Merge pull request #1077 from gennadiycivil/make-temp-dir-public-issue-1076
Changes to make TempDir() public
This commit is contained in:
commit
69c6db249a
|
@ -2217,6 +2217,10 @@ bool StaticAssertTypeEq() {
|
||||||
GTEST_TEST_(test_fixture, test_name, test_fixture, \
|
GTEST_TEST_(test_fixture, test_name, test_fixture, \
|
||||||
::testing::internal::GetTypeId<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
|
} // namespace testing
|
||||||
|
|
||||||
// Use this function in main() to run all tests. It returns 0 if all
|
// Use this function in main() to run all tests. It returns 0 if all
|
||||||
|
|
|
@ -1428,9 +1428,6 @@ GTEST_API_ std::string GetCapturedStderr();
|
||||||
|
|
||||||
#endif // GTEST_HAS_STREAM_REDIRECTION
|
#endif // GTEST_HAS_STREAM_REDIRECTION
|
||||||
|
|
||||||
// Returns a path to temporary directory.
|
|
||||||
GTEST_API_ std::string TempDir();
|
|
||||||
|
|
||||||
// Returns the size (in bytes) of a file.
|
// Returns the size (in bytes) of a file.
|
||||||
GTEST_API_ size_t GetFileSize(FILE* 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);
|
std::string StringFromGTestEnv(const char* flag, const char* default_val);
|
||||||
|
|
||||||
} // namespace internal
|
} // namespace internal
|
||||||
|
|
||||||
|
// Returns a path to temporary directory.
|
||||||
|
// Tries to determine an appropriate directory for the platform.
|
||||||
|
GTEST_API_ std::string TempDir();
|
||||||
|
|
||||||
} // namespace testing
|
} // namespace testing
|
||||||
|
|
||||||
#endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PORT_H_
|
#endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PORT_H_
|
||||||
|
|
|
@ -1055,24 +1055,6 @@ std::string GetCapturedStderr() {
|
||||||
|
|
||||||
#endif // GTEST_HAS_STREAM_REDIRECTION
|
#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) {
|
size_t GetFileSize(FILE* file) {
|
||||||
fseek(file, 0, SEEK_END);
|
fseek(file, 0, SEEK_END);
|
||||||
return static_cast<size_t>(ftell(file));
|
return static_cast<size_t>(ftell(file));
|
||||||
|
|
|
@ -5385,4 +5385,23 @@ void InitGoogleTest(int* argc, wchar_t** argv) {
|
||||||
#endif // defined(GTEST_CUSTOM_INIT_GOOGLE_TEST_FUNCTION_)
|
#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
|
} // namespace testing
|
||||||
|
|
|
@ -6411,7 +6411,7 @@ class FlagfileTest : public InitGoogleTestTest {
|
||||||
InitGoogleTestTest::SetUp();
|
InitGoogleTestTest::SetUp();
|
||||||
|
|
||||||
testdata_path_.Set(internal::FilePath(
|
testdata_path_.Set(internal::FilePath(
|
||||||
internal::TempDir() + internal::GetCurrentExecutableName().string() +
|
testing::TempDir() + internal::GetCurrentExecutableName().string() +
|
||||||
"_flagfile_test"));
|
"_flagfile_test"));
|
||||||
testing::internal::posix::RmDir(testdata_path_.c_str());
|
testing::internal::posix::RmDir(testdata_path_.c_str());
|
||||||
EXPECT_TRUE(testdata_path_.CreateFolder());
|
EXPECT_TRUE(testdata_path_.CreateFolder());
|
||||||
|
|
Loading…
Reference in New Issue
Block a user