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 // 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 "sync/test/engine/test_syncable_utils.h" |
8 | 8 |
9 #include "sync/syncable/base_transaction.h" | 9 #include "sync/syncable/base_transaction.h" |
10 #include "sync/syncable/directory.h" | 10 #include "sync/syncable/directory.h" |
11 #include "sync/syncable/entry.h" | 11 #include "sync/syncable/entry.h" |
| 12 #include "sync/syncable/mutable_entry.h" |
| 13 #include "sync/syncable/write_transaction.h" |
| 14 #include "sync/test/engine/test_id_factory.h" |
12 | 15 |
13 using std::string; | 16 using std::string; |
14 | 17 |
15 namespace syncer { | 18 namespace syncer { |
16 namespace syncable { | 19 namespace syncable { |
17 | 20 |
18 int CountEntriesWithName(BaseTransaction* rtrans, | 21 int CountEntriesWithName(BaseTransaction* rtrans, |
19 const syncable::Id& parent_id, | 22 const syncable::Id& parent_id, |
20 const string& name) { | 23 const string& name) { |
21 Directory::ChildHandles child_handles; | 24 Directory::ChildHandles child_handles; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 return Id(); | 58 return Id(); |
56 } | 59 } |
57 | 60 |
58 Id GetOnlyEntryWithName(BaseTransaction* rtrans, | 61 Id GetOnlyEntryWithName(BaseTransaction* rtrans, |
59 const syncable::Id& parent_id, | 62 const syncable::Id& parent_id, |
60 const string& name) { | 63 const string& name) { |
61 CHECK(1 == CountEntriesWithName(rtrans, parent_id, name)); | 64 CHECK(1 == CountEntriesWithName(rtrans, parent_id, name)); |
62 return GetFirstEntryWithName(rtrans, parent_id, name); | 65 return GetFirstEntryWithName(rtrans, parent_id, name); |
63 } | 66 } |
64 | 67 |
| 68 void CreateTypeRoot(WriteTransaction* trans, |
| 69 syncable::Directory *dir, |
| 70 ModelType type) { |
| 71 std::string tag_name = syncer::ModelTypeToRootTag(type); |
| 72 syncable::MutableEntry node(trans, |
| 73 syncable::CREATE, |
| 74 TestIdFactory::root(), |
| 75 tag_name); |
| 76 DCHECK(node.good()); |
| 77 node.Put(syncable::UNIQUE_SERVER_TAG, tag_name); |
| 78 node.Put(syncable::IS_DIR, true); |
| 79 node.Put(syncable::SERVER_IS_DIR, false); |
| 80 node.Put(syncable::IS_UNSYNCED, false); |
| 81 node.Put(syncable::IS_UNAPPLIED_UPDATE, false); |
| 82 node.Put(syncable::SERVER_VERSION, 20); |
| 83 node.Put(syncable::BASE_VERSION, 20); |
| 84 node.Put(syncable::IS_DEL, false); |
| 85 node.Put(syncable::ID, syncer::TestIdFactory::MakeServer(tag_name)); |
| 86 sync_pb::EntitySpecifics specifics; |
| 87 syncer::AddDefaultFieldValue(type, &specifics); |
| 88 node.Put(syncable::SERVER_SPECIFICS, specifics); |
| 89 node.Put(syncable::SPECIFICS, specifics); |
| 90 } |
| 91 |
65 } // namespace syncable | 92 } // namespace syncable |
66 } // namespace syncer | 93 } // namespace syncer |
OLD | NEW |