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