Index: components/sync/base/unique_position_unittest.cc |
diff --git a/sync/internal_api/public/base/unique_position_unittest.cc b/components/sync/base/unique_position_unittest.cc |
similarity index 83% |
rename from sync/internal_api/public/base/unique_position_unittest.cc |
rename to components/sync/base/unique_position_unittest.cc |
index 02ee57a969777c9e34b3cb755f96a8d7e99fe7d8..71b2d93f958568c69cdfb89f60f144bf7c271976 100644 |
--- a/sync/internal_api/public/base/unique_position_unittest.cc |
+++ b/components/sync/base/unique_position_unittest.cc |
@@ -2,7 +2,7 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
-#include "sync/internal_api/public/base/unique_position.h" |
+#include "components/sync/base/unique_position.h" |
#include <stddef.h> |
#include <stdint.h> |
@@ -18,7 +18,7 @@ |
#include "base/macros.h" |
#include "base/sha1.h" |
#include "base/strings/string_number_conversions.h" |
-#include "sync/protocol/unique_position.pb.h" |
+#include "components/sync/protocol/unique_position.pb.h" |
#include "testing/gtest/include/gtest/gtest.h" |
namespace syncer { |
@@ -57,20 +57,20 @@ const size_t kSmallPositionLength = kMinLength; |
// Be careful when adding more prefixes to this list. |
// We have to manually ensure each has a unique suffix. |
-const UniquePosition kGenericPredecessor = FromBytes( |
- (std::string(kGenericPredecessorLength, '\x23') + '\xFF')); |
-const UniquePosition kGenericSuccessor = FromBytes( |
- std::string(kGenericSuccessorLength, '\xAB') + '\xFF'); |
-const UniquePosition kBigPosition = FromBytes( |
- std::string(kBigPositionLength - 1, '\xFF') + '\xFE' + '\xFF'); |
-const UniquePosition kBigPositionLessTwo = FromBytes( |
- std::string(kBigPositionLength - 1, '\xFF') + '\xFC' + '\xFF'); |
-const UniquePosition kBiggerPosition = FromBytes( |
- std::string(kBigPositionLength, '\xFF') + '\xFF'); |
-const UniquePosition kSmallPosition = FromBytes( |
- std::string(kSmallPositionLength - 1, '\x00') + '\x01' + '\xFF'); |
-const UniquePosition kSmallPositionPlusOne = FromBytes( |
- std::string(kSmallPositionLength - 1, '\x00') + '\x02' + '\xFF'); |
+const UniquePosition kGenericPredecessor = |
+ FromBytes((std::string(kGenericPredecessorLength, '\x23') + '\xFF')); |
+const UniquePosition kGenericSuccessor = |
+ FromBytes(std::string(kGenericSuccessorLength, '\xAB') + '\xFF'); |
+const UniquePosition kBigPosition = |
+ FromBytes(std::string(kBigPositionLength - 1, '\xFF') + '\xFE' + '\xFF'); |
+const UniquePosition kBigPositionLessTwo = |
+ FromBytes(std::string(kBigPositionLength - 1, '\xFF') + '\xFC' + '\xFF'); |
+const UniquePosition kBiggerPosition = |
+ FromBytes(std::string(kBigPositionLength, '\xFF') + '\xFF'); |
+const UniquePosition kSmallPosition = |
+ FromBytes(std::string(kSmallPositionLength - 1, '\x00') + '\x01' + '\xFF'); |
+const UniquePosition kSmallPositionPlusOne = |
+ FromBytes(std::string(kSmallPositionLength - 1, '\x00') + '\x02' + '\xFF'); |
const UniquePosition kHugePosition = FromBytes( |
std::string(UniquePosition::kCompressBytesThreshold, '\xFF') + '\xAB'); |
@@ -83,26 +83,26 @@ const std::string kNormalSuffix( |
::testing::AssertionResult LessThan(const char* m_expr, |
const char* n_expr, |
- const UniquePosition &m, |
- const UniquePosition &n) { |
+ const UniquePosition& m, |
+ const UniquePosition& n) { |
if (m.LessThan(n)) |
return ::testing::AssertionSuccess(); |
- return ::testing::AssertionFailure() |
- << m_expr << " is not less than " << n_expr |
- << " (" << m.ToDebugString() << " and " << n.ToDebugString() << ")"; |
+ return ::testing::AssertionFailure() << m_expr << " is not less than " |
+ << n_expr << " (" << m.ToDebugString() |
+ << " and " << n.ToDebugString() << ")"; |
} |
::testing::AssertionResult Equals(const char* m_expr, |
const char* n_expr, |
- const UniquePosition &m, |
- const UniquePosition &n) { |
+ const UniquePosition& m, |
+ const UniquePosition& n) { |
if (m.Equals(n)) |
return ::testing::AssertionSuccess(); |
- return ::testing::AssertionFailure() |
- << m_expr << " is not equal to " << n_expr |
- << " (" << m.ToDebugString() << " != " << n.ToDebugString() << ")"; |
+ return ::testing::AssertionFailure() << m_expr << " is not equal to " |
+ << n_expr << " (" << m.ToDebugString() |
+ << " != " << n.ToDebugString() << ")"; |
} |
// Test that the code can read the uncompressed serialization format. |
@@ -111,10 +111,10 @@ TEST_F(UniquePositionTest, DeserializeObsoleteUncompressedPosition) { |
// input is a serialization of kGenericPredecessor created by an older version |
// of this code. |
const char kSerializedCstr[] = { |
- '\x0a', '\x1f', '\x23', '\x23', '\x23', '\x23', '\x23', '\x23', '\x23', |
- '\x23', '\x23', '\x23', '\x23', '\x23', '\x23', '\x23', '\x23', '\x23', |
- '\x23', '\x23', '\x23', '\x23', '\x23', '\x23', '\x23', '\x23', '\x23', |
- '\x23', '\x23', '\x23', '\x23', '\x23', '\xff' }; |
+ '\x0a', '\x1f', '\x23', '\x23', '\x23', '\x23', '\x23', '\x23', '\x23', |
+ '\x23', '\x23', '\x23', '\x23', '\x23', '\x23', '\x23', '\x23', '\x23', |
+ '\x23', '\x23', '\x23', '\x23', '\x23', '\x23', '\x23', '\x23', '\x23', |
+ '\x23', '\x23', '\x23', '\x23', '\x23', '\xff'}; |
const std::string serialized(kSerializedCstr, sizeof(kSerializedCstr)); |
sync_pb::UniquePosition proto; |
@@ -135,8 +135,8 @@ TEST_F(UniquePositionTest, DeserializeObsoleteGzippedPosition) { |
// input is a serialization of kHugePosition created by an older version of |
// this code. |
const char kSerializedCstr[] = { |
- '\x12', '\x0d', '\x78', '\x9c', '\xfb', '\xff', '\x7f', '\x60', '\xc1', |
- '\x6a', '\x00', '\xa2', '\x4c', '\x80', '\x2c', '\x18', '\x81', '\x01' }; |
+ '\x12', '\x0d', '\x78', '\x9c', '\xfb', '\xff', '\x7f', '\x60', '\xc1', |
+ '\x6a', '\x00', '\xa2', '\x4c', '\x80', '\x2c', '\x18', '\x81', '\x01'}; |
const std::string serialized(kSerializedCstr, sizeof(kSerializedCstr)); |
sync_pb::UniquePosition proto; |
@@ -151,26 +151,18 @@ TEST_F(UniquePositionTest, DeserializeObsoleteGzippedPosition) { |
EXPECT_PRED_FORMAT2(Equals, kHugePosition, pos); |
} |
-class RelativePositioningTest : public UniquePositionTest { }; |
+class RelativePositioningTest : public UniquePositionTest {}; |
const UniquePosition kPositionArray[] = { |
- kGenericPredecessor, |
- kGenericSuccessor, |
- kBigPosition, |
- kBigPositionLessTwo, |
- kBiggerPosition, |
- kSmallPosition, |
- kSmallPositionPlusOne, |
+ kGenericPredecessor, kGenericSuccessor, kBigPosition, |
+ kBigPositionLessTwo, kBiggerPosition, kSmallPosition, |
+ kSmallPositionPlusOne, |
}; |
const UniquePosition kSortedPositionArray[] = { |
- kSmallPosition, |
- kSmallPositionPlusOne, |
- kGenericPredecessor, |
- kGenericSuccessor, |
- kBigPositionLessTwo, |
- kBigPosition, |
- kBiggerPosition, |
+ kSmallPosition, kSmallPositionPlusOne, kGenericPredecessor, |
+ kGenericSuccessor, kBigPositionLessTwo, kBigPosition, |
+ kBiggerPosition, |
}; |
static const size_t kNumPositions = arraysize(kPositionArray); |
@@ -183,8 +175,8 @@ struct PositionLessThan { |
}; |
// Returns true iff the given position's suffix matches the input parameter. |
-static bool IsSuffixInUse( |
- const UniquePosition& pos, const std::string& suffix) { |
+static bool IsSuffixInUse(const UniquePosition& pos, |
+ const std::string& suffix) { |
return pos.GetSuffixForTest() == suffix; |
} |
@@ -220,9 +212,8 @@ TEST_F(RelativePositioningTest, SortPositions) { |
std::sort(&positions[0], &positions[kNumPositions], PositionLessThan()); |
for (size_t i = 0; i < kNumPositions; ++i) { |
EXPECT_TRUE(positions[i].Equals(kSortedPositionArray[i])) |
- << "i: " << i << ", " |
- << positions[i].ToDebugString() << " != " |
- << kSortedPositionArray[i].ToDebugString(); |
+ << "i: " << i << ", " << positions[i].ToDebugString() |
+ << " != " << kSortedPositionArray[i].ToDebugString(); |
} |
} |
@@ -238,15 +229,13 @@ TEST_F(RelativePositioningTest, ReverseSortPositions) { |
std::sort(&positions[0], &positions[kNumPositions], PositionLessThan()); |
for (size_t i = 0; i < kNumPositions; ++i) { |
EXPECT_TRUE(positions[i].Equals(kSortedPositionArray[i])) |
- << "i: " << i << ", " |
- << positions[i].ToDebugString() << " != " |
- << kSortedPositionArray[i].ToDebugString(); |
+ << "i: " << i << ", " << positions[i].ToDebugString() |
+ << " != " << kSortedPositionArray[i].ToDebugString(); |
} |
} |
-class PositionInsertTest : |
- public RelativePositioningTest, |
- public ::testing::WithParamInterface<std::string> { }; |
+class PositionInsertTest : public RelativePositioningTest, |
+ public ::testing::WithParamInterface<std::string> {}; |
// Exercise InsertBetween with various insertion operations. |
TEST_P(PositionInsertTest, InsertBetween) { |
@@ -386,9 +375,7 @@ TEST_P(PositionInsertTest, StressRightInsertBetween) { |
class SuffixGenerator { |
public: |
explicit SuffixGenerator(const std::string& cache_guid) |
- : cache_guid_(cache_guid), |
- next_id_(-65535) { |
- } |
+ : cache_guid_(cache_guid), next_id_(-65535) {} |
std::string NextSuffix() { |
// This is not entirely realistic, but that should be OK. The current |
@@ -412,17 +399,13 @@ static const char kCacheGuidStr2[] = "yaKb7zHtY06aue9a0vlZgw=="; |
class PositionScenariosTest : public UniquePositionTest { |
public: |
PositionScenariosTest() |
- : generator1_(std::string(kCacheGuidStr1, arraysize(kCacheGuidStr1)-1)), |
- generator2_(std::string(kCacheGuidStr2, arraysize(kCacheGuidStr2)-1)) { |
- } |
+ : generator1_(std::string(kCacheGuidStr1, arraysize(kCacheGuidStr1) - 1)), |
+ generator2_( |
+ std::string(kCacheGuidStr2, arraysize(kCacheGuidStr2) - 1)) {} |
- std::string NextClient1Suffix() { |
- return generator1_.NextSuffix(); |
- } |
+ std::string NextClient1Suffix() { return generator1_.NextSuffix(); } |
- std::string NextClient2Suffix() { |
- return generator2_.NextSuffix(); |
- } |
+ std::string NextClient2Suffix() { return generator2_.NextSuffix(); } |
private: |
SuffixGenerator generator1_; |
@@ -431,8 +414,7 @@ class PositionScenariosTest : public UniquePositionTest { |
// One client creating new bookmarks, always inserting at the end. |
TEST_F(PositionScenariosTest, OneClientInsertAtEnd) { |
- UniquePosition pos = |
- UniquePosition::InitialPosition(NextClient1Suffix()); |
+ UniquePosition pos = UniquePosition::InitialPosition(NextClient1Suffix()); |
for (int i = 0; i < 1024; i++) { |
const std::string suffix = NextClient1Suffix(); |
UniquePosition new_pos = UniquePosition::After(pos, suffix); |
@@ -451,8 +433,7 @@ TEST_F(PositionScenariosTest, OneClientInsertAtEnd) { |
// Two clients alternately inserting entries at the end, with a strong |
// bias towards insertions by the first client. |
TEST_F(PositionScenariosTest, TwoClientsInsertAtEnd_A) { |
- UniquePosition pos = |
- UniquePosition::InitialPosition(NextClient1Suffix()); |
+ UniquePosition pos = UniquePosition::InitialPosition(NextClient1Suffix()); |
for (int i = 0; i < 1024; i++) { |
std::string suffix; |
if (i % 5 == 0) { |
@@ -472,8 +453,7 @@ TEST_F(PositionScenariosTest, TwoClientsInsertAtEnd_A) { |
// Two clients alternately inserting entries at the end. |
TEST_F(PositionScenariosTest, TwoClientsInsertAtEnd_B) { |
- UniquePosition pos = |
- UniquePosition::InitialPosition(NextClient1Suffix()); |
+ UniquePosition pos = UniquePosition::InitialPosition(NextClient1Suffix()); |
for (int i = 0; i < 1024; i++) { |
std::string suffix; |
if (i % 2 == 0) { |
@@ -491,26 +471,27 @@ TEST_F(PositionScenariosTest, TwoClientsInsertAtEnd_B) { |
EXPECT_LT(GetLength(pos), 500U); |
} |
-INSTANTIATE_TEST_CASE_P(MinSuffix, PositionInsertTest, |
+INSTANTIATE_TEST_CASE_P(MinSuffix, |
+ PositionInsertTest, |
::testing::Values(kMinSuffix)); |
-INSTANTIATE_TEST_CASE_P(MaxSuffix, PositionInsertTest, |
+INSTANTIATE_TEST_CASE_P(MaxSuffix, |
+ PositionInsertTest, |
::testing::Values(kMaxSuffix)); |
-INSTANTIATE_TEST_CASE_P(NormalSuffix, PositionInsertTest, |
+INSTANTIATE_TEST_CASE_P(NormalSuffix, |
+ PositionInsertTest, |
::testing::Values(kNormalSuffix)); |
class PositionFromIntTest : public UniquePositionTest { |
public: |
PositionFromIntTest() |
- : generator_(std::string(kCacheGuidStr1, arraysize(kCacheGuidStr1)-1)) { |
+ : generator_(std::string(kCacheGuidStr1, arraysize(kCacheGuidStr1) - 1)) { |
} |
protected: |
static const int64_t kTestValues[]; |
static const size_t kNumTestValues; |
- std::string NextSuffix() { |
- return generator_.NextSuffix(); |
- } |
+ std::string NextSuffix() { return generator_.NextSuffix(); } |
private: |
SuffixGenerator generator_; |
@@ -559,7 +540,7 @@ const int64_t PositionFromIntTest::kTestValues[] = {0LL, |
INT64_MAX - 1}; |
const size_t PositionFromIntTest::kNumTestValues = |
-arraysize(PositionFromIntTest::kTestValues); |
+ arraysize(PositionFromIntTest::kTestValues); |
TEST_F(PositionFromIntTest, IsValid) { |
for (size_t i = 0; i < kNumTestValues; ++i) { |
@@ -579,7 +560,7 @@ TEST_F(PositionFromIntTest, RoundTripConversion) { |
} |
} |
-template <typename T, typename LessThan = std::less<T> > |
+template <typename T, typename LessThan = std::less<T>> |
class IndexedLessThan { |
public: |
explicit IndexedLessThan(const T* values) : values_(values) {} |
@@ -599,8 +580,7 @@ TEST_F(PositionFromIntTest, ConsistentOrdering) { |
std::vector<int> int64_ordering(kNumTestValues); |
std::vector<int> position_ordering(kNumTestValues); |
for (size_t i = 0; i < kNumTestValues; ++i) { |
- positions[i] = UniquePosition::FromInt64( |
- kTestValues[i], NextSuffix()); |
+ positions[i] = UniquePosition::FromInt64(kTestValues[i], NextSuffix()); |
original_ordering[i] = int64_ordering[i] = position_ordering[i] = i; |
} |
@@ -647,8 +627,8 @@ class CompressedPositionTest : public UniquePositionTest { |
}; |
UniquePosition CompressedPositionTest::MakePosition( |
- const std::string& compressed_prefix, |
- const std::string& compressed_suffix) { |
+ const std::string& compressed_prefix, |
+ const std::string& compressed_suffix) { |
sync_pb::UniquePosition proto; |
proto.set_custom_compressed_v1( |
std::string(compressed_prefix + compressed_suffix)); |
@@ -664,7 +644,7 @@ std::string CompressedPositionTest::MakeSuffix(char unique_value) { |
for (size_t i = 0; i < UniquePosition::kSuffixLength; ++i) { |
suffix.push_back(static_cast<char>(i)); |
} |
- suffix[UniquePosition::kSuffixLength-1] = unique_value; |
+ suffix[UniquePosition::kSuffixLength - 1] = unique_value; |
return suffix; |
} |
@@ -694,8 +674,8 @@ TEST_F(CompressedPositionTest, DeserializeProtobufFromTheFuture) { |
// Make sure the comparison functions are working correctly. |
// This requires values in the test harness to be hard-coded in ascending order. |
TEST_F(CompressedPositionTest, OrderingTest) { |
- for (size_t i = 0; i < positions_.size()-1; ++i) { |
- EXPECT_PRED_FORMAT2(LessThan, positions_[i], positions_[i+1]); |
+ for (size_t i = 0; i < positions_.size() - 1; ++i) { |
+ EXPECT_PRED_FORMAT2(LessThan, positions_[i], positions_[i + 1]); |
} |
} |