OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 SYNC_TEST_ENGINE_TEST_ID_FACTORY_H_ | 7 #ifndef SYNC_TEST_ENGINE_TEST_ID_FACTORY_H_ |
8 #define SYNC_TEST_ENGINE_TEST_ID_FACTORY_H_ | 8 #define SYNC_TEST_ENGINE_TEST_ID_FACTORY_H_ |
9 | 9 |
| 10 #include <stdint.h> |
| 11 |
10 #include <string> | 12 #include <string> |
11 | 13 |
12 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
13 #include "sync/syncable/syncable_id.h" | 15 #include "sync/syncable/syncable_id.h" |
14 | 16 |
15 namespace syncer { | 17 namespace syncer { |
16 | 18 |
17 class TestIdFactory { | 19 class TestIdFactory { |
18 public: | 20 public: |
19 TestIdFactory() : next_value_(1337000) {} | 21 TestIdFactory() : next_value_(1337000) {} |
20 ~TestIdFactory() {} | 22 ~TestIdFactory() {} |
21 | 23 |
22 // Get the root ID. | 24 // Get the root ID. |
23 static syncable::Id root() { return syncable::Id::GetRoot(); } | 25 static syncable::Id root() { return syncable::Id::GetRoot(); } |
24 | 26 |
25 // Make an ID from a number. If the number is zero, return the root ID. | 27 // Make an ID from a number. If the number is zero, return the root ID. |
26 // If the number is positive, create a server ID based on the value. If | 28 // If the number is positive, create a server ID based on the value. If |
27 // the number is negative, create a local ID based on the value. This | 29 // the number is negative, create a local ID based on the value. This |
28 // is deterministic, and [FromNumber(X) == FromNumber(Y)] iff [X == Y]. | 30 // is deterministic, and [FromNumber(X) == FromNumber(Y)] iff [X == Y]. |
29 static syncable::Id FromNumber(int64 value) { | 31 static syncable::Id FromNumber(int64_t value) { |
30 if (value == 0) | 32 if (value == 0) |
31 return root(); | 33 return root(); |
32 else if (value < 0) | 34 else if (value < 0) |
33 return syncable::Id::CreateFromClientString(base::Int64ToString(value)); | 35 return syncable::Id::CreateFromClientString(base::Int64ToString(value)); |
34 else | 36 else |
35 return syncable::Id::CreateFromServerId(base::Int64ToString(value)); | 37 return syncable::Id::CreateFromServerId(base::Int64ToString(value)); |
36 } | 38 } |
37 | 39 |
38 // Create a local ID from a name. | 40 // Create a local ID from a name. |
39 static syncable::Id MakeLocal(const std::string& name) { | 41 static syncable::Id MakeLocal(const std::string& name) { |
(...skipping 21 matching lines...) Expand all Loading... |
61 int next_value() { | 63 int next_value() { |
62 return next_value_++; | 64 return next_value_++; |
63 } | 65 } |
64 int next_value_; | 66 int next_value_; |
65 }; | 67 }; |
66 | 68 |
67 } // namespace syncer | 69 } // namespace syncer |
68 | 70 |
69 #endif // SYNC_TEST_ENGINE_TEST_ID_FACTORY_H_ | 71 #endif // SYNC_TEST_ENGINE_TEST_ID_FACTORY_H_ |
70 | 72 |
OLD | NEW |