#include "components/sync/base/unique_position.h"
#include <algorithm>
#include <functional>
#include <memory>
#include <vector>
#include "base/base64.h"
#include "base/hash/sha1.h"
#include "base/logging.h"
#include "base/memory/raw_ptr.h"
#include "base/ranges/algorithm.h"
#include "base/strings/string_number_conversions.h"
#include "components/sync/protocol/unique_position.pb.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace syncer {
namespace {
static UniquePosition FromBytes(const std::string& bytes) { … }
class UniquePositionTest : public ::testing::Test { … };
static constexpr char kMinSuffix[] = …;
static_assert …;
static constexpr char kMaxSuffix[] = …;
static_assert …;
static constexpr char kNormalSuffix[] = …;
static_assert …;
::testing::AssertionResult LessThan(const char* m_expr,
const char* n_expr,
const UniquePosition& m,
const UniquePosition& n) { … }
::testing::AssertionResult Equals(const char* m_expr,
const char* n_expr,
const UniquePosition& m,
const UniquePosition& n) { … }
TEST_F(UniquePositionTest, DeserializeObsoleteUncompressedPosition) { … }
TEST_F(UniquePositionTest, DeserializeObsoleteGzippedPosition) { … }
class RelativePositioningTest : public UniquePositionTest { … };
struct PositionLessThan { … };
static bool IsSuffixInUse(const UniquePosition& pos,
const std::string& suffix) { … }
TEST_F(RelativePositioningTest, ComparisonSanityTest1) { … }
TEST_F(RelativePositioningTest, ComparisonSanityTest2) { … }
TEST_F(RelativePositioningTest, SortPositions) { … }
TEST_F(RelativePositioningTest, ReverseSortPositions) { … }
class PositionInsertTest : public RelativePositioningTest,
public ::testing::WithParamInterface<std::string> { … };
TEST_P(PositionInsertTest, InsertBetween) { … }
TEST_P(PositionInsertTest, InsertBefore) { … }
TEST_P(PositionInsertTest, InsertAfter) { … }
TEST_P(PositionInsertTest, StressInsertAfter) { … }
TEST_P(PositionInsertTest, StressInsertBefore) { … }
TEST_P(PositionInsertTest, StressLeftInsertBetween) { … }
TEST_P(PositionInsertTest, StressRightInsertBetween) { … }
class SuffixGenerator { … };
static const char kCacheGuidStr1[] = …;
static const char kCacheGuidStr2[] = …;
class PositionScenariosTest : public UniquePositionTest { … };
TEST_F(PositionScenariosTest, OneClientInsertAtEnd) { … }
TEST_F(PositionScenariosTest, TwoClientsInsertAtEnd_A) { … }
TEST_F(PositionScenariosTest, TwoClientsInsertAtEnd_B) { … }
INSTANTIATE_TEST_SUITE_P(…);
INSTANTIATE_TEST_SUITE_P(…);
INSTANTIATE_TEST_SUITE_P(…);
class PositionFromIntTest : public UniquePositionTest { … };
TEST_F(PositionFromIntTest, IsValid) { … }
template <typename T, typename LessThan = std::less<T>>
class IndexedLessThan {
public:
explicit IndexedLessThan(base::span<const T> values) : … { … }
bool operator()(int i1, int i2) { … }
private:
base::span<const T> values_;
LessThan less_than_;
};
TEST_F(PositionFromIntTest, ConsistentOrdering) { … }
class CompressedPositionTest : public UniquePositionTest { … };
UniquePosition CompressedPositionTest::MakePosition(
const std::string& compressed_prefix,
const std::string& compressed_suffix) { … }
std::string CompressedPositionTest::MakeSuffix(char unique_value) { … }
TEST_F(CompressedPositionTest, SerializeAndDeserialize) { … }
TEST_F(CompressedPositionTest, DeserializeProtobufFromTheFuture) { … }
TEST_F(CompressedPositionTest, OrderingTest) { … }
}
}