From 5d06059ccb60f8babf72c551f14500ad63cc6080 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 24 Sep 2016 13:26:22 +0100 Subject: Support for custom model parts --- slicer/slicer/modelPartsTypes.impl.h | 2 +- slicer/test/conversions.cpp | 40 +++++++++++++++++++++++++++++++++++- slicer/test/conversions.h | 18 +++++++++++++++- slicer/test/initial/isodate.xml | 6 ++++++ slicer/test/serializers.cpp | 11 ++++++++++ slicer/test/types.ice | 2 ++ slicer/tool/parser.cpp | 4 ++++ 7 files changed, 80 insertions(+), 3 deletions(-) create mode 100644 slicer/test/initial/isodate.xml 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 +#include "common.h" #define MODELPARTFOR(Type, ModelPartType) \ template class ModelPartType; \ 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 #include @@ -104,3 +104,41 @@ namespace Slicer { } } +namespace TestModule { + int completions = 0; + + AbValidator::AbValidator(ClassTypePtr & m) : + Slicer::ModelPartForClass(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::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 #include +#include +#include namespace TestModule { - class DateTime; + DLL_PUBLIC extern int completions; + + class DLL_PUBLIC AbValidator : public Slicer::ModelPartForClass { + 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 @@ + + + 2016 + 6 + 31 + 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 #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("optionals-areset.xml", readXml, writeXml, freeXml, checkOptionals_areset); } +BOOST_AUTO_TEST_CASE( simple_complete_validator ) +{ + verifyByHelper("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"); -- cgit v1.2.3