aboutsummaryrefslogtreecommitdiff
path: root/NorthstarDedicatedTest/include/protobuf/testing
diff options
context:
space:
mode:
Diffstat (limited to 'NorthstarDedicatedTest/include/protobuf/testing')
-rw-r--r--NorthstarDedicatedTest/include/protobuf/testing/file.cc215
-rw-r--r--NorthstarDedicatedTest/include/protobuf/testing/file.h107
-rw-r--r--NorthstarDedicatedTest/include/protobuf/testing/googletest.cc302
-rw-r--r--NorthstarDedicatedTest/include/protobuf/testing/googletest.h104
-rw-r--r--NorthstarDedicatedTest/include/protobuf/testing/zcgunzip.cc84
-rw-r--r--NorthstarDedicatedTest/include/protobuf/testing/zcgzip.cc87
6 files changed, 899 insertions, 0 deletions
diff --git a/NorthstarDedicatedTest/include/protobuf/testing/file.cc b/NorthstarDedicatedTest/include/protobuf/testing/file.cc
new file mode 100644
index 00000000..f904028f
--- /dev/null
+++ b/NorthstarDedicatedTest/include/protobuf/testing/file.cc
@@ -0,0 +1,215 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+// Author: kenton@google.com (Kenton Varda)
+// emulates google3/file/base/file.cc
+
+#include <testing/file.h>
+#include <stdio.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#ifdef _MSC_VER
+#define WIN32_LEAN_AND_MEAN // yeah, right
+#include <windows.h> // Find*File(). :(
+// #include <direct.h>
+#else
+#include <dirent.h>
+#include <unistd.h>
+#endif
+#include <errno.h>
+
+#include <io/io_win32.h>
+#include <stubs/logging.h>
+
+namespace google {
+namespace protobuf {
+
+#ifdef _WIN32
+// Windows doesn't have symbolic links.
+#define lstat stat
+// DO NOT include <io.h>, instead create functions in io_win32.{h,cc} and import
+// them like we do below.
+#endif
+
+#ifdef _WIN32
+using google::protobuf::io::win32::access;
+using google::protobuf::io::win32::chdir;
+using google::protobuf::io::win32::fopen;
+using google::protobuf::io::win32::mkdir;
+using google::protobuf::io::win32::stat;
+#endif
+
+bool File::Exists(const std::string& name) {
+ return access(name.c_str(), F_OK) == 0;
+}
+
+bool File::ReadFileToString(const std::string& name, std::string* output,
+ bool text_mode) {
+ char buffer[1024];
+ FILE* file = fopen(name.c_str(), text_mode ? "rt" : "rb");
+ if (file == NULL) return false;
+
+ while (true) {
+ size_t n = fread(buffer, 1, sizeof(buffer), file);
+ if (n <= 0) break;
+ output->append(buffer, n);
+ }
+
+ int error = ferror(file);
+ if (fclose(file) != 0) return false;
+ return error == 0;
+}
+
+void File::ReadFileToStringOrDie(const std::string& name, std::string* output) {
+ GOOGLE_CHECK(ReadFileToString(name, output)) << "Could not read: " << name;
+}
+
+bool File::WriteStringToFile(const std::string& contents,
+ const std::string& name) {
+ FILE* file = fopen(name.c_str(), "wb");
+ if (file == NULL) {
+ GOOGLE_LOG(ERROR) << "fopen(" << name << ", \"wb\"): " << strerror(errno);
+ return false;
+ }
+
+ if (fwrite(contents.data(), 1, contents.size(), file) != contents.size()) {
+ GOOGLE_LOG(ERROR) << "fwrite(" << name << "): " << strerror(errno);
+ fclose(file);
+ return false;
+ }
+
+ if (fclose(file) != 0) {
+ return false;
+ }
+ return true;
+}
+
+void File::WriteStringToFileOrDie(const std::string& contents,
+ const std::string& name) {
+ FILE* file = fopen(name.c_str(), "wb");
+ GOOGLE_CHECK(file != NULL)
+ << "fopen(" << name << ", \"wb\"): " << strerror(errno);
+ GOOGLE_CHECK_EQ(fwrite(contents.data(), 1, contents.size(), file),
+ contents.size())
+ << "fwrite(" << name << "): " << strerror(errno);
+ GOOGLE_CHECK(fclose(file) == 0)
+ << "fclose(" << name << "): " << strerror(errno);
+}
+
+bool File::CreateDir(const std::string& name, int mode) {
+ if (!name.empty()) {
+ GOOGLE_CHECK_OK(name[name.size() - 1] != '.');
+ }
+ return mkdir(name.c_str(), mode) == 0;
+}
+
+bool File::RecursivelyCreateDir(const std::string& path, int mode) {
+ if (CreateDir(path, mode)) return true;
+
+ if (Exists(path)) return false;
+
+ // Try creating the parent.
+ std::string::size_type slashpos = path.find_last_of('/');
+ if (slashpos == std::string::npos) {
+ // No parent given.
+ return false;
+ }
+
+ return RecursivelyCreateDir(path.substr(0, slashpos), mode) &&
+ CreateDir(path, mode);
+}
+
+void File::DeleteRecursively(const std::string& name, void* dummy1,
+ void* dummy2) {
+ if (name.empty()) return;
+
+ // We don't care too much about error checking here since this is only used
+ // in tests to delete temporary directories that are under /tmp anyway.
+
+#ifdef _MSC_VER
+ // This interface is so weird.
+ WIN32_FIND_DATAA find_data;
+ HANDLE find_handle = FindFirstFileA((name + "/*").c_str(), &find_data);
+ if (find_handle == INVALID_HANDLE_VALUE) {
+ // Just delete it, whatever it is.
+ DeleteFileA(name.c_str());
+ RemoveDirectoryA(name.c_str());
+ return;
+ }
+
+ do {
+ std::string entry_name = find_data.cFileName;
+ if (entry_name != "." && entry_name != "..") {
+ std::string path = name + "/" + entry_name;
+ if (find_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
+ DeleteRecursively(path, NULL, NULL);
+ RemoveDirectoryA(path.c_str());
+ } else {
+ DeleteFileA(path.c_str());
+ }
+ }
+ } while(FindNextFileA(find_handle, &find_data));
+ FindClose(find_handle);
+
+ RemoveDirectoryA(name.c_str());
+#else
+ // Use opendir()! Yay!
+ // lstat = Don't follow symbolic links.
+ struct stat stats;
+ if (lstat(name.c_str(), &stats) != 0) return;
+
+ if (S_ISDIR(stats.st_mode)) {
+ DIR* dir = opendir(name.c_str());
+ if (dir != NULL) {
+ while (true) {
+ struct dirent* entry = readdir(dir);
+ if (entry == NULL) break;
+ std::string entry_name = entry->d_name;
+ if (entry_name != "." && entry_name != "..") {
+ DeleteRecursively(name + "/" + entry_name, NULL, NULL);
+ }
+ }
+ }
+
+ closedir(dir);
+ rmdir(name.c_str());
+
+ } else if (S_ISREG(stats.st_mode)) {
+ remove(name.c_str());
+ }
+#endif
+}
+
+bool File::ChangeWorkingDirectory(const std::string& new_working_directory) {
+ return chdir(new_working_directory.c_str()) == 0;
+}
+
+} // namespace protobuf
+} // namespace google
diff --git a/NorthstarDedicatedTest/include/protobuf/testing/file.h b/NorthstarDedicatedTest/include/protobuf/testing/file.h
new file mode 100644
index 00000000..45d641fb
--- /dev/null
+++ b/NorthstarDedicatedTest/include/protobuf/testing/file.h
@@ -0,0 +1,107 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+// Author: kenton@google.com (Kenton Varda)
+// emulates google3/file/base/file.h
+
+#ifndef GOOGLE_PROTOBUF_TESTING_FILE_H__
+#define GOOGLE_PROTOBUF_TESTING_FILE_H__
+
+#include <stubs/common.h>
+
+namespace google {
+namespace protobuf {
+
+const int DEFAULT_FILE_MODE = 0777;
+
+// Protocol buffer code only uses a couple static methods of File, and only
+// in tests.
+class File {
+ public:
+ // Check if the file exists.
+ static bool Exists(const std::string& name);
+
+ // Read an entire file to a string. Return true if successful, false
+ // otherwise.
+ static bool ReadFileToString(const std::string& name, std::string* output,
+ bool text_mode = false);
+
+ // Same as above, but crash on failure.
+ static void ReadFileToStringOrDie(const std::string& name,
+ std::string* output);
+
+ // Create a file and write a string to it.
+ static bool WriteStringToFile(const std::string& contents,
+ const std::string& name);
+
+ // Same as above, but crash on failure.
+ static void WriteStringToFileOrDie(const std::string& contents,
+ const std::string& name);
+
+ // Create a directory.
+ static bool CreateDir(const std::string& name, int mode);
+
+ // Create a directory and all parent directories if necessary.
+ static bool RecursivelyCreateDir(const std::string& path, int mode);
+
+ // If "name" is a file, we delete it. If it is a directory, we
+ // call DeleteRecursively() for each file or directory (other than
+ // dot and double-dot) within it, and then delete the directory itself.
+ // The "dummy" parameters have a meaning in the original version of this
+ // method but they are not used anywhere in protocol buffers.
+ static void DeleteRecursively(const std::string& name, void* dummy1,
+ void* dummy2);
+
+ // Change working directory to given directory.
+ static bool ChangeWorkingDirectory(const std::string& new_working_directory);
+
+ static bool GetContents(const std::string& name, std::string* output,
+ bool /*is_default*/) {
+ return ReadFileToString(name, output);
+ }
+
+ static bool GetContentsAsText(const std::string& name, std::string* output,
+ bool /*is_default*/) {
+ return ReadFileToString(name, output, true);
+ }
+
+ static bool SetContents(const std::string& name, const std::string& contents,
+ bool /*is_default*/) {
+ return WriteStringToFile(contents, name);
+ }
+
+ private:
+ GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(File);
+};
+
+} // namespace protobuf
+} // namespace google
+
+#endif // GOOGLE_PROTOBUF_TESTING_FILE_H__
diff --git a/NorthstarDedicatedTest/include/protobuf/testing/googletest.cc b/NorthstarDedicatedTest/include/protobuf/testing/googletest.cc
new file mode 100644
index 00000000..6fe64bc8
--- /dev/null
+++ b/NorthstarDedicatedTest/include/protobuf/testing/googletest.cc
@@ -0,0 +1,302 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+// Author: kenton@google.com (Kenton Varda)
+// emulates google3/testing/base/public/googletest.cc
+
+#include <testing/googletest.h>
+#include <testing/file.h>
+#include <io/io_win32.h>
+#include <stubs/strutil.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <errno.h>
+#include <stdlib.h>
+#ifdef _MSC_VER
+// #include <direct.h>
+#else
+#include <unistd.h>
+#endif
+#include <stdio.h>
+#include <fcntl.h>
+#include <iostream>
+#include <fstream>
+
+namespace google {
+namespace protobuf {
+
+#ifdef _WIN32
+// DO NOT include <io.h>, instead create functions in io_win32.{h,cc} and import
+// them like we do below.
+using google::protobuf::io::win32::close;
+using google::protobuf::io::win32::dup2;
+using google::protobuf::io::win32::dup;
+using google::protobuf::io::win32::mkdir;
+using google::protobuf::io::win32::open;
+#endif
+
+#ifndef O_BINARY
+#ifdef _O_BINARY
+#define O_BINARY _O_BINARY
+#else
+#define O_BINARY 0 // If this isn't defined, the platform doesn't need it.
+#endif
+#endif
+
+std::string TestSourceDir() {
+#ifndef GOOGLE_THIRD_PARTY_PROTOBUF
+#ifdef GOOGLE_PROTOBUF_TEST_SOURCE_PATH
+ return GOOGLE_PROTOBUF_TEST_SOURCE_PATH;
+#else
+#ifndef _MSC_VER
+ // automake sets the "srcdir" environment variable.
+ char* result = getenv("srcdir");
+ if (result != NULL) {
+ return result;
+ }
+#endif // _MSC_VER
+
+ // Look for the "src" directory.
+ std::string prefix = ".";
+
+ // Keep looking further up the directory tree until we find
+ // src/.../descriptor.cc. It is important to look for a particular file,
+ // keeping in mind that with Bazel builds the directory structure under
+ // bazel-bin/ looks similar to the main directory tree in the Git repo.
+ while (!File::Exists(prefix + "/src/google/protobuf/descriptor.cc")) {
+ if (!File::Exists(prefix)) {
+ GOOGLE_LOG(FATAL)
+ << "Could not find protobuf source code. Please run tests from "
+ "somewhere within the protobuf source package.";
+ }
+ prefix += "/..";
+ }
+ return prefix + "/src";
+#endif // GOOGLE_PROTOBUF_TEST_SOURCE_PATH
+#else
+ return "third_party/protobuf/src";
+#endif // GOOGLE_THIRD_PARTY_PROTOBUF
+}
+
+namespace {
+
+std::string GetTemporaryDirectoryName() {
+ // Tests run under Bazel "should not" use /tmp. Bazel sets this environment
+ // variable for tests to use instead.
+ char *from_environment = getenv("TEST_TMPDIR");
+ if (from_environment != NULL && from_environment[0] != '\0') {
+ return std::string(from_environment) + "/protobuf_tmpdir";
+ }
+
+ // tmpnam() is generally not considered safe but we're only using it for
+ // testing. We cannot use tmpfile() or mkstemp() since we're creating a
+ // directory.
+ char b[L_tmpnam + 1]; // HPUX multithread return 0 if s is 0
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
+ std::string result = tmpnam(b);
+#pragma GCC diagnostic pop
+#ifdef _WIN32
+ // Avoid a trailing dot by changing it to an underscore. On Win32 the names of
+ // files and directories can, but should not, end with dot.
+ //
+ // In MS-DOS and FAT16 filesystem the filenames were 8dot3 style so it didn't
+ // make sense to have a name ending in dot without an extension, so the shell
+ // silently ignored trailing dots. To this day the Win32 API still maintains
+ // this behavior and silently ignores trailing dots in path arguments of
+ // functions such as CreateFile{A,W}. Even POSIX API function implementations
+ // seem to wrap the Win32 API functions (e.g. CreateDirectoryA) and behave
+ // this way.
+ // It's possible to avoid this behavior and create files / directories with
+ // trailing dots (using CreateFileW / CreateDirectoryW and prefixing the path
+ // with "\\?\") but these will be degenerate in the sense that you cannot
+ // chdir into such directories (or navigate into them with Windows Explorer)
+ // nor can you open such files with some programs (e.g. Notepad).
+ if (result[result.size() - 1] == '.') {
+ result[result.size() - 1] = '_';
+ }
+ // On Win32, tmpnam() returns a file prefixed with '\', but which is supposed
+ // to be used in the current working directory. WTF?
+ if (HasPrefixString(result, "\\")) {
+ result.erase(0, 1);
+ }
+ // The Win32 API accepts forward slashes as a path delimiter as long as the
+ // path doesn't use the "\\?\" prefix.
+ // Let's avoid confusion and use only forward slashes.
+ result = StringReplace(result, "\\", "/", true);
+#endif // _WIN32
+ return result;
+}
+
+// Creates a temporary directory on demand and deletes it when the process
+// quits.
+class TempDirDeleter {
+ public:
+ TempDirDeleter() {}
+ ~TempDirDeleter() {
+ if (!name_.empty()) {
+ File::DeleteRecursively(name_, NULL, NULL);
+ }
+ }
+
+ std::string GetTempDir() {
+ if (name_.empty()) {
+ name_ = GetTemporaryDirectoryName();
+ GOOGLE_CHECK(mkdir(name_.c_str(), 0777) == 0) << strerror(errno);
+
+ // Stick a file in the directory that tells people what this is, in case
+ // we abort and don't get a chance to delete it.
+ File::WriteStringToFileOrDie("", name_ + "/TEMP_DIR_FOR_PROTOBUF_TESTS");
+ }
+ return name_;
+ }
+
+ private:
+ std::string name_;
+};
+
+TempDirDeleter temp_dir_deleter_;
+
+} // namespace
+
+std::string TestTempDir() { return temp_dir_deleter_.GetTempDir(); }
+
+// TODO(kenton): Share duplicated code below. Too busy/lazy for now.
+
+static std::string stdout_capture_filename_;
+static std::string stderr_capture_filename_;
+static int original_stdout_ = -1;
+static int original_stderr_ = -1;
+
+void CaptureTestStdout() {
+ GOOGLE_CHECK_EQ(original_stdout_, -1) << "Already capturing.";
+
+ stdout_capture_filename_ = TestTempDir() + "/captured_stdout";
+
+ int fd = open(stdout_capture_filename_.c_str(),
+ O_WRONLY | O_CREAT | O_EXCL | O_BINARY, 0777);
+ GOOGLE_CHECK(fd >= 0) << "open: " << strerror(errno);
+
+ original_stdout_ = dup(1);
+ close(1);
+ dup2(fd, 1);
+ close(fd);
+}
+
+void CaptureTestStderr() {
+ GOOGLE_CHECK_EQ(original_stderr_, -1) << "Already capturing.";
+
+ stderr_capture_filename_ = TestTempDir() + "/captured_stderr";
+
+ int fd = open(stderr_capture_filename_.c_str(),
+ O_WRONLY | O_CREAT | O_EXCL | O_BINARY, 0777);
+ GOOGLE_CHECK(fd >= 0) << "open: " << strerror(errno);
+
+ original_stderr_ = dup(2);
+ close(2);
+ dup2(fd, 2);
+ close(fd);
+}
+
+std::string GetCapturedTestStdout() {
+ GOOGLE_CHECK_NE(original_stdout_, -1) << "Not capturing.";
+
+ close(1);
+ dup2(original_stdout_, 1);
+ original_stdout_ = -1;
+
+ std::string result;
+ File::ReadFileToStringOrDie(stdout_capture_filename_, &result);
+
+ remove(stdout_capture_filename_.c_str());
+
+ return result;
+}
+
+std::string GetCapturedTestStderr() {
+ GOOGLE_CHECK_NE(original_stderr_, -1) << "Not capturing.";
+
+ close(2);
+ dup2(original_stderr_, 2);
+ original_stderr_ = -1;
+
+ std::string result;
+ File::ReadFileToStringOrDie(stderr_capture_filename_, &result);
+
+ remove(stderr_capture_filename_.c_str());
+
+ return result;
+}
+
+ScopedMemoryLog* ScopedMemoryLog::active_log_ = NULL;
+
+ScopedMemoryLog::ScopedMemoryLog() {
+ GOOGLE_CHECK(active_log_ == NULL);
+ active_log_ = this;
+ old_handler_ = SetLogHandler(&HandleLog);
+}
+
+ScopedMemoryLog::~ScopedMemoryLog() {
+ SetLogHandler(old_handler_);
+ active_log_ = NULL;
+}
+
+const std::vector<std::string>& ScopedMemoryLog::GetMessages(LogLevel level) {
+ GOOGLE_CHECK(level == ERROR ||
+ level == WARNING);
+ return messages_[level];
+}
+
+void ScopedMemoryLog::HandleLog(LogLevel level, const char* filename, int line,
+ const std::string& message) {
+ GOOGLE_CHECK(active_log_ != NULL);
+ if (level == ERROR || level == WARNING) {
+ active_log_->messages_[level].push_back(message);
+ }
+}
+
+namespace {
+
+// Force shutdown at process exit so that we can test for memory leaks. To
+// actually check for leaks, I suggest using the heap checker included with
+// google-perftools. Set it to "draconian" mode to ensure that every last
+// call to malloc() has a corresponding free().
+struct ForceShutdown {
+ ~ForceShutdown() {
+ ShutdownProtobufLibrary();
+ // Test to shutdown the library twice, which should succeed.
+ ShutdownProtobufLibrary();
+ }
+} force_shutdown;
+
+} // namespace
+
+} // namespace protobuf
+} // namespace google
diff --git a/NorthstarDedicatedTest/include/protobuf/testing/googletest.h b/NorthstarDedicatedTest/include/protobuf/testing/googletest.h
new file mode 100644
index 00000000..727b62be
--- /dev/null
+++ b/NorthstarDedicatedTest/include/protobuf/testing/googletest.h
@@ -0,0 +1,104 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+// Author: kenton@google.com (Kenton Varda)
+// emulates google3/testing/base/public/googletest.h
+
+#ifndef GOOGLE_PROTOBUF_GOOGLETEST_H__
+#define GOOGLE_PROTOBUF_GOOGLETEST_H__
+
+#include <map>
+#include <vector>
+#include <stubs/common.h>
+#include <stubs/logging.h>
+#include <gmock/gmock.h>
+// Disable death tests if we use exceptions in CHECK().
+#if !PROTOBUF_USE_EXCEPTIONS && defined(GTEST_HAS_DEATH_TEST) && \
+ !GTEST_OS_WINDOWS
+#define PROTOBUF_HAS_DEATH_TEST
+#endif
+
+namespace google {
+namespace protobuf {
+
+// When running unittests, get the directory containing the source code.
+std::string TestSourceDir();
+
+// When running unittests, get a directory where temporary files may be
+// placed.
+std::string TestTempDir();
+
+// Capture all text written to stdout or stderr.
+void CaptureTestStdout();
+void CaptureTestStderr();
+
+// Stop capturing stdout or stderr and return the text captured.
+std::string GetCapturedTestStdout();
+std::string GetCapturedTestStderr();
+
+// For use with ScopedMemoryLog::GetMessages(). Inside Google the LogLevel
+// constants don't have the LOGLEVEL_ prefix, so the code that used
+// ScopedMemoryLog refers to LOGLEVEL_ERROR as just ERROR.
+#undef ERROR // defend against promiscuous windows.h
+static const LogLevel ERROR = LOGLEVEL_ERROR;
+static const LogLevel WARNING = LOGLEVEL_WARNING;
+
+// Receives copies of all LOG(ERROR) messages while in scope. Sample usage:
+// {
+// ScopedMemoryLog log; // constructor registers object as a log sink
+// SomeRoutineThatMayLogMessages();
+// const vector<string>& warnings = log.GetMessages(ERROR);
+// } // destructor unregisters object as a log sink
+// This is a dummy implementation which covers only what is used by protocol
+// buffer unit tests.
+class ScopedMemoryLog {
+ public:
+ ScopedMemoryLog();
+ virtual ~ScopedMemoryLog();
+
+ // Fetches all messages with the given severity level.
+ const std::vector<std::string>& GetMessages(LogLevel error);
+
+ private:
+ std::map<LogLevel, std::vector<std::string> > messages_;
+ LogHandler* old_handler_;
+
+ static void HandleLog(LogLevel level, const char* filename, int line,
+ const std::string& message);
+
+ static ScopedMemoryLog* active_log_;
+
+ GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ScopedMemoryLog);
+};
+
+} // namespace protobuf
+} // namespace google
+
+#endif // GOOGLE_PROTOBUF_GOOGLETEST_H__
diff --git a/NorthstarDedicatedTest/include/protobuf/testing/zcgunzip.cc b/NorthstarDedicatedTest/include/protobuf/testing/zcgunzip.cc
new file mode 100644
index 00000000..e393e4ab
--- /dev/null
+++ b/NorthstarDedicatedTest/include/protobuf/testing/zcgunzip.cc
@@ -0,0 +1,84 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2009 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+// Author: brianolson@google.com (Brian Olson)
+// Based on original Protocol Buffers design by
+// Sanjay Ghemawat, Jeff Dean, and others.
+//
+// Test program to verify that GzipInputStream is compatible with command line
+// gunzip or java.util.zip.GzipInputStream
+//
+// Reads gzip stream on standard input and writes decompressed data to standard
+// output.
+
+#include <assert.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#ifdef _WIN32
+#ifndef STDIN_FILENO
+#define STDIN_FILENO 0
+#endif
+#ifndef STDOUT_FILENO
+#define STDOUT_FILENO 1
+#endif
+#endif
+
+#include <io/gzip_stream.h>
+#include <io/zero_copy_stream_impl.h>
+
+using google::protobuf::io::FileInputStream;
+using google::protobuf::io::GzipInputStream;
+
+int main(int argc, const char** argv) {
+ FileInputStream fin(STDIN_FILENO);
+ GzipInputStream in(&fin);
+
+ while (true) {
+ const void* inptr;
+ int inlen;
+ bool ok;
+ ok = in.Next(&inptr, &inlen);
+ if (!ok) {
+ break;
+ }
+ if (inlen > 0) {
+ int err = write(STDOUT_FILENO, inptr, inlen);
+ if (err != inlen) {
+ fprintf(stderr, "write unexpectedly returned %d.\n", err);
+ return 1;
+ }
+ }
+ }
+
+ return 0;
+}
diff --git a/NorthstarDedicatedTest/include/protobuf/testing/zcgzip.cc b/NorthstarDedicatedTest/include/protobuf/testing/zcgzip.cc
new file mode 100644
index 00000000..d2aba57a
--- /dev/null
+++ b/NorthstarDedicatedTest/include/protobuf/testing/zcgzip.cc
@@ -0,0 +1,87 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2009 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+// Author: brianolson@google.com (Brian Olson)
+// Based on original Protocol Buffers design by
+// Sanjay Ghemawat, Jeff Dean, and others.
+//
+// Test program to verify that GzipOutputStream is compatible with command line
+// gzip or java.util.zip.GzipOutputStream
+//
+// Reads data on standard input and writes compressed gzip stream to standard
+// output.
+
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#ifdef _WIN32
+#ifndef STDIN_FILENO
+#define STDIN_FILENO 0
+#endif
+#ifndef STDOUT_FILENO
+#define STDOUT_FILENO 1
+#endif
+#endif
+
+#include <io/gzip_stream.h>
+#include <io/zero_copy_stream_impl.h>
+
+using google::protobuf::io::FileOutputStream;
+using google::protobuf::io::GzipOutputStream;
+
+int main(int argc, const char** argv) {
+ FileOutputStream fout(STDOUT_FILENO);
+ GzipOutputStream out(&fout);
+ int readlen;
+
+ while (true) {
+ void* outptr;
+ int outlen;
+ bool ok;
+ do {
+ ok = out.Next(&outptr, &outlen);
+ if (!ok) {
+ break;
+ }
+ } while (outlen <= 0);
+ readlen = read(STDIN_FILENO, outptr, outlen);
+ if (readlen <= 0) {
+ out.BackUp(outlen);
+ break;
+ }
+ if (readlen < outlen) {
+ out.BackUp(outlen - readlen);
+ }
+ }
+
+ return 0;
+}