| 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 // https://developers.google.com/protocol-buffers/ |
| 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. |
| 11 // * Redistributions in binary form must reproduce the above | 11 // * Redistributions in binary form must reproduce the above |
| 12 // copyright notice, this list of conditions and the following disclaimer | 12 // copyright notice, this list of conditions and the following disclaimer |
| 13 // in the documentation and/or other materials provided with the | 13 // in the documentation and/or other materials provided with the |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 | 58 |
| 59 #ifndef O_BINARY | 59 #ifndef O_BINARY |
| 60 #ifdef _O_BINARY | 60 #ifdef _O_BINARY |
| 61 #define O_BINARY _O_BINARY | 61 #define O_BINARY _O_BINARY |
| 62 #else | 62 #else |
| 63 #define O_BINARY 0 // If this isn't defined, the platform doesn't need it. | 63 #define O_BINARY 0 // If this isn't defined, the platform doesn't need it. |
| 64 #endif | 64 #endif |
| 65 #endif | 65 #endif |
| 66 | 66 |
| 67 string TestSourceDir() { | 67 string TestSourceDir() { |
| 68 #ifdef _MSC_VER | 68 #ifndef GOOGLE_THIRD_PARTY_PROTOBUF |
| 69 #ifndef _MSC_VER |
| 70 // automake sets the "srcdir" environment variable. |
| 71 char* result = getenv("srcdir"); |
| 72 if (result != NULL) { |
| 73 return result; |
| 74 } |
| 75 #endif // _MSC_VER |
| 76 |
| 69 // Look for the "src" directory. | 77 // Look for the "src" directory. |
| 70 string prefix = "."; | 78 string prefix = "."; |
| 71 | 79 |
| 72 while (!File::Exists(prefix + "/src/google/protobuf")) { | 80 while (!File::Exists(prefix + "/src/google/protobuf")) { |
| 73 if (!File::Exists(prefix)) { | 81 if (!File::Exists(prefix)) { |
| 74 GOOGLE_LOG(FATAL) | 82 GOOGLE_LOG(FATAL) |
| 75 << "Could not find protobuf source code. Please run tests from " | 83 << "Could not find protobuf source code. Please run tests from " |
| 76 "somewhere within the protobuf source package."; | 84 "somewhere within the protobuf source package."; |
| 77 } | 85 } |
| 78 prefix += "/.."; | 86 prefix += "/.."; |
| 79 } | 87 } |
| 80 return prefix + "/src"; | 88 return prefix + "/src"; |
| 81 #else | 89 #else |
| 82 // automake sets the "srcdir" environment variable. | 90 return "third_party/protobuf/src"; |
| 83 char* result = getenv("srcdir"); | 91 #endif // GOOGLE_THIRD_PARTY_PROTOBUF |
| 84 if (result == NULL) { | |
| 85 // Otherwise, the test must be run from the source directory. | |
| 86 return "."; | |
| 87 } else { | |
| 88 return result; | |
| 89 } | |
| 90 #endif | |
| 91 } | 92 } |
| 92 | 93 |
| 93 namespace { | 94 namespace { |
| 94 | 95 |
| 95 string GetTemporaryDirectoryName() { | 96 string GetTemporaryDirectoryName() { |
| 97 // Tests run under Bazel "should not" use /tmp. Bazel sets this environment |
| 98 // variable for tests to use instead. |
| 99 char *from_environment = getenv("TEST_TMPDIR"); |
| 100 if (from_environment != NULL && from_environment[0] != '\0') { |
| 101 return string(from_environment) + "/protobuf_tmpdir"; |
| 102 } |
| 103 |
| 96 // tmpnam() is generally not considered safe but we're only using it for | 104 // tmpnam() is generally not considered safe but we're only using it for |
| 97 // testing. We cannot use tmpfile() or mkstemp() since we're creating a | 105 // testing. We cannot use tmpfile() or mkstemp() since we're creating a |
| 98 // directory. | 106 // directory. |
| 99 char b[L_tmpnam + 1]; // HPUX multithread return 0 if s is 0 | 107 char b[L_tmpnam + 1]; // HPUX multithread return 0 if s is 0 |
| 100 string result = tmpnam(b); | 108 string result = tmpnam(b); |
| 101 #ifdef _WIN32 | 109 #ifdef _WIN32 |
| 102 // On Win32, tmpnam() returns a file prefixed with '\', but which is supposed | 110 // On Win32, tmpnam() returns a file prefixed with '\', but which is supposed |
| 103 // to be used in the current working directory. WTF? | 111 // to be used in the current working directory. WTF? |
| 104 if (HasPrefixString(result, "\\")) { | 112 if (HasPrefixString(result, "\\")) { |
| 105 result.erase(0, 1); | 113 result.erase(0, 1); |
| 106 } | 114 } |
| 115 // The Win32 API accepts forward slashes as a path delimiter even though |
| 116 // backslashes are standard. Let's avoid confusion and use only forward |
| 117 // slashes. |
| 118 result = StringReplace(result, "\\", "/", true); |
| 107 #endif // _WIN32 | 119 #endif // _WIN32 |
| 108 return result; | 120 return result; |
| 109 } | 121 } |
| 110 | 122 |
| 111 // Creates a temporary directory on demand and deletes it when the process | 123 // Creates a temporary directory on demand and deletes it when the process |
| 112 // quits. | 124 // quits. |
| 113 class TempDirDeleter { | 125 class TempDirDeleter { |
| 114 public: | 126 public: |
| 115 TempDirDeleter() {} | 127 TempDirDeleter() {} |
| 116 ~TempDirDeleter() { | 128 ~TempDirDeleter() { |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 struct ForceShutdown { | 258 struct ForceShutdown { |
| 247 ~ForceShutdown() { | 259 ~ForceShutdown() { |
| 248 ShutdownProtobufLibrary(); | 260 ShutdownProtobufLibrary(); |
| 249 } | 261 } |
| 250 } force_shutdown; | 262 } force_shutdown; |
| 251 | 263 |
| 252 } // namespace | 264 } // namespace |
| 253 | 265 |
| 254 } // namespace protobuf | 266 } // namespace protobuf |
| 255 } // namespace google | 267 } // namespace google |
| OLD | NEW |