Chromium Code Reviews| Index: sync/internal_api/test/test_entry_factory.cc |
| diff --git a/sync/internal_api/test/test_entry_factory.cc b/sync/internal_api/test/test_entry_factory.cc |
| index 512fe55b9e1a288360b637318fad5fc4fdd2d10f..dcd28701d373dce6b8636466158f4e0468ac0d0f 100644 |
| --- a/sync/internal_api/test/test_entry_factory.cc |
| +++ b/sync/internal_api/test/test_entry_factory.cc |
| @@ -5,7 +5,9 @@ |
| #include "sync/internal_api/public/test/test_entry_factory.h" |
| #include "sync/syncable/directory.h" |
| +#include "sync/syncable/entry.h" |
| #include "sync/syncable/mutable_entry.h" |
| +#include "sync/syncable/read_transaction.h" |
| #include "sync/syncable/syncable_id.h" |
| #include "sync/syncable/write_transaction.h" |
| #include "sync/test/engine/test_id_factory.h" |
| @@ -42,10 +44,10 @@ void TestEntryFactory::CreateUnappliedNewItemWithParent( |
| entry.Put(syncable::SERVER_SPECIFICS, specifics); |
| } |
| -void TestEntryFactory::CreateUnappliedNewItem( |
| - const string& item_id, |
| - const sync_pb::EntitySpecifics& specifics, |
| - bool is_unique) { |
| +int64 TestEntryFactory::CreateUnappliedNewItem( |
| + const string& item_id, |
| + const sync_pb::EntitySpecifics& specifics, |
| + bool is_unique) { |
| WriteTransaction trans(FROM_HERE, UNITTEST, directory_); |
| MutableEntry entry(&trans, syncable::CREATE_NEW_UPDATE_ITEM, |
| Id::CreateFromServerId(item_id)); |
| @@ -58,6 +60,7 @@ void TestEntryFactory::CreateUnappliedNewItem( |
| entry.Put(syncable::SERVER_SPECIFICS, specifics); |
| if (is_unique) // For top-level nodes. |
| entry.Put(syncable::UNIQUE_SERVER_TAG, item_id); |
| + return entry.Get(syncable::META_HANDLE); |
| } |
| void TestEntryFactory::CreateUnsyncedItem( |
| @@ -159,6 +162,60 @@ int64 TestEntryFactory::CreateSyncedItem( |
| return entry.Get(syncable::META_HANDLE); |
| } |
| +bool TestEntryFactory::SetSpecificsForItem( |
| + int64 meta_handle, |
| + SpecificsType specifics_type, |
| + const sync_pb::EntitySpecifics specifics) { |
| + WriteTransaction trans(FROM_HERE, UNITTEST, directory_); |
| + MutableEntry entry(&trans, syncable::GET_BY_HANDLE, meta_handle); |
| + if (!entry.good()) { |
| + return false; |
| + } |
| + if (specifics_type == SERVER_SPECIFICS) { |
| + entry.Put(syncable::SERVER_SPECIFICS, specifics); |
| + entry.Put(syncable::IS_UNAPPLIED_UPDATE, true); |
| + } else { |
| + entry.Put(syncable::SPECIFICS, specifics); |
| + entry.Put(syncable::IS_UNSYNCED, true); |
| + } |
| + return true; |
| +} |
| + |
| +const sync_pb::EntitySpecifics& TestEntryFactory::GetSpecificsForItem( |
| + int64 meta_handle, |
| + SpecificsType specifics_type) const { |
| + syncable::ReadTransaction trans(FROM_HERE, directory_); |
| + syncable::Entry entry(&trans, syncable::GET_BY_HANDLE, meta_handle); |
| + if (!entry.good()) { |
|
rlarocque
2012/09/13 22:10:51
DCHECK() instead?
Nicolas Zea
2012/09/13 22:50:14
Done.
|
| + NOTREACHED(); |
| + } |
| + if (specifics_type == SERVER_SPECIFICS) { |
|
rlarocque
2012/09/13 22:10:51
Whereas the current definition allows you to reuse
Nicolas Zea
2012/09/13 22:50:14
Done (same for SetSpecificsForItem).
|
| + return entry.Get(syncable::SERVER_SPECIFICS); |
| + } else { |
| + return entry.Get(syncable::SPECIFICS); |
| + } |
| +} |
| + |
| +bool TestEntryFactory::GetIsUnsyncedForItem(int64 meta_handle) const { |
| + syncable::ReadTransaction trans(FROM_HERE, directory_); |
| + syncable::Entry entry(&trans, syncable::GET_BY_HANDLE, meta_handle); |
| + if (!entry.good()) { |
| + NOTREACHED(); |
| + return false; |
| + } |
| + return entry.Get(syncable::IS_UNSYNCED); |
| +} |
| + |
| +bool TestEntryFactory::GetIsUnappliedForItem(int64 meta_handle) const { |
| + syncable::ReadTransaction trans(FROM_HERE, directory_); |
| + syncable::Entry entry(&trans, syncable::GET_BY_HANDLE, meta_handle); |
| + if (!entry.good()) { |
| + NOTREACHED(); |
| + return false; |
| + } |
| + return entry.Get(syncable::IS_UNAPPLIED_UPDATE); |
| +} |
| + |
| int64 TestEntryFactory::GetNextRevision() { |
| return next_revision_++; |
| } |