Test whether code generation is skipped for included structs
This commit is contained in:
parent
51e55f1673
commit
c5968f1663
|
@ -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
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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<IncludedStruct> {
|
||||
int someInt = 0;
|
||||
};
|
||||
|
||||
#endif // REFLECTIVE_RAPIDJSON_TESTS_MORE_STRUCTS_H
|
|
@ -4,6 +4,10 @@
|
|||
#include <c++utilities/chrono/datetime.h>
|
||||
#include <c++utilities/chrono/timespan.h>
|
||||
|
||||
// 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"
|
||||
|
||||
|
|
Loading…
Reference in New Issue