52 const uint MAX_ID = 1000;
62 ,instanceID_(rand() % MAX_ID)
65 virtual operator string()
const 67 return util::typeStr(
this)
68 + TestTargetObj::operator string();
71 uint Sub::created = 0;
109 verify_defaultSingletonCreation();
110 verify_SubclassCreation();
111 verify_FactoryDefinition_is_sticky();
112 verify_customFactory();
113 verify_automaticReplacement();
118 verify_defaultSingletonCreation()
123 Sub & o1 = accessor1();
124 Sub & o2 = accessor2();
125 CHECK (isSameObject (o1, o2));
130 verify_SubclassCreation()
138 SubSub& oSub = specialAccessor();
139 Sub& o = genericAccessor();
141 CHECK (!isSameObject (oSub, o));
148 verify_FactoryDefinition_is_sticky()
152 SubSub& oSub = otherSpecialAccessor();
157 SubSub& yetAnotherInstance = yetAnotherSpecialAccessor();
158 CHECK (
INSTANCEOF (SubSubSub, &yetAnotherInstance));
161 CHECK (isSameObject (oSub, yetAnotherInstance));
166 verify_customFactory()
172 CHECK (
INSTANCEOF (SubSubDub, &customised()));
173 CHECK (MAX_ID + 10 == customised().instanceID_);
177 customFactoryFunction (
void)
179 SubSubDub* specialInstance =
new SubSubDub;
180 specialInstance->instanceID_ = MAX_ID + 10;
181 return specialInstance;
187 verify_automaticReplacement()
190 Sub& original = genericAccessor();
191 uint oID = original.instanceID_;
196 Sub& replacement = genericAccessor();
197 CHECK ( isSameObject (replacement, *mockObject));
198 CHECK (!isSameObject (original, replacement));
203 CHECK(!isSameObject (replacement, special() ));
204 CHECK(!isSameObject (replacement, custom() ));
207 Sub& nextFetch = genericAccessor();
208 CHECK (isSameObject (original, nextFetch));
209 CHECK (oID == nextFetch.instanceID_);
214 Sub& replacement = genericAccessor();
215 uint repID = replacement.instanceID_;
219 CHECK (!
INSTANCEOF (SubSubSub, &replacement));
220 CHECK (!isSameObject (original, replacement));
223 Sub& otherAccess = anotherAccessor();
224 CHECK (isSameObject (replacement, otherAccess));
225 CHECK (repID == otherAccess.instanceID_);
226 CHECK (repID == replacement.instanceID_);
227 CHECK ( oID == original.instanceID_);
232 SubSub& subTypeAccess = genericSubTypeAccessor();
234 CHECK (!isSameObject (replacement, subTypeAccess));
235 CHECK (!isSameObject (original, subTypeAccess));
236 CHECK (repID != subTypeAccess.instanceID_);
237 CHECK ( oID != subTypeAccess.instanceID_);
240 CHECK (isSameObject (original, genericAccessor()));
241 CHECK (oID == genericAccessor().instanceID_);
Dummy target object to be created by factory for unit tests Used to verify sane memory management and...
#define INSTANCEOF(CLASS, EXPR)
shortcut for subclass test, intended for assertions only.
Per type specific configuration of instances created as service dependencies.
static void useSingleton()
configure dependency-injection for type SRV to build a subclass singleton.
Access point to singletons and other kinds of dependencies designated by type.
Implementation namespace for support and library code.
Target object to be created by Test-Factories or as Singleton.
This framework allows to (re)configure the lib::Depend front-end for dependency-injection.
Simple test class runner.
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...
Singleton services and Dependency Injection.
Configuration handle for temporarily shadowing a dependency by a test mock instance.
bool isSameObject(A const &a, B const &b)
compare plain object identity, bypassing any custom comparison operators.