34 #include <boost/operators.hpp> 45 using lumiera::error::LUMIERA_ERROR_ASSERTION;
49 : boost::totally_ordered<X>
53 X(
long x=0) : x_(x) {}
54 operator long () {
return x_; }
56 bool operator< (
const X& ox)
const {
return x_ < ox.x_; }
57 bool operator== (
const X& ox)
const {
return x_ == ox.x_; }
66 XX(
long x=0) :
X(x), xx_(x+1) {}
82 check_shared_ownership ();
83 check_ownership_transfer ();
84 check_type_relations ();
95 CHECK (1 == p1.use_count());
100 CHECK (1 == p2.use_count());
103 CHECK (1 == p1.use_count());
104 CHECK (1 == p2.use_count());
107 CHECK (2 == p1.use_count());
108 CHECK (2 == p2.use_count());
111 CHECK (1 == p1.use_count());
115 CHECK (0 == p1.use_count());
126 CHECK (1 == pX.use_count());
130 CHECK (1 == pX.use_count());
136 CHECK (22 == sp3->x_);
137 CHECK (4 == pX.use_count());
139 CHECK (*sp1 == *sp2);
140 CHECK (*sp2 == *sp3);
145 CHECK (0 == pX.use_count());
146 CHECK (4 == pX2.use_count());
151 CHECK (0 == pX2.use_count());
152 CHECK (4 == pXX.use_count());
154 sp3 = sp2 = sp1 = pX;
155 CHECK (22 == pXX->x_);
156 CHECK (1 == pXX.use_count());
161 CHECK (22 == wX.lock()->x_);
162 CHECK (1 == pXX.use_count());
171 check_ownership_transfer ()
173 std::unique_ptr<X> up (
new X(23));
176 P<X> pX (std::move(up));
179 CHECK (1 == pX.use_count());
180 CHECK (23 == pX->x_);
232 pX.reset (
new XX(5));
236 CHECK (5 == pX2->x_);
237 CHECK (6 == pX2->xx_);
239 pX3.reset (
new X(7));
257 PX pX3, pX4, pX5, pX6;
261 pX4.reset(
new X(*pXX));
263 CHECK ( (pX1 == pX1));
264 CHECK (!(pX1 != pX1));
265 CHECK (!(pX1 < pX1));
266 CHECK (!(pX1 > pX1));
267 CHECK ( (pX1 <= pX1));
268 CHECK ( (pX1 >= pX1));
270 CHECK (!(pX1 == pX2));
271 CHECK ( (pX1 != pX2));
272 CHECK ( (pX1 < pX2));
273 CHECK (!(pX1 > pX2));
274 CHECK ( (pX1 <= pX2));
275 CHECK (!(pX1 >= pX2));
277 CHECK (!(pX2 == pXX));
278 CHECK ( (pX2 != pXX));
279 CHECK ( (pX2 < pXX));
280 CHECK (!(pX2 > pXX));
281 CHECK ( (pX2 <= pXX));
282 CHECK (!(pX2 >= pXX));
284 CHECK (!(pX1 == pXX));
285 CHECK ( (pX1 != pXX));
286 CHECK ( (pX1 < pXX));
287 CHECK (!(pX1 > pXX));
288 CHECK ( (pX1 <= pXX));
289 CHECK (!(pX1 >= pXX));
291 CHECK ( (pX3 == pXX));
292 CHECK (!(pX3 != pXX));
293 CHECK (!(pX3 < pXX));
294 CHECK (!(pX3 > pXX));
295 CHECK ( (pX3 <= pXX));
296 CHECK ( (pX3 >= pXX));
298 CHECK ( (pX4 == pXX));
299 CHECK (!(pX4 != pXX));
300 CHECK (!(pX4 < pXX));
301 CHECK (!(pX4 > pXX));
302 CHECK ( (pX4 <= pXX));
303 CHECK ( (pX4 >= pXX));
305 CHECK (!(pXX == pX5));
306 CHECK ( (pXX != pX5));
308 CHECK ( (pX5 == pX6));
309 CHECK (!(pX5 != pX6));
314 VERIFY_ERROR (ASSERTION, pXX < pX5 );
void check_type_relations()
#define INSTANCEOF(CLASS, EXPR)
shortcut for subclass test, intended for assertions only.
#define VERIFY_ERROR(ERROR_ID, ERRONEOUS_STATEMENT)
Macro to verify that a statement indeed raises an exception.
Customised refcounting smart pointer.
Implementation namespace for support and library code.
void check_shared_ownership()
Simple test class runner.
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...
A collection of frequently used helper functions to support unit testing.
Customised refcounting smart pointer template, built upon std::shared_ptr, but forwarding type relati...