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

Unified Diff: base/test/mock_log.h

Issue 2034393004: Allow multiple logging::LogMessage{Handler,Listener}s Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: only keep scoped API Created 4 years, 5 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 side-by-side diff with in-line comments
Download patch
Index: base/test/mock_log.h
diff --git a/base/test/mock_log.h b/base/test/mock_log.h
index cda2fcd6259cbf080ba1bdc0c4195c00a12d69be..adac25e494d9d0e34ab16c2f9af305911a08f42d 100644
--- a/base/test/mock_log.h
+++ b/base/test/mock_log.h
@@ -7,6 +7,7 @@
#include <stddef.h>
+#include <memory>
#include <string>
#include "base/logging.h"
@@ -17,6 +18,8 @@
namespace base {
namespace test {
+class MockLogMessageListener;
+
// A MockLog object intercepts LOG() messages issued during its lifespan. Using
// this together with gMock, it's very easy to test how a piece of code calls
// LOG(). The typical usage:
@@ -60,37 +63,20 @@ class MockLog {
void StopCapturingLogs();
// Log method is invoked for every log message before it's sent to other log
- // destinations (if any). The method should return true to signal that it
- // handled the message and the message should not be sent to other log
- // destinations.
+ // destinations (if any).
MOCK_METHOD5(Log,
- bool(int severity,
+ void(int severity,
const char* file,
int line,
size_t message_start,
const std::string& str));
private:
- // The currently active mock log.
- static MockLog* g_instance_;
-
- // Lock protecting access to g_instance_.
- static Lock g_lock;
-
- // Static function which is set as the logging message handler.
- // Called once for each message.
- static bool LogMessageHandler(int severity,
- const char* file,
- int line,
- size_t message_start,
- const std::string& str);
+ std::unique_ptr<MockLogMessageListener> listener_;
// True if this object is currently capturing logs.
bool is_capturing_logs_;
- // The previous handler to restore when the MockLog is destroyed.
- logging::LogMessageHandlerFunction previous_handler_;
-
DISALLOW_COPY_AND_ASSIGN(MockLog);
};
« base/logging_win.cc ('K') | « base/logging_win.cc ('k') | base/test/mock_log.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698