diff options
author | cpu@chromium.org <cpu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-24 21:56:26 +0000 |
---|---|---|
committer | cpu@chromium.org <cpu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-24 21:56:26 +0000 |
commit | c2c132c637874d6d3104293791b15b38da58bfc9 (patch) | |
tree | f054e86c5722eb229c08fe1a37181aa41020b6cf /base/file_util_unittest.cc | |
parent | a24642a800c1712eeaa791f0fb0ed1527885c6fb (diff) | |
download | chromium_src-c2c132c637874d6d3104293791b15b38da58bfc9.zip chromium_src-c2c132c637874d6d3104293791b15b38da58bfc9.tar.gz chromium_src-c2c132c637874d6d3104293791b15b38da58bfc9.tar.bz2 |
Function to compute the total size of the files in a directory
We need this for the diagnostic mode but it can be used by others.
Did not see test for GetFileSize() so added them
BUG=none
TEST=ut included
Review URL: http://codereview.chromium.org/1220001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@42540 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/file_util_unittest.cc')
-rw-r--r-- | base/file_util_unittest.cc | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/base/file_util_unittest.cc b/base/file_util_unittest.cc index fa92737..c46c39f 100644 --- a/base/file_util_unittest.cc +++ b/base/file_util_unittest.cc @@ -357,6 +357,34 @@ TEST_F(FileUtilTest, CountFilesCreatedAfter) { EXPECT_EQ(0, file_util::CountFilesCreatedAfter(test_dir_, now)); } +TEST_F(FileUtilTest, FileAndDirectorySize) { + // Create three files of 20, 30 and 3 chars (utf8). ComputeDirectorySize + // should return 53 bytes. + FilePath file_01 = test_dir_.Append(FPL("The file 01.txt")); + CreateTextFile(file_01, L"12345678901234567890"); + int64 size_f1 = 0; + ASSERT_TRUE(file_util::GetFileSize(file_01, &size_f1)); + EXPECT_EQ(20ll, size_f1); + + FilePath subdir_path = test_dir_.Append(FPL("Level2")); + file_util::CreateDirectory(subdir_path); + + FilePath file_02 = subdir_path.Append(FPL("The file 02.txt")); + CreateTextFile(file_02, L"123456789012345678901234567890"); + int64 size_f2 = 0; + ASSERT_TRUE(file_util::GetFileSize(file_02, &size_f2)); + EXPECT_EQ(30ll, size_f2); + + FilePath subsubdir_path = subdir_path.Append(FPL("Level3")); + file_util::CreateDirectory(subsubdir_path); + + FilePath file_03 = subsubdir_path.Append(FPL("The file 03.txt")); + CreateTextFile(file_03, L"123"); + + int64 computed_size = file_util::ComputeDirectorySize(test_dir_); + EXPECT_EQ(size_f1 + size_f2 + 3, computed_size); +} + // Tests that the Delete function works as expected, especially // the recursion flag. Also coincidentally tests PathExists. TEST_F(FileUtilTest, Delete) { |