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

Side by Side Diff: base/file_util_unittest.cc

Issue 73084: Reverting 13748. (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"
24 #include "testing/gtest/include/gtest/gtest.h" 23 #include "testing/gtest/include/gtest/gtest.h"
25 #include "testing/platform_test.h" 24 #include "testing/platform_test.h"
26 25
27 // This macro helps avoid wrapped lines in the test structs. 26 // This macro helps avoid wrapped lines in the test structs.
28 #define FPL(x) FILE_PATH_LITERAL(x) 27 #define FPL(x) FILE_PATH_LITERAL(x)
29 28
30 namespace { 29 namespace {
31 30
32 // file_util winds up using autoreleased objects on the Mac, so this needs 31 // file_util winds up using autoreleased objects on the Mac, so this needs
33 // to be a PlatformTest 32 // to be a PlatformTest
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 const std::wstring parent = 309 const std::wstring parent =
311 file_util::GetDirectoryFromPath(dir.full_path); 310 file_util::GetDirectoryFromPath(dir.full_path);
312 EXPECT_EQ(dir.directory, parent); 311 EXPECT_EQ(dir.directory, parent);
313 } 312 }
314 } 313 }
315 314
316 // TODO(erikkay): implement 315 // TODO(erikkay): implement
317 #if defined OS_WIN 316 #if defined OS_WIN
318 TEST_F(FileUtilTest, CountFilesCreatedAfter) { 317 TEST_F(FileUtilTest, CountFilesCreatedAfter) {
319 // Create old file (that we don't want to count) 318 // Create old file (that we don't want to count)
320 FilePath old_file_name = test_dir_.Append(FILE_PATH_LITERAL("Old File.txt")); 319 FilePath old_file_name = test_dir_.Append(L"Old File.txt");
321 CreateTextFile(old_file_name, L"Just call me Mr. Creakybits"); 320 CreateTextFile(old_file_name, L"Just call me Mr. Creakybits");
322 321
323 // Age to perfection 322 // Age to perfection
324 Sleep(100); 323 Sleep(100);
325 324
326 // Establish our cutoff time 325 // Establish our cutoff time
327 base::Time now(base::Time::Now()); 326 FILETIME test_start_time;
328 EXPECT_EQ(0, file_util::CountFilesCreatedAfter(test_dir_, now)); 327 GetSystemTimeAsFileTime(&test_start_time);
328 EXPECT_EQ(0, file_util::CountFilesCreatedAfter(test_dir_.value(),
329 test_start_time));
329 330
330 // Create a new file (that we do want to count) 331 // Create a new file (that we do want to count)
331 FilePath new_file_name = test_dir_.Append(FILE_PATH_LITERAL("New File.txt")); 332 FilePath new_file_name = test_dir_.Append(L"New File.txt");
332 CreateTextFile(new_file_name, L"Waaaaaaaaaaaaaah."); 333 CreateTextFile(new_file_name, L"Waaaaaaaaaaaaaah.");
333 334
334 // We should see only the new file. 335 // We should see only the new file.
335 EXPECT_EQ(1, file_util::CountFilesCreatedAfter(test_dir_, now)); 336 EXPECT_EQ(1, file_util::CountFilesCreatedAfter(test_dir_.value(),
337 test_start_time));
336 338
337 // Delete new file, we should see no files after cutoff now 339 // Delete new file, we should see no files after cutoff now
338 EXPECT_TRUE(file_util::Delete(new_file_name, false)); 340 EXPECT_TRUE(file_util::Delete(new_file_name, false));
339 EXPECT_EQ(0, file_util::CountFilesCreatedAfter(test_dir_, now)); 341 EXPECT_EQ(0, file_util::CountFilesCreatedAfter(test_dir_.value(),
342 test_start_time));
340 } 343 }
341 #endif 344 #endif
342 345
343 // Tests that the Delete function works as expected, especially 346 // Tests that the Delete function works as expected, especially
344 // the recursion flag. Also coincidentally tests PathExists. 347 // the recursion flag. Also coincidentally tests PathExists.
345 TEST_F(FileUtilTest, Delete) { 348 TEST_F(FileUtilTest, Delete) {
346 // Create a file 349 // Create a file
347 FilePath file_name = test_dir_.Append(FILE_PATH_LITERAL("Test File.txt")); 350 FilePath file_name = test_dir_.Append(FILE_PATH_LITERAL("Test File.txt"));
348 CreateTextFile(file_name, L"I'm cannon fodder."); 351 CreateTextFile(file_name, L"I'm cannon fodder.");
349 352
(...skipping 733 matching lines...) Expand 10 before | Expand all | Expand 10 after
1083 #elif defined(OS_LINUX) 1086 #elif defined(OS_LINUX)
1084 EXPECT_FALSE(file_util::ContainsPath(foo, 1087 EXPECT_FALSE(file_util::ContainsPath(foo,
1085 foo_caps.Append(FILE_PATH_LITERAL("bar.txt")))); 1088 foo_caps.Append(FILE_PATH_LITERAL("bar.txt"))));
1086 #else 1089 #else
1087 // We can't really do this test on osx since the case-sensitivity of the 1090 // We can't really do this test on osx since the case-sensitivity of the
1088 // filesystem is configurable. 1091 // filesystem is configurable.
1089 #endif 1092 #endif
1090 } 1093 }
1091 1094
1092 } // namespace 1095 } // 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