aboutsummaryrefslogtreecommitdiff
path: root/tests/unit/libstore/protocol.hh
diff options
context:
space:
mode:
Diffstat (limited to 'tests/unit/libstore/protocol.hh')
-rw-r--r--tests/unit/libstore/protocol.hh45
1 files changed, 24 insertions, 21 deletions
diff --git a/tests/unit/libstore/protocol.hh b/tests/unit/libstore/protocol.hh
index 0df819090..6f0db89ac 100644
--- a/tests/unit/libstore/protocol.hh
+++ b/tests/unit/libstore/protocol.hh
@@ -9,26 +9,23 @@ namespace nix {
template<class Proto, const char * protocolDir>
class ProtoTest : public LibStoreTest
{
- /**
- * Read this as simply `using S = Inner::Serialise;`.
- *
- * See `LengthPrefixedProtoHelper::S` for the same trick, and its
- * rationale.
- */
- template<typename U> using S = typename Proto::template Serialise<U>;
-
-public:
+protected:
Path unitTestData = getUnitTestData() + "/libstore/" + protocolDir;
Path goldenMaster(std::string_view testStem) {
return unitTestData + "/" + testStem + ".bin";
}
+};
+template<class Proto, const char * protocolDir>
+class VersionedProtoTest : public ProtoTest<Proto, protocolDir>
+{
+public:
/**
* Golden test for `T` reading
*/
template<typename T>
- void readTest(PathView testStem, T value)
+ void readTest(PathView testStem, typename Proto::Version version, T value)
{
if (testAccept())
{
@@ -36,13 +33,16 @@ public:
}
else
{
- auto expected = readFile(goldenMaster(testStem));
+ auto expected = readFile(ProtoTest<Proto, protocolDir>::goldenMaster(testStem));
T got = ({
StringSource from { expected };
- S<T>::read(
- *store,
- typename Proto::ReadConn { .from = from });
+ Proto::template Serialise<T>::read(
+ *LibStoreTest::store,
+ typename Proto::ReadConn {
+ .from = from,
+ .version = version,
+ });
});
ASSERT_EQ(got, value);
@@ -53,14 +53,17 @@ public:
* Golden test for `T` write
*/
template<typename T>
- void writeTest(PathView testStem, const T & value)
+ void writeTest(PathView testStem, typename Proto::Version version, const T & value)
{
- auto file = goldenMaster(testStem);
+ auto file = ProtoTest<Proto, protocolDir>::goldenMaster(testStem);
StringSink to;
Proto::write(
- *store,
- typename Proto::WriteConn { .to = to },
+ *LibStoreTest::store,
+ typename Proto::WriteConn {
+ .to = to,
+ .version = version,
+ },
value);
if (testAccept())
@@ -77,12 +80,12 @@ public:
}
};
-#define CHARACTERIZATION_TEST(FIXTURE, NAME, STEM, VALUE) \
+#define VERSIONED_CHARACTERIZATION_TEST(FIXTURE, NAME, STEM, VERSION, VALUE) \
TEST_F(FIXTURE, NAME ## _read) { \
- readTest(STEM, VALUE); \
+ readTest(STEM, VERSION, VALUE); \
} \
TEST_F(FIXTURE, NAME ## _write) { \
- writeTest(STEM, VALUE); \
+ writeTest(STEM, VERSION, VALUE); \
}
}