Shamrock
2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
shamtest
details
TestAssert.cpp
Go to the documentation of this file.
1
// -------------------------------------------------------//
2
//
3
// SHAMROCK code for hydrodynamics
4
// Copyright (c) 2021-2026 Timothée David--Cléris <tim.shamrock@proton.me>
5
// SPDX-License-Identifier: CeCILL Free Software License Agreement v2.1
6
// Shamrock is licensed under the CeCILL 2.1 License, see LICENSE for more information
7
//
8
// -------------------------------------------------------//
9
15
16
#include "
TestAssert.hpp
"
17
#include "
shambase/bytestream.hpp
"
18
19
namespace
shamtest::details
{
20
21
std::string
TestAssert::serialize_json
() {
22
std::string acc =
"\n{\n"
;
23
24
acc += R
"( "value" : )" + std::to_string(
value
) +
",\n"
;
25
acc += R
"( "name" : ")" +
name
+
"\""
;
26
27
if
(!
comment
.empty()) {
28
acc +=
",\n"
29
R
"( "comment" : ")"
30
+
comment
+
"\""
;
31
}
32
33
acc +=
"\n}"
;
34
return
acc;
35
}
36
37
void
TestAssert::serialize
(std::basic_stringstream<byte> &stream) {
38
byte
bl =
value
;
39
shambase::stream_write(stream, bl);
40
shambase::stream_write_string(stream,
name
);
41
shambase::stream_write_string(stream,
comment
);
42
}
43
44
TestAssert
TestAssert::deserialize
(std::basic_stringstream<byte> &stream) {
45
byte
bl;
46
std::string
name
;
47
std::string
comment
;
48
shambase::stream_read(stream, bl);
49
shambase::stream_read_string(stream,
name
);
50
shambase::stream_read_string(stream,
comment
);
51
52
return
{.value = bool(bl), .name =
name
, .comment =
comment
};
53
}
54
55
}
// namespace shamtest::details
TestAssert.hpp
bytestream.hpp
shamtest::details
implementation details of the test library
Definition
DataNode.cpp:20
shamtest::details::TestAssert
A test assertion.
Definition
TestAssert.hpp:24
shamtest::details::TestAssert::serialize_json
std::string serialize_json()
Serialize the assertion in JSON.
Definition
TestAssert.cpp:21
shamtest::details::TestAssert::comment
std::string comment
Comment attached to the assert.
Definition
TestAssert.hpp:27
shamtest::details::TestAssert::deserialize
static TestAssert deserialize(std::basic_stringstream< byte > &reader)
DeSerialize the assertion from binary format.
Definition
TestAssert.cpp:44
shamtest::details::TestAssert::value
bool value
Value of the assert.
Definition
TestAssert.hpp:25
shamtest::details::TestAssert::name
std::string name
Name of the assert.
Definition
TestAssert.hpp:26
shamtest::details::TestAssert::serialize
void serialize(std::basic_stringstream< byte > &stream)
Serialize the assertion in binary format.
Definition
TestAssert.cpp:37
Generated on
for Shamrock by
1.15.0