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
3 // found in the LICENSE file.
5 // A tool making it easier to create IDs for unit testing.
7 #ifndef SYNC_TEST_ENGINE_TEST_ID_FACTORY_H_
8 #define SYNC_TEST_ENGINE_TEST_ID_FACTORY_H_
12 #include "base/strings/string_number_conversions.h"
13 #include "sync/syncable/syncable_id.h"
19 TestIdFactory() : next_value_(1337000) {}
23 static syncable::Id
root() { return syncable::Id::GetRoot(); }
25 // 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
27 // the number is negative, create a local ID based on the value. This
28 // is deterministic, and [FromNumber(X) == FromNumber(Y)] iff [X == Y].
29 static syncable::Id
FromNumber(int64 value
) {
33 return syncable::Id::CreateFromClientString(base::Int64ToString(value
));
35 return syncable::Id::CreateFromServerId(base::Int64ToString(value
));
38 // Create a local ID from a name.
39 static syncable::Id
MakeLocal(const std::string
& name
) {
40 return syncable::Id::CreateFromClientString(std::string("lient ") + name
);
43 // Create a server ID from a string name.
44 static syncable::Id
MakeServer(const std::string
& name
) {
45 return syncable::Id::CreateFromServerId(std::string("erver ") + name
);
48 // Autogenerate a fresh local ID.
49 syncable::Id
NewLocalId() {
50 return syncable::Id::CreateFromClientString(
51 std::string("_auto ") + base::IntToString(-next_value()));
54 // Autogenerate a fresh server ID.
55 syncable::Id
NewServerId() {
56 return syncable::Id::CreateFromServerId(
57 std::string("_auto ") + base::IntToString(next_value()));
69 #endif // SYNC_TEST_ENGINE_TEST_ID_FACTORY_H_