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

Side by Side Diff: chrome/browser/chromeos/drive/resource_metadata_storage_unittest.cc

Issue 14858016: drive: Stop using callback for ResourceMetadataStorage::Iterate (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rename methods Created 7 years, 7 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 | « chrome/browser/chromeos/drive/resource_metadata_storage.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/bind.h"
10 #include "base/file_util.h" 9 #include "base/file_util.h"
11 #include "base/files/scoped_temp_dir.h" 10 #include "base/files/scoped_temp_dir.h"
12 #include "chrome/browser/chromeos/drive/drive.pb.h" 11 #include "chrome/browser/chromeos/drive/drive.pb.h"
13 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
14 #include "third_party/leveldatabase/src/include/leveldb/db.h" 13 #include "third_party/leveldatabase/src/include/leveldb/db.h"
15 14
16 namespace drive { 15 namespace drive {
17 16
18 namespace {
19
20 // Stores the entry to the map.
21 void StoreEntryToMap(std::map<std::string,ResourceEntry>* out,
22 const ResourceEntry& entry) {
23 (*out)[entry.resource_id()] = entry;
24 }
25
26 } // namespace
27
28 class ResourceMetadataStorageTest : public testing::Test { 17 class ResourceMetadataStorageTest : public testing::Test {
29 protected: 18 protected:
30 virtual void SetUp() OVERRIDE { 19 virtual void SetUp() OVERRIDE {
31 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 20 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
32 21
33 storage_.reset(new ResourceMetadataStorage(temp_dir_.path())); 22 storage_.reset(new ResourceMetadataStorage(temp_dir_.path()));
34 ASSERT_TRUE(storage_->Initialize()); 23 ASSERT_TRUE(storage_->Initialize());
35 } 24 }
36 25
37 virtual void TearDown() OVERRIDE { 26 virtual void TearDown() OVERRIDE {
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 125
137 // Remove entries. 126 // Remove entries.
138 EXPECT_TRUE(storage_->RemoveEntry(key3)); 127 EXPECT_TRUE(storage_->RemoveEntry(key3));
139 EXPECT_FALSE(storage_->GetEntry(key3)); 128 EXPECT_FALSE(storage_->GetEntry(key3));
140 EXPECT_TRUE(storage_->RemoveEntry(key2)); 129 EXPECT_TRUE(storage_->RemoveEntry(key2));
141 EXPECT_FALSE(storage_->GetEntry(key2)); 130 EXPECT_FALSE(storage_->GetEntry(key2));
142 EXPECT_TRUE(storage_->RemoveEntry(key1)); 131 EXPECT_TRUE(storage_->RemoveEntry(key1));
143 EXPECT_FALSE(storage_->GetEntry(key1)); 132 EXPECT_FALSE(storage_->GetEntry(key1));
144 } 133 }
145 134
146 TEST_F(ResourceMetadataStorageTest, Iterate) { 135 TEST_F(ResourceMetadataStorageTest, Iterator) {
147 // Prepare data. 136 // Prepare data.
148 std::vector<ResourceEntry> entries; 137 std::vector<ResourceEntry> entries;
149 ResourceEntry entry; 138 ResourceEntry entry;
150 139
151 entry.set_resource_id("entry1"); 140 entry.set_resource_id("entry1");
152 entries.push_back(entry); 141 entries.push_back(entry);
153 entry.set_resource_id("entry2"); 142 entry.set_resource_id("entry2");
154 entries.push_back(entry); 143 entries.push_back(entry);
155 entry.set_resource_id("entry3"); 144 entry.set_resource_id("entry3");
156 entries.push_back(entry); 145 entries.push_back(entry);
157 entry.set_resource_id("entry4"); 146 entry.set_resource_id("entry4");
158 entries.push_back(entry); 147 entries.push_back(entry);
159 148
160 for (size_t i = 0; i < entries.size(); ++i) 149 for (size_t i = 0; i < entries.size(); ++i)
161 EXPECT_TRUE(storage_->PutEntry(entries[i])); 150 EXPECT_TRUE(storage_->PutEntry(entries[i]));
162 151
163 // Call Iterate and check the result. 152 // Iterate and check the result.
164 std::map<std::string, ResourceEntry> result; 153 std::map<std::string, ResourceEntry> result;
165 storage_->Iterate(base::Bind(&StoreEntryToMap, base::Unretained(&result))); 154 scoped_ptr<ResourceMetadataStorage::Iterator> it = storage_->GetIterator();
155 ASSERT_TRUE(it);
156 for (; !it->IsAtEnd(); it->Advance()) {
157 const ResourceEntry& entry = it->Get();
158 result[entry.resource_id()] = entry;
159 }
160 EXPECT_FALSE(it->HasError());
166 161
167 EXPECT_EQ(entries.size(), result.size()); 162 EXPECT_EQ(entries.size(), result.size());
168 for (size_t i = 0; i < entries.size(); ++i) 163 for (size_t i = 0; i < entries.size(); ++i)
169 EXPECT_EQ(1U, result.count(entries[i].resource_id())); 164 EXPECT_EQ(1U, result.count(entries[i].resource_id()));
170 } 165 }
171 166
172 TEST_F(ResourceMetadataStorageTest, GetChildren) { 167 TEST_F(ResourceMetadataStorageTest, GetChildren) {
173 const std::string parents_id[] = { "mercury", "venus", "mars", "jupiter", 168 const std::string parents_id[] = { "mercury", "venus", "mars", "jupiter",
174 "saturn" }; 169 "saturn" };
175 std::vector<std::vector<std::pair<std::string, std::string> > > 170 std::vector<std::vector<std::pair<std::string, std::string> > >
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 EXPECT_FALSE(CheckValidity()); 348 EXPECT_FALSE(CheckValidity());
354 EXPECT_TRUE(storage_->RemoveEntry(key3)); 349 EXPECT_TRUE(storage_->RemoveEntry(key3));
355 EXPECT_TRUE(CheckValidity()); 350 EXPECT_TRUE(CheckValidity());
356 351
357 // Remove key1. 352 // Remove key1.
358 EXPECT_TRUE(storage_->RemoveEntry(key1)); 353 EXPECT_TRUE(storage_->RemoveEntry(key1));
359 EXPECT_TRUE(CheckValidity()); 354 EXPECT_TRUE(CheckValidity());
360 } 355 }
361 356
362 } // namespace drive 357 } // namespace drive
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/drive/resource_metadata_storage.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698