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

Side by Side Diff: chrome/test/sync/engine/test_syncable_utils.cc

Issue 371029: Remove unique naming. (Closed)
Patch Set: Ready and about to go in! Created 11 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
« no previous file with comments | « chrome/test/sync/engine/test_syncable_utils.h ('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
(Empty)
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 // Utilities to verify the state of items in unit tests.
6
7 #include "chrome/test/sync/engine/test_syncable_utils.h"
8
9 #include "chrome/browser/sync/syncable/syncable.h"
10
11 namespace syncable {
12
13 int CountEntriesWithName(BaseTransaction* rtrans,
14 const syncable::Id& parent_id,
15 const PathString& name) {
16 Directory::ChildHandles child_handles;
17 rtrans->directory()->GetChildHandles(rtrans, parent_id, &child_handles);
18 if (child_handles.size() <= 0) {
19 return 0;
20 }
21
22 int number_of_entries_with_name = 0;
23 for (Directory::ChildHandles::iterator i = child_handles.begin();
24 i != child_handles.end(); ++i) {
25 Entry e(rtrans, GET_BY_HANDLE, *i);
26 CHECK(e.good());
27 if (e.Get(NON_UNIQUE_NAME) == name) {
28 ++number_of_entries_with_name;
29 }
30 }
31 return number_of_entries_with_name;
32 }
33
34 Id GetFirstEntryWithName(BaseTransaction* rtrans,
35 const syncable::Id& parent_id,
36 const PathString& name) {
37 Directory::ChildHandles child_handles;
38 rtrans->directory()->GetChildHandles(rtrans, parent_id, &child_handles);
39
40 for (Directory::ChildHandles::iterator i = child_handles.begin();
41 i != child_handles.end(); ++i) {
42 Entry e(rtrans, GET_BY_HANDLE, *i);
43 CHECK(e.good());
44 if (e.Get(NON_UNIQUE_NAME) == name) {
45 return e.Get(ID);
46 }
47 }
48
49 CHECK(false);
50 return Id();
51 }
52
53 Id GetOnlyEntryWithName(BaseTransaction* rtrans,
54 const syncable::Id& parent_id,
55 const PathString& name) {
56 CHECK(1 == CountEntriesWithName(rtrans, parent_id, name));
57 return GetFirstEntryWithName(rtrans, parent_id, name);
58 }
59
60 } // namespace syncable
OLDNEW
« no previous file with comments | « chrome/test/sync/engine/test_syncable_utils.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698