46 using LERR_(BOTTOM_VALUE);
47 using LERR_(WRONG_TYPE);
48 using LERR_(ASSERTION);
58 uint _create_count = 0;
65 Base(uint i=0) : id_(i) { _checksum +=id_; ++_create_count; }
66 Base(
Base const& o) : id_(o.id_) { _checksum +=id_; ++_create_count; }
68 uint getIt() {
return id_; }
76 ~
DD() { _checksum -= ii; }
106 typedef vector<Opaque> TestList;
129 TestList objs = createDummies ();
130 for_each (objs, reAccess);
131 checkHandling (objs);
132 checkSpecialSubclass ();
134 CHECK (0 == _checksum);
142 list.push_back (DD<1>());
143 list.push_back (DD<3>());
144 list.push_back (DD<5>());
145 list.push_back (DD<7>());
151 reAccess (Opaque& elm)
153 cout << elm->getIt() << endl;
173 D3 d3 (oo.
get<D3>() );
174 CHECK (3 == oo->getIt());
175 CHECK (!isSameObject (d3, *oo));
181 CHECK (5 == oo->getIt());
185 D5 &rd5 (oo.
get<D5>());
186 CHECK (isSameObject (rd5, *oo));
190 CHECK (7 == oo->getIt());
193 CHECK (7 == rd5.getIt());
194 CHECK (isSameObject (rd5, *oo));
196 uint cnt_before = _create_count;
202 CHECK (5 == oo->getIt());
203 CHECK (_create_count == 2 + cnt_before);
208 cnt_before = _create_count;
211 CHECK (_create_count == cnt_before);
213 CHECK (_create_count == cnt_before);
215 CHECK (_create_count == cnt_before);
223 VERIFY_ERROR (ASSERTION, oo->getIt() ); 225 // can't access empty holder... 231 CHECK (!isSameObject (d3, *o2));
232 CHECK (3 == o2->getIt());
234 CHECK (
sizeof(Opaque) <=
sizeof(Base) +
sizeof(
void*) +
_ALIGN_);
254 cout << showSizeof<Base>() << endl;
255 cout << showSizeof<Special>() << endl;
256 cout << showSizeof<Opaque>() << endl;
257 cout << showSizeof<SpecialOpaque>() << endl;
259 CHECK (
sizeof(Special) >
sizeof(Base));
260 CHECK (
sizeof(SpecialOpaque) >
sizeof(Opaque));
261 CHECK (
sizeof(SpecialOpaque) <=
sizeof(Special) +
sizeof(
void*) +
_ALIGN_);
267 CHECK (7 == s1.getIt());
268 CHECK (7 == s2.getIt());
271 SpecialOpaque ospe1 (s1);
272 SpecialOpaque ospe2 (s2);
277 CHECK ( isnil(ospe0));
278 CHECK (!isnil(ospe1));
279 CHECK (!isnil(ospe2));
281 CHECK (7 == ospe1->getIt());
282 CHECK (6 == ospe1.get<Special>().myVal_);
283 CHECK (3 == ospe2.get<Special>().myVal_);
287 CHECK (5 == ospe1->getIt());
290 Opaque normal = DD<5>();
292 CHECK (5 == normal->getIt());
294 // Assertion protects against SEGV void checkSpecialSubclass()
void checkHandling(TestList &objs)
#define VERIFY_ERROR(ERROR_ID, ERRONEOUS_STATEMENT)
Macro to verify that a statement indeed raises an exception.
const size_t _ALIGN_
maximum additional storage maybe wasted due to alignment of the contained object within OpaqueHolder'...
Implementation namespace for support and library code.
Inline buffer to hold and own an object while concealing the concrete type.
Simple test class runner.
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...
Helper allowing type erasure while holding the actual object inline.
void for_each(CON const &elements, FUN function, P1 &&bind1, ARGS &&...args)
Accept binding for arbitrary function arguments.
A collection of frequently used helper functions to support unit testing.
SUB & get() const
re-accessing the concrete contained object.
Perform operations "for each element" of a collection.
bool isSameObject(A const &a, B const &b)
compare plain object identity, bypassing any custom comparison operators.