"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "googletest/test/googletest-filepath-test.cc" between
googletest-release-1.11.0.tar.gz and googletest-release-1.12.0.tar.gz

About: GoogleTest is Google's (unit) testing and mocking framework for C++ tests.

googletest-filepath-test.cc  (googletest-release-1.11.0):googletest-filepath-test.cc  (googletest-release-1.12.0)
skipping to change at line 38 skipping to change at line 38
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// //
// Google Test filepath utilities // Google Test filepath utilities
// //
// This file tests classes and functions used internally by // This file tests classes and functions used internally by
// Google Test. They are subject to change without notice. // Google Test. They are subject to change without notice.
// //
// This file is #included from gtest-internal.h. // This file is #included from gtest-internal.h.
// Do not #include this file anywhere else! // Do not #include this file anywhere else!
#include "gtest/internal/gtest-filepath.h"
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "gtest/internal/gtest-filepath.h"
#include "src/gtest-internal-inl.h" #include "src/gtest-internal-inl.h"
#if GTEST_OS_WINDOWS_MOBILE #if GTEST_OS_WINDOWS_MOBILE
# include <windows.h> // NOLINT #include <windows.h> // NOLINT
#elif GTEST_OS_WINDOWS #elif GTEST_OS_WINDOWS
# include <direct.h> // NOLINT #include <direct.h> // NOLINT
#endif // GTEST_OS_WINDOWS_MOBILE #endif // GTEST_OS_WINDOWS_MOBILE
namespace testing { namespace testing {
namespace internal { namespace internal {
namespace { namespace {
#if GTEST_OS_WINDOWS_MOBILE #if GTEST_OS_WINDOWS_MOBILE
// Windows CE doesn't have the remove C function. // Windows CE doesn't have the remove C function.
int remove(const char* path) { int remove(const char* path) {
LPCWSTR wpath = String::AnsiToUtf16(path); LPCWSTR wpath = String::AnsiToUtf16(path);
int ret = DeleteFile(wpath) ? 0 : -1; int ret = DeleteFile(wpath) ? 0 : -1;
delete [] wpath; delete[] wpath;
return ret; return ret;
} }
// Windows CE doesn't have the _rmdir C function. // Windows CE doesn't have the _rmdir C function.
int _rmdir(const char* path) { int _rmdir(const char* path) {
FilePath filepath(path); FilePath filepath(path);
LPCWSTR wpath = String::AnsiToUtf16( LPCWSTR wpath =
filepath.RemoveTrailingPathSeparator().c_str()); String::AnsiToUtf16(filepath.RemoveTrailingPathSeparator().c_str());
int ret = RemoveDirectory(wpath) ? 0 : -1; int ret = RemoveDirectory(wpath) ? 0 : -1;
delete [] wpath; delete[] wpath;
return ret; return ret;
} }
#else #else
TEST(GetCurrentDirTest, ReturnsCurrentDir) { TEST(GetCurrentDirTest, ReturnsCurrentDir) {
const FilePath original_dir = FilePath::GetCurrentDir(); const FilePath original_dir = FilePath::GetCurrentDir();
EXPECT_FALSE(original_dir.IsEmpty()); EXPECT_FALSE(original_dir.IsEmpty());
posix::ChDir(GTEST_PATH_SEP_); posix::ChDir(GTEST_PATH_SEP_);
const FilePath cwd = FilePath::GetCurrentDir(); const FilePath cwd = FilePath::GetCurrentDir();
posix::ChDir(original_dir.c_str()); posix::ChDir(original_dir.c_str());
# if GTEST_OS_WINDOWS || GTEST_OS_OS2 #if GTEST_OS_WINDOWS || GTEST_OS_OS2
// Skips the ":". // Skips the ":".
const char* const cwd_without_drive = strchr(cwd.c_str(), ':'); const char* const cwd_without_drive = strchr(cwd.c_str(), ':');
ASSERT_TRUE(cwd_without_drive != NULL); ASSERT_TRUE(cwd_without_drive != NULL);
EXPECT_STREQ(GTEST_PATH_SEP_, cwd_without_drive + 1); EXPECT_STREQ(GTEST_PATH_SEP_, cwd_without_drive + 1);
# else #else
EXPECT_EQ(GTEST_PATH_SEP_, cwd.string()); EXPECT_EQ(GTEST_PATH_SEP_, cwd.string());
# endif #endif
} }
#endif // GTEST_OS_WINDOWS_MOBILE #endif // GTEST_OS_WINDOWS_MOBILE
TEST(IsEmptyTest, ReturnsTrueForEmptyPath) { TEST(IsEmptyTest, ReturnsTrueForEmptyPath) {
EXPECT_TRUE(FilePath("").IsEmpty()); EXPECT_TRUE(FilePath("").IsEmpty());
} }
TEST(IsEmptyTest, ReturnsFalseForNonEmptyPath) { TEST(IsEmptyTest, ReturnsFalseForNonEmptyPath) {
EXPECT_FALSE(FilePath("a").IsEmpty()); EXPECT_FALSE(FilePath("a").IsEmpty());
skipping to change at line 115 skipping to change at line 115
EXPECT_FALSE(FilePath("a\\b\\").IsEmpty()); EXPECT_FALSE(FilePath("a\\b\\").IsEmpty());
} }
// RemoveDirectoryName "" -> "" // RemoveDirectoryName "" -> ""
TEST(RemoveDirectoryNameTest, WhenEmptyName) { TEST(RemoveDirectoryNameTest, WhenEmptyName) {
EXPECT_EQ("", FilePath("").RemoveDirectoryName().string()); EXPECT_EQ("", FilePath("").RemoveDirectoryName().string());
} }
// RemoveDirectoryName "afile" -> "afile" // RemoveDirectoryName "afile" -> "afile"
TEST(RemoveDirectoryNameTest, ButNoDirectory) { TEST(RemoveDirectoryNameTest, ButNoDirectory) {
EXPECT_EQ("afile", EXPECT_EQ("afile", FilePath("afile").RemoveDirectoryName().string());
FilePath("afile").RemoveDirectoryName().string());
} }
// RemoveDirectoryName "/afile" -> "afile" // RemoveDirectoryName "/afile" -> "afile"
TEST(RemoveDirectoryNameTest, RootFileShouldGiveFileName) { TEST(RemoveDirectoryNameTest, RootFileShouldGiveFileName) {
EXPECT_EQ("afile", EXPECT_EQ("afile",
FilePath(GTEST_PATH_SEP_ "afile").RemoveDirectoryName().string()); FilePath(GTEST_PATH_SEP_ "afile").RemoveDirectoryName().string());
} }
// RemoveDirectoryName "adir/" -> "" // RemoveDirectoryName "adir/" -> ""
TEST(RemoveDirectoryNameTest, WhereThereIsNoFileName) { TEST(RemoveDirectoryNameTest, WhereThereIsNoFileName) {
EXPECT_EQ("", EXPECT_EQ("",
FilePath("adir" GTEST_PATH_SEP_).RemoveDirectoryName().string()); FilePath("adir" GTEST_PATH_SEP_).RemoveDirectoryName().string());
} }
// RemoveDirectoryName "adir/afile" -> "afile" // RemoveDirectoryName "adir/afile" -> "afile"
TEST(RemoveDirectoryNameTest, ShouldGiveFileName) { TEST(RemoveDirectoryNameTest, ShouldGiveFileName) {
EXPECT_EQ("afile", EXPECT_EQ(
"afile",
FilePath("adir" GTEST_PATH_SEP_ "afile").RemoveDirectoryName().string()); FilePath("adir" GTEST_PATH_SEP_ "afile").RemoveDirectoryName().string());
} }
// RemoveDirectoryName "adir/subdir/afile" -> "afile" // RemoveDirectoryName "adir/subdir/afile" -> "afile"
TEST(RemoveDirectoryNameTest, ShouldAlsoGiveFileName) { TEST(RemoveDirectoryNameTest, ShouldAlsoGiveFileName) {
EXPECT_EQ("afile", EXPECT_EQ("afile",
FilePath("adir" GTEST_PATH_SEP_ "subdir" GTEST_PATH_SEP_ "afile") FilePath("adir" GTEST_PATH_SEP_ "subdir" GTEST_PATH_SEP_ "afile")
.RemoveDirectoryName().string()); .RemoveDirectoryName()
.string());
} }
#if GTEST_HAS_ALT_PATH_SEP_ #if GTEST_HAS_ALT_PATH_SEP_
// Tests that RemoveDirectoryName() works with the alternate separator // Tests that RemoveDirectoryName() works with the alternate separator
// on Windows. // on Windows.
// RemoveDirectoryName("/afile") -> "afile" // RemoveDirectoryName("/afile") -> "afile"
TEST(RemoveDirectoryNameTest, RootFileShouldGiveFileNameForAlternateSeparator) { TEST(RemoveDirectoryNameTest, RootFileShouldGiveFileNameForAlternateSeparator) {
EXPECT_EQ("afile", FilePath("/afile").RemoveDirectoryName().string()); EXPECT_EQ("afile", FilePath("/afile").RemoveDirectoryName().string());
skipping to change at line 185 skipping to change at line 186
// On Windows CE, we use the root as the current directory. // On Windows CE, we use the root as the current directory.
EXPECT_EQ(GTEST_PATH_SEP_, FilePath("").RemoveFileName().string()); EXPECT_EQ(GTEST_PATH_SEP_, FilePath("").RemoveFileName().string());
#else #else
EXPECT_EQ("." GTEST_PATH_SEP_, FilePath("").RemoveFileName().string()); EXPECT_EQ("." GTEST_PATH_SEP_, FilePath("").RemoveFileName().string());
#endif #endif
} }
// RemoveFileName "adir/" -> "adir/" // RemoveFileName "adir/" -> "adir/"
TEST(RemoveFileNameTest, ButNoFile) { TEST(RemoveFileNameTest, ButNoFile) {
EXPECT_EQ("adir" GTEST_PATH_SEP_, EXPECT_EQ("adir" GTEST_PATH_SEP_,
FilePath("adir" GTEST_PATH_SEP_).RemoveFileName().string()); FilePath("adir" GTEST_PATH_SEP_).RemoveFileName().string());
} }
// RemoveFileName "adir/afile" -> "adir/" // RemoveFileName "adir/afile" -> "adir/"
TEST(RemoveFileNameTest, GivesDirName) { TEST(RemoveFileNameTest, GivesDirName) {
EXPECT_EQ("adir" GTEST_PATH_SEP_, EXPECT_EQ("adir" GTEST_PATH_SEP_,
FilePath("adir" GTEST_PATH_SEP_ "afile").RemoveFileName().string()); FilePath("adir" GTEST_PATH_SEP_ "afile").RemoveFileName().string());
} }
// RemoveFileName "adir/subdir/afile" -> "adir/subdir/" // RemoveFileName "adir/subdir/afile" -> "adir/subdir/"
TEST(RemoveFileNameTest, GivesDirAndSubDirName) { TEST(RemoveFileNameTest, GivesDirAndSubDirName) {
EXPECT_EQ("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") FilePath("adir" GTEST_PATH_SEP_ "subdir" GTEST_PATH_SEP_ "afile")
.RemoveFileName().string()); .RemoveFileName()
.string());
} }
// RemoveFileName "/afile" -> "/" // RemoveFileName "/afile" -> "/"
TEST(RemoveFileNameTest, GivesRootDir) { TEST(RemoveFileNameTest, GivesRootDir) {
EXPECT_EQ(GTEST_PATH_SEP_, EXPECT_EQ(GTEST_PATH_SEP_,
FilePath(GTEST_PATH_SEP_ "afile").RemoveFileName().string()); FilePath(GTEST_PATH_SEP_ "afile").RemoveFileName().string());
} }
#if GTEST_HAS_ALT_PATH_SEP_ #if GTEST_HAS_ALT_PATH_SEP_
// Tests that RemoveFileName() works with the alternate separator on // Tests that RemoveFileName() works with the alternate separator on
// Windows. // Windows.
// RemoveFileName("adir/") -> "adir/" // RemoveFileName("adir/") -> "adir/"
TEST(RemoveFileNameTest, ButNoFileForAlternateSeparator) { TEST(RemoveFileNameTest, ButNoFileForAlternateSeparator) {
EXPECT_EQ("adir" GTEST_PATH_SEP_, EXPECT_EQ("adir" GTEST_PATH_SEP_,
skipping to change at line 238 skipping to change at line 240
} }
// RemoveFileName("/afile") -> "\" // RemoveFileName("/afile") -> "\"
TEST(RemoveFileNameTest, GivesRootDirForAlternateSeparator) { TEST(RemoveFileNameTest, GivesRootDirForAlternateSeparator) {
EXPECT_EQ(GTEST_PATH_SEP_, FilePath("/afile").RemoveFileName().string()); EXPECT_EQ(GTEST_PATH_SEP_, FilePath("/afile").RemoveFileName().string());
} }
#endif #endif
TEST(MakeFileNameTest, GenerateWhenNumberIsZero) { TEST(MakeFileNameTest, GenerateWhenNumberIsZero) {
FilePath actual = FilePath::MakeFileName(FilePath("foo"), FilePath("bar"), FilePath actual =
0, "xml"); FilePath::MakeFileName(FilePath("foo"), FilePath("bar"), 0, "xml");
EXPECT_EQ("foo" GTEST_PATH_SEP_ "bar.xml", actual.string()); EXPECT_EQ("foo" GTEST_PATH_SEP_ "bar.xml", actual.string());
} }
TEST(MakeFileNameTest, GenerateFileNameNumberGtZero) { TEST(MakeFileNameTest, GenerateFileNameNumberGtZero) {
FilePath actual = FilePath::MakeFileName(FilePath("foo"), FilePath("bar"), FilePath actual =
12, "xml"); FilePath::MakeFileName(FilePath("foo"), FilePath("bar"), 12, "xml");
EXPECT_EQ("foo" GTEST_PATH_SEP_ "bar_12.xml", actual.string()); EXPECT_EQ("foo" GTEST_PATH_SEP_ "bar_12.xml", actual.string());
} }
TEST(MakeFileNameTest, GenerateFileNameWithSlashNumberIsZero) { TEST(MakeFileNameTest, GenerateFileNameWithSlashNumberIsZero) {
FilePath actual = FilePath::MakeFileName(FilePath("foo" GTEST_PATH_SEP_), FilePath actual = FilePath::MakeFileName(FilePath("foo" GTEST_PATH_SEP_),
FilePath("bar"), 0, "xml"); FilePath("bar"), 0, "xml");
EXPECT_EQ("foo" GTEST_PATH_SEP_ "bar.xml", actual.string()); EXPECT_EQ("foo" GTEST_PATH_SEP_ "bar.xml", actual.string());
} }
TEST(MakeFileNameTest, GenerateFileNameWithSlashNumberGtZero) { TEST(MakeFileNameTest, GenerateFileNameWithSlashNumberGtZero) {
FilePath actual = FilePath::MakeFileName(FilePath("foo" GTEST_PATH_SEP_), FilePath actual = FilePath::MakeFileName(FilePath("foo" GTEST_PATH_SEP_),
FilePath("bar"), 12, "xml"); FilePath("bar"), 12, "xml");
EXPECT_EQ("foo" GTEST_PATH_SEP_ "bar_12.xml", actual.string()); EXPECT_EQ("foo" GTEST_PATH_SEP_ "bar_12.xml", actual.string());
} }
TEST(MakeFileNameTest, GenerateWhenNumberIsZeroAndDirIsEmpty) { TEST(MakeFileNameTest, GenerateWhenNumberIsZeroAndDirIsEmpty) {
FilePath actual = FilePath::MakeFileName(FilePath(""), FilePath("bar"), FilePath actual =
0, "xml"); FilePath::MakeFileName(FilePath(""), FilePath("bar"), 0, "xml");
EXPECT_EQ("bar.xml", actual.string()); EXPECT_EQ("bar.xml", actual.string());
} }
TEST(MakeFileNameTest, GenerateWhenNumberIsNotZeroAndDirIsEmpty) { TEST(MakeFileNameTest, GenerateWhenNumberIsNotZeroAndDirIsEmpty) {
FilePath actual = FilePath::MakeFileName(FilePath(""), FilePath("bar"), FilePath actual =
14, "xml"); FilePath::MakeFileName(FilePath(""), FilePath("bar"), 14, "xml");
EXPECT_EQ("bar_14.xml", actual.string()); EXPECT_EQ("bar_14.xml", actual.string());
} }
TEST(ConcatPathsTest, WorksWhenDirDoesNotEndWithPathSep) { TEST(ConcatPathsTest, WorksWhenDirDoesNotEndWithPathSep) {
FilePath actual = FilePath::ConcatPaths(FilePath("foo"), FilePath actual = FilePath::ConcatPaths(FilePath("foo"), FilePath("bar.xml"));
FilePath("bar.xml"));
EXPECT_EQ("foo" GTEST_PATH_SEP_ "bar.xml", actual.string()); EXPECT_EQ("foo" GTEST_PATH_SEP_ "bar.xml", actual.string());
} }
TEST(ConcatPathsTest, WorksWhenPath1EndsWithPathSep) { TEST(ConcatPathsTest, WorksWhenPath1EndsWithPathSep) {
FilePath actual = FilePath::ConcatPaths(FilePath("foo" GTEST_PATH_SEP_), FilePath actual = FilePath::ConcatPaths(FilePath("foo" GTEST_PATH_SEP_),
FilePath("bar.xml")); FilePath("bar.xml"));
EXPECT_EQ("foo" GTEST_PATH_SEP_ "bar.xml", actual.string()); EXPECT_EQ("foo" GTEST_PATH_SEP_ "bar.xml", actual.string());
} }
TEST(ConcatPathsTest, Path1BeingEmpty) { TEST(ConcatPathsTest, Path1BeingEmpty) {
FilePath actual = FilePath::ConcatPaths(FilePath(""), FilePath actual = FilePath::ConcatPaths(FilePath(""), FilePath("bar.xml"));
FilePath("bar.xml"));
EXPECT_EQ("bar.xml", actual.string()); EXPECT_EQ("bar.xml", actual.string());
} }
TEST(ConcatPathsTest, Path2BeingEmpty) { TEST(ConcatPathsTest, Path2BeingEmpty) {
FilePath actual = FilePath::ConcatPaths(FilePath("foo"), FilePath("")); FilePath actual = FilePath::ConcatPaths(FilePath("foo"), FilePath(""));
EXPECT_EQ("foo" GTEST_PATH_SEP_, actual.string()); EXPECT_EQ("foo" GTEST_PATH_SEP_, actual.string());
} }
TEST(ConcatPathsTest, BothPathBeingEmpty) { TEST(ConcatPathsTest, BothPathBeingEmpty) {
FilePath actual = FilePath::ConcatPaths(FilePath(""), FilePath actual = FilePath::ConcatPaths(FilePath(""), FilePath(""));
FilePath(""));
EXPECT_EQ("", actual.string()); EXPECT_EQ("", actual.string());
} }
TEST(ConcatPathsTest, Path1ContainsPathSep) { TEST(ConcatPathsTest, Path1ContainsPathSep) {
FilePath actual = FilePath::ConcatPaths(FilePath("foo" GTEST_PATH_SEP_ "bar"), FilePath actual = FilePath::ConcatPaths(FilePath("foo" GTEST_PATH_SEP_ "bar"),
FilePath("foobar.xml")); FilePath("foobar.xml"));
EXPECT_EQ("foo" GTEST_PATH_SEP_ "bar" GTEST_PATH_SEP_ "foobar.xml", EXPECT_EQ("foo" GTEST_PATH_SEP_ "bar" GTEST_PATH_SEP_ "foobar.xml",
actual.string()); actual.string());
} }
TEST(ConcatPathsTest, Path2ContainsPathSep) { TEST(ConcatPathsTest, Path2ContainsPathSep) {
FilePath actual = FilePath::ConcatPaths( FilePath actual =
FilePath("foo" GTEST_PATH_SEP_), FilePath::ConcatPaths(FilePath("foo" GTEST_PATH_SEP_),
FilePath("bar" GTEST_PATH_SEP_ "bar.xml")); FilePath("bar" GTEST_PATH_SEP_ "bar.xml"));
EXPECT_EQ("foo" GTEST_PATH_SEP_ "bar" GTEST_PATH_SEP_ "bar.xml", EXPECT_EQ("foo" GTEST_PATH_SEP_ "bar" GTEST_PATH_SEP_ "bar.xml",
actual.string()); actual.string());
} }
TEST(ConcatPathsTest, Path2EndsWithPathSep) { TEST(ConcatPathsTest, Path2EndsWithPathSep) {
FilePath actual = FilePath::ConcatPaths(FilePath("foo"), FilePath actual =
FilePath("bar" GTEST_PATH_SEP_)); FilePath::ConcatPaths(FilePath("foo"), FilePath("bar" GTEST_PATH_SEP_));
EXPECT_EQ("foo" GTEST_PATH_SEP_ "bar" GTEST_PATH_SEP_, actual.string()); EXPECT_EQ("foo" GTEST_PATH_SEP_ "bar" GTEST_PATH_SEP_, actual.string());
} }
// RemoveTrailingPathSeparator "" -> "" // RemoveTrailingPathSeparator "" -> ""
TEST(RemoveTrailingPathSeparatorTest, EmptyString) { TEST(RemoveTrailingPathSeparatorTest, EmptyString) {
EXPECT_EQ("", FilePath("").RemoveTrailingPathSeparator().string()); EXPECT_EQ("", FilePath("").RemoveTrailingPathSeparator().string());
} }
// RemoveTrailingPathSeparator "foo" -> "foo" // RemoveTrailingPathSeparator "foo" -> "foo"
TEST(RemoveTrailingPathSeparatorTest, FileNoSlashString) { TEST(RemoveTrailingPathSeparatorTest, FileNoSlashString) {
EXPECT_EQ("foo", FilePath("foo").RemoveTrailingPathSeparator().string()); EXPECT_EQ("foo", FilePath("foo").RemoveTrailingPathSeparator().string());
} }
// RemoveTrailingPathSeparator "foo/" -> "foo" // RemoveTrailingPathSeparator "foo/" -> "foo"
TEST(RemoveTrailingPathSeparatorTest, ShouldRemoveTrailingSeparator) { TEST(RemoveTrailingPathSeparatorTest, ShouldRemoveTrailingSeparator) {
EXPECT_EQ("foo", EXPECT_EQ(
"foo",
FilePath("foo" GTEST_PATH_SEP_).RemoveTrailingPathSeparator().string()); FilePath("foo" GTEST_PATH_SEP_).RemoveTrailingPathSeparator().string());
#if GTEST_HAS_ALT_PATH_SEP_ #if GTEST_HAS_ALT_PATH_SEP_
EXPECT_EQ("foo", FilePath("foo/").RemoveTrailingPathSeparator().string()); EXPECT_EQ("foo", FilePath("foo/").RemoveTrailingPathSeparator().string());
#endif #endif
} }
// RemoveTrailingPathSeparator "foo/bar/" -> "foo/bar/" // RemoveTrailingPathSeparator "foo/bar/" -> "foo/bar/"
TEST(RemoveTrailingPathSeparatorTest, ShouldRemoveLastSeparator) { TEST(RemoveTrailingPathSeparatorTest, ShouldRemoveLastSeparator) {
EXPECT_EQ("foo" GTEST_PATH_SEP_ "bar", EXPECT_EQ("foo" GTEST_PATH_SEP_ "bar",
FilePath("foo" GTEST_PATH_SEP_ "bar" GTEST_PATH_SEP_) FilePath("foo" GTEST_PATH_SEP_ "bar" GTEST_PATH_SEP_)
.RemoveTrailingPathSeparator().string()); .RemoveTrailingPathSeparator()
.string());
} }
// RemoveTrailingPathSeparator "foo/bar" -> "foo/bar" // RemoveTrailingPathSeparator "foo/bar" -> "foo/bar"
TEST(RemoveTrailingPathSeparatorTest, ShouldReturnUnmodified) { TEST(RemoveTrailingPathSeparatorTest, ShouldReturnUnmodified) {
EXPECT_EQ("foo" GTEST_PATH_SEP_ "bar", EXPECT_EQ("foo" GTEST_PATH_SEP_ "bar", FilePath("foo" GTEST_PATH_SEP_ "bar")
FilePath("foo" GTEST_PATH_SEP_ "bar") .RemoveTrailingPathSeparator()
.RemoveTrailingPathSeparator().string()); .string());
} }
TEST(DirectoryTest, RootDirectoryExists) { TEST(DirectoryTest, RootDirectoryExists) {
#if GTEST_OS_WINDOWS // We are on Windows. #if GTEST_OS_WINDOWS // We are on Windows.
char current_drive[_MAX_PATH]; // NOLINT char current_drive[_MAX_PATH]; // NOLINT
current_drive[0] = static_cast<char>(_getdrive() + 'A' - 1); current_drive[0] = static_cast<char>(_getdrive() + 'A' - 1);
current_drive[1] = ':'; current_drive[1] = ':';
current_drive[2] = '\\'; current_drive[2] = '\\';
current_drive[3] = '\0'; current_drive[3] = '\0';
EXPECT_TRUE(FilePath(current_drive).DirectoryExists()); EXPECT_TRUE(FilePath(current_drive).DirectoryExists());
#else #else
EXPECT_TRUE(FilePath("/").DirectoryExists()); EXPECT_TRUE(FilePath("/").DirectoryExists());
#endif // GTEST_OS_WINDOWS #endif // GTEST_OS_WINDOWS
} }
skipping to change at line 396 skipping to change at line 397
#if !GTEST_OS_WINDOWS_MOBILE #if !GTEST_OS_WINDOWS_MOBILE
// Windows CE _does_ consider an empty directory to exist. // Windows CE _does_ consider an empty directory to exist.
TEST(DirectoryTest, EmptyPathDirectoryDoesNotExist) { TEST(DirectoryTest, EmptyPathDirectoryDoesNotExist) {
EXPECT_FALSE(FilePath("").DirectoryExists()); EXPECT_FALSE(FilePath("").DirectoryExists());
} }
#endif // !GTEST_OS_WINDOWS_MOBILE #endif // !GTEST_OS_WINDOWS_MOBILE
TEST(DirectoryTest, CurrentDirectoryExists) { TEST(DirectoryTest, CurrentDirectoryExists) {
#if GTEST_OS_WINDOWS // We are on Windows. #if GTEST_OS_WINDOWS // We are on Windows.
# ifndef _WIN32_CE // Windows CE doesn't have a current directory. #ifndef _WIN32_CE // Windows CE doesn't have a current directory.
EXPECT_TRUE(FilePath(".").DirectoryExists()); EXPECT_TRUE(FilePath(".").DirectoryExists());
EXPECT_TRUE(FilePath(".\\").DirectoryExists()); EXPECT_TRUE(FilePath(".\\").DirectoryExists());
# endif // _WIN32_CE #endif // _WIN32_CE
#else #else
EXPECT_TRUE(FilePath(".").DirectoryExists()); EXPECT_TRUE(FilePath(".").DirectoryExists());
EXPECT_TRUE(FilePath("./").DirectoryExists()); EXPECT_TRUE(FilePath("./").DirectoryExists());
#endif // GTEST_OS_WINDOWS #endif // GTEST_OS_WINDOWS
} }
// "foo/bar" == foo//bar" == "foo///bar" // "foo/bar" == foo//bar" == "foo///bar"
TEST(NormalizeTest, MultipleConsecutiveSepaparatorsInMidstring) { TEST(NormalizeTest, MultipleConsecutiveSeparatorsInMidstring) {
EXPECT_EQ("foo" GTEST_PATH_SEP_ "bar", EXPECT_EQ("foo" GTEST_PATH_SEP_ "bar",
FilePath("foo" GTEST_PATH_SEP_ "bar").string()); FilePath("foo" GTEST_PATH_SEP_ "bar").string());
EXPECT_EQ("foo" GTEST_PATH_SEP_ "bar", EXPECT_EQ("foo" GTEST_PATH_SEP_ "bar",
FilePath("foo" GTEST_PATH_SEP_ GTEST_PATH_SEP_ "bar").string()); FilePath("foo" GTEST_PATH_SEP_ GTEST_PATH_SEP_ "bar").string());
EXPECT_EQ("foo" GTEST_PATH_SEP_ "bar", EXPECT_EQ(
FilePath("foo" GTEST_PATH_SEP_ GTEST_PATH_SEP_ "foo" GTEST_PATH_SEP_ "bar",
GTEST_PATH_SEP_ "bar").string()); FilePath("foo" GTEST_PATH_SEP_ GTEST_PATH_SEP_ GTEST_PATH_SEP_ "bar")
.string());
} }
// "/bar" == //bar" == "///bar" // "/bar" == //bar" == "///bar"
TEST(NormalizeTest, MultipleConsecutiveSepaparatorsAtStringStart) { TEST(NormalizeTest, MultipleConsecutiveSeparatorsAtStringStart) {
EXPECT_EQ(GTEST_PATH_SEP_ "bar", EXPECT_EQ(GTEST_PATH_SEP_ "bar", FilePath(GTEST_PATH_SEP_ "bar").string());
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", EXPECT_EQ(GTEST_PATH_SEP_ "bar",
FilePath(GTEST_PATH_SEP_ GTEST_PATH_SEP_ GTEST_PATH_SEP_ "bar").string()); 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///" // "foo/" == foo//" == "foo///"
TEST(NormalizeTest, MultipleConsecutiveSepaparatorsAtStringEnd) { TEST(NormalizeTest, MultipleConsecutiveSeparatorsAtStringEnd) {
EXPECT_EQ("foo" GTEST_PATH_SEP_, FilePath("foo" GTEST_PATH_SEP_).string());
EXPECT_EQ("foo" GTEST_PATH_SEP_, EXPECT_EQ("foo" GTEST_PATH_SEP_,
FilePath("foo" GTEST_PATH_SEP_).string()); FilePath("foo" GTEST_PATH_SEP_ GTEST_PATH_SEP_).string());
EXPECT_EQ("foo" GTEST_PATH_SEP_, EXPECT_EQ(
FilePath("foo" GTEST_PATH_SEP_ GTEST_PATH_SEP_).string()); "foo" GTEST_PATH_SEP_,
EXPECT_EQ("foo" GTEST_PATH_SEP_, FilePath("foo" GTEST_PATH_SEP_ GTEST_PATH_SEP_ GTEST_PATH_SEP_).string());
FilePath("foo" GTEST_PATH_SEP_ GTEST_PATH_SEP_ GTEST_PATH_SEP_).string());
} }
#if GTEST_HAS_ALT_PATH_SEP_ #if GTEST_HAS_ALT_PATH_SEP_
// Tests that separators at the end of the string are normalized // Tests that separators at the end of the string are normalized
// regardless of their combination (e.g. "foo\" =="foo/\" == // regardless of their combination (e.g. "foo\" =="foo/\" ==
// "foo\\/"). // "foo\\/").
TEST(NormalizeTest, MixAlternateSeparatorAtStringEnd) { TEST(NormalizeTest, MixAlternateSeparatorAtStringEnd) {
EXPECT_EQ("foo" GTEST_PATH_SEP_, EXPECT_EQ("foo" GTEST_PATH_SEP_, FilePath("foo/").string());
FilePath("foo/").string());
EXPECT_EQ("foo" GTEST_PATH_SEP_, EXPECT_EQ("foo" GTEST_PATH_SEP_,
FilePath("foo" GTEST_PATH_SEP_ "/").string()); FilePath("foo" GTEST_PATH_SEP_ "/").string());
EXPECT_EQ("foo" GTEST_PATH_SEP_, EXPECT_EQ("foo" GTEST_PATH_SEP_, FilePath("foo//" GTEST_PATH_SEP_).string());
FilePath("foo//" GTEST_PATH_SEP_).string());
} }
#endif #endif
TEST(AssignmentOperatorTest, DefaultAssignedToNonDefault) { TEST(AssignmentOperatorTest, DefaultAssignedToNonDefault) {
FilePath default_path; FilePath default_path;
FilePath non_default_path("path"); FilePath non_default_path("path");
non_default_path = default_path; non_default_path = default_path;
EXPECT_EQ("", non_default_path.string()); EXPECT_EQ("", non_default_path.string());
EXPECT_EQ("", default_path.string()); // RHS var is unchanged. EXPECT_EQ("", default_path.string()); // RHS var is unchanged.
skipping to change at line 481 skipping to change at line 481
TEST(AssignmentOperatorTest, ConstAssignedToNonConst) { TEST(AssignmentOperatorTest, ConstAssignedToNonConst) {
const FilePath const_default_path("const_path"); const FilePath const_default_path("const_path");
FilePath non_default_path("path"); FilePath non_default_path("path");
non_default_path = const_default_path; non_default_path = const_default_path;
EXPECT_EQ("const_path", non_default_path.string()); EXPECT_EQ("const_path", non_default_path.string());
} }
class DirectoryCreationTest : public Test { class DirectoryCreationTest : public Test {
protected: protected:
void SetUp() override { void SetUp() override {
testdata_path_.Set(FilePath( testdata_path_.Set(
TempDir() + GetCurrentExecutableName().string() + FilePath(TempDir() + GetCurrentExecutableName().string() +
"_directory_creation" GTEST_PATH_SEP_ "test" GTEST_PATH_SEP_)); "_directory_creation" GTEST_PATH_SEP_ "test" GTEST_PATH_SEP_));
testdata_file_.Set(testdata_path_.RemoveTrailingPathSeparator()); testdata_file_.Set(testdata_path_.RemoveTrailingPathSeparator());
unique_file0_.Set(FilePath::MakeFileName(testdata_path_, FilePath("unique"), unique_file0_.Set(
0, "txt")); FilePath::MakeFileName(testdata_path_, FilePath("unique"), 0, "txt"));
unique_file1_.Set(FilePath::MakeFileName(testdata_path_, FilePath("unique"), unique_file1_.Set(
1, "txt")); FilePath::MakeFileName(testdata_path_, FilePath("unique"), 1, "txt"));
remove(testdata_file_.c_str()); remove(testdata_file_.c_str());
remove(unique_file0_.c_str()); remove(unique_file0_.c_str());
remove(unique_file1_.c_str()); remove(unique_file1_.c_str());
posix::RmDir(testdata_path_.c_str()); posix::RmDir(testdata_path_.c_str());
} }
void TearDown() override { void TearDown() override {
remove(testdata_file_.c_str()); remove(testdata_file_.c_str());
remove(unique_file0_.c_str()); remove(unique_file0_.c_str());
skipping to change at line 515 skipping to change at line 515
FILE* f = posix::FOpen(filename, "w"); FILE* f = posix::FOpen(filename, "w");
fprintf(f, "text\n"); fprintf(f, "text\n");
fclose(f); fclose(f);
} }
// Strings representing a directory and a file, with identical paths // Strings representing a directory and a file, with identical paths
// except for the trailing separator character that distinquishes // except for the trailing separator character that distinquishes
// a directory named 'test' from a file named 'test'. Example names: // a directory named 'test' from a file named 'test'. Example names:
FilePath testdata_path_; // "/tmp/directory_creation/test/" FilePath testdata_path_; // "/tmp/directory_creation/test/"
FilePath testdata_file_; // "/tmp/directory_creation/test" FilePath testdata_file_; // "/tmp/directory_creation/test"
FilePath unique_file0_; // "/tmp/directory_creation/test/unique.txt" FilePath unique_file0_; // "/tmp/directory_creation/test/unique.txt"
FilePath unique_file1_; // "/tmp/directory_creation/test/unique_1.txt" FilePath unique_file1_; // "/tmp/directory_creation/test/unique_1.txt"
}; };
TEST_F(DirectoryCreationTest, CreateDirectoriesRecursively) { TEST_F(DirectoryCreationTest, CreateDirectoriesRecursively) {
EXPECT_FALSE(testdata_path_.DirectoryExists()) << testdata_path_.string(); EXPECT_FALSE(testdata_path_.DirectoryExists()) << testdata_path_.string();
EXPECT_TRUE(testdata_path_.CreateDirectoriesRecursively()); EXPECT_TRUE(testdata_path_.CreateDirectoriesRecursively());
EXPECT_TRUE(testdata_path_.DirectoryExists()); EXPECT_TRUE(testdata_path_.DirectoryExists());
} }
TEST_F(DirectoryCreationTest, CreateDirectoriesForAlreadyExistingPath) { TEST_F(DirectoryCreationTest, CreateDirectoriesForAlreadyExistingPath) {
EXPECT_FALSE(testdata_path_.DirectoryExists()) << testdata_path_.string(); EXPECT_FALSE(testdata_path_.DirectoryExists()) << testdata_path_.string();
EXPECT_TRUE(testdata_path_.CreateDirectoriesRecursively()); EXPECT_TRUE(testdata_path_.CreateDirectoriesRecursively());
// Call 'create' again... should still succeed. // Call 'create' again... should still succeed.
EXPECT_TRUE(testdata_path_.CreateDirectoriesRecursively()); EXPECT_TRUE(testdata_path_.CreateDirectoriesRecursively());
} }
TEST_F(DirectoryCreationTest, CreateDirectoriesAndUniqueFilename) { TEST_F(DirectoryCreationTest, CreateDirectoriesAndUniqueFilename) {
FilePath file_path(FilePath::GenerateUniqueFileName(testdata_path_, FilePath file_path(FilePath::GenerateUniqueFileName(
FilePath("unique"), "txt")); testdata_path_, FilePath("unique"), "txt"));
EXPECT_EQ(unique_file0_.string(), file_path.string()); EXPECT_EQ(unique_file0_.string(), file_path.string());
EXPECT_FALSE(file_path.FileOrDirectoryExists()); // file not there EXPECT_FALSE(file_path.FileOrDirectoryExists()); // file not there
testdata_path_.CreateDirectoriesRecursively(); testdata_path_.CreateDirectoriesRecursively();
EXPECT_FALSE(file_path.FileOrDirectoryExists()); // file still not there EXPECT_FALSE(file_path.FileOrDirectoryExists()); // file still not there
CreateTextFile(file_path.c_str()); CreateTextFile(file_path.c_str());
EXPECT_TRUE(file_path.FileOrDirectoryExists()); EXPECT_TRUE(file_path.FileOrDirectoryExists());
FilePath file_path2(FilePath::GenerateUniqueFileName(testdata_path_, FilePath file_path2(FilePath::GenerateUniqueFileName(
FilePath("unique"), "txt")); testdata_path_, FilePath("unique"), "txt"));
EXPECT_EQ(unique_file1_.string(), file_path2.string()); EXPECT_EQ(unique_file1_.string(), file_path2.string());
EXPECT_FALSE(file_path2.FileOrDirectoryExists()); // file not there EXPECT_FALSE(file_path2.FileOrDirectoryExists()); // file not there
CreateTextFile(file_path2.c_str()); CreateTextFile(file_path2.c_str());
EXPECT_TRUE(file_path2.FileOrDirectoryExists()); EXPECT_TRUE(file_path2.FileOrDirectoryExists());
} }
TEST_F(DirectoryCreationTest, CreateDirectoriesFail) { TEST_F(DirectoryCreationTest, CreateDirectoriesFail) {
// force a failure by putting a file where we will try to create a directory. // force a failure by putting a file where we will try to create a directory.
CreateTextFile(testdata_file_.c_str()); CreateTextFile(testdata_file_.c_str());
EXPECT_TRUE(testdata_file_.FileOrDirectoryExists()); EXPECT_TRUE(testdata_file_.FileOrDirectoryExists());
skipping to change at line 617 skipping to change at line 617
EXPECT_TRUE(FilePath("koala" GTEST_PATH_SEP_).IsDirectory()); EXPECT_TRUE(FilePath("koala" GTEST_PATH_SEP_).IsDirectory());
#if GTEST_HAS_ALT_PATH_SEP_ #if GTEST_HAS_ALT_PATH_SEP_
EXPECT_TRUE(FilePath("koala/").IsDirectory()); EXPECT_TRUE(FilePath("koala/").IsDirectory());
#endif #endif
} }
TEST(FilePathTest, IsAbsolutePath) { TEST(FilePathTest, IsAbsolutePath) {
EXPECT_FALSE(FilePath("is" GTEST_PATH_SEP_ "relative").IsAbsolutePath()); EXPECT_FALSE(FilePath("is" GTEST_PATH_SEP_ "relative").IsAbsolutePath());
EXPECT_FALSE(FilePath("").IsAbsolutePath()); EXPECT_FALSE(FilePath("").IsAbsolutePath());
#if GTEST_OS_WINDOWS #if GTEST_OS_WINDOWS
EXPECT_TRUE(FilePath("c:\\" GTEST_PATH_SEP_ "is_not" EXPECT_TRUE(
GTEST_PATH_SEP_ "relative").IsAbsolutePath()); FilePath("c:\\" GTEST_PATH_SEP_ "is_not" GTEST_PATH_SEP_ "relative")
.IsAbsolutePath());
EXPECT_FALSE(FilePath("c:foo" GTEST_PATH_SEP_ "bar").IsAbsolutePath()); EXPECT_FALSE(FilePath("c:foo" GTEST_PATH_SEP_ "bar").IsAbsolutePath());
EXPECT_TRUE(FilePath("c:/" GTEST_PATH_SEP_ "is_not" EXPECT_TRUE(
GTEST_PATH_SEP_ "relative").IsAbsolutePath()); FilePath("c:/" GTEST_PATH_SEP_ "is_not" GTEST_PATH_SEP_ "relative")
.IsAbsolutePath());
#else #else
EXPECT_TRUE(FilePath(GTEST_PATH_SEP_ "is_not" GTEST_PATH_SEP_ "relative") EXPECT_TRUE(FilePath(GTEST_PATH_SEP_ "is_not" GTEST_PATH_SEP_ "relative")
.IsAbsolutePath()); .IsAbsolutePath());
#endif // GTEST_OS_WINDOWS #endif // GTEST_OS_WINDOWS
} }
TEST(FilePathTest, IsRootDirectory) { TEST(FilePathTest, IsRootDirectory) {
#if GTEST_OS_WINDOWS #if GTEST_OS_WINDOWS
EXPECT_TRUE(FilePath("a:\\").IsRootDirectory()); EXPECT_TRUE(FilePath("a:\\").IsRootDirectory());
EXPECT_TRUE(FilePath("Z:/").IsRootDirectory()); EXPECT_TRUE(FilePath("Z:/").IsRootDirectory());
EXPECT_TRUE(FilePath("e://").IsRootDirectory()); EXPECT_TRUE(FilePath("e://").IsRootDirectory());
EXPECT_FALSE(FilePath("").IsRootDirectory()); EXPECT_FALSE(FilePath("").IsRootDirectory());
EXPECT_FALSE(FilePath("b:").IsRootDirectory()); EXPECT_FALSE(FilePath("b:").IsRootDirectory());
 End of changes. 51 change blocks. 
89 lines changed or deleted 91 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)