42 using lib::test::showSizeof;
45 using std::placeholders::_1;
67 bool operator!= (
Tracker const& t1,
Tracker const& t2) {
return t1.i_ != t2.i_; }
77 function<int&(size_t)>
78 pickElement_ofVector (vector<int>& vec)
106 ulong l1 (
rani (1000));
107 ulong l2 (
rani (1000));
108 string s1 (randStr(50));
109 string s2 (randStr(50));
110 const char* cp (s1.c_str());
112 verifyWrapper<ulong> (l1, l2);
113 verifyWrapper<ulong&> (l1, l2);
114 verifyWrapper<ulong*> (&l1, &l2);
115 verifyWrapper<ulong*> ((0), &l2);
116 verifyWrapper<ulong*> (&l1, (0));
117 verifyWrapper<ulong const&> (l1, l2);
119 verifyWrapper<string> (s1, s2);
120 verifyWrapper<string&> (s1, s2);
121 verifyWrapper<string*> (&s1, &s2);
123 verifyWrapper<const char*> (cp,
"Lumiera");
126 verifySaneInstanceHandling();
127 verifySaneMoveHandling();
130 verifyFunctionResult ();
131 verifyFunctionRefResult ();
137 verifyWrapper (X val, X otherVal)
142 cout <<
"ItemWrapper: " << showSizeof(wrap) << endl;
150 CHECK (
false ==
bool(empty));
152 CHECK (wrap == copy1);
153 CHECK (wrap != copy2);
154 CHECK (wrap != empty);
158 CHECK (wrap == copy2);
159 CHECK (wrap != empty);
163 CHECK (wrap != copy2);
164 CHECK (wrap != empty);
166 CHECK (val == *wrap);
167 CHECK (val == *copy1);
168 CHECK (val != *copy2);
171 CHECK (otherVal == *copy2);
173 CHECK (otherVal == *copy1);
174 CHECK (otherVal == *copy2);
175 CHECK (wrap != copy1);
176 CHECK (wrap != copy2);
183 CHECK (otherVal == *copy1);
185 CHECK (otherVal == *copy1);
187 CHECK (otherVal == *copy2);
192 CHECK (empty == copy1);
193 CHECK (copy2 != copy1);
209 verifyWrapper<Tracker> (t1, t2);
210 verifyWrapper<Tracker&> (t1, t2);
211 verifyWrapper<Tracker*> (&t1, &t2);
214 CHECK (0 == cntTracker);
225 Data data{
new int(12345)};
226 CHECK (1 == data.use_count());
229 CHECK (2 == data.use_count());
230 CHECK (12345 == **wrap);
231 CHECK (isSameObject (*data, **wrap));
232 CHECK (!isSameObject (data, *wrap));
235 CHECK (3 == data.use_count());
237 Wrap wmove{move (wcopy)};
238 CHECK (3 == data.use_count());
243 CHECK (3 == data.use_count());
247 Wrap wmove2{move (data)};
248 CHECK (0 == data.use_count());
249 CHECK (3 == wmove2->use_count());
254 wmove2 = move (wcopy);
255 CHECK (2 == wmove2->use_count());
260 wmove2 = move (wrap);
261 CHECK (1 == wmove2->use_count());
265 wmove2 = move (wmove);
284 CHECK (5 == *refWrap);
285 CHECK (x == *refWrap);
291 CHECK ( isSameObject (**ptrWrap, x));
292 CHECK (!isSameObject ( *ptrWrap, &x));
298 static auto produceResult() {
return rani(); }
314 int v1 = randomVal();
315 CHECK (v1 == *randomVal);
316 CHECK (v1 == *randomVal);
317 CHECK (v1 == *randomVal);
323 CHECK (v2 == *randomVal);
324 CHECK (v2 == *randomVal);
325 CHECK (v1 != *randomVal);
341 for (uint i=0; i<10; ++i)
342 testVec.push_back(i);
350 int& r5 = funRes (5);
354 CHECK (isSameObject (r5, testVec[5]));
357 CHECK (isSameObject (r5, r5x));
359 CHECK ( isSameObject (r5, *funRes));
360 int& r7 = funRes (7);
361 CHECK (!isSameObject (r5, *funRes));
362 CHECK ( isSameObject (r7, *funRes));
366 CHECK (5-1 == testVec[5]);
367 CHECK (7+1 == testVec[7]);
void verifySaneMoveHandling()
int rani(uint bound=_iBOUND())
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
Simplistic 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.
Generating (pseudo) random numbers with controlled seed.
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, based directly on the referee's memory identities. ...