| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "components/proximity_auth/logging/logging.h" | 5 #include "components/proximity_auth/logging/logging.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
| 10 #include "base/numerics/safe_conversions.h" | 10 #include "base/numerics/safe_conversions.h" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 size_t message_start, | 30 size_t message_start, |
| 31 const std::string& str) { | 31 const std::string& str) { |
| 32 g_standard_logs.Get().push_back(str); | 32 g_standard_logs.Get().push_back(str); |
| 33 return true; | 33 return true; |
| 34 } | 34 } |
| 35 | 35 |
| 36 } // namespace | 36 } // namespace |
| 37 | 37 |
| 38 class ProximityAuthLoggingTest : public testing::Test { | 38 class ProximityAuthLoggingTest : public testing::Test { |
| 39 public: | 39 public: |
| 40 ProximityAuthLoggingTest() : previous_handler_(NULL) {} | |
| 41 | |
| 42 void SetUp() override { | 40 void SetUp() override { |
| 43 LogBuffer::GetInstance()->Clear(); | 41 LogBuffer::GetInstance()->Clear(); |
| 44 g_standard_logs.Get().clear(); | 42 g_standard_logs.Get().clear(); |
| 45 | 43 |
| 46 previous_handler_ = logging::GetLogMessageHandler(); | 44 logging::PushLogMessageHandler(HandleStandardLogMessage); |
| 47 logging::SetLogMessageHandler(&HandleStandardLogMessage); | |
| 48 } | 45 } |
| 49 | 46 |
| 50 void TearDown() override { logging::SetLogMessageHandler(previous_handler_); } | 47 void TearDown() override { |
| 51 | 48 logging::PopLogMessageHandler(HandleStandardLogMessage); |
| 52 private: | 49 } |
| 53 logging::LogMessageHandlerFunction previous_handler_; | |
| 54 }; | 50 }; |
| 55 | 51 |
| 56 TEST_F(ProximityAuthLoggingTest, LogsSavedToBuffer) { | 52 TEST_F(ProximityAuthLoggingTest, LogsSavedToBuffer) { |
| 57 int base_line_number = __LINE__; | 53 int base_line_number = __LINE__; |
| 58 PA_LOG(INFO) << kLog1; | 54 PA_LOG(INFO) << kLog1; |
| 59 PA_LOG(WARNING) << kLog2; | 55 PA_LOG(WARNING) << kLog2; |
| 60 PA_LOG(ERROR) << kLog3; | 56 PA_LOG(ERROR) << kLog3; |
| 61 | 57 |
| 62 auto logs = LogBuffer::GetInstance()->logs(); | 58 auto logs = LogBuffer::GetInstance()->logs(); |
| 63 ASSERT_EQ(3u, logs->size()); | 59 ASSERT_EQ(3u, logs->size()); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 PA_LOG(WARNING) << kLog2; | 106 PA_LOG(WARNING) << kLog2; |
| 111 PA_LOG(ERROR) << kLog3; | 107 PA_LOG(ERROR) << kLog3; |
| 112 | 108 |
| 113 ASSERT_EQ(3u, g_standard_logs.Get().size()); | 109 ASSERT_EQ(3u, g_standard_logs.Get().size()); |
| 114 EXPECT_NE(std::string::npos, g_standard_logs.Get()[0].find(kLog1)); | 110 EXPECT_NE(std::string::npos, g_standard_logs.Get()[0].find(kLog1)); |
| 115 EXPECT_NE(std::string::npos, g_standard_logs.Get()[1].find(kLog2)); | 111 EXPECT_NE(std::string::npos, g_standard_logs.Get()[1].find(kLog2)); |
| 116 EXPECT_NE(std::string::npos, g_standard_logs.Get()[2].find(kLog3)); | 112 EXPECT_NE(std::string::npos, g_standard_logs.Get()[2].find(kLog3)); |
| 117 } | 113 } |
| 118 | 114 |
| 119 } // namespace proximity_auth | 115 } // namespace proximity_auth |
| OLD | NEW |