Nix 2.93.3
Lix: A modern, delicious implementation of the Nix package manager; unstable internal interfaces
Loading...
Searching...
No Matches
protocol.hh
Go to the documentation of this file.
1#pragma once
3#include <gtest/gtest.h>
4
6#include "tests/libstore.hh"
7#include "tests/characterization.hh"
8
9namespace nix {
10
11template<class Proto, const char * protocolDir>
12class ProtoTest : public LibStoreTest
13{
14protected:
15 Path unitTestData = getUnitTestData() + "/libstore/" + protocolDir;
16
17 Path goldenMaster(std::string_view testStem) {
18 return unitTestData + "/" + 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 readTest(PathView testStem, typename Proto::Version version, T value)
31 {
32 if (testAccept())
33 {
34 GTEST_SKIP() << cannotReadGoldenMaster;
35 }
36 else
37 {
38 auto expected = readFile(ProtoTest<Proto, protocolDir>::goldenMaster(testStem));
39
40 T got = ({
41 StringSource from { expected };
42 Proto::template Serialise<T>::read(
43 *LibStoreTest::store,
44 typename Proto::ReadConn {from, version}
45 );
46 });
47
48 ASSERT_EQ(got, value);
49 }
50 }
51
55 template<typename T>
56 void writeTest(PathView testStem, typename Proto::Version version, const T & value)
57 {
58 auto file = ProtoTest<Proto, protocolDir>::goldenMaster(testStem);
59
60 StringSink to;
61 to << Proto::write(
62 *LibStoreTest::store,
63 typename Proto::WriteConn {version},
64 value);
65
66 if (testAccept())
67 {
68 createDirs(dirOf(file));
69 writeFile(file, to.s);
70 GTEST_SKIP() << updatingGoldenMaster;
71 }
72 else
73 {
74 auto expected = readFile(file);
75 ASSERT_EQ(to.s, expected);
76 }
77 }
78};
79
80#define VERSIONED_CHARACTERIZATION_TEST(FIXTURE, NAME, STEM, VERSION, VALUE) \
81 TEST_F(FIXTURE, NAME ## _read) { \
82 readTest(STEM, VERSION, VALUE); \
83 } \
84 TEST_F(FIXTURE, NAME ## _write) { \
85 writeTest(STEM, VERSION, VALUE); \
86 }
87
88}
Definition protocol.hh:13
Definition protocol.hh:24
void readTest(PathView testStem, typename Proto::Version version, T value)
Definition protocol.hh:30
void writeTest(PathView testStem, typename Proto::Version version, const T &value)
Definition protocol.hh:56
Definition serialise.hh:188
Definition serialise.hh:204
std::string Path
Definition types.hh:28