24 #include <boost/lexical_cast.hpp> 34 using boost::lexical_cast;
43 using lumiera::error::LUMIERA_ERROR_INVALID;
51 virtual operator string () =0;
73 return instanceID_ + lexical_cast<
string> (ii);
88 return lexical_cast<
string> (rawVal);
94 return buildSome(ONE);
119 produce_simple_values();
120 produce_smart_pointers();
121 pass_additional_arguments();
122 fed_a_custom_finishing_functor();
131 uint invocations_ = 0;
135 produce_simple_values()
145 theFact.defineProduction (TWO, bind (buildSome<theID>, TWO));
148 auto memberFunction = bind (&MultiFact_test::callMe,
this,
"lalü");
149 theFact.defineProduction (THR, memberFunction);
152 string backdoor(
"backdoor");
153 theFact.defineProduction (FOU, [&] {
157 CHECK (!isnil (theFact));
161 CHECK (
theFact(THR) ==
"lalü");
162 CHECK (invocations_ == 1);
164 CHECK (
theFact(FOU) ==
"backdoor");
165 backdoor =
"I am " + backdoor.substr(0,4);
166 CHECK (
theFact(FOU) ==
"I am back");
170 CHECK (isnil (anotherFact));
173 anotherFact.defineProduction (ONE, memberFunction);
174 CHECK (anotherFact(ONE) ==
"lalü");
175 CHECK (invocations_ == 2);
177 CHECK (
theFact(THR) ==
"lalü");
178 CHECK (invocations_ == 3);
181 CHECK ( theFact.contains (FOU));
182 CHECK (!anotherFact.contains (FOU));
185 CHECK (anotherFact.contains (FOU));
186 CHECK (!isSameObject(theFact, anotherFact));
188 CHECK (anotherFact(ONE) ==
"1");
189 CHECK (anotherFact(TWO) ==
"2");
190 CHECK (anotherFact(THR) ==
"lalü");
191 CHECK (anotherFact(FOU) ==
"I am back");
192 CHECK (invocations_ == 4);
197 produce_smart_pointers()
206 theFact.defineProduction (TWO, [] {
return new Implementation<TWO>; });
207 theFact.defineProduction (THR, [] {
return new Implementation<THR>; });
208 theFact.defineProduction (FOU, [] {
return new Implementation<FOU>; });
209 CHECK (!isnil (theFact));
218 CHECK (
"Impl-1" ==
string(*p1));
219 CHECK (
"Impl-2" ==
string(*p2));
220 CHECK (
"Impl-3" ==
string(*p3));
221 CHECK (
"Impl-4" ==
string(*p4));
223 CHECK (
"Impl-1" ==
string(*p11));
224 CHECK (!isSameObject(*p1, *p11));
227 CHECK (isSameObject(*p11, *p12));
228 CHECK (
"Impl-1" ==
string(*p12));
229 CHECK (1 == p1.use_count());
230 CHECK (2 == p11.use_count());
231 CHECK (2 == p12.use_count());
236 pass_additional_arguments()
243 theFact.
defineProduction (ONE, [](
string ) {
return new Implementation<ONE>; });
244 theFact.defineProduction (TWO, [](
string ) {
return new Implementation<TWO>(
"X"); });
245 theFact.defineProduction (THR, [](
string id) {
return new Implementation<THR>(id); });
246 theFact.defineProduction (FOU, [](
string id) {
return new Implementation<FOU>(
"Z"+id);});
258 CHECK (
"Impl-1" ==
string(*p1));
259 CHECK (
"X2" ==
string(*p2));
260 CHECK (
"idiocy3"==
string(*p3));
261 CHECK (
"Zomg4" ==
string(*p4));
262 CHECK (
"Zz4" ==
string(*p5));
264 CHECK (!isSameObject(*p4, *p5));
280 fed_a_custom_finishing_functor()
288 theFact.defineProduction (TWO, [](
int par) {
return 2 * par; });
289 theFact.defineProduction (THR, [](
int par) {
return par*par; });
290 theFact.defineProduction (FOU, [](
int par) {
return 1 << par;});
294 theFact.defineFinalWrapper([](
int raw) {
return raw + 1; });
296 CHECK (
long(1 + 1) ==
theFact(ONE, 1));
297 CHECK (
long(1 + 2) ==
theFact(ONE, 2));
298 CHECK (
long(1 + 3) ==
theFact(ONE, 3));
300 CHECK (
long(1 + 2) ==
theFact(TWO, 1));
301 CHECK (
long(1 + 4) ==
theFact(TWO, 2));
302 CHECK (
long(1 + 6) ==
theFact(TWO, 3));
304 CHECK (
long(1 + 1) ==
theFact(THR, 1));
305 CHECK (
long(1 + 4) ==
theFact(THR, 2));
306 CHECK (
long(1 + 9) ==
theFact(THR, 3));
308 CHECK (
long(1 + 2) ==
theFact(FOU, 1));
309 CHECK (
long(1 + 4) ==
theFact(FOU, 2));
310 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...
Simplistic 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, based directly on the referee's memory identities. ...