1 #include "../binary/reflector-boosthana.h"
2 #include "../binary/serializable.h"
4 #include <c++utilities/conversion/stringbuilder.h>
5 #include <c++utilities/conversion/stringconversion.h>
6 #include <c++utilities/io/misc.h>
7 #include <c++utilities/tests/testutils.h>
9 using CppUtilities::operator<<;
10 #include <cppunit/TestFixture.h>
11 #include <cppunit/extensions/HelperMacros.h>
13 #include <rapidjson/document.h>
14 #include <rapidjson/stringbuffer.h>
15 #include <rapidjson/writer.h>
22 using namespace CPPUNIT_NS;
23 using namespace RAPIDJSON_NAMESPACE;
24 using namespace CppUtilities;
25 using namespace CppUtilities::Literals;
32 BOOST_HANA_DEFINE_STRUCT(TestObjectBinaryHana, (
int, number), (
double, number2), (vector<int>, numbers), (
string, text), (
bool,
boolean));
36 BOOST_HANA_DEFINE_STRUCT(NestingArrayBinaryHana, (
string, name), (vector<TestObjectBinaryHana>, testObjects));
47 CPPUNIT_TEST(testSerializingAndDeserializing);
48 CPPUNIT_TEST_SUITE_END();
51 void setUp()
override;
52 void tearDown()
override;
54 void testSerializingAndDeserializing();
71 TestObjectBinaryHana testObject;
72 testObject.number = 42;
73 testObject.number2 = 1234.25;
74 testObject.numbers = { 1, 2, 3, 4, 5 };
75 testObject.text =
"foo";
76 testObject.boolean =
true;
78 NestingArrayBinaryHana nestingObject;
79 nestingObject.name =
"bar";
80 nestingObject.testObjects.emplace_back(testObject);
82 stringstream stream(ios_base::in | ios_base::out | ios_base::binary);
83 stream.exceptions(ios_base::failbit | ios_base::badbit);
84 nestingObject.toBinary(stream);
86 const auto deserializedObject(NestingArrayBinaryHana::fromBinary(stream));
87 const auto &deserializedTestObj(deserializedObject.testObjects.at(0));
88 CPPUNIT_ASSERT_EQUAL(nestingObject.name, deserializedObject.name);
89 CPPUNIT_ASSERT_EQUAL(testObject.number, deserializedTestObj.number);
90 CPPUNIT_ASSERT_EQUAL(testObject.number2, deserializedTestObj.number2);
91 CPPUNIT_ASSERT_EQUAL(testObject.numbers, deserializedTestObj.numbers);
92 CPPUNIT_ASSERT_EQUAL(testObject.text, deserializedTestObj.text);
93 CPPUNIT_ASSERT_EQUAL(testObject.boolean, deserializedTestObj.boolean);