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

Side by Side Diff: components/proximity_auth/logging/logging_unittest.cc

Issue 2034393004: Allow multiple logging::LogMessage{Handler,Listener}s Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix installation_validator_unittest Created 4 years, 6 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
OLDNEW
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
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 { logging::PopLogMessageHandler(); }
51
52 private:
53 logging::LogMessageHandlerFunction previous_handler_;
54 }; 48 };
55 49
56 TEST_F(ProximityAuthLoggingTest, LogsSavedToBuffer) { 50 TEST_F(ProximityAuthLoggingTest, LogsSavedToBuffer) {
57 int base_line_number = __LINE__; 51 int base_line_number = __LINE__;
58 PA_LOG(INFO) << kLog1; 52 PA_LOG(INFO) << kLog1;
59 PA_LOG(WARNING) << kLog2; 53 PA_LOG(WARNING) << kLog2;
60 PA_LOG(ERROR) << kLog3; 54 PA_LOG(ERROR) << kLog3;
61 55
62 auto logs = LogBuffer::GetInstance()->logs(); 56 auto logs = LogBuffer::GetInstance()->logs();
63 ASSERT_EQ(3u, logs->size()); 57 ASSERT_EQ(3u, logs->size());
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 PA_LOG(WARNING) << kLog2; 104 PA_LOG(WARNING) << kLog2;
111 PA_LOG(ERROR) << kLog3; 105 PA_LOG(ERROR) << kLog3;
112 106
113 ASSERT_EQ(3u, g_standard_logs.Get().size()); 107 ASSERT_EQ(3u, g_standard_logs.Get().size());
114 EXPECT_NE(std::string::npos, g_standard_logs.Get()[0].find(kLog1)); 108 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)); 109 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)); 110 EXPECT_NE(std::string::npos, g_standard_logs.Get()[2].find(kLog3));
117 } 111 }
118 112
119 } // namespace proximity_auth 113 } // namespace proximity_auth
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698