| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2011 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/engine/build_commit_command.h" | |
| 6 #include "chrome/browser/sync/test/engine/syncer_command_test.h" | |
| 7 | |
| 8 namespace browser_sync { | |
| 9 | |
| 10 // A test fixture for tests exercising ClearDataCommandTest. | |
| 11 class BuildCommitCommandTest : public SyncerCommandTest { | |
| 12 protected: | |
| 13 BuildCommitCommandTest() {} | |
| 14 BuildCommitCommand command_; | |
| 15 | |
| 16 private: | |
| 17 DISALLOW_COPY_AND_ASSIGN(BuildCommitCommandTest); | |
| 18 }; | |
| 19 | |
| 20 TEST_F(BuildCommitCommandTest, InterpolatePosition) { | |
| 21 EXPECT_LT(BuildCommitCommand::GetFirstPosition(), | |
| 22 BuildCommitCommand::GetLastPosition()); | |
| 23 | |
| 24 // Dense ranges. | |
| 25 EXPECT_EQ(10, command_.InterpolatePosition(10, 10)); | |
| 26 EXPECT_EQ(11, command_.InterpolatePosition(10, 11)); | |
| 27 EXPECT_EQ(11, command_.InterpolatePosition(10, 12)); | |
| 28 EXPECT_EQ(11, command_.InterpolatePosition(10, 13)); | |
| 29 EXPECT_EQ(11, command_.InterpolatePosition(10, 14)); | |
| 30 EXPECT_EQ(11, command_.InterpolatePosition(10, 15)); | |
| 31 EXPECT_EQ(11, command_.InterpolatePosition(10, 16)); | |
| 32 EXPECT_EQ(11, command_.InterpolatePosition(10, 17)); | |
| 33 EXPECT_EQ(11, command_.InterpolatePosition(10, 18)); | |
| 34 EXPECT_EQ(12, command_.InterpolatePosition(10, 19)); | |
| 35 EXPECT_EQ(12, command_.InterpolatePosition(10, 20)); | |
| 36 | |
| 37 // Sparse ranges. | |
| 38 EXPECT_EQ(0x32535ffe3dc97LL + BuildCommitCommand::GetGap(), | |
| 39 command_.InterpolatePosition(0x32535ffe3dc97LL, 0x61abcd323122cLL)); | |
| 40 EXPECT_EQ(~0x61abcd323122cLL + BuildCommitCommand::GetGap(), | |
| 41 command_.InterpolatePosition(~0x61abcd323122cLL, ~0x32535ffe3dc97LL)); | |
| 42 | |
| 43 // Lower limits | |
| 44 EXPECT_EQ(BuildCommitCommand::GetFirstPosition() + 0x20, | |
| 45 command_.InterpolatePosition( | |
| 46 BuildCommitCommand::GetFirstPosition(), | |
| 47 BuildCommitCommand::GetFirstPosition() + 0x100)); | |
| 48 EXPECT_EQ(BuildCommitCommand::GetFirstPosition() + 2, | |
| 49 command_.InterpolatePosition(BuildCommitCommand::GetFirstPosition() + 1, | |
| 50 BuildCommitCommand::GetFirstPosition() + 2)); | |
| 51 EXPECT_EQ(BuildCommitCommand::GetFirstPosition() + | |
| 52 BuildCommitCommand::GetGap()/8 + 1, | |
| 53 command_.InterpolatePosition( | |
| 54 BuildCommitCommand::GetFirstPosition() + 1, | |
| 55 BuildCommitCommand::GetFirstPosition() + 1 + | |
| 56 BuildCommitCommand::GetGap())); | |
| 57 | |
| 58 // Extremal cases. | |
| 59 EXPECT_EQ(0, | |
| 60 command_.InterpolatePosition(BuildCommitCommand::GetFirstPosition(), | |
| 61 BuildCommitCommand::GetLastPosition())); | |
| 62 EXPECT_EQ(BuildCommitCommand::GetFirstPosition() + 1 + | |
| 63 BuildCommitCommand::GetGap(), | |
| 64 command_.InterpolatePosition(BuildCommitCommand::GetFirstPosition() + 1, | |
| 65 BuildCommitCommand::GetLastPosition())); | |
| 66 EXPECT_EQ(BuildCommitCommand::GetFirstPosition() + 1 + | |
| 67 BuildCommitCommand::GetGap(), | |
| 68 command_.InterpolatePosition(BuildCommitCommand::GetFirstPosition() + 1, | |
| 69 BuildCommitCommand::GetLastPosition() - 1)); | |
| 70 EXPECT_EQ(BuildCommitCommand::GetLastPosition() - 1 - | |
| 71 BuildCommitCommand::GetGap(), | |
| 72 command_.InterpolatePosition(BuildCommitCommand::GetFirstPosition(), | |
| 73 BuildCommitCommand::GetLastPosition() - 1)); | |
| 74 | |
| 75 // Edge cases around zero. | |
| 76 EXPECT_EQ(BuildCommitCommand::GetGap(), | |
| 77 command_.InterpolatePosition(0, BuildCommitCommand::GetLastPosition())); | |
| 78 EXPECT_EQ(BuildCommitCommand::GetGap() + 1, | |
| 79 command_.InterpolatePosition(1, BuildCommitCommand::GetLastPosition())); | |
| 80 EXPECT_EQ(BuildCommitCommand::GetGap() - 1, | |
| 81 command_.InterpolatePosition(-1, BuildCommitCommand::GetLastPosition())); | |
| 82 EXPECT_EQ(-BuildCommitCommand::GetGap(), | |
| 83 command_.InterpolatePosition(BuildCommitCommand::GetFirstPosition(), 0)); | |
| 84 EXPECT_EQ(-BuildCommitCommand::GetGap() + 1, | |
| 85 command_.InterpolatePosition(BuildCommitCommand::GetFirstPosition(), 1)); | |
| 86 EXPECT_EQ(-BuildCommitCommand::GetGap() - 1, | |
| 87 command_.InterpolatePosition(BuildCommitCommand::GetFirstPosition(), -1)); | |
| 88 EXPECT_EQ(BuildCommitCommand::GetGap() / 8, | |
| 89 command_.InterpolatePosition(0, BuildCommitCommand::GetGap())); | |
| 90 EXPECT_EQ(BuildCommitCommand::GetGap() / 4, | |
| 91 command_.InterpolatePosition(0, BuildCommitCommand::GetGap()*2)); | |
| 92 EXPECT_EQ(BuildCommitCommand::GetGap(), | |
| 93 command_.InterpolatePosition(0, BuildCommitCommand::GetGap()*2 + 1)); | |
| 94 } | |
| 95 | |
| 96 } // namespace browser_sync | |
| 97 | |
| 98 | |
| OLD | NEW |