From 2a8600e96ea8398627a24cc53f4554bcdae5f286 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Wed, 7 Jan 2015 12:33:38 +0000 Subject: Add support, tests and test data for simple roots --- slicer/slicer/modelParts.cpp | 9 +++++++++ slicer/slicer/modelParts.h | 35 +++++++++++++++++------------------ slicer/test/initial/int.xml | 2 ++ slicer/test/initial/int2.json | 1 + slicer/test/initial/string.xml | 2 ++ slicer/test/initial/string2.json | 1 + slicer/test/serializers.cpp | 27 +++++++++++++++++++++++++++ 7 files changed, 59 insertions(+), 18 deletions(-) create mode 100644 slicer/test/initial/int.xml create mode 100644 slicer/test/initial/int2.json create mode 100644 slicer/test/initial/string.xml create mode 100644 slicer/test/initial/string2.json 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::rootName = "String"; + template<> std::string Slicer::ModelPartForRoot::rootName = "Boolean"; + template<> std::string Slicer::ModelPartForRoot::rootName = "Float"; + template<> std::string Slicer::ModelPartForRoot::rootName = "Double"; + template<> std::string Slicer::ModelPartForRoot::rootName = "Byte"; + template<> std::string Slicer::ModelPartForRoot::rootName = "Short"; + template<> std::string Slicer::ModelPartForRoot::rootName = "Int"; + template<> std::string Slicer::ModelPartForRoot::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 ModelPartPtr ModelPartFor(Type & t); \ template ModelPartPtr ModelPartFor(Type * t); - templateMODELPARTFOR(IceInternal::Handle, ModelPartForClass); - templateMODELPARTFOR(std::vector, ModelPartForSequence); - templateMODELPARTFOR(std::list, ModelPartForSequence); +#define MODELPARTFOR(Type) \ + ModelPartPtr ModelPartFor(Type & t); \ + ModelPartPtr ModelPartFor(Type * t); + templateMODELPARTFOR(IceInternal::Handle); + templateMODELPARTFOR(std::vector); + templateMODELPARTFOR(std::list); template ModelPartPtr ModelPartFor(std::map & t); template ModelPartPtr ModelPartFor(std::map * 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 ModelPartPtr ModelPartFor(Type & t) { return new ModelPart< Type >(t); } \ template ModelPartPtr ModelPartFor(Type * t) { return new ModelPart< Type >(t); } -#define MODELPARTFOR(Type, ModelPart) \ - ModelPartPtr ModelPartFor(Type & t); \ - ModelPartPtr ModelPartFor(Type * t); - templateMODELPARTFOR(IceInternal::Handle, ModelPartForClass); templateMODELPARTFOR(std::vector, ModelPartForSequence); templateMODELPARTFOR(std::list, ModelPartForSequence); template ModelPartPtr ModelPartFor(std::map & t) { return new ModelPartForDictionary< std::map >(t); } \ template ModelPartPtr ModelPartFor(std::map * t) { return new ModelPartForDictionary< std::map >(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 @@ + +27 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 @@ + +test 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 +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("struct2.json", checkStruct); } +BOOST_AUTO_TEST_CASE( simplestring_xml ) +{ + verifyByFile("string.xml", boost::bind(checkAssertEq, "test string", _1)); +} + +BOOST_AUTO_TEST_CASE( simpleint_xml ) +{ + verifyByFile("int.xml", boost::bind(checkAssertEq, 27, _1)); +} + +BOOST_AUTO_TEST_CASE( simplestring_json ) +{ + verifyByFile("string2.json", boost::bind(checkAssertEq, "test string", _1)); +} + +BOOST_AUTO_TEST_CASE( simpleint_json ) +{ + verifyByFile("int2.json", boost::bind(checkAssertEq, 27, _1)); +} + BOOST_AUTO_TEST_CASE( sequenceOfClass_xml ) { verifyByFile("seqOfClass.xml", checkSeqOfClass); -- cgit v1.2.3