49 #define GTEST_IMPLEMENTATION_ 1
51 #undef GTEST_IMPLEMENTATION_
53 #if GTEST_OS_WINDOWS_MOBILE
55 #elif GTEST_OS_WINDOWS
57 #endif // GTEST_OS_WINDOWS_MOBILE
63 #if GTEST_OS_WINDOWS_MOBILE
68 int remove(
const char*
path) {
69 LPCWSTR wpath = String::AnsiToUtf16(
path);
70 int ret = DeleteFile(wpath) ? 0 : -1;
75 int _rmdir(
const char*
path) {
76 FilePath filepath(path);
77 LPCWSTR wpath = String::AnsiToUtf16(
78 filepath.RemoveTrailingPathSeparator().c_str());
79 int ret = RemoveDirectory(wpath) ? 0 : -1;
86 TEST(GetCurrentDirTest, ReturnsCurrentDir) {
97 const char*
const cwd_without_drive = strchr(cwd.c_str(),
':');
108 #endif // GTEST_OS_WINDOWS_MOBILE
110 TEST(IsEmptyTest, ReturnsTrueForEmptyPath) {
114 TEST(IsEmptyTest, ReturnsFalseForNonEmptyPath) {
122 TEST(RemoveDirectoryNameTest, WhenEmptyName) {
123 EXPECT_EQ(
"", FilePath(
"").RemoveDirectoryName().
string());
127 TEST(RemoveDirectoryNameTest, ButNoDirectory) {
129 FilePath(
"afile").RemoveDirectoryName().
string());
133 TEST(RemoveDirectoryNameTest, RootFileShouldGiveFileName) {
139 TEST(RemoveDirectoryNameTest, WhereThereIsNoFileName) {
145 TEST(RemoveDirectoryNameTest, ShouldGiveFileName) {
147 FilePath(
"adir" GTEST_PATH_SEP_ "afile").RemoveDirectoryName().
string());
151 TEST(RemoveDirectoryNameTest, ShouldAlsoGiveFileName) {
154 .RemoveDirectoryName().
string());
157 #if GTEST_HAS_ALT_PATH_SEP_
163 TEST(RemoveDirectoryNameTest, RootFileShouldGiveFileNameForAlternateSeparator) {
164 EXPECT_EQ(
"afile", FilePath(
"/afile").RemoveDirectoryName().
string());
168 TEST(RemoveDirectoryNameTest, WhereThereIsNoFileNameForAlternateSeparator) {
169 EXPECT_EQ(
"", FilePath(
"adir/").RemoveDirectoryName().
string());
173 TEST(RemoveDirectoryNameTest, ShouldGiveFileNameForAlternateSeparator) {
174 EXPECT_EQ(
"afile", FilePath(
"adir/afile").RemoveDirectoryName().
string());
178 TEST(RemoveDirectoryNameTest, ShouldAlsoGiveFileNameForAlternateSeparator) {
180 FilePath(
"adir/subdir/afile").RemoveDirectoryName().
string());
186 TEST(RemoveFileNameTest, EmptyName) {
187 #if GTEST_OS_WINDOWS_MOBILE
196 TEST(RemoveFileNameTest, ButNoFile) {
202 TEST(RemoveFileNameTest, GivesDirName) {
208 TEST(RemoveFileNameTest, GivesDirAndSubDirName) {
210 FilePath(
"adir" GTEST_PATH_SEP_
"subdir" GTEST_PATH_SEP_
"afile")
211 .RemoveFileName().
string());
215 TEST(RemoveFileNameTest, GivesRootDir) {
220 #if GTEST_HAS_ALT_PATH_SEP_
226 TEST(RemoveFileNameTest, ButNoFileForAlternateSeparator) {
228 FilePath(
"adir/").RemoveFileName().
string());
232 TEST(RemoveFileNameTest, GivesDirNameForAlternateSeparator) {
234 FilePath(
"adir/afile").RemoveFileName().
string());
238 TEST(RemoveFileNameTest, GivesDirAndSubDirNameForAlternateSeparator) {
240 FilePath(
"adir/subdir/afile").RemoveFileName().
string());
244 TEST(RemoveFileNameTest, GivesRootDirForAlternateSeparator) {
250 TEST(MakeFileNameTest, GenerateWhenNumberIsZero) {
256 TEST(MakeFileNameTest, GenerateFileNameNumberGtZero) {
262 TEST(MakeFileNameTest, GenerateFileNameWithSlashNumberIsZero) {
264 FilePath(
"bar"), 0,
"xml");
268 TEST(MakeFileNameTest, GenerateFileNameWithSlashNumberGtZero) {
270 FilePath(
"bar"), 12,
"xml");
274 TEST(MakeFileNameTest, GenerateWhenNumberIsZeroAndDirIsEmpty) {
280 TEST(MakeFileNameTest, GenerateWhenNumberIsNotZeroAndDirIsEmpty) {
283 EXPECT_EQ(
"bar_14.xml", actual.string());
286 TEST(ConcatPathsTest, WorksWhenDirDoesNotEndWithPathSep) {
288 FilePath(
"bar.xml"));
292 TEST(ConcatPathsTest, WorksWhenPath1EndsWithPathSep) {
294 FilePath(
"bar.xml"));
298 TEST(ConcatPathsTest, Path1BeingEmpty) {
300 FilePath(
"bar.xml"));
304 TEST(ConcatPathsTest, Path2BeingEmpty) {
309 TEST(ConcatPathsTest, BothPathBeingEmpty) {
315 TEST(ConcatPathsTest, Path1ContainsPathSep) {
317 FilePath(
"foobar.xml"));
322 TEST(ConcatPathsTest, Path2ContainsPathSep) {
330 TEST(ConcatPathsTest, Path2EndsWithPathSep) {
337 TEST(RemoveTrailingPathSeparatorTest, EmptyString) {
338 EXPECT_EQ(
"", FilePath(
"").RemoveTrailingPathSeparator().
string());
342 TEST(RemoveTrailingPathSeparatorTest, FileNoSlashString) {
343 EXPECT_EQ(
"foo", FilePath(
"foo").RemoveTrailingPathSeparator().
string());
347 TEST(RemoveTrailingPathSeparatorTest, ShouldRemoveTrailingSeparator) {
349 FilePath(
"foo" GTEST_PATH_SEP_).RemoveTrailingPathSeparator().
string());
350 #if GTEST_HAS_ALT_PATH_SEP_
351 EXPECT_EQ(
"foo", FilePath(
"foo/").RemoveTrailingPathSeparator().
string());
356 TEST(RemoveTrailingPathSeparatorTest, ShouldRemoveLastSeparator) {
359 .RemoveTrailingPathSeparator().
string());
363 TEST(RemoveTrailingPathSeparatorTest, ShouldReturnUnmodified) {
366 .RemoveTrailingPathSeparator().
string());
369 TEST(DirectoryTest, RootDirectoryExists) {
370 #if GTEST_OS_WINDOWS // We are on Windows.
371 char current_drive[_MAX_PATH];
372 current_drive[0] =
static_cast<char>(_getdrive() +
'A' - 1);
373 current_drive[1] =
':';
374 current_drive[2] =
'\\';
375 current_drive[3] =
'\0';
376 EXPECT_TRUE(FilePath(current_drive).DirectoryExists());
379 #endif // GTEST_OS_WINDOWS
383 TEST(DirectoryTest, RootOfWrongDriveDoesNotExists) {
384 const int saved_drive_ = _getdrive();
386 for (
char drive =
'Z'; drive >=
'A'; drive--)
387 if (_chdrive(drive -
'A' + 1) == -1) {
388 char non_drive[_MAX_PATH];
389 non_drive[0] = drive;
396 _chdrive(saved_drive_);
398 #endif // GTEST_OS_WINDOWS
400 #if !GTEST_OS_WINDOWS_MOBILE
402 TEST(DirectoryTest, EmptyPathDirectoryDoesNotExist) {
405 #endif // !GTEST_OS_WINDOWS_MOBILE
407 TEST(DirectoryTest, CurrentDirectoryExists) {
408 #if GTEST_OS_WINDOWS // We are on Windows.
409 # ifndef _WIN32_CE // Windows CE doesn't have a current directory.
418 #endif // GTEST_OS_WINDOWS
422 TEST(NormalizeTest, MultipleConsecutiveSepaparatorsInMidstring) {
428 FilePath(
"foo" GTEST_PATH_SEP_ GTEST_PATH_SEP_
429 GTEST_PATH_SEP_
"bar").
string());
433 TEST(NormalizeTest, MultipleConsecutiveSepaparatorsAtStringStart) {
439 FilePath(GTEST_PATH_SEP_ GTEST_PATH_SEP_ GTEST_PATH_SEP_
"bar").
string());
443 TEST(NormalizeTest, MultipleConsecutiveSepaparatorsAtStringEnd) {
449 FilePath(
"foo" GTEST_PATH_SEP_ GTEST_PATH_SEP_ GTEST_PATH_SEP_).
string());
452 #if GTEST_HAS_ALT_PATH_SEP_
457 TEST(NormalizeTest, MixAlternateSeparatorAtStringEnd) {
459 FilePath(
"foo/").
string());
468 TEST(AssignmentOperatorTest, DefaultAssignedToNonDefault) {
469 FilePath default_path;
470 FilePath non_default_path(
"path");
471 non_default_path = default_path;
472 EXPECT_EQ(
"", non_default_path.string());
476 TEST(AssignmentOperatorTest, NonDefaultAssignedToDefault) {
477 FilePath non_default_path(
"path");
478 FilePath default_path;
479 default_path = non_default_path;
480 EXPECT_EQ(
"path", default_path.string());
481 EXPECT_EQ(
"path", non_default_path.string());
484 TEST(AssignmentOperatorTest, ConstAssignedToNonConst) {
485 const FilePath const_default_path(
"const_path");
486 FilePath non_default_path(
"path");
487 non_default_path = const_default_path;
488 EXPECT_EQ(
"const_path", non_default_path.string());
491 class DirectoryCreationTest :
public Test {
493 virtual void SetUp() {
510 virtual void TearDown() {
517 void CreateTextFile(
const char*
filename) {
532 TEST_F(DirectoryCreationTest, CreateDirectoriesRecursively) {
538 TEST_F(DirectoryCreationTest, CreateDirectoriesForAlreadyExistingPath) {
545 TEST_F(DirectoryCreationTest, CreateDirectoriesAndUniqueFilename) {
547 FilePath(
"unique"),
"txt"));
553 CreateTextFile(file_path.c_str());
557 FilePath(
"unique"),
"txt"));
560 CreateTextFile(file_path2.c_str());
564 TEST_F(DirectoryCreationTest, CreateDirectoriesFail) {
572 TEST(NoDirectoryCreationTest, CreateNoDirectoriesForDefaultXmlFile) {
573 const FilePath test_detail_xml(
"test_detail.xml");
574 EXPECT_FALSE(test_detail_xml.CreateDirectoriesRecursively());
577 TEST(FilePathTest, DefaultConstructor) {
582 TEST(FilePathTest, CharAndCopyConstructors) {
583 const FilePath fp(
"spicy");
586 const FilePath fp_copy(fp);
590 TEST(FilePathTest, StringConstructor) {
596 const FilePath apple(
"apple");
603 TEST(FilePathTest, ToString) {
604 const FilePath
file(
"drink");
608 TEST(FilePathTest, RemoveExtension) {
609 EXPECT_EQ(
"app", FilePath(
"app.cc").RemoveExtension(
"cc").
string());
610 EXPECT_EQ(
"app", FilePath(
"app.exe").RemoveExtension(
"exe").
string());
611 EXPECT_EQ(
"APP", FilePath(
"APP.EXE").RemoveExtension(
"exe").
string());
614 TEST(FilePathTest, RemoveExtensionWhenThereIsNoExtension) {
615 EXPECT_EQ(
"app", FilePath(
"app").RemoveExtension(
"exe").
string());
618 TEST(FilePathTest, IsDirectory) {
621 #if GTEST_HAS_ALT_PATH_SEP_
626 TEST(FilePathTest, IsAbsolutePath) {
632 EXPECT_FALSE(FilePath(
"c:foo" GTEST_PATH_SEP_
"bar").IsAbsolutePath());
633 EXPECT_TRUE(FilePath(
"c:/" GTEST_PATH_SEP_
"is_not"
634 GTEST_PATH_SEP_
"relative").IsAbsolutePath());
636 EXPECT_TRUE(FilePath(GTEST_PATH_SEP_
"is_not" GTEST_PATH_SEP_
"relative")
638 #endif // GTEST_OS_WINDOWS
641 TEST(FilePathTest, IsRootDirectory) {