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/resource_metadata_storage.h" | 5 #include "chrome/browser/chromeos/drive/resource_metadata_storage.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/files/scoped_temp_dir.h" | 10 #include "base/files/scoped_temp_dir.h" |
(...skipping 14 matching lines...) Expand all Loading... |
25 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 25 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
26 | 26 |
27 storage_.reset(new ResourceMetadataStorage( | 27 storage_.reset(new ResourceMetadataStorage( |
28 temp_dir_.path(), base::MessageLoopProxy::current().get())); | 28 temp_dir_.path(), base::MessageLoopProxy::current().get())); |
29 ASSERT_TRUE(storage_->Initialize()); | 29 ASSERT_TRUE(storage_->Initialize()); |
30 } | 30 } |
31 | 31 |
32 // Overwrites |storage_|'s version. | 32 // Overwrites |storage_|'s version. |
33 void SetDBVersion(int version) { | 33 void SetDBVersion(int version) { |
34 ResourceMetadataHeader header; | 34 ResourceMetadataHeader header; |
35 ASSERT_TRUE(storage_->GetHeader(&header)); | 35 ASSERT_EQ(FILE_ERROR_OK, storage_->GetHeader(&header)); |
36 header.set_version(version); | 36 header.set_version(version); |
37 EXPECT_TRUE(storage_->PutHeader(header)); | 37 EXPECT_EQ(FILE_ERROR_OK, storage_->PutHeader(header)); |
38 } | 38 } |
39 | 39 |
40 bool CheckValidity() { | 40 bool CheckValidity() { |
41 return storage_->CheckValidity(); | 41 return storage_->CheckValidity(); |
42 } | 42 } |
43 | 43 |
44 leveldb::DB* resource_map() { return storage_->resource_map_.get(); } | 44 leveldb::DB* resource_map() { return storage_->resource_map_.get(); } |
45 | 45 |
46 // Puts a child entry. | 46 // Puts a child entry. |
47 void PutChild(const std::string& parent_id, | 47 void PutChild(const std::string& parent_id, |
(...skipping 14 matching lines...) Expand all Loading... |
62 } | 62 } |
63 | 63 |
64 content::TestBrowserThreadBundle thread_bundle_; | 64 content::TestBrowserThreadBundle thread_bundle_; |
65 base::ScopedTempDir temp_dir_; | 65 base::ScopedTempDir temp_dir_; |
66 scoped_ptr<ResourceMetadataStorage, | 66 scoped_ptr<ResourceMetadataStorage, |
67 test_util::DestroyHelperForTests> storage_; | 67 test_util::DestroyHelperForTests> storage_; |
68 }; | 68 }; |
69 | 69 |
70 TEST_F(ResourceMetadataStorageTest, LargestChangestamp) { | 70 TEST_F(ResourceMetadataStorageTest, LargestChangestamp) { |
71 const int64 kLargestChangestamp = 1234567890; | 71 const int64 kLargestChangestamp = 1234567890; |
72 EXPECT_TRUE(storage_->SetLargestChangestamp(kLargestChangestamp)); | 72 EXPECT_EQ(FILE_ERROR_OK, |
73 EXPECT_EQ(kLargestChangestamp, storage_->GetLargestChangestamp()); | 73 storage_->SetLargestChangestamp(kLargestChangestamp)); |
| 74 int64 value = 0; |
| 75 EXPECT_EQ(FILE_ERROR_OK, storage_->GetLargestChangestamp(&value)); |
| 76 EXPECT_EQ(kLargestChangestamp, value); |
74 } | 77 } |
75 | 78 |
76 TEST_F(ResourceMetadataStorageTest, PutEntry) { | 79 TEST_F(ResourceMetadataStorageTest, PutEntry) { |
77 const std::string key1 = "abcdefg"; | 80 const std::string key1 = "abcdefg"; |
78 const std::string key2 = "abcd"; | 81 const std::string key2 = "abcd"; |
79 const std::string key3 = "efgh"; | 82 const std::string key3 = "efgh"; |
80 const std::string name2 = "ABCD"; | 83 const std::string name2 = "ABCD"; |
81 const std::string name3 = "EFGH"; | 84 const std::string name3 = "EFGH"; |
82 | 85 |
83 // key1 not found. | 86 // key1 not found. |
84 ResourceEntry result; | 87 ResourceEntry result; |
85 EXPECT_FALSE(storage_->GetEntry(key1, &result)); | 88 EXPECT_EQ(FILE_ERROR_NOT_FOUND, storage_->GetEntry(key1, &result)); |
86 | 89 |
87 // Put entry1. | 90 // Put entry1. |
88 ResourceEntry entry1; | 91 ResourceEntry entry1; |
89 entry1.set_local_id(key1); | 92 entry1.set_local_id(key1); |
90 EXPECT_TRUE(storage_->PutEntry(entry1)); | 93 EXPECT_EQ(FILE_ERROR_OK, storage_->PutEntry(entry1)); |
91 | 94 |
92 // key1 found. | 95 // key1 found. |
93 EXPECT_TRUE(storage_->GetEntry(key1, &result)); | 96 EXPECT_EQ(FILE_ERROR_OK, storage_->GetEntry(key1, &result)); |
94 | 97 |
95 // key2 not found. | 98 // key2 not found. |
96 EXPECT_FALSE(storage_->GetEntry(key2, &result)); | 99 EXPECT_EQ(FILE_ERROR_NOT_FOUND, storage_->GetEntry(key2, &result)); |
97 | 100 |
98 // Put entry2 as a child of entry1. | 101 // Put entry2 as a child of entry1. |
99 ResourceEntry entry2; | 102 ResourceEntry entry2; |
100 entry2.set_local_id(key2); | 103 entry2.set_local_id(key2); |
101 entry2.set_parent_local_id(key1); | 104 entry2.set_parent_local_id(key1); |
102 entry2.set_base_name(name2); | 105 entry2.set_base_name(name2); |
103 EXPECT_TRUE(storage_->PutEntry(entry2)); | 106 EXPECT_EQ(FILE_ERROR_OK, storage_->PutEntry(entry2)); |
104 | 107 |
105 // key2 found. | 108 // key2 found. |
106 EXPECT_TRUE(storage_->GetEntry(key2, &result)); | 109 std::string child_id; |
107 EXPECT_EQ(key2, storage_->GetChild(key1, name2)); | 110 EXPECT_EQ(FILE_ERROR_OK, storage_->GetEntry(key2, &result)); |
| 111 EXPECT_EQ(FILE_ERROR_OK, storage_->GetChild(key1, name2, &child_id)); |
| 112 EXPECT_EQ(key2, child_id); |
108 | 113 |
109 // Put entry3 as a child of entry2. | 114 // Put entry3 as a child of entry2. |
110 ResourceEntry entry3; | 115 ResourceEntry entry3; |
111 entry3.set_local_id(key3); | 116 entry3.set_local_id(key3); |
112 entry3.set_parent_local_id(key2); | 117 entry3.set_parent_local_id(key2); |
113 entry3.set_base_name(name3); | 118 entry3.set_base_name(name3); |
114 EXPECT_TRUE(storage_->PutEntry(entry3)); | 119 EXPECT_EQ(FILE_ERROR_OK, storage_->PutEntry(entry3)); |
115 | 120 |
116 // key3 found. | 121 // key3 found. |
117 EXPECT_TRUE(storage_->GetEntry(key3, &result)); | 122 EXPECT_EQ(FILE_ERROR_OK, storage_->GetEntry(key3, &result)); |
118 EXPECT_EQ(key3, storage_->GetChild(key2, name3)); | 123 EXPECT_EQ(FILE_ERROR_OK, storage_->GetChild(key2, name3, &child_id)); |
| 124 EXPECT_EQ(key3, child_id); |
119 | 125 |
120 // Change entry3's parent to entry1. | 126 // Change entry3's parent to entry1. |
121 entry3.set_parent_local_id(key1); | 127 entry3.set_parent_local_id(key1); |
122 EXPECT_TRUE(storage_->PutEntry(entry3)); | 128 EXPECT_EQ(FILE_ERROR_OK, storage_->PutEntry(entry3)); |
123 | 129 |
124 // entry3 is a child of entry1 now. | 130 // entry3 is a child of entry1 now. |
125 EXPECT_TRUE(storage_->GetChild(key2, name3).empty()); | 131 EXPECT_EQ(FILE_ERROR_NOT_FOUND, storage_->GetChild(key2, name3, &child_id)); |
126 EXPECT_EQ(key3, storage_->GetChild(key1, name3)); | 132 EXPECT_EQ(FILE_ERROR_OK, storage_->GetChild(key1, name3, &child_id)); |
| 133 EXPECT_EQ(key3, child_id); |
127 | 134 |
128 // Remove entries. | 135 // Remove entries. |
129 EXPECT_TRUE(storage_->RemoveEntry(key3)); | 136 EXPECT_EQ(FILE_ERROR_OK, storage_->RemoveEntry(key3)); |
130 EXPECT_FALSE(storage_->GetEntry(key3, &result)); | 137 EXPECT_EQ(FILE_ERROR_NOT_FOUND, storage_->GetEntry(key3, &result)); |
131 EXPECT_TRUE(storage_->RemoveEntry(key2)); | 138 EXPECT_EQ(FILE_ERROR_OK, storage_->RemoveEntry(key2)); |
132 EXPECT_FALSE(storage_->GetEntry(key2, &result)); | 139 EXPECT_EQ(FILE_ERROR_NOT_FOUND, storage_->GetEntry(key2, &result)); |
133 EXPECT_TRUE(storage_->RemoveEntry(key1)); | 140 EXPECT_EQ(FILE_ERROR_OK, storage_->RemoveEntry(key1)); |
134 EXPECT_FALSE(storage_->GetEntry(key1, &result)); | 141 EXPECT_EQ(FILE_ERROR_NOT_FOUND, storage_->GetEntry(key1, &result)); |
135 } | 142 } |
136 | 143 |
137 TEST_F(ResourceMetadataStorageTest, Iterator) { | 144 TEST_F(ResourceMetadataStorageTest, Iterator) { |
138 // Prepare data. | 145 // Prepare data. |
139 std::vector<std::string> keys; | 146 std::vector<std::string> keys; |
140 | 147 |
141 keys.push_back("entry1"); | 148 keys.push_back("entry1"); |
142 keys.push_back("entry2"); | 149 keys.push_back("entry2"); |
143 keys.push_back("entry3"); | 150 keys.push_back("entry3"); |
144 keys.push_back("entry4"); | 151 keys.push_back("entry4"); |
145 | 152 |
146 for (size_t i = 0; i < keys.size(); ++i) { | 153 for (size_t i = 0; i < keys.size(); ++i) { |
147 ResourceEntry entry; | 154 ResourceEntry entry; |
148 entry.set_local_id(keys[i]); | 155 entry.set_local_id(keys[i]); |
149 EXPECT_TRUE(storage_->PutEntry(entry)); | 156 EXPECT_EQ(FILE_ERROR_OK, storage_->PutEntry(entry)); |
150 } | 157 } |
151 | 158 |
152 // Insert some cache entries. | 159 // Insert some cache entries. |
153 std::map<std::string, FileCacheEntry> cache_entries; | 160 std::map<std::string, FileCacheEntry> cache_entries; |
154 cache_entries[keys[0]].set_md5("aaaaaa"); | 161 cache_entries[keys[0]].set_md5("aaaaaa"); |
155 cache_entries[keys[1]].set_md5("bbbbbb"); | 162 cache_entries[keys[1]].set_md5("bbbbbb"); |
156 for (std::map<std::string, FileCacheEntry>::iterator it = | 163 for (std::map<std::string, FileCacheEntry>::iterator it = |
157 cache_entries.begin(); it != cache_entries.end(); ++it) | 164 cache_entries.begin(); it != cache_entries.end(); ++it) |
158 EXPECT_TRUE(storage_->PutCacheEntry(it->first, it->second)); | 165 EXPECT_EQ(FILE_ERROR_OK, storage_->PutCacheEntry(it->first, it->second)); |
159 | 166 |
160 // Iterate and check the result. | 167 // Iterate and check the result. |
161 std::map<std::string, ResourceEntry> found_entries; | 168 std::map<std::string, ResourceEntry> found_entries; |
162 std::map<std::string, FileCacheEntry> found_cache_entries; | 169 std::map<std::string, FileCacheEntry> found_cache_entries; |
163 scoped_ptr<ResourceMetadataStorage::Iterator> it = storage_->GetIterator(); | 170 scoped_ptr<ResourceMetadataStorage::Iterator> it = storage_->GetIterator(); |
164 ASSERT_TRUE(it); | 171 ASSERT_TRUE(it); |
165 for (; !it->IsAtEnd(); it->Advance()) { | 172 for (; !it->IsAtEnd(); it->Advance()) { |
166 const ResourceEntry& entry = it->GetValue(); | 173 const ResourceEntry& entry = it->GetValue(); |
167 found_entries[it->GetID()] = entry; | 174 found_entries[it->GetID()] = entry; |
168 | 175 |
(...skipping 17 matching lines...) Expand all Loading... |
186 | 193 |
187 TEST_F(ResourceMetadataStorageTest, PutCacheEntry) { | 194 TEST_F(ResourceMetadataStorageTest, PutCacheEntry) { |
188 FileCacheEntry entry; | 195 FileCacheEntry entry; |
189 const std::string key1 = "abcdefg"; | 196 const std::string key1 = "abcdefg"; |
190 const std::string key2 = "abcd"; | 197 const std::string key2 = "abcd"; |
191 const std::string md5_1 = "foo"; | 198 const std::string md5_1 = "foo"; |
192 const std::string md5_2 = "bar"; | 199 const std::string md5_2 = "bar"; |
193 | 200 |
194 // Put cache entries. | 201 // Put cache entries. |
195 entry.set_md5(md5_1); | 202 entry.set_md5(md5_1); |
196 EXPECT_TRUE(storage_->PutCacheEntry(key1, entry)); | 203 EXPECT_EQ(FILE_ERROR_OK, storage_->PutCacheEntry(key1, entry)); |
197 entry.set_md5(md5_2); | 204 entry.set_md5(md5_2); |
198 EXPECT_TRUE(storage_->PutCacheEntry(key2, entry)); | 205 EXPECT_EQ(FILE_ERROR_OK, storage_->PutCacheEntry(key2, entry)); |
199 | 206 |
200 // Get cache entires. | 207 // Get cache entires. |
201 EXPECT_TRUE(storage_->GetCacheEntry(key1, &entry)); | 208 EXPECT_EQ(FILE_ERROR_OK, storage_->GetCacheEntry(key1, &entry)); |
202 EXPECT_EQ(md5_1, entry.md5()); | 209 EXPECT_EQ(md5_1, entry.md5()); |
203 EXPECT_TRUE(storage_->GetCacheEntry(key2, &entry)); | 210 EXPECT_EQ(FILE_ERROR_OK, storage_->GetCacheEntry(key2, &entry)); |
204 EXPECT_EQ(md5_2, entry.md5()); | 211 EXPECT_EQ(md5_2, entry.md5()); |
205 | 212 |
206 // Remove cache entries. | 213 // Remove cache entries. |
207 EXPECT_TRUE(storage_->RemoveCacheEntry(key1)); | 214 EXPECT_EQ(FILE_ERROR_OK, storage_->RemoveCacheEntry(key1)); |
208 EXPECT_FALSE(storage_->GetCacheEntry(key1, &entry)); | 215 EXPECT_EQ(FILE_ERROR_NOT_FOUND, storage_->GetCacheEntry(key1, &entry)); |
209 | 216 |
210 EXPECT_TRUE(storage_->RemoveCacheEntry(key2)); | 217 EXPECT_EQ(FILE_ERROR_OK, storage_->RemoveCacheEntry(key2)); |
211 EXPECT_FALSE(storage_->GetCacheEntry(key2, &entry)); | 218 EXPECT_EQ(FILE_ERROR_NOT_FOUND, storage_->GetCacheEntry(key2, &entry)); |
212 } | 219 } |
213 | 220 |
214 TEST_F(ResourceMetadataStorageTest, CacheEntryIterator) { | 221 TEST_F(ResourceMetadataStorageTest, CacheEntryIterator) { |
215 // Prepare data. | 222 // Prepare data. |
216 std::map<std::string, FileCacheEntry> entries; | 223 std::map<std::string, FileCacheEntry> entries; |
217 FileCacheEntry cache_entry; | 224 FileCacheEntry cache_entry; |
218 | 225 |
219 cache_entry.set_md5("aA"); | 226 cache_entry.set_md5("aA"); |
220 entries["entry1"] = cache_entry; | 227 entries["entry1"] = cache_entry; |
221 cache_entry.set_md5("bB"); | 228 cache_entry.set_md5("bB"); |
222 entries["entry2"] = cache_entry; | 229 entries["entry2"] = cache_entry; |
223 cache_entry.set_md5("cC"); | 230 cache_entry.set_md5("cC"); |
224 entries["entry3"] = cache_entry; | 231 entries["entry3"] = cache_entry; |
225 cache_entry.set_md5("dD"); | 232 cache_entry.set_md5("dD"); |
226 entries["entry4"] = cache_entry; | 233 entries["entry4"] = cache_entry; |
227 | 234 |
228 for (std::map<std::string, FileCacheEntry>::iterator it = entries.begin(); | 235 for (std::map<std::string, FileCacheEntry>::iterator it = entries.begin(); |
229 it != entries.end(); ++it) | 236 it != entries.end(); ++it) |
230 EXPECT_TRUE(storage_->PutCacheEntry(it->first, it->second)); | 237 EXPECT_EQ(FILE_ERROR_OK, storage_->PutCacheEntry(it->first, it->second)); |
231 | 238 |
232 // Insert some dummy entries. | 239 // Insert some dummy entries. |
233 ResourceEntry entry; | 240 ResourceEntry entry; |
234 entry.set_local_id("entry1"); | 241 entry.set_local_id("entry1"); |
235 EXPECT_TRUE(storage_->PutEntry(entry)); | 242 EXPECT_EQ(FILE_ERROR_OK, storage_->PutEntry(entry)); |
236 entry.set_local_id("entry2"); | 243 entry.set_local_id("entry2"); |
237 EXPECT_TRUE(storage_->PutEntry(entry)); | 244 EXPECT_EQ(FILE_ERROR_OK, storage_->PutEntry(entry)); |
238 | 245 |
239 // Iterate and check the result. | 246 // Iterate and check the result. |
240 scoped_ptr<ResourceMetadataStorage::CacheEntryIterator> it = | 247 scoped_ptr<ResourceMetadataStorage::CacheEntryIterator> it = |
241 storage_->GetCacheEntryIterator(); | 248 storage_->GetCacheEntryIterator(); |
242 ASSERT_TRUE(it); | 249 ASSERT_TRUE(it); |
243 size_t num_entries = 0; | 250 size_t num_entries = 0; |
244 for (; !it->IsAtEnd(); it->Advance()) { | 251 for (; !it->IsAtEnd(); it->Advance()) { |
245 EXPECT_EQ(1U, entries.count(it->GetID())); | 252 EXPECT_EQ(1U, entries.count(it->GetID())); |
246 EXPECT_EQ(entries[it->GetID()].md5(), it->GetValue().md5()); | 253 EXPECT_EQ(entries[it->GetID()].md5(), it->GetValue().md5()); |
247 ++num_entries; | 254 ++num_entries; |
248 } | 255 } |
249 EXPECT_FALSE(it->HasError()); | 256 EXPECT_FALSE(it->HasError()); |
250 EXPECT_EQ(entries.size(), num_entries); | 257 EXPECT_EQ(entries.size(), num_entries); |
251 } | 258 } |
252 | 259 |
253 TEST_F(ResourceMetadataStorageTest, GetIdByResourceId) { | 260 TEST_F(ResourceMetadataStorageTest, GetIdByResourceId) { |
254 const std::string local_id = "local_id"; | 261 const std::string local_id = "local_id"; |
255 const std::string resource_id = "resource_id"; | 262 const std::string resource_id = "resource_id"; |
256 | 263 |
257 // Resource ID to local ID mapping is not stored yet. | 264 // Resource ID to local ID mapping is not stored yet. |
258 std::string id; | 265 std::string id; |
259 EXPECT_FALSE(storage_->GetIdByResourceId(resource_id, &id)); | 266 EXPECT_EQ(FILE_ERROR_NOT_FOUND, |
| 267 storage_->GetIdByResourceId(resource_id, &id)); |
260 | 268 |
261 // Put an entry with the resource ID. | 269 // Put an entry with the resource ID. |
262 ResourceEntry entry; | 270 ResourceEntry entry; |
263 entry.set_local_id(local_id); | 271 entry.set_local_id(local_id); |
264 entry.set_resource_id(resource_id); | 272 entry.set_resource_id(resource_id); |
265 EXPECT_TRUE(storage_->PutEntry(entry)); | 273 EXPECT_EQ(FILE_ERROR_OK, storage_->PutEntry(entry)); |
266 | 274 |
267 // Can get local ID by resource ID. | 275 // Can get local ID by resource ID. |
268 EXPECT_TRUE(storage_->GetIdByResourceId(resource_id, &id)); | 276 EXPECT_EQ(FILE_ERROR_OK, storage_->GetIdByResourceId(resource_id, &id)); |
269 EXPECT_EQ(local_id, id); | 277 EXPECT_EQ(local_id, id); |
270 | 278 |
271 // Resource ID to local ID mapping is removed. | 279 // Resource ID to local ID mapping is removed. |
272 EXPECT_TRUE(storage_->RemoveEntry(local_id)); | 280 EXPECT_EQ(FILE_ERROR_OK, storage_->RemoveEntry(local_id)); |
273 EXPECT_FALSE(storage_->GetIdByResourceId(resource_id, &id)); | 281 EXPECT_EQ(FILE_ERROR_NOT_FOUND, |
| 282 storage_->GetIdByResourceId(resource_id, &id)); |
274 } | 283 } |
275 | 284 |
276 TEST_F(ResourceMetadataStorageTest, GetChildren) { | 285 TEST_F(ResourceMetadataStorageTest, GetChildren) { |
277 const std::string parents_id[] = { "mercury", "venus", "mars", "jupiter", | 286 const std::string parents_id[] = { "mercury", "venus", "mars", "jupiter", |
278 "saturn" }; | 287 "saturn" }; |
279 std::vector<std::vector<std::pair<std::string, std::string> > > | 288 std::vector<std::vector<std::pair<std::string, std::string> > > |
280 children_name_id(arraysize(parents_id)); | 289 children_name_id(arraysize(parents_id)); |
281 // Skip children_name_id[0/1] here because Mercury and Venus have no moon. | 290 // Skip children_name_id[0/1] here because Mercury and Venus have no moon. |
282 children_name_id[2].push_back(std::make_pair("phobos", "mars_i")); | 291 children_name_id[2].push_back(std::make_pair("phobos", "mars_i")); |
283 children_name_id[2].push_back(std::make_pair("deimos", "mars_ii")); | 292 children_name_id[2].push_back(std::make_pair("deimos", "mars_ii")); |
284 children_name_id[3].push_back(std::make_pair("io", "jupiter_i")); | 293 children_name_id[3].push_back(std::make_pair("io", "jupiter_i")); |
285 children_name_id[3].push_back(std::make_pair("europa", "jupiter_ii")); | 294 children_name_id[3].push_back(std::make_pair("europa", "jupiter_ii")); |
286 children_name_id[3].push_back(std::make_pair("ganymede", "jupiter_iii")); | 295 children_name_id[3].push_back(std::make_pair("ganymede", "jupiter_iii")); |
287 children_name_id[3].push_back(std::make_pair("calisto", "jupiter_iv")); | 296 children_name_id[3].push_back(std::make_pair("calisto", "jupiter_iv")); |
288 children_name_id[4].push_back(std::make_pair("mimas", "saturn_i")); | 297 children_name_id[4].push_back(std::make_pair("mimas", "saturn_i")); |
289 children_name_id[4].push_back(std::make_pair("enceladus", "saturn_ii")); | 298 children_name_id[4].push_back(std::make_pair("enceladus", "saturn_ii")); |
290 children_name_id[4].push_back(std::make_pair("tethys", "saturn_iii")); | 299 children_name_id[4].push_back(std::make_pair("tethys", "saturn_iii")); |
291 children_name_id[4].push_back(std::make_pair("dione", "saturn_iv")); | 300 children_name_id[4].push_back(std::make_pair("dione", "saturn_iv")); |
292 children_name_id[4].push_back(std::make_pair("rhea", "saturn_v")); | 301 children_name_id[4].push_back(std::make_pair("rhea", "saturn_v")); |
293 children_name_id[4].push_back(std::make_pair("titan", "saturn_vi")); | 302 children_name_id[4].push_back(std::make_pair("titan", "saturn_vi")); |
294 children_name_id[4].push_back(std::make_pair("iapetus", "saturn_vii")); | 303 children_name_id[4].push_back(std::make_pair("iapetus", "saturn_vii")); |
295 | 304 |
296 // Put parents. | 305 // Put parents. |
297 for (size_t i = 0; i < arraysize(parents_id); ++i) { | 306 for (size_t i = 0; i < arraysize(parents_id); ++i) { |
298 ResourceEntry entry; | 307 ResourceEntry entry; |
299 entry.set_local_id(parents_id[i]); | 308 entry.set_local_id(parents_id[i]); |
300 EXPECT_TRUE(storage_->PutEntry(entry)); | 309 EXPECT_EQ(FILE_ERROR_OK, storage_->PutEntry(entry)); |
301 } | 310 } |
302 | 311 |
303 // Put children. | 312 // Put children. |
304 for (size_t i = 0; i < children_name_id.size(); ++i) { | 313 for (size_t i = 0; i < children_name_id.size(); ++i) { |
305 for (size_t j = 0; j < children_name_id[i].size(); ++j) { | 314 for (size_t j = 0; j < children_name_id[i].size(); ++j) { |
306 ResourceEntry entry; | 315 ResourceEntry entry; |
307 entry.set_local_id(children_name_id[i][j].second); | 316 entry.set_local_id(children_name_id[i][j].second); |
308 entry.set_parent_local_id(parents_id[i]); | 317 entry.set_parent_local_id(parents_id[i]); |
309 entry.set_base_name(children_name_id[i][j].first); | 318 entry.set_base_name(children_name_id[i][j].first); |
310 EXPECT_TRUE(storage_->PutEntry(entry)); | 319 EXPECT_EQ(FILE_ERROR_OK, storage_->PutEntry(entry)); |
311 } | 320 } |
312 } | 321 } |
313 | 322 |
314 // Put some dummy cache entries. | 323 // Put some dummy cache entries. |
315 for (size_t i = 0; i < arraysize(parents_id); ++i) { | 324 for (size_t i = 0; i < arraysize(parents_id); ++i) { |
316 FileCacheEntry cache_entry; | 325 FileCacheEntry cache_entry; |
317 EXPECT_TRUE(storage_->PutCacheEntry(parents_id[i], cache_entry)); | 326 EXPECT_EQ(FILE_ERROR_OK, |
| 327 storage_->PutCacheEntry(parents_id[i], cache_entry)); |
318 } | 328 } |
319 | 329 |
320 // Try to get children. | 330 // Try to get children. |
321 for (size_t i = 0; i < children_name_id.size(); ++i) { | 331 for (size_t i = 0; i < children_name_id.size(); ++i) { |
322 std::vector<std::string> children; | 332 std::vector<std::string> children; |
323 storage_->GetChildren(parents_id[i], &children); | 333 storage_->GetChildren(parents_id[i], &children); |
324 EXPECT_EQ(children_name_id[i].size(), children.size()); | 334 EXPECT_EQ(children_name_id[i].size(), children.size()); |
325 for (size_t j = 0; j < children_name_id[i].size(); ++j) { | 335 for (size_t j = 0; j < children_name_id[i].size(); ++j) { |
326 EXPECT_EQ(1, std::count(children.begin(), | 336 EXPECT_EQ(1, std::count(children.begin(), |
327 children.end(), | 337 children.end(), |
328 children_name_id[i][j].second)); | 338 children_name_id[i][j].second)); |
329 } | 339 } |
330 } | 340 } |
331 } | 341 } |
332 | 342 |
333 TEST_F(ResourceMetadataStorageTest, OpenExistingDB) { | 343 TEST_F(ResourceMetadataStorageTest, OpenExistingDB) { |
334 const std::string parent_id1 = "abcdefg"; | 344 const std::string parent_id1 = "abcdefg"; |
335 const std::string child_name1 = "WXYZABC"; | 345 const std::string child_name1 = "WXYZABC"; |
336 const std::string child_id1 = "qwerty"; | 346 const std::string child_id1 = "qwerty"; |
337 | 347 |
338 ResourceEntry entry1; | 348 ResourceEntry entry1; |
339 entry1.set_local_id(parent_id1); | 349 entry1.set_local_id(parent_id1); |
340 ResourceEntry entry2; | 350 ResourceEntry entry2; |
341 entry2.set_local_id(child_id1); | 351 entry2.set_local_id(child_id1); |
342 entry2.set_parent_local_id(parent_id1); | 352 entry2.set_parent_local_id(parent_id1); |
343 entry2.set_base_name(child_name1); | 353 entry2.set_base_name(child_name1); |
344 | 354 |
345 // Put some data. | 355 // Put some data. |
346 EXPECT_TRUE(storage_->PutEntry(entry1)); | 356 EXPECT_EQ(FILE_ERROR_OK, storage_->PutEntry(entry1)); |
347 EXPECT_TRUE(storage_->PutEntry(entry2)); | 357 EXPECT_EQ(FILE_ERROR_OK, storage_->PutEntry(entry2)); |
348 | 358 |
349 // Close DB and reopen. | 359 // Close DB and reopen. |
350 storage_.reset(new ResourceMetadataStorage( | 360 storage_.reset(new ResourceMetadataStorage( |
351 temp_dir_.path(), base::MessageLoopProxy::current().get())); | 361 temp_dir_.path(), base::MessageLoopProxy::current().get())); |
352 ASSERT_TRUE(storage_->Initialize()); | 362 ASSERT_TRUE(storage_->Initialize()); |
353 | 363 |
354 // Can read data. | 364 // Can read data. |
355 ResourceEntry result; | 365 ResourceEntry result; |
356 EXPECT_TRUE(storage_->GetEntry(parent_id1, &result)); | 366 EXPECT_EQ(FILE_ERROR_OK, storage_->GetEntry(parent_id1, &result)); |
357 | 367 |
358 EXPECT_TRUE(storage_->GetEntry(child_id1, &result)); | 368 EXPECT_EQ(FILE_ERROR_OK, storage_->GetEntry(child_id1, &result)); |
359 EXPECT_EQ(parent_id1, result.parent_local_id()); | 369 EXPECT_EQ(parent_id1, result.parent_local_id()); |
360 EXPECT_EQ(child_name1, result.base_name()); | 370 EXPECT_EQ(child_name1, result.base_name()); |
361 | 371 |
362 EXPECT_EQ(child_id1, storage_->GetChild(parent_id1, child_name1)); | 372 std::string child_id; |
| 373 EXPECT_EQ(FILE_ERROR_OK, |
| 374 storage_->GetChild(parent_id1, child_name1, &child_id)); |
| 375 EXPECT_EQ(child_id1, child_id); |
363 } | 376 } |
364 | 377 |
365 TEST_F(ResourceMetadataStorageTest, IncompatibleDB_M29) { | 378 TEST_F(ResourceMetadataStorageTest, IncompatibleDB_M29) { |
366 const int64 kLargestChangestamp = 1234567890; | 379 const int64 kLargestChangestamp = 1234567890; |
367 | 380 |
368 // Construct M29 version DB. | 381 // Construct M29 version DB. |
369 SetDBVersion(6); | 382 SetDBVersion(6); |
370 EXPECT_TRUE(storage_->SetLargestChangestamp(kLargestChangestamp)); | 383 EXPECT_EQ(FILE_ERROR_OK, |
| 384 storage_->SetLargestChangestamp(kLargestChangestamp)); |
371 | 385 |
372 leveldb::WriteBatch batch; | 386 leveldb::WriteBatch batch; |
373 | 387 |
374 // Put a file entry and its cache entry. | 388 // Put a file entry and its cache entry. |
375 ResourceEntry entry; | 389 ResourceEntry entry; |
376 std::string serialized_entry; | 390 std::string serialized_entry; |
377 entry.set_resource_id("file:abcd"); | 391 entry.set_resource_id("file:abcd"); |
378 EXPECT_TRUE(entry.SerializeToString(&serialized_entry)); | 392 EXPECT_TRUE(entry.SerializeToString(&serialized_entry)); |
379 batch.Put("file:abcd", serialized_entry); | 393 batch.Put("file:abcd", serialized_entry); |
380 | 394 |
381 FileCacheEntry cache_entry; | 395 FileCacheEntry cache_entry; |
382 EXPECT_TRUE(cache_entry.SerializeToString(&serialized_entry)); | 396 EXPECT_TRUE(cache_entry.SerializeToString(&serialized_entry)); |
383 batch.Put(std::string("file:abcd") + '\0' + "CACHE", serialized_entry); | 397 batch.Put(std::string("file:abcd") + '\0' + "CACHE", serialized_entry); |
384 | 398 |
385 EXPECT_TRUE(resource_map()->Write(leveldb::WriteOptions(), &batch).ok()); | 399 EXPECT_TRUE(resource_map()->Write(leveldb::WriteOptions(), &batch).ok()); |
386 | 400 |
387 // Upgrade and reopen. | 401 // Upgrade and reopen. |
388 storage_.reset(); | 402 storage_.reset(); |
389 EXPECT_TRUE(ResourceMetadataStorage::UpgradeOldDB( | 403 EXPECT_TRUE(ResourceMetadataStorage::UpgradeOldDB( |
390 temp_dir_.path(), base::Bind(&util::CanonicalizeResourceId))); | 404 temp_dir_.path(), base::Bind(&util::CanonicalizeResourceId))); |
391 storage_.reset(new ResourceMetadataStorage( | 405 storage_.reset(new ResourceMetadataStorage( |
392 temp_dir_.path(), base::MessageLoopProxy::current().get())); | 406 temp_dir_.path(), base::MessageLoopProxy::current().get())); |
393 ASSERT_TRUE(storage_->Initialize()); | 407 ASSERT_TRUE(storage_->Initialize()); |
394 | 408 |
395 // Resource-ID-to-local-ID mapping is added. | 409 // Resource-ID-to-local-ID mapping is added. |
396 std::string id; | 410 std::string id; |
397 EXPECT_TRUE(storage_->GetIdByResourceId("abcd", &id)); // "file:" is dropped. | 411 EXPECT_EQ(FILE_ERROR_OK, |
| 412 storage_->GetIdByResourceId("abcd", &id)); // "file:" is dropped. |
398 | 413 |
399 // Data is erased, except cache entries. | 414 // Data is erased, except cache entries. |
400 EXPECT_EQ(0, storage_->GetLargestChangestamp()); | 415 int64 largest_changestamp = 0; |
401 EXPECT_FALSE(storage_->GetEntry(id, &entry)); | 416 EXPECT_EQ(FILE_ERROR_OK, |
402 EXPECT_TRUE(storage_->GetCacheEntry(id, &cache_entry)); | 417 storage_->GetLargestChangestamp(&largest_changestamp)); |
| 418 EXPECT_EQ(0, largest_changestamp); |
| 419 EXPECT_EQ(FILE_ERROR_NOT_FOUND, storage_->GetEntry(id, &entry)); |
| 420 EXPECT_EQ(FILE_ERROR_OK, storage_->GetCacheEntry(id, &cache_entry)); |
403 } | 421 } |
404 | 422 |
405 TEST_F(ResourceMetadataStorageTest, IncompatibleDB_M32) { | 423 TEST_F(ResourceMetadataStorageTest, IncompatibleDB_M32) { |
406 const int64 kLargestChangestamp = 1234567890; | 424 const int64 kLargestChangestamp = 1234567890; |
407 const std::string resource_id = "abcd"; | 425 const std::string resource_id = "abcd"; |
408 const std::string local_id = "local-abcd"; | 426 const std::string local_id = "local-abcd"; |
409 | 427 |
410 // Construct M32 version DB. | 428 // Construct M32 version DB. |
411 SetDBVersion(11); | 429 SetDBVersion(11); |
412 EXPECT_TRUE(storage_->SetLargestChangestamp(kLargestChangestamp)); | 430 EXPECT_EQ(FILE_ERROR_OK, |
| 431 storage_->SetLargestChangestamp(kLargestChangestamp)); |
413 | 432 |
414 leveldb::WriteBatch batch; | 433 leveldb::WriteBatch batch; |
415 | 434 |
416 // Put a file entry and its cache and id entry. | 435 // Put a file entry and its cache and id entry. |
417 ResourceEntry entry; | 436 ResourceEntry entry; |
418 std::string serialized_entry; | 437 std::string serialized_entry; |
419 entry.set_resource_id(resource_id); | 438 entry.set_resource_id(resource_id); |
420 EXPECT_TRUE(entry.SerializeToString(&serialized_entry)); | 439 EXPECT_TRUE(entry.SerializeToString(&serialized_entry)); |
421 batch.Put(local_id, serialized_entry); | 440 batch.Put(local_id, serialized_entry); |
422 | 441 |
423 FileCacheEntry cache_entry; | 442 FileCacheEntry cache_entry; |
424 EXPECT_TRUE(cache_entry.SerializeToString(&serialized_entry)); | 443 EXPECT_TRUE(cache_entry.SerializeToString(&serialized_entry)); |
425 batch.Put(local_id + '\0' + "CACHE", serialized_entry); | 444 batch.Put(local_id + '\0' + "CACHE", serialized_entry); |
426 | 445 |
427 batch.Put('\0' + std::string("ID") + '\0' + resource_id, local_id); | 446 batch.Put('\0' + std::string("ID") + '\0' + resource_id, local_id); |
428 | 447 |
429 EXPECT_TRUE(resource_map()->Write(leveldb::WriteOptions(), &batch).ok()); | 448 EXPECT_TRUE(resource_map()->Write(leveldb::WriteOptions(), &batch).ok()); |
430 | 449 |
431 // Upgrade and reopen. | 450 // Upgrade and reopen. |
432 storage_.reset(); | 451 storage_.reset(); |
433 EXPECT_TRUE(ResourceMetadataStorage::UpgradeOldDB( | 452 EXPECT_TRUE(ResourceMetadataStorage::UpgradeOldDB( |
434 temp_dir_.path(), base::Bind(&util::CanonicalizeResourceId))); | 453 temp_dir_.path(), base::Bind(&util::CanonicalizeResourceId))); |
435 storage_.reset(new ResourceMetadataStorage( | 454 storage_.reset(new ResourceMetadataStorage( |
436 temp_dir_.path(), base::MessageLoopProxy::current().get())); | 455 temp_dir_.path(), base::MessageLoopProxy::current().get())); |
437 ASSERT_TRUE(storage_->Initialize()); | 456 ASSERT_TRUE(storage_->Initialize()); |
438 | 457 |
439 // Data is erased, except cache and id mapping entries. | 458 // Data is erased, except cache and id mapping entries. |
440 std::string id; | 459 std::string id; |
441 EXPECT_TRUE(storage_->GetIdByResourceId(resource_id, &id)); | 460 EXPECT_EQ(FILE_ERROR_OK, storage_->GetIdByResourceId(resource_id, &id)); |
442 EXPECT_EQ(local_id, id); | 461 EXPECT_EQ(local_id, id); |
443 EXPECT_EQ(0, storage_->GetLargestChangestamp()); | 462 int64 largest_changestamp = 0; |
444 EXPECT_FALSE(storage_->GetEntry(id, &entry)); | 463 EXPECT_EQ(FILE_ERROR_OK, |
445 EXPECT_TRUE(storage_->GetCacheEntry(id, &cache_entry)); | 464 storage_->GetLargestChangestamp(&largest_changestamp)); |
| 465 EXPECT_EQ(0, largest_changestamp); |
| 466 EXPECT_EQ(FILE_ERROR_NOT_FOUND, storage_->GetEntry(id, &entry)); |
| 467 EXPECT_EQ(FILE_ERROR_OK, storage_->GetCacheEntry(id, &cache_entry)); |
446 } | 468 } |
447 | 469 |
448 TEST_F(ResourceMetadataStorageTest, IncompatibleDB_Unknown) { | 470 TEST_F(ResourceMetadataStorageTest, IncompatibleDB_Unknown) { |
449 const int64 kLargestChangestamp = 1234567890; | 471 const int64 kLargestChangestamp = 1234567890; |
450 const std::string key1 = "abcd"; | 472 const std::string key1 = "abcd"; |
451 | 473 |
452 // Put some data. | 474 // Put some data. |
453 EXPECT_TRUE(storage_->SetLargestChangestamp(kLargestChangestamp)); | 475 EXPECT_EQ(FILE_ERROR_OK, |
| 476 storage_->SetLargestChangestamp(kLargestChangestamp)); |
454 ResourceEntry entry; | 477 ResourceEntry entry; |
455 entry.set_local_id(key1); | 478 entry.set_local_id(key1); |
456 EXPECT_TRUE(storage_->PutEntry(entry)); | 479 EXPECT_EQ(FILE_ERROR_OK, storage_->PutEntry(entry)); |
457 FileCacheEntry cache_entry; | 480 FileCacheEntry cache_entry; |
458 EXPECT_TRUE(storage_->PutCacheEntry(key1, cache_entry)); | 481 EXPECT_EQ(FILE_ERROR_OK, storage_->PutCacheEntry(key1, cache_entry)); |
459 | 482 |
460 // Set newer version, upgrade and reopen DB. | 483 // Set newer version, upgrade and reopen DB. |
461 SetDBVersion(ResourceMetadataStorage::kDBVersion + 1); | 484 SetDBVersion(ResourceMetadataStorage::kDBVersion + 1); |
462 storage_.reset(); | 485 storage_.reset(); |
463 EXPECT_FALSE(ResourceMetadataStorage::UpgradeOldDB( | 486 EXPECT_FALSE(ResourceMetadataStorage::UpgradeOldDB( |
464 temp_dir_.path(), base::Bind(&util::CanonicalizeResourceId))); | 487 temp_dir_.path(), base::Bind(&util::CanonicalizeResourceId))); |
465 storage_.reset(new ResourceMetadataStorage( | 488 storage_.reset(new ResourceMetadataStorage( |
466 temp_dir_.path(), base::MessageLoopProxy::current().get())); | 489 temp_dir_.path(), base::MessageLoopProxy::current().get())); |
467 ASSERT_TRUE(storage_->Initialize()); | 490 ASSERT_TRUE(storage_->Initialize()); |
468 | 491 |
469 // Data is erased because of the incompatible version. | 492 // Data is erased because of the incompatible version. |
470 EXPECT_EQ(0, storage_->GetLargestChangestamp()); | 493 int64 largest_changestamp = 0; |
471 EXPECT_FALSE(storage_->GetEntry(key1, &entry)); | 494 EXPECT_EQ(FILE_ERROR_OK, |
472 EXPECT_FALSE(storage_->GetCacheEntry(key1, &cache_entry)); | 495 storage_->GetLargestChangestamp(&largest_changestamp)); |
| 496 EXPECT_EQ(0, largest_changestamp); |
| 497 EXPECT_EQ(FILE_ERROR_NOT_FOUND, storage_->GetEntry(key1, &entry)); |
| 498 EXPECT_EQ(FILE_ERROR_NOT_FOUND, storage_->GetCacheEntry(key1, &cache_entry)); |
473 } | 499 } |
474 | 500 |
475 TEST_F(ResourceMetadataStorageTest, WrongPath) { | 501 TEST_F(ResourceMetadataStorageTest, WrongPath) { |
476 // Create a file. | 502 // Create a file. |
477 base::FilePath path; | 503 base::FilePath path; |
478 ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir_.path(), &path)); | 504 ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir_.path(), &path)); |
479 | 505 |
480 storage_.reset(new ResourceMetadataStorage( | 506 storage_.reset(new ResourceMetadataStorage( |
481 path, base::MessageLoopProxy::current().get())); | 507 path, base::MessageLoopProxy::current().get())); |
482 // Cannot initialize DB beacause the path does not point a directory. | 508 // Cannot initialize DB beacause the path does not point a directory. |
483 ASSERT_FALSE(storage_->Initialize()); | 509 ASSERT_FALSE(storage_->Initialize()); |
484 } | 510 } |
485 | 511 |
486 TEST_F(ResourceMetadataStorageTest, RecoverCacheEntriesFromTrashedResourceMap) { | 512 TEST_F(ResourceMetadataStorageTest, RecoverCacheEntriesFromTrashedResourceMap) { |
487 // Put some cache entries. | 513 // Put some cache entries. |
488 FileCacheEntry cache_entry; | 514 FileCacheEntry cache_entry; |
489 cache_entry.set_md5("md5_foo"); | 515 cache_entry.set_md5("md5_foo"); |
490 EXPECT_TRUE(storage_->PutCacheEntry("id_foo", cache_entry)); | 516 EXPECT_EQ(FILE_ERROR_OK, storage_->PutCacheEntry("id_foo", cache_entry)); |
491 cache_entry.set_md5("md5_bar"); | 517 cache_entry.set_md5("md5_bar"); |
492 cache_entry.set_is_dirty(true); | 518 cache_entry.set_is_dirty(true); |
493 EXPECT_TRUE(storage_->PutCacheEntry("id_bar", cache_entry)); | 519 EXPECT_EQ(FILE_ERROR_OK, storage_->PutCacheEntry("id_bar", cache_entry)); |
494 | 520 |
495 // Put entry with id_foo. | 521 // Put entry with id_foo. |
496 ResourceEntry entry; | 522 ResourceEntry entry; |
497 entry.set_local_id("id_foo"); | 523 entry.set_local_id("id_foo"); |
498 entry.set_base_name("foo"); | 524 entry.set_base_name("foo"); |
499 entry.set_title("foo"); | 525 entry.set_title("foo"); |
500 EXPECT_TRUE(storage_->PutEntry(entry)); | 526 EXPECT_EQ(FILE_ERROR_OK, storage_->PutEntry(entry)); |
501 | 527 |
502 // Put entry with id_bar as a id_foo's child. | 528 // Put entry with id_bar as a id_foo's child. |
503 entry.set_local_id("id_bar"); | 529 entry.set_local_id("id_bar"); |
504 entry.set_parent_local_id("id_foo"); | 530 entry.set_parent_local_id("id_foo"); |
505 entry.set_base_name("bar"); | 531 entry.set_base_name("bar"); |
506 entry.set_title("bar"); | 532 entry.set_title("bar"); |
507 EXPECT_TRUE(storage_->PutEntry(entry)); | 533 EXPECT_EQ(FILE_ERROR_OK, storage_->PutEntry(entry)); |
508 | 534 |
509 // Remove parent-child relationship to make the DB invalid. | 535 // Remove parent-child relationship to make the DB invalid. |
510 RemoveChild("id_foo", "bar"); | 536 RemoveChild("id_foo", "bar"); |
511 EXPECT_FALSE(CheckValidity()); | 537 EXPECT_FALSE(CheckValidity()); |
512 | 538 |
513 // Reopen. This should result in trashing the DB. | 539 // Reopen. This should result in trashing the DB. |
514 storage_.reset(new ResourceMetadataStorage( | 540 storage_.reset(new ResourceMetadataStorage( |
515 temp_dir_.path(), base::MessageLoopProxy::current().get())); | 541 temp_dir_.path(), base::MessageLoopProxy::current().get())); |
516 ASSERT_TRUE(storage_->Initialize()); | 542 ASSERT_TRUE(storage_->Initialize()); |
517 | 543 |
(...skipping 17 matching lines...) Expand all Loading... |
535 const std::string key3 = "boo"; | 561 const std::string key3 = "boo"; |
536 const std::string name3 = "piyo"; | 562 const std::string name3 = "piyo"; |
537 | 563 |
538 // Empty storage is valid. | 564 // Empty storage is valid. |
539 EXPECT_TRUE(CheckValidity()); | 565 EXPECT_TRUE(CheckValidity()); |
540 | 566 |
541 // Put entry with key1. | 567 // Put entry with key1. |
542 ResourceEntry entry; | 568 ResourceEntry entry; |
543 entry.set_local_id(key1); | 569 entry.set_local_id(key1); |
544 entry.set_base_name(name1); | 570 entry.set_base_name(name1); |
545 EXPECT_TRUE(storage_->PutEntry(entry)); | 571 EXPECT_EQ(FILE_ERROR_OK, storage_->PutEntry(entry)); |
546 EXPECT_TRUE(CheckValidity()); | 572 EXPECT_TRUE(CheckValidity()); |
547 | 573 |
548 // Put entry with key2 under key1. | 574 // Put entry with key2 under key1. |
549 entry.set_local_id(key2); | 575 entry.set_local_id(key2); |
550 entry.set_parent_local_id(key1); | 576 entry.set_parent_local_id(key1); |
551 entry.set_base_name(name2); | 577 entry.set_base_name(name2); |
552 EXPECT_TRUE(storage_->PutEntry(entry)); | 578 EXPECT_EQ(FILE_ERROR_OK, storage_->PutEntry(entry)); |
553 EXPECT_TRUE(CheckValidity()); | 579 EXPECT_TRUE(CheckValidity()); |
554 | 580 |
555 RemoveChild(key1, name2); | 581 RemoveChild(key1, name2); |
556 EXPECT_FALSE(CheckValidity()); // Missing parent-child relationship. | 582 EXPECT_FALSE(CheckValidity()); // Missing parent-child relationship. |
557 | 583 |
558 // Add back parent-child relationship between key1 and key2. | 584 // Add back parent-child relationship between key1 and key2. |
559 PutChild(key1, name2, key2); | 585 PutChild(key1, name2, key2); |
560 EXPECT_TRUE(CheckValidity()); | 586 EXPECT_TRUE(CheckValidity()); |
561 | 587 |
562 // Add parent-child relationship between key2 and key3. | 588 // Add parent-child relationship between key2 and key3. |
563 PutChild(key2, name3, key3); | 589 PutChild(key2, name3, key3); |
564 EXPECT_FALSE(CheckValidity()); // key3 is not stored in the storage. | 590 EXPECT_FALSE(CheckValidity()); // key3 is not stored in the storage. |
565 | 591 |
566 // Put entry with key3 under key2. | 592 // Put entry with key3 under key2. |
567 entry.set_local_id(key3); | 593 entry.set_local_id(key3); |
568 entry.set_parent_local_id(key2); | 594 entry.set_parent_local_id(key2); |
569 entry.set_base_name(name3); | 595 entry.set_base_name(name3); |
570 EXPECT_TRUE(storage_->PutEntry(entry)); | 596 EXPECT_EQ(FILE_ERROR_OK, storage_->PutEntry(entry)); |
571 EXPECT_TRUE(CheckValidity()); | 597 EXPECT_TRUE(CheckValidity()); |
572 | 598 |
573 // Parent-child relationship with wrong name. | 599 // Parent-child relationship with wrong name. |
574 RemoveChild(key2, name3); | 600 RemoveChild(key2, name3); |
575 EXPECT_FALSE(CheckValidity()); | 601 EXPECT_FALSE(CheckValidity()); |
576 PutChild(key2, name2, key3); | 602 PutChild(key2, name2, key3); |
577 EXPECT_FALSE(CheckValidity()); | 603 EXPECT_FALSE(CheckValidity()); |
578 | 604 |
579 // Fix up the relationship between key2 and key3. | 605 // Fix up the relationship between key2 and key3. |
580 RemoveChild(key2, name2); | 606 RemoveChild(key2, name2); |
581 EXPECT_FALSE(CheckValidity()); | 607 EXPECT_FALSE(CheckValidity()); |
582 PutChild(key2, name3, key3); | 608 PutChild(key2, name3, key3); |
583 EXPECT_TRUE(CheckValidity()); | 609 EXPECT_TRUE(CheckValidity()); |
584 | 610 |
585 // Add some cache entries. | 611 // Add some cache entries. |
586 FileCacheEntry cache_entry; | 612 FileCacheEntry cache_entry; |
587 EXPECT_TRUE(storage_->PutCacheEntry(key1, cache_entry)); | 613 EXPECT_EQ(FILE_ERROR_OK, storage_->PutCacheEntry(key1, cache_entry)); |
588 EXPECT_TRUE(storage_->PutCacheEntry(key2, cache_entry)); | 614 EXPECT_EQ(FILE_ERROR_OK, storage_->PutCacheEntry(key2, cache_entry)); |
589 | 615 |
590 // Remove key2. | 616 // Remove key2. |
591 RemoveChild(key1, name2); | 617 RemoveChild(key1, name2); |
592 EXPECT_FALSE(CheckValidity()); | 618 EXPECT_FALSE(CheckValidity()); |
593 EXPECT_TRUE(storage_->RemoveEntry(key2)); | 619 EXPECT_EQ(FILE_ERROR_OK, storage_->RemoveEntry(key2)); |
594 EXPECT_FALSE(CheckValidity()); | 620 EXPECT_FALSE(CheckValidity()); |
595 | 621 |
596 // Remove key3. | 622 // Remove key3. |
597 RemoveChild(key2, name3); | 623 RemoveChild(key2, name3); |
598 EXPECT_FALSE(CheckValidity()); | 624 EXPECT_FALSE(CheckValidity()); |
599 EXPECT_TRUE(storage_->RemoveEntry(key3)); | 625 EXPECT_EQ(FILE_ERROR_OK, storage_->RemoveEntry(key3)); |
600 EXPECT_TRUE(CheckValidity()); | 626 EXPECT_TRUE(CheckValidity()); |
601 | 627 |
602 // Remove key1. | 628 // Remove key1. |
603 EXPECT_TRUE(storage_->RemoveEntry(key1)); | 629 EXPECT_EQ(FILE_ERROR_OK, storage_->RemoveEntry(key1)); |
604 EXPECT_TRUE(CheckValidity()); | 630 EXPECT_TRUE(CheckValidity()); |
605 } | 631 } |
606 | 632 |
607 } // namespace internal | 633 } // namespace internal |
608 } // namespace drive | 634 } // namespace drive |
OLD | NEW |