#include #include #include #include #include namespace { using namespace testing; using namespace EsmLoader; struct Value { int mKey; int mValue; }; auto tie(const Value& v) { return std::tie(v.mKey, v.mValue); } bool operator==(const Value& l, const Value& r) { return tie(l) == tie(r); } std::ostream& operator<<(std::ostream& s, const Value& v) { return s << "Value {" << v.mKey << ", " << v.mValue << "}"; } Record present(const Value& v) { return Record(false, v); } Record deleted(const Value& v) { return Record(true, v); } struct Params { Records mRecords; std::vector mResult; }; struct EsmLoaderPrepareRecordTest : TestWithParam { }; TEST_P(EsmLoaderPrepareRecordTest, prepareRecords) { auto records = GetParam().mRecords; const auto getKey = [&](const Record& v) { return v.mValue.mKey; }; EXPECT_THAT(prepareRecords(records, getKey), ElementsAreArray(GetParam().mResult)); } const std::array params = { Params{ {}, {} }, Params{ { present(Value{ 1, 1 }) }, { Value{ 1, 1 } } }, Params{ { deleted(Value{ 1, 1 }) }, {} }, Params{ { present(Value{ 1, 1 }), present(Value{ 2, 2 }) }, { Value{ 1, 1 }, Value{ 2, 2 } } }, Params{ { present(Value{ 2, 2 }), present(Value{ 1, 1 }) }, { Value{ 1, 1 }, Value{ 2, 2 } } }, Params{ { present(Value{ 1, 1 }), present(Value{ 1, 2 }) }, { Value{ 1, 2 } } }, Params{ { present(Value{ 1, 2 }), present(Value{ 1, 1 }) }, { Value{ 1, 1 } } }, Params{ { present(Value{ 1, 1 }), deleted(Value{ 1, 2 }) }, {} }, Params{ { deleted(Value{ 1, 1 }), present(Value{ 1, 2 }) }, { Value{ 1, 2 } } }, Params{ { present(Value{ 1, 2 }), deleted(Value{ 1, 1 }) }, {} }, Params{ { deleted(Value{ 1, 2 }), present(Value{ 1, 1 }) }, { Value{ 1, 1 } } }, }; INSTANTIATE_TEST_SUITE_P(Params, EsmLoaderPrepareRecordTest, ValuesIn(params)); }