NaCl: Update revision in DEPS, r9066 -> r9086
[chromium-blink-merge.git] / sync / engine / build_commit_command_unittest.cc
blob66ba14ba1c88b2a91237a85e37d0e46dfe7a4c1f
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/engine/build_commit_command.h"
6 #include "sync/test/engine/syncer_command_test.h"
8 namespace syncer {
10 // A test fixture for tests exercising ClearDataCommandTest.
11 class BuildCommitCommandTest : public SyncerCommandTest {
12 protected:
13 BuildCommitCommandTest()
14 : batch_commit_set_(ModelSafeRoutingInfo()),
15 command_(batch_commit_set_, &commit_message_) {
18 private:
19 sessions::OrderedCommitSet batch_commit_set_;
20 ClientToServerMessage commit_message_;
22 protected:
23 BuildCommitCommand command_;
25 private:
26 DISALLOW_COPY_AND_ASSIGN(BuildCommitCommandTest);
29 TEST_F(BuildCommitCommandTest, InterpolatePosition) {
30 EXPECT_LT(BuildCommitCommand::GetFirstPosition(),
31 BuildCommitCommand::GetLastPosition());
33 // Dense ranges.
34 EXPECT_EQ(10, command_.InterpolatePosition(10, 10));
35 EXPECT_EQ(11, command_.InterpolatePosition(10, 11));
36 EXPECT_EQ(11, command_.InterpolatePosition(10, 12));
37 EXPECT_EQ(11, command_.InterpolatePosition(10, 13));
38 EXPECT_EQ(11, command_.InterpolatePosition(10, 14));
39 EXPECT_EQ(11, command_.InterpolatePosition(10, 15));
40 EXPECT_EQ(11, command_.InterpolatePosition(10, 16));
41 EXPECT_EQ(11, command_.InterpolatePosition(10, 17));
42 EXPECT_EQ(11, command_.InterpolatePosition(10, 18));
43 EXPECT_EQ(12, command_.InterpolatePosition(10, 19));
44 EXPECT_EQ(12, command_.InterpolatePosition(10, 20));
46 // Sparse ranges.
47 EXPECT_EQ(0x32535ffe3dc97LL + BuildCommitCommand::GetGap(),
48 command_.InterpolatePosition(0x32535ffe3dc97LL, 0x61abcd323122cLL));
49 EXPECT_EQ(~0x61abcd323122cLL + BuildCommitCommand::GetGap(),
50 command_.InterpolatePosition(~0x61abcd323122cLL, ~0x32535ffe3dc97LL));
52 // Lower limits
53 EXPECT_EQ(BuildCommitCommand::GetFirstPosition() + 0x20,
54 command_.InterpolatePosition(
55 BuildCommitCommand::GetFirstPosition(),
56 BuildCommitCommand::GetFirstPosition() + 0x100));
57 EXPECT_EQ(BuildCommitCommand::GetFirstPosition() + 2,
58 command_.InterpolatePosition(BuildCommitCommand::GetFirstPosition() + 1,
59 BuildCommitCommand::GetFirstPosition() + 2));
60 EXPECT_EQ(BuildCommitCommand::GetFirstPosition() +
61 BuildCommitCommand::GetGap()/8 + 1,
62 command_.InterpolatePosition(
63 BuildCommitCommand::GetFirstPosition() + 1,
64 BuildCommitCommand::GetFirstPosition() + 1 +
65 BuildCommitCommand::GetGap()));
67 // Extremal cases.
68 EXPECT_EQ(0,
69 command_.InterpolatePosition(BuildCommitCommand::GetFirstPosition(),
70 BuildCommitCommand::GetLastPosition()));
71 EXPECT_EQ(BuildCommitCommand::GetFirstPosition() + 1 +
72 BuildCommitCommand::GetGap(),
73 command_.InterpolatePosition(BuildCommitCommand::GetFirstPosition() + 1,
74 BuildCommitCommand::GetLastPosition()));
75 EXPECT_EQ(BuildCommitCommand::GetFirstPosition() + 1 +
76 BuildCommitCommand::GetGap(),
77 command_.InterpolatePosition(BuildCommitCommand::GetFirstPosition() + 1,
78 BuildCommitCommand::GetLastPosition() - 1));
79 EXPECT_EQ(BuildCommitCommand::GetLastPosition() - 1 -
80 BuildCommitCommand::GetGap(),
81 command_.InterpolatePosition(BuildCommitCommand::GetFirstPosition(),
82 BuildCommitCommand::GetLastPosition() - 1));
84 // Edge cases around zero.
85 EXPECT_EQ(BuildCommitCommand::GetGap(),
86 command_.InterpolatePosition(0, BuildCommitCommand::GetLastPosition()));
87 EXPECT_EQ(BuildCommitCommand::GetGap() + 1,
88 command_.InterpolatePosition(1, BuildCommitCommand::GetLastPosition()));
89 EXPECT_EQ(BuildCommitCommand::GetGap() - 1,
90 command_.InterpolatePosition(-1, BuildCommitCommand::GetLastPosition()));
91 EXPECT_EQ(-BuildCommitCommand::GetGap(),
92 command_.InterpolatePosition(BuildCommitCommand::GetFirstPosition(), 0));
93 EXPECT_EQ(-BuildCommitCommand::GetGap() + 1,
94 command_.InterpolatePosition(BuildCommitCommand::GetFirstPosition(), 1));
95 EXPECT_EQ(-BuildCommitCommand::GetGap() - 1,
96 command_.InterpolatePosition(BuildCommitCommand::GetFirstPosition(), -1));
97 EXPECT_EQ(BuildCommitCommand::GetGap() / 8,
98 command_.InterpolatePosition(0, BuildCommitCommand::GetGap()));
99 EXPECT_EQ(BuildCommitCommand::GetGap() / 4,
100 command_.InterpolatePosition(0, BuildCommitCommand::GetGap()*2));
101 EXPECT_EQ(BuildCommitCommand::GetGap(),
102 command_.InterpolatePosition(0, BuildCommitCommand::GetGap()*2 + 1));
105 } // namespace syncer