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

Unified Diff: base/numerics/safe_numerics_unittest.cc

Issue 2496143003: Simplify CheckedNumeric macros (Closed)
Patch Set: nits 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/numerics/safe_math_impl.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/numerics/safe_numerics_unittest.cc
diff --git a/base/numerics/safe_numerics_unittest.cc b/base/numerics/safe_numerics_unittest.cc
index c7098527f8a9b694a234ab323460efe4c4c5f352..3652ac54252aa70c1bfc6557184f2051dd8853ff 100644
--- a/base/numerics/safe_numerics_unittest.cc
+++ b/base/numerics/safe_numerics_unittest.cc
@@ -66,7 +66,7 @@ Dst GetMaxConvertibleToFloat() {
#define TEST_EXPECTED_VALIDITY(expected, actual) \
EXPECT_EQ(expected, CheckedNumeric<Dst>(actual).IsValid()) \
<< "Result test: Value " << +(actual).ValueUnsafe() << " as " << dst \
- << " on line " << line;
+ << " on line " << line
#define TEST_EXPECTED_SUCCESS(actual) TEST_EXPECTED_VALIDITY(true, actual)
#define TEST_EXPECTED_FAILURE(actual) TEST_EXPECTED_VALIDITY(false, actual)
@@ -75,7 +75,7 @@ Dst GetMaxConvertibleToFloat() {
EXPECT_EQ(static_cast<Dst>(expected), \
CheckedNumeric<Dst>(actual).ValueOrDie()) \
<< "Result test: Value " << +((actual).ValueUnsafe()) << " as " << dst \
- << " on line " << line;
+ << " on line " << line
// Signed integer arithmetic.
template <typename Dst>
@@ -106,6 +106,7 @@ static void TestSpecializedArithmetic(
TEST_EXPECTED_FAILURE(CheckedNumeric<Dst>(DstLimits::min()) / -1);
TEST_EXPECTED_VALUE(0, CheckedNumeric<Dst>(-1) / 2);
+ TEST_EXPECTED_FAILURE(CheckedNumeric<Dst>(DstLimits::min()) * -1);
// Modulus is legal only for integers.
TEST_EXPECTED_VALUE(0, CheckedNumeric<Dst>() % 1);
@@ -256,6 +257,8 @@ static void TestArithmetic(const char* dst, int line) {
if (numeric_limits<Dst>::is_signed) {
TEST_EXPECTED_VALUE(-1, (CheckedNumeric<Dst>() - 1));
TEST_EXPECTED_VALUE(-2, (CheckedNumeric<Dst>(-1) - 1));
+ } else {
+ TEST_EXPECTED_FAILURE(CheckedNumeric<Dst>(DstLimits::max()) - -1);
}
// Generic multiplication.
@@ -266,6 +269,10 @@ static void TestArithmetic(const char* dst, int line) {
TEST_EXPECTED_VALUE(0, (CheckedNumeric<Dst>(-1) * 0));
TEST_EXPECTED_VALUE(0, (CheckedNumeric<Dst>(0) * -1));
TEST_EXPECTED_VALUE(-2, (CheckedNumeric<Dst>(-1) * 2));
+ } else {
+ TEST_EXPECTED_FAILURE(CheckedNumeric<Dst>(DstLimits::max()) * -2);
+ TEST_EXPECTED_FAILURE(CheckedNumeric<Dst>(DstLimits::max()) *
+ CheckedNumeric<uintmax_t>(-2));
}
TEST_EXPECTED_FAILURE(CheckedNumeric<Dst>(DstLimits::max()) *
DstLimits::max());
@@ -320,7 +327,7 @@ struct TestNumericConversion {};
#define TEST_EXPECTED_RANGE(expected, actual) \
EXPECT_EQ(expected, base::internal::DstRangeRelationToSrcRange<Dst>(actual)) \
<< "Conversion test: " << src << " value " << actual << " to " << dst \
- << " on line " << line;
+ << " on line " << line
template <typename Dst, typename Src>
struct TestNumericConversion<Dst, Src, SIGN_PRESERVING_VALUE_PRESERVING> {
« no previous file with comments | « base/numerics/safe_math_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698