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

Side by Side Diff: test/unittests/base/logging-unittest.cc

Issue 2526783002: [base] Define CHECK comparison for signed vs. unsigned (Closed)
Patch Set: Rebase Created 4 years 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
« no previous file with comments | « src/wasm/wasm-text.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 the V8 project 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 <cstdint>
6
5 #include "src/base/logging.h" 7 #include "src/base/logging.h"
8 #include "src/objects.h"
6 #include "testing/gtest-support.h" 9 #include "testing/gtest-support.h"
7 10
8 namespace v8 { 11 namespace v8 {
9 namespace base { 12 namespace base {
10 13
11 namespace { 14 namespace {
12 template <typename Lhs, typename Rhs> 15
13 std::string *CallCheckEQ(Lhs lhs, Rhs rhs, const char *msg) { 16 #define CHECK_SUCCEED(NAME, lhs, rhs) \
14 return CheckEQImpl<Lhs, Rhs>(lhs, rhs, msg); 17 { \
15 } 18 std::string* error_message = \
19 Check##NAME##Impl<decltype(lhs), decltype(rhs)>((lhs), (rhs), ""); \
20 EXPECT_EQ(nullptr, error_message); \
21 }
22
23 #define CHECK_FAIL(NAME, lhs, rhs) \
24 { \
25 std::string* error_message = \
26 Check##NAME##Impl<decltype(lhs), decltype(rhs)>((lhs), (rhs), ""); \
27 EXPECT_NE(nullptr, error_message); \
28 }
29
16 } // namespace 30 } // namespace
17 31
18 TEST(LoggingTest, CheckEQImpl) { 32 TEST(LoggingTest, CheckEQImpl) {
19 EXPECT_EQ(nullptr, CallCheckEQ(0.0, 0.0, "")); 33 CHECK_SUCCEED(EQ, 0.0, 0.0)
20 EXPECT_EQ(nullptr, CallCheckEQ(0.0, -0.0, "")); 34 CHECK_SUCCEED(EQ, 0.0, -0.0)
21 EXPECT_EQ(nullptr, CallCheckEQ(-0.0, 0.0, "")); 35 CHECK_SUCCEED(EQ, -0.0, 0.0)
22 EXPECT_EQ(nullptr, CallCheckEQ(-0.0, -0.0, "")); 36 CHECK_SUCCEED(EQ, -0.0, -0.0)
37 }
38
39 TEST(LoggingTest, CompareSignedMismatch) {
40 CHECK_SUCCEED(EQ, static_cast<int32_t>(14), static_cast<uint32_t>(14))
41 CHECK_FAIL(EQ, static_cast<int32_t>(14), static_cast<uint32_t>(15))
42 CHECK_FAIL(EQ, static_cast<int32_t>(-1), static_cast<uint32_t>(-1))
43 CHECK_SUCCEED(LT, static_cast<int32_t>(-1), static_cast<uint32_t>(0))
44 CHECK_SUCCEED(LT, static_cast<int32_t>(-1), static_cast<uint32_t>(-1))
45 CHECK_SUCCEED(LE, static_cast<int32_t>(-1), static_cast<uint32_t>(0))
46 CHECK_SUCCEED(LE, static_cast<int32_t>(55), static_cast<uint32_t>(55))
47 CHECK_SUCCEED(LT, static_cast<int32_t>(55), static_cast<uint32_t>(0x7fffff00))
48 CHECK_SUCCEED(LE, static_cast<int32_t>(55), static_cast<uint32_t>(0x7fffff00))
49 CHECK_SUCCEED(GE, static_cast<uint32_t>(0x7fffff00), static_cast<int32_t>(55))
50 CHECK_SUCCEED(GT, static_cast<uint32_t>(0x7fffff00), static_cast<int32_t>(55))
51 CHECK_SUCCEED(GT, static_cast<uint32_t>(-1), static_cast<int32_t>(-1))
52 CHECK_SUCCEED(GE, static_cast<uint32_t>(0), static_cast<int32_t>(-1))
53 CHECK_SUCCEED(LT, static_cast<int8_t>(-1), static_cast<uint32_t>(0))
54 CHECK_SUCCEED(GT, static_cast<uint64_t>(0x7f01010101010101), 0)
55 CHECK_SUCCEED(LE, static_cast<int64_t>(0xff01010101010101),
56 static_cast<uint8_t>(13))
57 }
58
59 TEST(LoggingTest, CompareAgainstStaticConstPointer) {
60 // These used to produce link errors before http://crrev.com/2524093002.
61 CHECK_FAIL(EQ, v8::internal::Smi::kZero, v8::internal::Smi::FromInt(17));
62 CHECK_SUCCEED(GT, 0, v8::internal::Smi::kMinValue);
23 } 63 }
24 64
25 } // namespace base 65 } // namespace base
26 } // namespace v8 66 } // namespace v8
OLDNEW
« no previous file with comments | « src/wasm/wasm-text.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698