OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #if defined(COMPILER_MSVC) && defined(ARCH_CPU_32_BITS) | 5 #if defined(COMPILER_MSVC) && defined(ARCH_CPU_32_BITS) |
6 #include <mmintrin.h> | 6 #include <mmintrin.h> |
7 #endif | 7 #endif |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <limits> | 10 #include <limits> |
(...skipping 11 matching lines...) Expand all Loading... |
22 using base::StrictNumeric; | 22 using base::StrictNumeric; |
23 using base::saturated_cast; | 23 using base::saturated_cast; |
24 using base::strict_cast; | 24 using base::strict_cast; |
25 using base::internal::MaxExponent; | 25 using base::internal::MaxExponent; |
26 using base::internal::RANGE_VALID; | 26 using base::internal::RANGE_VALID; |
27 using base::internal::RANGE_INVALID; | 27 using base::internal::RANGE_INVALID; |
28 using base::internal::RANGE_OVERFLOW; | 28 using base::internal::RANGE_OVERFLOW; |
29 using base::internal::RANGE_UNDERFLOW; | 29 using base::internal::RANGE_UNDERFLOW; |
30 using base::enable_if; | 30 using base::enable_if; |
31 | 31 |
32 // These tests deliberately cause arithmetic overflows. If the compiler is | |
33 // aggressive enough, it can const fold these overflows. Disable warnings about | |
34 // overflows for const expressions. | |
35 #if defined(OS_WIN) | |
36 #pragma warning(disable:4756) | |
37 #endif | |
38 | |
39 // Helper macros to wrap displaying the conversion types and line numbers. | 32 // Helper macros to wrap displaying the conversion types and line numbers. |
40 #define TEST_EXPECTED_VALIDITY(expected, actual) \ | 33 #define TEST_EXPECTED_VALIDITY(expected, actual) \ |
41 EXPECT_EQ(expected, CheckedNumeric<Dst>(actual).validity()) \ | 34 EXPECT_EQ(expected, CheckedNumeric<Dst>(actual).validity()) \ |
42 << "Result test: Value " << +(actual).ValueUnsafe() << " as " << dst \ | 35 << "Result test: Value " << +(actual).ValueUnsafe() << " as " << dst \ |
43 << " on line " << line; | 36 << " on line " << line; |
44 | 37 |
45 #define TEST_EXPECTED_VALUE(expected, actual) \ | 38 #define TEST_EXPECTED_VALUE(expected, actual) \ |
46 EXPECT_EQ(static_cast<Dst>(expected), \ | 39 EXPECT_EQ(static_cast<Dst>(expected), \ |
47 CheckedNumeric<Dst>(actual).ValueUnsafe()) \ | 40 CheckedNumeric<Dst>(actual).ValueUnsafe()) \ |
48 << "Result test: Value " << +((actual).ValueUnsafe()) << " as " << dst \ | 41 << "Result test: Value " << +((actual).ValueUnsafe()) << " as " << dst \ |
(...skipping 544 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
593 static_cast<unsigned>(0)); | 586 static_cast<unsigned>(0)); |
594 EXPECT_EQ(saturated_cast<int>(double_small), | 587 EXPECT_EQ(saturated_cast<int>(double_small), |
595 static_cast<int>(double_small)); | 588 static_cast<int>(double_small)); |
596 EXPECT_EQ(saturated_cast<int>(double_large), numeric_limits<int>::max()); | 589 EXPECT_EQ(saturated_cast<int>(double_large), numeric_limits<int>::max()); |
597 EXPECT_EQ(saturated_cast<float>(double_large), double_infinity); | 590 EXPECT_EQ(saturated_cast<float>(double_large), double_infinity); |
598 EXPECT_EQ(saturated_cast<float>(-double_large), -double_infinity); | 591 EXPECT_EQ(saturated_cast<float>(-double_large), -double_infinity); |
599 EXPECT_EQ(numeric_limits<int>::min(), saturated_cast<int>(double_small_int)); | 592 EXPECT_EQ(numeric_limits<int>::min(), saturated_cast<int>(double_small_int)); |
600 EXPECT_EQ(numeric_limits<int>::max(), saturated_cast<int>(double_large_int)); | 593 EXPECT_EQ(numeric_limits<int>::max(), saturated_cast<int>(double_large_int)); |
601 } | 594 } |
602 | 595 |
OLD | NEW |