Unfortunately, the svn repo is a bit out of date. This commit contains 8
changes that haven't made it to svn. The descriptions of each change are listed below. - Fixes some python shebang lines. - Add ElementsAreArray overloads to gmock. ElementsAreArray now makes a copy of its input elements before the conversion to a Matcher. ElementsAreArray can now take a vector as input. ElementsAreArray can now take an iterator pair as input. - Templatize MatchAndExplain to allow independent string types for the matcher and matchee. I also templatized the ConstCharPointer version of MatchAndExplain to avoid calls with "char*" from using the new templated MatchAndExplain. - Fixes the bug where the constructor of the return type of ElementsAre() saves a reference instead of a copy of the arguments. - Extends ElementsAre() to accept arrays whose sizes aren't known. - Switches gTest's internal FilePath class from testing::internal::String to std::string. testing::internal::String was introduced when gTest couldn't depend on std::string. It's now deprecated. - Switches gTest & gMock from using testing::internal::String objects to std::string. Some static methods of String are still in use. We may be able to remove some but not all of them. In particular, String::Format() should eventually be removed as it truncates the result at 4096 characters, often causing problems.
This commit is contained in:
@@ -100,7 +100,7 @@ TEST(GetCurrentDirTest, ReturnsCurrentDir) {
|
||||
|
||||
# else
|
||||
|
||||
EXPECT_STREQ(GTEST_PATH_SEP_, cwd.c_str());
|
||||
EXPECT_EQ(GTEST_PATH_SEP_, cwd.string());
|
||||
|
||||
# endif
|
||||
}
|
||||
@@ -109,7 +109,6 @@ TEST(GetCurrentDirTest, ReturnsCurrentDir) {
|
||||
|
||||
TEST(IsEmptyTest, ReturnsTrueForEmptyPath) {
|
||||
EXPECT_TRUE(FilePath("").IsEmpty());
|
||||
EXPECT_TRUE(FilePath(NULL).IsEmpty());
|
||||
}
|
||||
|
||||
TEST(IsEmptyTest, ReturnsFalseForNonEmptyPath) {
|
||||
@@ -121,38 +120,38 @@ TEST(IsEmptyTest, ReturnsFalseForNonEmptyPath) {
|
||||
|
||||
// RemoveDirectoryName "" -> ""
|
||||
TEST(RemoveDirectoryNameTest, WhenEmptyName) {
|
||||
EXPECT_STREQ("", FilePath("").RemoveDirectoryName().c_str());
|
||||
EXPECT_EQ("", FilePath("").RemoveDirectoryName().string());
|
||||
}
|
||||
|
||||
// RemoveDirectoryName "afile" -> "afile"
|
||||
TEST(RemoveDirectoryNameTest, ButNoDirectory) {
|
||||
EXPECT_STREQ("afile",
|
||||
FilePath("afile").RemoveDirectoryName().c_str());
|
||||
EXPECT_EQ("afile",
|
||||
FilePath("afile").RemoveDirectoryName().string());
|
||||
}
|
||||
|
||||
// RemoveDirectoryName "/afile" -> "afile"
|
||||
TEST(RemoveDirectoryNameTest, RootFileShouldGiveFileName) {
|
||||
EXPECT_STREQ("afile",
|
||||
FilePath(GTEST_PATH_SEP_ "afile").RemoveDirectoryName().c_str());
|
||||
EXPECT_EQ("afile",
|
||||
FilePath(GTEST_PATH_SEP_ "afile").RemoveDirectoryName().string());
|
||||
}
|
||||
|
||||
// RemoveDirectoryName "adir/" -> ""
|
||||
TEST(RemoveDirectoryNameTest, WhereThereIsNoFileName) {
|
||||
EXPECT_STREQ("",
|
||||
FilePath("adir" GTEST_PATH_SEP_).RemoveDirectoryName().c_str());
|
||||
EXPECT_EQ("",
|
||||
FilePath("adir" GTEST_PATH_SEP_).RemoveDirectoryName().string());
|
||||
}
|
||||
|
||||
// RemoveDirectoryName "adir/afile" -> "afile"
|
||||
TEST(RemoveDirectoryNameTest, ShouldGiveFileName) {
|
||||
EXPECT_STREQ("afile",
|
||||
FilePath("adir" GTEST_PATH_SEP_ "afile").RemoveDirectoryName().c_str());
|
||||
EXPECT_EQ("afile",
|
||||
FilePath("adir" GTEST_PATH_SEP_ "afile").RemoveDirectoryName().string());
|
||||
}
|
||||
|
||||
// RemoveDirectoryName "adir/subdir/afile" -> "afile"
|
||||
TEST(RemoveDirectoryNameTest, ShouldAlsoGiveFileName) {
|
||||
EXPECT_STREQ("afile",
|
||||
EXPECT_EQ("afile",
|
||||
FilePath("adir" GTEST_PATH_SEP_ "subdir" GTEST_PATH_SEP_ "afile")
|
||||
.RemoveDirectoryName().c_str());
|
||||
.RemoveDirectoryName().string());
|
||||
}
|
||||
|
||||
#if GTEST_HAS_ALT_PATH_SEP_
|
||||
@@ -162,26 +161,23 @@ TEST(RemoveDirectoryNameTest, ShouldAlsoGiveFileName) {
|
||||
|
||||
// RemoveDirectoryName("/afile") -> "afile"
|
||||
TEST(RemoveDirectoryNameTest, RootFileShouldGiveFileNameForAlternateSeparator) {
|
||||
EXPECT_STREQ("afile",
|
||||
FilePath("/afile").RemoveDirectoryName().c_str());
|
||||
EXPECT_EQ("afile", FilePath("/afile").RemoveDirectoryName().string());
|
||||
}
|
||||
|
||||
// RemoveDirectoryName("adir/") -> ""
|
||||
TEST(RemoveDirectoryNameTest, WhereThereIsNoFileNameForAlternateSeparator) {
|
||||
EXPECT_STREQ("",
|
||||
FilePath("adir/").RemoveDirectoryName().c_str());
|
||||
EXPECT_EQ("", FilePath("adir/").RemoveDirectoryName().string());
|
||||
}
|
||||
|
||||
// RemoveDirectoryName("adir/afile") -> "afile"
|
||||
TEST(RemoveDirectoryNameTest, ShouldGiveFileNameForAlternateSeparator) {
|
||||
EXPECT_STREQ("afile",
|
||||
FilePath("adir/afile").RemoveDirectoryName().c_str());
|
||||
EXPECT_EQ("afile", FilePath("adir/afile").RemoveDirectoryName().string());
|
||||
}
|
||||
|
||||
// RemoveDirectoryName("adir/subdir/afile") -> "afile"
|
||||
TEST(RemoveDirectoryNameTest, ShouldAlsoGiveFileNameForAlternateSeparator) {
|
||||
EXPECT_STREQ("afile",
|
||||
FilePath("adir/subdir/afile").RemoveDirectoryName().c_str());
|
||||
EXPECT_EQ("afile",
|
||||
FilePath("adir/subdir/afile").RemoveDirectoryName().string());
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -190,38 +186,35 @@ TEST(RemoveDirectoryNameTest, ShouldAlsoGiveFileNameForAlternateSeparator) {
|
||||
TEST(RemoveFileNameTest, EmptyName) {
|
||||
#if GTEST_OS_WINDOWS_MOBILE
|
||||
// On Windows CE, we use the root as the current directory.
|
||||
EXPECT_STREQ(GTEST_PATH_SEP_,
|
||||
FilePath("").RemoveFileName().c_str());
|
||||
EXPECT_EQ(GTEST_PATH_SEP_, FilePath("").RemoveFileName().string());
|
||||
#else
|
||||
EXPECT_STREQ("." GTEST_PATH_SEP_,
|
||||
FilePath("").RemoveFileName().c_str());
|
||||
EXPECT_EQ("." GTEST_PATH_SEP_, FilePath("").RemoveFileName().string());
|
||||
#endif
|
||||
}
|
||||
|
||||
// RemoveFileName "adir/" -> "adir/"
|
||||
TEST(RemoveFileNameTest, ButNoFile) {
|
||||
EXPECT_STREQ("adir" GTEST_PATH_SEP_,
|
||||
FilePath("adir" GTEST_PATH_SEP_).RemoveFileName().c_str());
|
||||
EXPECT_EQ("adir" GTEST_PATH_SEP_,
|
||||
FilePath("adir" GTEST_PATH_SEP_).RemoveFileName().string());
|
||||
}
|
||||
|
||||
// RemoveFileName "adir/afile" -> "adir/"
|
||||
TEST(RemoveFileNameTest, GivesDirName) {
|
||||
EXPECT_STREQ("adir" GTEST_PATH_SEP_,
|
||||
FilePath("adir" GTEST_PATH_SEP_ "afile")
|
||||
.RemoveFileName().c_str());
|
||||
EXPECT_EQ("adir" GTEST_PATH_SEP_,
|
||||
FilePath("adir" GTEST_PATH_SEP_ "afile").RemoveFileName().string());
|
||||
}
|
||||
|
||||
// RemoveFileName "adir/subdir/afile" -> "adir/subdir/"
|
||||
TEST(RemoveFileNameTest, GivesDirAndSubDirName) {
|
||||
EXPECT_STREQ("adir" GTEST_PATH_SEP_ "subdir" GTEST_PATH_SEP_,
|
||||
EXPECT_EQ("adir" GTEST_PATH_SEP_ "subdir" GTEST_PATH_SEP_,
|
||||
FilePath("adir" GTEST_PATH_SEP_ "subdir" GTEST_PATH_SEP_ "afile")
|
||||
.RemoveFileName().c_str());
|
||||
.RemoveFileName().string());
|
||||
}
|
||||
|
||||
// RemoveFileName "/afile" -> "/"
|
||||
TEST(RemoveFileNameTest, GivesRootDir) {
|
||||
EXPECT_STREQ(GTEST_PATH_SEP_,
|
||||
FilePath(GTEST_PATH_SEP_ "afile").RemoveFileName().c_str());
|
||||
EXPECT_EQ(GTEST_PATH_SEP_,
|
||||
FilePath(GTEST_PATH_SEP_ "afile").RemoveFileName().string());
|
||||
}
|
||||
|
||||
#if GTEST_HAS_ALT_PATH_SEP_
|
||||
@@ -231,26 +224,25 @@ TEST(RemoveFileNameTest, GivesRootDir) {
|
||||
|
||||
// RemoveFileName("adir/") -> "adir/"
|
||||
TEST(RemoveFileNameTest, ButNoFileForAlternateSeparator) {
|
||||
EXPECT_STREQ("adir" GTEST_PATH_SEP_,
|
||||
FilePath("adir/").RemoveFileName().c_str());
|
||||
EXPECT_EQ("adir" GTEST_PATH_SEP_,
|
||||
FilePath("adir/").RemoveFileName().string());
|
||||
}
|
||||
|
||||
// RemoveFileName("adir/afile") -> "adir/"
|
||||
TEST(RemoveFileNameTest, GivesDirNameForAlternateSeparator) {
|
||||
EXPECT_STREQ("adir" GTEST_PATH_SEP_,
|
||||
FilePath("adir/afile").RemoveFileName().c_str());
|
||||
EXPECT_EQ("adir" GTEST_PATH_SEP_,
|
||||
FilePath("adir/afile").RemoveFileName().string());
|
||||
}
|
||||
|
||||
// RemoveFileName("adir/subdir/afile") -> "adir/subdir/"
|
||||
TEST(RemoveFileNameTest, GivesDirAndSubDirNameForAlternateSeparator) {
|
||||
EXPECT_STREQ("adir" GTEST_PATH_SEP_ "subdir" GTEST_PATH_SEP_,
|
||||
FilePath("adir/subdir/afile").RemoveFileName().c_str());
|
||||
EXPECT_EQ("adir" GTEST_PATH_SEP_ "subdir" GTEST_PATH_SEP_,
|
||||
FilePath("adir/subdir/afile").RemoveFileName().string());
|
||||
}
|
||||
|
||||
// RemoveFileName("/afile") -> "\"
|
||||
TEST(RemoveFileNameTest, GivesRootDirForAlternateSeparator) {
|
||||
EXPECT_STREQ(GTEST_PATH_SEP_,
|
||||
FilePath("/afile").RemoveFileName().c_str());
|
||||
EXPECT_EQ(GTEST_PATH_SEP_, FilePath("/afile").RemoveFileName().string());
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -258,125 +250,120 @@ TEST(RemoveFileNameTest, GivesRootDirForAlternateSeparator) {
|
||||
TEST(MakeFileNameTest, GenerateWhenNumberIsZero) {
|
||||
FilePath actual = FilePath::MakeFileName(FilePath("foo"), FilePath("bar"),
|
||||
0, "xml");
|
||||
EXPECT_STREQ("foo" GTEST_PATH_SEP_ "bar.xml", actual.c_str());
|
||||
EXPECT_EQ("foo" GTEST_PATH_SEP_ "bar.xml", actual.string());
|
||||
}
|
||||
|
||||
TEST(MakeFileNameTest, GenerateFileNameNumberGtZero) {
|
||||
FilePath actual = FilePath::MakeFileName(FilePath("foo"), FilePath("bar"),
|
||||
12, "xml");
|
||||
EXPECT_STREQ("foo" GTEST_PATH_SEP_ "bar_12.xml", actual.c_str());
|
||||
EXPECT_EQ("foo" GTEST_PATH_SEP_ "bar_12.xml", actual.string());
|
||||
}
|
||||
|
||||
TEST(MakeFileNameTest, GenerateFileNameWithSlashNumberIsZero) {
|
||||
FilePath actual = FilePath::MakeFileName(FilePath("foo" GTEST_PATH_SEP_),
|
||||
FilePath("bar"), 0, "xml");
|
||||
EXPECT_STREQ("foo" GTEST_PATH_SEP_ "bar.xml", actual.c_str());
|
||||
EXPECT_EQ("foo" GTEST_PATH_SEP_ "bar.xml", actual.string());
|
||||
}
|
||||
|
||||
TEST(MakeFileNameTest, GenerateFileNameWithSlashNumberGtZero) {
|
||||
FilePath actual = FilePath::MakeFileName(FilePath("foo" GTEST_PATH_SEP_),
|
||||
FilePath("bar"), 12, "xml");
|
||||
EXPECT_STREQ("foo" GTEST_PATH_SEP_ "bar_12.xml", actual.c_str());
|
||||
EXPECT_EQ("foo" GTEST_PATH_SEP_ "bar_12.xml", actual.string());
|
||||
}
|
||||
|
||||
TEST(MakeFileNameTest, GenerateWhenNumberIsZeroAndDirIsEmpty) {
|
||||
FilePath actual = FilePath::MakeFileName(FilePath(""), FilePath("bar"),
|
||||
0, "xml");
|
||||
EXPECT_STREQ("bar.xml", actual.c_str());
|
||||
EXPECT_EQ("bar.xml", actual.string());
|
||||
}
|
||||
|
||||
TEST(MakeFileNameTest, GenerateWhenNumberIsNotZeroAndDirIsEmpty) {
|
||||
FilePath actual = FilePath::MakeFileName(FilePath(""), FilePath("bar"),
|
||||
14, "xml");
|
||||
EXPECT_STREQ("bar_14.xml", actual.c_str());
|
||||
EXPECT_EQ("bar_14.xml", actual.string());
|
||||
}
|
||||
|
||||
TEST(ConcatPathsTest, WorksWhenDirDoesNotEndWithPathSep) {
|
||||
FilePath actual = FilePath::ConcatPaths(FilePath("foo"),
|
||||
FilePath("bar.xml"));
|
||||
EXPECT_STREQ("foo" GTEST_PATH_SEP_ "bar.xml", actual.c_str());
|
||||
EXPECT_EQ("foo" GTEST_PATH_SEP_ "bar.xml", actual.string());
|
||||
}
|
||||
|
||||
TEST(ConcatPathsTest, WorksWhenPath1EndsWithPathSep) {
|
||||
FilePath actual = FilePath::ConcatPaths(FilePath("foo" GTEST_PATH_SEP_),
|
||||
FilePath("bar.xml"));
|
||||
EXPECT_STREQ("foo" GTEST_PATH_SEP_ "bar.xml", actual.c_str());
|
||||
EXPECT_EQ("foo" GTEST_PATH_SEP_ "bar.xml", actual.string());
|
||||
}
|
||||
|
||||
TEST(ConcatPathsTest, Path1BeingEmpty) {
|
||||
FilePath actual = FilePath::ConcatPaths(FilePath(""),
|
||||
FilePath("bar.xml"));
|
||||
EXPECT_STREQ("bar.xml", actual.c_str());
|
||||
EXPECT_EQ("bar.xml", actual.string());
|
||||
}
|
||||
|
||||
TEST(ConcatPathsTest, Path2BeingEmpty) {
|
||||
FilePath actual = FilePath::ConcatPaths(FilePath("foo"),
|
||||
FilePath(""));
|
||||
EXPECT_STREQ("foo" GTEST_PATH_SEP_, actual.c_str());
|
||||
FilePath actual = FilePath::ConcatPaths(FilePath("foo"), FilePath(""));
|
||||
EXPECT_EQ("foo" GTEST_PATH_SEP_, actual.string());
|
||||
}
|
||||
|
||||
TEST(ConcatPathsTest, BothPathBeingEmpty) {
|
||||
FilePath actual = FilePath::ConcatPaths(FilePath(""),
|
||||
FilePath(""));
|
||||
EXPECT_STREQ("", actual.c_str());
|
||||
EXPECT_EQ("", actual.string());
|
||||
}
|
||||
|
||||
TEST(ConcatPathsTest, Path1ContainsPathSep) {
|
||||
FilePath actual = FilePath::ConcatPaths(FilePath("foo" GTEST_PATH_SEP_ "bar"),
|
||||
FilePath("foobar.xml"));
|
||||
EXPECT_STREQ("foo" GTEST_PATH_SEP_ "bar" GTEST_PATH_SEP_ "foobar.xml",
|
||||
actual.c_str());
|
||||
EXPECT_EQ("foo" GTEST_PATH_SEP_ "bar" GTEST_PATH_SEP_ "foobar.xml",
|
||||
actual.string());
|
||||
}
|
||||
|
||||
TEST(ConcatPathsTest, Path2ContainsPathSep) {
|
||||
FilePath actual = FilePath::ConcatPaths(
|
||||
FilePath("foo" GTEST_PATH_SEP_),
|
||||
FilePath("bar" GTEST_PATH_SEP_ "bar.xml"));
|
||||
EXPECT_STREQ("foo" GTEST_PATH_SEP_ "bar" GTEST_PATH_SEP_ "bar.xml",
|
||||
actual.c_str());
|
||||
EXPECT_EQ("foo" GTEST_PATH_SEP_ "bar" GTEST_PATH_SEP_ "bar.xml",
|
||||
actual.string());
|
||||
}
|
||||
|
||||
TEST(ConcatPathsTest, Path2EndsWithPathSep) {
|
||||
FilePath actual = FilePath::ConcatPaths(FilePath("foo"),
|
||||
FilePath("bar" GTEST_PATH_SEP_));
|
||||
EXPECT_STREQ("foo" GTEST_PATH_SEP_ "bar" GTEST_PATH_SEP_, actual.c_str());
|
||||
EXPECT_EQ("foo" GTEST_PATH_SEP_ "bar" GTEST_PATH_SEP_, actual.string());
|
||||
}
|
||||
|
||||
// RemoveTrailingPathSeparator "" -> ""
|
||||
TEST(RemoveTrailingPathSeparatorTest, EmptyString) {
|
||||
EXPECT_STREQ("",
|
||||
FilePath("").RemoveTrailingPathSeparator().c_str());
|
||||
EXPECT_EQ("", FilePath("").RemoveTrailingPathSeparator().string());
|
||||
}
|
||||
|
||||
// RemoveTrailingPathSeparator "foo" -> "foo"
|
||||
TEST(RemoveTrailingPathSeparatorTest, FileNoSlashString) {
|
||||
EXPECT_STREQ("foo",
|
||||
FilePath("foo").RemoveTrailingPathSeparator().c_str());
|
||||
EXPECT_EQ("foo", FilePath("foo").RemoveTrailingPathSeparator().string());
|
||||
}
|
||||
|
||||
// RemoveTrailingPathSeparator "foo/" -> "foo"
|
||||
TEST(RemoveTrailingPathSeparatorTest, ShouldRemoveTrailingSeparator) {
|
||||
EXPECT_STREQ(
|
||||
"foo",
|
||||
FilePath("foo" GTEST_PATH_SEP_).RemoveTrailingPathSeparator().c_str());
|
||||
EXPECT_EQ("foo",
|
||||
FilePath("foo" GTEST_PATH_SEP_).RemoveTrailingPathSeparator().string());
|
||||
#if GTEST_HAS_ALT_PATH_SEP_
|
||||
EXPECT_STREQ("foo",
|
||||
FilePath("foo/").RemoveTrailingPathSeparator().c_str());
|
||||
EXPECT_EQ("foo", FilePath("foo/").RemoveTrailingPathSeparator().string());
|
||||
#endif
|
||||
}
|
||||
|
||||
// RemoveTrailingPathSeparator "foo/bar/" -> "foo/bar/"
|
||||
TEST(RemoveTrailingPathSeparatorTest, ShouldRemoveLastSeparator) {
|
||||
EXPECT_STREQ("foo" GTEST_PATH_SEP_ "bar",
|
||||
FilePath("foo" GTEST_PATH_SEP_ "bar" GTEST_PATH_SEP_)
|
||||
.RemoveTrailingPathSeparator().c_str());
|
||||
EXPECT_EQ("foo" GTEST_PATH_SEP_ "bar",
|
||||
FilePath("foo" GTEST_PATH_SEP_ "bar" GTEST_PATH_SEP_)
|
||||
.RemoveTrailingPathSeparator().string());
|
||||
}
|
||||
|
||||
// RemoveTrailingPathSeparator "foo/bar" -> "foo/bar"
|
||||
TEST(RemoveTrailingPathSeparatorTest, ShouldReturnUnmodified) {
|
||||
EXPECT_STREQ("foo" GTEST_PATH_SEP_ "bar",
|
||||
FilePath("foo" GTEST_PATH_SEP_ "bar")
|
||||
.RemoveTrailingPathSeparator().c_str());
|
||||
EXPECT_EQ("foo" GTEST_PATH_SEP_ "bar",
|
||||
FilePath("foo" GTEST_PATH_SEP_ "bar")
|
||||
.RemoveTrailingPathSeparator().string());
|
||||
}
|
||||
|
||||
TEST(DirectoryTest, RootDirectoryExists) {
|
||||
@@ -431,40 +418,35 @@ TEST(DirectoryTest, CurrentDirectoryExists) {
|
||||
#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" GTEST_PATH_SEP_ "bar",
|
||||
FilePath("foo" GTEST_PATH_SEP_ "bar").c_str());
|
||||
EXPECT_STREQ("foo" GTEST_PATH_SEP_ "bar",
|
||||
FilePath("foo" GTEST_PATH_SEP_ GTEST_PATH_SEP_ "bar").c_str());
|
||||
EXPECT_STREQ("foo" GTEST_PATH_SEP_ "bar",
|
||||
FilePath("foo" GTEST_PATH_SEP_ GTEST_PATH_SEP_
|
||||
GTEST_PATH_SEP_ "bar").c_str());
|
||||
EXPECT_EQ("foo" GTEST_PATH_SEP_ "bar",
|
||||
FilePath("foo" GTEST_PATH_SEP_ "bar").string());
|
||||
EXPECT_EQ("foo" GTEST_PATH_SEP_ "bar",
|
||||
FilePath("foo" GTEST_PATH_SEP_ GTEST_PATH_SEP_ "bar").string());
|
||||
EXPECT_EQ("foo" GTEST_PATH_SEP_ "bar",
|
||||
FilePath("foo" GTEST_PATH_SEP_ GTEST_PATH_SEP_
|
||||
GTEST_PATH_SEP_ "bar").string());
|
||||
}
|
||||
|
||||
// "/bar" == //bar" == "///bar"
|
||||
TEST(NormalizeTest, MultipleConsecutiveSepaparatorsAtStringStart) {
|
||||
EXPECT_STREQ(GTEST_PATH_SEP_ "bar",
|
||||
FilePath(GTEST_PATH_SEP_ "bar").c_str());
|
||||
EXPECT_STREQ(GTEST_PATH_SEP_ "bar",
|
||||
FilePath(GTEST_PATH_SEP_ GTEST_PATH_SEP_ "bar").c_str());
|
||||
EXPECT_STREQ(GTEST_PATH_SEP_ "bar",
|
||||
FilePath(GTEST_PATH_SEP_ GTEST_PATH_SEP_ GTEST_PATH_SEP_ "bar").c_str());
|
||||
EXPECT_EQ(GTEST_PATH_SEP_ "bar",
|
||||
FilePath(GTEST_PATH_SEP_ "bar").string());
|
||||
EXPECT_EQ(GTEST_PATH_SEP_ "bar",
|
||||
FilePath(GTEST_PATH_SEP_ GTEST_PATH_SEP_ "bar").string());
|
||||
EXPECT_EQ(GTEST_PATH_SEP_ "bar",
|
||||
FilePath(GTEST_PATH_SEP_ GTEST_PATH_SEP_ GTEST_PATH_SEP_ "bar").string());
|
||||
}
|
||||
|
||||
// "foo/" == foo//" == "foo///"
|
||||
TEST(NormalizeTest, MultipleConsecutiveSepaparatorsAtStringEnd) {
|
||||
EXPECT_STREQ("foo" GTEST_PATH_SEP_,
|
||||
FilePath("foo" GTEST_PATH_SEP_).c_str());
|
||||
EXPECT_STREQ("foo" GTEST_PATH_SEP_,
|
||||
FilePath("foo" GTEST_PATH_SEP_ GTEST_PATH_SEP_).c_str());
|
||||
EXPECT_STREQ("foo" GTEST_PATH_SEP_,
|
||||
FilePath("foo" GTEST_PATH_SEP_ GTEST_PATH_SEP_ GTEST_PATH_SEP_).c_str());
|
||||
EXPECT_EQ("foo" GTEST_PATH_SEP_,
|
||||
FilePath("foo" GTEST_PATH_SEP_).string());
|
||||
EXPECT_EQ("foo" GTEST_PATH_SEP_,
|
||||
FilePath("foo" GTEST_PATH_SEP_ GTEST_PATH_SEP_).string());
|
||||
EXPECT_EQ("foo" GTEST_PATH_SEP_,
|
||||
FilePath("foo" GTEST_PATH_SEP_ GTEST_PATH_SEP_ GTEST_PATH_SEP_).string());
|
||||
}
|
||||
|
||||
#if GTEST_HAS_ALT_PATH_SEP_
|
||||
@@ -473,12 +455,12 @@ TEST(NormalizeTest, MultipleConsecutiveSepaparatorsAtStringEnd) {
|
||||
// regardless of their combination (e.g. "foo\" =="foo/\" ==
|
||||
// "foo\\/").
|
||||
TEST(NormalizeTest, MixAlternateSeparatorAtStringEnd) {
|
||||
EXPECT_STREQ("foo" GTEST_PATH_SEP_,
|
||||
FilePath("foo/").c_str());
|
||||
EXPECT_STREQ("foo" GTEST_PATH_SEP_,
|
||||
FilePath("foo" GTEST_PATH_SEP_ "/").c_str());
|
||||
EXPECT_STREQ("foo" GTEST_PATH_SEP_,
|
||||
FilePath("foo//" GTEST_PATH_SEP_).c_str());
|
||||
EXPECT_EQ("foo" GTEST_PATH_SEP_,
|
||||
FilePath("foo/").string());
|
||||
EXPECT_EQ("foo" GTEST_PATH_SEP_,
|
||||
FilePath("foo" GTEST_PATH_SEP_ "/").string());
|
||||
EXPECT_EQ("foo" GTEST_PATH_SEP_,
|
||||
FilePath("foo//" GTEST_PATH_SEP_).string());
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -487,31 +469,31 @@ 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.
|
||||
EXPECT_EQ("", non_default_path.string());
|
||||
EXPECT_EQ("", default_path.string()); // 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.
|
||||
EXPECT_EQ("path", default_path.string());
|
||||
EXPECT_EQ("path", non_default_path.string()); // 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());
|
||||
EXPECT_EQ("const_path", non_default_path.string());
|
||||
}
|
||||
|
||||
class DirectoryCreationTest : public Test {
|
||||
protected:
|
||||
virtual void SetUp() {
|
||||
testdata_path_.Set(FilePath(String::Format("%s%s%s",
|
||||
TempDir().c_str(), GetCurrentExecutableName().c_str(),
|
||||
"_directory_creation" GTEST_PATH_SEP_ "test" GTEST_PATH_SEP_)));
|
||||
testdata_path_.Set(FilePath(
|
||||
TempDir() + GetCurrentExecutableName().string() +
|
||||
"_directory_creation" GTEST_PATH_SEP_ "test" GTEST_PATH_SEP_));
|
||||
testdata_file_.Set(testdata_path_.RemoveTrailingPathSeparator());
|
||||
|
||||
unique_file0_.Set(FilePath::MakeFileName(testdata_path_, FilePath("unique"),
|
||||
@@ -532,21 +514,21 @@ class DirectoryCreationTest : public Test {
|
||||
posix::RmDir(testdata_path_.c_str());
|
||||
}
|
||||
|
||||
String TempDir() const {
|
||||
std::string TempDir() const {
|
||||
#if GTEST_OS_WINDOWS_MOBILE
|
||||
return String("\\temp\\");
|
||||
return "\\temp\\";
|
||||
#elif GTEST_OS_WINDOWS
|
||||
const char* temp_dir = posix::GetEnv("TEMP");
|
||||
if (temp_dir == NULL || temp_dir[0] == '\0')
|
||||
return String("\\temp\\");
|
||||
else if (String(temp_dir).EndsWith("\\"))
|
||||
return String(temp_dir);
|
||||
return "\\temp\\";
|
||||
else if (temp_dir[strlen(temp_dir) - 1] == '\\')
|
||||
return temp_dir;
|
||||
else
|
||||
return String::Format("%s\\", temp_dir);
|
||||
return std::string(temp_dir) + "\\";
|
||||
#elif GTEST_OS_LINUX_ANDROID
|
||||
return String("/sdcard/");
|
||||
return "/sdcard/";
|
||||
#else
|
||||
return String("/tmp/");
|
||||
return "/tmp/";
|
||||
#endif // GTEST_OS_WINDOWS_MOBILE
|
||||
}
|
||||
|
||||
@@ -566,13 +548,13 @@ class DirectoryCreationTest : public Test {
|
||||
};
|
||||
|
||||
TEST_F(DirectoryCreationTest, CreateDirectoriesRecursively) {
|
||||
EXPECT_FALSE(testdata_path_.DirectoryExists()) << testdata_path_.c_str();
|
||||
EXPECT_FALSE(testdata_path_.DirectoryExists()) << testdata_path_.string();
|
||||
EXPECT_TRUE(testdata_path_.CreateDirectoriesRecursively());
|
||||
EXPECT_TRUE(testdata_path_.DirectoryExists());
|
||||
}
|
||||
|
||||
TEST_F(DirectoryCreationTest, CreateDirectoriesForAlreadyExistingPath) {
|
||||
EXPECT_FALSE(testdata_path_.DirectoryExists()) << testdata_path_.c_str();
|
||||
EXPECT_FALSE(testdata_path_.DirectoryExists()) << testdata_path_.string();
|
||||
EXPECT_TRUE(testdata_path_.CreateDirectoriesRecursively());
|
||||
// Call 'create' again... should still succeed.
|
||||
EXPECT_TRUE(testdata_path_.CreateDirectoriesRecursively());
|
||||
@@ -581,7 +563,7 @@ TEST_F(DirectoryCreationTest, CreateDirectoriesForAlreadyExistingPath) {
|
||||
TEST_F(DirectoryCreationTest, CreateDirectoriesAndUniqueFilename) {
|
||||
FilePath file_path(FilePath::GenerateUniqueFileName(testdata_path_,
|
||||
FilePath("unique"), "txt"));
|
||||
EXPECT_STREQ(unique_file0_.c_str(), file_path.c_str());
|
||||
EXPECT_EQ(unique_file0_.string(), file_path.string());
|
||||
EXPECT_FALSE(file_path.FileOrDirectoryExists()); // file not there
|
||||
|
||||
testdata_path_.CreateDirectoriesRecursively();
|
||||
@@ -591,7 +573,7 @@ TEST_F(DirectoryCreationTest, CreateDirectoriesAndUniqueFilename) {
|
||||
|
||||
FilePath file_path2(FilePath::GenerateUniqueFileName(testdata_path_,
|
||||
FilePath("unique"), "txt"));
|
||||
EXPECT_STREQ(unique_file1_.c_str(), file_path2.c_str());
|
||||
EXPECT_EQ(unique_file1_.string(), file_path2.string());
|
||||
EXPECT_FALSE(file_path2.FileOrDirectoryExists()); // file not there
|
||||
CreateTextFile(file_path2.c_str());
|
||||
EXPECT_TRUE(file_path2.FileOrDirectoryExists());
|
||||
@@ -612,43 +594,43 @@ TEST(NoDirectoryCreationTest, CreateNoDirectoriesForDefaultXmlFile) {
|
||||
|
||||
TEST(FilePathTest, DefaultConstructor) {
|
||||
FilePath fp;
|
||||
EXPECT_STREQ("", fp.c_str());
|
||||
EXPECT_EQ("", fp.string());
|
||||
}
|
||||
|
||||
TEST(FilePathTest, CharAndCopyConstructors) {
|
||||
const FilePath fp("spicy");
|
||||
EXPECT_STREQ("spicy", fp.c_str());
|
||||
EXPECT_EQ("spicy", fp.string());
|
||||
|
||||
const FilePath fp_copy(fp);
|
||||
EXPECT_STREQ("spicy", fp_copy.c_str());
|
||||
EXPECT_EQ("spicy", fp_copy.string());
|
||||
}
|
||||
|
||||
TEST(FilePathTest, StringConstructor) {
|
||||
const FilePath fp(String("cider"));
|
||||
EXPECT_STREQ("cider", fp.c_str());
|
||||
const FilePath fp(std::string("cider"));
|
||||
EXPECT_EQ("cider", fp.string());
|
||||
}
|
||||
|
||||
TEST(FilePathTest, Set) {
|
||||
const FilePath apple("apple");
|
||||
FilePath mac("mac");
|
||||
mac.Set(apple); // Implement Set() since overloading operator= is forbidden.
|
||||
EXPECT_STREQ("apple", mac.c_str());
|
||||
EXPECT_STREQ("apple", apple.c_str());
|
||||
EXPECT_EQ("apple", mac.string());
|
||||
EXPECT_EQ("apple", apple.string());
|
||||
}
|
||||
|
||||
TEST(FilePathTest, ToString) {
|
||||
const FilePath file("drink");
|
||||
String str(file.ToString());
|
||||
EXPECT_STREQ("drink", str.c_str());
|
||||
EXPECT_EQ("drink", file.string());
|
||||
}
|
||||
|
||||
TEST(FilePathTest, RemoveExtension) {
|
||||
EXPECT_STREQ("app", FilePath("app.exe").RemoveExtension("exe").c_str());
|
||||
EXPECT_STREQ("APP", FilePath("APP.EXE").RemoveExtension("exe").c_str());
|
||||
EXPECT_EQ("app", FilePath("app.cc").RemoveExtension("cc").string());
|
||||
EXPECT_EQ("app", FilePath("app.exe").RemoveExtension("exe").string());
|
||||
EXPECT_EQ("APP", FilePath("APP.EXE").RemoveExtension("exe").string());
|
||||
}
|
||||
|
||||
TEST(FilePathTest, RemoveExtensionWhenThereIsNoExtension) {
|
||||
EXPECT_STREQ("app", FilePath("app").RemoveExtension("exe").c_str());
|
||||
EXPECT_EQ("app", FilePath("app").RemoveExtension("exe").string());
|
||||
}
|
||||
|
||||
TEST(FilePathTest, IsDirectory) {
|
||||
|
||||
Reference in New Issue
Block a user