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

Side by Side Diff: chrome/test/sync/engine/test_id_factory.h

Issue 194065: Initial commit of sync engine code to browser/sync.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Fixes to gtest include path, reverted syncapi. Created 11 years, 3 months 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 unified diff | Download patch | Annotate | Revision Log
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(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 // A tool making it easier to create IDs for unit testing.
6
7 #ifndef CHROME_TEST_SYNC_ENGINE_TEST_ID_FACTORY_H_
8 #define CHROME_TEST_SYNC_ENGINE_TEST_ID_FACTORY_H_
9
10 #include <string>
11
12 #include "base/string_util.h"
13 #include "chrome/browser/sync/syncable/syncable_id.h"
14
15 namespace browser_sync {
16
17 class TestIdFactory {
18 public:
19 TestIdFactory() : next_value_(1337000) {}
20 ~TestIdFactory() {}
21
22 // Get the root ID.
23 static syncable::Id root() {
24 return syncable::Id();
25 }
26
27 // Make an ID from a number. If the number is zero, return the root ID.
28 // If the number is positive, create a server ID based on the value. If
29 // the number is negative, create a local ID based on the value. This
30 // is deterministic, and [FromNumber(X) == FromNumber(Y)] iff [X == Y].
31 static syncable::Id FromNumber(int64 value) {
32 if (value == 0)
33 return root();
34 else if (value < 0)
35 return syncable::Id::CreateFromClientString(Int64ToString(value));
36 else
37 return syncable::Id::CreateFromServerId(Int64ToString(value));
38 }
39
40 // Create a local ID from a name.
41 static syncable::Id MakeLocal(std::string name) {
42 return syncable::Id::CreateFromClientString(std::string("lient ") + name);
43 }
44
45 // Create a server ID from a string name.
46 static syncable::Id MakeServer(std::string name) {
47 return syncable::Id::CreateFromServerId(std::string("erver ") + name);
48 }
49
50 // Autogenerate a fresh local ID.
51 syncable::Id NewLocalId() {
52 return syncable::Id::CreateFromClientString(
53 std::string("_auto ") + IntToString(-next_value()));
54 }
55
56 // Autogenerate a fresh server ID.
57 syncable::Id NewServerId() {
58 return syncable::Id::CreateFromServerId(
59 std::string("_auto ") + IntToString(next_value()));
60 }
61
62 private:
63 int next_value() {
64 return next_value_++;
65 }
66 int next_value_;
67 };
68
69 } // namespace browser_sync
70
71 #endif // CHROME_TEST_SYNC_ENGINE_TEST_ID_FACTORY_H_
72
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698