From c5968f16630271af4afc9cbf158b0af8a11996df Mon Sep 17 00:00:00 2001 From: Martchus Date: Sun, 31 Dec 2017 00:37:30 +0100 Subject: [PATCH] Test whether code generation is skipped for included structs --- generator/CMakeLists.txt | 6 ++++-- generator/tests/jsongenerator.cpp | 4 ++++ generator/tests/morestructs.h | 22 ++++++++++++++++++++++ generator/tests/structs.h | 4 ++++ 4 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 generator/tests/morestructs.h diff --git a/generator/CMakeLists.txt b/generator/CMakeLists.txt index e855092..3f7a99d 100644 --- a/generator/CMakeLists.txt +++ b/generator/CMakeLists.txt @@ -36,6 +36,7 @@ set(TEST_SRC_FILES if(RapidJSON_FOUND) list(APPEND TEST_HEADER_FILES tests/structs.h + tests/morestructs.h ) list(APPEND TEST_SRC_FILES tests/jsongenerator.cpp @@ -61,8 +62,9 @@ include(AppTarget) include(ReflectionGenerator) add_reflection_generator_invocation( INPUT_FILES - tests/structs.h # used by test cases - tests/cppunit.cpp # just for testing multiple input files and the "empty file" case + tests/structs.h # used by test cases + tests/morestructs.h # used by test cases + tests/cppunit.cpp # just for testing multiple input files and the "empty file" case GENERATORS json OUTPUT_LISTS diff --git a/generator/tests/jsongenerator.cpp b/generator/tests/jsongenerator.cpp index f4734f2..01e3c7e 100644 --- a/generator/tests/jsongenerator.cpp +++ b/generator/tests/jsongenerator.cpp @@ -263,6 +263,10 @@ void JsonGeneratorTests::test3rdPartyAdaption() // * the include must happen in exactly one translation unit of the project at a point where the structs are defined #include "reflection/structs.h" +// 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" + // 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 #include "reflection/cppunit.h" diff --git a/generator/tests/morestructs.h b/generator/tests/morestructs.h new file mode 100644 index 0000000..171af6c --- /dev/null +++ b/generator/tests/morestructs.h @@ -0,0 +1,22 @@ +#ifndef REFLECTIVE_RAPIDJSON_TESTS_MORE_STRUCTS_H +#define REFLECTIVE_RAPIDJSON_TESTS_MORE_STRUCTS_H + +#include "../../lib/json/serializable.h" + +using namespace std; +using namespace ReflectiveRapidJSON; + +/*! + * \brief The IncludedStruct struct is used to test whether only code for directly included + * structs is generated. + * + * The containing header file morestructs.h is indirectly included by struct.h. When + * generating code for struct.h, the code generator should ignore this struct. + * + * \remarks This is important to prevent violating the one definition rule. + */ +struct IncludedStruct : public JsonSerializable { + int someInt = 0; +}; + +#endif // REFLECTIVE_RAPIDJSON_TESTS_MORE_STRUCTS_H diff --git a/generator/tests/structs.h b/generator/tests/structs.h index 3fce9b4..556c71f 100644 --- a/generator/tests/structs.h +++ b/generator/tests/structs.h @@ -4,6 +4,10 @@ #include #include +// including this header should *not* cause the code generator to generate code for the +// contained structs as well (to prevent violating the one definition rule) +#include "./morestructs.h" + #include "../../lib/json/reflector-chronoutilities.h" #include "../../lib/json/serializable.h"