| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 "sync/internal_api/public/test/test_entry_factory.h" |
| 6 | 6 |
| 7 #include "sync/syncable/directory.h" | 7 #include "sync/syncable/directory.h" |
| 8 #include "sync/syncable/entry.h" |
| 8 #include "sync/syncable/mutable_entry.h" | 9 #include "sync/syncable/mutable_entry.h" |
| 10 #include "sync/syncable/read_transaction.h" |
| 9 #include "sync/syncable/syncable_id.h" | 11 #include "sync/syncable/syncable_id.h" |
| 10 #include "sync/syncable/write_transaction.h" | 12 #include "sync/syncable/write_transaction.h" |
| 11 #include "sync/test/engine/test_id_factory.h" | 13 #include "sync/test/engine/test_id_factory.h" |
| 12 | 14 |
| 13 using std::string; | 15 using std::string; |
| 14 | 16 |
| 15 namespace syncer { | 17 namespace syncer { |
| 16 | 18 |
| 17 using syncable::Id; | 19 using syncable::Id; |
| 18 using syncable::MutableEntry; | 20 using syncable::MutableEntry; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 35 DCHECK(entry.good()); | 37 DCHECK(entry.good()); |
| 36 entry.Put(syncable::SERVER_VERSION, GetNextRevision()); | 38 entry.Put(syncable::SERVER_VERSION, GetNextRevision()); |
| 37 entry.Put(syncable::IS_UNAPPLIED_UPDATE, true); | 39 entry.Put(syncable::IS_UNAPPLIED_UPDATE, true); |
| 38 | 40 |
| 39 entry.Put(syncable::SERVER_NON_UNIQUE_NAME, item_id); | 41 entry.Put(syncable::SERVER_NON_UNIQUE_NAME, item_id); |
| 40 entry.Put(syncable::SERVER_PARENT_ID, Id::CreateFromServerId(parent_id)); | 42 entry.Put(syncable::SERVER_PARENT_ID, Id::CreateFromServerId(parent_id)); |
| 41 entry.Put(syncable::SERVER_IS_DIR, true); | 43 entry.Put(syncable::SERVER_IS_DIR, true); |
| 42 entry.Put(syncable::SERVER_SPECIFICS, specifics); | 44 entry.Put(syncable::SERVER_SPECIFICS, specifics); |
| 43 } | 45 } |
| 44 | 46 |
| 45 void TestEntryFactory::CreateUnappliedNewItem( | 47 int64 TestEntryFactory::CreateUnappliedNewItem( |
| 46 const string& item_id, | 48 const string& item_id, |
| 47 const sync_pb::EntitySpecifics& specifics, | 49 const sync_pb::EntitySpecifics& specifics, |
| 48 bool is_unique) { | 50 bool is_unique) { |
| 49 WriteTransaction trans(FROM_HERE, UNITTEST, directory_); | 51 WriteTransaction trans(FROM_HERE, UNITTEST, directory_); |
| 50 MutableEntry entry(&trans, syncable::CREATE_NEW_UPDATE_ITEM, | 52 MutableEntry entry(&trans, syncable::CREATE_NEW_UPDATE_ITEM, |
| 51 Id::CreateFromServerId(item_id)); | 53 Id::CreateFromServerId(item_id)); |
| 52 DCHECK(entry.good()); | 54 DCHECK(entry.good()); |
| 53 entry.Put(syncable::SERVER_VERSION, GetNextRevision()); | 55 entry.Put(syncable::SERVER_VERSION, GetNextRevision()); |
| 54 entry.Put(syncable::IS_UNAPPLIED_UPDATE, true); | 56 entry.Put(syncable::IS_UNAPPLIED_UPDATE, true); |
| 55 entry.Put(syncable::SERVER_NON_UNIQUE_NAME, item_id); | 57 entry.Put(syncable::SERVER_NON_UNIQUE_NAME, item_id); |
| 56 entry.Put(syncable::SERVER_PARENT_ID, syncable::GetNullId()); | 58 entry.Put(syncable::SERVER_PARENT_ID, syncable::GetNullId()); |
| 57 entry.Put(syncable::SERVER_IS_DIR, false); | 59 entry.Put(syncable::SERVER_IS_DIR, false); |
| 58 entry.Put(syncable::SERVER_SPECIFICS, specifics); | 60 entry.Put(syncable::SERVER_SPECIFICS, specifics); |
| 59 if (is_unique) // For top-level nodes. | 61 if (is_unique) // For top-level nodes. |
| 60 entry.Put(syncable::UNIQUE_SERVER_TAG, item_id); | 62 entry.Put(syncable::UNIQUE_SERVER_TAG, item_id); |
| 63 return entry.Get(syncable::META_HANDLE); |
| 61 } | 64 } |
| 62 | 65 |
| 63 void TestEntryFactory::CreateUnsyncedItem( | 66 void TestEntryFactory::CreateUnsyncedItem( |
| 64 const Id& item_id, | 67 const Id& item_id, |
| 65 const Id& parent_id, | 68 const Id& parent_id, |
| 66 const string& name, | 69 const string& name, |
| 67 bool is_folder, | 70 bool is_folder, |
| 68 ModelType model_type, | 71 ModelType model_type, |
| 69 int64* metahandle_out) { | 72 int64* metahandle_out) { |
| 70 WriteTransaction trans(FROM_HERE, UNITTEST, directory_); | 73 WriteTransaction trans(FROM_HERE, UNITTEST, directory_); |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 entry.Put(syncable::SERVER_NON_UNIQUE_NAME, "X"); | 155 entry.Put(syncable::SERVER_NON_UNIQUE_NAME, "X"); |
| 153 entry.Put(syncable::SERVER_PARENT_ID, TestIdFactory::MakeServer("Y")); | 156 entry.Put(syncable::SERVER_PARENT_ID, TestIdFactory::MakeServer("Y")); |
| 154 entry.Put(syncable::SERVER_IS_DIR, is_folder); | 157 entry.Put(syncable::SERVER_IS_DIR, is_folder); |
| 155 entry.Put(syncable::SERVER_IS_DEL, false); | 158 entry.Put(syncable::SERVER_IS_DEL, false); |
| 156 entry.Put(syncable::SERVER_SPECIFICS, default_specifics); | 159 entry.Put(syncable::SERVER_SPECIFICS, default_specifics); |
| 157 entry.Put(syncable::SERVER_PARENT_ID, parent_id); | 160 entry.Put(syncable::SERVER_PARENT_ID, parent_id); |
| 158 | 161 |
| 159 return entry.Get(syncable::META_HANDLE); | 162 return entry.Get(syncable::META_HANDLE); |
| 160 } | 163 } |
| 161 | 164 |
| 165 bool TestEntryFactory::SetServerSpecificsForItem( |
| 166 int64 meta_handle, |
| 167 const sync_pb::EntitySpecifics specifics) { |
| 168 WriteTransaction trans(FROM_HERE, UNITTEST, directory_); |
| 169 MutableEntry entry(&trans, syncable::GET_BY_HANDLE, meta_handle); |
| 170 if (!entry.good()) { |
| 171 return false; |
| 172 } |
| 173 entry.Put(syncable::SERVER_SPECIFICS, specifics); |
| 174 entry.Put(syncable::IS_UNAPPLIED_UPDATE, true); |
| 175 return true; |
| 176 } |
| 177 |
| 178 bool TestEntryFactory::SetLocalSpecificsForItem( |
| 179 int64 meta_handle, |
| 180 const sync_pb::EntitySpecifics specifics) { |
| 181 WriteTransaction trans(FROM_HERE, UNITTEST, directory_); |
| 182 MutableEntry entry(&trans, syncable::GET_BY_HANDLE, meta_handle); |
| 183 if (!entry.good()) { |
| 184 return false; |
| 185 } |
| 186 entry.Put(syncable::SPECIFICS, specifics); |
| 187 entry.Put(syncable::IS_UNSYNCED, true); |
| 188 return true; |
| 189 } |
| 190 |
| 191 const sync_pb::EntitySpecifics& TestEntryFactory::GetServerSpecificsForItem( |
| 192 int64 meta_handle) const { |
| 193 syncable::ReadTransaction trans(FROM_HERE, directory_); |
| 194 syncable::Entry entry(&trans, syncable::GET_BY_HANDLE, meta_handle); |
| 195 DCHECK(entry.good()); |
| 196 return entry.Get(syncable::SERVER_SPECIFICS); |
| 197 } |
| 198 |
| 199 const sync_pb::EntitySpecifics& TestEntryFactory::GetLocalSpecificsForItem( |
| 200 int64 meta_handle) const { |
| 201 syncable::ReadTransaction trans(FROM_HERE, directory_); |
| 202 syncable::Entry entry(&trans, syncable::GET_BY_HANDLE, meta_handle); |
| 203 DCHECK(entry.good()); |
| 204 return entry.Get(syncable::SPECIFICS); |
| 205 } |
| 206 |
| 207 bool TestEntryFactory::GetIsUnsyncedForItem(int64 meta_handle) const { |
| 208 syncable::ReadTransaction trans(FROM_HERE, directory_); |
| 209 syncable::Entry entry(&trans, syncable::GET_BY_HANDLE, meta_handle); |
| 210 if (!entry.good()) { |
| 211 NOTREACHED(); |
| 212 return false; |
| 213 } |
| 214 return entry.Get(syncable::IS_UNSYNCED); |
| 215 } |
| 216 |
| 217 bool TestEntryFactory::GetIsUnappliedForItem(int64 meta_handle) const { |
| 218 syncable::ReadTransaction trans(FROM_HERE, directory_); |
| 219 syncable::Entry entry(&trans, syncable::GET_BY_HANDLE, meta_handle); |
| 220 if (!entry.good()) { |
| 221 NOTREACHED(); |
| 222 return false; |
| 223 } |
| 224 return entry.Get(syncable::IS_UNAPPLIED_UPDATE); |
| 225 } |
| 226 |
| 162 int64 TestEntryFactory::GetNextRevision() { | 227 int64 TestEntryFactory::GetNextRevision() { |
| 163 return next_revision_++; | 228 return next_revision_++; |
| 164 } | 229 } |
| 165 | 230 |
| 166 } // namespace syncer | 231 } // namespace syncer |
| OLD | NEW |