42 #if GTEST_OS_WINDOWS_MOBILE
44 #elif GTEST_OS_WINDOWS
46 #endif // GTEST_OS_WINDOWS_MOBILE
52 #if GTEST_OS_WINDOWS_MOBILE
55 int remove(
const char* path) {
56 LPCWSTR wpath = String::AnsiToUtf16(path);
57 int ret = DeleteFile(wpath) ? 0 : -1;
62 int _rmdir(
const char* path) {
63 FilePath filepath(path);
64 LPCWSTR wpath = String::AnsiToUtf16(
65 filepath.RemoveTrailingPathSeparator().c_str());
66 int ret = RemoveDirectory(wpath) ? 0 : -1;
73 TEST(GetCurrentDirTest, ReturnsCurrentDir) {
74 const FilePath original_dir = FilePath::GetCurrentDir();
78 const FilePath cwd = FilePath::GetCurrentDir();
81 # if GTEST_OS_WINDOWS || GTEST_OS_OS2
84 const char*
const cwd_without_drive = strchr(cwd.c_str(),
':');
95 #endif // GTEST_OS_WINDOWS_MOBILE
97 TEST(IsEmptyTest, ReturnsTrueForEmptyPath) {
101 TEST(IsEmptyTest, ReturnsFalseForNonEmptyPath) {
109 TEST(RemoveDirectoryNameTest, WhenEmptyName) {
110 EXPECT_EQ(
"", FilePath(
"").RemoveDirectoryName().
string());
114 TEST(RemoveDirectoryNameTest, ButNoDirectory) {
116 FilePath(
"afile").RemoveDirectoryName().
string());
120 TEST(RemoveDirectoryNameTest, RootFileShouldGiveFileName) {
126 TEST(RemoveDirectoryNameTest, WhereThereIsNoFileName) {
132 TEST(RemoveDirectoryNameTest, ShouldGiveFileName) {
134 FilePath(
"adir" GTEST_PATH_SEP_ "afile").RemoveDirectoryName().
string());
138 TEST(RemoveDirectoryNameTest, ShouldAlsoGiveFileName) {
141 .RemoveDirectoryName().
string());
144 #if GTEST_HAS_ALT_PATH_SEP_
150 TEST(RemoveDirectoryNameTest, RootFileShouldGiveFileNameForAlternateSeparator) {
151 EXPECT_EQ(
"afile", FilePath(
"/afile").RemoveDirectoryName().
string());
155 TEST(RemoveDirectoryNameTest, WhereThereIsNoFileNameForAlternateSeparator) {
156 EXPECT_EQ(
"", FilePath(
"adir/").RemoveDirectoryName().
string());
160 TEST(RemoveDirectoryNameTest, ShouldGiveFileNameForAlternateSeparator) {
161 EXPECT_EQ(
"afile", FilePath(
"adir/afile").RemoveDirectoryName().
string());
165 TEST(RemoveDirectoryNameTest, ShouldAlsoGiveFileNameForAlternateSeparator) {
167 FilePath(
"adir/subdir/afile").RemoveDirectoryName().
string());
173 TEST(RemoveFileNameTest, EmptyName) {
174 #if GTEST_OS_WINDOWS_MOBILE
176 EXPECT_EQ(GTEST_PATH_SEP_, FilePath(
"").RemoveFileName().
string());
178 EXPECT_EQ(
"." GTEST_PATH_SEP_, FilePath(
"").RemoveFileName().
string());
183 TEST(RemoveFileNameTest, ButNoFile) {
185 FilePath(
"adir" GTEST_PATH_SEP_).RemoveFileName().
string());
189 TEST(RemoveFileNameTest, GivesDirName) {
191 FilePath(
"adir" GTEST_PATH_SEP_
"afile").RemoveFileName().
string());
195 TEST(RemoveFileNameTest, GivesDirAndSubDirName) {
196 EXPECT_EQ(
"adir" GTEST_PATH_SEP_
"subdir" GTEST_PATH_SEP_,
197 FilePath(
"adir" GTEST_PATH_SEP_
"subdir" GTEST_PATH_SEP_
"afile")
198 .RemoveFileName().
string());
202 TEST(RemoveFileNameTest, GivesRootDir) {
204 FilePath(GTEST_PATH_SEP_
"afile").RemoveFileName().
string());
207 #if GTEST_HAS_ALT_PATH_SEP_
213 TEST(RemoveFileNameTest, ButNoFileForAlternateSeparator) {
215 FilePath(
"adir/").RemoveFileName().
string());
219 TEST(RemoveFileNameTest, GivesDirNameForAlternateSeparator) {
221 FilePath(
"adir/afile").RemoveFileName().
string());
225 TEST(RemoveFileNameTest, GivesDirAndSubDirNameForAlternateSeparator) {
226 EXPECT_EQ(
"adir" GTEST_PATH_SEP_
"subdir" GTEST_PATH_SEP_,
227 FilePath(
"adir/subdir/afile").RemoveFileName().
string());
231 TEST(RemoveFileNameTest, GivesRootDirForAlternateSeparator) {
232 EXPECT_EQ(GTEST_PATH_SEP_, FilePath(
"/afile").RemoveFileName().
string());
237 TEST(MakeFileNameTest, GenerateWhenNumberIsZero) {
238 FilePath actual = FilePath::MakeFileName(FilePath(
"foo"), FilePath(
"bar"),
240 EXPECT_EQ(
"foo" GTEST_PATH_SEP_
"bar.xml", actual.string());
243 TEST(MakeFileNameTest, GenerateFileNameNumberGtZero) {
244 FilePath actual = FilePath::MakeFileName(FilePath(
"foo"), FilePath(
"bar"),
246 EXPECT_EQ(
"foo" GTEST_PATH_SEP_
"bar_12.xml", actual.string());
249 TEST(MakeFileNameTest, GenerateFileNameWithSlashNumberIsZero) {
250 FilePath actual = FilePath::MakeFileName(FilePath(
"foo" GTEST_PATH_SEP_),
251 FilePath(
"bar"), 0,
"xml");
252 EXPECT_EQ(
"foo" GTEST_PATH_SEP_
"bar.xml", actual.string());
255 TEST(MakeFileNameTest, GenerateFileNameWithSlashNumberGtZero) {
256 FilePath actual = FilePath::MakeFileName(FilePath(
"foo" GTEST_PATH_SEP_),
257 FilePath(
"bar"), 12,
"xml");
258 EXPECT_EQ(
"foo" GTEST_PATH_SEP_
"bar_12.xml", actual.string());
261 TEST(MakeFileNameTest, GenerateWhenNumberIsZeroAndDirIsEmpty) {
262 FilePath actual = FilePath::MakeFileName(FilePath(
""), FilePath(
"bar"),
267 TEST(MakeFileNameTest, GenerateWhenNumberIsNotZeroAndDirIsEmpty) {
268 FilePath actual = FilePath::MakeFileName(FilePath(
""), FilePath(
"bar"),
270 EXPECT_EQ(
"bar_14.xml", actual.string());
273 TEST(ConcatPathsTest, WorksWhenDirDoesNotEndWithPathSep) {
274 FilePath actual = FilePath::ConcatPaths(FilePath(
"foo"),
275 FilePath(
"bar.xml"));
276 EXPECT_EQ(
"foo" GTEST_PATH_SEP_
"bar.xml", actual.string());
279 TEST(ConcatPathsTest, WorksWhenPath1EndsWithPathSep) {
280 FilePath actual = FilePath::ConcatPaths(FilePath(
"foo" GTEST_PATH_SEP_),
281 FilePath(
"bar.xml"));
282 EXPECT_EQ(
"foo" GTEST_PATH_SEP_
"bar.xml", actual.string());
285 TEST(ConcatPathsTest, Path1BeingEmpty) {
286 FilePath actual = FilePath::ConcatPaths(FilePath(
""),
287 FilePath(
"bar.xml"));
291 TEST(ConcatPathsTest, Path2BeingEmpty) {
292 FilePath actual = FilePath::ConcatPaths(FilePath(
"foo"), FilePath(
""));
293 EXPECT_EQ(
"foo" GTEST_PATH_SEP_, actual.string());
296 TEST(ConcatPathsTest, BothPathBeingEmpty) {
297 FilePath actual = FilePath::ConcatPaths(FilePath(
""),
302 TEST(ConcatPathsTest, Path1ContainsPathSep) {
303 FilePath actual = FilePath::ConcatPaths(FilePath(
"foo" GTEST_PATH_SEP_
"bar"),
304 FilePath(
"foobar.xml"));
305 EXPECT_EQ(
"foo" GTEST_PATH_SEP_
"bar" GTEST_PATH_SEP_
"foobar.xml",
309 TEST(ConcatPathsTest, Path2ContainsPathSep) {
310 FilePath actual = FilePath::ConcatPaths(
311 FilePath(
"foo" GTEST_PATH_SEP_),
312 FilePath(
"bar" GTEST_PATH_SEP_
"bar.xml"));
313 EXPECT_EQ(
"foo" GTEST_PATH_SEP_
"bar" GTEST_PATH_SEP_
"bar.xml",
317 TEST(ConcatPathsTest, Path2EndsWithPathSep) {
318 FilePath actual = FilePath::ConcatPaths(FilePath(
"foo"),
319 FilePath(
"bar" GTEST_PATH_SEP_));
320 EXPECT_EQ(
"foo" GTEST_PATH_SEP_
"bar" GTEST_PATH_SEP_, actual.string());
324 TEST(RemoveTrailingPathSeparatorTest, EmptyString) {
325 EXPECT_EQ(
"", FilePath(
"").RemoveTrailingPathSeparator().
string());
329 TEST(RemoveTrailingPathSeparatorTest, FileNoSlashString) {
330 EXPECT_EQ(
"foo", FilePath(
"foo").RemoveTrailingPathSeparator().
string());
334 TEST(RemoveTrailingPathSeparatorTest, ShouldRemoveTrailingSeparator) {
336 FilePath(
"foo" GTEST_PATH_SEP_).RemoveTrailingPathSeparator().
string());
337 #if GTEST_HAS_ALT_PATH_SEP_
338 EXPECT_EQ(
"foo", FilePath(
"foo/").RemoveTrailingPathSeparator().
string());
343 TEST(RemoveTrailingPathSeparatorTest, ShouldRemoveLastSeparator) {
345 FilePath(
"foo" GTEST_PATH_SEP_
"bar" GTEST_PATH_SEP_)
346 .RemoveTrailingPathSeparator().
string());
350 TEST(RemoveTrailingPathSeparatorTest, ShouldReturnUnmodified) {
352 FilePath(
"foo" GTEST_PATH_SEP_
"bar")
353 .RemoveTrailingPathSeparator().
string());
356 TEST(DirectoryTest, RootDirectoryExists) {
357 #if GTEST_OS_WINDOWS // We are on Windows.
358 char current_drive[_MAX_PATH];
359 current_drive[0] =
static_cast<char>(_getdrive() +
'A' - 1);
360 current_drive[1] =
':';
361 current_drive[2] =
'\\';
362 current_drive[3] =
'\0';
363 EXPECT_TRUE(FilePath(current_drive).DirectoryExists());
366 #endif // GTEST_OS_WINDOWS
370 TEST(DirectoryTest, RootOfWrongDriveDoesNotExists) {
371 const int saved_drive_ = _getdrive();
373 for (
char drive =
'Z'; drive >=
'A'; drive--)
374 if (_chdrive(drive -
'A' + 1) == -1) {
375 char non_drive[_MAX_PATH];
376 non_drive[0] = drive;
383 _chdrive(saved_drive_);
385 #endif // GTEST_OS_WINDOWS
387 #if !GTEST_OS_WINDOWS_MOBILE
389 TEST(DirectoryTest, EmptyPathDirectoryDoesNotExist) {
392 #endif // !GTEST_OS_WINDOWS_MOBILE
394 TEST(DirectoryTest, CurrentDirectoryExists) {
395 #if GTEST_OS_WINDOWS // We are on Windows.
396 # ifndef _WIN32_CE // Windows CE doesn't have a current directory.
405 #endif // GTEST_OS_WINDOWS
409 TEST(NormalizeTest, MultipleConsecutiveSepaparatorsInMidstring) {
411 FilePath(
"foo" GTEST_PATH_SEP_
"bar").
string());
413 FilePath(
"foo" GTEST_PATH_SEP_ GTEST_PATH_SEP_
"bar").
string());
415 FilePath(
"foo" GTEST_PATH_SEP_ GTEST_PATH_SEP_
416 GTEST_PATH_SEP_
"bar").
string());
420 TEST(NormalizeTest, MultipleConsecutiveSepaparatorsAtStringStart) {
422 FilePath(GTEST_PATH_SEP_
"bar").
string());
424 FilePath(GTEST_PATH_SEP_ GTEST_PATH_SEP_
"bar").
string());
426 FilePath(GTEST_PATH_SEP_ GTEST_PATH_SEP_ GTEST_PATH_SEP_
"bar").
string());
430 TEST(NormalizeTest, MultipleConsecutiveSepaparatorsAtStringEnd) {
432 FilePath(
"foo" GTEST_PATH_SEP_).
string());
434 FilePath(
"foo" GTEST_PATH_SEP_ GTEST_PATH_SEP_).
string());
436 FilePath(
"foo" GTEST_PATH_SEP_ GTEST_PATH_SEP_ GTEST_PATH_SEP_).
string());
439 #if GTEST_HAS_ALT_PATH_SEP_
444 TEST(NormalizeTest, MixAlternateSeparatorAtStringEnd) {
446 FilePath(
"foo/").
string());
448 FilePath(
"foo" GTEST_PATH_SEP_
"/").
string());
450 FilePath(
"foo//" GTEST_PATH_SEP_).
string());
455 TEST(AssignmentOperatorTest, DefaultAssignedToNonDefault) {
456 FilePath default_path;
457 FilePath non_default_path(
"path");
458 non_default_path = default_path;
459 EXPECT_EQ(
"", non_default_path.string());
463 TEST(AssignmentOperatorTest, NonDefaultAssignedToDefault) {
464 FilePath non_default_path(
"path");
465 FilePath default_path;
466 default_path = non_default_path;
467 EXPECT_EQ(
"path", default_path.string());
468 EXPECT_EQ(
"path", non_default_path.string());
471 TEST(AssignmentOperatorTest, ConstAssignedToNonConst) {
472 const FilePath const_default_path(
"const_path");
473 FilePath non_default_path(
"path");
474 non_default_path = const_default_path;
475 EXPECT_EQ(
"const_path", non_default_path.string());
478 class DirectoryCreationTest :
public Test {
480 void SetUp()
override {
483 "_directory_creation" GTEST_PATH_SEP_
"test" GTEST_PATH_SEP_));
497 void TearDown()
override {
504 void CreateTextFile(
const char* filename) {
506 fprintf(f,
"text\n");
519 TEST_F(DirectoryCreationTest, CreateDirectoriesRecursively) {
525 TEST_F(DirectoryCreationTest, CreateDirectoriesForAlreadyExistingPath) {
532 TEST_F(DirectoryCreationTest, CreateDirectoriesAndUniqueFilename) {
533 FilePath file_path(FilePath::GenerateUniqueFileName(
testdata_path_,
534 FilePath(
"unique"),
"txt"));
540 CreateTextFile(file_path.c_str());
543 FilePath file_path2(FilePath::GenerateUniqueFileName(
testdata_path_,
544 FilePath(
"unique"),
"txt"));
547 CreateTextFile(file_path2.c_str());
551 TEST_F(DirectoryCreationTest, CreateDirectoriesFail) {
559 TEST(NoDirectoryCreationTest, CreateNoDirectoriesForDefaultXmlFile) {
560 const FilePath test_detail_xml(
"test_detail.xml");
561 EXPECT_FALSE(test_detail_xml.CreateDirectoriesRecursively());
564 TEST(FilePathTest, DefaultConstructor) {
569 TEST(FilePathTest, CharAndCopyConstructors) {
570 const FilePath fp(
"spicy");
573 const FilePath fp_copy(fp);
577 TEST(FilePathTest, StringConstructor) {
578 const FilePath fp(std::string(
"cider"));
582 TEST(FilePathTest, Set) {
583 const FilePath apple(
"apple");
590 TEST(FilePathTest, ToString) {
591 const FilePath file(
"drink");
595 TEST(FilePathTest, RemoveExtension) {
596 EXPECT_EQ(
"app", FilePath(
"app.cc").RemoveExtension(
"cc").
string());
597 EXPECT_EQ(
"app", FilePath(
"app.exe").RemoveExtension(
"exe").
string());
598 EXPECT_EQ(
"APP", FilePath(
"APP.EXE").RemoveExtension(
"exe").
string());
601 TEST(FilePathTest, RemoveExtensionWhenThereIsNoExtension) {
602 EXPECT_EQ(
"app", FilePath(
"app").RemoveExtension(
"exe").
string());
605 TEST(FilePathTest, IsDirectory) {
607 EXPECT_TRUE(FilePath(
"koala" GTEST_PATH_SEP_).IsDirectory());
608 #if GTEST_HAS_ALT_PATH_SEP_
613 TEST(FilePathTest, IsAbsolutePath) {
614 EXPECT_FALSE(FilePath(
"is" GTEST_PATH_SEP_
"relative").IsAbsolutePath());
617 EXPECT_TRUE(FilePath(
"c:\\" GTEST_PATH_SEP_
"is_not"
618 GTEST_PATH_SEP_
"relative").IsAbsolutePath());
619 EXPECT_FALSE(FilePath(
"c:foo" GTEST_PATH_SEP_
"bar").IsAbsolutePath());
620 EXPECT_TRUE(FilePath(
"c:/" GTEST_PATH_SEP_
"is_not"
621 GTEST_PATH_SEP_
"relative").IsAbsolutePath());
623 EXPECT_TRUE(FilePath(GTEST_PATH_SEP_
"is_not" GTEST_PATH_SEP_
"relative")
625 #endif // GTEST_OS_WINDOWS
628 TEST(FilePathTest, IsRootDirectory) {
int ChDir(const char *dir)
TEST_F(ListenerTest, DoesFoo)
#define ASSERT_TRUE(condition)
int RmDir(const char *dir)
#define EXPECT_STREQ(s1, s2)
FilePath GetCurrentExecutableName()
FILE * FOpen(const char *path, const char *mode)
#define EXPECT_EQ(val1, val2)
#define EXPECT_TRUE(condition)
#define EXPECT_FALSE(condition)
TEST(IsXDigitTest, WorksForNarrowAscii)
GTEST_API_ std::string TempDir()