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

Side by Side Diff: chrome/browser/sync/syncable/syncable_unittest.cc

Issue 8396022: [Sync] Add HasChildren() function and use it instead of GetFirstChildId() (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments Created 9 years, 1 month 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/sync/syncable/syncable.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 (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/sync/syncable/syncable.h" 5 #include "chrome/browser/sync/syncable/syncable.h"
6 6
7 #include "build/build_config.h" 7 #include "build/build_config.h"
8 8
9 #include <sys/types.h> 9 #include <sys/types.h>
10 10
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 WriteTransaction trans(FROM_HERE, UNITTEST, &dir); 200 WriteTransaction trans(FROM_HERE, UNITTEST, &dir);
201 MutableEntry e(&trans, GET_BY_HANDLE, written_metahandle); 201 MutableEntry e(&trans, GET_BY_HANDLE, written_metahandle);
202 e.Put(IS_DEL, true); 202 e.Put(IS_DEL, true);
203 203
204 EXPECT_EQ(0, CountEntriesWithName(&trans, trans.root_id(), name)); 204 EXPECT_EQ(0, CountEntriesWithName(&trans, trans.root_id(), name));
205 } 205 }
206 206
207 dir.SaveChanges(); 207 dir.SaveChanges();
208 } 208 }
209 209
210 TEST_F(SyncableGeneralTest, ChildrenOps) {
211 Directory dir;
212 dir.Open(db_path_, "SimpleTest", &delegate_);
213
214 int64 root_metahandle;
215 {
216 ReadTransaction rtrans(FROM_HERE, &dir);
217 Entry e(&rtrans, GET_BY_ID, rtrans.root_id());
218 ASSERT_TRUE(e.good());
219 root_metahandle = e.Get(META_HANDLE);
220 }
221
222 int64 written_metahandle;
223 const Id id = TestIdFactory::FromNumber(99);
224 std::string name = "Jeff";
225 {
226 ReadTransaction rtrans(FROM_HERE, &dir);
227 Entry e(&rtrans, GET_BY_ID, id);
228 ASSERT_FALSE(e.good()); // Hasn't been written yet.
229
230 EXPECT_FALSE(dir.HasChildren(&rtrans, rtrans.root_id()));
231 EXPECT_TRUE(dir.GetFirstChildId(&rtrans, rtrans.root_id()).IsRoot());
232 }
233
234 {
235 WriteTransaction wtrans(FROM_HERE, UNITTEST, &dir);
236 MutableEntry me(&wtrans, CREATE, wtrans.root_id(), name);
237 ASSERT_TRUE(me.good());
238 me.Put(ID, id);
239 me.Put(BASE_VERSION, 1);
240 written_metahandle = me.Get(META_HANDLE);
241 }
242
243 // Test children ops after something is now in the DB.
244 {
245 ReadTransaction rtrans(FROM_HERE, &dir);
246 Entry e(&rtrans, GET_BY_ID, id);
247 ASSERT_TRUE(e.good());
248
249 Entry child(&rtrans, GET_BY_HANDLE, written_metahandle);
250 ASSERT_TRUE(child.good());
251
252 EXPECT_TRUE(dir.HasChildren(&rtrans, rtrans.root_id()));
253 EXPECT_EQ(e.Get(ID), dir.GetFirstChildId(&rtrans, rtrans.root_id()));
254 }
255
256 {
257 WriteTransaction wtrans(FROM_HERE, UNITTEST, &dir);
258 MutableEntry me(&wtrans, GET_BY_HANDLE, written_metahandle);
259 ASSERT_TRUE(me.good());
260 me.Put(IS_DEL, true);
261 }
262
263 // Test children ops after the children have been deleted.
264 {
265 ReadTransaction rtrans(FROM_HERE, &dir);
266 Entry e(&rtrans, GET_BY_ID, id);
267 ASSERT_TRUE(e.good());
268
269 EXPECT_FALSE(dir.HasChildren(&rtrans, rtrans.root_id()));
270 EXPECT_TRUE(dir.GetFirstChildId(&rtrans, rtrans.root_id()).IsRoot());
271 }
272
273 dir.SaveChanges();
274 }
275
210 TEST_F(SyncableGeneralTest, ClientIndexRebuildsProperly) { 276 TEST_F(SyncableGeneralTest, ClientIndexRebuildsProperly) {
211 int64 written_metahandle; 277 int64 written_metahandle;
212 TestIdFactory factory; 278 TestIdFactory factory;
213 const Id id = factory.NewServerId(); 279 const Id id = factory.NewServerId();
214 std::string name = "cheesepuffs"; 280 std::string name = "cheesepuffs";
215 std::string tag = "dietcoke"; 281 std::string tag = "dietcoke";
216 282
217 // Test creating a new meta entry. 283 // Test creating a new meta entry.
218 { 284 {
219 Directory dir; 285 Directory dir;
(...skipping 1595 matching lines...) Expand 10 before | Expand all | Expand 10 after
1815 TEST_F(SyncableClientTagTest, TestClientTagIndexDuplicateServer) { 1881 TEST_F(SyncableClientTagTest, TestClientTagIndexDuplicateServer) {
1816 EXPECT_TRUE(CreateWithDefaultTag(factory_.NewServerId(), true)); 1882 EXPECT_TRUE(CreateWithDefaultTag(factory_.NewServerId(), true));
1817 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewServerId(), true)); 1883 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewServerId(), true));
1818 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewServerId(), false)); 1884 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewServerId(), false));
1819 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewLocalId(), false)); 1885 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewLocalId(), false));
1820 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewLocalId(), true)); 1886 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewLocalId(), true));
1821 } 1887 }
1822 1888
1823 } // namespace 1889 } // namespace
1824 } // namespace syncable 1890 } // namespace syncable
OLDNEW
« no previous file with comments | « chrome/browser/sync/syncable/syncable.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698