summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2015-01-07 00:23:28 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2015-01-07 00:23:28 +0000
commit327c2c1a206a8a80104863f1a041c9bce7e09aa5 (patch)
treeedc5a611d0c03fd9002833d5651a3723ffe6e989
parentAdd tests and test data for sequence roots (diff)
downloadslicer-327c2c1a206a8a80104863f1a041c9bce7e09aa5.tar.bz2
slicer-327c2c1a206a8a80104863f1a041c9bce7e09aa5.tar.xz
slicer-327c2c1a206a8a80104863f1a041c9bce7e09aa5.zip
Add support, tests and test data for struct roots
-rw-r--r--slicer/slicer/parser.cpp5
-rw-r--r--slicer/test/initial/struct.xml5
-rw-r--r--slicer/test/initial/struct2.json1
-rw-r--r--slicer/test/serializers.cpp17
4 files changed, 27 insertions, 1 deletions
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 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<StructType>
+ <a>10</a>
+ <b>13</b>
+</StructType>
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<TestModule::BuiltInsPtr, Slicer::XmlFileDeserializer>("builtins.xml", checkBuiltIns_valuesCorrect);
}
+BOOST_AUTO_TEST_CASE( structtype_xml )
+{
+ verifyByFile<TestModule::StructType, Slicer::XmlFileDeserializer>("struct.xml", checkStruct);
+}
+
+BOOST_AUTO_TEST_CASE( structtype_json )
+{
+ verifyByFile<TestModule::StructType, Slicer::JsonFileDeserializer>("struct2.json", checkStruct);
+}
+
BOOST_AUTO_TEST_CASE( sequenceOfClass_xml )
{
verifyByFile<TestModule::Classes, Slicer::XmlFileDeserializer>("seqOfClass.xml", checkSeqOfClass);