1fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// Protocol Buffers - Google's data interchange format 2fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// Copyright 2008 Google Inc. All rights reserved. 3fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// http://code.google.com/p/protobuf/ 4fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// 5fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// Redistribution and use in source and binary forms, with or without 6fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// modification, are permitted provided that the following conditions are 7fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// met: 8fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// 9fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// * Redistributions of source code must retain the above copyright 10fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// notice, this list of conditions and the following disclaimer. 11fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// * Redistributions in binary form must reproduce the above 12fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// copyright notice, this list of conditions and the following disclaimer 13fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// in the documentation and/or other materials provided with the 14fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// distribution. 15fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// * Neither the name of Google Inc. nor the names of its 16fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// contributors may be used to endorse or promote products derived from 17fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// this software without specific prior written permission. 18fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// 19fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville 31fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// Author: kenton@google.com (Kenton Varda) 32fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// emulates google3/testing/base/public/googletest.h 33fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville 34fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville#ifndef GOOGLE_PROTOBUF_GOOGLETEST_H__ 35fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville#define GOOGLE_PROTOBUF_GOOGLETEST_H__ 36fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville 37fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville#include <vector> 38fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville#include <google/protobuf/stubs/common.h> 39fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville 40fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Savillenamespace google { 41fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Savillenamespace protobuf { 42fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville 43fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// When running unittests, get the directory containing the source code. 44fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Savillestring TestSourceDir(); 45fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville 46fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// When running unittests, get a directory where temporary files may be 47fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// placed. 48fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Savillestring TestTempDir(); 49fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville 50fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// Capture all text written to stdout or stderr. 51fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Savillevoid CaptureTestStdout(); 52fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Savillevoid CaptureTestStderr(); 53fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville 54fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// Stop capturing stdout or stderr and return the text captured. 55fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Savillestring GetCapturedTestStdout(); 56fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Savillestring GetCapturedTestStderr(); 57fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville 58fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// For use with ScopedMemoryLog::GetMessages(). Inside Google the LogLevel 59fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// constants don't have the LOGLEVEL_ prefix, so the code that used 60fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// ScopedMemoryLog refers to LOGLEVEL_ERROR as just ERROR. 61fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville#undef ERROR // defend against promiscuous windows.h 62fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Savillestatic const LogLevel ERROR = LOGLEVEL_ERROR; 63fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville 64fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// Receives copies of all LOG(ERROR) messages while in scope. Sample usage: 65fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// { 66fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// ScopedMemoryLog log; // constructor registers object as a log sink 67fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// SomeRoutineThatMayLogMessages(); 68fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// const vector<string>& warnings = log.GetMessages(ERROR); 69fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// } // destructor unregisters object as a log sink 70fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// This is a dummy implementation which covers only what is used by protocol 71fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// buffer unit tests. 72fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Savilleclass ScopedMemoryLog { 73fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville public: 74fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville ScopedMemoryLog(); 75fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville virtual ~ScopedMemoryLog(); 76fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville 77fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville // Fetches all messages logged. The internal version of this class 78fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville // would only fetch messages at the given security level, but the protobuf 79fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville // open source version ignores the argument since we always pass ERROR 80fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville // anyway. 81fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville const vector<string>& GetMessages(LogLevel dummy) const; 82fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville 83fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville private: 84fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville vector<string> messages_; 85fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville LogHandler* old_handler_; 86fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville 87fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville static void HandleLog(LogLevel level, const char* filename, int line, 88fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville const string& message); 89fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville 90fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville static ScopedMemoryLog* active_log_; 91fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville 92fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ScopedMemoryLog); 93fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville}; 94fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville 95fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville} // namespace protobuf 96fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville} // namespace google 97fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville 98fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville#endif // GOOGLE_PROTOBUF_GOOGLETEST_H__ 99