1 // Protocol Buffers - Google's data interchange format
2 // Copyright 2008 Google Inc.
3 // http://code.google.com/p/protobuf/
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
17 // Author: kenton@google.com (Kenton Varda)
18 // emulates google3/testing/base/public/googletest.h
20 #ifndef GOOGLE_PROTOBUF_GOOGLETEST_H__
21 #define GOOGLE_PROTOBUF_GOOGLETEST_H__
24 #include <google/protobuf/stubs/common.h>
29 // When running unittests, get the directory containing the source code.
30 string
TestSourceDir();
32 // When running unittests, get a directory where temporary files may be
36 // Capture all text written to stderr.
37 void CaptureTestStderr();
39 // Stop capturing stderr and return the text captured.
40 string
GetCapturedTestStderr();
42 // For use with ScopedMemoryLog::GetMessages(). Inside Google the LogLevel
43 // constants don't have the LOGLEVEL_ prefix, so the code that used
44 // ScopedMemoryLog refers to LOGLEVEL_ERROR as just ERROR.
45 static const LogLevel ERROR
= LOGLEVEL_ERROR
;
47 // Receives copies of all LOG(ERROR) messages while in scope. Sample usage:
49 // ScopedMemoryLog log; // constructor registers object as a log sink
50 // SomeRoutineThatMayLogMessages();
51 // const vector<string>& warnings = log.GetMessages(ERROR);
52 // } // destructor unregisters object as a log sink
53 // This is a dummy implementation which covers only what is used by protocol
55 class ScopedMemoryLog
{
58 virtual ~ScopedMemoryLog();
60 // Fetches all messages logged. The internal version of this class
61 // would only fetch messages at the given security level, but the protobuf
62 // open source version ignores the argument since we always pass ERROR
64 const vector
<string
>& GetMessages(LogLevel dummy
) const;
67 vector
<string
> messages_
;
68 LogHandler
* old_handler_
;
70 static void HandleLog(LogLevel level
, const char* filename
, int line
,
71 const string
& message
);
73 static ScopedMemoryLog
* active_log_
;
75 GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ScopedMemoryLog
);
78 } // namespace protobuf
81 #endif // GOOGLE_PROTOBUF_GOOGLETEST_H__