| 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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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). The method should return true to signal that it |
| 64 // handled the message and the message should not be sent to other log | 64 // handled the message and the message should not be sent to other log |
| 65 // destinations. | 65 // destinations. |
| 66 MOCK_METHOD5(Log, | 66 MOCK_METHOD4(Log, |
| 67 bool(int severity, | 67 bool(int severity, |
| 68 const char* file, | 68 const std::string& file, |
| 69 int line, | 69 int line, |
| 70 size_t message_start, | |
| 71 const std::string& str)); | 70 const std::string& str)); |
| 72 | 71 |
| 73 private: | 72 private: |
| 74 // The currently active mock log. | 73 // The currently active mock log. |
| 75 static MockLog* g_instance_; | 74 static MockLog* g_instance_; |
| 76 | 75 |
| 77 // Lock protecting access to g_instance_. | 76 // Lock protecting access to g_instance_. |
| 78 static Lock g_lock; | 77 static Lock g_lock; |
| 79 | 78 |
| 80 // Static function which is set as the logging message handler. | 79 // Static function which is set as the logging message handler. |
| 81 // Called once for each message. | 80 // Called once for each message. |
| 82 static bool LogMessageHandler(int severity, | 81 static bool LogMessageHandler(int severity, |
| 83 const char* file, | 82 const std::string& file, |
| 84 int line, | 83 int line, |
| 85 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 |