summaryrefslogtreecommitdiffstats
path: root/test/gtest-filepath_test.cc
diff options
context:
space:
mode:
authorshiqian <shiqian@861a406c-534a-0410-8894-cb66d6ee9925>2008-09-26 16:08:30 (GMT)
committershiqian <shiqian@861a406c-534a-0410-8894-cb66d6ee9925>2008-09-26 16:08:30 (GMT)
commit64cdcb69b28fc26e78d95c574187f7dd9830c84c (patch)
tree68f49941b72ce8f866c4f762cb3043504804800f /test/gtest-filepath_test.cc
parente79c3ccb73d68543e8ad98d69179dee74abff7ab (diff)
downloadgoogletest-64cdcb69b28fc26e78d95c574187f7dd9830c84c.zip
googletest-64cdcb69b28fc26e78d95c574187f7dd9830c84c.tar.gz
googletest-64cdcb69b28fc26e78d95c574187f7dd9830c84c.tar.bz2
Lots of changes:
* changes the XML report format to match JUnit/Ant's. * improves file path handling. * allows the user to disable RTTI using the GTEST_HAS_RTTI macro. * makes the code compile with -Wswitch-enum.
Diffstat (limited to 'test/gtest-filepath_test.cc')
-rw-r--r--test/gtest-filepath_test.cc106
1 files changed, 104 insertions, 2 deletions
diff --git a/test/gtest-filepath_test.cc b/test/gtest-filepath_test.cc
index 603427c..ae5e3fb 100644
--- a/test/gtest-filepath_test.cc
+++ b/test/gtest-filepath_test.cc
@@ -123,8 +123,6 @@ TEST(IsEmptyTest, ReturnsFalseForNonEmptyPath) {
EXPECT_FALSE(FilePath("a\\b\\").IsEmpty());
}
-// FilePath's functions used by UnitTestOptions::GetOutputFile.
-
// RemoveDirectoryName "" -> ""
TEST(RemoveDirectoryNameTest, WhenEmptyName) {
EXPECT_STREQ("", FilePath("").RemoveDirectoryName().c_str());
@@ -257,6 +255,110 @@ TEST(RemoveTrailingPathSeparatorTest, ShouldReturnUnmodified) {
FilePath("foo" PATH_SEP "bar").RemoveTrailingPathSeparator().c_str());
}
+TEST(DirectoryTest, RootDirectoryExists) {
+#ifdef GTEST_OS_WINDOWS // We are on Windows.
+ char current_drive[_MAX_PATH];
+ current_drive[0] = _getdrive() + 'A' - 1;
+ current_drive[1] = ':';
+ current_drive[2] = '\\';
+ current_drive[3] = '\0';
+ EXPECT_TRUE(FilePath(current_drive).DirectoryExists());
+#else
+ EXPECT_TRUE(FilePath("/").DirectoryExists());
+#endif // GTEST_OS_WINDOWS
+}
+
+#ifdef GTEST_OS_WINDOWS
+TEST(DirectoryTest, RootOfWrongDriveDoesNotExists) {
+ const int saved_drive_ = _getdrive();
+ // Find a drive that doesn't exist. Start with 'Z' to avoid common ones.
+ for (char drive = 'Z'; drive >= 'A'; drive--)
+ if (_chdrive(drive - 'A' + 1) == -1) {
+ char non_drive[_MAX_PATH];
+ non_drive[0] = drive;
+ non_drive[1] = ':';
+ non_drive[2] = '\\';
+ non_drive[3] = '\0';
+ EXPECT_FALSE(FilePath(non_drive).DirectoryExists());
+ break;
+ }
+ _chdrive(saved_drive_);
+}
+#endif // GTEST_OS_WINDOWS
+
+TEST(DirectoryTest, EmptyPathDirectoryDoesNotExist) {
+ EXPECT_FALSE(FilePath("").DirectoryExists());
+}
+
+TEST(DirectoryTest, CurrentDirectoryExists) {
+#ifdef GTEST_OS_WINDOWS // We are on Windows.
+#ifndef _WIN32_CE // Windows CE doesn't have a current directory.
+ EXPECT_TRUE(FilePath(".").DirectoryExists());
+ EXPECT_TRUE(FilePath(".\\").DirectoryExists());
+#endif // _WIN32_CE
+#else
+ EXPECT_TRUE(FilePath(".").DirectoryExists());
+ EXPECT_TRUE(FilePath("./").DirectoryExists());
+#endif // GTEST_OS_WINDOWS
+}
+
+TEST(NormalizeTest, NullStringsEqualEmptyDirectory) {
+ EXPECT_STREQ("", FilePath(NULL).c_str());
+ EXPECT_STREQ("", FilePath(String(NULL)).c_str());
+}
+
+// "foo/bar" == foo//bar" == "foo///bar"
+TEST(NormalizeTest, MultipleConsecutiveSepaparatorsInMidstring) {
+ EXPECT_STREQ("foo" PATH_SEP "bar",
+ FilePath("foo" PATH_SEP "bar").c_str());
+ EXPECT_STREQ("foo" PATH_SEP "bar",
+ FilePath("foo" PATH_SEP PATH_SEP "bar").c_str());
+ EXPECT_STREQ("foo" PATH_SEP "bar",
+ FilePath("foo" PATH_SEP PATH_SEP PATH_SEP "bar").c_str());
+}
+
+// "/bar" == //bar" == "///bar"
+TEST(NormalizeTest, MultipleConsecutiveSepaparatorsAtStringStart) {
+ EXPECT_STREQ(PATH_SEP "bar",
+ FilePath(PATH_SEP "bar").c_str());
+ EXPECT_STREQ(PATH_SEP "bar",
+ FilePath(PATH_SEP PATH_SEP "bar").c_str());
+ EXPECT_STREQ(PATH_SEP "bar",
+ FilePath(PATH_SEP PATH_SEP PATH_SEP "bar").c_str());
+}
+
+// "foo/" == foo//" == "foo///"
+TEST(NormalizeTest, MultipleConsecutiveSepaparatorsAtStringEnd) {
+ EXPECT_STREQ("foo" PATH_SEP,
+ FilePath("foo" PATH_SEP).c_str());
+ EXPECT_STREQ("foo" PATH_SEP,
+ FilePath("foo" PATH_SEP PATH_SEP).c_str());
+ EXPECT_STREQ("foo" PATH_SEP,
+ FilePath("foo" PATH_SEP PATH_SEP PATH_SEP).c_str());
+}
+
+TEST(AssignmentOperatorTest, DefaultAssignedToNonDefault) {
+ FilePath default_path;
+ FilePath non_default_path("path");
+ non_default_path = default_path;
+ EXPECT_STREQ("", non_default_path.c_str());
+ EXPECT_STREQ("", default_path.c_str()); // RHS var is unchanged.
+}
+
+TEST(AssignmentOperatorTest, NonDefaultAssignedToDefault) {
+ FilePath non_default_path("path");
+ FilePath default_path;
+ default_path = non_default_path;
+ EXPECT_STREQ("path", default_path.c_str());
+ EXPECT_STREQ("path", non_default_path.c_str()); // RHS var is unchanged.
+}
+
+TEST(AssignmentOperatorTest, ConstAssignedToNonConst) {
+ const FilePath const_default_path("const_path");
+ FilePath non_default_path("path");
+ non_default_path = const_default_path;
+ EXPECT_STREQ("const_path", non_default_path.c_str());
+}
class DirectoryCreationTest : public Test {
protected: