2009-10-26 01:39:25 +01:00
|
|
|
|
/*
|
2009-10-26 01:42:35 +01:00
|
|
|
|
MultiFactArgument(Test) - passing additional invocation arguments to registered factory functions
|
2010-12-17 23:28:49 +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
|
|
|
|
Copyright (C)
|
|
|
|
|
|
2009, Hermann Vosseler <Ichthyostega@web.de>
|
2010-12-17 23:28:49 +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.
|
2010-12-17 23:28:49 +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
|
|
|
|
* *****************************************************************/
|
2009-10-26 01:39:25 +01:00
|
|
|
|
|
2017-02-22 01:54:20 +01:00
|
|
|
|
/** @file multifact-argument-test.cpp
|
2017-02-22 03:17:18 +01:00
|
|
|
|
** unit test \ref MultiFactArgument_test
|
2016-11-03 18:20:10 +01:00
|
|
|
|
*/
|
|
|
|
|
|
|
2009-10-26 01:39:25 +01:00
|
|
|
|
|
|
|
|
|
|
#include "lib/test/run.hpp"
|
|
|
|
|
|
#include "lib/test/test-helper.hpp"
|
2016-01-07 03:58:29 +01:00
|
|
|
|
#include "lib/format-cout.hpp"
|
2014-09-14 23:58:05 +02:00
|
|
|
|
#include "lib/multifact.hpp"
|
2009-10-26 01:39:25 +01:00
|
|
|
|
|
2014-04-03 22:42:48 +02:00
|
|
|
|
#include <functional>
|
2009-10-26 01:39:25 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace lib {
|
|
|
|
|
|
namespace test{
|
|
|
|
|
|
|
2014-04-03 22:42:48 +02:00
|
|
|
|
using std::bind;
|
|
|
|
|
|
using std::function;
|
|
|
|
|
|
using std::placeholders::_1;
|
2009-10-30 00:32:26 +01:00
|
|
|
|
using lib::test::showSizeof;
|
2009-10-26 01:39:25 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-10-28 04:45:17 +01:00
|
|
|
|
namespace { // dummy fabrication function, creating wrapped numbers, controlled by an additional argument
|
2009-10-26 01:39:25 +01:00
|
|
|
|
|
2009-10-28 04:45:17 +01:00
|
|
|
|
enum prodID
|
2009-10-26 01:39:25 +01:00
|
|
|
|
{ ONE = 1
|
|
|
|
|
|
, TWO
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2009-10-26 01:42:35 +01:00
|
|
|
|
struct Num { int n_; };
|
|
|
|
|
|
|
2009-10-28 04:45:17 +01:00
|
|
|
|
/** dummy "factory" function to be invoked
|
2009-10-30 00:32:26 +01:00
|
|
|
|
* @return pointer to heap allocated product object
|
2009-10-28 04:45:17 +01:00
|
|
|
|
* @note this function needs to deliver the product in a form
|
|
|
|
|
|
* which can be accepted by the concrete wrapper, which
|
2009-10-30 00:32:26 +01:00
|
|
|
|
* is going to be configured into the factory.
|
2009-10-28 04:45:17 +01:00
|
|
|
|
*/
|
2009-10-26 01:42:35 +01:00
|
|
|
|
Num*
|
|
|
|
|
|
fabricateNumberz (int base, int offset)
|
|
|
|
|
|
{
|
|
|
|
|
|
cout << "fabricate("<<base<<", "<<offset<<")" << endl;
|
|
|
|
|
|
Num* product = new Num;
|
|
|
|
|
|
product->n_ = base*offset;
|
|
|
|
|
|
return product;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-10-28 04:45:17 +01:00
|
|
|
|
/** the factory instantiation used for this test */
|
2009-10-29 22:00:17 +01:00
|
|
|
|
typedef factory::MultiFact< Num(int) // nominal signature of fabrication
|
2009-10-28 04:45:17 +01:00
|
|
|
|
, prodID // select factory function by prodID
|
|
|
|
|
|
, factory::BuildRefcountPtr // wrapper: manage product by smart-ptr
|
|
|
|
|
|
> TestFactory;
|
2009-10-26 01:42:35 +01:00
|
|
|
|
|
2009-10-30 00:32:26 +01:00
|
|
|
|
// for reference: type of an equivalent dispatcher table...
|
|
|
|
|
|
typedef std::map<prodID, function<Num(int)> > DispatcherMap;
|
2009-10-26 01:39:25 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-10-24 23:06:36 +02:00
|
|
|
|
/***************************************************************//**
|
2009-10-26 01:42:35 +01:00
|
|
|
|
* @test define a MultiFact (factory with dynamic registration),
|
|
|
|
|
|
* which accepts additional arguments and passes them
|
|
|
|
|
|
* through to the registered factory function(s).
|
2025-06-07 23:59:57 +02:00
|
|
|
|
* @note we set up fabrication functions by binding the functions
|
2012-10-14 01:30:08 +02:00
|
|
|
|
* in such a way as to match the function signature declared
|
|
|
|
|
|
* in the factory; thereby one argument remains unclosed,
|
|
|
|
|
|
* which is the argument to be supplied on each
|
|
|
|
|
|
* factory invocation by the client code.
|
2009-10-28 04:45:17 +01:00
|
|
|
|
*
|
2009-10-26 01:39:25 +01:00
|
|
|
|
* @see lib::MultiFact
|
2009-10-26 01:42:35 +01:00
|
|
|
|
* @see query-resolver.cpp
|
2009-10-26 01:39:25 +01:00
|
|
|
|
*/
|
2009-10-26 01:42:35 +01:00
|
|
|
|
class MultiFactArgument_test : public Test
|
2009-10-26 01:39:25 +01:00
|
|
|
|
{
|
|
|
|
|
|
void
|
2009-10-30 00:32:26 +01:00
|
|
|
|
run (Arg)
|
2009-10-26 01:39:25 +01:00
|
|
|
|
{
|
2009-10-26 01:42:35 +01:00
|
|
|
|
TestFactory theFact;
|
2009-10-30 00:32:26 +01:00
|
|
|
|
theFact.defineProduction (ONE, bind (&fabricateNumberz, 1, _1 ));
|
|
|
|
|
|
theFact.defineProduction (TWO, bind (&fabricateNumberz, 2, _1 ));
|
2009-10-26 01:42:35 +01:00
|
|
|
|
|
2009-10-26 01:39:25 +01:00
|
|
|
|
cout << showSizeof (theFact) << endl;
|
2010-12-10 02:55:40 +01:00
|
|
|
|
CHECK (sizeof(theFact) == sizeof(DispatcherMap));
|
2009-10-26 01:39:25 +01:00
|
|
|
|
|
2009-10-27 05:13:38 +01:00
|
|
|
|
typedef TestFactory::Product PP;
|
2009-10-26 01:39:25 +01:00
|
|
|
|
|
2009-10-28 04:45:17 +01:00
|
|
|
|
PP p1 = theFact(ONE, 2);
|
|
|
|
|
|
PP p2 = theFact(TWO, 3);
|
2010-12-10 02:55:40 +01:00
|
|
|
|
CHECK (1*2 == p1->n_);
|
|
|
|
|
|
CHECK (2*3 == p2->n_);
|
2009-10-30 00:32:26 +01:00
|
|
|
|
}
|
2009-10-26 01:39:25 +01:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** Register this test class... */
|
2009-10-26 01:42:35 +01:00
|
|
|
|
LAUNCHER (MultiFactArgument_test, "unit common");
|
2009-10-26 01:39:25 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}} // namespace lib::test
|