Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(452)

Side by Side Diff: base/numerics/safe_numerics_unittest.cc

Issue 2481903002: Make checked_cast a constexpr (Closed)
Patch Set: nit Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 646 matching lines...) Expand 10 before | Expand all | Expand 10 after
657 std::numeric_limits<float>::infinity(); 657 std::numeric_limits<float>::infinity();
658 EXPECT_TRUE(std::isnan(not_a_number)); 658 EXPECT_TRUE(std::isnan(not_a_number));
659 EXPECT_EQ(0, saturated_cast<int>(not_a_number)); 659 EXPECT_EQ(0, saturated_cast<int>(not_a_number));
660 } 660 }
661 661
662 TEST(SafeNumerics, SaturatedCastChecks) { 662 TEST(SafeNumerics, SaturatedCastChecks) {
663 float not_a_number = std::numeric_limits<float>::infinity() - 663 float not_a_number = std::numeric_limits<float>::infinity() -
664 std::numeric_limits<float>::infinity(); 664 std::numeric_limits<float>::infinity();
665 EXPECT_TRUE(std::isnan(not_a_number)); 665 EXPECT_TRUE(std::isnan(not_a_number));
666 EXPECT_DEATH_IF_SUPPORTED( 666 EXPECT_DEATH_IF_SUPPORTED(
667 (saturated_cast<int, base::SaturatedCastNaNBehaviorCheck>(not_a_number)), 667 (saturated_cast<int, base::CheckOnFailure>(not_a_number)),
668 ""); 668 "");
669 } 669 }
670 670
671 TEST(SafeNumerics, IsValueInRangeForNumericType) { 671 TEST(SafeNumerics, IsValueInRangeForNumericType) {
672 EXPECT_TRUE(IsValueInRangeForNumericType<uint32_t>(0)); 672 EXPECT_TRUE(IsValueInRangeForNumericType<uint32_t>(0));
673 EXPECT_TRUE(IsValueInRangeForNumericType<uint32_t>(1)); 673 EXPECT_TRUE(IsValueInRangeForNumericType<uint32_t>(1));
674 EXPECT_TRUE(IsValueInRangeForNumericType<uint32_t>(2)); 674 EXPECT_TRUE(IsValueInRangeForNumericType<uint32_t>(2));
675 EXPECT_FALSE(IsValueInRangeForNumericType<uint32_t>(-1)); 675 EXPECT_FALSE(IsValueInRangeForNumericType<uint32_t>(-1));
676 EXPECT_TRUE(IsValueInRangeForNumericType<uint32_t>(0xffffffffu)); 676 EXPECT_TRUE(IsValueInRangeForNumericType<uint32_t>(0xffffffffu));
677 EXPECT_TRUE(IsValueInRangeForNumericType<uint32_t>(UINT64_C(0xffffffff))); 677 EXPECT_TRUE(IsValueInRangeForNumericType<uint32_t>(UINT64_C(0xffffffff)));
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
759 759
760 CheckedNumeric<int> too_large = std::numeric_limits<int>::max(); 760 CheckedNumeric<int> too_large = std::numeric_limits<int>::max();
761 EXPECT_TRUE(too_large.IsValid()); 761 EXPECT_TRUE(too_large.IsValid());
762 too_large += d; 762 too_large += d;
763 EXPECT_FALSE(too_large.IsValid()); 763 EXPECT_FALSE(too_large.IsValid());
764 too_large -= d; 764 too_large -= d;
765 EXPECT_FALSE(too_large.IsValid()); 765 EXPECT_FALSE(too_large.IsValid());
766 too_large /= d; 766 too_large /= d;
767 EXPECT_FALSE(too_large.IsValid()); 767 EXPECT_FALSE(too_large.IsValid());
768 } 768 }
OLDNEW
« no previous file with comments | « base/numerics/safe_conversions.h ('k') | components/autofill/core/common/save_password_progress_logger.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698