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 #ifndef BASE_TEST_MOCK_LOG_H_ | 5 #ifndef BASE_TEST_MOCK_LOG_H_ |
6 #define BASE_TEST_MOCK_LOG_H_ | 6 #define BASE_TEST_MOCK_LOG_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
10 #include <string> | 10 #include <string> |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 ~MockLog(); | 53 ~MockLog(); |
54 | 54 |
55 // Starts log capturing if the object isn't already doing so. | 55 // Starts log capturing if the object isn't already doing so. |
56 // Otherwise crashes. | 56 // Otherwise crashes. |
57 void StartCapturingLogs(); | 57 void StartCapturingLogs(); |
58 | 58 |
59 // Stops log capturing if the object is capturing logs. Otherwise crashes. | 59 // Stops log capturing if the object is capturing logs. Otherwise crashes. |
60 void StopCapturingLogs(); | 60 void StopCapturingLogs(); |
61 | 61 |
62 // Log method is invoked for every log message before it's sent to other log | 62 // Log method is invoked for every log message before it's sent to other log |
63 // destinations (if any). The method should return true to signal that it | 63 // destinations (if any). |
64 // handled the message and the message should not be sent to other log | |
65 // destinations. | |
66 MOCK_METHOD5(Log, | 64 MOCK_METHOD5(Log, |
67 bool(int severity, | 65 void(int severity, |
68 const char* file, | 66 const char* file, |
69 int line, | 67 int line, |
70 size_t message_start, | 68 size_t message_start, |
71 const std::string& str)); | 69 const std::string& str)); |
72 | 70 |
73 private: | 71 private: |
74 // The currently active mock log. | 72 // The currently active mock log. |
75 static MockLog* g_instance_; | 73 static MockLog* g_instance_; |
76 | 74 |
77 // Lock protecting access to g_instance_. | 75 // Lock protecting access to g_instance_. |
78 static Lock g_lock; | 76 static Lock g_lock; |
79 | 77 |
80 // Static function which is set as the logging message handler. | 78 // Static function which is set as the logging message listener. |
81 // Called once for each message. | 79 // Called once for each message. |
82 static bool LogMessageHandler(int severity, | 80 static void LogMessageListener(int severity, |
83 const char* file, | 81 const char* file, |
84 int line, | 82 int line, |
85 size_t message_start, | 83 size_t message_start, |
86 const std::string& str); | 84 const std::string& str); |
87 | 85 |
88 // True if this object is currently capturing logs. | 86 // True if this object is currently capturing logs. |
89 bool is_capturing_logs_; | 87 bool is_capturing_logs_; |
90 | 88 |
91 // The previous handler to restore when the MockLog is destroyed. | |
92 logging::LogMessageHandlerFunction previous_handler_; | |
93 | |
94 DISALLOW_COPY_AND_ASSIGN(MockLog); | 89 DISALLOW_COPY_AND_ASSIGN(MockLog); |
95 }; | 90 }; |
96 | 91 |
97 } // namespace test | 92 } // namespace test |
98 } // namespace base | 93 } // namespace base |
99 | 94 |
100 #endif // BASE_TEST_MOCK_LOG_H_ | 95 #endif // BASE_TEST_MOCK_LOG_H_ |
OLD | NEW |