diff options
author | danakj <danakj@chromium.org> | 2015-03-09 15:27:25 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-03-09 22:28:34 +0000 |
commit | 94219a212c616eac1914ca851c55256c4bbd9e36 (patch) | |
tree | b9721bd6f2d10f117355fdfa1a0391262b745628 | |
parent | 6be122fb693fe8f2a5b150a12bddd5c85160b7a6 (diff) | |
download | chromium_src-94219a212c616eac1914ca851c55256c4bbd9e36.zip chromium_src-94219a212c616eac1914ca851c55256c4bbd9e36.tar.gz chromium_src-94219a212c616eac1914ca851c55256c4bbd9e36.tar.bz2 |
base: Use more specific CHECK macros for comparisons.
Prefer DCHECK_EQ(a, b) over DCHECK(a == b) when possible as this
provides more data on a failure. Similar for other operators such as
>=, <, !=, etc.
This also applies to CHECK, EXPECT, and ASSERT macros.
R=Nico
BUG=464816
Review URL: https://codereview.chromium.org/985723003
Cr-Commit-Position: refs/heads/master@{#319751}
23 files changed, 65 insertions, 66 deletions
diff --git a/base/barrier_closure.cc b/base/barrier_closure.cc index 5abe2bf..1b77429 100644 --- a/base/barrier_closure.cc +++ b/base/barrier_closure.cc @@ -39,7 +39,7 @@ namespace base { base::Closure BarrierClosure(int num_callbacks_left, const base::Closure& done_closure) { - DCHECK(num_callbacks_left >= 0); + DCHECK_GE(num_callbacks_left, 0); if (num_callbacks_left == 0) done_closure.Run(); diff --git a/base/command_line.cc b/base/command_line.cc index 6125667d..d28a4b4 100644 --- a/base/command_line.cc +++ b/base/command_line.cc @@ -187,7 +187,7 @@ CommandLine::~CommandLine() { // static void CommandLine::set_slash_is_not_a_switch() { // The last switch prefix should be slash, so adjust the size to skip it. - DCHECK(wcscmp(kSwitchPrefixes[arraysize(kSwitchPrefixes) - 1], L"/") == 0); + DCHECK_EQ(wcscmp(kSwitchPrefixes[arraysize(kSwitchPrefixes) - 1], L"/"), 0); switch_prefix_count = arraysize(kSwitchPrefixes) - 1; } #endif diff --git a/base/mac/scoped_mach_vm.cc b/base/mac/scoped_mach_vm.cc index 1c28d9c..d52c77f 100644 --- a/base/mac/scoped_mach_vm.cc +++ b/base/mac/scoped_mach_vm.cc @@ -8,8 +8,8 @@ namespace base { namespace mac { void ScopedMachVM::reset(vm_address_t address, vm_size_t size) { - DCHECK(address % PAGE_SIZE == 0); - DCHECK(size % PAGE_SIZE == 0); + DCHECK_EQ(address % PAGE_SIZE, 0u); + DCHECK_EQ(size % PAGE_SIZE, 0u); if (size_) { if (address_ < address) { diff --git a/base/mac/scoped_mach_vm.h b/base/mac/scoped_mach_vm.h index b130a79..ffc00d5 100644 --- a/base/mac/scoped_mach_vm.h +++ b/base/mac/scoped_mach_vm.h @@ -48,10 +48,9 @@ namespace mac { class BASE_EXPORT ScopedMachVM { public: explicit ScopedMachVM(vm_address_t address = 0, vm_size_t size = 0) - : address_(address), - size_(size) { - DCHECK(address % PAGE_SIZE == 0); - DCHECK(size % PAGE_SIZE == 0); + : address_(address), size_(size) { + DCHECK_EQ(address % PAGE_SIZE, 0u); + DCHECK_EQ(size % PAGE_SIZE, 0u); } ~ScopedMachVM() { diff --git a/base/memory/discardable_memory_ashmem_allocator_unittest.cc b/base/memory/discardable_memory_ashmem_allocator_unittest.cc index e9f63ba..e6f2fea 100644 --- a/base/memory/discardable_memory_ashmem_allocator_unittest.cc +++ b/base/memory/discardable_memory_ashmem_allocator_unittest.cc @@ -85,7 +85,7 @@ TEST_F(DiscardableMemoryAshmemAllocatorTest, scoped_ptr<DiscardableAshmemChunk> memory(allocator.Allocate(kPageSize)); ASSERT_TRUE(memory); EXPECT_GT(kMaxAllowedAllocationSize, allocator.last_ashmem_region_size()); - ASSERT_TRUE(allocator.last_ashmem_region_size() % kPageSize == 0); + ASSERT_EQ(allocator.last_ashmem_region_size() % kPageSize, 0u); } TEST_F(DiscardableMemoryAshmemAllocatorTest, LargeAllocation) { diff --git a/base/memory/shared_memory_posix.cc b/base/memory/shared_memory_posix.cc index fd26ad1..f8efa42 100644 --- a/base/memory/shared_memory_posix.cc +++ b/base/memory/shared_memory_posix.cc @@ -453,7 +453,7 @@ bool SharedMemory::ShareToProcessCommon(ProcessHandle process, case SHARE_READONLY: // We could imagine re-opening the file from /dev/fd, but that can't make // it readonly on Mac: https://codereview.chromium.org/27265002/#msg10 - CHECK(readonly_mapped_file_ >= 0); + CHECK_GE(readonly_mapped_file_, 0); handle_to_dup = readonly_mapped_file_; break; } diff --git a/base/message_loop/message_pump_win.cc b/base/message_loop/message_pump_win.cc index 5ef3a50..8226495 100644 --- a/base/message_loop/message_pump_win.cc +++ b/base/message_loop/message_pump_win.cc @@ -673,7 +673,7 @@ ULONG_PTR MessagePumpForIO::HandlerToKey(IOHandler* handler, // |IOHandler| is at least pointer-size aligned, so the lowest two bits are // always cleared. We use the lowest bit to distinguish completion keys with // and without the associated |IOContext|. - DCHECK((key & 1) == 0); + DCHECK_EQ(key & 1, 0u); // Mark the completion key as context-less. if (!has_valid_io_context) diff --git a/base/posix/unix_domain_socket_linux.cc b/base/posix/unix_domain_socket_linux.cc index 203285b..16d8eaa 100644 --- a/base/posix/unix_domain_socket_linux.cc +++ b/base/posix/unix_domain_socket_linux.cc @@ -136,8 +136,8 @@ ssize_t UnixDomainSocket::RecvMsgWithFlags(int fd, const unsigned payload_len = cmsg->cmsg_len - CMSG_LEN(0); if (cmsg->cmsg_level == SOL_SOCKET && cmsg->cmsg_type == SCM_RIGHTS) { - DCHECK(payload_len % sizeof(int) == 0); - DCHECK(wire_fds == NULL); + DCHECK_EQ(payload_len % sizeof(int), 0u); + DCHECK_EQ(wire_fds, static_cast<void*>(nullptr)); wire_fds = reinterpret_cast<int*>(CMSG_DATA(cmsg)); wire_fds_len = payload_len / sizeof(int); } @@ -146,8 +146,8 @@ ssize_t UnixDomainSocket::RecvMsgWithFlags(int fd, // SCM_CREDENTIALS. if (cmsg->cmsg_level == SOL_SOCKET && cmsg->cmsg_type == SCM_CREDENTIALS) { - DCHECK(payload_len == sizeof(struct ucred)); - DCHECK(pid == -1); + DCHECK_EQ(payload_len, sizeof(struct ucred)); + DCHECK_EQ(pid, -1); pid = reinterpret_cast<struct ucred*>(CMSG_DATA(cmsg))->pid; } #endif diff --git a/base/process/kill_mac.cc b/base/process/kill_mac.cc index 8c42400..a4e0a14 100644 --- a/base/process/kill_mac.cc +++ b/base/process/kill_mac.cc @@ -66,8 +66,8 @@ void BlockingReap(pid_t child) { // work in that case, but waitpid won't, and killing a non-child might not be // the best approach. void WaitForChildToDie(pid_t child, int timeout) { - DCHECK(child > 0); - DCHECK(timeout > 0); + DCHECK_GT(child, 0); + DCHECK_GT(timeout, 0); // DON'T ADD ANY EARLY RETURNS TO THIS FUNCTION without ensuring that // |child| has been reaped. Specifically, even if a kqueue, kevent, or other diff --git a/base/process/process_linux.cc b/base/process/process_linux.cc index 59ee288..88a310e 100644 --- a/base/process/process_linux.cc +++ b/base/process/process_linux.cc @@ -103,7 +103,7 @@ bool Process::IsProcessBackgrounded() const { &proc)) { std::vector<std::string> proc_parts; base::SplitString(proc, ':', &proc_parts); - DCHECK(proc_parts.size() == 3); + DCHECK_EQ(proc_parts.size(), 3u); bool ret = proc_parts[2] == std::string(kBackground); return ret; } else { diff --git a/base/process/process_metrics_unittest.cc b/base/process/process_metrics_unittest.cc index dbfaa1a..76767b0 100644 --- a/base/process/process_metrics_unittest.cc +++ b/base/process/process_metrics_unittest.cc @@ -143,29 +143,29 @@ TEST_F(SystemMetricsTest, ParseMeminfo) { "Hugepagesize: 4096 kB\n"; EXPECT_TRUE(ParseProcMeminfo(valid_input1, &meminfo)); - EXPECT_TRUE(meminfo.total == 3981504); - EXPECT_TRUE(meminfo.free == 140764); - EXPECT_TRUE(meminfo.buffers == 116480); - EXPECT_TRUE(meminfo.cached == 406160); - EXPECT_TRUE(meminfo.active_anon == 2972352); - EXPECT_TRUE(meminfo.active_file == 179688); - EXPECT_TRUE(meminfo.inactive_anon == 270108); - EXPECT_TRUE(meminfo.inactive_file == 202748); - EXPECT_TRUE(meminfo.swap_total == 5832280); - EXPECT_TRUE(meminfo.swap_free == 3672368); - EXPECT_TRUE(meminfo.dirty == 184); + EXPECT_EQ(meminfo.total, 3981504); + EXPECT_EQ(meminfo.free, 140764); + EXPECT_EQ(meminfo.buffers, 116480); + EXPECT_EQ(meminfo.cached, 406160); + EXPECT_EQ(meminfo.active_anon, 2972352); + EXPECT_EQ(meminfo.active_file, 179688); + EXPECT_EQ(meminfo.inactive_anon, 270108); + EXPECT_EQ(meminfo.inactive_file, 202748); + EXPECT_EQ(meminfo.swap_total, 5832280); + EXPECT_EQ(meminfo.swap_free, 3672368); + EXPECT_EQ(meminfo.dirty, 184); #if defined(OS_CHROMEOS) - EXPECT_TRUE(meminfo.shmem == 140204); - EXPECT_TRUE(meminfo.slab == 54212); + EXPECT_EQ(meminfo.shmem, 140204); + EXPECT_EQ(meminfo.slab, 54212); #endif EXPECT_TRUE(ParseProcMeminfo(valid_input2, &meminfo)); - EXPECT_TRUE(meminfo.total == 255908); - EXPECT_TRUE(meminfo.free == 69936); - EXPECT_TRUE(meminfo.buffers == 15812); - EXPECT_TRUE(meminfo.cached == 115124); - EXPECT_TRUE(meminfo.swap_total == 524280); - EXPECT_TRUE(meminfo.swap_free == 524200); - EXPECT_TRUE(meminfo.dirty == 4); + EXPECT_EQ(meminfo.total, 255908); + EXPECT_EQ(meminfo.free, 69936); + EXPECT_EQ(meminfo.buffers, 15812); + EXPECT_EQ(meminfo.cached, 115124); + EXPECT_EQ(meminfo.swap_total, 524280); + EXPECT_EQ(meminfo.swap_free, 524200); + EXPECT_EQ(meminfo.dirty, 4); } TEST_F(SystemMetricsTest, ParseVmstat) { @@ -260,13 +260,13 @@ TEST_F(SystemMetricsTest, ParseVmstat) { "pgrefill_high 0\n" "pgrefill_movable 0\n"; EXPECT_TRUE(ParseProcVmstat(valid_input1, &meminfo)); - EXPECT_TRUE(meminfo.pswpin == 179); - EXPECT_TRUE(meminfo.pswpout == 406); - EXPECT_TRUE(meminfo.pgmajfault == 487192); + EXPECT_EQ(meminfo.pswpin, 179); + EXPECT_EQ(meminfo.pswpout, 406); + EXPECT_EQ(meminfo.pgmajfault, 487192); EXPECT_TRUE(ParseProcVmstat(valid_input2, &meminfo)); - EXPECT_TRUE(meminfo.pswpin == 12); - EXPECT_TRUE(meminfo.pswpout == 901); - EXPECT_TRUE(meminfo.pgmajfault == 2023); + EXPECT_EQ(meminfo.pswpin, 12); + EXPECT_EQ(meminfo.pswpout, 901); + EXPECT_EQ(meminfo.pgmajfault, 2023); } #endif // defined(OS_LINUX) || defined(OS_ANDROID) diff --git a/base/strings/string_piece_unittest.cc b/base/strings/string_piece_unittest.cc index 7f50cfb..5336603 100644 --- a/base/strings/string_piece_unittest.cc +++ b/base/strings/string_piece_unittest.cc @@ -602,13 +602,13 @@ TYPED_TEST(CommonStringPieceTest, CheckComparisons2) { // check comparison operations on strings longer than 4 bytes. ASSERT_TRUE(abc == BasicStringPiece<TypeParam>(alphabet)); - ASSERT_TRUE(abc.compare(BasicStringPiece<TypeParam>(alphabet)) == 0); + ASSERT_EQ(abc.compare(BasicStringPiece<TypeParam>(alphabet)), 0); ASSERT_TRUE(abc < BasicStringPiece<TypeParam>(alphabet_z)); - ASSERT_TRUE(abc.compare(BasicStringPiece<TypeParam>(alphabet_z)) < 0); + ASSERT_LT(abc.compare(BasicStringPiece<TypeParam>(alphabet_z)), 0); ASSERT_TRUE(abc > BasicStringPiece<TypeParam>(alphabet_y)); - ASSERT_TRUE(abc.compare(BasicStringPiece<TypeParam>(alphabet_y)) > 0); + ASSERT_GT(abc.compare(BasicStringPiece<TypeParam>(alphabet_y)), 0); } // Test operations only supported by std::string version. diff --git a/base/strings/string_split.cc b/base/strings/string_split.cc index 7ef4760..692f300 100644 --- a/base/strings/string_split.cc +++ b/base/strings/string_split.cc @@ -138,9 +138,9 @@ void SplitString(const std::string& str, char c, std::vector<std::string>* r) { #if CHAR_MIN < 0 - DCHECK(c >= 0); + DCHECK_GE(c, 0); #endif - DCHECK(c < 0x7F); + DCHECK_LT(c, 0x7F); SplitStringT(str, c, true, r); } @@ -195,9 +195,9 @@ void SplitStringDontTrim(const std::string& str, std::vector<std::string>* r) { DCHECK(IsStringUTF8(str)); #if CHAR_MIN < 0 - DCHECK(c >= 0); + DCHECK_GE(c, 0); #endif - DCHECK(c < 0x7F); + DCHECK_LT(c, 0x7F); SplitStringT(str, c, false, r); } diff --git a/base/sys_info_linux.cc b/base/sys_info_linux.cc index 2e679ed..c698f91 100644 --- a/base/sys_info_linux.cc +++ b/base/sys_info_linux.cc @@ -43,7 +43,7 @@ size_t MaxSharedMemorySize() { if (limit > std::numeric_limits<size_t>::max()) { limit = 0; } - DCHECK(limit > 0); + DCHECK_GT(limit, 0u); return static_cast<size_t>(limit); } diff --git a/base/test/test_file_util_win.cc b/base/test/test_file_util_win.cc index af8bd76..5496a55 100644 --- a/base/test/test_file_util_win.cc +++ b/base/test/test_file_util_win.cc @@ -175,7 +175,7 @@ bool EvictFileFromSystemCache(const FilePath& file) { // Move back to the position we just read from. // Note that SetFilePointer will also fail if total_bytes isn't sector // aligned, but that shouldn't happen here. - DCHECK((total_bytes % kOneMB) == 0); + DCHECK_EQ(total_bytes % kOneMB, 0); SetFilePointer(file_handle.Get(), total_bytes, NULL, FILE_BEGIN); if (!::WriteFile(file_handle.Get(), buffer, kOneMB, &bytes_written, NULL) || bytes_written != kOneMB) { diff --git a/base/threading/sequenced_worker_pool.cc b/base/threading/sequenced_worker_pool.cc index 19b81b7..f20d997 100644 --- a/base/threading/sequenced_worker_pool.cc +++ b/base/threading/sequenced_worker_pool.cc @@ -1091,7 +1091,7 @@ int SequencedWorkerPool::Inner::PrepareToStartAdditionalThreadIfHelpful() { void SequencedWorkerPool::Inner::FinishStartingAdditionalThread( int thread_number) { // Called outside of the lock. - DCHECK(thread_number > 0); + DCHECK_GT(thread_number, 0); // The worker is assigned to the list when the thread actually starts, which // will manage the memory of the pointer. diff --git a/base/threading/sequenced_worker_pool_unittest.cc b/base/threading/sequenced_worker_pool_unittest.cc index 9d0f607..c132731 100644 --- a/base/threading/sequenced_worker_pool_unittest.cc +++ b/base/threading/sequenced_worker_pool_unittest.cc @@ -54,7 +54,7 @@ class ThreadBlocker { void Unblock(size_t count) { { base::AutoLock lock(lock_); - DCHECK(unblock_counter_ == 0); + DCHECK_EQ(unblock_counter_, 0u); unblock_counter_ = count; } cond_var_.Signal(); diff --git a/base/time/time_win.cc b/base/time/time_win.cc index 8ae7640..d2403f2 100644 --- a/base/time/time_win.cc +++ b/base/time/time_win.cc @@ -203,12 +203,12 @@ bool Time::ActivateHighResolutionTimer(bool activating) { UINT period = g_high_res_timer_enabled ? kMinTimerIntervalHighResMs : kMinTimerIntervalLowResMs; if (activating) { - DCHECK(g_high_res_timer_count != max); + DCHECK_NE(g_high_res_timer_count, max); ++g_high_res_timer_count; if (g_high_res_timer_count == 1) timeBeginPeriod(period); } else { - DCHECK(g_high_res_timer_count != 0); + DCHECK_NE(g_high_res_timer_count, 0u); --g_high_res_timer_count; if (g_high_res_timer_count == 0) timeEndPeriod(period); diff --git a/base/trace_event/process_memory_maps_dump_provider.cc b/base/trace_event/process_memory_maps_dump_provider.cc index 93feded..fbe0eb1 100644 --- a/base/trace_event/process_memory_maps_dump_provider.cc +++ b/base/trace_event/process_memory_maps_dump_provider.cc @@ -47,7 +47,7 @@ bool ParseSmapsHeader(std::istream* smaps, region->protection_flags = 0; *smaps >> protection_flags; - CHECK(4UL == protection_flags.size()); + CHECK_EQ(4UL, protection_flags.size()); if (protection_flags[0] == 'r') { region->protection_flags |= ProcessMemoryMaps::VMRegion::kProtectionFlagsRead; diff --git a/base/trace_event/trace_event_impl.cc b/base/trace_event/trace_event_impl.cc index 34bbb28..bd0b57d 100644 --- a/base/trace_event/trace_event_impl.cc +++ b/base/trace_event/trace_event_impl.cc @@ -624,7 +624,7 @@ void TraceEvent::Reset() { void TraceEvent::UpdateDuration(const TimeTicks& now, const TimeTicks& thread_now) { - DCHECK(duration_.ToInternalValue() == -1); + DCHECK_EQ(duration_.ToInternalValue(), -1); duration_ = now - timestamp_; thread_duration_ = thread_now - thread_timestamp_; } @@ -2588,7 +2588,7 @@ namespace trace_event_internal { ScopedTraceBinaryEfficient::ScopedTraceBinaryEfficient( const char* category_group, const char* name) { // The single atom works because for now the category_group can only be "gpu". - DCHECK(strcmp(category_group, "gpu") == 0); + DCHECK_EQ(strcmp(category_group, "gpu"), 0); static TRACE_EVENT_API_ATOMIC_WORD atomic = 0; INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO_CUSTOM_VARIABLES( category_group, atomic, category_group_enabled_); diff --git a/base/win/registry.cc b/base/win/registry.cc index b39b749..d0df48a 100644 --- a/base/win/registry.cc +++ b/base/win/registry.cc @@ -210,7 +210,7 @@ void RegKey::Set(HKEY key) { } HKEY RegKey::Take() { - DCHECK(wow64access_ == 0); + DCHECK_EQ(wow64access_, 0u); HKEY key = key_; key_ = NULL; return key; diff --git a/base/win/scoped_comptr_unittest.cc b/base/win/scoped_comptr_unittest.cc index 711c52f..d38752d 100644 --- a/base/win/scoped_comptr_unittest.cc +++ b/base/win/scoped_comptr_unittest.cc @@ -31,8 +31,8 @@ const IID dummy_iid = { 0x12345678u, 0x1234u, 0x5678u, 01, 23, 45, 67, 89, } // namespace TEST(ScopedComPtrTest, ScopedComPtr) { - EXPECT_TRUE(memcmp(&ScopedComPtr<IUnknown>::iid(), &IID_IUnknown, - sizeof(IID)) == 0); + EXPECT_EQ(memcmp(&ScopedComPtr<IUnknown>::iid(), &IID_IUnknown, sizeof(IID)), + 0); base::win::ScopedCOMInitializer com_initializer; EXPECT_TRUE(com_initializer.succeeded()); diff --git a/base/win/win_util_unittest.cc b/base/win/win_util_unittest.cc index 8300c16..24141cd 100644 --- a/base/win/win_util_unittest.cc +++ b/base/win/win_util_unittest.cc @@ -49,9 +49,9 @@ TEST(BaseWinUtilTest, TestGetUserSidString) { TEST(BaseWinUtilTest, TestGetNonClientMetrics) { NONCLIENTMETRICS_XP metrics = {0}; GetNonClientMetrics(&metrics); - EXPECT_TRUE(metrics.cbSize > 0); - EXPECT_TRUE(metrics.iScrollWidth > 0); - EXPECT_TRUE(metrics.iScrollHeight > 0); + EXPECT_GT(metrics.cbSize, 0u); + EXPECT_GT(metrics.iScrollWidth, 0); + EXPECT_GT(metrics.iScrollHeight, 0); } } // namespace win |