summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2016-09-24 13:26:22 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2016-09-24 14:03:59 +0100
commit5d06059ccb60f8babf72c551f14500ad63cc6080 (patch)
tree5d90ff95c42dae949f304b288999648e713be234
parentBuild test case libs with bjam, not a messy set of tests (diff)
downloadslicer-5d06059ccb60f8babf72c551f14500ad63cc6080.tar.bz2
slicer-5d06059ccb60f8babf72c551f14500ad63cc6080.tar.xz
slicer-5d06059ccb60f8babf72c551f14500ad63cc6080.zip
Support for custom model parts
-rw-r--r--slicer/slicer/modelPartsTypes.impl.h2
-rw-r--r--slicer/test/conversions.cpp40
-rw-r--r--slicer/test/conversions.h18
-rw-r--r--slicer/test/initial/isodate.xml6
-rw-r--r--slicer/test/serializers.cpp11
-rw-r--r--slicer/test/types.ice2
-rw-r--r--slicer/tool/parser.cpp4
7 files changed, 80 insertions, 3 deletions
diff --git a/slicer/slicer/modelPartsTypes.impl.h b/slicer/slicer/modelPartsTypes.impl.h
index e38d307..a7b43bd 100644
--- a/slicer/slicer/modelPartsTypes.impl.h
+++ b/slicer/slicer/modelPartsTypes.impl.h
@@ -2,7 +2,7 @@
#define SLICER_MODELPARTSTYPES_IMPL_H
#include "modelPartsTypes.h"
-#include <common.h>
+#include "common.h"
#define MODELPARTFOR(Type, ModelPartType) \
template class ModelPartType<Type>; \
diff --git a/slicer/test/conversions.cpp b/slicer/test/conversions.cpp
index 9f79f2e..af3afcd 100644
--- a/slicer/test/conversions.cpp
+++ b/slicer/test/conversions.cpp
@@ -1,4 +1,4 @@
-#include "types.h"
+#include "conversions.h"
#include <boost/numeric/conversion/cast.hpp>
#include <visibility.h>
@@ -104,3 +104,41 @@ namespace Slicer {
}
}
+namespace TestModule {
+ int completions = 0;
+
+ AbValidator::AbValidator(ClassTypePtr & m) :
+ Slicer::ModelPartForClass<ClassTypePtr>(m)
+ {
+ }
+
+ void
+ AbValidator::Complete()
+ {
+ if (this->Model->a == 0 || this->Model->b == 0) {
+ // LCOV_EXCL_START
+ throw std::runtime_error("Mock error");
+ // LCOV_EXCL_STOP
+ }
+ Slicer::ModelPartForClass<ClassTypePtr>::Complete();
+ completions += 1;
+ }
+
+ MonthValidator::MonthValidator(::Ice::Short & m) :
+ Slicer::ModelPartForSimple<::Ice::Short>(m)
+ {
+ }
+
+ void
+ MonthValidator::Complete()
+ {
+ if (this->Model < 1 || this->Model > 12) {
+ // LCOV_EXCL_START
+ throw std::runtime_error("This date smells fishy.");
+ // LCOV_EXCL_STOP
+ }
+ Slicer::ModelPartForSimple<::Ice::Short>::Complete();
+ completions += 1;
+ }
+}
+
diff --git a/slicer/test/conversions.h b/slicer/test/conversions.h
index 4fa2527..e33b670 100644
--- a/slicer/test/conversions.h
+++ b/slicer/test/conversions.h
@@ -3,9 +3,25 @@
#include <boost/date_time/posix_time/posix_time_types.hpp>
#include <visibility.h>
+#include <slicer/modelPartsTypes.h>
+#include <types.h>
namespace TestModule {
- class DateTime;
+ DLL_PUBLIC extern int completions;
+
+ class DLL_PUBLIC AbValidator : public Slicer::ModelPartForClass<ClassTypePtr> {
+ public:
+ AbValidator(ClassTypePtr &);
+
+ void Complete() override;
+ };
+
+ class DLL_PUBLIC MonthValidator : public Slicer::ModelPartForSimple<::Ice::Short> {
+ public:
+ MonthValidator(::Ice::Short &);
+
+ void Complete() override;
+ };
}
namespace Slicer {
DLL_PUBLIC
diff --git a/slicer/test/initial/isodate.xml b/slicer/test/initial/isodate.xml
new file mode 100644
index 0000000..9cc2f7c
--- /dev/null
+++ b/slicer/test/initial/isodate.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<IsoDate>
+ <year>2016</year>
+ <month>6</month>
+ <day>31</day>
+</IsoDate>
diff --git a/slicer/test/serializers.cpp b/slicer/test/serializers.cpp
index 9c4b406..65bc8cd 100644
--- a/slicer/test/serializers.cpp
+++ b/slicer/test/serializers.cpp
@@ -16,6 +16,7 @@
#include <fstream>
#include "helpers.h"
#include "fileStructure.h"
+#include "conversions.h"
namespace fs = boost::filesystem;
@@ -515,6 +516,11 @@ BOOST_AUTO_TEST_CASE( optionals_areset_xml )
verifyByHelper<TestModule::OptionalsPtr, Slicer::XmlDocumentDeserializer, Slicer::XmlDocumentSerializer, xmlpp::Document *>("optionals-areset.xml", readXml, writeXml, freeXml, checkOptionals_areset);
}
+BOOST_AUTO_TEST_CASE( simple_complete_validator )
+{
+ verifyByHelper<TestModule::IsoDate, Slicer::XmlDocumentDeserializer, Slicer::XmlDocumentSerializer, xmlpp::Document *>("isodate.xml", readXml, writeXml, freeXml);
+}
+
BOOST_AUTO_TEST_CASE( missingConversion )
{
auto in = json::parseValue("{\"conv\": \"2016-06-30 12:34:56\"}");
@@ -576,3 +582,8 @@ BOOST_AUTO_TEST_SUITE_END();
BOOST_AUTO_TEST_SUITE_END();
+BOOST_AUTO_TEST_CASE( customerModelPartCounters )
+{
+ BOOST_REQUIRE_EQUAL(7, TestModule::completions);
+}
+
diff --git a/slicer/test/types.ice b/slicer/test/types.ice
index e7811d0..bdc8da8 100644
--- a/slicer/test/types.ice
+++ b/slicer/test/types.ice
@@ -20,6 +20,7 @@ module TestModule {
[ "slicer:conversion:std.string:stringToIsoDate:isoDateToString" ]
struct IsoDate {
short year;
+ [ "slicer:custommodelpart:TestModule.MonthValidator" ]
short month;
short day;
};
@@ -42,6 +43,7 @@ module TestModule {
double mdouble;
string mstring;
};
+ [ "slicer:custommodelpart:TestModule.AbValidator" ]
class ClassType {
int a;
int b;
diff --git a/slicer/tool/parser.cpp b/slicer/tool/parser.cpp
index 425e688..99d3f5f 100644
--- a/slicer/tool/parser.cpp
+++ b/slicer/tool/parser.cpp
@@ -492,6 +492,10 @@ namespace Slicer {
boost::algorithm::trim_right_copy_if(dm->container()->thisScope(), ispunct),
dm->scoped());
}
+ else if (auto cmp = metaDataValue("slicer:custommodelpart:", md)) {
+ fprintbf(cpp, "%s",
+ boost::algorithm::replace_all_copy(*cmp, ".", "::"));
+ }
else {
if (auto builtin = Slice::BuiltinPtr::dynamicCast(type)) {
fprintbf(cpp, "ModelPartForSimple");