OLD | NEW |
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 Loading... |
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 |
OLD | NEW |