43#if GTEST_OS_WINDOWS_MOBILE
53#if GTEST_OS_WINDOWS_MOBILE
58int remove(
const char* path) {
59 LPCWSTR wpath = String::AnsiToUtf16(path);
60 int ret = DeleteFile(wpath) ? 0 : -1;
65int _rmdir(
const char* path) {
66 FilePath filepath(path);
67 LPCWSTR wpath = String::AnsiToUtf16(
68 filepath.RemoveTrailingPathSeparator().c_str());
69 int ret = RemoveDirectory(wpath) ? 0 : -1;
76TEST(GetCurrentDirTest, ReturnsCurrentDir) {
87 const char*
const cwd_without_drive = strchr(
cwd.c_str(),
':');
100TEST(IsEmptyTest, ReturnsTrueForEmptyPath) {
104TEST(IsEmptyTest, ReturnsFalseForNonEmptyPath) {
112TEST(RemoveDirectoryNameTest, WhenEmptyName) {
113 EXPECT_EQ(
"", FilePath(
"").RemoveDirectoryName().
string());
117TEST(RemoveDirectoryNameTest, ButNoDirectory) {
119 FilePath(
"afile").RemoveDirectoryName().
string());
123TEST(RemoveDirectoryNameTest, RootFileShouldGiveFileName) {
129TEST(RemoveDirectoryNameTest, WhereThereIsNoFileName) {
135TEST(RemoveDirectoryNameTest, ShouldGiveFileName) {
137 FilePath(
"adir" GTEST_PATH_SEP_ "afile").RemoveDirectoryName().
string());
141TEST(RemoveDirectoryNameTest, ShouldAlsoGiveFileName) {
144 .RemoveDirectoryName().
string());
147#if GTEST_HAS_ALT_PATH_SEP_
153TEST(RemoveDirectoryNameTest, RootFileShouldGiveFileNameForAlternateSeparator) {
154 EXPECT_EQ(
"afile", FilePath(
"/afile").RemoveDirectoryName().
string());
158TEST(RemoveDirectoryNameTest, WhereThereIsNoFileNameForAlternateSeparator) {
159 EXPECT_EQ(
"", FilePath(
"adir/").RemoveDirectoryName().
string());
163TEST(RemoveDirectoryNameTest, ShouldGiveFileNameForAlternateSeparator) {
164 EXPECT_EQ(
"afile", FilePath(
"adir/afile").RemoveDirectoryName().
string());
168TEST(RemoveDirectoryNameTest, ShouldAlsoGiveFileNameForAlternateSeparator) {
170 FilePath(
"adir/subdir/afile").RemoveDirectoryName().
string());
176TEST(RemoveFileNameTest, EmptyName) {
177#if GTEST_OS_WINDOWS_MOBILE
186TEST(RemoveFileNameTest, ButNoFile) {
192TEST(RemoveFileNameTest, GivesDirName) {
198TEST(RemoveFileNameTest, GivesDirAndSubDirName) {
201 .RemoveFileName().
string());
205TEST(RemoveFileNameTest, GivesRootDir) {
210#if GTEST_HAS_ALT_PATH_SEP_
216TEST(RemoveFileNameTest, ButNoFileForAlternateSeparator) {
218 FilePath(
"adir/").RemoveFileName().
string());
222TEST(RemoveFileNameTest, GivesDirNameForAlternateSeparator) {
224 FilePath(
"adir/afile").RemoveFileName().
string());
228TEST(RemoveFileNameTest, GivesDirAndSubDirNameForAlternateSeparator) {
230 FilePath(
"adir/subdir/afile").RemoveFileName().
string());
234TEST(RemoveFileNameTest, GivesRootDirForAlternateSeparator) {
240TEST(MakeFileNameTest, GenerateWhenNumberIsZero) {
246TEST(MakeFileNameTest, GenerateFileNameNumberGtZero) {
252TEST(MakeFileNameTest, GenerateFileNameWithSlashNumberIsZero) {
254 FilePath(
"bar"), 0,
"xml");
258TEST(MakeFileNameTest, GenerateFileNameWithSlashNumberGtZero) {
260 FilePath(
"bar"), 12,
"xml");
264TEST(MakeFileNameTest, GenerateWhenNumberIsZeroAndDirIsEmpty) {
270TEST(MakeFileNameTest, GenerateWhenNumberIsNotZeroAndDirIsEmpty) {
273 EXPECT_EQ(
"bar_14.xml", actual.string());
276TEST(ConcatPathsTest, WorksWhenDirDoesNotEndWithPathSep) {
278 FilePath(
"bar.xml"));
282TEST(ConcatPathsTest, WorksWhenPath1EndsWithPathSep) {
284 FilePath(
"bar.xml"));
288TEST(ConcatPathsTest, Path1BeingEmpty) {
290 FilePath(
"bar.xml"));
294TEST(ConcatPathsTest, Path2BeingEmpty) {
299TEST(ConcatPathsTest, BothPathBeingEmpty) {
305TEST(ConcatPathsTest, Path1ContainsPathSep) {
307 FilePath(
"foobar.xml"));
312TEST(ConcatPathsTest, Path2ContainsPathSep) {
320TEST(ConcatPathsTest, Path2EndsWithPathSep) {
327TEST(RemoveTrailingPathSeparatorTest, EmptyString) {
328 EXPECT_EQ(
"", FilePath(
"").RemoveTrailingPathSeparator().
string());
332TEST(RemoveTrailingPathSeparatorTest, FileNoSlashString) {
333 EXPECT_EQ(
"foo", FilePath(
"foo").RemoveTrailingPathSeparator().
string());
337TEST(RemoveTrailingPathSeparatorTest, ShouldRemoveTrailingSeparator) {
339 FilePath(
"foo" GTEST_PATH_SEP_).RemoveTrailingPathSeparator().
string());
340#if GTEST_HAS_ALT_PATH_SEP_
341 EXPECT_EQ(
"foo", FilePath(
"foo/").RemoveTrailingPathSeparator().
string());
346TEST(RemoveTrailingPathSeparatorTest, ShouldRemoveLastSeparator) {
349 .RemoveTrailingPathSeparator().
string());
353TEST(RemoveTrailingPathSeparatorTest, ShouldReturnUnmodified) {
356 .RemoveTrailingPathSeparator().
string());
359TEST(DirectoryTest, RootDirectoryExists) {
361 char current_drive[_MAX_PATH];
362 current_drive[0] =
static_cast<char>(_getdrive() +
'A' - 1);
363 current_drive[1] =
':';
364 current_drive[2] =
'\\';
365 current_drive[3] =
'\0';
366 EXPECT_TRUE(FilePath(current_drive).DirectoryExists());
373TEST(DirectoryTest, RootOfWrongDriveDoesNotExists) {
374 const int saved_drive_ = _getdrive();
376 for (
char drive =
'Z'; drive >=
'A'; drive--)
377 if (_chdrive(drive -
'A' + 1) == -1) {
378 char non_drive[_MAX_PATH];
379 non_drive[0] = drive;
386 _chdrive(saved_drive_);
390#if !GTEST_OS_WINDOWS_MOBILE
392TEST(DirectoryTest, EmptyPathDirectoryDoesNotExist) {
397TEST(DirectoryTest, CurrentDirectoryExists) {
412TEST(NormalizeTest, MultipleConsecutiveSepaparatorsInMidstring) {
423TEST(NormalizeTest, MultipleConsecutiveSepaparatorsAtStringStart) {
433TEST(NormalizeTest, MultipleConsecutiveSepaparatorsAtStringEnd) {
442#if GTEST_HAS_ALT_PATH_SEP_
447TEST(NormalizeTest, MixAlternateSeparatorAtStringEnd) {
449 FilePath(
"foo/").
string());
458TEST(AssignmentOperatorTest, DefaultAssignedToNonDefault) {
459 FilePath default_path;
460 FilePath non_default_path(
"path");
461 non_default_path = default_path;
462 EXPECT_EQ(
"", non_default_path.string());
466TEST(AssignmentOperatorTest, NonDefaultAssignedToDefault) {
467 FilePath non_default_path(
"path");
468 FilePath default_path;
469 default_path = non_default_path;
470 EXPECT_EQ(
"path", default_path.string());
471 EXPECT_EQ(
"path", non_default_path.string());
474TEST(AssignmentOperatorTest, ConstAssignedToNonConst) {
475 const FilePath const_default_path(
"const_path");
476 FilePath non_default_path(
"path");
477 non_default_path = const_default_path;
478 EXPECT_EQ(
"const_path", non_default_path.string());
481class DirectoryCreationTest :
public Test {
483 virtual void SetUp() {
500 virtual void TearDown() {
507 void CreateTextFile(
const char* filename) {
509 fprintf(
f,
"text\n");
522TEST_F(DirectoryCreationTest, CreateDirectoriesRecursively) {
528TEST_F(DirectoryCreationTest, CreateDirectoriesForAlreadyExistingPath) {
535TEST_F(DirectoryCreationTest, CreateDirectoriesAndUniqueFilename) {
537 FilePath(
"unique"),
"txt"));
543 CreateTextFile(file_path.c_str());
547 FilePath(
"unique"),
"txt"));
550 CreateTextFile(file_path2.c_str());
554TEST_F(DirectoryCreationTest, CreateDirectoriesFail) {
562TEST(NoDirectoryCreationTest, CreateNoDirectoriesForDefaultXmlFile) {
563 const FilePath test_detail_xml(
"test_detail.xml");
564 EXPECT_FALSE(test_detail_xml.CreateDirectoriesRecursively());
567TEST(FilePathTest, DefaultConstructor) {
572TEST(FilePathTest, CharAndCopyConstructors) {
573 const FilePath fp(
"spicy");
576 const FilePath fp_copy(fp);
580TEST(FilePathTest, StringConstructor) {
581 const FilePath fp(std::string(
"cider"));
585TEST(FilePathTest, Set) {
586 const FilePath apple(
"apple");
593TEST(FilePathTest, ToString) {
594 const FilePath file(
"drink");
598TEST(FilePathTest, RemoveExtension) {
599 EXPECT_EQ(
"app", FilePath(
"app.cc").RemoveExtension(
"cc").
string());
600 EXPECT_EQ(
"app", FilePath(
"app.exe").RemoveExtension(
"exe").
string());
601 EXPECT_EQ(
"APP", FilePath(
"APP.EXE").RemoveExtension(
"exe").
string());
604TEST(FilePathTest, RemoveExtensionWhenThereIsNoExtension) {
605 EXPECT_EQ(
"app", FilePath(
"app").RemoveExtension(
"exe").
string());
608TEST(FilePathTest, IsDirectory) {
611#if GTEST_HAS_ALT_PATH_SEP_
616TEST(FilePathTest, IsAbsolutePath) {
631TEST(FilePathTest, IsRootDirectory) {
bool FileOrDirectoryExists() const
static FilePath GenerateUniqueFileName(const FilePath &directory, const FilePath &base_name, const char *extension)
bool CreateDirectoriesRecursively() const
const std::string & string() const
const char * c_str() const
bool DirectoryExists() const
static FilePath MakeFileName(const FilePath &directory, const FilePath &base_name, int number, const char *extension)
static FilePath GetCurrentDir()
static FilePath ConcatPaths(const FilePath &directory, const FilePath &relative_path)
#define TEST_F(test_fixture, test_name)
#define EXPECT_EQ(val1, val2)
#define EXPECT_TRUE(condition)
#define EXPECT_STREQ(s1, s2)
#define TEST(test_case_name, test_name)
#define ASSERT_TRUE(condition)
#define EXPECT_FALSE(condition)
bool remove(const path &p)
int ChDir(const char *dir)
int RmDir(const char *dir)
FILE * FOpen(const char *path, const char *mode)
GTEST_API_ FilePath GetCurrentExecutableName()
GTEST_API_ std::string TempDir()