From 327c2c1a206a8a80104863f1a041c9bce7e09aa5 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Wed, 7 Jan 2015 00:23:28 +0000 Subject: Add support, tests and test data for struct roots --- slicer/slicer/parser.cpp | 5 ++++- slicer/test/initial/struct.xml | 5 +++++ slicer/test/initial/struct2.json | 1 + slicer/test/serializers.cpp | 17 +++++++++++++++++ 4 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 slicer/test/initial/struct.xml create mode 100644 slicer/test/initial/struct2.json diff --git a/slicer/slicer/parser.cpp b/slicer/slicer/parser.cpp index 7cd45f1..bf24bd6 100644 --- a/slicer/slicer/parser.cpp +++ b/slicer/slicer/parser.cpp @@ -204,7 +204,10 @@ namespace Slicer { fprintf(cpp, "// Struct %s\n", c->name().c_str()); visitComplexDataMembers(c, c->dataMembers()); - + + auto name = metaDataValue("slicer:root:", c->getMetaData()); + defineRootName(c->scoped(), name ? *name : c->name()); + fprintf(cpp, "template<>\nMetadata ModelPartForComplex< %s >::metadata ", c->scoped().c_str()); copyMetadata(c->getMetaData()); diff --git a/slicer/test/initial/struct.xml b/slicer/test/initial/struct.xml new file mode 100644 index 0000000..dbba018 --- /dev/null +++ b/slicer/test/initial/struct.xml @@ -0,0 +1,5 @@ + + + 10 + 13 + diff --git a/slicer/test/initial/struct2.json b/slicer/test/initial/struct2.json new file mode 100644 index 0000000..661e51c --- /dev/null +++ b/slicer/test/initial/struct2.json @@ -0,0 +1 @@ +{"a":10.000000,"b":13.000000} diff --git a/slicer/test/serializers.cpp b/slicer/test/serializers.cpp index efe9b9d..107a2ba 100644 --- a/slicer/test/serializers.cpp +++ b/slicer/test/serializers.cpp @@ -190,6 +190,13 @@ checkSeqOfClass(const TestModule::Classes & seqOfClass) BOOST_REQUIRE_EQUAL(seqOfClass[1]->b, 5); } +void +checkStruct(const TestModule::StructType & st) +{ + BOOST_REQUIRE_EQUAL(st.a, 10); + BOOST_REQUIRE_EQUAL(st.b, 13); +} + xmlpp::Document * readXml(const fs::path & path) { @@ -238,6 +245,16 @@ BOOST_AUTO_TEST_CASE( builtins_xml ) verifyByFile("builtins.xml", checkBuiltIns_valuesCorrect); } +BOOST_AUTO_TEST_CASE( structtype_xml ) +{ + verifyByFile("struct.xml", checkStruct); +} + +BOOST_AUTO_TEST_CASE( structtype_json ) +{ + verifyByFile("struct2.json", checkStruct); +} + BOOST_AUTO_TEST_CASE( sequenceOfClass_xml ) { verifyByFile("seqOfClass.xml", checkSeqOfClass); -- cgit v1.2.3