24#include <boost/lexical_cast.hpp>
34 using boost::lexical_cast;
38 using std::shared_ptr;
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);
152 string backdoor(
"backdoor");
157 CHECK (!isnil (theFact));
158 CHECK (theFact(ONE) ==
"1");
159 CHECK (theFact(TWO) ==
"2");
161 CHECK (theFact(THR) ==
"lalü");
164 CHECK (theFact(FOU) ==
"backdoor");
165 backdoor =
"I am " + backdoor.substr(0,4);
166 CHECK (theFact(FOU) ==
"I am back");
169 TestFactory anotherFact;
170 CHECK (isnil (anotherFact));
173 anotherFact.defineProduction (ONE, memberFunction);
174 CHECK (anotherFact(ONE) ==
"lalü");
177 CHECK (theFact(THR) ==
"lalü");
182 CHECK (!anotherFact.contains (FOU));
184 anotherFact = theFact;
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");
200 using PIfa = shared_ptr<Interface>;
209 CHECK (!isnil (theFact));
211 PIfa p1 = theFact(ONE);
212 PIfa p2 = theFact(TWO);
213 PIfa p3 = theFact(THR);
214 PIfa p4 = theFact(FOU);
216 PIfa p11 = theFact(ONE);
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());
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);});
248 Interface *p1 = theFact(ONE,
"irrelevant"),
249 *p2 = theFact(TWO,
"ignored"),
250 *p3 = theFact(THR,
"idiocy"),
251 *p4 = theFact(FOU,
"omg"),
252 *p5 = theFact(FOU,
"z");
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));
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 for creating a family of objects by ID.
void defineProduction(ID id, FUNC &&fun)
to set up a production line, associated with a specific ID
bool contains(ID id) const
Target object to be instantiated as Singleton Allocates a variable amount of additional heap memory a...
void pass_additional_arguments()
void produce_simple_values()
void produce_smart_pointers()
void fed_a_custom_finishing_functor()
string callMe(string val)
Implementation(string id="Impl-")
Framework for building a configurable factory, to generate families of related objects.
string buildSome(X rawVal)
Implementation namespace for support and library code.
Test runner and basic definitions for tests.
bool isSameObject(A const &a, B const &b)
compare plain object identity, based directly on the referee's memory identities.
bool isnil(lib::time::Duration const &dur)
Simplistic test class runner.
#define LAUNCHER(_TEST_CLASS_, _GROUPS_)
A collection of frequently used helper functions to support unit testing.
#define VERIFY_ERROR(ERROR_ID, ERRONEOUS_STATEMENT)
Macro to verify that a statement indeed raises an exception.
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...
#define INSTANCEOF(CLASS, EXPR)
shortcut for subclass test, intended for assertions only.