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

Side by Side Diff: sync/syncable/syncable_id_unittest.cc

Issue 2130453004: [Sync] Move //sync to //components/sync. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 4 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
« no previous file with comments | « sync/syncable/syncable_id.cc ('k') | sync/syncable/syncable_model_neutral_write_transaction.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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.
4
5 #include "sync/syncable/syncable_id.h"
6
7 #include <vector>
8
9 #include "base/test/values_test_util.h"
10 #include "base/values.h"
11 #include "sync/test/engine/test_id_factory.h"
12 #include "testing/gtest/include/gtest/gtest.h"
13
14 namespace syncer {
15 namespace syncable {
16
17 using std::vector;
18
19 class SyncableIdTest : public testing::Test { };
20
21 TEST(SyncableIdTest, TestIDCreation) {
22 vector<Id> v;
23 v.push_back(TestIdFactory::FromNumber(5));
24 v.push_back(TestIdFactory::FromNumber(1));
25 v.push_back(TestIdFactory::FromNumber(-5));
26 v.push_back(TestIdFactory::MakeLocal("A"));
27 v.push_back(TestIdFactory::MakeLocal("B"));
28 v.push_back(TestIdFactory::MakeServer("A"));
29 v.push_back(TestIdFactory::MakeServer("B"));
30 v.push_back(Id::CreateFromServerId("-5"));
31 v.push_back(Id::CreateFromClientString("A"));
32 v.push_back(Id::CreateFromServerId("A"));
33
34 for (vector<Id>::iterator i = v.begin(); i != v.end(); ++i) {
35 for (vector<Id>::iterator j = v.begin(); j != i; ++j) {
36 ASSERT_NE(*i, *j) << "mis equated two distinct ids";
37 }
38 ASSERT_EQ(*i, *i) << "self-equality failed";
39 Id copy1 = *i;
40 Id copy2 = *i;
41 ASSERT_EQ(copy1, copy2) << "equality after copy failed";
42 }
43 }
44
45 TEST(SyncableIdTest, GetLeastIdForLexicographicComparison) {
46 vector<Id> v;
47 v.push_back(Id::CreateFromServerId("z5"));
48 v.push_back(Id::CreateFromServerId("z55"));
49 v.push_back(Id::CreateFromServerId("z6"));
50 v.push_back(Id::CreateFromClientString("zA-"));
51 v.push_back(Id::CreateFromClientString("zA--"));
52 v.push_back(Id::CreateFromServerId("zA--"));
53
54 for (int i = 0; i <= 255; ++i) {
55 std::string one_character_id;
56 one_character_id.push_back(i);
57 v.push_back(Id::CreateFromClientString(one_character_id));
58 }
59
60 for (vector<Id>::iterator i = v.begin(); i != v.end(); ++i) {
61 // The following looks redundant, but we're testing a custom operator<.
62 ASSERT_LT(Id::GetLeastIdForLexicographicComparison(), *i);
63 ASSERT_NE(*i, i->GetLexicographicSuccessor());
64 ASSERT_NE(i->GetLexicographicSuccessor(), *i);
65 ASSERT_LT(*i, i->GetLexicographicSuccessor());
66 ASSERT_GT(i->GetLexicographicSuccessor(), *i);
67 for (vector<Id>::iterator j = v.begin(); j != v.end(); ++j) {
68 if (j == i)
69 continue;
70 if (*j < *i) {
71 ASSERT_LT(j->GetLexicographicSuccessor(), *i);
72 ASSERT_LT(j->GetLexicographicSuccessor(),
73 i->GetLexicographicSuccessor());
74 ASSERT_LT(*j, i->GetLexicographicSuccessor());
75 } else {
76 ASSERT_GT(j->GetLexicographicSuccessor(), *i);
77 ASSERT_GT(j->GetLexicographicSuccessor(),
78 i->GetLexicographicSuccessor());
79 ASSERT_GT(*j, i->GetLexicographicSuccessor());
80 }
81 }
82 }
83 }
84
85 TEST(SyncableIdTest, ToValue) {
86 base::ExpectStringValue("r", Id::CreateFromServerId("0").ToValue());
87 base::ExpectStringValue("svalue", Id::CreateFromServerId("value").ToValue());
88
89 base::ExpectStringValue("r", Id::CreateFromClientString("0").ToValue());
90 base::ExpectStringValue("cvalue",
91 Id::CreateFromClientString("value").ToValue());
92 }
93
94 } // namespace syncable
95 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/syncable/syncable_id.cc ('k') | sync/syncable/syncable_model_neutral_write_transaction.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698