aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorzhanyong.wan <zhanyong.wan@861a406c-534a-0410-8894-cb66d6ee9925>2009-03-26 19:03:47 +0000
committerzhanyong.wan <zhanyong.wan@861a406c-534a-0410-8894-cb66d6ee9925>2009-03-26 19:03:47 +0000
commit3c7bbf5b46679aea4e0ac7d3ad241cb036146751 (patch)
treef452879c8f86232be2dec970ec7bce3a9963ed49 /test
parentf3c6efd8d78f96a9a500b3ba7e024de122b9afa1 (diff)
downloadgoogletest-3c7bbf5b46679aea4e0ac7d3ad241cb036146751.tar.gz
googletest-3c7bbf5b46679aea4e0ac7d3ad241cb036146751.tar.bz2
googletest-3c7bbf5b46679aea4e0ac7d3ad241cb036146751.zip
Simplifies implementation by defining a POSIX portability layer; adds the death test style flag to --help.
Diffstat (limited to 'test')
-rw-r--r--test/gtest-death-test_test.cc17
-rw-r--r--test/gtest-filepath_test.cc42
-rw-r--r--test/gtest-options_test.cc12
-rwxr-xr-xtest/gtest_help_test.py3
-rw-r--r--test/gtest_output_test_.cc12
5 files changed, 21 insertions, 65 deletions
diff --git a/test/gtest-death-test_test.cc b/test/gtest-death-test_test.cc
index a6d7b18d..db5f72e0 100644
--- a/test/gtest-death-test_test.cc
+++ b/test/gtest-death-test_test.cc
@@ -60,8 +60,9 @@
#include "src/gtest-internal-inl.h"
#undef GTEST_IMPLEMENTATION_
-using testing::Message;
+namespace posix = ::testing::internal::posix;
+using testing::Message;
using testing::internal::DeathTest;
using testing::internal::DeathTestFactory;
using testing::internal::FilePath;
@@ -105,11 +106,7 @@ class TestForDeathTest : public testing::Test {
TestForDeathTest() : original_dir_(FilePath::GetCurrentDir()) {}
virtual ~TestForDeathTest() {
-#if GTEST_OS_WINDOWS
- _chdir(original_dir_.c_str());
-#else
- chdir(original_dir_.c_str());
-#endif
+ posix::chdir(original_dir_.c_str());
}
// A static member function that's expected to die.
@@ -348,13 +345,7 @@ TEST_F(TestForDeathTest, MemberFunctionFastStyle) {
EXPECT_DEATH(MemberFunction(), "inside.*MemberFunction");
}
-void ChangeToRootDir() {
-#if GTEST_OS_WINDOWS
- _chdir("\\");
-#else
- chdir("/");
-#endif // GTEST_OS_WINDOWS
-}
+void ChangeToRootDir() { posix::chdir(GTEST_PATH_SEP_); }
// Tests that death tests work even if the current directory has been
// changed.
diff --git a/test/gtest-filepath_test.cc b/test/gtest-filepath_test.cc
index f8b68a78..77a2988e 100644
--- a/test/gtest-filepath_test.cc
+++ b/test/gtest-filepath_test.cc
@@ -86,18 +86,17 @@ TEST(GetCurrentDirTest, ReturnsCurrentDir) {
const FilePath original_dir = FilePath::GetCurrentDir();
EXPECT_FALSE(original_dir.IsEmpty());
-#if GTEST_OS_WINDOWS
- _chdir(GTEST_PATH_SEP_);
+ posix::chdir(GTEST_PATH_SEP_);
const FilePath cwd = FilePath::GetCurrentDir();
- _chdir(original_dir.c_str());
+ posix::chdir(original_dir.c_str());
+
+#if GTEST_OS_WINDOWS
// Skips the ":".
const char* const cwd_without_drive = strchr(cwd.c_str(), ':');
ASSERT_TRUE(cwd_without_drive != NULL);
EXPECT_STREQ(GTEST_PATH_SEP_, cwd_without_drive + 1);
#else
- chdir(GTEST_PATH_SEP_);
- EXPECT_STREQ(GTEST_PATH_SEP_, FilePath::GetCurrentDir().c_str());
- chdir(original_dir.c_str());
+ EXPECT_STREQ(GTEST_PATH_SEP_, cwd.c_str());
#endif
}
@@ -436,22 +435,14 @@ class DirectoryCreationTest : public Test {
remove(testdata_file_.c_str());
remove(unique_file0_.c_str());
remove(unique_file1_.c_str());
-#if GTEST_OS_WINDOWS
- _rmdir(testdata_path_.c_str());
-#else
- rmdir(testdata_path_.c_str());
-#endif // GTEST_OS_WINDOWS
+ posix::rmdir(testdata_path_.c_str());
}
virtual void TearDown() {
remove(testdata_file_.c_str());
remove(unique_file0_.c_str());
remove(unique_file1_.c_str());
-#if GTEST_OS_WINDOWS
- _rmdir(testdata_path_.c_str());
-#else
- rmdir(testdata_path_.c_str());
-#endif // GTEST_OS_WINDOWS
+ posix::rmdir(testdata_path_.c_str());
}
String TempDir() const {
@@ -459,13 +450,7 @@ class DirectoryCreationTest : public Test {
return String("\\temp\\");
#elif GTEST_OS_WINDOWS
- // MSVC 8 deprecates getenv(), so we want to suppress warning 4996
- // (deprecated function) there.
-#pragma warning(push) // Saves the current warning state.
-#pragma warning(disable:4996) // Temporarily disables warning 4996.
- const char* temp_dir = getenv("TEMP");
-#pragma warning(pop) // Restores the warning state.
-
+ const char* temp_dir = posix::getenv("TEMP");
if (temp_dir == NULL || temp_dir[0] == '\0')
return String("\\temp\\");
else if (String(temp_dir).EndsWith("\\"))
@@ -478,16 +463,7 @@ class DirectoryCreationTest : public Test {
}
void CreateTextFile(const char* filename) {
-#if GTEST_OS_WINDOWS
- // MSVC 8 deprecates fopen(), so we want to suppress warning 4996
- // (deprecated function) there.#pragma warning(push)
-#pragma warning(push) // Saves the current warning state.
-#pragma warning(disable:4996) // Temporarily disables warning 4996.
- FILE* f = fopen(filename, "w");
-#pragma warning(pop) // Restores the warning state.
-#else // We are on Linux or Mac OS.
- FILE* f = fopen(filename, "w");
-#endif // GTEST_OS_WINDOWS
+ FILE* f = posix::fopen(filename, "w");
fprintf(f, "text\n");
fclose(f);
}
diff --git a/test/gtest-options_test.cc b/test/gtest-options_test.cc
index 27a6fe54..d49efe49 100644
--- a/test/gtest-options_test.cc
+++ b/test/gtest-options_test.cc
@@ -150,22 +150,14 @@ class XmlOutputChangeDirTest : public Test {
protected:
virtual void SetUp() {
original_working_dir_ = FilePath::GetCurrentDir();
- ChDir("..");
+ posix::chdir("..");
// This will make the test fail if run from the root directory.
EXPECT_STRNE(original_working_dir_.c_str(),
FilePath::GetCurrentDir().c_str());
}
virtual void TearDown() {
- ChDir(original_working_dir_.c_str());
- }
-
- void ChDir(const char* dir) {
-#if GTEST_OS_WINDOWS
- _chdir(dir);
-#else
- chdir(dir);
-#endif
+ posix::chdir(original_working_dir_.c_str());
}
FilePath original_working_dir_;
diff --git a/test/gtest_help_test.py b/test/gtest_help_test.py
index 98c8fe75..62710192 100755
--- a/test/gtest_help_test.py
+++ b/test/gtest_help_test.py
@@ -55,6 +55,7 @@ else:
PROGRAM_PATH = os.path.join(gtest_test_utils.GetBuildDir(), PROGRAM)
FLAG_PREFIX = '--gtest_'
CATCH_EXCEPTIONS_FLAG = FLAG_PREFIX + 'catch_exceptions'
+DEATH_TEST_STYLE_FLAG = FLAG_PREFIX + 'death_test_style'
# The help message must match this regex.
HELP_REGEX = re.compile(
@@ -99,8 +100,10 @@ class GTestHelpTest(unittest.TestCase):
self.assert_(HELP_REGEX.search(output), output)
if IS_WINDOWS:
self.assert_(CATCH_EXCEPTIONS_FLAG in output, output)
+ self.assert_(DEATH_TEST_STYLE_FLAG not in output, output)
else:
self.assert_(CATCH_EXCEPTIONS_FLAG not in output, output)
+ self.assert_(DEATH_TEST_STYLE_FLAG in output, output)
def testPrintsHelpWithFullFlag(self):
self.TestHelpFlag('--help')
diff --git a/test/gtest_output_test_.cc b/test/gtest_output_test_.cc
index 90d89b94..c867e159 100644
--- a/test/gtest_output_test_.cc
+++ b/test/gtest_output_test_.cc
@@ -60,6 +60,7 @@
using testing::ScopedFakeTestPartResultReporter;
using testing::TestPartResultArray;
+namespace posix = ::testing::internal::posix;
using testing::internal::String;
// Tests catching fatal failures.
@@ -989,16 +990,9 @@ int main(int argc, char **argv) {
// Skip the usual output capturing if we're running as the child
// process of an threadsafe-style death test.
#if GTEST_OS_WINDOWS
-#ifdef _MSC_VER
-#pragma warning(push)
-#pragma warning(disable:4996)
-#endif // _MSC_VER
- freopen("nul:", "w", stdout);
-#ifdef _MSC_VER
-#pragma warning(pop)
-#endif // _MSC_VER
+ posix::freopen("nul:", "w", stdout);
#else
- freopen("/dev/null", "w", stdout);
+ posix::freopen("/dev/null", "w", stdout);
#endif // GTEST_OS_WINDOWS
return RUN_ALL_TESTS();
}