| 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 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 entry.set_resource_id("entry2"); | 144 entry.set_resource_id("entry2"); |
| 145 entries.push_back(entry); | 145 entries.push_back(entry); |
| 146 entry.set_resource_id("entry3"); | 146 entry.set_resource_id("entry3"); |
| 147 entries.push_back(entry); | 147 entries.push_back(entry); |
| 148 entry.set_resource_id("entry4"); | 148 entry.set_resource_id("entry4"); |
| 149 entries.push_back(entry); | 149 entries.push_back(entry); |
| 150 | 150 |
| 151 for (size_t i = 0; i < entries.size(); ++i) | 151 for (size_t i = 0; i < entries.size(); ++i) |
| 152 EXPECT_TRUE(storage_->PutEntry(entries[i])); | 152 EXPECT_TRUE(storage_->PutEntry(entries[i])); |
| 153 | 153 |
| 154 // Insert some dummy cache entries. | 154 // Insert some cache entries. |
| 155 FileCacheEntry cache_entry; | 155 std::map<std::string, FileCacheEntry> cache_entries; |
| 156 EXPECT_TRUE(storage_->PutCacheEntry(entries[0].resource_id(), cache_entry)); | 156 cache_entries[entries[0].resource_id()].set_md5("aaaaaa"); |
| 157 EXPECT_TRUE(storage_->PutCacheEntry(entries[1].resource_id(), cache_entry)); | 157 cache_entries[entries[1].resource_id()].set_md5("bbbbbb"); |
| 158 for (std::map<std::string, FileCacheEntry>::iterator it = |
| 159 cache_entries.begin(); it != cache_entries.end(); ++it) |
| 160 EXPECT_TRUE(storage_->PutCacheEntry(it->first, it->second)); |
| 158 | 161 |
| 159 // Iterate and check the result. | 162 // Iterate and check the result. |
| 160 std::map<std::string, ResourceEntry> result; | 163 std::map<std::string, ResourceEntry> found_entries; |
| 164 std::map<std::string, FileCacheEntry> found_cache_entries; |
| 161 scoped_ptr<ResourceMetadataStorage::Iterator> it = storage_->GetIterator(); | 165 scoped_ptr<ResourceMetadataStorage::Iterator> it = storage_->GetIterator(); |
| 162 ASSERT_TRUE(it); | 166 ASSERT_TRUE(it); |
| 163 for (; !it->IsAtEnd(); it->Advance()) { | 167 for (; !it->IsAtEnd(); it->Advance()) { |
| 164 const ResourceEntry& entry = it->Get(); | 168 const ResourceEntry& entry = it->Get(); |
| 165 result[entry.resource_id()] = entry; | 169 found_entries[entry.resource_id()] = entry; |
| 170 |
| 171 FileCacheEntry cache_entry; |
| 172 if (it->GetCacheEntry(&cache_entry)) |
| 173 found_cache_entries[entry.resource_id()] = cache_entry; |
| 166 } | 174 } |
| 167 EXPECT_FALSE(it->HasError()); | 175 EXPECT_FALSE(it->HasError()); |
| 168 | 176 |
| 169 EXPECT_EQ(entries.size(), result.size()); | 177 EXPECT_EQ(entries.size(), found_entries.size()); |
| 170 for (size_t i = 0; i < entries.size(); ++i) | 178 for (size_t i = 0; i < entries.size(); ++i) |
| 171 EXPECT_EQ(1U, result.count(entries[i].resource_id())); | 179 EXPECT_EQ(1U, found_entries.count(entries[i].resource_id())); |
| 180 |
| 181 EXPECT_EQ(cache_entries.size(), found_cache_entries.size()); |
| 182 for (std::map<std::string, FileCacheEntry>::iterator it = |
| 183 cache_entries.begin(); it != cache_entries.end(); ++it) { |
| 184 ASSERT_EQ(1U, found_cache_entries.count(it->first)); |
| 185 EXPECT_EQ(it->second.md5(), found_cache_entries[it->first].md5()); |
| 186 } |
| 172 } | 187 } |
| 173 | 188 |
| 174 TEST_F(ResourceMetadataStorageTest, PutCacheEntry) { | 189 TEST_F(ResourceMetadataStorageTest, PutCacheEntry) { |
| 175 FileCacheEntry entry; | 190 FileCacheEntry entry; |
| 176 const std::string key1 = "abcdefg"; | 191 const std::string key1 = "abcdefg"; |
| 177 const std::string key2 = "abcd"; | 192 const std::string key2 = "abcd"; |
| 178 const std::string md5_1 = "foo"; | 193 const std::string md5_1 = "foo"; |
| 179 const std::string md5_2 = "bar"; | 194 const std::string md5_2 = "bar"; |
| 180 | 195 |
| 181 // Put cache entries. | 196 // Put cache entries. |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 435 EXPECT_TRUE(storage_->RemoveEntry(key3)); | 450 EXPECT_TRUE(storage_->RemoveEntry(key3)); |
| 436 EXPECT_TRUE(CheckValidity()); | 451 EXPECT_TRUE(CheckValidity()); |
| 437 | 452 |
| 438 // Remove key1. | 453 // Remove key1. |
| 439 EXPECT_TRUE(storage_->RemoveEntry(key1)); | 454 EXPECT_TRUE(storage_->RemoveEntry(key1)); |
| 440 EXPECT_TRUE(CheckValidity()); | 455 EXPECT_TRUE(CheckValidity()); |
| 441 } | 456 } |
| 442 | 457 |
| 443 } // namespace internal | 458 } // namespace internal |
| 444 } // namespace drive | 459 } // namespace drive |
| OLD | NEW |