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

Side by Side Diff: base/logging_unittest.cc

Issue 66213008: Try to fix build more after r234081 / r234112. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | 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 (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
11 namespace logging { 11 namespace logging {
12 12
13 namespace { 13 namespace {
14 14
15 using ::testing::Return; 15 using ::testing::Return;
16 16
17 // Needs to be global since log assert handlers can't maintain state. 17 // Needs to be global since log assert handlers can't maintain state.
18 int log_sink_call_count = 0; 18 int log_sink_call_count = 0;
19 19
20 #if !defined(LOGGING_IS_OFFICIAL_BUILD) 20 #if !LOGGING_IS_OFFICIAL_BUILD
21 void LogSink(const std::string& str) { 21 void LogSink(const std::string& str) {
22 ++log_sink_call_count; 22 ++log_sink_call_count;
23 } 23 }
24 #endif // !defined(LOGGING_IS_OFFICIAL_BUILD) 24 #endif // !LOGGING_IS_OFFICIAL_BUILD
25 25
26 // Class to make sure any manipulations we do to the min log level are 26 // Class to make sure any manipulations we do to the min log level are
27 // contained (i.e., do not affect other unit tests). 27 // contained (i.e., do not affect other unit tests).
28 class LogStateSaver { 28 class LogStateSaver {
29 public: 29 public:
30 LogStateSaver() : old_min_log_level_(GetMinLogLevel()) {} 30 LogStateSaver() : old_min_log_level_(GetMinLogLevel()) {}
31 31
32 ~LogStateSaver() { 32 ~LogStateSaver() {
33 SetMinLogLevel(old_min_log_level_); 33 SetMinLogLevel(old_min_log_level_);
34 SetLogAssertHandler(NULL); 34 SetLogAssertHandler(NULL);
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 162
163 DLOG(INFO) << mock_log_source.Log(); 163 DLOG(INFO) << mock_log_source.Log();
164 DLOG_IF(INFO, true) << mock_log_source.Log(); 164 DLOG_IF(INFO, true) << mock_log_source.Log();
165 DPLOG(INFO) << mock_log_source.Log(); 165 DPLOG(INFO) << mock_log_source.Log();
166 DPLOG_IF(INFO, true) << mock_log_source.Log(); 166 DPLOG_IF(INFO, true) << mock_log_source.Log();
167 DVLOG(1) << mock_log_source.Log(); 167 DVLOG(1) << mock_log_source.Log();
168 DVLOG_IF(1, true) << mock_log_source.Log(); 168 DVLOG_IF(1, true) << mock_log_source.Log();
169 } 169 }
170 170
171 // Official builds have CHECKs directly call BreakDebugger. 171 // Official builds have CHECKs directly call BreakDebugger.
172 #if !defined(LOGGING_IS_OFFICIAL_BUILD) 172 #if !LOGGING_IS_OFFICIAL_BUILD
173 173
174 TEST_F(LoggingTest, CheckStreamsAreLazy) { 174 TEST_F(LoggingTest, CheckStreamsAreLazy) {
175 MockLogSource mock_log_source, uncalled_mock_log_source; 175 MockLogSource mock_log_source, uncalled_mock_log_source;
176 EXPECT_CALL(mock_log_source, Log()).Times(8). 176 EXPECT_CALL(mock_log_source, Log()).Times(8).
177 WillRepeatedly(Return("check message")); 177 WillRepeatedly(Return("check message"));
178 EXPECT_CALL(uncalled_mock_log_source, Log()).Times(0); 178 EXPECT_CALL(uncalled_mock_log_source, Log()).Times(0);
179 179
180 SetLogAssertHandler(&LogSink); 180 SetLogAssertHandler(&LogSink);
181 181
182 CHECK(mock_log_source.Log()) << uncalled_mock_log_source.Log(); 182 CHECK(mock_log_source.Log()) << uncalled_mock_log_source.Log();
(...skipping 14 matching lines...) Expand all
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 !defined(LOGGING_IS_OFFICIAL_BUILD) && defined(NDEBUG) && \ 207 #if !LOGGING_IS_OFFICIAL_BUILD && defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON)
208 !defined(DCHECK_ALWAYS_ON)
209 // Unofficial release build without dcheck enabled. 208 // Unofficial release build without dcheck enabled.
210 set_dcheck_state(DISABLE_DCHECK_FOR_NON_OFFICIAL_RELEASE_BUILDS); 209 set_dcheck_state(DISABLE_DCHECK_FOR_NON_OFFICIAL_RELEASE_BUILDS);
211 DCHECK(mock_log_source.Log()) << mock_log_source.Log(); 210 DCHECK(mock_log_source.Log()) << mock_log_source.Log();
212 DPCHECK(mock_log_source.Log()) << mock_log_source.Log(); 211 DPCHECK(mock_log_source.Log()) << mock_log_source.Log();
213 DCHECK_EQ(0, 0) << mock_log_source.Log(); 212 DCHECK_EQ(0, 0) << mock_log_source.Log();
214 DCHECK_EQ(mock_log_source.Log(), static_cast<const char*>(NULL)) 213 DCHECK_EQ(mock_log_source.Log(), static_cast<const char*>(NULL))
215 << mock_log_source.Log(); 214 << mock_log_source.Log();
216 #endif 215 #endif
217 } 216 }
218 217
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 // These should still reference |some_variable| so we don't get 253 // These should still reference |some_variable| so we don't get
255 // unused variable warnings. 254 // unused variable warnings.
256 DCHECK(some_variable) << "test"; 255 DCHECK(some_variable) << "test";
257 DPCHECK(some_variable) << "test"; 256 DPCHECK(some_variable) << "test";
258 DCHECK_EQ(some_variable, 1) << "test"; 257 DCHECK_EQ(some_variable, 1) << "test";
259 } 258 }
260 259
261 } // namespace 260 } // namespace
262 261
263 } // namespace logging 262 } // namespace logging
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698