50 using lib::test::showSizeof;
53 using std::placeholders::_1;
72 Tracker() : i_(rand() % 500) { ++cntTracker; }
78 bool operator!= (
Tracker const& t1,
Tracker const& t2) {
return t1.i_ != t2.i_; }
88 function<int&(size_t)>
89 pickElement_ofVector (vector<int>& vec)
115 ulong l1 (rand() % 1000);
116 ulong l2 (rand() % 1000);
117 string s1 (randStr(50));
118 string s2 (randStr(50));
119 const char* cp (s1.c_str());
121 verifyWrapper<ulong> (l1, l2);
122 verifyWrapper<ulong&> (l1, l2);
123 verifyWrapper<ulong*> (&l1, &l2);
124 verifyWrapper<ulong*> ((0), &l2);
125 verifyWrapper<ulong*> (&l1, (0));
126 verifyWrapper<ulong const&> (l1, l2);
128 verifyWrapper<string> (s1, s2);
129 verifyWrapper<string&> (s1, s2);
130 verifyWrapper<string*> (&s1, &s2);
132 verifyWrapper<const char*> (cp,
"Lumiera");
135 verifySaneInstanceHandling();
136 verifySaneMoveHandling();
139 verifyFunctionResult ();
140 verifyFunctionRefResult ();
146 verifyWrapper (X val, X otherVal)
151 cout <<
"ItemWrapper: " << showSizeof(wrap) << endl;
159 CHECK (
false ==
bool(empty));
161 CHECK (wrap == copy1);
162 CHECK (wrap != copy2);
163 CHECK (wrap != empty);
167 CHECK (wrap == copy2);
168 CHECK (wrap != empty);
172 CHECK (wrap != copy2);
173 CHECK (wrap != empty);
175 CHECK (val == *wrap);
176 CHECK (val == *copy1);
177 CHECK (val != *copy2);
180 CHECK (otherVal == *copy2);
182 CHECK (otherVal == *copy1);
183 CHECK (otherVal == *copy2);
184 CHECK (wrap != copy1);
185 CHECK (wrap != copy2);
192 CHECK (otherVal == *copy1);
194 CHECK (otherVal == *copy1);
196 CHECK (otherVal == *copy2);
201 CHECK (empty == copy1);
202 CHECK (copy2 != copy1);
218 verifyWrapper<Tracker> (t1, t2);
219 verifyWrapper<Tracker&> (t1, t2);
220 verifyWrapper<Tracker*> (&t1, &t2);
223 CHECK (0 == cntTracker);
234 Data data{
new int(12345)};
235 CHECK (1 == data.use_count());
238 CHECK (2 == data.use_count());
239 CHECK (12345 == **wrap);
240 CHECK (isSameObject (*data, **wrap));
241 CHECK (!isSameObject (data, *wrap));
244 CHECK (3 == data.use_count());
246 Wrap wmove{move (wcopy)};
247 CHECK (3 == data.use_count());
252 CHECK (3 == data.use_count());
256 Wrap wmove2{move (data)};
257 CHECK (0 == data.use_count());
258 CHECK (3 == wmove2->use_count());
263 wmove2 = move (wcopy);
264 CHECK (2 == wmove2->use_count());
269 wmove2 = move (wrap);
270 CHECK (1 == wmove2->use_count());
274 wmove2 = move (wmove);
293 CHECK (5 == *refWrap);
294 CHECK (x == *refWrap);
300 CHECK ( isSameObject (**ptrWrap, x));
301 CHECK (!isSameObject ( *ptrWrap, &x));
321 int v1 = randomVal();
322 CHECK (v1 == *randomVal);
323 CHECK (v1 == *randomVal);
324 CHECK (v1 == *randomVal);
330 CHECK (v2 == *randomVal);
331 CHECK (v2 == *randomVal);
332 CHECK (v1 != *randomVal);
348 for (uint i=0; i<10; ++i)
349 testVec.push_back(i);
357 int& r5 = funRes (5);
361 CHECK (isSameObject (r5, testVec[5]));
364 CHECK (isSameObject (r5, r5x));
366 CHECK ( isSameObject (r5, *funRes));
367 int& r7 = funRes (7);
368 CHECK (!isSameObject (r5, *funRes));
369 CHECK ( isSameObject (r7, *funRes));
373 CHECK (5-1 == testVec[5]);
374 CHECK (7+1 == testVec[7]);
void verifySaneMoveHandling()
bool operator==(PtrDerefIter< I1 > const &il, PtrDerefIter< I2 > const &ir)
Supporting equality comparisons...
#define VERIFY_ERROR(ERROR_ID, ERRONEOUS_STATEMENT)
Macro to verify that a statement indeed raises an exception.
Universal value/ref wrapper accessible similar to a pointer.
void verifyFunctionResult()
Implementation namespace for support and library code.
string randStr(size_t len)
create garbage string of given length
Simple test class runner.
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...
Extension of ItemWrapper: a function remembering the result of the last invocation.
int & pickElement(vector< int > &vec, size_t idx)
to be bound as test function....
A collection of frequently used helper functions to support unit testing.
void verifySaneInstanceHandling()
void verifyFunctionRefResult()
Library implementation: smart-pointer variations, wrappers and managing holders.
bool isSameObject(A const &a, B const &b)
compare plain object identity, bypassing any custom comparison operators.