33 #include <boost/lexical_cast.hpp> 42 using boost::lexical_cast;
50 using lumiera::error::LUMIERA_ERROR_INVALID;
58 virtual operator string () =0;
80 return instanceID_ + lexical_cast<
string> (ii);
95 return lexical_cast<
string> (rawVal);
101 return buildSome(ONE);
126 produce_simple_values();
127 produce_smart_pointers();
128 pass_additional_arguments();
129 fed_a_custom_finishing_functor();
138 uint invocations_ = 0;
142 produce_simple_values()
152 theFact.defineProduction (TWO, bind (buildSome<theID>, TWO));
155 auto memberFunction = bind (&MultiFact_test::callMe,
this,
"lalü");
156 theFact.defineProduction (THR, memberFunction);
159 string backdoor(
"backdoor");
160 theFact.defineProduction (FOU, [&] {
164 CHECK (!isnil (theFact));
168 CHECK (
theFact(THR) ==
"lalü");
169 CHECK (invocations_ == 1);
171 CHECK (
theFact(FOU) ==
"backdoor");
172 backdoor =
"I am " + backdoor.substr(0,4);
173 CHECK (
theFact(FOU) ==
"I am back");
177 CHECK (isnil (anotherFact));
180 anotherFact.defineProduction (ONE, memberFunction);
181 CHECK (anotherFact(ONE) ==
"lalü");
182 CHECK (invocations_ == 2);
184 CHECK (
theFact(THR) ==
"lalü");
185 CHECK (invocations_ == 3);
188 CHECK ( theFact.contains (FOU));
189 CHECK (!anotherFact.contains (FOU));
192 CHECK (anotherFact.contains (FOU));
193 CHECK (!isSameObject(theFact, anotherFact));
195 CHECK (anotherFact(ONE) ==
"1");
196 CHECK (anotherFact(TWO) ==
"2");
197 CHECK (anotherFact(THR) ==
"lalü");
198 CHECK (anotherFact(FOU) ==
"I am back");
199 CHECK (invocations_ == 4);
204 produce_smart_pointers()
213 theFact.defineProduction (TWO, [] {
return new Implementation<TWO>; });
214 theFact.defineProduction (THR, [] {
return new Implementation<THR>; });
215 theFact.defineProduction (FOU, [] {
return new Implementation<FOU>; });
216 CHECK (!isnil (theFact));
225 CHECK (
"Impl-1" ==
string(*p1));
226 CHECK (
"Impl-2" ==
string(*p2));
227 CHECK (
"Impl-3" ==
string(*p3));
228 CHECK (
"Impl-4" ==
string(*p4));
230 CHECK (
"Impl-1" ==
string(*p11));
231 CHECK (!isSameObject(*p1, *p11));
234 CHECK (isSameObject(*p11, *p12));
235 CHECK (
"Impl-1" ==
string(*p12));
236 CHECK (1 == p1.use_count());
237 CHECK (2 == p11.use_count());
238 CHECK (2 == p12.use_count());
243 pass_additional_arguments()
250 theFact.
defineProduction (ONE, [](
string ) {
return new Implementation<ONE>; });
251 theFact.defineProduction (TWO, [](
string ) {
return new Implementation<TWO>(
"X"); });
252 theFact.defineProduction (THR, [](
string id) {
return new Implementation<THR>(id); });
253 theFact.defineProduction (FOU, [](
string id) {
return new Implementation<FOU>(
"Z"+id);});
265 CHECK (
"Impl-1" ==
string(*p1));
266 CHECK (
"X2" ==
string(*p2));
267 CHECK (
"idiocy3"==
string(*p3));
268 CHECK (
"Zomg4" ==
string(*p4));
269 CHECK (
"Zz4" ==
string(*p5));
271 CHECK (!isSameObject(*p4, *p5));
287 fed_a_custom_finishing_functor()
295 theFact.defineProduction (TWO, [](
int par) {
return 2 * par; });
296 theFact.defineProduction (THR, [](
int par) {
return par*par; });
297 theFact.defineProduction (FOU, [](
int par) {
return 1 << par;});
301 theFact.defineFinalWrapper([](
int raw) {
return raw + 1; });
303 CHECK (
long(1 + 1) ==
theFact(ONE, 1));
304 CHECK (
long(1 + 2) ==
theFact(ONE, 2));
305 CHECK (
long(1 + 3) ==
theFact(ONE, 3));
307 CHECK (
long(1 + 2) ==
theFact(TWO, 1));
308 CHECK (
long(1 + 4) ==
theFact(TWO, 2));
309 CHECK (
long(1 + 6) ==
theFact(TWO, 3));
311 CHECK (
long(1 + 1) ==
theFact(THR, 1));
312 CHECK (
long(1 + 4) ==
theFact(THR, 2));
313 CHECK (
long(1 + 9) ==
theFact(THR, 3));
315 CHECK (
long(1 + 2) ==
theFact(FOU, 1));
316 CHECK (
long(1 + 4) ==
theFact(FOU, 2));
317 CHECK (
long(1 + 8) ==
theFact(FOU, 3));
factory::MultiFact< Num(int), prodID, factory::BuildRefcountPtr > TestFactory
the factory instantiation used for this test
Framework for building a configurable factory, to generate families of related objects.
#define INSTANCEOF(CLASS, EXPR)
shortcut for subclass test, intended for assertions only.
#define VERIFY_ERROR(ERROR_ID, ERRONEOUS_STATEMENT)
Macro to verify that a statement indeed raises an exception.
TestFactory theFact
Factory instance for the tests...
Implementation namespace for support and library code.
Factory for creating a family of objects by ID.
Target object to be instantiated as Singleton Allocates a variable amount of additional heap memory a...
Simple test class runner.
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...
A collection of frequently used helper functions to support unit testing.
void defineProduction(ID id, FUNC &&fun)
to set up a production line, associated with a specific ID
bool isSameObject(A const &a, B const &b)
compare plain object identity, bypassing any custom comparison operators.