summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2015-01-07 22:00:23 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2015-01-07 22:00:23 +0000
commit3bbd61689bb9faa8d628adce55403c6430e079a5 (patch)
tree4f552c601ce8f33bc0eaadc43ab61b39376fe485
parentMove mp not null to cover all cases (diff)
downloadslicer-3bbd61689bb9faa8d628adce55403c6430e079a5.tar.bz2
slicer-3bbd61689bb9faa8d628adce55403c6430e079a5.tar.xz
slicer-3bbd61689bb9faa8d628adce55403c6430e079a5.zip
Support for XML text in otherwise complex objects, test data and test case
-rw-r--r--slicer/test/initial/entityref.xml2
-rw-r--r--slicer/test/preprocessor.cpp2
-rw-r--r--slicer/test/serializers.cpp12
-rw-r--r--slicer/test/types.ice6
-rw-r--r--slicer/xml/serializer.cpp15
5 files changed, 35 insertions, 2 deletions
diff --git a/slicer/test/initial/entityref.xml b/slicer/test/initial/entityref.xml
new file mode 100644
index 0000000..05f3f62
--- /dev/null
+++ b/slicer/test/initial/entityref.xml
@@ -0,0 +1,2 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<EntityRef Id="26">Hull City</EntityRef>
diff --git a/slicer/test/preprocessor.cpp b/slicer/test/preprocessor.cpp
index 54099df..10fedef 100644
--- a/slicer/test/preprocessor.cpp
+++ b/slicer/test/preprocessor.cpp
@@ -13,7 +13,7 @@
namespace fs = boost::filesystem;
-const unsigned int COMPONENTS_IN_TEST_ICE = 26;
+const unsigned int COMPONENTS_IN_TEST_ICE = 27;
BOOST_FIXTURE_TEST_SUITE ( preprocessor, FileStructure );
diff --git a/slicer/test/serializers.cpp b/slicer/test/serializers.cpp
index 12dc37b..6395ce0 100644
--- a/slicer/test/serializers.cpp
+++ b/slicer/test/serializers.cpp
@@ -204,6 +204,13 @@ checkAssertEq(const T & expected, const T & actual)
BOOST_REQUIRE_EQUAL(expected, actual);
}
+void
+checkEntityRef(const TestModule2::EntityRef & er)
+{
+ BOOST_REQUIRE_EQUAL(er.Id, 26);
+ BOOST_REQUIRE_EQUAL(er.Name, "Hull City");
+}
+
xmlpp::Document *
readXml(const fs::path & path)
{
@@ -282,6 +289,11 @@ BOOST_AUTO_TEST_CASE( simpleint_json )
verifyByFile<Ice::Int, Slicer::JsonFileDeserializer>("int2.json", boost::bind(checkAssertEq<Ice::Int>, 27, _1));
}
+BOOST_AUTO_TEST_CASE( complexClass_xmlattrAndText )
+{
+ verifyByFile<TestModule2::EntityRef, Slicer::XmlFileDeserializer>("entityref.xml", checkEntityRef);
+}
+
BOOST_AUTO_TEST_CASE( sequenceOfClass_xml )
{
verifyByFile<TestModule::Classes, Slicer::XmlFileDeserializer>("seqOfClass.xml", checkSeqOfClass);
diff --git a/slicer/test/types.ice b/slicer/test/types.ice
index 6339cd7..7a66387 100644
--- a/slicer/test/types.ice
+++ b/slicer/test/types.ice
@@ -110,5 +110,11 @@ module TestModule2 {
TestModule::DateTime dt;
TestModule::Base base;
};
+ struct EntityRef {
+ [ "slicer:xml:attribute" ]
+ int Id;
+ [ "slicer:xml:text" ]
+ string Name;
+ };
};
diff --git a/slicer/xml/serializer.cpp b/slicer/xml/serializer.cpp
index 4670012..99c4e1c 100644
--- a/slicer/xml/serializer.cpp
+++ b/slicer/xml/serializer.cpp
@@ -10,6 +10,7 @@
namespace Slicer {
const std::string md_attribute = "xml:attribute";
+ const std::string md_text = "xml:text";
class BadBooleanValue : public std::invalid_argument {
public:
@@ -196,7 +197,16 @@ namespace Slicer {
}
}
else if (auto content = dynamic_cast<const xmlpp::ContentNode *>(node)) {
- mp->SetValue(new XmlContentValueSource(content));
+ ModelPartPtr smp;
+ if (!content->is_white_space()) {
+ smp = mp->GetChild(boost::bind(metaDataFlagSet, boost::bind(&Slicer::HookCommon::GetMetadata, _1), md_text));
+ }
+ if (smp) {
+ smp->SetValue(new XmlContentValueSource(content));
+ }
+ else {
+ mp->SetValue(new XmlContentValueSource(content));
+ }
}
node = node->get_next_sibling();
}
@@ -217,6 +227,9 @@ namespace Slicer {
if (hp && metaDataFlagSet(hp->GetMetadata(), md_attribute)) {
mp->GetValue(new XmlAttributeValueTarget(n, name));
}
+ else if (hp && metaDataFlagSet(hp->GetMetadata(), md_text)) {
+ mp->GetValue(new XmlContentValueTarget(n));
+ }
else {
ModelTreeProcessElement(n->add_child(name), mp);
}