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

Side by Side Diff: base/logging_unittest.cc

Issue 195973002: Change DCHECK_IS_ON() to DCHECK_IS_ON (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Keep a comment Created 6 years, 9 months 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 | Annotate | Revision Log
« no previous file with comments | « base/logging.h ('k') | base/mac/mac_logging.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "base/basictypes.h" 5 #include "base/basictypes.h"
6 #include "base/logging.h" 6 #include "base/logging.h"
7 7
8 #include "testing/gmock/include/gmock/gmock.h" 8 #include "testing/gmock/include/gmock/gmock.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 10
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 // in release mode. 197 // in release mode.
198 DLOG_IF(INFO, debug_only_variable) << "test"; 198 DLOG_IF(INFO, debug_only_variable) << "test";
199 DLOG_ASSERT(debug_only_variable) << "test"; 199 DLOG_ASSERT(debug_only_variable) << "test";
200 DPLOG_IF(INFO, debug_only_variable) << "test"; 200 DPLOG_IF(INFO, debug_only_variable) << "test";
201 DVLOG_IF(1, debug_only_variable) << "test"; 201 DVLOG_IF(1, debug_only_variable) << "test";
202 } 202 }
203 203
204 TEST_F(LoggingTest, DcheckStreamsAreLazy) { 204 TEST_F(LoggingTest, DcheckStreamsAreLazy) {
205 MockLogSource mock_log_source; 205 MockLogSource mock_log_source;
206 EXPECT_CALL(mock_log_source, Log()).Times(0); 206 EXPECT_CALL(mock_log_source, Log()).Times(0);
207 if (DCHECK_IS_ON()) { 207 #if DCHECK_IS_ON
208 DCHECK(true) << mock_log_source.Log(); 208 DCHECK(true) << mock_log_source.Log();
209 DCHECK_EQ(0, 0) << mock_log_source.Log(); 209 DCHECK_EQ(0, 0) << mock_log_source.Log();
210 } else { 210 #else
211 DCHECK(mock_log_source.Log()) << mock_log_source.Log(); 211 DCHECK(mock_log_source.Log()) << mock_log_source.Log();
212 DPCHECK(mock_log_source.Log()) << mock_log_source.Log(); 212 DPCHECK(mock_log_source.Log()) << mock_log_source.Log();
213 DCHECK_EQ(0, 0) << mock_log_source.Log(); 213 DCHECK_EQ(0, 0) << mock_log_source.Log();
214 DCHECK_EQ(mock_log_source.Log(), static_cast<const char*>(NULL)) 214 DCHECK_EQ(mock_log_source.Log(), static_cast<const char*>(NULL))
215 << mock_log_source.Log(); 215 << mock_log_source.Log();
216 } 216 #endif
217 } 217 }
218 218
219 TEST_F(LoggingTest, Dcheck) { 219 TEST_F(LoggingTest, Dcheck) {
220 #if defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON) 220 #if defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON)
221 // Release build. 221 // Release build.
222 EXPECT_FALSE(DCHECK_IS_ON()); 222 EXPECT_FALSE(DCHECK_IS_ON);
223 EXPECT_FALSE(DLOG_IS_ON(DCHECK)); 223 EXPECT_FALSE(DLOG_IS_ON(DCHECK));
224 #elif defined(NDEBUG) && defined(DCHECK_ALWAYS_ON) 224 #elif defined(NDEBUG) && defined(DCHECK_ALWAYS_ON)
225 // Release build with real DCHECKS. 225 // Release build with real DCHECKS.
226 SetLogAssertHandler(&LogSink); 226 SetLogAssertHandler(&LogSink);
227 EXPECT_TRUE(DCHECK_IS_ON()); 227 EXPECT_TRUE(DCHECK_IS_ON);
228 EXPECT_FALSE(DLOG_IS_ON(DCHECK)); 228 EXPECT_FALSE(DLOG_IS_ON(DCHECK));
229 #else 229 #else
230 // Debug build. 230 // Debug build.
231 SetLogAssertHandler(&LogSink); 231 SetLogAssertHandler(&LogSink);
232 EXPECT_TRUE(DCHECK_IS_ON()); 232 EXPECT_TRUE(DCHECK_IS_ON);
233 EXPECT_TRUE(DLOG_IS_ON(DCHECK)); 233 EXPECT_TRUE(DLOG_IS_ON(DCHECK));
234 #endif 234 #endif
235 235
236 EXPECT_EQ(0, log_sink_call_count); 236 EXPECT_EQ(0, log_sink_call_count);
237 DCHECK(false); 237 DCHECK(false);
238 EXPECT_EQ(DCHECK_IS_ON() ? 1 : 0, log_sink_call_count); 238 EXPECT_EQ(DCHECK_IS_ON ? 1 : 0, log_sink_call_count);
239 DPCHECK(false); 239 DPCHECK(false);
240 EXPECT_EQ(DCHECK_IS_ON() ? 2 : 0, log_sink_call_count); 240 EXPECT_EQ(DCHECK_IS_ON ? 2 : 0, log_sink_call_count);
241 DCHECK_EQ(0, 1); 241 DCHECK_EQ(0, 1);
242 EXPECT_EQ(DCHECK_IS_ON() ? 3 : 0, log_sink_call_count); 242 EXPECT_EQ(DCHECK_IS_ON ? 3 : 0, log_sink_call_count);
243 } 243 }
244 244
245 TEST_F(LoggingTest, DcheckReleaseBehavior) { 245 TEST_F(LoggingTest, DcheckReleaseBehavior) {
246 int some_variable = 1; 246 int some_variable = 1;
247 // These should still reference |some_variable| so we don't get 247 // These should still reference |some_variable| so we don't get
248 // unused variable warnings. 248 // unused variable warnings.
249 DCHECK(some_variable) << "test"; 249 DCHECK(some_variable) << "test";
250 DPCHECK(some_variable) << "test"; 250 DPCHECK(some_variable) << "test";
251 DCHECK_EQ(some_variable, 1) << "test"; 251 DCHECK_EQ(some_variable, 1) << "test";
252 } 252 }
253 253
254 } // namespace 254 } // namespace
255 255
256 } // namespace logging 256 } // namespace logging
OLDNEW
« no previous file with comments | « base/logging.h ('k') | base/mac/mac_logging.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698