Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / sync / syncable / syncable_id_unittest.cc
blobe0b014387fbb86d5f2ae39e18627429fd64da4c7
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 #include "sync/syncable/syncable_id.h"
7 #include <vector>
9 #include "base/memory/scoped_ptr.h"
10 #include "base/test/values_test_util.h"
11 #include "base/values.h"
12 #include "sync/test/engine/test_id_factory.h"
13 #include "testing/gtest/include/gtest/gtest.h"
15 namespace syncer {
16 namespace syncable {
18 using std::vector;
20 class SyncableIdTest : public testing::Test { };
22 TEST(SyncableIdTest, TestIDCreation) {
23 vector<Id> v;
24 v.push_back(TestIdFactory::FromNumber(5));
25 v.push_back(TestIdFactory::FromNumber(1));
26 v.push_back(TestIdFactory::FromNumber(-5));
27 v.push_back(TestIdFactory::MakeLocal("A"));
28 v.push_back(TestIdFactory::MakeLocal("B"));
29 v.push_back(TestIdFactory::MakeServer("A"));
30 v.push_back(TestIdFactory::MakeServer("B"));
31 v.push_back(Id::CreateFromServerId("-5"));
32 v.push_back(Id::CreateFromClientString("A"));
33 v.push_back(Id::CreateFromServerId("A"));
35 for (vector<Id>::iterator i = v.begin(); i != v.end(); ++i) {
36 for (vector<Id>::iterator j = v.begin(); j != i; ++j) {
37 ASSERT_NE(*i, *j) << "mis equated two distinct ids";
39 ASSERT_EQ(*i, *i) << "self-equality failed";
40 Id copy1 = *i;
41 Id copy2 = *i;
42 ASSERT_EQ(copy1, copy2) << "equality after copy failed";
46 TEST(SyncableIdTest, GetLeastIdForLexicographicComparison) {
47 vector<Id> v;
48 v.push_back(Id::CreateFromServerId("z5"));
49 v.push_back(Id::CreateFromServerId("z55"));
50 v.push_back(Id::CreateFromServerId("z6"));
51 v.push_back(Id::CreateFromClientString("zA-"));
52 v.push_back(Id::CreateFromClientString("zA--"));
53 v.push_back(Id::CreateFromServerId("zA--"));
55 for (int i = 0; i <= 255; ++i) {
56 std::string one_character_id;
57 one_character_id.push_back(i);
58 v.push_back(Id::CreateFromClientString(one_character_id));
61 for (vector<Id>::iterator i = v.begin(); i != v.end(); ++i) {
62 // The following looks redundant, but we're testing a custom operator<.
63 ASSERT_LT(Id::GetLeastIdForLexicographicComparison(), *i);
64 ASSERT_NE(*i, i->GetLexicographicSuccessor());
65 ASSERT_NE(i->GetLexicographicSuccessor(), *i);
66 ASSERT_LT(*i, i->GetLexicographicSuccessor());
67 ASSERT_GT(i->GetLexicographicSuccessor(), *i);
68 for (vector<Id>::iterator j = v.begin(); j != v.end(); ++j) {
69 if (j == i)
70 continue;
71 if (*j < *i) {
72 ASSERT_LT(j->GetLexicographicSuccessor(), *i);
73 ASSERT_LT(j->GetLexicographicSuccessor(),
74 i->GetLexicographicSuccessor());
75 ASSERT_LT(*j, i->GetLexicographicSuccessor());
76 } else {
77 ASSERT_GT(j->GetLexicographicSuccessor(), *i);
78 ASSERT_GT(j->GetLexicographicSuccessor(),
79 i->GetLexicographicSuccessor());
80 ASSERT_GT(*j, i->GetLexicographicSuccessor());
86 TEST(SyncableIdTest, ToValue) {
87 base::ExpectStringValue("r", Id::CreateFromServerId("0").ToValue());
88 base::ExpectStringValue("svalue", Id::CreateFromServerId("value").ToValue());
90 base::ExpectStringValue("r", Id::CreateFromClientString("0").ToValue());
91 base::ExpectStringValue("cvalue",
92 Id::CreateFromClientString("value").ToValue());
95 } // namespace syncable
96 } // namespace syncer