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/logging.h" |
| 6 |
| 7 #include <sstream> |
| 8 |
5 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
6 #include "base/logging.h" | |
7 #include "base/macros.h" | 10 #include "base/macros.h" |
8 | 11 |
9 #include "testing/gmock/include/gmock/gmock.h" | 12 #include "testing/gmock/include/gmock/gmock.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
11 | 14 |
12 namespace logging { | 15 namespace logging { |
13 | 16 |
14 namespace { | 17 namespace { |
15 | 18 |
16 using ::testing::Return; | 19 using ::testing::Return; |
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
269 if (false) | 272 if (false) |
270 CHECK_EQ(false, true); // Unreached. | 273 CHECK_EQ(false, true); // Unreached. |
271 else | 274 else |
272 CHECK_EQ(true, reached = true); // Reached, passed. | 275 CHECK_EQ(true, reached = true); // Reached, passed. |
273 ASSERT_TRUE(reached); | 276 ASSERT_TRUE(reached); |
274 | 277 |
275 if (false) | 278 if (false) |
276 CHECK_EQ(false, true); // Unreached. | 279 CHECK_EQ(false, true); // Unreached. |
277 } | 280 } |
278 | 281 |
| 282 // Test that scoped enums can be logged. |
| 283 TEST_F(LoggingTest, ScopedEnum) { |
| 284 #if 0 |
| 285 std::ostringstream ss1; |
| 286 // Default underlying type is int. |
| 287 enum class SignedTestEnum { |
| 288 Value = -1, |
| 289 }; |
| 290 ss1 << SignedTestEnum::Value; |
| 291 EXPECT_EQ("-1", ss1.str()); |
| 292 |
| 293 std::ostringstream ss2; |
| 294 enum class UnsignedTestEnum : unsigned { |
| 295 Value = -1, // This is intentional. |
| 296 }; |
| 297 ss2 << UnsignedTestEnum::Value; |
| 298 EXPECT_EQ("0xffffffff", ss2.str()); |
| 299 #endif |
| 300 } |
| 301 |
279 // Test that defining an operator<< for a type in a namespace doesn't prevent | 302 // Test that defining an operator<< for a type in a namespace doesn't prevent |
280 // other code in that namespace from calling the operator<<(ostream, wstring) | 303 // other code in that namespace from calling the operator<<(ostream, wstring) |
281 // defined by logging.h. This can fail if operator<<(ostream, wstring) can't be | 304 // defined by logging.h. This can fail if operator<<(ostream, wstring) can't be |
282 // found by ADL, since defining another operator<< prevents name lookup from | 305 // found by ADL, since defining another operator<< prevents name lookup from |
283 // looking in the global namespace. | 306 // looking in the global namespace. |
284 namespace nested_test { | 307 namespace nested_test { |
285 class Streamable {}; | 308 class Streamable {}; |
286 ALLOW_UNUSED_TYPE std::ostream& operator<<(std::ostream& out, | 309 ALLOW_UNUSED_TYPE std::ostream& operator<<(std::ostream& out, |
287 const Streamable&) { | 310 const Streamable&) { |
288 return out << "Streamable"; | 311 return out << "Streamable"; |
289 } | 312 } |
290 TEST_F(LoggingTest, StreamingWstringFindsCorrectOperator) { | 313 TEST_F(LoggingTest, StreamingWstringFindsCorrectOperator) { |
291 std::wstring wstr = L"Hello World"; | 314 std::wstring wstr = L"Hello World"; |
292 std::ostringstream ostr; | 315 std::ostringstream ostr; |
293 ostr << wstr; | 316 ostr << wstr; |
294 EXPECT_EQ("Hello World", ostr.str()); | 317 EXPECT_EQ("Hello World", ostr.str()); |
295 } | 318 } |
296 } // namespace nested_test | 319 } // namespace nested_test |
297 | 320 |
298 } // namespace | 321 } // namespace |
299 | 322 |
300 } // namespace logging | 323 } // namespace logging |
OLD | NEW |