diff options
author | Gennadiy Civil <misterg@google.com> | 2017-05-02 18:16:11 (GMT) |
---|---|---|
committer | Gennadiy Civil <misterg@google.com> | 2017-05-02 18:16:11 (GMT) |
commit | 611e8a99de2b1c049fcd65c0d32a532c1b6301d6 (patch) | |
tree | a2d81b0832231e7017dcadeeae58301ab8920124 /googletest | |
parent | aa148eb2b7f70ede0eb10de34b6254826bfb34f4 (diff) | |
download | googletest-611e8a99de2b1c049fcd65c0d32a532c1b6301d6.zip googletest-611e8a99de2b1c049fcd65c0d32a532c1b6301d6.tar.gz googletest-611e8a99de2b1c049fcd65c0d32a532c1b6301d6.tar.bz2 |
Changes to make TempDir() publicrefs/pull/1077/head
Fixes #1076.
Diffstat (limited to 'googletest')
-rw-r--r-- | googletest/include/gtest/gtest.h | 4 | ||||
-rw-r--r-- | googletest/include/gtest/internal/gtest-port.h | 8 | ||||
-rw-r--r-- | googletest/src/gtest-port.cc | 18 | ||||
-rw-r--r-- | googletest/src/gtest.cc | 19 | ||||
-rw-r--r-- | googletest/test/gtest_unittest.cc | 2 |
5 files changed, 29 insertions, 22 deletions
diff --git a/googletest/include/gtest/gtest.h b/googletest/include/gtest/gtest.h index f846c5b..a42aa2a 100644 --- a/googletest/include/gtest/gtest.h +++ b/googletest/include/gtest/gtest.h @@ -2217,6 +2217,10 @@ bool StaticAssertTypeEq() { GTEST_TEST_(test_fixture, test_name, test_fixture, \ ::testing::internal::GetTypeId<test_fixture>()) +// Returns a path to temporary directory. +// Tries to determine an appropriate directory for the platform. +GTEST_API_ std::string TempDir(); + } // namespace testing // Use this function in main() to run all tests. It returns 0 if all diff --git a/googletest/include/gtest/internal/gtest-port.h b/googletest/include/gtest/internal/gtest-port.h index 0d53ad2..cb9ab95 100644 --- a/googletest/include/gtest/internal/gtest-port.h +++ b/googletest/include/gtest/internal/gtest-port.h @@ -1428,9 +1428,6 @@ GTEST_API_ std::string GetCapturedStderr(); #endif // GTEST_HAS_STREAM_REDIRECTION -// Returns a path to temporary directory. -GTEST_API_ std::string TempDir(); - // Returns the size (in bytes) of a file. GTEST_API_ size_t GetFileSize(FILE* file); @@ -2559,6 +2556,11 @@ GTEST_API_ Int32 Int32FromGTestEnv(const char* flag, Int32 default_val); std::string StringFromGTestEnv(const char* flag, const char* default_val); } // namespace internal + +// Returns a path to temporary directory. +// Tries to determine an appropriate directory for the platform. +GTEST_API_ std::string TempDir(); + } // namespace testing #endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PORT_H_ diff --git a/googletest/src/gtest-port.cc b/googletest/src/gtest-port.cc index e5bf3dd..e378d7d 100644 --- a/googletest/src/gtest-port.cc +++ b/googletest/src/gtest-port.cc @@ -1055,24 +1055,6 @@ std::string GetCapturedStderr() { #endif // GTEST_HAS_STREAM_REDIRECTION -std::string TempDir() { -#if GTEST_OS_WINDOWS_MOBILE - return "\\temp\\"; -#elif GTEST_OS_WINDOWS - const char* temp_dir = posix::GetEnv("TEMP"); - if (temp_dir == NULL || temp_dir[0] == '\0') - return "\\temp\\"; - else if (temp_dir[strlen(temp_dir) - 1] == '\\') - return temp_dir; - else - return std::string(temp_dir) + "\\"; -#elif GTEST_OS_LINUX_ANDROID - return "/sdcard/"; -#else - return "/tmp/"; -#endif // GTEST_OS_WINDOWS_MOBILE -} - size_t GetFileSize(FILE* file) { fseek(file, 0, SEEK_END); return static_cast<size_t>(ftell(file)); diff --git a/googletest/src/gtest.cc b/googletest/src/gtest.cc index d882ab2..d6fd8a6 100644 --- a/googletest/src/gtest.cc +++ b/googletest/src/gtest.cc @@ -5385,4 +5385,23 @@ void InitGoogleTest(int* argc, wchar_t** argv) { #endif // defined(GTEST_CUSTOM_INIT_GOOGLE_TEST_FUNCTION_) } +std::string TempDir() { +#if GTEST_OS_WINDOWS_MOBILE + return "\\temp\\"; +#elif GTEST_OS_WINDOWS + const char* temp_dir = internal::posix::GetEnv("TEMP"); + if (temp_dir == NULL || temp_dir[0] == '\0') + return "\\temp\\"; + else if (temp_dir[strlen(temp_dir) - 1] == '\\') + return temp_dir; + else + return std::string(temp_dir) + "\\"; +#elif GTEST_OS_LINUX_ANDROID + return "/sdcard/"; +#else + return "/tmp/"; +#endif // GTEST_OS_WINDOWS_MOBILE +} + + } // namespace testing diff --git a/googletest/test/gtest_unittest.cc b/googletest/test/gtest_unittest.cc index 97fcd5a..814a025 100644 --- a/googletest/test/gtest_unittest.cc +++ b/googletest/test/gtest_unittest.cc @@ -6411,7 +6411,7 @@ class FlagfileTest : public InitGoogleTestTest { InitGoogleTestTest::SetUp(); testdata_path_.Set(internal::FilePath( - internal::TempDir() + internal::GetCurrentExecutableName().string() + + testing::TempDir() + internal::GetCurrentExecutableName().string() + "_flagfile_test")); testing::internal::posix::RmDir(testdata_path_.c_str()); EXPECT_TRUE(testdata_path_.CreateFolder()); |