OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 // Utilities to verify the state of items in unit tests. |
| 6 |
| 7 #include "chrome/test/sync/engine/test_syncable_utils.h" |
| 8 |
| 9 #include "chrome/browser/sync/syncable/syncable.h" |
| 10 |
| 11 namespace syncable { |
| 12 |
| 13 int CountEntriesWithName(BaseTransaction* rtrans, |
| 14 const syncable::Id& parent_id, |
| 15 const PathString& name) { |
| 16 Directory::ChildHandles child_handles; |
| 17 rtrans->directory()->GetChildHandles(rtrans, parent_id, &child_handles); |
| 18 if (child_handles.size() <= 0) { |
| 19 return 0; |
| 20 } |
| 21 |
| 22 int number_of_entries_with_name = 0; |
| 23 for (Directory::ChildHandles::iterator i = child_handles.begin(); |
| 24 i != child_handles.end(); ++i) { |
| 25 Entry e(rtrans, GET_BY_HANDLE, *i); |
| 26 CHECK(e.good()); |
| 27 if (e.Get(NON_UNIQUE_NAME) == name) { |
| 28 ++number_of_entries_with_name; |
| 29 } |
| 30 } |
| 31 return number_of_entries_with_name; |
| 32 } |
| 33 |
| 34 Id GetFirstEntryWithName(BaseTransaction* rtrans, |
| 35 const syncable::Id& parent_id, |
| 36 const PathString& name) { |
| 37 Directory::ChildHandles child_handles; |
| 38 rtrans->directory()->GetChildHandles(rtrans, parent_id, &child_handles); |
| 39 |
| 40 for (Directory::ChildHandles::iterator i = child_handles.begin(); |
| 41 i != child_handles.end(); ++i) { |
| 42 Entry e(rtrans, GET_BY_HANDLE, *i); |
| 43 CHECK(e.good()); |
| 44 if (e.Get(NON_UNIQUE_NAME) == name) { |
| 45 return e.Get(ID); |
| 46 } |
| 47 } |
| 48 |
| 49 CHECK(false); |
| 50 return Id(); |
| 51 } |
| 52 |
| 53 Id GetOnlyEntryWithName(BaseTransaction* rtrans, |
| 54 const syncable::Id& parent_id, |
| 55 const PathString& name) { |
| 56 CHECK(1 == CountEntriesWithName(rtrans, parent_id, name)); |
| 57 return GetFirstEntryWithName(rtrans, parent_id, name); |
| 58 } |
| 59 |
| 60 } // namespace syncable |
OLD | NEW |