00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 #include "gtest/internal/gtest-filepath.h"
00042 #include "gtest/gtest.h"
00043
00044
00045
00046
00047
00048
00049 #define GTEST_IMPLEMENTATION_ 1
00050 #include "src/gtest-internal-inl.h"
00051 #undef GTEST_IMPLEMENTATION_
00052
00053 #if GTEST_OS_WINDOWS_MOBILE
00054 # include <windows.h>
00055 #elif GTEST_OS_WINDOWS
00056 # include <direct.h>
00057 #endif // GTEST_OS_WINDOWS_MOBILE
00058
00059 namespace testing {
00060 namespace internal {
00061 namespace {
00062
00063 #if GTEST_OS_WINDOWS_MOBILE
00064
00065
00066
00067
00068 int remove(const char* path) {
00069 LPCWSTR wpath = String::AnsiToUtf16(path);
00070 int ret = DeleteFile(wpath) ? 0 : -1;
00071 delete [] wpath;
00072 return ret;
00073 }
00074
00075 int _rmdir(const char* path) {
00076 FilePath filepath(path);
00077 LPCWSTR wpath = String::AnsiToUtf16(
00078 filepath.RemoveTrailingPathSeparator().c_str());
00079 int ret = RemoveDirectory(wpath) ? 0 : -1;
00080 delete [] wpath;
00081 return ret;
00082 }
00083
00084 #else
00085
00086 TEST(GetCurrentDirTest, ReturnsCurrentDir) {
00087 const FilePath original_dir = FilePath::GetCurrentDir();
00088 EXPECT_FALSE(original_dir.IsEmpty());
00089
00090 posix::ChDir(GTEST_PATH_SEP_);
00091 const FilePath cwd = FilePath::GetCurrentDir();
00092 posix::ChDir(original_dir.c_str());
00093
00094 # if GTEST_OS_WINDOWS
00095
00096
00097 const char* const cwd_without_drive = strchr(cwd.c_str(), ':');
00098 ASSERT_TRUE(cwd_without_drive != NULL);
00099 EXPECT_STREQ(GTEST_PATH_SEP_, cwd_without_drive + 1);
00100
00101 # else
00102
00103 EXPECT_EQ(GTEST_PATH_SEP_, cwd.string());
00104
00105 # endif
00106 }
00107
00108 #endif // GTEST_OS_WINDOWS_MOBILE
00109
00110 TEST(IsEmptyTest, ReturnsTrueForEmptyPath) {
00111 EXPECT_TRUE(FilePath("").IsEmpty());
00112 }
00113
00114 TEST(IsEmptyTest, ReturnsFalseForNonEmptyPath) {
00115 EXPECT_FALSE(FilePath("a").IsEmpty());
00116 EXPECT_FALSE(FilePath(".").IsEmpty());
00117 EXPECT_FALSE(FilePath("a/b").IsEmpty());
00118 EXPECT_FALSE(FilePath("a\\b\\").IsEmpty());
00119 }
00120
00121
00122 TEST(RemoveDirectoryNameTest, WhenEmptyName) {
00123 EXPECT_EQ("", FilePath("").RemoveDirectoryName().string());
00124 }
00125
00126
00127 TEST(RemoveDirectoryNameTest, ButNoDirectory) {
00128 EXPECT_EQ("afile",
00129 FilePath("afile").RemoveDirectoryName().string());
00130 }
00131
00132
00133 TEST(RemoveDirectoryNameTest, RootFileShouldGiveFileName) {
00134 EXPECT_EQ("afile",
00135 FilePath(GTEST_PATH_SEP_ "afile").RemoveDirectoryName().string());
00136 }
00137
00138
00139 TEST(RemoveDirectoryNameTest, WhereThereIsNoFileName) {
00140 EXPECT_EQ("",
00141 FilePath("adir" GTEST_PATH_SEP_).RemoveDirectoryName().string());
00142 }
00143
00144
00145 TEST(RemoveDirectoryNameTest, ShouldGiveFileName) {
00146 EXPECT_EQ("afile",
00147 FilePath("adir" GTEST_PATH_SEP_ "afile").RemoveDirectoryName().string());
00148 }
00149
00150
00151 TEST(RemoveDirectoryNameTest, ShouldAlsoGiveFileName) {
00152 EXPECT_EQ("afile",
00153 FilePath("adir" GTEST_PATH_SEP_ "subdir" GTEST_PATH_SEP_ "afile")
00154 .RemoveDirectoryName().string());
00155 }
00156
00157 #if GTEST_HAS_ALT_PATH_SEP_
00158
00159
00160
00161
00162
00163 TEST(RemoveDirectoryNameTest, RootFileShouldGiveFileNameForAlternateSeparator) {
00164 EXPECT_EQ("afile", FilePath("/afile").RemoveDirectoryName().string());
00165 }
00166
00167
00168 TEST(RemoveDirectoryNameTest, WhereThereIsNoFileNameForAlternateSeparator) {
00169 EXPECT_EQ("", FilePath("adir/").RemoveDirectoryName().string());
00170 }
00171
00172
00173 TEST(RemoveDirectoryNameTest, ShouldGiveFileNameForAlternateSeparator) {
00174 EXPECT_EQ("afile", FilePath("adir/afile").RemoveDirectoryName().string());
00175 }
00176
00177
00178 TEST(RemoveDirectoryNameTest, ShouldAlsoGiveFileNameForAlternateSeparator) {
00179 EXPECT_EQ("afile",
00180 FilePath("adir/subdir/afile").RemoveDirectoryName().string());
00181 }
00182
00183 #endif
00184
00185
00186 TEST(RemoveFileNameTest, EmptyName) {
00187 #if GTEST_OS_WINDOWS_MOBILE
00188
00189 EXPECT_EQ(GTEST_PATH_SEP_, FilePath("").RemoveFileName().string());
00190 #else
00191 EXPECT_EQ("." GTEST_PATH_SEP_, FilePath("").RemoveFileName().string());
00192 #endif
00193 }
00194
00195
00196 TEST(RemoveFileNameTest, ButNoFile) {
00197 EXPECT_EQ("adir" GTEST_PATH_SEP_,
00198 FilePath("adir" GTEST_PATH_SEP_).RemoveFileName().string());
00199 }
00200
00201
00202 TEST(RemoveFileNameTest, GivesDirName) {
00203 EXPECT_EQ("adir" GTEST_PATH_SEP_,
00204 FilePath("adir" GTEST_PATH_SEP_ "afile").RemoveFileName().string());
00205 }
00206
00207
00208 TEST(RemoveFileNameTest, GivesDirAndSubDirName) {
00209 EXPECT_EQ("adir" GTEST_PATH_SEP_ "subdir" GTEST_PATH_SEP_,
00210 FilePath("adir" GTEST_PATH_SEP_ "subdir" GTEST_PATH_SEP_ "afile")
00211 .RemoveFileName().string());
00212 }
00213
00214
00215 TEST(RemoveFileNameTest, GivesRootDir) {
00216 EXPECT_EQ(GTEST_PATH_SEP_,
00217 FilePath(GTEST_PATH_SEP_ "afile").RemoveFileName().string());
00218 }
00219
00220 #if GTEST_HAS_ALT_PATH_SEP_
00221
00222
00223
00224
00225
00226 TEST(RemoveFileNameTest, ButNoFileForAlternateSeparator) {
00227 EXPECT_EQ("adir" GTEST_PATH_SEP_,
00228 FilePath("adir/").RemoveFileName().string());
00229 }
00230
00231
00232 TEST(RemoveFileNameTest, GivesDirNameForAlternateSeparator) {
00233 EXPECT_EQ("adir" GTEST_PATH_SEP_,
00234 FilePath("adir/afile").RemoveFileName().string());
00235 }
00236
00237
00238 TEST(RemoveFileNameTest, GivesDirAndSubDirNameForAlternateSeparator) {
00239 EXPECT_EQ("adir" GTEST_PATH_SEP_ "subdir" GTEST_PATH_SEP_,
00240 FilePath("adir/subdir/afile").RemoveFileName().string());
00241 }
00242
00243
00244 TEST(RemoveFileNameTest, GivesRootDirForAlternateSeparator) {
00245 EXPECT_EQ(GTEST_PATH_SEP_, FilePath("/afile").RemoveFileName().string());
00246 }
00247
00248 #endif
00249
00250 TEST(MakeFileNameTest, GenerateWhenNumberIsZero) {
00251 FilePath actual = FilePath::MakeFileName(FilePath("foo"), FilePath("bar"),
00252 0, "xml");
00253 EXPECT_EQ("foo" GTEST_PATH_SEP_ "bar.xml", actual.string());
00254 }
00255
00256 TEST(MakeFileNameTest, GenerateFileNameNumberGtZero) {
00257 FilePath actual = FilePath::MakeFileName(FilePath("foo"), FilePath("bar"),
00258 12, "xml");
00259 EXPECT_EQ("foo" GTEST_PATH_SEP_ "bar_12.xml", actual.string());
00260 }
00261
00262 TEST(MakeFileNameTest, GenerateFileNameWithSlashNumberIsZero) {
00263 FilePath actual = FilePath::MakeFileName(FilePath("foo" GTEST_PATH_SEP_),
00264 FilePath("bar"), 0, "xml");
00265 EXPECT_EQ("foo" GTEST_PATH_SEP_ "bar.xml", actual.string());
00266 }
00267
00268 TEST(MakeFileNameTest, GenerateFileNameWithSlashNumberGtZero) {
00269 FilePath actual = FilePath::MakeFileName(FilePath("foo" GTEST_PATH_SEP_),
00270 FilePath("bar"), 12, "xml");
00271 EXPECT_EQ("foo" GTEST_PATH_SEP_ "bar_12.xml", actual.string());
00272 }
00273
00274 TEST(MakeFileNameTest, GenerateWhenNumberIsZeroAndDirIsEmpty) {
00275 FilePath actual = FilePath::MakeFileName(FilePath(""), FilePath("bar"),
00276 0, "xml");
00277 EXPECT_EQ("bar.xml", actual.string());
00278 }
00279
00280 TEST(MakeFileNameTest, GenerateWhenNumberIsNotZeroAndDirIsEmpty) {
00281 FilePath actual = FilePath::MakeFileName(FilePath(""), FilePath("bar"),
00282 14, "xml");
00283 EXPECT_EQ("bar_14.xml", actual.string());
00284 }
00285
00286 TEST(ConcatPathsTest, WorksWhenDirDoesNotEndWithPathSep) {
00287 FilePath actual = FilePath::ConcatPaths(FilePath("foo"),
00288 FilePath("bar.xml"));
00289 EXPECT_EQ("foo" GTEST_PATH_SEP_ "bar.xml", actual.string());
00290 }
00291
00292 TEST(ConcatPathsTest, WorksWhenPath1EndsWithPathSep) {
00293 FilePath actual = FilePath::ConcatPaths(FilePath("foo" GTEST_PATH_SEP_),
00294 FilePath("bar.xml"));
00295 EXPECT_EQ("foo" GTEST_PATH_SEP_ "bar.xml", actual.string());
00296 }
00297
00298 TEST(ConcatPathsTest, Path1BeingEmpty) {
00299 FilePath actual = FilePath::ConcatPaths(FilePath(""),
00300 FilePath("bar.xml"));
00301 EXPECT_EQ("bar.xml", actual.string());
00302 }
00303
00304 TEST(ConcatPathsTest, Path2BeingEmpty) {
00305 FilePath actual = FilePath::ConcatPaths(FilePath("foo"), FilePath(""));
00306 EXPECT_EQ("foo" GTEST_PATH_SEP_, actual.string());
00307 }
00308
00309 TEST(ConcatPathsTest, BothPathBeingEmpty) {
00310 FilePath actual = FilePath::ConcatPaths(FilePath(""),
00311 FilePath(""));
00312 EXPECT_EQ("", actual.string());
00313 }
00314
00315 TEST(ConcatPathsTest, Path1ContainsPathSep) {
00316 FilePath actual = FilePath::ConcatPaths(FilePath("foo" GTEST_PATH_SEP_ "bar"),
00317 FilePath("foobar.xml"));
00318 EXPECT_EQ("foo" GTEST_PATH_SEP_ "bar" GTEST_PATH_SEP_ "foobar.xml",
00319 actual.string());
00320 }
00321
00322 TEST(ConcatPathsTest, Path2ContainsPathSep) {
00323 FilePath actual = FilePath::ConcatPaths(
00324 FilePath("foo" GTEST_PATH_SEP_),
00325 FilePath("bar" GTEST_PATH_SEP_ "bar.xml"));
00326 EXPECT_EQ("foo" GTEST_PATH_SEP_ "bar" GTEST_PATH_SEP_ "bar.xml",
00327 actual.string());
00328 }
00329
00330 TEST(ConcatPathsTest, Path2EndsWithPathSep) {
00331 FilePath actual = FilePath::ConcatPaths(FilePath("foo"),
00332 FilePath("bar" GTEST_PATH_SEP_));
00333 EXPECT_EQ("foo" GTEST_PATH_SEP_ "bar" GTEST_PATH_SEP_, actual.string());
00334 }
00335
00336
00337 TEST(RemoveTrailingPathSeparatorTest, EmptyString) {
00338 EXPECT_EQ("", FilePath("").RemoveTrailingPathSeparator().string());
00339 }
00340
00341
00342 TEST(RemoveTrailingPathSeparatorTest, FileNoSlashString) {
00343 EXPECT_EQ("foo", FilePath("foo").RemoveTrailingPathSeparator().string());
00344 }
00345
00346
00347 TEST(RemoveTrailingPathSeparatorTest, ShouldRemoveTrailingSeparator) {
00348 EXPECT_EQ("foo",
00349 FilePath("foo" GTEST_PATH_SEP_).RemoveTrailingPathSeparator().string());
00350 #if GTEST_HAS_ALT_PATH_SEP_
00351 EXPECT_EQ("foo", FilePath("foo/").RemoveTrailingPathSeparator().string());
00352 #endif
00353 }
00354
00355
00356 TEST(RemoveTrailingPathSeparatorTest, ShouldRemoveLastSeparator) {
00357 EXPECT_EQ("foo" GTEST_PATH_SEP_ "bar",
00358 FilePath("foo" GTEST_PATH_SEP_ "bar" GTEST_PATH_SEP_)
00359 .RemoveTrailingPathSeparator().string());
00360 }
00361
00362
00363 TEST(RemoveTrailingPathSeparatorTest, ShouldReturnUnmodified) {
00364 EXPECT_EQ("foo" GTEST_PATH_SEP_ "bar",
00365 FilePath("foo" GTEST_PATH_SEP_ "bar")
00366 .RemoveTrailingPathSeparator().string());
00367 }
00368
00369 TEST(DirectoryTest, RootDirectoryExists) {
00370 #if GTEST_OS_WINDOWS // We are on Windows.
00371 char current_drive[_MAX_PATH];
00372 current_drive[0] = static_cast<char>(_getdrive() + 'A' - 1);
00373 current_drive[1] = ':';
00374 current_drive[2] = '\\';
00375 current_drive[3] = '\0';
00376 EXPECT_TRUE(FilePath(current_drive).DirectoryExists());
00377 #else
00378 EXPECT_TRUE(FilePath("/").DirectoryExists());
00379 #endif // GTEST_OS_WINDOWS
00380 }
00381
00382 #if GTEST_OS_WINDOWS
00383 TEST(DirectoryTest, RootOfWrongDriveDoesNotExists) {
00384 const int saved_drive_ = _getdrive();
00385
00386 for (char drive = 'Z'; drive >= 'A'; drive--)
00387 if (_chdrive(drive - 'A' + 1) == -1) {
00388 char non_drive[_MAX_PATH];
00389 non_drive[0] = drive;
00390 non_drive[1] = ':';
00391 non_drive[2] = '\\';
00392 non_drive[3] = '\0';
00393 EXPECT_FALSE(FilePath(non_drive).DirectoryExists());
00394 break;
00395 }
00396 _chdrive(saved_drive_);
00397 }
00398 #endif // GTEST_OS_WINDOWS
00399
00400 #if !GTEST_OS_WINDOWS_MOBILE
00401
00402 TEST(DirectoryTest, EmptyPathDirectoryDoesNotExist) {
00403 EXPECT_FALSE(FilePath("").DirectoryExists());
00404 }
00405 #endif // !GTEST_OS_WINDOWS_MOBILE
00406
00407 TEST(DirectoryTest, CurrentDirectoryExists) {
00408 #if GTEST_OS_WINDOWS // We are on Windows.
00409 # ifndef _WIN32_CE // Windows CE doesn't have a current directory.
00410
00411 EXPECT_TRUE(FilePath(".").DirectoryExists());
00412 EXPECT_TRUE(FilePath(".\\").DirectoryExists());
00413
00414 # endif // _WIN32_CE
00415 #else
00416 EXPECT_TRUE(FilePath(".").DirectoryExists());
00417 EXPECT_TRUE(FilePath("./").DirectoryExists());
00418 #endif // GTEST_OS_WINDOWS
00419 }
00420
00421
00422 TEST(NormalizeTest, MultipleConsecutiveSepaparatorsInMidstring) {
00423 EXPECT_EQ("foo" GTEST_PATH_SEP_ "bar",
00424 FilePath("foo" GTEST_PATH_SEP_ "bar").string());
00425 EXPECT_EQ("foo" GTEST_PATH_SEP_ "bar",
00426 FilePath("foo" GTEST_PATH_SEP_ GTEST_PATH_SEP_ "bar").string());
00427 EXPECT_EQ("foo" GTEST_PATH_SEP_ "bar",
00428 FilePath("foo" GTEST_PATH_SEP_ GTEST_PATH_SEP_
00429 GTEST_PATH_SEP_ "bar").string());
00430 }
00431
00432
00433 TEST(NormalizeTest, MultipleConsecutiveSepaparatorsAtStringStart) {
00434 EXPECT_EQ(GTEST_PATH_SEP_ "bar",
00435 FilePath(GTEST_PATH_SEP_ "bar").string());
00436 EXPECT_EQ(GTEST_PATH_SEP_ "bar",
00437 FilePath(GTEST_PATH_SEP_ GTEST_PATH_SEP_ "bar").string());
00438 EXPECT_EQ(GTEST_PATH_SEP_ "bar",
00439 FilePath(GTEST_PATH_SEP_ GTEST_PATH_SEP_ GTEST_PATH_SEP_ "bar").string());
00440 }
00441
00442
00443 TEST(NormalizeTest, MultipleConsecutiveSepaparatorsAtStringEnd) {
00444 EXPECT_EQ("foo" GTEST_PATH_SEP_,
00445 FilePath("foo" GTEST_PATH_SEP_).string());
00446 EXPECT_EQ("foo" GTEST_PATH_SEP_,
00447 FilePath("foo" GTEST_PATH_SEP_ GTEST_PATH_SEP_).string());
00448 EXPECT_EQ("foo" GTEST_PATH_SEP_,
00449 FilePath("foo" GTEST_PATH_SEP_ GTEST_PATH_SEP_ GTEST_PATH_SEP_).string());
00450 }
00451
00452 #if GTEST_HAS_ALT_PATH_SEP_
00453
00454
00455
00456
00457 TEST(NormalizeTest, MixAlternateSeparatorAtStringEnd) {
00458 EXPECT_EQ("foo" GTEST_PATH_SEP_,
00459 FilePath("foo/").string());
00460 EXPECT_EQ("foo" GTEST_PATH_SEP_,
00461 FilePath("foo" GTEST_PATH_SEP_ "/").string());
00462 EXPECT_EQ("foo" GTEST_PATH_SEP_,
00463 FilePath("foo//" GTEST_PATH_SEP_).string());
00464 }
00465
00466 #endif
00467
00468 TEST(AssignmentOperatorTest, DefaultAssignedToNonDefault) {
00469 FilePath default_path;
00470 FilePath non_default_path("path");
00471 non_default_path = default_path;
00472 EXPECT_EQ("", non_default_path.string());
00473 EXPECT_EQ("", default_path.string());
00474 }
00475
00476 TEST(AssignmentOperatorTest, NonDefaultAssignedToDefault) {
00477 FilePath non_default_path("path");
00478 FilePath default_path;
00479 default_path = non_default_path;
00480 EXPECT_EQ("path", default_path.string());
00481 EXPECT_EQ("path", non_default_path.string());
00482 }
00483
00484 TEST(AssignmentOperatorTest, ConstAssignedToNonConst) {
00485 const FilePath const_default_path("const_path");
00486 FilePath non_default_path("path");
00487 non_default_path = const_default_path;
00488 EXPECT_EQ("const_path", non_default_path.string());
00489 }
00490
00491 class DirectoryCreationTest : public Test {
00492 protected:
00493 virtual void SetUp() {
00494 testdata_path_.Set(FilePath(
00495 TempDir() + GetCurrentExecutableName().string() +
00496 "_directory_creation" GTEST_PATH_SEP_ "test" GTEST_PATH_SEP_));
00497 testdata_file_.Set(testdata_path_.RemoveTrailingPathSeparator());
00498
00499 unique_file0_.Set(FilePath::MakeFileName(testdata_path_, FilePath("unique"),
00500 0, "txt"));
00501 unique_file1_.Set(FilePath::MakeFileName(testdata_path_, FilePath("unique"),
00502 1, "txt"));
00503
00504 remove(testdata_file_.c_str());
00505 remove(unique_file0_.c_str());
00506 remove(unique_file1_.c_str());
00507 posix::RmDir(testdata_path_.c_str());
00508 }
00509
00510 virtual void TearDown() {
00511 remove(testdata_file_.c_str());
00512 remove(unique_file0_.c_str());
00513 remove(unique_file1_.c_str());
00514 posix::RmDir(testdata_path_.c_str());
00515 }
00516
00517 std::string TempDir() const {
00518 #if GTEST_OS_WINDOWS_MOBILE
00519 return "\\temp\\";
00520 #elif GTEST_OS_WINDOWS
00521 const char* temp_dir = posix::GetEnv("TEMP");
00522 if (temp_dir == NULL || temp_dir[0] == '\0')
00523 return "\\temp\\";
00524 else if (temp_dir[strlen(temp_dir) - 1] == '\\')
00525 return temp_dir;
00526 else
00527 return std::string(temp_dir) + "\\";
00528 #elif GTEST_OS_LINUX_ANDROID
00529 return "/sdcard/";
00530 #else
00531 return "/tmp/";
00532 #endif // GTEST_OS_WINDOWS_MOBILE
00533 }
00534
00535 void CreateTextFile(const char* filename) {
00536 FILE* f = posix::FOpen(filename, "w");
00537 fprintf(f, "text\n");
00538 fclose(f);
00539 }
00540
00541
00542
00543
00544 FilePath testdata_path_;
00545 FilePath testdata_file_;
00546 FilePath unique_file0_;
00547 FilePath unique_file1_;
00548 };
00549
00550 TEST_F(DirectoryCreationTest, CreateDirectoriesRecursively) {
00551 EXPECT_FALSE(testdata_path_.DirectoryExists()) << testdata_path_.string();
00552 EXPECT_TRUE(testdata_path_.CreateDirectoriesRecursively());
00553 EXPECT_TRUE(testdata_path_.DirectoryExists());
00554 }
00555
00556 TEST_F(DirectoryCreationTest, CreateDirectoriesForAlreadyExistingPath) {
00557 EXPECT_FALSE(testdata_path_.DirectoryExists()) << testdata_path_.string();
00558 EXPECT_TRUE(testdata_path_.CreateDirectoriesRecursively());
00559
00560 EXPECT_TRUE(testdata_path_.CreateDirectoriesRecursively());
00561 }
00562
00563 TEST_F(DirectoryCreationTest, CreateDirectoriesAndUniqueFilename) {
00564 FilePath file_path(FilePath::GenerateUniqueFileName(testdata_path_,
00565 FilePath("unique"), "txt"));
00566 EXPECT_EQ(unique_file0_.string(), file_path.string());
00567 EXPECT_FALSE(file_path.FileOrDirectoryExists());
00568
00569 testdata_path_.CreateDirectoriesRecursively();
00570 EXPECT_FALSE(file_path.FileOrDirectoryExists());
00571 CreateTextFile(file_path.c_str());
00572 EXPECT_TRUE(file_path.FileOrDirectoryExists());
00573
00574 FilePath file_path2(FilePath::GenerateUniqueFileName(testdata_path_,
00575 FilePath("unique"), "txt"));
00576 EXPECT_EQ(unique_file1_.string(), file_path2.string());
00577 EXPECT_FALSE(file_path2.FileOrDirectoryExists());
00578 CreateTextFile(file_path2.c_str());
00579 EXPECT_TRUE(file_path2.FileOrDirectoryExists());
00580 }
00581
00582 TEST_F(DirectoryCreationTest, CreateDirectoriesFail) {
00583
00584 CreateTextFile(testdata_file_.c_str());
00585 EXPECT_TRUE(testdata_file_.FileOrDirectoryExists());
00586 EXPECT_FALSE(testdata_file_.DirectoryExists());
00587 EXPECT_FALSE(testdata_file_.CreateDirectoriesRecursively());
00588 }
00589
00590 TEST(NoDirectoryCreationTest, CreateNoDirectoriesForDefaultXmlFile) {
00591 const FilePath test_detail_xml("test_detail.xml");
00592 EXPECT_FALSE(test_detail_xml.CreateDirectoriesRecursively());
00593 }
00594
00595 TEST(FilePathTest, DefaultConstructor) {
00596 FilePath fp;
00597 EXPECT_EQ("", fp.string());
00598 }
00599
00600 TEST(FilePathTest, CharAndCopyConstructors) {
00601 const FilePath fp("spicy");
00602 EXPECT_EQ("spicy", fp.string());
00603
00604 const FilePath fp_copy(fp);
00605 EXPECT_EQ("spicy", fp_copy.string());
00606 }
00607
00608 TEST(FilePathTest, StringConstructor) {
00609 const FilePath fp(std::string("cider"));
00610 EXPECT_EQ("cider", fp.string());
00611 }
00612
00613 TEST(FilePathTest, Set) {
00614 const FilePath apple("apple");
00615 FilePath mac("mac");
00616 mac.Set(apple);
00617 EXPECT_EQ("apple", mac.string());
00618 EXPECT_EQ("apple", apple.string());
00619 }
00620
00621 TEST(FilePathTest, ToString) {
00622 const FilePath file("drink");
00623 EXPECT_EQ("drink", file.string());
00624 }
00625
00626 TEST(FilePathTest, RemoveExtension) {
00627 EXPECT_EQ("app", FilePath("app.cc").RemoveExtension("cc").string());
00628 EXPECT_EQ("app", FilePath("app.exe").RemoveExtension("exe").string());
00629 EXPECT_EQ("APP", FilePath("APP.EXE").RemoveExtension("exe").string());
00630 }
00631
00632 TEST(FilePathTest, RemoveExtensionWhenThereIsNoExtension) {
00633 EXPECT_EQ("app", FilePath("app").RemoveExtension("exe").string());
00634 }
00635
00636 TEST(FilePathTest, IsDirectory) {
00637 EXPECT_FALSE(FilePath("cola").IsDirectory());
00638 EXPECT_TRUE(FilePath("koala" GTEST_PATH_SEP_).IsDirectory());
00639 #if GTEST_HAS_ALT_PATH_SEP_
00640 EXPECT_TRUE(FilePath("koala/").IsDirectory());
00641 #endif
00642 }
00643
00644 TEST(FilePathTest, IsAbsolutePath) {
00645 EXPECT_FALSE(FilePath("is" GTEST_PATH_SEP_ "relative").IsAbsolutePath());
00646 EXPECT_FALSE(FilePath("").IsAbsolutePath());
00647 #if GTEST_OS_WINDOWS
00648 EXPECT_TRUE(FilePath("c:\\" GTEST_PATH_SEP_ "is_not"
00649 GTEST_PATH_SEP_ "relative").IsAbsolutePath());
00650 EXPECT_FALSE(FilePath("c:foo" GTEST_PATH_SEP_ "bar").IsAbsolutePath());
00651 EXPECT_TRUE(FilePath("c:/" GTEST_PATH_SEP_ "is_not"
00652 GTEST_PATH_SEP_ "relative").IsAbsolutePath());
00653 #else
00654 EXPECT_TRUE(FilePath(GTEST_PATH_SEP_ "is_not" GTEST_PATH_SEP_ "relative")
00655 .IsAbsolutePath());
00656 #endif // GTEST_OS_WINDOWS
00657 }
00658
00659 TEST(FilePathTest, IsRootDirectory) {
00660 #if GTEST_OS_WINDOWS
00661 EXPECT_TRUE(FilePath("a:\\").IsRootDirectory());
00662 EXPECT_TRUE(FilePath("Z:/").IsRootDirectory());
00663 EXPECT_TRUE(FilePath("e://").IsRootDirectory());
00664 EXPECT_FALSE(FilePath("").IsRootDirectory());
00665 EXPECT_FALSE(FilePath("b:").IsRootDirectory());
00666 EXPECT_FALSE(FilePath("b:a").IsRootDirectory());
00667 EXPECT_FALSE(FilePath("8:/").IsRootDirectory());
00668 EXPECT_FALSE(FilePath("c|/").IsRootDirectory());
00669 #else
00670 EXPECT_TRUE(FilePath("/").IsRootDirectory());
00671 EXPECT_TRUE(FilePath("//").IsRootDirectory());
00672 EXPECT_FALSE(FilePath("").IsRootDirectory());
00673 EXPECT_FALSE(FilePath("\\").IsRootDirectory());
00674 EXPECT_FALSE(FilePath("/x").IsRootDirectory());
00675 #endif
00676 }
00677
00678 }
00679 }
00680 }