| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 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 | 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 "chrome/test/sync/engine/test_syncable_utils.h" | 7 #include "chrome/test/sync/engine/test_syncable_utils.h" |
| 8 | 8 |
| 9 #include "chrome/browser/sync/syncable/syncable.h" | 9 #include "chrome/browser/sync/syncable/syncable.h" |
| 10 | 10 |
| 11 using std::string; | 11 using std::string; |
| 12 | 12 |
| 13 namespace syncable { | 13 namespace syncable { |
| 14 | 14 |
| 15 int CountEntriesWithName(BaseTransaction* rtrans, | 15 int CountEntriesWithName(BaseTransaction* rtrans, |
| 16 const syncable::Id& parent_id, | 16 const syncable::Id& parent_id, |
| 17 const string& name) { | 17 const string& name) { |
| 18 Directory::ChildHandles child_handles; | 18 Directory::ChildHandles child_handles; |
| 19 rtrans->directory()->GetChildHandles(rtrans, parent_id, &child_handles); | 19 rtrans->directory()->GetChildHandlesById(rtrans, parent_id, &child_handles); |
| 20 if (child_handles.size() <= 0) { | 20 if (child_handles.size() <= 0) { |
| 21 return 0; | 21 return 0; |
| 22 } | 22 } |
| 23 | 23 |
| 24 int number_of_entries_with_name = 0; | 24 int number_of_entries_with_name = 0; |
| 25 for (Directory::ChildHandles::iterator i = child_handles.begin(); | 25 for (Directory::ChildHandles::iterator i = child_handles.begin(); |
| 26 i != child_handles.end(); ++i) { | 26 i != child_handles.end(); ++i) { |
| 27 Entry e(rtrans, GET_BY_HANDLE, *i); | 27 Entry e(rtrans, GET_BY_HANDLE, *i); |
| 28 CHECK(e.good()); | 28 CHECK(e.good()); |
| 29 if (e.Get(NON_UNIQUE_NAME) == name) { | 29 if (e.Get(NON_UNIQUE_NAME) == name) { |
| 30 ++number_of_entries_with_name; | 30 ++number_of_entries_with_name; |
| 31 } | 31 } |
| 32 } | 32 } |
| 33 return number_of_entries_with_name; | 33 return number_of_entries_with_name; |
| 34 } | 34 } |
| 35 | 35 |
| 36 Id GetFirstEntryWithName(BaseTransaction* rtrans, | 36 Id GetFirstEntryWithName(BaseTransaction* rtrans, |
| 37 const syncable::Id& parent_id, | 37 const syncable::Id& parent_id, |
| 38 const string& name) { | 38 const string& name) { |
| 39 Directory::ChildHandles child_handles; | 39 Directory::ChildHandles child_handles; |
| 40 rtrans->directory()->GetChildHandles(rtrans, parent_id, &child_handles); | 40 rtrans->directory()->GetChildHandlesById(rtrans, parent_id, &child_handles); |
| 41 | 41 |
| 42 for (Directory::ChildHandles::iterator i = child_handles.begin(); | 42 for (Directory::ChildHandles::iterator i = child_handles.begin(); |
| 43 i != child_handles.end(); ++i) { | 43 i != child_handles.end(); ++i) { |
| 44 Entry e(rtrans, GET_BY_HANDLE, *i); | 44 Entry e(rtrans, GET_BY_HANDLE, *i); |
| 45 CHECK(e.good()); | 45 CHECK(e.good()); |
| 46 if (e.Get(NON_UNIQUE_NAME) == name) { | 46 if (e.Get(NON_UNIQUE_NAME) == name) { |
| 47 return e.Get(ID); | 47 return e.Get(ID); |
| 48 } | 48 } |
| 49 } | 49 } |
| 50 | 50 |
| 51 CHECK(false); | 51 CHECK(false); |
| 52 return Id(); | 52 return Id(); |
| 53 } | 53 } |
| 54 | 54 |
| 55 Id GetOnlyEntryWithName(BaseTransaction* rtrans, | 55 Id GetOnlyEntryWithName(BaseTransaction* rtrans, |
| 56 const syncable::Id& parent_id, | 56 const syncable::Id& parent_id, |
| 57 const string& name) { | 57 const string& name) { |
| 58 CHECK(1 == CountEntriesWithName(rtrans, parent_id, name)); | 58 CHECK(1 == CountEntriesWithName(rtrans, parent_id, name)); |
| 59 return GetFirstEntryWithName(rtrans, parent_id, name); | 59 return GetFirstEntryWithName(rtrans, parent_id, name); |
| 60 } | 60 } |
| 61 | 61 |
| 62 } // namespace syncable | 62 } // namespace syncable |
| OLD | NEW |