Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(298)

Side by Side Diff: base/file_util_unittest.cc

Issue 73083: Submitting http://codereview.chromium.org/73075 on behalf of shinichiro.hamaj... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 11 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/file_util.h ('k') | base/file_util_win.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "build/build_config.h" 5 #include "build/build_config.h"
6 6
7 #if defined(OS_WIN) 7 #if defined(OS_WIN)
8 #include <windows.h> 8 #include <windows.h>
9 #include <shellapi.h> 9 #include <shellapi.h>
10 #include <shlobj.h> 10 #include <shlobj.h>
11 #endif 11 #endif
12 12
13 #include <fstream> 13 #include <fstream>
14 #include <iostream> 14 #include <iostream>
15 #include <set> 15 #include <set>
16 16
17 #include "base/base_paths.h" 17 #include "base/base_paths.h"
18 #include "base/file_path.h" 18 #include "base/file_path.h"
19 #include "base/file_util.h" 19 #include "base/file_util.h"
20 #include "base/logging.h" 20 #include "base/logging.h"
21 #include "base/path_service.h" 21 #include "base/path_service.h"
22 #include "base/string_util.h" 22 #include "base/string_util.h"
23 #include "base/time.h"
23 #include "testing/gtest/include/gtest/gtest.h" 24 #include "testing/gtest/include/gtest/gtest.h"
24 #include "testing/platform_test.h" 25 #include "testing/platform_test.h"
25 26
26 // This macro helps avoid wrapped lines in the test structs. 27 // This macro helps avoid wrapped lines in the test structs.
27 #define FPL(x) FILE_PATH_LITERAL(x) 28 #define FPL(x) FILE_PATH_LITERAL(x)
28 29
29 namespace { 30 namespace {
30 31
31 // file_util winds up using autoreleased objects on the Mac, so this needs 32 // file_util winds up using autoreleased objects on the Mac, so this needs
32 // to be a PlatformTest 33 // to be a PlatformTest
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 const std::wstring parent = 310 const std::wstring parent =
310 file_util::GetDirectoryFromPath(dir.full_path); 311 file_util::GetDirectoryFromPath(dir.full_path);
311 EXPECT_EQ(dir.directory, parent); 312 EXPECT_EQ(dir.directory, parent);
312 } 313 }
313 } 314 }
314 315
315 // TODO(erikkay): implement 316 // TODO(erikkay): implement
316 #if defined OS_WIN 317 #if defined OS_WIN
317 TEST_F(FileUtilTest, CountFilesCreatedAfter) { 318 TEST_F(FileUtilTest, CountFilesCreatedAfter) {
318 // Create old file (that we don't want to count) 319 // Create old file (that we don't want to count)
319 FilePath old_file_name = test_dir_.Append(L"Old File.txt"); 320 FilePath old_file_name = test_dir_.Append(FILE_PATH_LITERAL("Old File.txt"));
320 CreateTextFile(old_file_name, L"Just call me Mr. Creakybits"); 321 CreateTextFile(old_file_name, L"Just call me Mr. Creakybits");
321 322
322 // Age to perfection 323 // Age to perfection
323 Sleep(100); 324 Sleep(100);
324 325
325 // Establish our cutoff time 326 // Establish our cutoff time
326 FILETIME test_start_time; 327 base::Time now(base::Time::Now());
327 GetSystemTimeAsFileTime(&test_start_time); 328 EXPECT_EQ(0, file_util::CountFilesCreatedAfter(test_dir_, now));
328 EXPECT_EQ(0, file_util::CountFilesCreatedAfter(test_dir_.value(),
329 test_start_time));
330 329
331 // Create a new file (that we do want to count) 330 // Create a new file (that we do want to count)
332 FilePath new_file_name = test_dir_.Append(L"New File.txt"); 331 FilePath new_file_name = test_dir_.Append(FILE_PATH_LITERAL("New File.txt"));
333 CreateTextFile(new_file_name, L"Waaaaaaaaaaaaaah."); 332 CreateTextFile(new_file_name, L"Waaaaaaaaaaaaaah.");
334 333
335 // We should see only the new file. 334 // We should see only the new file.
336 EXPECT_EQ(1, file_util::CountFilesCreatedAfter(test_dir_.value(), 335 EXPECT_EQ(1, file_util::CountFilesCreatedAfter(test_dir_, now));
337 test_start_time));
338 336
339 // Delete new file, we should see no files after cutoff now 337 // Delete new file, we should see no files after cutoff now
340 EXPECT_TRUE(file_util::Delete(new_file_name, false)); 338 EXPECT_TRUE(file_util::Delete(new_file_name, false));
341 EXPECT_EQ(0, file_util::CountFilesCreatedAfter(test_dir_.value(), 339 EXPECT_EQ(0, file_util::CountFilesCreatedAfter(test_dir_, now));
342 test_start_time));
343 } 340 }
344 #endif 341 #endif
345 342
346 // Tests that the Delete function works as expected, especially 343 // Tests that the Delete function works as expected, especially
347 // the recursion flag. Also coincidentally tests PathExists. 344 // the recursion flag. Also coincidentally tests PathExists.
348 TEST_F(FileUtilTest, Delete) { 345 TEST_F(FileUtilTest, Delete) {
349 // Create a file 346 // Create a file
350 FilePath file_name = test_dir_.Append(FILE_PATH_LITERAL("Test File.txt")); 347 FilePath file_name = test_dir_.Append(FILE_PATH_LITERAL("Test File.txt"));
351 CreateTextFile(file_name, L"I'm cannon fodder."); 348 CreateTextFile(file_name, L"I'm cannon fodder.");
352 349
(...skipping 733 matching lines...) Expand 10 before | Expand all | Expand 10 after
1086 #elif defined(OS_LINUX) 1083 #elif defined(OS_LINUX)
1087 EXPECT_FALSE(file_util::ContainsPath(foo, 1084 EXPECT_FALSE(file_util::ContainsPath(foo,
1088 foo_caps.Append(FILE_PATH_LITERAL("bar.txt")))); 1085 foo_caps.Append(FILE_PATH_LITERAL("bar.txt"))));
1089 #else 1086 #else
1090 // We can't really do this test on osx since the case-sensitivity of the 1087 // We can't really do this test on osx since the case-sensitivity of the
1091 // filesystem is configurable. 1088 // filesystem is configurable.
1092 #endif 1089 #endif
1093 } 1090 }
1094 1091
1095 } // namespace 1092 } // namespace
OLDNEW
« no previous file with comments | « base/file_util.h ('k') | base/file_util_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698