25 #include <boost/operators.hpp> 36 using lumiera::error::LUMIERA_ERROR_ASSERTION;
40 : boost::totally_ordered<X>
44 X(
long x=0) : x_(x) {}
45 operator long () {
return x_; }
47 bool operator< (
const X& ox)
const {
return x_ < ox.x_; }
48 bool operator== (
const X& ox)
const {
return x_ == ox.x_; }
57 XX(
long x=0) :
X(x), xx_(x+1) {}
73 check_shared_ownership ();
74 check_ownership_transfer ();
75 check_type_relations ();
86 CHECK (1 == p1.use_count());
91 CHECK (1 == p2.use_count());
94 CHECK (1 == p1.use_count());
95 CHECK (1 == p2.use_count());
98 CHECK (2 == p1.use_count());
99 CHECK (2 == p2.use_count());
102 CHECK (1 == p1.use_count());
106 CHECK (0 == p1.use_count());
117 CHECK (1 == pX.use_count());
121 CHECK (1 == pX.use_count());
127 CHECK (22 == sp3->x_);
128 CHECK (4 == pX.use_count());
130 CHECK (*sp1 == *sp2);
131 CHECK (*sp2 == *sp3);
136 CHECK (0 == pX.use_count());
137 CHECK (4 == pX2.use_count());
142 CHECK (0 == pX2.use_count());
143 CHECK (4 == pXX.use_count());
145 sp3 = sp2 = sp1 = pX;
146 CHECK (22 == pXX->x_);
147 CHECK (1 == pXX.use_count());
152 CHECK (22 == wX.lock()->x_);
153 CHECK (1 == pXX.use_count());
162 check_ownership_transfer ()
164 std::unique_ptr<X> up (
new X(23));
167 P<X> pX (std::move(up));
170 CHECK (1 == pX.use_count());
171 CHECK (23 == pX->x_);
223 pX.reset (
new XX(5));
227 CHECK (5 == pX2->x_);
228 CHECK (6 == pX2->xx_);
230 pX3.reset (
new X(7));
248 PX pX3, pX4, pX5, pX6;
252 pX4.reset(
new X(*pXX));
254 CHECK ( (pX1 == pX1));
255 CHECK (!(pX1 != pX1));
256 CHECK (!(pX1 < pX1));
257 CHECK (!(pX1 > pX1));
258 CHECK ( (pX1 <= pX1));
259 CHECK ( (pX1 >= pX1));
261 CHECK (!(pX1 == pX2));
262 CHECK ( (pX1 != pX2));
263 CHECK ( (pX1 < pX2));
264 CHECK (!(pX1 > pX2));
265 CHECK ( (pX1 <= pX2));
266 CHECK (!(pX1 >= pX2));
268 CHECK (!(pX2 == pXX));
269 CHECK ( (pX2 != pXX));
270 CHECK ( (pX2 < pXX));
271 CHECK (!(pX2 > pXX));
272 CHECK ( (pX2 <= pXX));
273 CHECK (!(pX2 >= pXX));
275 CHECK (!(pX1 == pXX));
276 CHECK ( (pX1 != pXX));
277 CHECK ( (pX1 < pXX));
278 CHECK (!(pX1 > pXX));
279 CHECK ( (pX1 <= pXX));
280 CHECK (!(pX1 >= pXX));
282 CHECK ( (pX3 == pXX));
283 CHECK (!(pX3 != pXX));
284 CHECK (!(pX3 < pXX));
285 CHECK (!(pX3 > pXX));
286 CHECK ( (pX3 <= pXX));
287 CHECK ( (pX3 >= pXX));
289 CHECK ( (pX4 == pXX));
290 CHECK (!(pX4 != pXX));
291 CHECK (!(pX4 < pXX));
292 CHECK (!(pX4 > pXX));
293 CHECK ( (pX4 <= pXX));
294 CHECK ( (pX4 >= pXX));
296 CHECK (!(pXX == pX5));
297 CHECK ( (pXX != pX5));
299 CHECK ( (pX5 == pX6));
300 CHECK (!(pX5 != pX6));
305 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()
Simplistic 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...