OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "chrome/test/sync/engine/test_directory_setter_upper.h" | 5 #include "chrome/test/sync/engine/test_directory_setter_upper.h" |
6 | 6 |
| 7 #include "base/file_util.h" |
7 #include "base/string_util.h" | 8 #include "base/string_util.h" |
8 #include "chrome/browser/sync/syncable/directory_manager.h" | 9 #include "chrome/browser/sync/syncable/directory_manager.h" |
9 #include "chrome/browser/sync/syncable/syncable.h" | 10 #include "chrome/browser/sync/syncable/syncable.h" |
10 #include "chrome/browser/sync/util/character_set_converters.h" | |
11 #include "chrome/browser/sync/util/compat_file.h" | |
12 #include "chrome/browser/sync/util/event_sys-inl.h" | 11 #include "chrome/browser/sync/util/event_sys-inl.h" |
13 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
14 | 13 |
15 using syncable::DirectoryManager; | 14 using syncable::DirectoryManager; |
16 using syncable::ReadTransaction; | 15 using syncable::ReadTransaction; |
17 using syncable::ScopedDirLookup; | 16 using syncable::ScopedDirLookup; |
18 | 17 |
19 namespace browser_sync { | 18 namespace browser_sync { |
20 | 19 |
21 TestDirectorySetterUpper::TestDirectorySetterUpper() : name_(PSTR("Test")) {} | 20 TestDirectorySetterUpper::TestDirectorySetterUpper() : name_(PSTR("Test")) {} |
22 TestDirectorySetterUpper::TestDirectorySetterUpper(const PathString& name) | 21 TestDirectorySetterUpper::TestDirectorySetterUpper(const PathString& name) |
23 : name_(name) {} | 22 : name_(name) {} |
24 | 23 |
25 TestDirectorySetterUpper::~TestDirectorySetterUpper() {} | 24 TestDirectorySetterUpper::~TestDirectorySetterUpper() {} |
26 | 25 |
27 void TestDirectorySetterUpper::Init() { | 26 void TestDirectorySetterUpper::Init() { |
28 PathString test_data_dir_ = PSTR("."); | 27 FilePath test_data_dir_(FILE_PATH_LITERAL(".")); |
29 manager_.reset(new DirectoryManager(test_data_dir_)); | 28 manager_.reset(new DirectoryManager(test_data_dir_)); |
30 file_path_ = manager_->GetSyncDataDatabasePath(); | 29 file_path_ = manager_->GetSyncDataDatabasePath(); |
31 PathRemove(file_path_.c_str()); | 30 file_util::Delete(file_path_, false); |
32 } | 31 } |
33 | 32 |
34 void TestDirectorySetterUpper::SetUp() { | 33 void TestDirectorySetterUpper::SetUp() { |
35 Init(); | 34 Init(); |
36 ASSERT_TRUE(manager()->Open(name())); | 35 ASSERT_TRUE(manager()->Open(name())); |
37 } | 36 } |
38 | 37 |
39 void TestDirectorySetterUpper::TearDown() { | 38 void TestDirectorySetterUpper::TearDown() { |
40 if (!manager()) | 39 if (!manager()) |
41 return; | 40 return; |
42 | 41 |
43 { | 42 { |
44 // A small scope so we don't have the dir open when we close it and reset | 43 // A small scope so we don't have the dir open when we close it and reset |
45 // the DirectoryManager below. | 44 // the DirectoryManager below. |
46 ScopedDirLookup dir(manager(), name()); | 45 ScopedDirLookup dir(manager(), name()); |
47 CHECK(dir.good()) << "Bad directory during tear down check"; | 46 CHECK(dir.good()) << "Bad directory during tear down check"; |
48 RunInvariantCheck(dir); | 47 RunInvariantCheck(dir); |
49 dir->SaveChanges(); | 48 dir->SaveChanges(); |
50 RunInvariantCheck(dir); | 49 RunInvariantCheck(dir); |
51 dir->SaveChanges(); | 50 dir->SaveChanges(); |
52 } | 51 } |
53 | 52 |
54 manager()->FinalSaveChangesForAll(); | 53 manager()->FinalSaveChangesForAll(); |
55 manager()->Close(name()); | 54 manager()->Close(name()); |
56 manager_.reset(); | 55 manager_.reset(); |
57 EXPECT_EQ(0, PathRemove(file_path_.c_str())); | 56 EXPECT_TRUE(file_util::Delete(file_path_, false)); |
58 file_path_.clear(); | 57 file_path_ = FilePath(FILE_PATH_LITERAL("")); |
59 } | 58 } |
60 | 59 |
61 void TestDirectorySetterUpper::RunInvariantCheck(const ScopedDirLookup& dir) { | 60 void TestDirectorySetterUpper::RunInvariantCheck(const ScopedDirLookup& dir) { |
62 { | 61 { |
63 // Check invariants for in-memory items. | 62 // Check invariants for in-memory items. |
64 ReadTransaction trans(dir, __FILE__, __LINE__); | 63 ReadTransaction trans(dir, __FILE__, __LINE__); |
65 dir->CheckTreeInvariants(&trans, false); | 64 dir->CheckTreeInvariants(&trans, false); |
66 } | 65 } |
67 { | 66 { |
68 // Check invariants for all items. | 67 // Check invariants for all items. |
(...skipping 12 matching lines...) Expand all Loading... |
81 } | 80 } |
82 | 81 |
83 void ManuallyOpenedTestDirectorySetterUpper::TearDown() { | 82 void ManuallyOpenedTestDirectorySetterUpper::TearDown() { |
84 if (was_opened_) { | 83 if (was_opened_) { |
85 TestDirectorySetterUpper::TearDown(); | 84 TestDirectorySetterUpper::TearDown(); |
86 } | 85 } |
87 } | 86 } |
88 | 87 |
89 TriggeredOpenTestDirectorySetterUpper::TriggeredOpenTestDirectorySetterUpper( | 88 TriggeredOpenTestDirectorySetterUpper::TriggeredOpenTestDirectorySetterUpper( |
90 const std::string& name) | 89 const std::string& name) |
91 : TestDirectorySetterUpper(UTF8ToPathStringQuick(name)) { | 90 : TestDirectorySetterUpper(name) { |
92 } | 91 } |
93 | 92 |
94 void TriggeredOpenTestDirectorySetterUpper::SetUp() { | 93 void TriggeredOpenTestDirectorySetterUpper::SetUp() { |
95 Init(); | 94 Init(); |
96 } | 95 } |
97 | 96 |
98 void TriggeredOpenTestDirectorySetterUpper::TearDown() { | 97 void TriggeredOpenTestDirectorySetterUpper::TearDown() { |
99 DirectoryManager::DirNames names; | 98 DirectoryManager::DirNames names; |
100 manager()->GetOpenDirectories(&names); | 99 manager()->GetOpenDirectories(&names); |
101 if (!names.empty()) { | 100 if (!names.empty()) { |
102 ASSERT_EQ(1U, names.size()); | 101 ASSERT_EQ(1U, names.size()); |
103 ASSERT_EQ(name(), names[0]); | 102 ASSERT_EQ(name(), names[0]); |
104 TestDirectorySetterUpper::TearDown(); | 103 TestDirectorySetterUpper::TearDown(); |
105 } | 104 } |
106 } | 105 } |
107 | 106 |
108 } // namespace browser_sync | 107 } // namespace browser_sync |
OLD | NEW |