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

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

Issue 3056029: Move the number conversions from string_util to a new file.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 4 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
« no previous file with comments | « chrome/test/startup/startup_test.cc ('k') | chrome/test/ui/npapi_uitest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 // A tool making it easier to create IDs for unit testing. 5 // A tool making it easier to create IDs for unit testing.
6 6
7 #ifndef CHROME_TEST_SYNC_ENGINE_TEST_ID_FACTORY_H_ 7 #ifndef CHROME_TEST_SYNC_ENGINE_TEST_ID_FACTORY_H_
8 #define CHROME_TEST_SYNC_ENGINE_TEST_ID_FACTORY_H_ 8 #define CHROME_TEST_SYNC_ENGINE_TEST_ID_FACTORY_H_
9 #pragma once 9 #pragma once
10 10
11 #include <string> 11 #include <string>
12 12
13 #include "base/string_util.h" 13 #include "base/string_number_conversions.h"
14 #include "chrome/browser/sync/syncable/syncable_id.h" 14 #include "chrome/browser/sync/syncable/syncable_id.h"
15 15
16 namespace browser_sync { 16 namespace browser_sync {
17 17
18 class TestIdFactory { 18 class TestIdFactory {
19 public: 19 public:
20 TestIdFactory() : next_value_(1337000) {} 20 TestIdFactory() : next_value_(1337000) {}
21 ~TestIdFactory() {} 21 ~TestIdFactory() {}
22 22
23 // Get the root ID. 23 // Get the root ID.
24 static syncable::Id root() { 24 static syncable::Id root() {
25 return syncable::Id(); 25 return syncable::Id();
26 } 26 }
27 27
28 // Make an ID from a number. If the number is zero, return the root ID. 28 // Make an ID from a number. If the number is zero, return the root ID.
29 // If the number is positive, create a server ID based on the value. If 29 // If the number is positive, create a server ID based on the value. If
30 // the number is negative, create a local ID based on the value. This 30 // the number is negative, create a local ID based on the value. This
31 // is deterministic, and [FromNumber(X) == FromNumber(Y)] iff [X == Y]. 31 // is deterministic, and [FromNumber(X) == FromNumber(Y)] iff [X == Y].
32 static syncable::Id FromNumber(int64 value) { 32 static syncable::Id FromNumber(int64 value) {
33 if (value == 0) 33 if (value == 0)
34 return root(); 34 return root();
35 else if (value < 0) 35 else if (value < 0)
36 return syncable::Id::CreateFromClientString(Int64ToString(value)); 36 return syncable::Id::CreateFromClientString(base::Int64ToString(value));
37 else 37 else
38 return syncable::Id::CreateFromServerId(Int64ToString(value)); 38 return syncable::Id::CreateFromServerId(base::Int64ToString(value));
39 } 39 }
40 40
41 // Create a local ID from a name. 41 // Create a local ID from a name.
42 static syncable::Id MakeLocal(std::string name) { 42 static syncable::Id MakeLocal(std::string name) {
43 return syncable::Id::CreateFromClientString(std::string("lient ") + name); 43 return syncable::Id::CreateFromClientString(std::string("lient ") + name);
44 } 44 }
45 45
46 // Create a server ID from a string name. 46 // Create a server ID from a string name.
47 static syncable::Id MakeServer(std::string name) { 47 static syncable::Id MakeServer(std::string name) {
48 return syncable::Id::CreateFromServerId(std::string("erver ") + name); 48 return syncable::Id::CreateFromServerId(std::string("erver ") + name);
49 } 49 }
50 50
51 // Autogenerate a fresh local ID. 51 // Autogenerate a fresh local ID.
52 syncable::Id NewLocalId() { 52 syncable::Id NewLocalId() {
53 return syncable::Id::CreateFromClientString( 53 return syncable::Id::CreateFromClientString(
54 std::string("_auto ") + IntToString(-next_value())); 54 std::string("_auto ") + base::IntToString(-next_value()));
55 } 55 }
56 56
57 // Autogenerate a fresh server ID. 57 // Autogenerate a fresh server ID.
58 syncable::Id NewServerId() { 58 syncable::Id NewServerId() {
59 return syncable::Id::CreateFromServerId( 59 return syncable::Id::CreateFromServerId(
60 std::string("_auto ") + IntToString(next_value())); 60 std::string("_auto ") + base::IntToString(next_value()));
61 } 61 }
62 62
63 private: 63 private:
64 int next_value() { 64 int next_value() {
65 return next_value_++; 65 return next_value_++;
66 } 66 }
67 int next_value_; 67 int next_value_;
68 }; 68 };
69 69
70 } // namespace browser_sync 70 } // namespace browser_sync
71 71
72 #endif // CHROME_TEST_SYNC_ENGINE_TEST_ID_FACTORY_H_ 72 #endif // CHROME_TEST_SYNC_ENGINE_TEST_ID_FACTORY_H_
73 73
OLDNEW
« no previous file with comments | « chrome/test/startup/startup_test.cc ('k') | chrome/test/ui/npapi_uitest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698