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

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

Issue 2130453004: [Sync] Move //sync to //components/sync. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 4 years, 4 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
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 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 // Utilities to verify the state of items in unit tests. 5 // Utilities to verify the state of items in unit tests.
6 6
7 #include "sync/test/engine/test_syncable_utils.h" 7 #include "components/sync/test/engine/test_syncable_utils.h"
8 8
9 #include "sync/syncable/directory.h" 9 #include "components/sync/syncable/directory.h"
10 #include "sync/syncable/entry.h" 10 #include "components/sync/syncable/entry.h"
11 #include "sync/syncable/mutable_entry.h" 11 #include "components/sync/syncable/mutable_entry.h"
12 #include "sync/syncable/syncable_base_transaction.h" 12 #include "components/sync/syncable/syncable_base_transaction.h"
13 #include "sync/syncable/syncable_write_transaction.h" 13 #include "components/sync/syncable/syncable_write_transaction.h"
14 #include "sync/test/engine/test_id_factory.h" 14 #include "components/sync/test/engine/test_id_factory.h"
15 15
16 using std::string; 16 using std::string;
17 17
18 namespace syncer { 18 namespace syncer {
19 namespace syncable { 19 namespace syncable {
20 20
21 int CountEntriesWithName(BaseTransaction* rtrans, 21 int CountEntriesWithName(BaseTransaction* rtrans,
22 const syncable::Id& parent_id, 22 const syncable::Id& parent_id,
23 const string& name) { 23 const string& name) {
24 Directory::Metahandles child_handles; 24 Directory::Metahandles child_handles;
25 rtrans->directory()->GetChildHandlesById(rtrans, parent_id, &child_handles); 25 rtrans->directory()->GetChildHandlesById(rtrans, parent_id, &child_handles);
26 if (child_handles.size() <= 0) { 26 if (child_handles.size() <= 0) {
27 return 0; 27 return 0;
28 } 28 }
29 29
30 int number_of_entries_with_name = 0; 30 int number_of_entries_with_name = 0;
31 for (Directory::Metahandles::iterator i = child_handles.begin(); 31 for (Directory::Metahandles::iterator i = child_handles.begin();
32 i != child_handles.end(); ++i) { 32 i != child_handles.end(); ++i) {
33 Entry e(rtrans, GET_BY_HANDLE, *i); 33 Entry e(rtrans, GET_BY_HANDLE, *i);
34 CHECK(e.good()); 34 CHECK(e.good());
35 if (e.GetNonUniqueName()== name) { 35 if (e.GetNonUniqueName() == name) {
36 ++number_of_entries_with_name; 36 ++number_of_entries_with_name;
37 } 37 }
38 } 38 }
39 return number_of_entries_with_name; 39 return number_of_entries_with_name;
40 } 40 }
41 41
42 Id GetFirstEntryWithName(BaseTransaction* rtrans, 42 Id GetFirstEntryWithName(BaseTransaction* rtrans,
43 const syncable::Id& parent_id, 43 const syncable::Id& parent_id,
44 const string& name) { 44 const string& name) {
45 Directory::Metahandles child_handles; 45 Directory::Metahandles child_handles;
46 rtrans->directory()->GetChildHandlesById(rtrans, parent_id, &child_handles); 46 rtrans->directory()->GetChildHandlesById(rtrans, parent_id, &child_handles);
47 47
48 for (Directory::Metahandles::iterator i = child_handles.begin(); 48 for (Directory::Metahandles::iterator i = child_handles.begin();
49 i != child_handles.end(); ++i) { 49 i != child_handles.end(); ++i) {
50 Entry e(rtrans, GET_BY_HANDLE, *i); 50 Entry e(rtrans, GET_BY_HANDLE, *i);
51 CHECK(e.good()); 51 CHECK(e.good());
52 if (e.GetNonUniqueName()== name) { 52 if (e.GetNonUniqueName() == name) {
53 return e.GetId(); 53 return e.GetId();
54 } 54 }
55 } 55 }
56 56
57 CHECK(false); 57 CHECK(false);
58 return Id(); 58 return Id();
59 } 59 }
60 60
61 Id GetOnlyEntryWithName(BaseTransaction* rtrans, 61 Id GetOnlyEntryWithName(BaseTransaction* rtrans,
62 const syncable::Id& parent_id, 62 const syncable::Id& parent_id,
63 const string& name) { 63 const string& name) {
64 CHECK_EQ(1, CountEntriesWithName(rtrans, parent_id, name)); 64 CHECK_EQ(1, CountEntriesWithName(rtrans, parent_id, name));
65 return GetFirstEntryWithName(rtrans, parent_id, name); 65 return GetFirstEntryWithName(rtrans, parent_id, name);
66 } 66 }
67 67
68 void CreateTypeRoot(WriteTransaction* trans, 68 void CreateTypeRoot(WriteTransaction* trans,
69 syncable::Directory *dir, 69 syncable::Directory* dir,
70 ModelType type) { 70 ModelType type) {
71 std::string tag_name = syncer::ModelTypeToRootTag(type); 71 std::string tag_name = syncer::ModelTypeToRootTag(type);
72 syncable::MutableEntry node(trans, 72 syncable::MutableEntry node(trans, syncable::CREATE, type,
73 syncable::CREATE, 73 TestIdFactory::root(), tag_name);
74 type,
75 TestIdFactory::root(),
76 tag_name);
77 DCHECK(node.good()); 74 DCHECK(node.good());
78 node.PutUniqueServerTag(tag_name); 75 node.PutUniqueServerTag(tag_name);
79 node.PutIsDir(true); 76 node.PutIsDir(true);
80 node.PutServerIsDir(false); 77 node.PutServerIsDir(false);
81 node.PutIsUnsynced(false); 78 node.PutIsUnsynced(false);
82 node.PutIsUnappliedUpdate(false); 79 node.PutIsUnappliedUpdate(false);
83 node.PutServerVersion(20); 80 node.PutServerVersion(20);
84 node.PutBaseVersion(20); 81 node.PutBaseVersion(20);
85 node.PutIsDel(false); 82 node.PutIsDel(false);
86 node.PutId(syncer::TestIdFactory::MakeServer(tag_name)); 83 node.PutId(syncer::TestIdFactory::MakeServer(tag_name));
87 sync_pb::EntitySpecifics specifics; 84 sync_pb::EntitySpecifics specifics;
88 syncer::AddDefaultFieldValue(type, &specifics); 85 syncer::AddDefaultFieldValue(type, &specifics);
89 node.PutServerSpecifics(specifics); 86 node.PutServerSpecifics(specifics);
90 node.PutSpecifics(specifics); 87 node.PutSpecifics(specifics);
91 } 88 }
92 89
93 sync_pb::DataTypeProgressMarker BuildProgress(ModelType type) { 90 sync_pb::DataTypeProgressMarker BuildProgress(ModelType type) {
94 sync_pb::DataTypeProgressMarker progress; 91 sync_pb::DataTypeProgressMarker progress;
95 progress.set_token("token"); 92 progress.set_token("token");
96 progress.set_data_type_id(GetSpecificsFieldNumberFromModelType(type)); 93 progress.set_data_type_id(GetSpecificsFieldNumberFromModelType(type));
97 return progress; 94 return progress;
98 } 95 }
99 96
100 } // namespace syncable 97 } // namespace syncable
101 } // namespace syncer 98 } // namespace syncer
OLDNEW
« no previous file with comments | « components/sync/test/engine/test_syncable_utils.h ('k') | components/sync/test/fake_encryptor.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698