userver
C++ Async Framework
Loading...
Searching...
No Matches
test_helpers.hpp
1
#
pragma
once
2
3
#
include
<
utility
>
4
5
#
include
<
userver
/
utest
/
utest
.
hpp
>
6
#
include
<
userver
/
utils
/
fast_scope_guard
.
hpp
>
7
8
#
include
<
userver
/
dump
/
operations_mock
.
hpp
>
9
10
USERVER_NAMESPACE_BEGIN
11
12
namespace
dump
{
13
14
/// Converts to binary using `Write(Writer&, const T&)`
15
template
<
typename
T>
16
std
::
string
ToBinary
(
const
T& value) {
17
MockWriter writer;
18
writer.Write(value);
19
return
std::move(writer).Extract();
20
}
21
22
/// Converts from binary using `Read(Reader&, To<T>)`
23
template
<
typename
T>
24
std
::
remove_const_t
<
T
>
FromBinary
(std::string data) {
25
MockReader reader(std::move(data));
26
auto
value = reader.Read<std::remove_const_t<T>>();
27
reader.Finish();
28
return
value;
29
}
30
31
/// Write a value to a cache dump and immediately read it back. If `Write` and
32
/// `Read` are implemented correctly, the result should be equal to the original
33
/// value.
34
template
<
typename
T>
35
void
TestWriteReadCycle
(
const
T& original) {
36
MockReader reader(
dump
::ToBinary(original));
37
T after_cycle = reader.Read<T>();
38
reader.Finish();
39
EXPECT_EQ(after_cycle, original);
40
}
41
42
}
// namespace dump
43
44
USERVER_NAMESPACE_END
userver
dump
test_helpers.hpp
Generated on Tue Sep 2 2025 12:34:22 for userver by
Doxygen
1.13.2