OLD | NEW |
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 #include "sync/internal_api/public/test/test_entry_factory.h" | 5 #include "components/sync/core/test/test_entry_factory.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.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_id.h" | 12 #include "components/sync/syncable/syncable_id.h" |
13 #include "sync/syncable/syncable_read_transaction.h" | 13 #include "components/sync/syncable/syncable_read_transaction.h" |
14 #include "sync/syncable/syncable_util.h" | 14 #include "components/sync/syncable/syncable_util.h" |
15 #include "sync/syncable/syncable_write_transaction.h" | 15 #include "components/sync/syncable/syncable_write_transaction.h" |
16 #include "sync/test/engine/test_id_factory.h" | 16 #include "components/sync/test/engine/test_id_factory.h" |
17 | 17 |
18 using std::string; | 18 using std::string; |
19 | 19 |
20 namespace syncer { | 20 namespace syncer { |
21 | 21 |
22 using syncable::Id; | 22 using syncable::Id; |
23 using syncable::MutableEntry; | 23 using syncable::MutableEntry; |
24 using syncable::UNITTEST; | 24 using syncable::UNITTEST; |
25 using syncable::WriteTransaction; | 25 using syncable::WriteTransaction; |
26 | 26 |
27 TestEntryFactory::TestEntryFactory(syncable::Directory *dir) | 27 TestEntryFactory::TestEntryFactory(syncable::Directory* dir) |
28 : directory_(dir), next_revision_(1) { | 28 : directory_(dir), next_revision_(1) {} |
29 } | |
30 | 29 |
31 TestEntryFactory::~TestEntryFactory() { } | 30 TestEntryFactory::~TestEntryFactory() {} |
32 | 31 |
33 int64_t TestEntryFactory::CreateUnappliedNewItemWithParent( | 32 int64_t TestEntryFactory::CreateUnappliedNewItemWithParent( |
34 const string& item_id, | 33 const string& item_id, |
35 const sync_pb::EntitySpecifics& specifics, | 34 const sync_pb::EntitySpecifics& specifics, |
36 const string& parent_id) { | 35 const string& parent_id) { |
37 WriteTransaction trans(FROM_HERE, UNITTEST, directory_); | 36 WriteTransaction trans(FROM_HERE, UNITTEST, directory_); |
38 MutableEntry entry(&trans, syncable::CREATE_NEW_UPDATE_ITEM, | 37 MutableEntry entry(&trans, syncable::CREATE_NEW_UPDATE_ITEM, |
39 Id::CreateFromServerId(item_id)); | 38 Id::CreateFromServerId(item_id)); |
40 DCHECK(entry.good()); | 39 DCHECK(entry.good()); |
41 entry.PutServerVersion(GetNextRevision()); | 40 entry.PutServerVersion(GetNextRevision()); |
42 entry.PutIsUnappliedUpdate(true); | 41 entry.PutIsUnappliedUpdate(true); |
43 | 42 |
44 entry.PutServerNonUniqueName(item_id); | 43 entry.PutServerNonUniqueName(item_id); |
45 entry.PutServerParentId(Id::CreateFromServerId(parent_id)); | 44 entry.PutServerParentId(Id::CreateFromServerId(parent_id)); |
46 entry.PutServerIsDir(true); | 45 entry.PutServerIsDir(true); |
47 entry.PutServerSpecifics(specifics); | 46 entry.PutServerSpecifics(specifics); |
48 return entry.GetMetahandle(); | 47 return entry.GetMetahandle(); |
49 } | 48 } |
50 | 49 |
51 int64_t TestEntryFactory::CreateUnappliedNewBookmarkItemWithParent( | 50 int64_t TestEntryFactory::CreateUnappliedNewBookmarkItemWithParent( |
52 const string& item_id, | 51 const string& item_id, |
53 const sync_pb::EntitySpecifics& specifics, | 52 const sync_pb::EntitySpecifics& specifics, |
54 const string& parent_id) { | 53 const string& parent_id) { |
55 WriteTransaction trans(FROM_HERE, UNITTEST, directory_); | 54 WriteTransaction trans(FROM_HERE, UNITTEST, directory_); |
56 MutableEntry entry(&trans, syncable::CREATE_NEW_UPDATE_ITEM, | 55 MutableEntry entry(&trans, syncable::CREATE_NEW_UPDATE_ITEM, |
57 Id::CreateFromServerId(item_id)); | 56 Id::CreateFromServerId(item_id)); |
58 DCHECK(entry.good()); | 57 DCHECK(entry.good()); |
59 entry.PutServerVersion(GetNextRevision()); | 58 entry.PutServerVersion(GetNextRevision()); |
60 entry.PutIsUnappliedUpdate(true); | 59 entry.PutIsUnappliedUpdate(true); |
61 | 60 |
62 entry.PutServerNonUniqueName(item_id); | 61 entry.PutServerNonUniqueName(item_id); |
63 entry.PutServerParentId(Id::CreateFromServerId(parent_id)); | 62 entry.PutServerParentId(Id::CreateFromServerId(parent_id)); |
64 entry.PutServerIsDir(true); | 63 entry.PutServerIsDir(true); |
65 entry.PutServerSpecifics(specifics); | 64 entry.PutServerSpecifics(specifics); |
66 | 65 |
67 return entry.GetMetahandle(); | 66 return entry.GetMetahandle(); |
68 } | 67 } |
69 | 68 |
70 int64_t TestEntryFactory::CreateUnappliedNewItem( | 69 int64_t TestEntryFactory::CreateUnappliedNewItem( |
71 const string& item_id, | 70 const string& item_id, |
72 const sync_pb::EntitySpecifics& specifics, | 71 const sync_pb::EntitySpecifics& specifics, |
73 bool is_unique) { | 72 bool is_unique) { |
74 WriteTransaction trans(FROM_HERE, UNITTEST, directory_); | 73 WriteTransaction trans(FROM_HERE, UNITTEST, directory_); |
75 MutableEntry entry(&trans, syncable::CREATE_NEW_UPDATE_ITEM, | 74 MutableEntry entry(&trans, syncable::CREATE_NEW_UPDATE_ITEM, |
76 Id::CreateFromServerId(item_id)); | 75 Id::CreateFromServerId(item_id)); |
77 DCHECK(entry.good()); | 76 DCHECK(entry.good()); |
78 entry.PutServerVersion(GetNextRevision()); | 77 entry.PutServerVersion(GetNextRevision()); |
79 entry.PutIsUnappliedUpdate(true); | 78 entry.PutIsUnappliedUpdate(true); |
80 entry.PutServerNonUniqueName(item_id); | 79 entry.PutServerNonUniqueName(item_id); |
81 entry.PutServerParentId(syncable::Id::GetRoot()); | 80 entry.PutServerParentId(syncable::Id::GetRoot()); |
82 entry.PutServerIsDir(is_unique); | 81 entry.PutServerIsDir(is_unique); |
83 entry.PutServerSpecifics(specifics); | 82 entry.PutServerSpecifics(specifics); |
84 if (is_unique) { // For top-level nodes. | 83 if (is_unique) { // For top-level nodes. |
85 entry.PutUniqueServerTag( | 84 entry.PutUniqueServerTag( |
86 ModelTypeToRootTag(GetModelTypeFromSpecifics(specifics))); | 85 ModelTypeToRootTag(GetModelTypeFromSpecifics(specifics))); |
87 } | 86 } |
88 return entry.GetMetahandle(); | 87 return entry.GetMetahandle(); |
89 } | 88 } |
90 | 89 |
91 void TestEntryFactory::CreateUnsyncedItem(const Id& item_id, | 90 void TestEntryFactory::CreateUnsyncedItem(const Id& item_id, |
92 const Id& parent_id, | 91 const Id& parent_id, |
93 const string& name, | 92 const string& name, |
94 bool is_folder, | 93 bool is_folder, |
95 ModelType model_type, | 94 ModelType model_type, |
96 int64_t* metahandle_out) { | 95 int64_t* metahandle_out) { |
97 if (is_folder) { | 96 if (is_folder) { |
98 DCHECK_EQ(model_type, BOOKMARKS); | 97 DCHECK_EQ(model_type, BOOKMARKS); |
99 } | 98 } |
100 | 99 |
101 WriteTransaction trans(FROM_HERE, UNITTEST, directory_); | 100 WriteTransaction trans(FROM_HERE, UNITTEST, directory_); |
102 | 101 |
103 MutableEntry entry(&trans, syncable::CREATE, model_type, parent_id, name); | 102 MutableEntry entry(&trans, syncable::CREATE, model_type, parent_id, name); |
104 DCHECK(entry.good()); | 103 DCHECK(entry.good()); |
105 entry.PutId(item_id); | 104 entry.PutId(item_id); |
106 entry.PutBaseVersion( | 105 entry.PutBaseVersion(item_id.ServerKnows() ? GetNextRevision() : 0); |
107 item_id.ServerKnows() ? GetNextRevision() : 0); | |
108 entry.PutIsUnsynced(true); | 106 entry.PutIsUnsynced(true); |
109 entry.PutIsDir(is_folder); | 107 entry.PutIsDir(is_folder); |
110 entry.PutIsDel(false); | 108 entry.PutIsDel(false); |
111 entry.PutParentId(parent_id); | 109 entry.PutParentId(parent_id); |
112 sync_pb::EntitySpecifics default_specifics; | 110 sync_pb::EntitySpecifics default_specifics; |
113 AddDefaultFieldValue(model_type, &default_specifics); | 111 AddDefaultFieldValue(model_type, &default_specifics); |
114 entry.PutSpecifics(default_specifics); | 112 entry.PutSpecifics(default_specifics); |
115 | 113 |
116 if (item_id.ServerKnows()) { | 114 if (item_id.ServerKnows()) { |
117 entry.PutServerSpecifics(default_specifics); | 115 entry.PutServerSpecifics(default_specifics); |
118 entry.PutServerIsDir(false); | 116 entry.PutServerIsDir(false); |
119 entry.PutServerParentId(parent_id); | 117 entry.PutServerParentId(parent_id); |
120 entry.PutServerIsDel(false); | 118 entry.PutServerIsDel(false); |
121 } | 119 } |
122 if (metahandle_out) | 120 if (metahandle_out) |
123 *metahandle_out = entry.GetMetahandle(); | 121 *metahandle_out = entry.GetMetahandle(); |
124 } | 122 } |
125 | 123 |
126 int64_t TestEntryFactory::CreateUnappliedAndUnsyncedBookmarkItem( | 124 int64_t TestEntryFactory::CreateUnappliedAndUnsyncedBookmarkItem( |
127 const string& name) { | 125 const string& name) { |
128 int64_t metahandle = 0; | 126 int64_t metahandle = 0; |
129 CreateUnsyncedItem( | 127 CreateUnsyncedItem(TestIdFactory::MakeServer(name), TestIdFactory::root(), |
130 TestIdFactory::MakeServer(name), TestIdFactory::root(), | 128 name, false, BOOKMARKS, &metahandle); |
131 name, false, BOOKMARKS, &metahandle); | |
132 | 129 |
133 WriteTransaction trans(FROM_HERE, UNITTEST, directory_); | 130 WriteTransaction trans(FROM_HERE, UNITTEST, directory_); |
134 MutableEntry entry(&trans, syncable::GET_BY_HANDLE, metahandle); | 131 MutableEntry entry(&trans, syncable::GET_BY_HANDLE, metahandle); |
135 if (!entry.good()) { | 132 if (!entry.good()) { |
136 NOTREACHED(); | 133 NOTREACHED(); |
137 return syncable::kInvalidMetaHandle; | 134 return syncable::kInvalidMetaHandle; |
138 } | 135 } |
139 | 136 |
140 entry.PutIsUnappliedUpdate(true); | 137 entry.PutIsUnappliedUpdate(true); |
141 entry.PutServerVersion(GetNextRevision()); | 138 entry.PutServerVersion(GetNextRevision()); |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
301 return false; | 298 return false; |
302 } | 299 } |
303 return entry.GetIsUnappliedUpdate(); | 300 return entry.GetIsUnappliedUpdate(); |
304 } | 301 } |
305 | 302 |
306 int64_t TestEntryFactory::GetNextRevision() { | 303 int64_t TestEntryFactory::GetNextRevision() { |
307 return next_revision_++; | 304 return next_revision_++; |
308 } | 305 } |
309 | 306 |
310 } // namespace syncer | 307 } // namespace syncer |
OLD | NEW |