summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2015-10-16 20:51:06 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2015-10-16 20:51:06 +0100
commitaa2a9f4da591509858b011f5aacc7cfc742821ff (patch)
tree3b299eccd0a2c66b3ac6e83cce5a430c1dcbc9e6
parentExclude BOOST_TEST_DONT_PRINT_LOG_VALUE code (diff)
downloadslicer-aa2a9f4da591509858b011f5aacc7cfc742821ff.tar.bz2
slicer-aa2a9f4da591509858b011f5aacc7cfc742821ff.tar.xz
slicer-aa2a9f4da591509858b011f5aacc7cfc742821ff.zip
Improve test coverage.
Fix empty xml element handling to still call into children with empty content
-rw-r--r--slicer/test/initial/builtins3.json2
-rw-r--r--slicer/test/serializers.cpp18
-rw-r--r--slicer/xml/Jamfile.jam20
-rw-r--r--slicer/xml/serializer.cpp23
-rw-r--r--slicer/xml/serializer.h5
-rw-r--r--slicer/xml/testSpecifics.cpp48
6 files changed, 107 insertions, 9 deletions
diff --git a/slicer/test/initial/builtins3.json b/slicer/test/initial/builtins3.json
new file mode 100644
index 0000000..753395b
--- /dev/null
+++ b/slicer/test/initial/builtins3.json
@@ -0,0 +1,2 @@
+{"mbool":false,"mbyte":255,"mdouble":-3.0625,"mfloat":-3.125,"mint":-80,"mlong":-800,"mshort":-40,"mstring":"-Sample text-"}
+
diff --git a/slicer/test/serializers.cpp b/slicer/test/serializers.cpp
index e381c6d..0d309dc 100644
--- a/slicer/test/serializers.cpp
+++ b/slicer/test/serializers.cpp
@@ -115,6 +115,19 @@ checkBuiltIns_valuesCorrect(const TestModule::BuiltInsPtr & bt)
}
void
+checkBuiltIns3_valuesCorrect(const TestModule::BuiltInsPtr & bt)
+{
+ BOOST_REQUIRE_EQUAL(bt->mbool, false);
+ BOOST_REQUIRE_EQUAL(bt->mbyte, 255);
+ BOOST_REQUIRE_EQUAL(bt->mshort, -40);
+ BOOST_REQUIRE_EQUAL(bt->mint, -80);
+ BOOST_REQUIRE_EQUAL(bt->mlong, -800);
+ BOOST_REQUIRE_EQUAL(bt->mfloat, -3.125);
+ BOOST_REQUIRE_EQUAL(bt->mdouble, -3.0625);
+ BOOST_REQUIRE_EQUAL(bt->mstring, "-Sample text-");
+}
+
+void
checkInherits_types(const TestModule::InheritanceContPtr & i)
{
BOOST_REQUIRE(i->b);
@@ -359,6 +372,11 @@ BOOST_AUTO_TEST_CASE( builtins2_json )
verifyByFile<TestModule::BuiltInsPtr, Slicer::JsonFileDeserializer>("builtins2.json", checkBuiltIns_valuesCorrect);
}
+BOOST_AUTO_TEST_CASE( builtins3_json )
+{
+ verifyByFile<TestModule::BuiltInsPtr, Slicer::JsonFileDeserializer>("builtins3.json", checkBuiltIns3_valuesCorrect);
+}
+
BOOST_AUTO_TEST_CASE( optionals_areset2_json )
{
verifyByFile<TestModule::OptionalsPtr, Slicer::JsonFileDeserializer>("optionals-areset2.json", checkOptionals_areset);
diff --git a/slicer/xml/Jamfile.jam b/slicer/xml/Jamfile.jam
index ed2fbf1..7b07545 100644
--- a/slicer/xml/Jamfile.jam
+++ b/slicer/xml/Jamfile.jam
@@ -1,13 +1,16 @@
+import testing ;
+
alias libxmlpp : : : :
<cflags>"`pkg-config --cflags libxml++-2.6`"
<linkflags>"`pkg-config --libs libxml++-2.6`" ;
lib boost_system ;
lib boost_filesystem ;
+lib boost_utf : : <name>boost_unit_test_framework ;
lib IceUtil ;
lib adhocutil : : : : <include>/usr/include/adhocutil ;
lib slicer-xml :
- [ glob *.cpp ]
+ [ glob *.cpp : test*.cpp ]
:
<include>..
<library>boost_system
@@ -21,3 +24,18 @@ lib slicer-xml :
: :
<library>libxmlpp
;
+
+run testSpecifics.cpp
+ : : :
+ <define>BOOST_TEST_DYN_LINK
+ <library>slicer-xml
+ <library>boost_utf
+ <library>../test//slicer-test
+ <library>../test//common
+ <library>../slicer//slicer
+ <include>..
+ <dependency>../test//compilation
+ :
+ testSpecifics
+ ;
+
diff --git a/slicer/xml/serializer.cpp b/slicer/xml/serializer.cpp
index 225a1b3..6f5df3a 100644
--- a/slicer/xml/serializer.cpp
+++ b/slicer/xml/serializer.cpp
@@ -14,13 +14,10 @@ namespace Slicer {
const std::string md_bare = "xml:bare";
const auto defaultElementCreator = boost::bind(&xmlpp::Element::add_child, _1, _2, Glib::ustring());
- class BadBooleanValue : public std::invalid_argument {
- public:
- BadBooleanValue(const Glib::ustring &) :
- std::invalid_argument("Bad boolean value")
- {
- }
- };
+ BadBooleanValue::BadBooleanValue(const Glib::ustring &) :
+ std::invalid_argument("Bad boolean value")
+ {
+ }
static const Glib::ustring TrueText("true");
static const Glib::ustring FalseText("false");
@@ -80,6 +77,10 @@ namespace Slicer {
class XmlContentValueSource : public XmlValueSource {
public:
+ XmlContentValueSource() :
+ XmlValueSource(Glib::ustring())
+ {
+ }
XmlContentValueSource(const xmlpp::ContentNode * c) :
XmlValueSource(c->get_content())
{
@@ -190,7 +191,13 @@ namespace Slicer {
if (!attrs.empty()) {
DocumentTreeIterate(attrs.front(), smp);
}
- DocumentTreeIterate(element->get_first_child(), smp);
+ auto firstChild = element->get_first_child();
+ if (firstChild) {
+ DocumentTreeIterate(firstChild, smp);
+ }
+ else {
+ smp->SetValue(new XmlContentValueSource());
+ }
smp->Complete();
}
}
diff --git a/slicer/xml/serializer.h b/slicer/xml/serializer.h
index f50435e..a57e846 100644
--- a/slicer/xml/serializer.h
+++ b/slicer/xml/serializer.h
@@ -6,6 +6,11 @@
#include <visibility.h>
namespace Slicer {
+ class BadBooleanValue : public std::invalid_argument {
+ public:
+ BadBooleanValue(const Glib::ustring &);
+ };
+
class XmlSerializer : public Serializer {
protected:
typedef boost::function<xmlpp::Element *(xmlpp::Element *, const Glib::ustring &)> ElementCreator;
diff --git a/slicer/xml/testSpecifics.cpp b/slicer/xml/testSpecifics.cpp
new file mode 100644
index 0000000..20f65fe
--- /dev/null
+++ b/slicer/xml/testSpecifics.cpp
@@ -0,0 +1,48 @@
+#define BOOST_TEST_MODULE db_insert
+#include <boost/test/unit_test.hpp>
+#include <slicer/slicer.h>
+#include "serializer.h"
+#include <libxml++/parsers/domparser.h>
+#include <types.h>
+
+template <typename T, typename ... P>
+T
+BoostThrowWrapperHelper(P && ... p)
+{
+ return Slicer::DeserializeAny<Slicer::XmlDocumentDeserializer, T>(p...);
+}
+
+BOOST_AUTO_TEST_CASE( boolean_values )
+{
+ xmlpp::DomParser doc;
+ doc.parse_memory("<Boolean>true</Boolean>");
+ BOOST_REQUIRE_EQUAL(true, BoostThrowWrapperHelper<bool>(doc.get_document()));
+ doc.parse_memory("<Boolean>false</Boolean>");
+ BOOST_REQUIRE_EQUAL(false, BoostThrowWrapperHelper<bool>(doc.get_document()));
+ doc.parse_memory("<Boolean>nonsense</Boolean>");
+ BOOST_REQUIRE_THROW(BoostThrowWrapperHelper<bool>(doc.get_document()), Slicer::BadBooleanValue);
+ doc.parse_memory("<Boolean> </Boolean>");
+ BOOST_REQUIRE_THROW(BoostThrowWrapperHelper<bool>(doc.get_document()), Slicer::BadBooleanValue);
+ doc.parse_memory("<Boolean></Boolean>");
+ BOOST_REQUIRE_THROW(BoostThrowWrapperHelper<bool>(doc.get_document()), Slicer::BadBooleanValue);
+}
+
+BOOST_AUTO_TEST_CASE( int_values )
+{
+ xmlpp::DomParser doc;
+ doc.parse_memory("<Int>13</Int>");
+ BOOST_REQUIRE_EQUAL(13, BoostThrowWrapperHelper<Ice::Int>(doc.get_document()));
+ doc.parse_memory("<Int>84</Int>");
+ BOOST_REQUIRE_EQUAL(84, BoostThrowWrapperHelper<Ice::Int>(doc.get_document()));
+ doc.parse_memory("<Int>0</Int>");
+ BOOST_REQUIRE_EQUAL(0, BoostThrowWrapperHelper<Ice::Int>(doc.get_document()));
+ doc.parse_memory("<Int>-4</Int>");
+ BOOST_REQUIRE_EQUAL(-4, BoostThrowWrapperHelper<Ice::Int>(doc.get_document()));
+ doc.parse_memory("<Int> </Int>");
+ BOOST_REQUIRE_THROW(BoostThrowWrapperHelper<Ice::Int>(doc.get_document()), std::bad_cast);
+ doc.parse_memory("<Int>notanint</Int>");
+ BOOST_REQUIRE_THROW(BoostThrowWrapperHelper<Ice::Int>(doc.get_document()), std::bad_cast);
+ doc.parse_memory("<Int></Int>");
+ BOOST_REQUIRE_THROW(BoostThrowWrapperHelper<Ice::Int>(doc.get_document()), std::bad_cast);
+}
+