Nix 2.26.3
Nix, the purely functional package manager; unstable internal interfaces
 
Loading...
Searching...
No Matches
protocol.hh
Go to the documentation of this file.
1#pragma once
3
4#include <nlohmann/json.hpp>
5#include <gtest/gtest.h>
6
7#include "tests/libstore.hh"
9
10namespace nix {
11
12template<class Proto, const char * protocolDir>
13class ProtoTest : public CharacterizationTest, public LibStoreTest
14{
15 std::filesystem::path unitTestData = getUnitTestData() / protocolDir;
16
17 std::filesystem::path goldenMaster(std::string_view testStem) const override {
18 return unitTestData / (std::string { testStem + ".bin" });
19 }
20};
21
22template<class Proto, const char * protocolDir>
23class VersionedProtoTest : public ProtoTest<Proto, protocolDir>
24{
25public:
29 template<typename T>
30 void readProtoTest(PathView testStem, typename Proto::Version version, T expected)
31 {
32 CharacterizationTest::readTest(testStem, [&](const auto & encoded) {
33 T got = ({
34 StringSource from { encoded };
35 Proto::template Serialise<T>::read(
36 *LibStoreTest::store,
37 typename Proto::ReadConn {
38 .from = from,
39 .version = version,
40 });
41 });
42
43 ASSERT_EQ(got, expected);
44 });
45 }
46
50 template<typename T>
51 void writeProtoTest(PathView testStem, typename Proto::Version version, const T & decoded)
52 {
53 CharacterizationTest::writeTest(testStem, [&]() {
55 Proto::template Serialise<T>::write(
56 *LibStoreTest::store,
57 typename Proto::WriteConn {
58 .to = to,
59 .version = version,
60 },
61 decoded);
62 return std::move(to.s);
63 });
64 }
65};
66
67#define VERSIONED_CHARACTERIZATION_TEST(FIXTURE, NAME, STEM, VERSION, VALUE) \
68 TEST_F(FIXTURE, NAME ## _read) { \
69 readProtoTest(STEM, VERSION, VALUE); \
70 } \
71 TEST_F(FIXTURE, NAME ## _write) { \
72 writeProtoTest(STEM, VERSION, VALUE); \
73 }
74
75}
Definition characterization.hh:33
void writeTest(PathView testStem, auto &&test, auto &&readFile2, auto &&writeFile2)
Definition characterization.hh:71
void readTest(PathView testStem, auto &&test)
Definition characterization.hh:48
Definition protocol.hh:14
Definition protocol.hh:24
void writeProtoTest(PathView testStem, typename Proto::Version version, const T &decoded)
Definition protocol.hh:51
void readProtoTest(PathView testStem, typename Proto::Version version, T expected)
Definition protocol.hh:30
std::string std::string_view from
Definition lexer.l:2591
std::string std::string_view std::string_view to
Definition lexer.l:2592
Definition serialise.hh:187
Definition serialise.hh:203