From b711e23dc10c222f3e141d8a733b360559f338b6 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Thu, 30 Jun 2016 22:51:50 +0100 Subject: Fix case of type level metadata not being picked up if the type is a class --- slicer/db/testInsert.cpp | 7 +++++-- slicer/db/testSelect.cpp | 8 ++++---- slicer/slicer/parser.cpp | 3 +++ slicer/test/conversions.cpp | 8 ++++---- slicer/test/types.ice | 2 +- 5 files changed, 17 insertions(+), 11 deletions(-) diff --git a/slicer/db/testInsert.cpp b/slicer/db/testInsert.cpp index 2068de3..e2118b8 100644 --- a/slicer/db/testInsert.cpp +++ b/slicer/db/testInsert.cpp @@ -144,14 +144,17 @@ BOOST_AUTO_TEST_CASE( insert_converted ) DB::SpecificTypesPtr st = new DB::SpecificTypes { {2015, 10, 16, 19, 12, 34}, {2015, 10, 16}, - {1, 2, 3, 4} + new DB::Timespan(1, 2, 3, 4) }; Slicer::SerializeAny(st, db.get(), "converted"); auto sel = SelectPtr(db->newSelectCommand("SELECT * FROM converted")); auto st2 = Slicer::DeserializeAny(*sel); BOOST_REQUIRE_EQUAL(st->date, st2->date); BOOST_REQUIRE_EQUAL(st->dt, st2->dt); - BOOST_REQUIRE_EQUAL(st->ts, st2->ts); + BOOST_REQUIRE_EQUAL(st->ts->days, st2->ts->days); + BOOST_REQUIRE_EQUAL(st->ts->hours, st2->ts->hours); + BOOST_REQUIRE_EQUAL(st->ts->minutes, st2->ts->minutes); + BOOST_REQUIRE_EQUAL(st->ts->seconds, st2->ts->seconds); } BOOST_AUTO_TEST_CASE( insert_unsupportedModel ) diff --git a/slicer/db/testSelect.cpp b/slicer/db/testSelect.cpp index afea1d3..b5664a1 100644 --- a/slicer/db/testSelect.cpp +++ b/slicer/db/testSelect.cpp @@ -141,10 +141,10 @@ BOOST_AUTO_TEST_CASE( select_inherit_datetime ) BOOST_REQUIRE_EQUAL(2015, bi->date.year); BOOST_REQUIRE_EQUAL(3, bi->date.month); BOOST_REQUIRE_EQUAL(27, bi->date.day); - BOOST_REQUIRE_EQUAL(1, bi->ts.days); - BOOST_REQUIRE_EQUAL(13, bi->ts.hours); - BOOST_REQUIRE_EQUAL(13, bi->ts.minutes); - BOOST_REQUIRE_EQUAL(12, bi->ts.seconds); + BOOST_REQUIRE_EQUAL(1, bi->ts->days); + BOOST_REQUIRE_EQUAL(13, bi->ts->hours); + BOOST_REQUIRE_EQUAL(13, bi->ts->minutes); + BOOST_REQUIRE_EQUAL(12, bi->ts->seconds); } template diff --git a/slicer/slicer/parser.cpp b/slicer/slicer/parser.cpp index 1159fee..7e795be 100644 --- a/slicer/slicer/parser.cpp +++ b/slicer/slicer/parser.cpp @@ -548,6 +548,9 @@ namespace Slicer { auto conversions = getConversions(dm->getMetaData()); auto typec = Slice::ContainedPtr::dynamicCast(dm->type()); if (typec) { + if (auto cd = Slice::ClassDeclPtr::dynamicCast(typec)) { + typec = cd->definition(); + } auto typeConversions = getConversions(typec->getMetaData()); std::copy(typeConversions.begin(), typeConversions.end(), std::back_inserter(conversions)); } diff --git a/slicer/test/conversions.cpp b/slicer/test/conversions.cpp index 5f7e699..aaad378 100644 --- a/slicer/test/conversions.cpp +++ b/slicer/test/conversions.cpp @@ -89,17 +89,17 @@ namespace Slicer { } DLL_PUBLIC - ::DB::Timespan + ::DB::TimespanPtr timedurationToTimespan(const boost::posix_time::time_duration & td) { - return ::DB::Timespan({ SHORT(td.hours() / 24), SHORT(td.hours() % 24), SHORT(td.minutes()), SHORT(td.seconds()) }); + return new ::DB::Timespan(SHORT(td.hours() / 24), SHORT(td.hours() % 24), SHORT(td.minutes()), SHORT(td.seconds())); } DLL_PUBLIC boost::posix_time::time_duration - timespanToTimeduration(const ::DB::Timespan & ts) + timespanToTimeduration(const ::DB::TimespanPtr & ts) { - return boost::posix_time::time_duration((ts.days * 24) + ts.hours, ts.minutes, ts.seconds); + return boost::posix_time::time_duration((ts->days * 24) + ts->hours, ts->minutes, ts->seconds); } } diff --git a/slicer/test/types.ice b/slicer/test/types.ice index 97df71b..b119df0 100644 --- a/slicer/test/types.ice +++ b/slicer/test/types.ice @@ -152,7 +152,7 @@ module TestModule2 { module DB { [ "slicer:conversion:boost.posix_time.time_duration:timedurationToTimespan:timespanToTimeduration" ] - struct Timespan { + class Timespan { int days; short hours; short minutes; -- cgit v1.2.3