Logan Chien | 008fa51 | 2012-06-22 08:09:57 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include "runtime_support.h" |
| 18 | |
| 19 | #include "common_test.h" |
| 20 | #include <limits> |
| 21 | |
| 22 | namespace art { |
| 23 | |
| 24 | class RuntimeSupportTest : public CommonTest {}; |
| 25 | |
| 26 | TEST_F(RuntimeSupportTest, DoubleToLong) { |
| 27 | EXPECT_EQ(std::numeric_limits<int64_t>::max(), art_d2l(1.85e19)); |
| 28 | EXPECT_EQ(std::numeric_limits<int64_t>::min(), art_d2l(-1.85e19)); |
| 29 | EXPECT_EQ(0LL, art_d2l(0)); |
| 30 | EXPECT_EQ(1LL, art_d2l(1.0)); |
| 31 | EXPECT_EQ(10LL, art_d2l(10.0)); |
| 32 | EXPECT_EQ(100LL, art_d2l(100.0)); |
| 33 | EXPECT_EQ(-1LL, art_d2l(-1.0)); |
| 34 | EXPECT_EQ(-10LL, art_d2l(-10.0)); |
| 35 | EXPECT_EQ(-100LL, art_d2l(-100.0)); |
| 36 | } |
| 37 | |
| 38 | TEST_F(RuntimeSupportTest, FloatToLong) { |
| 39 | EXPECT_EQ(std::numeric_limits<int64_t>::max(), art_f2l(1.85e19)); |
| 40 | EXPECT_EQ(std::numeric_limits<int64_t>::min(), art_f2l(-1.85e19)); |
| 41 | EXPECT_EQ(0LL, art_f2l(0)); |
| 42 | EXPECT_EQ(1LL, art_f2l(1.0)); |
| 43 | EXPECT_EQ(10LL, art_f2l(10.0)); |
| 44 | EXPECT_EQ(100LL, art_f2l(100.0)); |
| 45 | EXPECT_EQ(-1LL, art_f2l(-1.0)); |
| 46 | EXPECT_EQ(-10LL, art_f2l(-10.0)); |
| 47 | EXPECT_EQ(-100LL, art_f2l(-100.0)); |
| 48 | } |
| 49 | |
| 50 | TEST_F(RuntimeSupportTest, DoubleToInt) { |
| 51 | EXPECT_EQ(std::numeric_limits<int32_t>::max(), art_d2i(4.3e9)); |
| 52 | EXPECT_EQ(std::numeric_limits<int32_t>::min(), art_d2i(-4.3e9)); |
| 53 | EXPECT_EQ(0L, art_d2i(0)); |
| 54 | EXPECT_EQ(1L, art_d2i(1.0)); |
| 55 | EXPECT_EQ(10L, art_d2i(10.0)); |
| 56 | EXPECT_EQ(100L, art_d2i(100.0)); |
| 57 | EXPECT_EQ(-1L, art_d2i(-1.0)); |
| 58 | EXPECT_EQ(-10L, art_d2i(-10.0)); |
| 59 | EXPECT_EQ(-100L, art_d2i(-100.0)); |
| 60 | } |
| 61 | |
| 62 | TEST_F(RuntimeSupportTest, FloatToInt) { |
| 63 | EXPECT_EQ(std::numeric_limits<int32_t>::max(), art_f2i(4.3e9)); |
| 64 | EXPECT_EQ(std::numeric_limits<int32_t>::min(), art_f2i(-4.3e9)); |
| 65 | EXPECT_EQ(0L, art_f2i(0)); |
| 66 | EXPECT_EQ(1L, art_f2i(1.0)); |
| 67 | EXPECT_EQ(10L, art_f2i(10.0)); |
| 68 | EXPECT_EQ(100L, art_f2i(100.0)); |
| 69 | EXPECT_EQ(-1L, art_f2i(-1.0)); |
| 70 | EXPECT_EQ(-10L, art_f2i(-10.0)); |
| 71 | EXPECT_EQ(-100L, art_f2i(-100.0)); |
| 72 | } |
| 73 | |
| 74 | } // namespace art |