2016-01-28 15:37:35 +01:00
|
|
|
|
/*
|
|
|
|
|
|
TupleRecordInit(Test) - to build a tuple from a GenNode sequence
|
|
|
|
|
|
|
Copyright: clarify and simplify the file headers
* Lumiera source code always was copyrighted by individual contributors
* there is no entity "Lumiera.org" which holds any copyrights
* Lumiera source code is provided under the GPL Version 2+
== Explanations ==
Lumiera as a whole is distributed under Copyleft, GNU General Public License Version 2 or above.
For this to become legally effective, the ''File COPYING in the root directory is sufficient.''
The licensing header in each file is not strictly necessary, yet considered good practice;
attaching a licence notice increases the likeliness that this information is retained
in case someone extracts individual code files. However, it is not by the presence of some
text, that legally binding licensing terms become effective; rather the fact matters that a
given piece of code was provably copyrighted and published under a license. Even reformatting
the code, renaming some variables or deleting parts of the code will not alter this legal
situation, but rather creates a derivative work, which is likewise covered by the GPL!
The most relevant information in the file header is the notice regarding the
time of the first individual copyright claim. By virtue of this initial copyright,
the first author is entitled to choose the terms of licensing. All further
modifications are permitted and covered by the License. The specific wording
or format of the copyright header is not legally relevant, as long as the
intention to publish under the GPL remains clear. The extended wording was
based on a recommendation by the FSF. It can be shortened, because the full terms
of the license are provided alongside the distribution, in the file COPYING.
2024-11-17 23:42:55 +01:00
|
|
|
|
Copyright (C)
|
|
|
|
|
|
2016, Hermann Vosseler <Ichthyostega@web.de>
|
2016-01-28 15:37:35 +01:00
|
|
|
|
|
Copyright: clarify and simplify the file headers
* Lumiera source code always was copyrighted by individual contributors
* there is no entity "Lumiera.org" which holds any copyrights
* Lumiera source code is provided under the GPL Version 2+
== Explanations ==
Lumiera as a whole is distributed under Copyleft, GNU General Public License Version 2 or above.
For this to become legally effective, the ''File COPYING in the root directory is sufficient.''
The licensing header in each file is not strictly necessary, yet considered good practice;
attaching a licence notice increases the likeliness that this information is retained
in case someone extracts individual code files. However, it is not by the presence of some
text, that legally binding licensing terms become effective; rather the fact matters that a
given piece of code was provably copyrighted and published under a license. Even reformatting
the code, renaming some variables or deleting parts of the code will not alter this legal
situation, but rather creates a derivative work, which is likewise covered by the GPL!
The most relevant information in the file header is the notice regarding the
time of the first individual copyright claim. By virtue of this initial copyright,
the first author is entitled to choose the terms of licensing. All further
modifications are permitted and covered by the License. The specific wording
or format of the copyright header is not legally relevant, as long as the
intention to publish under the GPL remains clear. The extended wording was
based on a recommendation by the FSF. It can be shortened, because the full terms
of the license are provided alongside the distribution, in the file COPYING.
2024-11-17 23:42:55 +01:00
|
|
|
|
**Lumiera** is free software; you can redistribute it and/or modify it
|
|
|
|
|
|
under the terms of the GNU General Public License as published by the
|
|
|
|
|
|
Free Software Foundation; either version 2 of the License, or (at your
|
|
|
|
|
|
option) any later version. See the file COPYING for further details.
|
2016-01-28 15:37:35 +01:00
|
|
|
|
|
Copyright: clarify and simplify the file headers
* Lumiera source code always was copyrighted by individual contributors
* there is no entity "Lumiera.org" which holds any copyrights
* Lumiera source code is provided under the GPL Version 2+
== Explanations ==
Lumiera as a whole is distributed under Copyleft, GNU General Public License Version 2 or above.
For this to become legally effective, the ''File COPYING in the root directory is sufficient.''
The licensing header in each file is not strictly necessary, yet considered good practice;
attaching a licence notice increases the likeliness that this information is retained
in case someone extracts individual code files. However, it is not by the presence of some
text, that legally binding licensing terms become effective; rather the fact matters that a
given piece of code was provably copyrighted and published under a license. Even reformatting
the code, renaming some variables or deleting parts of the code will not alter this legal
situation, but rather creates a derivative work, which is likewise covered by the GPL!
The most relevant information in the file header is the notice regarding the
time of the first individual copyright claim. By virtue of this initial copyright,
the first author is entitled to choose the terms of licensing. All further
modifications are permitted and covered by the License. The specific wording
or format of the copyright header is not legally relevant, as long as the
intention to publish under the GPL remains clear. The extended wording was
based on a recommendation by the FSF. It can be shortened, because the full terms
of the license are provided alongside the distribution, in the file COPYING.
2024-11-17 23:42:55 +01:00
|
|
|
|
* *****************************************************************/
|
2016-11-03 18:20:10 +01:00
|
|
|
|
|
2017-02-22 01:54:20 +01:00
|
|
|
|
/** @file tuple-record-init-test.cpp
|
2017-02-22 03:17:18 +01:00
|
|
|
|
** unit test \ref TupleRecordInit_test
|
2016-11-03 18:20:10 +01:00
|
|
|
|
*/
|
2016-01-28 15:37:35 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "lib/test/run.hpp"
|
2016-01-28 22:39:38 +01:00
|
|
|
|
#include "lib/test/test-helper.hpp"
|
2016-01-28 15:37:35 +01:00
|
|
|
|
#include "lib/time/timevalue.hpp"
|
|
|
|
|
|
#include "lib/meta/tuple-record-init.hpp"
|
|
|
|
|
|
#include "lib/format-cout.hpp"
|
|
|
|
|
|
#include "lib/format-util.hpp"
|
|
|
|
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
|
|
2017-04-09 01:34:18 +02:00
|
|
|
|
using lib::Symbol;
|
2016-01-28 15:37:35 +01:00
|
|
|
|
using lib::Variant;
|
|
|
|
|
|
using lib::idi::EntryID;
|
|
|
|
|
|
using lib::diff::Rec;
|
|
|
|
|
|
using lib::diff::MakeRec;
|
|
|
|
|
|
using lib::diff::GenNode;
|
2025-06-02 02:24:09 +02:00
|
|
|
|
using lib::meta::TyOLD;
|
2016-01-28 15:37:35 +01:00
|
|
|
|
using lib::meta::Tuple;
|
|
|
|
|
|
using lib::meta::buildTuple;
|
2016-02-07 02:20:01 +01:00
|
|
|
|
using lib::time::Duration;
|
2016-01-28 15:37:35 +01:00
|
|
|
|
using lib::time::Time;
|
2016-01-28 23:30:13 +01:00
|
|
|
|
using lib::hash::LuidH;
|
2016-01-28 15:37:35 +01:00
|
|
|
|
|
|
|
|
|
|
using std::string;
|
|
|
|
|
|
using std::tuple;
|
2016-01-28 22:39:38 +01:00
|
|
|
|
using std::get;
|
2016-01-28 15:37:35 +01:00
|
|
|
|
|
|
|
|
|
|
namespace lib {
|
|
|
|
|
|
namespace meta {
|
|
|
|
|
|
namespace test {
|
2016-01-28 22:39:38 +01:00
|
|
|
|
|
2024-03-16 02:04:47 +01:00
|
|
|
|
using LERR_(WRONG_TYPE);
|
2016-01-28 22:39:38 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*************************************************************************//**
|
|
|
|
|
|
* @test 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-compile-time barrier, using a
|
|
|
|
|
|
* pre-generated double-dispatch (visitor).
|
|
|
|
|
|
*
|
|
|
|
|
|
* The concrete problem leading to the development of such a generic
|
|
|
|
|
|
* converter was the necessity to receive a command invocation
|
|
|
|
|
|
* parameter tuple from a Record<GenNode> sent via the UI-Bus.
|
|
|
|
|
|
* @see ElementExtractor
|
|
|
|
|
|
* @see GenNodeAccessor
|
|
|
|
|
|
* @see BusTerm_test::commandInvocation
|
2018-11-15 23:59:23 +01:00
|
|
|
|
* @see stage::test::Nexus::prepareDiagnosticCommandHandler
|
2016-01-28 22:39:38 +01:00
|
|
|
|
* @see ui-bus.hpp UI-Bus
|
|
|
|
|
|
*/
|
2016-01-28 15:37:35 +01:00
|
|
|
|
class TupleRecordInit_test : public Test
|
|
|
|
|
|
{
|
|
|
|
|
|
virtual void
|
|
|
|
|
|
run (Arg)
|
2016-01-28 22:39:38 +01:00
|
|
|
|
{
|
|
|
|
|
|
show_simpleUsage();
|
|
|
|
|
|
verify_errorHandling();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
|
show_simpleUsage()
|
|
|
|
|
|
{
|
2025-06-02 02:24:09 +02:00
|
|
|
|
using NiceTypes = TyOLD<string, int>;
|
|
|
|
|
|
using UgglyTypes = TyOLD<EntryID<long>, Symbol, int, int64_t, double, Duration>; // various conversions and an immutable type (Duration)
|
2016-01-28 22:39:38 +01:00
|
|
|
|
|
|
|
|
|
|
Rec args = MakeRec().scope("lalü", 42);
|
|
|
|
|
|
Rec urgs = MakeRec().scope("lalü", "lala", 12, 34, 5.6, Time(7,8,9));
|
|
|
|
|
|
|
|
|
|
|
|
cout << args <<endl;
|
|
|
|
|
|
cout << urgs <<endl;
|
|
|
|
|
|
|
|
|
|
|
|
cout << buildTuple<NiceTypes> (args) <<endl;
|
|
|
|
|
|
cout << buildTuple<UgglyTypes> (urgs) <<endl;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
|
verify_errorHandling()
|
|
|
|
|
|
{
|
|
|
|
|
|
Rec args = MakeRec().scope("surprise", 42);
|
|
|
|
|
|
|
2025-06-02 02:24:09 +02:00
|
|
|
|
using TooMany = TyOLD<string, int, long>;
|
2016-02-08 23:29:15 +01:00
|
|
|
|
VERIFY_ERROR (WRONG_TYPE, buildTuple<TooMany> (args)); // number of types in tuple exceeds capacity of the supplied argument record
|
2016-01-28 22:39:38 +01:00
|
|
|
|
|
2025-06-02 02:24:09 +02:00
|
|
|
|
using Unsigned = TyOLD<string, uint>;
|
|
|
|
|
|
using Floating = TyOLD<string, float>;
|
|
|
|
|
|
using Narrowing = TyOLD<string, short>;
|
2016-01-28 22:39:38 +01:00
|
|
|
|
VERIFY_ERROR (WRONG_TYPE, buildTuple<Unsigned> (args)); // dangerous conversion from signed to unsigned int is prohibited
|
|
|
|
|
|
VERIFY_ERROR (WRONG_TYPE, buildTuple<Floating> (args)); // conversion from integral to floating point element is prohibited
|
|
|
|
|
|
VERIFY_ERROR (WRONG_TYPE, buildTuple<Narrowing> (args)); // narrowing conversion from int to short is prohibited
|
|
|
|
|
|
|
|
|
|
|
|
// yet other (non-numeric) conversions are still possible
|
2016-01-28 23:30:13 +01:00
|
|
|
|
Rec timeArg = MakeRec().scope(Time(1,2,3,4));
|
2025-06-02 02:24:09 +02:00
|
|
|
|
using TupStr = TyOLD<string>;
|
2016-01-28 23:30:13 +01:00
|
|
|
|
Tuple<TupStr> tup = buildTuple<TupStr> (timeArg);
|
2016-01-28 22:39:38 +01:00
|
|
|
|
|
|
|
|
|
|
CHECK (std::get<string> (tup) == "4:03:02.001");
|
|
|
|
|
|
CHECK (string(Time(1,2,3,4)) == "4:03:02.001");
|
2016-01-28 23:30:13 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// conversions from LUID elements are handled restrictively
|
|
|
|
|
|
Rec hashArg = MakeRec().scope("random", LuidH());
|
|
|
|
|
|
VERIFY_ERROR (WRONG_TYPE, buildTuple<Unsigned> (args));
|
|
|
|
|
|
VERIFY_ERROR (WRONG_TYPE, buildTuple<Floating> (args));
|
|
|
|
|
|
VERIFY_ERROR (WRONG_TYPE, buildTuple<Narrowing> (args));
|
|
|
|
|
|
|
2025-06-02 02:24:09 +02:00
|
|
|
|
using ToSizeT = TyOLD<string, size_t>;
|
2016-01-28 23:30:13 +01:00
|
|
|
|
VERIFY_ERROR (WRONG_TYPE, (buildTuple<ToSizeT> (args))); // not even conversion to size_t is allowed
|
|
|
|
|
|
|
|
|
|
|
|
struct Dummy
|
|
|
|
|
|
{
|
|
|
|
|
|
HashVal hash;
|
|
|
|
|
|
|
|
|
|
|
|
Dummy (LuidH const& luid)
|
|
|
|
|
|
: hash(luid)
|
|
|
|
|
|
{ }
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2025-06-02 02:24:09 +02:00
|
|
|
|
using WithDummy = TyOLD<string, Dummy>;
|
2016-01-28 23:30:13 +01:00
|
|
|
|
|
|
|
|
|
|
Tuple<WithDummy> tup2 = buildTuple<WithDummy> (hashArg); // while any type explicitly constructible from LUID are permitted.
|
|
|
|
|
|
VERIFY_ERROR (WRONG_TYPE, buildTuple<WithDummy> (args)); // building a Dummy from int(42) is disallowed, of course
|
|
|
|
|
|
|
|
|
|
|
|
HashVal h = get<Dummy>(tup2).hash;
|
|
|
|
|
|
CHECK (h == hashArg.child(1).data.get<LuidH>()); // note: the narrowing conversion happens within LuidH::operator HashVal()
|
2016-01-28 22:39:38 +01:00
|
|
|
|
}
|
2016-01-28 15:37:35 +01:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** Register this test class... */
|
|
|
|
|
|
LAUNCHER (TupleRecordInit_test, "unit meta");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}}} // namespace lib::meta::test
|