| 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 #include <stddef.h> | 5 #include <stddef.h> |
| 6 #include <stdint.h> | 6 #include <stdint.h> |
| 7 | 7 |
| 8 #include <limits> | 8 #include <limits> |
| 9 #include <type_traits> | 9 #include <type_traits> |
| 10 | 10 |
| (...skipping 638 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 649 std::numeric_limits<float>::infinity(); | 649 std::numeric_limits<float>::infinity(); |
| 650 EXPECT_TRUE(std::isnan(not_a_number)); | 650 EXPECT_TRUE(std::isnan(not_a_number)); |
| 651 EXPECT_EQ(0, saturated_cast<int>(not_a_number)); | 651 EXPECT_EQ(0, saturated_cast<int>(not_a_number)); |
| 652 } | 652 } |
| 653 | 653 |
| 654 TEST(SafeNumerics, SaturatedCastChecks) { | 654 TEST(SafeNumerics, SaturatedCastChecks) { |
| 655 float not_a_number = std::numeric_limits<float>::infinity() - | 655 float not_a_number = std::numeric_limits<float>::infinity() - |
| 656 std::numeric_limits<float>::infinity(); | 656 std::numeric_limits<float>::infinity(); |
| 657 EXPECT_TRUE(std::isnan(not_a_number)); | 657 EXPECT_TRUE(std::isnan(not_a_number)); |
| 658 EXPECT_DCHECK_DEATH( | 658 EXPECT_DCHECK_DEATH( |
| 659 (saturated_cast<int, base::SaturatedCastNaNBehaviorCheck>(not_a_number)), | 659 (saturated_cast<int, base::SaturatedCastNaNBehaviorCheck>(not_a_number))); |
| 660 ""); | |
| 661 } | 660 } |
| 662 | 661 |
| 663 TEST(SafeNumerics, IsValueInRangeForNumericType) { | 662 TEST(SafeNumerics, IsValueInRangeForNumericType) { |
| 664 EXPECT_TRUE(IsValueInRangeForNumericType<uint32_t>(0)); | 663 EXPECT_TRUE(IsValueInRangeForNumericType<uint32_t>(0)); |
| 665 EXPECT_TRUE(IsValueInRangeForNumericType<uint32_t>(1)); | 664 EXPECT_TRUE(IsValueInRangeForNumericType<uint32_t>(1)); |
| 666 EXPECT_TRUE(IsValueInRangeForNumericType<uint32_t>(2)); | 665 EXPECT_TRUE(IsValueInRangeForNumericType<uint32_t>(2)); |
| 667 EXPECT_FALSE(IsValueInRangeForNumericType<uint32_t>(-1)); | 666 EXPECT_FALSE(IsValueInRangeForNumericType<uint32_t>(-1)); |
| 668 EXPECT_TRUE(IsValueInRangeForNumericType<uint32_t>(0xffffffffu)); | 667 EXPECT_TRUE(IsValueInRangeForNumericType<uint32_t>(0xffffffffu)); |
| 669 EXPECT_TRUE(IsValueInRangeForNumericType<uint32_t>(UINT64_C(0xffffffff))); | 668 EXPECT_TRUE(IsValueInRangeForNumericType<uint32_t>(UINT64_C(0xffffffff))); |
| 670 EXPECT_FALSE(IsValueInRangeForNumericType<uint32_t>(UINT64_C(0x100000000))); | 669 EXPECT_FALSE(IsValueInRangeForNumericType<uint32_t>(UINT64_C(0x100000000))); |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 751 | 750 |
| 752 CheckedNumeric<int> too_large = std::numeric_limits<int>::max(); | 751 CheckedNumeric<int> too_large = std::numeric_limits<int>::max(); |
| 753 EXPECT_TRUE(too_large.IsValid()); | 752 EXPECT_TRUE(too_large.IsValid()); |
| 754 too_large += d; | 753 too_large += d; |
| 755 EXPECT_FALSE(too_large.IsValid()); | 754 EXPECT_FALSE(too_large.IsValid()); |
| 756 too_large -= d; | 755 too_large -= d; |
| 757 EXPECT_FALSE(too_large.IsValid()); | 756 EXPECT_FALSE(too_large.IsValid()); |
| 758 too_large /= d; | 757 too_large /= d; |
| 759 EXPECT_FALSE(too_large.IsValid()); | 758 EXPECT_FALSE(too_large.IsValid()); |
| 760 } | 759 } |
| OLD | NEW |