diff --git a/tests/12metaprogramming.tests b/tests/12metaprogramming.tests index 8ba95bb83..c81578e4a 100644 --- a/tests/12metaprogramming.tests +++ b/tests/12metaprogramming.tests @@ -569,7 +569,11 @@ return: 0 END -PLANNED "tuple initialisation from GenNode" TupleRecordInit_test <»──(lalü,42) +out-lit: «tuple, string, int, long, double, TimeVar>»──(ID-lal,lala,12,34,5.6,548s7ms) return: 0 END diff --git a/tests/library/meta/tuple-record-init-test.cpp b/tests/library/meta/tuple-record-init-test.cpp index 50232de36..27e982119 100644 --- a/tests/library/meta/tuple-record-init-test.cpp +++ b/tests/library/meta/tuple-record-init-test.cpp @@ -19,24 +19,12 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * *****************************************************/ +///@file -/** @file tuple-record-init-test.cpp - ** Metaprogramming: how to unload the contents of a runtime typed variant sequence - ** into ctor arguments of a (compile time typed) tuple. This involves two problems - ** - how to combine iteration, compile-time indexing and run-time access. - ** - how to overcome the runtime-to-compiletime barrier, using a pre-generated - ** double-dispatch (visitor). - ** - ** The concrete problem prompting this research is the necessity to receive - ** a command invocation parameter tuple from a Record - ** - */ - -typedef unsigned int uint; #include "lib/test/run.hpp" -#include "lib/symbol.hpp" +#include "lib/test/test-helper.hpp" #include "lib/time/timevalue.hpp" #include "lib/meta/tuple-record-init.hpp" #include "lib/format-cout.hpp" @@ -57,94 +45,90 @@ using lib::meta::buildTuple; using lib::time::TimeVar; using lib::time::Time; +using lumiera::error::LUMIERA_ERROR_INDEX_BOUNDS; +using lumiera::error::LUMIERA_ERROR_WRONG_TYPE; + using std::string; using std::tuple; +using std::get; namespace lib { namespace meta { namespace test { - -////////////////////////TODO reworked for function-closure.hpp -template -struct SomeArgs - { - - template - using IdxSelector = typename lib::meta::func::PartiallyInitTuple::template IndexMapper; - - static Tuple - doIt (Tuple const& args) - { - return lib::meta::TupleConstructor (args); - } - }; -////////////////////////TODO reworked for function-closure.hpp - - - - -#define SHOW_TYPE(_TY_) \ - cout << "typeof( " << STRINGIFY(_TY_) << " )= " << lib::meta::typeStr<_TY_>() < ::value) - EVAL_PREDICATE(is_arithmetic ::value) - EVAL_PREDICATE(is_floating_point::value) - EVAL_PREDICATE(is_nonFloat ::value) - - EVAL_PREDICATE(GenNodeAccessor ::allow_Conversion ::value) - EVAL_PREDICATE(GenNodeAccessor::allow_Conversion::value) - EVAL_PREDICATE(GenNodeAccessor::allow_Conversion::value) - EVAL_PREDICATE(GenNodeAccessor::allow_Conversion ::value) - EVAL_PREDICATE(GenNodeAccessor::allow_Conversion ::value) - EVAL_PREDICATE(GenNodeAccessor::allow_Conversion::value) - EVAL_PREDICATE(GenNodeAccessor ::allow_Conversion ::value) - EVAL_PREDICATE(GenNodeAccessor ::allow_Conversion::value) - EVAL_PREDICATE(GenNodeAccessor::allow_Conversion::value) - EVAL_PREDICATE(GenNodeAccessor::allow_Conversion::value) - EVAL_PREDICATE(GenNodeAccessor ::allow_Conversion::value) - - cout < sent via the UI-Bus. + * @see ElementExtractor + * @see GenNodeAccessor + * @see BusTerm_test::commandInvocation + * @see gui::test::Nexus::prepareDiagnosticCommandHandler + * @see ui-bus.hpp UI-Bus + */ class TupleRecordInit_test : public Test { virtual void run (Arg) - { - verifyConversions(); - - using NiceTypes = Types; - using UgglyTypes = Types, string, int, int64_t, double, TimeVar>; - - Rec args = MakeRec().scope("lalü", 42); - Rec urgs = MakeRec().scope("lalü", "lala", 12, 34, 5.6, Time(7,8,9)); - - cout << args < (args) < (urgs) <::doIt(std::make_tuple("hui", 88)) <; + using UgglyTypes = Types, string, int, int64_t, double, TimeVar>; + + Rec args = MakeRec().scope("lalü", 42); + Rec urgs = MakeRec().scope("lalü", "lala", 12, 34, 5.6, Time(7,8,9)); + + cout << args < (args) < (urgs) <; + VERIFY_ERROR (INDEX_BOUNDS, buildTuple (args)); // number of types in tuple exceeds capacity of the supplied argument record + + using Unsigned = Types; + using Floating = Types; + using Narrowing = Types; + VERIFY_ERROR (WRONG_TYPE, buildTuple (args)); // dangerous conversion from signed to unsigned int is prohibited + VERIFY_ERROR (WRONG_TYPE, buildTuple (args)); // conversion from integral to floating point element is prohibited + 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)); + using TupStr = Types; + Tuple tup = buildTuple (arg1); + + CHECK (std::get (tup) == "4:03:02.001"); + CHECK (string(Time(1,2,3,4)) == "4:03:02.001"); + } + };