summaryrefslogtreecommitdiffstats
path: root/base/file_util_unittest.cc
diff options
context:
space:
mode:
authormmoss@google.com <mmoss@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-09-11 16:09:11 +0000
committermmoss@google.com <mmoss@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-09-11 16:09:11 +0000
commit806b9c6f00c6d21259d049d21ebea52de9b47663 (patch)
tree4f5130957bf055d7371a5d6621063e6616cc340d /base/file_util_unittest.cc
parente6f84f1438b160aab349b417bbd9eea34bd3568e (diff)
downloadchromium_src-806b9c6f00c6d21259d049d21ebea52de9b47663.zip
chromium_src-806b9c6f00c6d21259d049d21ebea52de9b47663.tar.gz
chromium_src-806b9c6f00c6d21259d049d21ebea52de9b47663.tar.bz2
CreateDirectory() should check if an existing path is actually a directory before skipping it. Also update a couple instances and comments to reflect current behaviour (see also http://codereview.chromium.org/1681).
Review URL: http://codereview.chromium.org/1709 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@2060 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/file_util_unittest.cc')
-rw-r--r--base/file_util_unittest.cc55
1 files changed, 43 insertions, 12 deletions
diff --git a/base/file_util_unittest.cc b/base/file_util_unittest.cc
index a93eda3..142967e 100644
--- a/base/file_util_unittest.cc
+++ b/base/file_util_unittest.cc
@@ -517,7 +517,7 @@ TEST_F(FileUtilTest, CopyFile) {
std::wstring dest_file(dir_name_from);
file_util::AppendToPath(&dest_file, L"DestFile.txt");
ASSERT_TRUE(file_util::CopyFile(file_name_from, dest_file));
-
+
// Copy the file to another location using '..' in the path.
std::wstring dest_file2(dir_name_from);
file_util::AppendToPath(&dest_file2, L"..");
@@ -697,15 +697,15 @@ TEST_F(FileUtilTest, CreateShortcutTest) {
TEST_F(FileUtilTest, CreateTemporaryFileNameTest) {
std::wstring temp_file;
file_util::CreateTemporaryFileName(&temp_file);
- EXPECT_EQ(file_util::PathExists(temp_file), true);
- EXPECT_EQ(file_util::Delete(temp_file, false), true);
+ EXPECT_TRUE(file_util::PathExists(temp_file));
+ EXPECT_TRUE(file_util::Delete(temp_file, false));
}
TEST_F(FileUtilTest, CreateNewTempDirectoryTest) {
std::wstring temp_dir;
file_util::CreateNewTempDirectory(std::wstring(), &temp_dir);
- EXPECT_EQ(file_util::PathExists(temp_dir), true);
- EXPECT_EQ(file_util::Delete(temp_dir, false), true);
+ EXPECT_TRUE(file_util::PathExists(temp_dir));
+ EXPECT_TRUE(file_util::Delete(temp_dir, false));
}
TEST_F(FileUtilTest, CreateDirectoryTest) {
@@ -717,13 +717,44 @@ TEST_F(FileUtilTest, CreateDirectoryTest) {
#elif defined(OS_POSIX)
file_util::AppendToPath(&test_path, L"dir/tree/likely/doesnt/exist/");
#endif
-
- EXPECT_EQ(file_util::PathExists(test_path), false);
- EXPECT_EQ(file_util::CreateDirectory(test_path), true);
- EXPECT_EQ(file_util::PathExists(test_path), true);
- EXPECT_EQ(file_util::Delete(test_root, true), true);
- EXPECT_EQ(file_util::PathExists(test_root), false);
- EXPECT_EQ(file_util::PathExists(test_path), false);
+
+ EXPECT_FALSE(file_util::PathExists(test_path));
+ EXPECT_TRUE(file_util::CreateDirectory(test_path));
+ EXPECT_TRUE(file_util::PathExists(test_path));
+ // CreateDirectory returns true if the DirectoryExists returns true.
+ EXPECT_TRUE(file_util::CreateDirectory(test_path));
+
+ // Doesn't work to create it on top of a non-dir
+ file_util::AppendToPath(&test_path, L"foobar.txt");
+ EXPECT_FALSE(file_util::PathExists(test_path));
+ CreateTextFile(test_path, L"test file");
+ EXPECT_TRUE(file_util::PathExists(test_path));
+ EXPECT_FALSE(file_util::CreateDirectory(test_path));
+
+ EXPECT_TRUE(file_util::Delete(test_root, true));
+ EXPECT_FALSE(file_util::PathExists(test_root));
+ EXPECT_FALSE(file_util::PathExists(test_path));
+}
+
+TEST_F(FileUtilTest, DetectDirectoryTest) {
+ // Check a directory
+ std::wstring test_root = test_dir_;
+ file_util::AppendToPath(&test_root, L"detect_directory_test");
+ EXPECT_FALSE(file_util::PathExists(test_root));
+ EXPECT_TRUE(file_util::CreateDirectory(test_root));
+ EXPECT_TRUE(file_util::PathExists(test_root));
+ EXPECT_TRUE(file_util::DirectoryExists(test_root));
+
+ // Check a file
+ std::wstring test_path(test_root);
+ file_util::AppendToPath(&test_path, L"foobar.txt");
+ EXPECT_FALSE(file_util::PathExists(test_path));
+ CreateTextFile(test_path, L"test file");
+ EXPECT_TRUE(file_util::PathExists(test_path));
+ EXPECT_FALSE(file_util::DirectoryExists(test_path));
+ EXPECT_TRUE(file_util::Delete(test_path, false));
+
+ EXPECT_TRUE(file_util::Delete(test_root, true));
}
static const struct goodbad_pair {