OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/browser/chromeos/drive/drive_resource_metadata_storage.h" | 5 #include "chrome/browser/chromeos/drive/drive_resource_metadata_storage.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
11 #include "base/files/scoped_temp_dir.h" | 11 #include "base/files/scoped_temp_dir.h" |
12 #include "chrome/browser/chromeos/drive/drive.pb.h" | 12 #include "chrome/browser/chromeos/drive/drive.pb.h" |
13 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 14 #include "third_party/leveldatabase/src/include/leveldb/db.h" |
14 | 15 |
15 namespace drive { | 16 namespace drive { |
16 | 17 |
17 namespace { | 18 namespace { |
18 | 19 |
19 // Stores the entry to the map. | 20 // Stores the entry to the map. |
20 void StoreEntryToMap(std::map<std::string,DriveEntryProto>* out, | 21 void StoreEntryToMap(std::map<std::string,DriveEntryProto>* out, |
21 const DriveEntryProto& entry) { | 22 const DriveEntryProto& entry) { |
22 (*out)[entry.resource_id()] = entry; | 23 (*out)[entry.resource_id()] = entry; |
23 } | 24 } |
(...skipping 17 matching lines...) Expand all Loading... |
41 scoped_ptr<DriveResourceMetadataHeader> header = storage_->GetHeader(); | 42 scoped_ptr<DriveResourceMetadataHeader> header = storage_->GetHeader(); |
42 ASSERT_TRUE(header); | 43 ASSERT_TRUE(header); |
43 header->set_version(version); | 44 header->set_version(version); |
44 storage_->PutHeader(*header); | 45 storage_->PutHeader(*header); |
45 } | 46 } |
46 | 47 |
47 bool CheckValidity() { | 48 bool CheckValidity() { |
48 return storage_->CheckValidity(); | 49 return storage_->CheckValidity(); |
49 } | 50 } |
50 | 51 |
| 52 // Puts a child entry. |
| 53 void PutChild(const std::string& parent_resource_id, |
| 54 const std::string& child_base_name, |
| 55 const std::string& child_resource_id) { |
| 56 storage_->resource_map_->Put( |
| 57 leveldb::WriteOptions(), |
| 58 DriveResourceMetadataStorage::GetChildEntryKey(parent_resource_id, |
| 59 child_base_name), |
| 60 child_resource_id); |
| 61 } |
| 62 |
| 63 // Removes a child entry. |
| 64 void RemoveChild(const std::string& parent_resource_id, |
| 65 const std::string& child_base_name) { |
| 66 storage_->resource_map_->Delete( |
| 67 leveldb::WriteOptions(), |
| 68 DriveResourceMetadataStorage::GetChildEntryKey(parent_resource_id, |
| 69 child_base_name)); |
| 70 } |
| 71 |
51 base::ScopedTempDir temp_dir_; | 72 base::ScopedTempDir temp_dir_; |
52 scoped_ptr<DriveResourceMetadataStorage> storage_; | 73 scoped_ptr<DriveResourceMetadataStorage> storage_; |
53 }; | 74 }; |
54 | 75 |
55 TEST_F(DriveResourceMetadataStorageTest, LargestChangestamp) { | 76 TEST_F(DriveResourceMetadataStorageTest, LargestChangestamp) { |
56 const int64 kLargestChangestamp = 1234567890; | 77 const int64 kLargestChangestamp = 1234567890; |
57 storage_->SetLargestChangestamp(kLargestChangestamp); | 78 storage_->SetLargestChangestamp(kLargestChangestamp); |
58 EXPECT_EQ(kLargestChangestamp, storage_->GetLargestChangestamp()); | 79 EXPECT_EQ(kLargestChangestamp, storage_->GetLargestChangestamp()); |
59 } | 80 } |
60 | 81 |
61 TEST_F(DriveResourceMetadataStorageTest, PutEntry) { | 82 TEST_F(DriveResourceMetadataStorageTest, PutEntry) { |
62 const std::string key1 = "abcdefg"; | 83 const std::string key1 = "abcdefg"; |
63 const std::string key2 = "abcd"; | 84 const std::string key2 = "abcd"; |
| 85 const std::string key3 = "efgh"; |
| 86 const std::string name2 = "ABCD"; |
| 87 const std::string name3 = "EFGH"; |
64 | 88 |
65 DriveEntryProto entry1; | 89 DriveEntryProto entry1; |
66 entry1.set_resource_id(key1); | 90 entry1.set_resource_id(key1); |
67 | 91 |
68 // key1 not found. | 92 // key1 not found. |
69 EXPECT_FALSE(storage_->GetEntry(key1)); | 93 EXPECT_FALSE(storage_->GetEntry(key1)); |
70 | 94 |
71 // Put entry1. | 95 // Put entry1. |
72 storage_->PutEntry(entry1); | 96 EXPECT_TRUE(storage_->PutEntry(entry1)); |
73 | 97 |
74 // key1 found. | 98 // key1 found. |
75 scoped_ptr<DriveEntryProto> result; | 99 scoped_ptr<DriveEntryProto> result; |
76 result = storage_->GetEntry(key1); | 100 result = storage_->GetEntry(key1); |
77 ASSERT_TRUE(result); | 101 ASSERT_TRUE(result); |
78 EXPECT_EQ(key1, result->resource_id()); | 102 EXPECT_EQ(key1, result->resource_id()); |
79 | 103 |
80 // key2 not found. | 104 // key2 not found. |
81 EXPECT_FALSE(storage_->GetEntry(key2)); | 105 EXPECT_FALSE(storage_->GetEntry(key2)); |
82 | 106 |
83 // Remove key1. | 107 // Put entry2 as a child of entry1. |
84 storage_->RemoveEntry(key1); | 108 DriveEntryProto entry2; |
| 109 entry2.set_parent_resource_id(key1); |
| 110 entry2.set_resource_id(key2); |
| 111 entry2.set_base_name(name2); |
| 112 EXPECT_TRUE(storage_->PutEntry(entry2)); |
| 113 |
| 114 // key2 found. |
| 115 EXPECT_TRUE(storage_->GetEntry(key2)); |
| 116 EXPECT_EQ(key2, storage_->GetChild(key1, name2)); |
| 117 |
| 118 // Put entry3 as a child of entry2. |
| 119 DriveEntryProto entry3; |
| 120 entry3.set_parent_resource_id(key2); |
| 121 entry3.set_resource_id(key3); |
| 122 entry3.set_base_name(name3); |
| 123 EXPECT_TRUE(storage_->PutEntry(entry3)); |
| 124 |
| 125 // key3 found. |
| 126 EXPECT_TRUE(storage_->GetEntry(key3)); |
| 127 EXPECT_EQ(key3, storage_->GetChild(key2, name3)); |
| 128 |
| 129 // Change entry3's parent to entry1. |
| 130 entry3.set_parent_resource_id(key1); |
| 131 EXPECT_TRUE(storage_->PutEntry(entry3)); |
| 132 |
| 133 // entry3 is a child of entry1 now. |
| 134 EXPECT_TRUE(storage_->GetChild(key2, name3).empty()); |
| 135 EXPECT_EQ(key3, storage_->GetChild(key1, name3)); |
| 136 |
| 137 // Remove entries. |
| 138 EXPECT_TRUE(storage_->RemoveEntry(key3)); |
| 139 EXPECT_FALSE(storage_->GetEntry(key3)); |
| 140 EXPECT_TRUE(storage_->RemoveEntry(key2)); |
| 141 EXPECT_FALSE(storage_->GetEntry(key2)); |
| 142 EXPECT_TRUE(storage_->RemoveEntry(key1)); |
85 EXPECT_FALSE(storage_->GetEntry(key1)); | 143 EXPECT_FALSE(storage_->GetEntry(key1)); |
86 } | 144 } |
87 | 145 |
88 TEST_F(DriveResourceMetadataStorageTest, Iterate) { | 146 TEST_F(DriveResourceMetadataStorageTest, Iterate) { |
89 // Prepare data. | 147 // Prepare data. |
90 std::vector<DriveEntryProto> entries; | 148 std::vector<DriveEntryProto> entries; |
91 DriveEntryProto entry; | 149 DriveEntryProto entry; |
92 | 150 |
93 entry.set_resource_id("entry1"); | 151 entry.set_resource_id("entry1"); |
94 entries.push_back(entry); | 152 entries.push_back(entry); |
95 entry.set_resource_id("entry2"); | 153 entry.set_resource_id("entry2"); |
96 entries.push_back(entry); | 154 entries.push_back(entry); |
97 entry.set_resource_id("entry3"); | 155 entry.set_resource_id("entry3"); |
98 entries.push_back(entry); | 156 entries.push_back(entry); |
99 entry.set_resource_id("entry4"); | 157 entry.set_resource_id("entry4"); |
100 entries.push_back(entry); | 158 entries.push_back(entry); |
101 | 159 |
102 for (size_t i = 0; i < entries.size(); ++i) | 160 for (size_t i = 0; i < entries.size(); ++i) |
103 storage_->PutEntry(entries[i]); | 161 EXPECT_TRUE(storage_->PutEntry(entries[i])); |
104 | 162 |
105 // Call Iterate and check the result. | 163 // Call Iterate and check the result. |
106 std::map<std::string, DriveEntryProto> result; | 164 std::map<std::string, DriveEntryProto> result; |
107 storage_->Iterate(base::Bind(&StoreEntryToMap, base::Unretained(&result))); | 165 storage_->Iterate(base::Bind(&StoreEntryToMap, base::Unretained(&result))); |
108 | 166 |
109 EXPECT_EQ(entries.size(), result.size()); | 167 EXPECT_EQ(entries.size(), result.size()); |
110 for (size_t i = 0; i < entries.size(); ++i) | 168 for (size_t i = 0; i < entries.size(); ++i) |
111 EXPECT_EQ(1U, result.count(entries[i].resource_id())); | 169 EXPECT_EQ(1U, result.count(entries[i].resource_id())); |
112 } | 170 } |
113 | 171 |
114 TEST_F(DriveResourceMetadataStorageTest, PutChild) { | |
115 const std::string parent_id1 = "abcdefg"; | |
116 const std::string parent_id2 = "abcd"; | |
117 const std::string child_name1 = "WXYZABC"; | |
118 const std::string child_name2 = "efgWXYZABC"; | |
119 const std::string child_id1 = "qwerty"; | |
120 const std::string child_id2 = "asdfgh"; | |
121 | |
122 // No child found. | |
123 EXPECT_TRUE(storage_->GetChild(parent_id1, child_name1).empty()); | |
124 EXPECT_TRUE(storage_->GetChild(parent_id1, child_name2).empty()); | |
125 EXPECT_TRUE(storage_->GetChild(parent_id2, child_name1).empty()); | |
126 EXPECT_TRUE(storage_->GetChild(parent_id2, child_name2).empty()); | |
127 | |
128 // Put child1 under parent1. | |
129 storage_->PutChild(parent_id1, child_name1, child_id1); | |
130 EXPECT_EQ(child_id1, storage_->GetChild(parent_id1, child_name1)); | |
131 EXPECT_TRUE(storage_->GetChild(parent_id1, child_name2).empty()); | |
132 EXPECT_TRUE(storage_->GetChild(parent_id2, child_name1).empty()); | |
133 EXPECT_TRUE(storage_->GetChild(parent_id2, child_name2).empty()); | |
134 | |
135 // Put child2 under parent1. | |
136 storage_->PutChild(parent_id1, child_name2, child_id2); | |
137 EXPECT_EQ(child_id1, storage_->GetChild(parent_id1, child_name1)); | |
138 EXPECT_EQ(child_id2, storage_->GetChild(parent_id1, child_name2)); | |
139 EXPECT_TRUE(storage_->GetChild(parent_id2, child_name1).empty()); | |
140 EXPECT_TRUE(storage_->GetChild(parent_id2, child_name2).empty()); | |
141 | |
142 // Remove child1. | |
143 storage_->RemoveChild(parent_id1, child_name1); | |
144 EXPECT_TRUE(storage_->GetChild(parent_id1, child_name1).empty()); | |
145 EXPECT_EQ(child_id2, storage_->GetChild(parent_id1, child_name2)); | |
146 EXPECT_TRUE(storage_->GetChild(parent_id2, child_name1).empty()); | |
147 EXPECT_TRUE(storage_->GetChild(parent_id2, child_name2).empty()); | |
148 | |
149 // Remove child2. | |
150 storage_->RemoveChild(parent_id1, child_name2); | |
151 EXPECT_TRUE(storage_->GetChild(parent_id1, child_name1).empty()); | |
152 EXPECT_TRUE(storage_->GetChild(parent_id1, child_name2).empty()); | |
153 EXPECT_TRUE(storage_->GetChild(parent_id2, child_name1).empty()); | |
154 EXPECT_TRUE(storage_->GetChild(parent_id2, child_name2).empty()); | |
155 } | |
156 | |
157 TEST_F(DriveResourceMetadataStorageTest, GetChildren) { | 172 TEST_F(DriveResourceMetadataStorageTest, GetChildren) { |
158 const std::string parents_id[] = { "mercury", "venus", "mars", "jupiter", | 173 const std::string parents_id[] = { "mercury", "venus", "mars", "jupiter", |
159 "saturn" }; | 174 "saturn" }; |
160 std::vector<std::vector<std::pair<std::string, std::string> > > | 175 std::vector<std::vector<std::pair<std::string, std::string> > > |
161 children_name_id(arraysize(parents_id)); | 176 children_name_id(arraysize(parents_id)); |
162 // Skip children_name_id[0/1] here because Mercury and Venus have no moon. | 177 // Skip children_name_id[0/1] here because Mercury and Venus have no moon. |
163 children_name_id[2].push_back(std::make_pair("phobos", "mars_i")); | 178 children_name_id[2].push_back(std::make_pair("phobos", "mars_i")); |
164 children_name_id[2].push_back(std::make_pair("deimos", "mars_ii")); | 179 children_name_id[2].push_back(std::make_pair("deimos", "mars_ii")); |
165 children_name_id[3].push_back(std::make_pair("io", "jupiter_i")); | 180 children_name_id[3].push_back(std::make_pair("io", "jupiter_i")); |
166 children_name_id[3].push_back(std::make_pair("europa", "jupiter_ii")); | 181 children_name_id[3].push_back(std::make_pair("europa", "jupiter_ii")); |
167 children_name_id[3].push_back(std::make_pair("ganymede", "jupiter_iii")); | 182 children_name_id[3].push_back(std::make_pair("ganymede", "jupiter_iii")); |
168 children_name_id[3].push_back(std::make_pair("calisto", "jupiter_iv")); | 183 children_name_id[3].push_back(std::make_pair("calisto", "jupiter_iv")); |
169 children_name_id[4].push_back(std::make_pair("mimas", "saturn_i")); | 184 children_name_id[4].push_back(std::make_pair("mimas", "saturn_i")); |
170 children_name_id[4].push_back(std::make_pair("enceladus", "saturn_ii")); | 185 children_name_id[4].push_back(std::make_pair("enceladus", "saturn_ii")); |
171 children_name_id[4].push_back(std::make_pair("tethys", "saturn_iii")); | 186 children_name_id[4].push_back(std::make_pair("tethys", "saturn_iii")); |
172 children_name_id[4].push_back(std::make_pair("dione", "saturn_iv")); | 187 children_name_id[4].push_back(std::make_pair("dione", "saturn_iv")); |
173 children_name_id[4].push_back(std::make_pair("rhea", "saturn_v")); | 188 children_name_id[4].push_back(std::make_pair("rhea", "saturn_v")); |
174 children_name_id[4].push_back(std::make_pair("titan", "saturn_vi")); | 189 children_name_id[4].push_back(std::make_pair("titan", "saturn_vi")); |
175 children_name_id[4].push_back(std::make_pair("iapetus", "saturn_vii")); | 190 children_name_id[4].push_back(std::make_pair("iapetus", "saturn_vii")); |
176 | 191 |
| 192 // Put parents. |
| 193 for (size_t i = 0; i < arraysize(parents_id); ++i) { |
| 194 DriveEntryProto entry; |
| 195 entry.set_resource_id(parents_id[i]); |
| 196 EXPECT_TRUE(storage_->PutEntry(entry)); |
| 197 } |
| 198 |
177 // Put some data. | 199 // Put some data. |
178 for (size_t i = 0; i != children_name_id.size(); ++i) { | 200 for (size_t i = 0; i < children_name_id.size(); ++i) { |
179 for (size_t j = 0; j != children_name_id[i].size(); ++j) { | 201 for (size_t j = 0; j < children_name_id[i].size(); ++j) { |
180 storage_->PutChild(parents_id[i], | 202 DriveEntryProto entry; |
181 children_name_id[i][j].first, | 203 entry.set_parent_resource_id(parents_id[i]); |
182 children_name_id[i][j].second); | 204 entry.set_base_name(children_name_id[i][j].first); |
| 205 entry.set_resource_id(children_name_id[i][j].second); |
| 206 EXPECT_TRUE(storage_->PutEntry(entry)); |
183 } | 207 } |
184 } | 208 } |
185 | 209 |
186 // Try to get children. | 210 // Try to get children. |
187 for (size_t i = 0; i != children_name_id.size(); ++i) { | 211 for (size_t i = 0; i < children_name_id.size(); ++i) { |
188 std::vector<std::string> children; | 212 std::vector<std::string> children; |
189 storage_->GetChildren(parents_id[i], &children); | 213 storage_->GetChildren(parents_id[i], &children); |
190 EXPECT_EQ(children_name_id[i].size(), children.size()); | 214 EXPECT_EQ(children_name_id[i].size(), children.size()); |
191 for (size_t j = 0; j != children_name_id[i].size(); ++j) { | 215 for (size_t j = 0; j < children_name_id[i].size(); ++j) { |
192 EXPECT_EQ(1, std::count(children.begin(), | 216 EXPECT_EQ(1, std::count(children.begin(), |
193 children.end(), | 217 children.end(), |
194 children_name_id[i][j].second)); | 218 children_name_id[i][j].second)); |
195 } | 219 } |
196 } | 220 } |
197 } | 221 } |
198 | 222 |
199 TEST_F(DriveResourceMetadataStorageTest, OpenExistingDB) { | 223 TEST_F(DriveResourceMetadataStorageTest, OpenExistingDB) { |
200 const std::string parent_id1 = "abcdefg"; | 224 const std::string parent_id1 = "abcdefg"; |
201 const std::string child_name1 = "WXYZABC"; | 225 const std::string child_name1 = "WXYZABC"; |
202 const std::string child_id1 = "qwerty"; | 226 const std::string child_id1 = "qwerty"; |
203 | 227 |
204 DriveEntryProto entry1; | 228 DriveEntryProto entry1; |
205 entry1.set_resource_id(parent_id1); | 229 entry1.set_resource_id(parent_id1); |
206 DriveEntryProto entry2; | 230 DriveEntryProto entry2; |
207 entry2.set_resource_id(child_id1); | 231 entry2.set_resource_id(child_id1); |
208 entry2.set_parent_resource_id(parent_id1); | 232 entry2.set_parent_resource_id(parent_id1); |
209 entry2.set_base_name(child_name1); | 233 entry2.set_base_name(child_name1); |
210 | 234 |
211 // Put some data. | 235 // Put some data. |
212 storage_->PutEntry(entry1); | 236 EXPECT_TRUE(storage_->PutEntry(entry1)); |
213 storage_->PutEntry(entry2); | 237 EXPECT_TRUE(storage_->PutEntry(entry2)); |
214 storage_->PutChild(parent_id1, child_name1, child_id1); | |
215 | 238 |
216 // Close DB and reopen. | 239 // Close DB and reopen. |
217 storage_.reset(new DriveResourceMetadataStorage(temp_dir_.path())); | 240 storage_.reset(new DriveResourceMetadataStorage(temp_dir_.path())); |
218 ASSERT_TRUE(storage_->Initialize()); | 241 ASSERT_TRUE(storage_->Initialize()); |
219 | 242 |
220 // Can read data. | 243 // Can read data. |
221 scoped_ptr<DriveEntryProto> result; | 244 scoped_ptr<DriveEntryProto> result; |
222 result = storage_->GetEntry(parent_id1); | 245 result = storage_->GetEntry(parent_id1); |
223 ASSERT_TRUE(result); | 246 ASSERT_TRUE(result); |
224 EXPECT_EQ(parent_id1, result->resource_id()); | 247 EXPECT_EQ(parent_id1, result->resource_id()); |
225 | 248 |
226 result = storage_->GetEntry(child_id1); | 249 result = storage_->GetEntry(child_id1); |
227 ASSERT_TRUE(result); | 250 ASSERT_TRUE(result); |
228 EXPECT_EQ(child_id1, result->resource_id()); | 251 EXPECT_EQ(child_id1, result->resource_id()); |
229 EXPECT_EQ(parent_id1, result->parent_resource_id()); | 252 EXPECT_EQ(parent_id1, result->parent_resource_id()); |
230 EXPECT_EQ(child_name1, result->base_name()); | 253 EXPECT_EQ(child_name1, result->base_name()); |
231 | 254 |
232 EXPECT_EQ(child_id1, storage_->GetChild(parent_id1, child_name1)); | 255 EXPECT_EQ(child_id1, storage_->GetChild(parent_id1, child_name1)); |
233 } | 256 } |
234 | 257 |
235 TEST_F(DriveResourceMetadataStorageTest, IncompatibleDB) { | 258 TEST_F(DriveResourceMetadataStorageTest, IncompatibleDB) { |
236 const int64 kLargestChangestamp = 1234567890; | 259 const int64 kLargestChangestamp = 1234567890; |
237 const std::string key1 = "abcd"; | 260 const std::string key1 = "abcd"; |
238 | 261 |
239 DriveEntryProto entry; | 262 DriveEntryProto entry; |
240 entry.set_resource_id(key1); | 263 entry.set_resource_id(key1); |
241 | 264 |
242 // Put some data. | 265 // Put some data. |
243 storage_->SetLargestChangestamp(kLargestChangestamp); | 266 storage_->SetLargestChangestamp(kLargestChangestamp); |
244 storage_->PutEntry(entry); | 267 EXPECT_TRUE(storage_->PutEntry(entry)); |
245 EXPECT_TRUE(storage_->GetEntry(key1)); | 268 EXPECT_TRUE(storage_->GetEntry(key1)); |
246 | 269 |
247 // Set incompatible version and reopen DB. | 270 // Set incompatible version and reopen DB. |
248 SetDBVersion(DriveResourceMetadataStorage::kDBVersion - 1); | 271 SetDBVersion(DriveResourceMetadataStorage::kDBVersion - 1); |
249 storage_.reset(new DriveResourceMetadataStorage(temp_dir_.path())); | 272 storage_.reset(new DriveResourceMetadataStorage(temp_dir_.path())); |
250 ASSERT_TRUE(storage_->Initialize()); | 273 ASSERT_TRUE(storage_->Initialize()); |
251 | 274 |
252 // Data is erased because of the incompatible version. | 275 // Data is erased because of the incompatible version. |
253 EXPECT_EQ(0, storage_->GetLargestChangestamp()); | 276 EXPECT_EQ(0, storage_->GetLargestChangestamp()); |
254 EXPECT_FALSE(storage_->GetEntry(key1)); | 277 EXPECT_FALSE(storage_->GetEntry(key1)); |
(...skipping 17 matching lines...) Expand all Loading... |
272 const std::string key3 = "boo"; | 295 const std::string key3 = "boo"; |
273 const std::string name3 = "piyo"; | 296 const std::string name3 = "piyo"; |
274 | 297 |
275 // Empty storage is valid. | 298 // Empty storage is valid. |
276 EXPECT_TRUE(CheckValidity()); | 299 EXPECT_TRUE(CheckValidity()); |
277 | 300 |
278 // Put entry with key1. | 301 // Put entry with key1. |
279 DriveEntryProto entry; | 302 DriveEntryProto entry; |
280 entry.set_resource_id(key1); | 303 entry.set_resource_id(key1); |
281 entry.set_base_name(name1); | 304 entry.set_base_name(name1); |
282 storage_->PutEntry(entry); | 305 EXPECT_TRUE(storage_->PutEntry(entry)); |
283 EXPECT_TRUE(CheckValidity()); | 306 EXPECT_TRUE(CheckValidity()); |
284 | 307 |
285 // Put entry with key2 under key1. | 308 // Put entry with key2 under key1. |
286 entry.set_resource_id(key2); | 309 entry.set_resource_id(key2); |
287 entry.set_parent_resource_id(key1); | 310 entry.set_parent_resource_id(key1); |
288 entry.set_base_name(name2); | 311 entry.set_base_name(name2); |
289 storage_->PutEntry(entry); | 312 EXPECT_TRUE(storage_->PutEntry(entry)); |
| 313 EXPECT_TRUE(CheckValidity()); |
| 314 |
| 315 RemoveChild(key1, name2); |
290 EXPECT_FALSE(CheckValidity()); // Missing parent-child relationship. | 316 EXPECT_FALSE(CheckValidity()); // Missing parent-child relationship. |
291 | 317 |
292 // Add missing parent-child relationship between key1 and key2. | 318 // Add back parent-child relationship between key1 and key2. |
293 storage_->PutChild(key1, name2, key2); | 319 PutChild(key1, name2, key2); |
294 EXPECT_TRUE(CheckValidity()); | 320 EXPECT_TRUE(CheckValidity()); |
295 | 321 |
296 // Add parent-child relationship between key2 and key3. | 322 // Add parent-child relationship between key2 and key3. |
297 storage_->PutChild(key2, name3, key3); | 323 PutChild(key2, name3, key3); |
298 EXPECT_FALSE(CheckValidity()); // key3 is not stored in the storage. | 324 EXPECT_FALSE(CheckValidity()); // key3 is not stored in the storage. |
299 | 325 |
300 // Put entry with key3 under key2. | 326 // Put entry with key3 under key2. |
301 entry.set_resource_id(key3); | 327 entry.set_resource_id(key3); |
302 entry.set_parent_resource_id(key2); | 328 entry.set_parent_resource_id(key2); |
303 entry.set_base_name(name3); | 329 entry.set_base_name(name3); |
304 storage_->PutEntry(entry); | 330 EXPECT_TRUE(storage_->PutEntry(entry)); |
305 EXPECT_TRUE(CheckValidity()); | 331 EXPECT_TRUE(CheckValidity()); |
306 | 332 |
307 // Parent-child relationship with wrong name. | 333 // Parent-child relationship with wrong name. |
308 storage_->RemoveChild(key2, name3); | 334 RemoveChild(key2, name3); |
309 EXPECT_FALSE(CheckValidity()); | 335 EXPECT_FALSE(CheckValidity()); |
310 storage_->PutChild(key2, name2, key3); | 336 PutChild(key2, name2, key3); |
311 EXPECT_FALSE(CheckValidity()); | 337 EXPECT_FALSE(CheckValidity()); |
312 | 338 |
313 // Fix up the relationship between key2 and key3. | 339 // Fix up the relationship between key2 and key3. |
314 storage_->RemoveChild(key2, name2); | 340 RemoveChild(key2, name2); |
315 EXPECT_FALSE(CheckValidity()); | 341 EXPECT_FALSE(CheckValidity()); |
316 storage_->PutChild(key2, name3, key3); | 342 PutChild(key2, name3, key3); |
317 EXPECT_TRUE(CheckValidity()); | 343 EXPECT_TRUE(CheckValidity()); |
318 | 344 |
319 // Remove key2. | 345 // Remove key2. |
320 storage_->RemoveChild(key1, name2); | 346 RemoveChild(key1, name2); |
321 EXPECT_FALSE(CheckValidity()); | 347 EXPECT_FALSE(CheckValidity()); |
322 storage_->RemoveEntry(key2); | 348 EXPECT_TRUE(storage_->RemoveEntry(key2)); |
323 EXPECT_FALSE(CheckValidity()); | 349 EXPECT_FALSE(CheckValidity()); |
324 | 350 |
325 // Remove key3. | 351 // Remove key3. |
326 storage_->RemoveChild(key2, name3); | 352 RemoveChild(key2, name3); |
327 EXPECT_FALSE(CheckValidity()); | 353 EXPECT_FALSE(CheckValidity()); |
328 storage_->RemoveEntry(key3); | 354 EXPECT_TRUE(storage_->RemoveEntry(key3)); |
329 EXPECT_TRUE(CheckValidity()); | 355 EXPECT_TRUE(CheckValidity()); |
330 | 356 |
331 // Remove key1. | 357 // Remove key1. |
332 storage_->RemoveEntry(key1); | 358 EXPECT_TRUE(storage_->RemoveEntry(key1)); |
333 EXPECT_TRUE(CheckValidity()); | 359 EXPECT_TRUE(CheckValidity()); |
334 } | 360 } |
335 | 361 |
336 } // namespace drive | 362 } // namespace drive |
OLD | NEW |