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