42 using lib::test::randStr;
43 using lib::test::showSizeof;
46 using std::placeholders::_1;
48 using std::shared_ptr;
78 function<
int&(size_t)>
79 pickElement_ofVector (vector<int>& vec)
109 string s1 (randStr(50));
110 string s2 (randStr(50));
111 CStr cp (s1.c_str());
113 verifyWrapper<ulong> (l1, l2);
114 verifyWrapper<ulong&> (l1, l2);
115 verifyWrapper<ulong*> (&l1, &l2);
116 verifyWrapper<ulong*> ((0), &l2);
117 verifyWrapper<ulong*> (&l1, (0));
118 verifyWrapper<ulong const&> (l1, l2);
120 verifyWrapper<string> (s1, s2);
121 verifyWrapper<string&> (s1, s2);
122 verifyWrapper<string*> (&s1, &s2);
124 verifyWrapper<CStr> (cp,
"Lumiera");
143 cout <<
"ItemWrapper: " << showSizeof(wrap) << endl;
151 CHECK (
false ==
bool(empty));
153 CHECK (wrap == copy1);
154 CHECK (wrap != copy2);
155 CHECK (wrap != empty);
159 CHECK (wrap == copy2);
160 CHECK (wrap != empty);
164 CHECK (wrap != copy2);
165 CHECK (wrap != empty);
167 CHECK (val == *wrap);
168 CHECK (val == *copy1);
169 CHECK (val != *copy2);
172 CHECK (otherVal == *copy2);
174 CHECK (otherVal == *copy1);
175 CHECK (otherVal == *copy2);
176 CHECK (wrap != copy1);
177 CHECK (wrap != copy2);
184 CHECK (otherVal == *copy1);
186 CHECK (otherVal == *copy1);
188 CHECK (otherVal == *copy2);
193 CHECK (empty == copy1);
194 CHECK (copy2 != copy1);
210 verifyWrapper<Tracker> (t1, t2);
211 verifyWrapper<Tracker&> (t1, t2);
212 verifyWrapper<Tracker*> (&t1, &t2);
215 CHECK (0 == cntTracker);
223 using Data = shared_ptr<int>;
226 Data data{
new int(12345)};
227 CHECK (1 == data.use_count());
230 CHECK (2 == data.use_count());
231 CHECK (12345 == **wrap);
232 CHECK (isSameObject (*data, **wrap));
233 CHECK (!isSameObject (data, *wrap));
236 CHECK (3 == data.use_count());
238 Wrap wmove{move (wcopy)};
239 CHECK (3 == data.use_count());
244 CHECK (3 == data.use_count());
248 Wrap wmove2{move (data)};
249 CHECK (0 == data.use_count());
250 CHECK (3 == wmove2->use_count());
255 wmove2 = move (wcopy);
256 CHECK (2 == wmove2->use_count());
261 wmove2 = move (wrap);
262 CHECK (1 == wmove2->use_count());
266 wmove2 = move (wmove);
285 CHECK (5 == *refWrap);
286 CHECK (x == *refWrap);
292 CHECK ( isSameObject (**ptrWrap, x));
293 CHECK (!isSameObject ( *ptrWrap, &x));
315 int v1 = randomVal();
316 CHECK (v1 == *randomVal);
317 CHECK (v1 == *randomVal);
318 CHECK (v1 == *randomVal);
324 CHECK (v2 == *randomVal);
325 CHECK (v2 == *randomVal);
326 CHECK (v1 != *randomVal);
342 for (
uint i=0; i<10; ++i)
343 testVec.push_back(i);
345 FunctionResult<
int&(size_t)> funRes (pickElement_ofVector(testVec));
351 int& r5 = funRes (5);
355 CHECK (isSameObject (r5, testVec[5]));
358 CHECK (isSameObject (r5, r5x));
360 CHECK ( isSameObject (r5, *funRes));
361 int& r7 = funRes (7);
362 CHECK (!isSameObject (r5, *funRes));
363 CHECK ( isSameObject (r7, *funRes));
367 CHECK (5-1 == testVec[5]);
368 CHECK (7+1 == testVec[7]);
Universal value/ref wrapper accessible similar to a pointer.
void verifySaneMoveHandling()
void verifySaneInstanceHandling()
void verifyFunctionRefResult()
void verifyWrapper(X val, X otherVal)
void verifyFunctionResult()
static auto produceResult()
Adapter to store and hold an element of arbitrary type in local storage.
int & pickElement(vector< int > &vec, size_t idx)
to be bound as test function....
bool operator!=(ItemWrapper< TY > const &w1, ItemWrapper< TY > const &w2)
bool operator==(ItemWrapper< TY > const &w1, ItemWrapper< TY > const &w2)
allow equality comparison if the wrapped types are comparable
Implementation namespace for support and library code.
int rani(uint bound=_iBOUND())
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.
Generating (pseudo) random numbers with controlled seed.
Simplistic test class runner.
#define LAUNCHER(_TEST_CLASS_, _GROUPS_)
Extension of ItemWrapper: a function remembering the result of the last invocation.
Tracker(Tracker const &ot)
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...
Helper to cache the result of function invocation.