summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <daniel.goodliffe@pressassociation.com>2015-01-07 12:33:38 +0000
committerDan Goodliffe <daniel.goodliffe@pressassociation.com>2015-01-07 12:33:38 +0000
commit2a8600e96ea8398627a24cc53f4554bcdae5f286 (patch)
tree63c17fb8717363b6fa756af5971d30db6fa9b684
parentFix xml serializer modeltreeiterateroot to work the same as iterate element part (diff)
downloadslicer-2a8600e96ea8398627a24cc53f4554bcdae5f286.tar.bz2
slicer-2a8600e96ea8398627a24cc53f4554bcdae5f286.tar.xz
slicer-2a8600e96ea8398627a24cc53f4554bcdae5f286.zip
Add support, tests and test data for simple roots
-rw-r--r--slicer/slicer/modelParts.cpp9
-rw-r--r--slicer/slicer/modelParts.h35
-rw-r--r--slicer/test/initial/int.xml2
-rw-r--r--slicer/test/initial/int2.json1
-rw-r--r--slicer/test/initial/string.xml2
-rw-r--r--slicer/test/initial/string2.json1
-rw-r--r--slicer/test/serializers.cpp27
7 files changed, 59 insertions, 18 deletions
diff --git a/slicer/slicer/modelParts.cpp b/slicer/slicer/modelParts.cpp
index 80d90cf..e2711a1 100644
--- a/slicer/slicer/modelParts.cpp
+++ b/slicer/slicer/modelParts.cpp
@@ -90,5 +90,14 @@ namespace Slicer {
{
return emptyMetadata;
}
+
+ template<> std::string Slicer::ModelPartForRoot<std::string>::rootName = "String";
+ template<> std::string Slicer::ModelPartForRoot<bool>::rootName = "Boolean";
+ template<> std::string Slicer::ModelPartForRoot<Ice::Float>::rootName = "Float";
+ template<> std::string Slicer::ModelPartForRoot<Ice::Double>::rootName = "Double";
+ template<> std::string Slicer::ModelPartForRoot<Ice::Byte>::rootName = "Byte";
+ template<> std::string Slicer::ModelPartForRoot<Ice::Short>::rootName = "Short";
+ template<> std::string Slicer::ModelPartForRoot<Ice::Int>::rootName = "Int";
+ template<> std::string Slicer::ModelPartForRoot<Ice::Long>::rootName = "Long";
}
diff --git a/slicer/slicer/modelParts.h b/slicer/slicer/modelParts.h
index 7cc6332..388fe05 100644
--- a/slicer/slicer/modelParts.h
+++ b/slicer/slicer/modelParts.h
@@ -115,16 +115,28 @@ namespace Slicer {
virtual const Metadata & GetMetadata() const = 0;
};
-#define templateMODELPARTFOR(Type, ModelPart) \
+#define templateMODELPARTFOR(Type) \
template <class T> ModelPartPtr ModelPartFor(Type & t); \
template <class T> ModelPartPtr ModelPartFor(Type * t);
- templateMODELPARTFOR(IceInternal::Handle<T>, ModelPartForClass);
- templateMODELPARTFOR(std::vector<T>, ModelPartForSequence);
- templateMODELPARTFOR(std::list<T>, ModelPartForSequence);
+#define MODELPARTFOR(Type) \
+ ModelPartPtr ModelPartFor(Type & t); \
+ ModelPartPtr ModelPartFor(Type * t);
+ templateMODELPARTFOR(IceInternal::Handle<T>);
+ templateMODELPARTFOR(std::vector<T>);
+ templateMODELPARTFOR(std::list<T>);
template <class K, class V> ModelPartPtr ModelPartFor(std::map<K, V> & t);
template <class K, class V> ModelPartPtr ModelPartFor(std::map<K, V> * t);
- templateMODELPARTFOR(T, ModelPartForStruct);
+ MODELPARTFOR(std::string);
+ MODELPARTFOR(bool);
+ MODELPARTFOR(Ice::Float);
+ MODELPARTFOR(Ice::Double);
+ MODELPARTFOR(Ice::Byte);
+ MODELPARTFOR(Ice::Short);
+ MODELPARTFOR(Ice::Int);
+ MODELPARTFOR(Ice::Long);
+ templateMODELPARTFOR(T);
#undef templateMODELPARTFOR
+#undef MODELPARTFOR
class ModelPart : public IceUtil::Shared {
public:
@@ -591,27 +603,14 @@ namespace Slicer {
#define templateMODELPARTFOR(Type, ModelPart) \
template <class T> ModelPartPtr ModelPartFor(Type & t) { return new ModelPart< Type >(t); } \
template <class T> ModelPartPtr ModelPartFor(Type * t) { return new ModelPart< Type >(t); }
-#define MODELPARTFOR(Type, ModelPart) \
- ModelPartPtr ModelPartFor(Type & t); \
- ModelPartPtr ModelPartFor(Type * t);
-
templateMODELPARTFOR(IceInternal::Handle<T>, ModelPartForClass);
templateMODELPARTFOR(std::vector<T>, ModelPartForSequence);
templateMODELPARTFOR(std::list<T>, ModelPartForSequence);
template <class K, class V> ModelPartPtr ModelPartFor(std::map<K, V> & t) { return new ModelPartForDictionary< std::map<K, V> >(t); } \
template <class K, class V> ModelPartPtr ModelPartFor(std::map<K, V> * t) { return new ModelPartForDictionary< std::map<K, V> >(t); } \
- MODELPARTFOR(std::string, ModelPartForSimple);
- MODELPARTFOR(bool, ModelPartForSimple);
- MODELPARTFOR(Ice::Float, ModelPartForSimple);
- MODELPARTFOR(Ice::Double, ModelPartForSimple);
- MODELPARTFOR(Ice::Byte, ModelPartForSimple);
- MODELPARTFOR(Ice::Short, ModelPartForSimple);
- MODELPARTFOR(Ice::Int, ModelPartForSimple);
- MODELPARTFOR(Ice::Long, ModelPartForSimple);
// Everything else is a struct?
templateMODELPARTFOR(T, ModelPartForStruct);
#undef templateMODELPARTFOR
-#undef MODELPARTFOR
}
#endif
diff --git a/slicer/test/initial/int.xml b/slicer/test/initial/int.xml
new file mode 100644
index 0000000..af15a80
--- /dev/null
+++ b/slicer/test/initial/int.xml
@@ -0,0 +1,2 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Int>27</Int>
diff --git a/slicer/test/initial/int2.json b/slicer/test/initial/int2.json
new file mode 100644
index 0000000..a5c750f
--- /dev/null
+++ b/slicer/test/initial/int2.json
@@ -0,0 +1 @@
+27 \ No newline at end of file
diff --git a/slicer/test/initial/string.xml b/slicer/test/initial/string.xml
new file mode 100644
index 0000000..8812534
--- /dev/null
+++ b/slicer/test/initial/string.xml
@@ -0,0 +1,2 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<String>test string</String>
diff --git a/slicer/test/initial/string2.json b/slicer/test/initial/string2.json
new file mode 100644
index 0000000..31825f5
--- /dev/null
+++ b/slicer/test/initial/string2.json
@@ -0,0 +1 @@
+"test string" \ No newline at end of file
diff --git a/slicer/test/serializers.cpp b/slicer/test/serializers.cpp
index 107a2ba..12dc37b 100644
--- a/slicer/test/serializers.cpp
+++ b/slicer/test/serializers.cpp
@@ -197,6 +197,13 @@ checkStruct(const TestModule::StructType & st)
BOOST_REQUIRE_EQUAL(st.b, 13);
}
+template<class T>
+void
+checkAssertEq(const T & expected, const T & actual)
+{
+ BOOST_REQUIRE_EQUAL(expected, actual);
+}
+
xmlpp::Document *
readXml(const fs::path & path)
{
@@ -255,6 +262,26 @@ BOOST_AUTO_TEST_CASE( structtype_json )
verifyByFile<TestModule::StructType, Slicer::JsonFileDeserializer>("struct2.json", checkStruct);
}
+BOOST_AUTO_TEST_CASE( simplestring_xml )
+{
+ verifyByFile<std::string, Slicer::XmlFileDeserializer>("string.xml", boost::bind(checkAssertEq<std::string>, "test string", _1));
+}
+
+BOOST_AUTO_TEST_CASE( simpleint_xml )
+{
+ verifyByFile<Ice::Int, Slicer::XmlFileDeserializer>("int.xml", boost::bind(checkAssertEq<Ice::Int>, 27, _1));
+}
+
+BOOST_AUTO_TEST_CASE( simplestring_json )
+{
+ verifyByFile<std::string, Slicer::JsonFileDeserializer>("string2.json", boost::bind(checkAssertEq<std::string>, "test string", _1));
+}
+
+BOOST_AUTO_TEST_CASE( simpleint_json )
+{
+ verifyByFile<Ice::Int, Slicer::JsonFileDeserializer>("int2.json", boost::bind(checkAssertEq<Ice::Int>, 27, _1));
+}
+
BOOST_AUTO_TEST_CASE( sequenceOfClass_xml )
{
verifyByFile<TestModule::Classes, Slicer::XmlFileDeserializer>("seqOfClass.xml", checkSeqOfClass);