From 5abc44b81317e93348aa541780bd65ef5fb692f6 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Thu, 28 Jan 2016 23:30:13 +0100 Subject: [PATCH] additional coverage regarding the restrictive handling of LuidH --- tests/library/meta/tuple-record-init-test.cpp | 33 +++++++++++++++++-- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/tests/library/meta/tuple-record-init-test.cpp b/tests/library/meta/tuple-record-init-test.cpp index 27e982119..0020ed16e 100644 --- a/tests/library/meta/tuple-record-init-test.cpp +++ b/tests/library/meta/tuple-record-init-test.cpp @@ -44,6 +44,7 @@ using lib::meta::Tuple; using lib::meta::buildTuple; using lib::time::TimeVar; using lib::time::Time; +using lib::hash::LuidH; using lumiera::error::LUMIERA_ERROR_INDEX_BOUNDS; using lumiera::error::LUMIERA_ERROR_WRONG_TYPE; @@ -121,14 +122,40 @@ namespace test { VERIFY_ERROR (WRONG_TYPE, buildTuple (args)); // narrowing conversion from int to short is prohibited // yet other (non-numeric) conversions are still possible - Rec arg1 = MakeRec().scope(Time(1,2,3,4)); + Rec timeArg = MakeRec().scope(Time(1,2,3,4)); using TupStr = Types; - Tuple tup = buildTuple (arg1); + Tuple tup = buildTuple (timeArg); CHECK (std::get (tup) == "4:03:02.001"); CHECK (string(Time(1,2,3,4)) == "4:03:02.001"); + + + // conversions from LUID elements are handled restrictively + Rec hashArg = MakeRec().scope("random", LuidH()); + VERIFY_ERROR (WRONG_TYPE, buildTuple (args)); + VERIFY_ERROR (WRONG_TYPE, buildTuple (args)); + VERIFY_ERROR (WRONG_TYPE, buildTuple (args)); + + using ToSizeT = Types; + VERIFY_ERROR (WRONG_TYPE, (buildTuple (args))); // not even conversion to size_t is allowed + + struct Dummy + { + HashVal hash; + + Dummy (LuidH const& luid) + : hash(luid) + { } + }; + + using WithDummy = Types; + + Tuple tup2 = buildTuple (hashArg); // while any type explicitly constructible from LUID are permitted. + VERIFY_ERROR (WRONG_TYPE, buildTuple (args)); // building a Dummy from int(42) is disallowed, of course + + HashVal h = get(tup2).hash; + CHECK (h == hashArg.child(1).data.get()); // note: the narrowing conversion happens within LuidH::operator HashVal() } - };