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

Side by Side Diff: blimp/helium/version_vector_unittest.cc

Issue 2602103002: Delete blimp/helium and remove references to it from dependent targets (Closed)
Patch Set: . Created 3 years, 11 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 | « blimp/helium/version_vector.cc ('k') | blimp/net/BUILD.gn » ('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 2016 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 <tuple>
6
7 #include "base/macros.h"
8 #include "blimp/helium/version_vector.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10
11 namespace blimp {
12 namespace helium {
13 namespace {
14
15 class VersionVectorComparisonTest
16 : public ::testing::TestWithParam<
17 std::tuple<VersionVector, VersionVector, VersionVector::Comparison>> {
18 public:
19 VersionVectorComparisonTest() {}
20 ~VersionVectorComparisonTest() override {}
21 };
22
23 TEST_P(VersionVectorComparisonTest, CompareTo) {
24 auto param = GetParam();
25 VersionVector v1 = std::get<0>(param);
26 VersionVector v2 = std::get<1>(param);
27 VersionVector::Comparison expected = std::get<2>(param);
28 EXPECT_EQ(expected, v1.CompareTo(v2));
29 }
30
31 INSTANTIATE_TEST_CASE_P(
32 LessThan,
33 VersionVectorComparisonTest,
34 ::testing::Values(std::make_tuple(VersionVector(1, 2),
35 VersionVector(1, 3),
36 VersionVector::Comparison::LessThan)));
37
38 INSTANTIATE_TEST_CASE_P(
39 GreaterThan,
40 VersionVectorComparisonTest,
41 ::testing::Values(std::make_tuple(VersionVector(1, 3),
42 VersionVector(1, 2),
43 VersionVector::Comparison::GreaterThan),
44 std::make_tuple(VersionVector(2, 2),
45 VersionVector(1, 2),
46 VersionVector::Comparison::GreaterThan)));
47
48 INSTANTIATE_TEST_CASE_P(
49 Conflict,
50 VersionVectorComparisonTest,
51 ::testing::Values(std::make_tuple(VersionVector(1, 2),
52 VersionVector(0, 1),
53 VersionVector::Comparison::Conflict),
54 std::make_tuple(VersionVector(1, 2),
55 VersionVector(0, 3),
56 VersionVector::Comparison::Conflict)));
57
58 INSTANTIATE_TEST_CASE_P(
59 EqualTo,
60 VersionVectorComparisonTest,
61 ::testing::Values(std::make_tuple(VersionVector(1, 1),
62 VersionVector(1, 1),
63 VersionVector::Comparison::EqualTo),
64 std::make_tuple(VersionVector(2, 3),
65 VersionVector(2, 3),
66 VersionVector::Comparison::EqualTo),
67 std::make_tuple(VersionVector(3, 2),
68 VersionVector(3, 2),
69 VersionVector::Comparison::EqualTo)));
70
71 class VersionVectorTest : public testing::Test {
72 public:
73 VersionVectorTest() {}
74 ~VersionVectorTest() override {}
75
76 protected:
77 void CheckCumulativeMerge(const VersionVector& v1,
78 const VersionVector& v2,
79 const VersionVector& expected) {
80 // Compute the merge of v1 and v2
81 VersionVector r1 = v1.MergeWith(v2);
82 EXPECT_EQ(expected.local_revision(), r1.local_revision());
83 EXPECT_EQ(expected.remote_revision(), r1.remote_revision());
84
85 // Compute the merge of v2 and v1
86 VersionVector r2 = v2.MergeWith(v1);
87 EXPECT_EQ(expected.local_revision(), r2.local_revision());
88 EXPECT_EQ(expected.remote_revision(), r2.remote_revision());
89 }
90
91 private:
92 DISALLOW_COPY_AND_ASSIGN(VersionVectorTest);
93 };
94
95 TEST_F(VersionVectorTest, IncrementLocal1) {
96 VersionVector v(0, 0);
97 v.IncrementLocal();
98 EXPECT_EQ(1U, v.local_revision());
99 EXPECT_EQ(0U, v.remote_revision());
100 }
101
102 TEST_F(VersionVectorTest, IncrementLocal2) {
103 VersionVector v(4, 5);
104 v.IncrementLocal();
105 EXPECT_EQ(5U, v.local_revision());
106 EXPECT_EQ(5U, v.remote_revision());
107 }
108
109 TEST_F(VersionVectorTest, MergeLocalEqualRemoteSmaller) {
110 VersionVector v1(1, 2);
111 VersionVector v2(1, 4);
112
113 VersionVector expected(1, 4);
114 CheckCumulativeMerge(v1, v2, expected);
115 }
116
117 TEST_F(VersionVectorTest, MergeLocalSmallerRemoteEqual) {
118 VersionVector v1(1, 4);
119 VersionVector v2(2, 4);
120
121 VersionVector expected(2, 4);
122 CheckCumulativeMerge(v1, v2, expected);
123 }
124
125 TEST_F(VersionVectorTest, MergeLocalSmallerRemoteSmaller) {
126 VersionVector v1(1, 2);
127 VersionVector v2(3, 4);
128
129 VersionVector expected(3, 4);
130 CheckCumulativeMerge(v1, v2, expected);
131 }
132
133 TEST_F(VersionVectorTest, MergeLocalSmallerRemoteGreater) {
134 VersionVector v1(1, 4);
135 VersionVector v2(3, 2);
136
137 VersionVector expected(3, 4);
138 CheckCumulativeMerge(v1, v2, expected);
139 }
140
141 } // namespace
142 } // namespace helium
143 } // namespace blimp
OLDNEW
« no previous file with comments | « blimp/helium/version_vector.cc ('k') | blimp/net/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698