Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(571)

Unified Diff: chrome/test/sync/engine/test_syncable_utils.cc

Issue 371029: Remove unique naming. (Closed)
Patch Set: Ready and about to go in! Created 11 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/test/sync/engine/test_syncable_utils.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/test/sync/engine/test_syncable_utils.cc
diff --git a/chrome/test/sync/engine/test_syncable_utils.cc b/chrome/test/sync/engine/test_syncable_utils.cc
new file mode 100755
index 0000000000000000000000000000000000000000..e01d3f0467b00a3ecef7f34fd0f514a9ec1a7c11
--- /dev/null
+++ b/chrome/test/sync/engine/test_syncable_utils.cc
@@ -0,0 +1,60 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Utilities to verify the state of items in unit tests.
+
+#include "chrome/test/sync/engine/test_syncable_utils.h"
+
+#include "chrome/browser/sync/syncable/syncable.h"
+
+namespace syncable {
+
+int CountEntriesWithName(BaseTransaction* rtrans,
+ const syncable::Id& parent_id,
+ const PathString& name) {
+ Directory::ChildHandles child_handles;
+ rtrans->directory()->GetChildHandles(rtrans, parent_id, &child_handles);
+ if (child_handles.size() <= 0) {
+ return 0;
+ }
+
+ int number_of_entries_with_name = 0;
+ for (Directory::ChildHandles::iterator i = child_handles.begin();
+ i != child_handles.end(); ++i) {
+ Entry e(rtrans, GET_BY_HANDLE, *i);
+ CHECK(e.good());
+ if (e.Get(NON_UNIQUE_NAME) == name) {
+ ++number_of_entries_with_name;
+ }
+ }
+ return number_of_entries_with_name;
+}
+
+Id GetFirstEntryWithName(BaseTransaction* rtrans,
+ const syncable::Id& parent_id,
+ const PathString& name) {
+ Directory::ChildHandles child_handles;
+ rtrans->directory()->GetChildHandles(rtrans, parent_id, &child_handles);
+
+ for (Directory::ChildHandles::iterator i = child_handles.begin();
+ i != child_handles.end(); ++i) {
+ Entry e(rtrans, GET_BY_HANDLE, *i);
+ CHECK(e.good());
+ if (e.Get(NON_UNIQUE_NAME) == name) {
+ return e.Get(ID);
+ }
+ }
+
+ CHECK(false);
+ return Id();
+}
+
+Id GetOnlyEntryWithName(BaseTransaction* rtrans,
+ const syncable::Id& parent_id,
+ const PathString& name) {
+ CHECK(1 == CountEntriesWithName(rtrans, parent_id, name));
+ return GetFirstEntryWithName(rtrans, parent_id, name);
+}
+
+} // namespace syncable
« no previous file with comments | « chrome/test/sync/engine/test_syncable_utils.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698