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

Side by Side Diff: base/logging_unittest.cc

Issue 1193873004: Make CHECK_EQ and friends work properly in an if/else structure without braces. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Cut back test coverage. Created 5 years, 5 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') | 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/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 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 }
236 236
237 TEST_F(LoggingTest, DCheckEqStatements) {
238 bool reached = false;
239 if (false)
240 DCHECK_EQ(false, true); // Unreached.
241 else
242 DCHECK_EQ(true, reached = true); // Reached, passed.
243 ASSERT_EQ(DCHECK_IS_ON() ? true : false, reached);
244
245 if (false)
246 DCHECK_EQ(false, true); // Unreached.
247 }
248
249 TEST_F(LoggingTest, CheckEqStatements) {
250 bool reached = false;
251 if (false)
252 CHECK_EQ(false, true); // Unreached.
253 else
254 CHECK_EQ(true, reached = true); // Reached, passed.
255 ASSERT_TRUE(reached);
256
257 if (false)
258 CHECK_EQ(false, true); // Unreached.
259 }
260
237 // Test that defining an operator<< for a type in a namespace doesn't prevent 261 // Test that defining an operator<< for a type in a namespace doesn't prevent
238 // other code in that namespace from calling the operator<<(ostream, wstring) 262 // other code in that namespace from calling the operator<<(ostream, wstring)
239 // defined by logging.h. This can fail if operator<<(ostream, wstring) can't be 263 // defined by logging.h. This can fail if operator<<(ostream, wstring) can't be
240 // found by ADL, since defining another operator<< prevents name lookup from 264 // found by ADL, since defining another operator<< prevents name lookup from
241 // looking in the global namespace. 265 // looking in the global namespace.
242 namespace nested_test { 266 namespace nested_test {
243 class Streamable {}; 267 class Streamable {};
244 ALLOW_UNUSED_TYPE std::ostream& operator<<(std::ostream& out, 268 ALLOW_UNUSED_TYPE std::ostream& operator<<(std::ostream& out,
245 const Streamable&) { 269 const Streamable&) {
246 return out << "Streamable"; 270 return out << "Streamable";
247 } 271 }
248 TEST_F(LoggingTest, StreamingWstringFindsCorrectOperator) { 272 TEST_F(LoggingTest, StreamingWstringFindsCorrectOperator) {
249 std::wstring wstr = L"Hello World"; 273 std::wstring wstr = L"Hello World";
250 std::ostringstream ostr; 274 std::ostringstream ostr;
251 ostr << wstr; 275 ostr << wstr;
252 EXPECT_EQ("Hello World", ostr.str()); 276 EXPECT_EQ("Hello World", ostr.str());
253 } 277 }
254 } // namespace nested_test 278 } // namespace nested_test
255 279
256 } // namespace 280 } // namespace
257 281
258 } // namespace logging 282 } // namespace logging
OLDNEW
« no previous file with comments | « base/logging.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698