| OLD | NEW |
| 1 // Protocol Buffers - Google's data interchange format | 1 // Protocol Buffers - Google's data interchange format |
| 2 // Copyright 2008 Google Inc. All rights reserved. | 2 // Copyright 2008 Google Inc. All rights reserved. |
| 3 // http://code.google.com/p/protobuf/ | 3 // http://code.google.com/p/protobuf/ |
| 4 // | 4 // |
| 5 // Redistribution and use in source and binary forms, with or without | 5 // Redistribution and use in source and binary forms, with or without |
| 6 // modification, are permitted provided that the following conditions are | 6 // modification, are permitted provided that the following conditions are |
| 7 // met: | 7 // met: |
| 8 // | 8 // |
| 9 // * Redistributions of source code must retain the above copyright | 9 // * Redistributions of source code must retain the above copyright |
| 10 // notice, this list of conditions and the following disclaimer. | 10 // notice, this list of conditions and the following disclaimer. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 27 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 28 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 28 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 29 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 29 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 30 | 30 |
| 31 // Author: kenton@google.com (Kenton Varda) | 31 // Author: kenton@google.com (Kenton Varda) |
| 32 // emulates google3/testing/base/public/googletest.h | 32 // emulates google3/testing/base/public/googletest.h |
| 33 | 33 |
| 34 #ifndef GOOGLE_PROTOBUF_GOOGLETEST_H__ | 34 #ifndef GOOGLE_PROTOBUF_GOOGLETEST_H__ |
| 35 #define GOOGLE_PROTOBUF_GOOGLETEST_H__ | 35 #define GOOGLE_PROTOBUF_GOOGLETEST_H__ |
| 36 | 36 |
| 37 #include <map> |
| 37 #include <vector> | 38 #include <vector> |
| 38 #include <google/protobuf/stubs/common.h> | 39 #include <google/protobuf/stubs/common.h> |
| 39 | 40 |
| 40 namespace google { | 41 namespace google { |
| 41 namespace protobuf { | 42 namespace protobuf { |
| 42 | 43 |
| 43 // When running unittests, get the directory containing the source code. | 44 // When running unittests, get the directory containing the source code. |
| 44 string TestSourceDir(); | 45 string TestSourceDir(); |
| 45 | 46 |
| 46 // When running unittests, get a directory where temporary files may be | 47 // When running unittests, get a directory where temporary files may be |
| 47 // placed. | 48 // placed. |
| 48 string TestTempDir(); | 49 string TestTempDir(); |
| 49 | 50 |
| 50 // Capture all text written to stdout or stderr. | 51 // Capture all text written to stdout or stderr. |
| 51 void CaptureTestStdout(); | 52 void CaptureTestStdout(); |
| 52 void CaptureTestStderr(); | 53 void CaptureTestStderr(); |
| 53 | 54 |
| 54 // Stop capturing stdout or stderr and return the text captured. | 55 // Stop capturing stdout or stderr and return the text captured. |
| 55 string GetCapturedTestStdout(); | 56 string GetCapturedTestStdout(); |
| 56 string GetCapturedTestStderr(); | 57 string GetCapturedTestStderr(); |
| 57 | 58 |
| 58 // For use with ScopedMemoryLog::GetMessages(). Inside Google the LogLevel | 59 // For use with ScopedMemoryLog::GetMessages(). Inside Google the LogLevel |
| 59 // constants don't have the LOGLEVEL_ prefix, so the code that used | 60 // constants don't have the LOGLEVEL_ prefix, so the code that used |
| 60 // ScopedMemoryLog refers to LOGLEVEL_ERROR as just ERROR. | 61 // ScopedMemoryLog refers to LOGLEVEL_ERROR as just ERROR. |
| 61 #undef ERROR // defend against promiscuous windows.h | 62 #undef ERROR // defend against promiscuous windows.h |
| 62 static const LogLevel ERROR = LOGLEVEL_ERROR; | 63 static const LogLevel ERROR = LOGLEVEL_ERROR; |
| 64 static const LogLevel WARNING = LOGLEVEL_WARNING; |
| 63 | 65 |
| 64 // Receives copies of all LOG(ERROR) messages while in scope. Sample usage: | 66 // Receives copies of all LOG(ERROR) messages while in scope. Sample usage: |
| 65 // { | 67 // { |
| 66 // ScopedMemoryLog log; // constructor registers object as a log sink | 68 // ScopedMemoryLog log; // constructor registers object as a log sink |
| 67 // SomeRoutineThatMayLogMessages(); | 69 // SomeRoutineThatMayLogMessages(); |
| 68 // const vector<string>& warnings = log.GetMessages(ERROR); | 70 // const vector<string>& warnings = log.GetMessages(ERROR); |
| 69 // } // destructor unregisters object as a log sink | 71 // } // destructor unregisters object as a log sink |
| 70 // This is a dummy implementation which covers only what is used by protocol | 72 // This is a dummy implementation which covers only what is used by protocol |
| 71 // buffer unit tests. | 73 // buffer unit tests. |
| 72 class ScopedMemoryLog { | 74 class ScopedMemoryLog { |
| 73 public: | 75 public: |
| 74 ScopedMemoryLog(); | 76 ScopedMemoryLog(); |
| 75 virtual ~ScopedMemoryLog(); | 77 virtual ~ScopedMemoryLog(); |
| 76 | 78 |
| 77 // Fetches all messages logged. The internal version of this class | 79 // Fetches all messages with the given severity level. |
| 78 // would only fetch messages at the given security level, but the protobuf | 80 const vector<string>& GetMessages(LogLevel error); |
| 79 // open source version ignores the argument since we always pass ERROR | |
| 80 // anyway. | |
| 81 const vector<string>& GetMessages(LogLevel dummy) const; | |
| 82 | 81 |
| 83 private: | 82 private: |
| 84 vector<string> messages_; | 83 map<LogLevel, vector<string> > messages_; |
| 85 LogHandler* old_handler_; | 84 LogHandler* old_handler_; |
| 86 | 85 |
| 87 static void HandleLog(LogLevel level, const char* filename, int line, | 86 static void HandleLog(LogLevel level, const char* filename, int line, |
| 88 const string& message); | 87 const string& message); |
| 89 | 88 |
| 90 static ScopedMemoryLog* active_log_; | 89 static ScopedMemoryLog* active_log_; |
| 91 | 90 |
| 92 GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ScopedMemoryLog); | 91 GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ScopedMemoryLog); |
| 93 }; | 92 }; |
| 94 | 93 |
| 95 } // namespace protobuf | 94 } // namespace protobuf |
| 96 } // namespace google | 95 } // namespace google |
| 97 | 96 |
| 98 #endif // GOOGLE_PROTOBUF_GOOGLETEST_H__ | 97 #endif // GOOGLE_PROTOBUF_GOOGLETEST_H__ |
| OLD | NEW |