Skip to content

Commit

Permalink
test: add unit tests for serializing variants
Browse files Browse the repository at this point in the history
  • Loading branch information
div72 committed Dec 26, 2023
1 parent 88d6729 commit 97b5572
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/test/serialize_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -330,4 +330,36 @@ BOOST_AUTO_TEST_CASE(class_methods)
BOOST_CHECK(methodtest3 == methodtest4);
}

BOOST_AUTO_TEST_CASE(variants)
{
CDataStream ss(SER_DISK, PROTOCOL_VERSION);
using p_t = std::pair<int, int>;
std::variant<int, std::string, double, p_t, CSerializeMethodsTestSingle> v;
CTransaction txval;
const char charstrval[16] = "testing charstr";
CSerializeMethodsTestSingle csmts(-3, false, "testing", charstrval, txval);

v = 42;
ss << v;
v = "sel";
ss << v;
v = 3.1415;
ss << v;
v = std::make_pair(14, 48);
ss << v;
v = csmts;
ss << v;

ss >> v;
BOOST_CHECK_EQUAL(std::get<int>(v), 42);
ss >> v;
BOOST_CHECK_EQUAL(std::get<std::string>(v), "sel");
ss >> v;
BOOST_CHECK_EQUAL(std::get<double>(v), 3.1415);
ss >> v;
BOOST_CHECK(std::get<p_t>(v) == std::make_pair(14, 48));
ss >> v;
BOOST_CHECK(std::get<CSerializeMethodsTestSingle>(v) == csmts);
}

BOOST_AUTO_TEST_SUITE_END()

0 comments on commit 97b5572

Please sign in to comment.