2017-10-25 18:25:34 +02:00
|
|
|
#include "./helper.h"
|
2017-10-27 15:48:26 +02:00
|
|
|
#include "./structs.h"
|
2017-10-18 23:07:17 +02:00
|
|
|
|
2017-10-25 18:25:34 +02:00
|
|
|
#include "../codefactory.h"
|
2017-10-28 16:31:07 +02:00
|
|
|
#include "../jsonserializationcodegenerator.h"
|
2017-10-24 01:00:40 +02:00
|
|
|
|
2017-10-18 23:07:17 +02:00
|
|
|
#include "resources/config.h"
|
|
|
|
|
|
|
|
#include <c++utilities/conversion/stringconversion.h>
|
|
|
|
#include <c++utilities/io/misc.h>
|
|
|
|
#include <c++utilities/tests/testutils.h>
|
|
|
|
|
|
|
|
#include <cppunit/TestFixture.h>
|
|
|
|
#include <cppunit/extensions/HelperMacros.h>
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
using namespace CPPUNIT_NS;
|
|
|
|
using namespace IoUtilities;
|
|
|
|
using namespace TestUtilities;
|
2017-10-27 17:53:25 +02:00
|
|
|
using namespace TestUtilities::Literals;
|
2017-10-21 00:32:42 +02:00
|
|
|
using namespace ConversionUtilities;
|
2017-10-25 16:47:14 +02:00
|
|
|
|
2017-10-21 00:32:42 +02:00
|
|
|
/*!
|
|
|
|
* \brief The OverallTests class tests the overall functionality of the code generator (CLI and generator itself).
|
|
|
|
*/
|
2017-11-02 23:09:39 +01:00
|
|
|
class JsonGeneratorTests : public TestFixture {
|
|
|
|
CPPUNIT_TEST_SUITE(JsonGeneratorTests);
|
2017-10-21 00:32:42 +02:00
|
|
|
CPPUNIT_TEST(testGeneratorItself);
|
2017-10-18 23:07:17 +02:00
|
|
|
CPPUNIT_TEST(testCLI);
|
2017-10-24 01:00:40 +02:00
|
|
|
CPPUNIT_TEST(testIncludingGeneratedHeader);
|
2017-10-27 17:53:25 +02:00
|
|
|
CPPUNIT_TEST(testNesting);
|
2017-10-25 16:47:14 +02:00
|
|
|
CPPUNIT_TEST(testSingleInheritence);
|
|
|
|
CPPUNIT_TEST(testMultipleInheritence);
|
2017-11-04 15:17:06 +01:00
|
|
|
CPPUNIT_TEST(testCustomSerialization);
|
2017-11-06 21:25:45 +01:00
|
|
|
CPPUNIT_TEST(test3rdPartyAdaption);
|
2017-12-31 00:48:51 +01:00
|
|
|
CPPUNIT_TEST(testHandlingConstMembers);
|
2017-10-18 23:07:17 +02:00
|
|
|
CPPUNIT_TEST_SUITE_END();
|
|
|
|
|
|
|
|
public:
|
2017-11-02 23:09:39 +01:00
|
|
|
JsonGeneratorTests();
|
2017-10-21 00:32:42 +02:00
|
|
|
void testGeneratorItself();
|
2017-10-18 23:07:17 +02:00
|
|
|
void testCLI();
|
2017-10-24 01:00:40 +02:00
|
|
|
void testIncludingGeneratedHeader();
|
2017-10-27 17:53:25 +02:00
|
|
|
void testNesting();
|
2017-10-25 16:47:14 +02:00
|
|
|
void testSingleInheritence();
|
|
|
|
void testMultipleInheritence();
|
2017-11-04 15:17:06 +01:00
|
|
|
void testCustomSerialization();
|
2017-11-06 21:25:45 +01:00
|
|
|
void test3rdPartyAdaption();
|
2017-12-31 00:48:51 +01:00
|
|
|
void testHandlingConstMembers();
|
2017-10-18 23:07:17 +02:00
|
|
|
|
|
|
|
private:
|
2017-11-02 23:09:39 +01:00
|
|
|
const vector<string> m_expectedCode;
|
2017-10-18 23:07:17 +02:00
|
|
|
};
|
|
|
|
|
2017-11-02 23:09:39 +01:00
|
|
|
CPPUNIT_TEST_SUITE_REGISTRATION(JsonGeneratorTests);
|
2017-10-18 23:07:17 +02:00
|
|
|
|
2017-11-02 23:09:39 +01:00
|
|
|
JsonGeneratorTests::JsonGeneratorTests()
|
2017-11-06 20:04:42 +01:00
|
|
|
: m_expectedCode(toArrayOfLines(readFile(testFilePath("some_structs_json_serialization.h"), 3 * 1024)))
|
2017-10-18 23:07:17 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-10-24 01:00:40 +02:00
|
|
|
/*!
|
|
|
|
* \brief Tests whether the generator works by using it directly.
|
|
|
|
*/
|
2017-11-02 23:09:39 +01:00
|
|
|
void JsonGeneratorTests::testGeneratorItself()
|
2017-10-18 23:07:17 +02:00
|
|
|
{
|
|
|
|
const string inputFilePath(testFilePath("some_structs.h"));
|
2017-10-21 00:32:42 +02:00
|
|
|
const vector<const char *> inputFiles{ inputFilePath.data() };
|
2018-02-03 15:44:10 +01:00
|
|
|
const vector<string> clangOptions{ "-resource-dir", REFLECTION_GENERATOR_CLANG_RESOURCE_DIR, "-I", CPP_UTILITIES_INCLUDE_DIRS, "-I",
|
|
|
|
RAPIDJSON_INCLUDE_DIRS };
|
2017-10-21 00:32:42 +02:00
|
|
|
|
2017-10-18 23:07:17 +02:00
|
|
|
stringstream buffer;
|
2017-11-06 15:31:21 +01:00
|
|
|
JsonSerializationCodeGenerator::Options jsonOptions;
|
2017-11-06 20:04:42 +01:00
|
|
|
jsonOptions.additionalClassesArg.occurrenceInfo().emplace_back(0);
|
|
|
|
jsonOptions.additionalClassesArg.occurrenceInfo().back().values.emplace_back("TestNamespace2::ThirdPartyStruct");
|
2017-10-24 01:00:40 +02:00
|
|
|
CodeFactory factory(TestApplication::appPath(), inputFiles, clangOptions, buffer);
|
2017-11-06 15:31:21 +01:00
|
|
|
factory.addGenerator<JsonSerializationCodeGenerator>(jsonOptions);
|
2017-10-27 17:53:25 +02:00
|
|
|
CPPUNIT_ASSERT(factory.run());
|
2017-10-21 00:32:42 +02:00
|
|
|
assertEqualityLinewise(m_expectedCode, toArrayOfLines(buffer.str()));
|
2017-10-18 23:07:17 +02:00
|
|
|
}
|
|
|
|
|
2017-10-24 01:00:40 +02:00
|
|
|
/*!
|
2017-11-02 23:09:39 +01:00
|
|
|
* \brief Tests the generator CLI explicitely.
|
2017-10-24 01:00:40 +02:00
|
|
|
* \remarks Only available under UNIX (like) systems so far, because TESTUTILS_ASSERT_EXEC has not been implemented
|
|
|
|
* for other platforms.
|
|
|
|
*/
|
2017-11-02 23:09:39 +01:00
|
|
|
void JsonGeneratorTests::testCLI()
|
2017-10-18 23:07:17 +02:00
|
|
|
{
|
|
|
|
#ifdef PLATFORM_UNIX
|
|
|
|
string stdout, stderr;
|
2017-10-21 00:32:42 +02:00
|
|
|
|
|
|
|
const string inputFilePath(testFilePath("some_structs.h"));
|
2018-02-03 15:44:10 +01:00
|
|
|
const char *const args1[]
|
|
|
|
= { PROJECT_NAME, "--input-file", inputFilePath.data(), "--json-classes", "TestNamespace2::ThirdPartyStruct", "--clang-opt", "-resource-dir",
|
|
|
|
REFLECTION_GENERATOR_CLANG_RESOURCE_DIR, "-I", CPP_UTILITIES_INCLUDE_DIRS, "-I", RAPIDJSON_INCLUDE_DIRS, nullptr };
|
2017-10-18 23:07:17 +02:00
|
|
|
TESTUTILS_ASSERT_EXEC(args1);
|
2017-10-21 00:32:42 +02:00
|
|
|
assertEqualityLinewise(m_expectedCode, toArrayOfLines(stdout));
|
2017-10-18 23:07:17 +02:00
|
|
|
#endif
|
|
|
|
}
|
2017-10-24 01:00:40 +02:00
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Tests whether the generated reflection code actually works.
|
2017-11-02 23:09:39 +01:00
|
|
|
* \remarks The following methods do the same. This test case is supposed to be the minimum example.
|
2017-10-24 01:00:40 +02:00
|
|
|
*/
|
2017-11-02 23:09:39 +01:00
|
|
|
void JsonGeneratorTests::testIncludingGeneratedHeader()
|
2017-10-24 01:00:40 +02:00
|
|
|
{
|
|
|
|
TestStruct test;
|
|
|
|
test.someInt = 42;
|
2018-02-03 16:14:20 +01:00
|
|
|
test.someSize = 0xAAAAAAAA;
|
2017-10-24 01:00:40 +02:00
|
|
|
test.someString = "the answer";
|
|
|
|
test.yetAnotherString = "but what was the question";
|
2018-02-03 16:14:20 +01:00
|
|
|
const string expectedJSON(
|
|
|
|
"{\"someInt\":42,\"someSize\":2863311530,\"someString\":\"the answer\",\"yetAnotherString\":\"but what was the question\"}");
|
2017-10-24 01:00:40 +02:00
|
|
|
|
|
|
|
// test serialization
|
|
|
|
CPPUNIT_ASSERT_EQUAL(expectedJSON, string(test.toJson().GetString()));
|
|
|
|
|
|
|
|
// test deserialization
|
|
|
|
const TestStruct parsedTest(TestStruct::fromJson(expectedJSON));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(test.someInt, parsedTest.someInt);
|
2018-02-03 16:14:20 +01:00
|
|
|
CPPUNIT_ASSERT_EQUAL(test.someSize, parsedTest.someSize);
|
2017-10-24 01:00:40 +02:00
|
|
|
CPPUNIT_ASSERT_EQUAL(test.someString, parsedTest.someString);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(test.yetAnotherString, parsedTest.yetAnotherString);
|
|
|
|
}
|
|
|
|
|
2017-11-02 23:09:39 +01:00
|
|
|
/*!
|
|
|
|
* \brief Like testIncludingGeneratedHeader() but also for nested structures.
|
|
|
|
*/
|
|
|
|
void JsonGeneratorTests::testNesting()
|
2017-10-27 17:53:25 +02:00
|
|
|
{
|
|
|
|
TestStruct test;
|
|
|
|
test.someInt = 42;
|
2018-02-03 16:14:20 +01:00
|
|
|
test.someSize = 0xAAAAAAAA;
|
2017-10-27 17:53:25 +02:00
|
|
|
test.someString = "the answer";
|
|
|
|
test.yetAnotherString = "but what was the question";
|
|
|
|
NestedTestStruct nested;
|
|
|
|
nested.nested.emplace_front(vector<TestStruct>{ test });
|
|
|
|
nested.deq.emplace_back(3.14);
|
2018-02-03 16:14:20 +01:00
|
|
|
const string expectedJSON(
|
|
|
|
"{\"nested\":[[{\"someInt\":42,\"someSize\":2863311530,\"someString\":\"the answer\",\"yetAnotherString\":\"but what was the "
|
|
|
|
"question\"}]],\"ptr\":null,\"deq\":[3.14]}");
|
2017-10-27 17:53:25 +02:00
|
|
|
|
|
|
|
// test serialization
|
|
|
|
CPPUNIT_ASSERT_EQUAL(expectedJSON, string(nested.toJson().GetString()));
|
|
|
|
|
|
|
|
// test deserialization
|
|
|
|
const NestedTestStruct parsedNested(NestedTestStruct::fromJson(expectedJSON));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(1_st, parsedNested.nested.size());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(1_st, parsedNested.nested.front().size());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(1_st, parsedNested.deq.size());
|
|
|
|
const TestStruct &parsedTest(parsedNested.nested.front().front());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(test.someInt, parsedTest.someInt);
|
2018-02-03 16:14:20 +01:00
|
|
|
CPPUNIT_ASSERT_EQUAL(test.someSize, parsedTest.someSize);
|
2017-10-27 17:53:25 +02:00
|
|
|
CPPUNIT_ASSERT_EQUAL(test.someString, parsedTest.someString);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(test.yetAnotherString, parsedTest.yetAnotherString);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(3.14, parsedNested.deq.front());
|
|
|
|
}
|
|
|
|
|
2017-10-25 16:47:14 +02:00
|
|
|
/*!
|
|
|
|
* \brief Like testIncludingGeneratedHeader() but also tests single inheritence.
|
|
|
|
*/
|
2017-11-02 23:09:39 +01:00
|
|
|
void JsonGeneratorTests::testSingleInheritence()
|
2017-10-25 16:47:14 +02:00
|
|
|
{
|
|
|
|
DerivedTestStruct test;
|
|
|
|
test.someInt = 42;
|
2018-02-03 16:14:20 +01:00
|
|
|
test.someSize = 5;
|
2017-10-25 16:47:14 +02:00
|
|
|
test.someString = "the answer";
|
|
|
|
test.yetAnotherString = "but what was the question";
|
|
|
|
test.someBool = false;
|
2018-02-03 16:14:20 +01:00
|
|
|
const string expectedJSONForBase(
|
|
|
|
"{\"someInt\":42,\"someSize\":5,\"someString\":\"the answer\",\"yetAnotherString\":\"but what was the question\"}");
|
2017-10-25 16:47:14 +02:00
|
|
|
const string expectedJSONForDerived(
|
2018-02-03 16:14:20 +01:00
|
|
|
"{\"someInt\":42,\"someSize\":5,\"someString\":\"the answer\",\"yetAnotherString\":\"but what was the question\",\"someBool\":false}");
|
2017-10-25 16:47:14 +02:00
|
|
|
|
|
|
|
// test serialization
|
2017-10-27 15:48:26 +02:00
|
|
|
CPPUNIT_ASSERT_EQUAL(expectedJSONForBase, string(as<TestStruct>(test).toJson().GetString()));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(expectedJSONForDerived, string(as<DerivedTestStruct>(test).toJson().GetString()));
|
2017-10-25 16:47:14 +02:00
|
|
|
|
|
|
|
// test deserialization
|
2017-10-28 16:23:39 +02:00
|
|
|
const DerivedTestStruct parsedTest(JsonSerializable<DerivedTestStruct>::fromJson(expectedJSONForDerived));
|
2017-10-25 16:47:14 +02:00
|
|
|
CPPUNIT_ASSERT_EQUAL(test.someInt, parsedTest.someInt);
|
2018-02-03 16:14:20 +01:00
|
|
|
CPPUNIT_ASSERT_EQUAL(test.someSize, parsedTest.someSize);
|
2017-10-25 16:47:14 +02:00
|
|
|
CPPUNIT_ASSERT_EQUAL(test.someString, parsedTest.someString);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(test.yetAnotherString, parsedTest.yetAnotherString);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(test.someBool, parsedTest.someBool);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Like testIncludingGeneratedHeader() but also tests multiple inheritence.
|
|
|
|
*/
|
2017-11-02 23:09:39 +01:00
|
|
|
void JsonGeneratorTests::testMultipleInheritence()
|
2017-10-25 16:47:14 +02:00
|
|
|
{
|
|
|
|
MultipleDerivedTestStruct test;
|
|
|
|
test.someInt = 42;
|
2018-02-03 16:14:20 +01:00
|
|
|
test.someSize = 4294967274;
|
2017-10-25 16:47:14 +02:00
|
|
|
test.someString = "the answer";
|
|
|
|
test.yetAnotherString = "but what was the question";
|
|
|
|
test.someBool = false;
|
|
|
|
test.arrayOfStrings = { "array", "of", "strings" };
|
2018-02-03 16:14:20 +01:00
|
|
|
const string expectedJSONForDerived(
|
|
|
|
"{\"someInt\":42,\"someSize\":4294967274,\"someString\":\"the answer\",\"yetAnotherString\":\"but what was the "
|
|
|
|
"question\",\"arrayOfStrings\":[\"array\",\"of\",\"strings\"],\"someBool\":false}");
|
2017-10-25 16:47:14 +02:00
|
|
|
|
|
|
|
// test serialization
|
2017-10-27 15:48:26 +02:00
|
|
|
CPPUNIT_ASSERT_EQUAL(expectedJSONForDerived, string(as<MultipleDerivedTestStruct>(test).toJson().GetString()));
|
2017-10-25 16:47:14 +02:00
|
|
|
|
|
|
|
// test deserialization
|
2017-10-28 16:23:39 +02:00
|
|
|
const MultipleDerivedTestStruct parsedTest(JsonSerializable<MultipleDerivedTestStruct>::fromJson(expectedJSONForDerived));
|
2017-10-25 16:47:14 +02:00
|
|
|
CPPUNIT_ASSERT_EQUAL(test.someInt, parsedTest.someInt);
|
2018-02-03 16:14:20 +01:00
|
|
|
CPPUNIT_ASSERT_EQUAL(test.someSize, parsedTest.someSize);
|
2017-10-25 16:47:14 +02:00
|
|
|
CPPUNIT_ASSERT_EQUAL(test.someString, parsedTest.someString);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(test.yetAnotherString, parsedTest.yetAnotherString);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(test.someBool, parsedTest.someBool);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(test.arrayOfStrings, parsedTest.arrayOfStrings);
|
|
|
|
}
|
|
|
|
|
2017-11-04 15:17:06 +01:00
|
|
|
/*!
|
|
|
|
* \brief Like testIncludingGeneratedHeader() but also tests custom (de)serialization.
|
|
|
|
*/
|
|
|
|
void JsonGeneratorTests::testCustomSerialization()
|
|
|
|
{
|
|
|
|
const StructWithCustomTypes test;
|
|
|
|
const string str("{\"dt\":\"2017-04-02T15:31:21.165125\",\"ts\":\"03:15:19.125\"}");
|
|
|
|
|
|
|
|
// test serialization
|
|
|
|
CPPUNIT_ASSERT_EQUAL(str, string(test.toJson().GetString()));
|
|
|
|
|
|
|
|
// test deserialization
|
|
|
|
const StructWithCustomTypes parsedTest(StructWithCustomTypes::fromJson(str));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(test.dt.toString(), parsedTest.dt.toString());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(test.ts.toString(), parsedTest.ts.toString());
|
|
|
|
}
|
|
|
|
|
2017-11-06 21:25:45 +01:00
|
|
|
/*!
|
|
|
|
* \brief Tests whether adapting (de)serialization for 3rd party structs works.
|
|
|
|
*/
|
|
|
|
void JsonGeneratorTests::test3rdPartyAdaption()
|
|
|
|
{
|
2017-11-12 00:44:47 +01:00
|
|
|
// test whether specializations of AdaptedJsonSerializable are generated
|
2017-11-09 01:03:34 +01:00
|
|
|
static_assert(
|
|
|
|
ReflectiveRapidJSON::AdaptedJsonSerializable<NotJsonSerializable>::value, "can serialize NotJsonSerializable because of adaption macro");
|
2017-11-12 00:44:47 +01:00
|
|
|
static_assert(ReflectiveRapidJSON::AdaptedJsonSerializable<NestedNotJsonSerializable>::value,
|
|
|
|
"can serialize NestedNotJsonSerializable because of adaption macro");
|
2017-11-09 01:03:34 +01:00
|
|
|
static_assert(!ReflectiveRapidJSON::AdaptedJsonSerializable<OtherNotJsonSerializable>::value,
|
2017-11-06 21:25:45 +01:00
|
|
|
"can not serialize OtherNotJsonSerializable because adaption macro missing");
|
2017-11-09 01:03:34 +01:00
|
|
|
static_assert(!ReflectiveRapidJSON::AdaptedJsonSerializable<ReallyNotJsonSerializable>::value, "can not serialize ReallyNotJsonSerializable");
|
2017-11-06 21:25:45 +01:00
|
|
|
|
2017-11-12 00:44:47 +01:00
|
|
|
const NotJsonSerializable simple;
|
|
|
|
const string strSimple("{\"butSerializableAnyways\":\"useful to adapt 3rd party structs\"}");
|
|
|
|
const NestedNotJsonSerializable nested{ { "foo" }, { { "1" }, { "2" }, { "3" } }, { 42, { "bar" } } };
|
|
|
|
const string strNested("{\"asMember\":{\"butSerializableAnyways\":\"foo\"},\"asArrayElement\":[{\"butSerializableAnyways\":\"1\"},{"
|
|
|
|
"\"butSerializableAnyways\":\"2\"},{\"butSerializableAnyways\":\"3\"}],\"asTupleElement\":[42,{\"butSerializableAnyways\":"
|
|
|
|
"\"bar\"}]}");
|
2017-11-06 21:25:45 +01:00
|
|
|
|
|
|
|
// test serialization
|
2017-11-12 00:44:47 +01:00
|
|
|
CPPUNIT_ASSERT_EQUAL(strSimple, string(ReflectiveRapidJSON::JsonReflector::toJson(simple).GetString()));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(strNested, string(ReflectiveRapidJSON::JsonReflector::toJson(nested).GetString()));
|
2017-11-06 21:25:45 +01:00
|
|
|
|
|
|
|
// test deserialization
|
2017-11-12 00:44:47 +01:00
|
|
|
JsonDeserializationErrors errors;
|
|
|
|
const auto parsedSimple(ReflectiveRapidJSON::JsonReflector::fromJson<NotJsonSerializable>(strSimple, &errors));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(0_st, errors.size());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(simple.butSerializableAnyways, parsedSimple.butSerializableAnyways);
|
|
|
|
const auto parsedNested(ReflectiveRapidJSON::JsonReflector::fromJson<NestedNotJsonSerializable>(strNested, &errors));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(0_st, errors.size());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(nested.asMember.butSerializableAnyways, parsedNested.asMember.butSerializableAnyways);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(nested.asMember.butSerializableAnyways, parsedNested.asMember.butSerializableAnyways);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(nested.asArrayElement.size(), parsedNested.asArrayElement.size());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(nested.asArrayElement.at(0).butSerializableAnyways, parsedNested.asArrayElement.at(0).butSerializableAnyways);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(nested.asArrayElement.at(1).butSerializableAnyways, parsedNested.asArrayElement.at(1).butSerializableAnyways);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(nested.asArrayElement.at(2).butSerializableAnyways, parsedNested.asArrayElement.at(2).butSerializableAnyways);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(get<0>(nested.asTupleElement), get<0>(parsedNested.asTupleElement));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(get<1>(nested.asTupleElement).butSerializableAnyways, get<1>(parsedNested.asTupleElement).butSerializableAnyways);
|
2017-11-06 21:25:45 +01:00
|
|
|
}
|
|
|
|
|
2017-12-31 00:48:51 +01:00
|
|
|
/*!
|
|
|
|
* \brief Tests whether const member variables are ignored when deserializing.
|
|
|
|
* \remarks This test is very simple since no checks/diagnostics for const members have been implemented yet.
|
|
|
|
*/
|
|
|
|
void JsonGeneratorTests::testHandlingConstMembers()
|
|
|
|
{
|
|
|
|
ConstStruct constStruct;
|
|
|
|
constStruct.modifiableInt = 24;
|
|
|
|
const string strConstStruct("{\"modifiableInt\":24,\"constInt\":42}");
|
|
|
|
CPPUNIT_ASSERT_EQUAL(strConstStruct, string(constStruct.toJson().GetString()));
|
|
|
|
|
|
|
|
JsonDeserializationErrors errors;
|
|
|
|
auto parsedConstStruct(constStruct.fromJson(strConstStruct));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(0_st, errors.size());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(24, parsedConstStruct.modifiableInt);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(42, parsedConstStruct.constInt);
|
|
|
|
}
|
|
|
|
|
2017-10-25 18:25:34 +02:00
|
|
|
// include file required for reflection of TestStruct and other structs defined in structs.h
|
|
|
|
// NOTE: * generation of this header is triggered using the CMake function add_reflection_generator_invocation()
|
|
|
|
// * the include must happen in exactly one translation unit of the project at a point where the structs are defined
|
|
|
|
#include "reflection/structs.h"
|
2017-10-25 17:32:03 +02:00
|
|
|
|
2017-12-31 00:37:30 +01:00
|
|
|
// include file required for reflection of structs defined in morestructs.h
|
|
|
|
// NOTE: this inclusion should not lead to multiple definition errors (despite the fact that structs.h included morestructs.h)
|
|
|
|
#include "reflection/morestructs.h"
|
|
|
|
|
2017-10-25 18:25:34 +02:00
|
|
|
// this file should also be generated via add_reflection_generator_invocation() and hence includeable
|
|
|
|
// it is included to test the "empty" case when a unit doesn't contain relevant classes
|
2017-10-25 17:32:03 +02:00
|
|
|
#include "reflection/cppunit.h"
|