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

Side by Side Diff: base/logging_unittest.cc

Issue 851503003: Update from https://crrev.com/311076 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 11 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
« no previous file with comments | « base/logging.h ('k') | base/mac/foundation_util.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/compiler_specific.h" 6 #include "base/compiler_specific.h"
7 #include "base/logging.h" 7 #include "base/logging.h"
8 8
9 #include "testing/gmock/include/gmock/gmock.h" 9 #include "testing/gmock/include/gmock/gmock.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 // in release mode. 180 // in release mode.
181 DLOG_IF(INFO, debug_only_variable) << "test"; 181 DLOG_IF(INFO, debug_only_variable) << "test";
182 DLOG_ASSERT(debug_only_variable) << "test"; 182 DLOG_ASSERT(debug_only_variable) << "test";
183 DPLOG_IF(INFO, debug_only_variable) << "test"; 183 DPLOG_IF(INFO, debug_only_variable) << "test";
184 DVLOG_IF(1, debug_only_variable) << "test"; 184 DVLOG_IF(1, debug_only_variable) << "test";
185 } 185 }
186 186
187 TEST_F(LoggingTest, DcheckStreamsAreLazy) { 187 TEST_F(LoggingTest, DcheckStreamsAreLazy) {
188 MockLogSource mock_log_source; 188 MockLogSource mock_log_source;
189 EXPECT_CALL(mock_log_source, Log()).Times(0); 189 EXPECT_CALL(mock_log_source, Log()).Times(0);
190 #if DCHECK_IS_ON 190 #if DCHECK_IS_ON()
191 DCHECK(true) << mock_log_source.Log(); 191 DCHECK(true) << mock_log_source.Log();
192 DCHECK_EQ(0, 0) << mock_log_source.Log(); 192 DCHECK_EQ(0, 0) << mock_log_source.Log();
193 #else 193 #else
194 DCHECK(mock_log_source.Log()) << mock_log_source.Log(); 194 DCHECK(mock_log_source.Log()) << mock_log_source.Log();
195 DPCHECK(mock_log_source.Log()) << mock_log_source.Log(); 195 DPCHECK(mock_log_source.Log()) << mock_log_source.Log();
196 DCHECK_EQ(0, 0) << mock_log_source.Log(); 196 DCHECK_EQ(0, 0) << mock_log_source.Log();
197 DCHECK_EQ(mock_log_source.Log(), static_cast<const char*>(NULL)) 197 DCHECK_EQ(mock_log_source.Log(), static_cast<const char*>(NULL))
198 << mock_log_source.Log(); 198 << mock_log_source.Log();
199 #endif 199 #endif
200 } 200 }
201 201
202 TEST_F(LoggingTest, Dcheck) { 202 TEST_F(LoggingTest, Dcheck) {
203 #if defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON) 203 #if defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON)
204 // Release build. 204 // Release build.
205 EXPECT_FALSE(DCHECK_IS_ON); 205 EXPECT_FALSE(DCHECK_IS_ON());
206 EXPECT_FALSE(DLOG_IS_ON(DCHECK)); 206 EXPECT_FALSE(DLOG_IS_ON(DCHECK));
207 #elif defined(NDEBUG) && defined(DCHECK_ALWAYS_ON) 207 #elif defined(NDEBUG) && defined(DCHECK_ALWAYS_ON)
208 // Release build with real DCHECKS. 208 // Release build with real DCHECKS.
209 SetLogAssertHandler(&LogSink); 209 SetLogAssertHandler(&LogSink);
210 EXPECT_TRUE(DCHECK_IS_ON); 210 EXPECT_TRUE(DCHECK_IS_ON());
211 EXPECT_FALSE(DLOG_IS_ON(DCHECK)); 211 EXPECT_FALSE(DLOG_IS_ON(DCHECK));
212 #else 212 #else
213 // Debug build. 213 // Debug build.
214 SetLogAssertHandler(&LogSink); 214 SetLogAssertHandler(&LogSink);
215 EXPECT_TRUE(DCHECK_IS_ON); 215 EXPECT_TRUE(DCHECK_IS_ON());
216 EXPECT_TRUE(DLOG_IS_ON(DCHECK)); 216 EXPECT_TRUE(DLOG_IS_ON(DCHECK));
217 #endif 217 #endif
218 218
219 EXPECT_EQ(0, log_sink_call_count); 219 EXPECT_EQ(0, log_sink_call_count);
220 DCHECK(false); 220 DCHECK(false);
221 EXPECT_EQ(DCHECK_IS_ON ? 1 : 0, log_sink_call_count); 221 EXPECT_EQ(DCHECK_IS_ON() ? 1 : 0, log_sink_call_count);
222 DPCHECK(false); 222 DPCHECK(false);
223 EXPECT_EQ(DCHECK_IS_ON ? 2 : 0, log_sink_call_count); 223 EXPECT_EQ(DCHECK_IS_ON() ? 2 : 0, log_sink_call_count);
224 DCHECK_EQ(0, 1); 224 DCHECK_EQ(0, 1);
225 EXPECT_EQ(DCHECK_IS_ON ? 3 : 0, log_sink_call_count); 225 EXPECT_EQ(DCHECK_IS_ON() ? 3 : 0, log_sink_call_count);
226 } 226 }
227 227
228 TEST_F(LoggingTest, DcheckReleaseBehavior) { 228 TEST_F(LoggingTest, DcheckReleaseBehavior) {
229 int some_variable = 1; 229 int some_variable = 1;
230 // These should still reference |some_variable| so we don't get 230 // These should still reference |some_variable| so we don't get
231 // unused variable warnings. 231 // unused variable warnings.
232 DCHECK(some_variable) << "test"; 232 DCHECK(some_variable) << "test";
233 DPCHECK(some_variable) << "test"; 233 DPCHECK(some_variable) << "test";
234 DCHECK_EQ(some_variable, 1) << "test"; 234 DCHECK_EQ(some_variable, 1) << "test";
235 } 235 }
(...skipping 13 matching lines...) Expand all
249 std::wstring wstr = L"Hello World"; 249 std::wstring wstr = L"Hello World";
250 std::ostringstream ostr; 250 std::ostringstream ostr;
251 ostr << wstr; 251 ostr << wstr;
252 EXPECT_EQ("Hello World", ostr.str()); 252 EXPECT_EQ("Hello World", ostr.str());
253 } 253 }
254 } // namespace nested_test 254 } // namespace nested_test
255 255
256 } // namespace 256 } // namespace
257 257
258 } // namespace logging 258 } // namespace logging
OLDNEW
« no previous file with comments | « base/logging.h ('k') | base/mac/foundation_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698