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