40 using LERR_(ITER_EXHAUST);
47 const uint NUM_ELEMENTS = 500;
48 int exception_trigger = -1;
50 inline void __triggerErrorAt(
int i) { exception_trigger = i; }
51 inline void __triggerError_reset() { exception_trigger =-1; }
73 if (i == exception_trigger)
74 throw error::Fatal(
"simulated error", LUMIERA_ERROR_PROVOKED_FAILURE);
88 Num (
int i=0,
int j=0,
int k=0)
117 uint current = num->getVal();
118 if (maxNum_ <= current)
121 num =
new Nummy(current+1);
132 :
public NummyGenerator::iterator
137 : NummyGenerator::iterator (
180 verify_nonOwnership();
181 verify_ExceptionSafety();
182 populate_by_iterator();
183 verify_RAII_safety();
184 verify_customAllocator();
191 CHECK (0 == Dummy::checksum());
194 CHECK (isnil (elements));
195 CHECK (0 == elements.
size());
196 CHECK (0 == Dummy::checksum());
203 CHECK (!isnil (elements));
204 CHECK (5 == elements.
size());
205 CHECK (0 != Dummy::checksum());
207 CHECK (Dummy::checksum() == elements[0].getVal()
208 + elements[1].getVal()
209 + elements[2].getVal()
210 + elements[3].getVal()
211 + elements[4].getVal());
214 CHECK (isnil (elements));
215 CHECK (0 == elements.
size());
216 CHECK (0 == Dummy::checksum());
222 CHECK (3 == elements.
size());
223 CHECK (0 != Dummy::checksum());
225 CHECK (0 == Dummy::checksum());
232 CHECK (0 == Dummy::checksum());
235 for (uint i=1; i<=NUM_ELEMENTS; ++i)
240 int check=NUM_ELEMENTS;
244 CHECK (check == ii->getVal());
245 CHECK (check == ii->calc(+5) - 5);
253 List const& const_elm (elements);
254 check = NUM_ELEMENTS;
258 CHECK (check == cii->getVal());
266 CHECK (! (elements.end()));
267 CHECK (isnil (elements.end()));
272 CHECK (ii == elements.end());
274 CHECK (cii == elements.end());
280 CHECK (0 == Dummy::checksum());
287 CHECK (0 == Dummy::checksum());
290 CHECK (isnil (list));
292 CHECK (isnil (list));
293 CHECK (0 == Dummy::checksum());
296 CHECK (not isnil (list));
297 CHECK (1 == list[0].getVal());
298 CHECK (1 == Dummy::checksum());
300 CHECK (1 == Dummy::checksum());
301 CHECK (1 == list[0].getVal());
302 CHECK (not isnil (list));
305 CHECK (not isnil (list));
306 CHECK (2 == list.
size());
307 CHECK (2 == list[0].getVal());
308 CHECK (2+1 == Dummy::checksum());
310 CHECK (1+2 == Dummy::checksum());
311 CHECK (1 == list[0].getVal());
312 CHECK (2 == list.
size());
315 CHECK (3 == list.
size());
316 CHECK (3 == list.
top().getVal());
317 CHECK (3+1+2 == Dummy::checksum());
319 CHECK (2 == list[0].getVal());
320 CHECK (1 == list[1].getVal());
321 CHECK (3 == list[2].getVal());
323 CHECK (2 == ii->getVal());
325 CHECK (1 == ii->getVal());
327 CHECK (3 == ii->getVal());
330 CHECK (2+1+3 == Dummy::checksum());
333 CHECK (4 == list.
top().getVal());
334 CHECK (3 == list[3].getVal());
336 CHECK (3 == list[0].getVal());
337 CHECK (1 == list[1].getVal());
338 CHECK (2 == list[2].getVal());
339 CHECK (4 == list[3].getVal());
340 CHECK (3+1+2+4 == Dummy::checksum());
342 CHECK (0 == Dummy::checksum());
357 CHECK (0 == Dummy::checksum());
360 CHECK (isnil (elements));
365 CHECK (22+44+66 == Dummy::checksum());
370 CHECK (!isnil (elements));
371 CHECK (3 == elements.
size());
372 CHECK (22+44+66 == Dummy::checksum());
374 CHECK (66 == elements[0].getVal());
375 CHECK (44 == elements[1].getVal());
376 CHECK (22 == elements[2].getVal());
377 CHECK (isSameObject(n2, elements[2]));
378 CHECK (isSameObject(n4, elements[1]));
379 CHECK (isSameObject(n6, elements[0]));
382 CHECK (isnil (elements));
383 CHECK (22+44+66 == Dummy::checksum());
385 CHECK (0 == Dummy::checksum());
390 verify_ExceptionSafety()
392 CHECK (0 == Dummy::checksum());
395 CHECK (isnil (elements));
401 CHECK (1+2 == Dummy::checksum());
404 CHECK (1+2 == Dummy::checksum());
405 CHECK (2 == elements.
size());
407 CHECK (2 == elements[0].getVal());
408 CHECK (1 == elements[1].getVal());
411 CHECK (0 == Dummy::checksum());
412 __triggerError_reset();
414 CHECK (0 == Dummy::checksum());
419 populate_by_iterator()
421 CHECK (0 == Dummy::checksum());
423 Populator yieldSomeElements(NUM_ELEMENTS);
426 CHECK (!isnil (elements));
427 CHECK (NUM_ELEMENTS == elements.
size());
428 CHECK (sum(NUM_ELEMENTS) == Dummy::checksum());
430 int check=NUM_ELEMENTS;
434 CHECK (check == ii->getVal());
440 CHECK (0 == Dummy::checksum());
453 CHECK (0 == Dummy::checksum());
456 Populator yieldSomeElements(NUM_ELEMENTS);
459 CHECK (0 == Dummy::checksum());
460 __triggerError_reset();
471 CustomAllocator cluster_;
477 template<
class TY,
typename...ARGS>
479 create (ARGS&& ...args)
481 return & cluster_.create<TY> (std::forward<ARGS> (args)...);
484 void dispose (
void*) { }
501 CHECK (0 == Dummy::checksum());
508 elements.
emplace<Num<3>> (4,5);
509 elements.
emplace<Num<6>> (7,8,9);
511 const size_t EXPECT =
sizeof(Num<1>) +
sizeof(Num<3>) +
sizeof(Num<6>)
513 CHECK (EXPECT == cluster.
numBytes());
514 CHECK (sum(9) == Dummy::checksum());
516 CHECK (3 == elements.
size());
517 CHECK (1+2 == elements[2].getVal());
518 CHECK (3+4+5 == elements[1].getVal());
519 CHECK (6+7+8+9 == elements[0].getVal());
522 CHECK (EXPECT == cluster.
numBytes());
523 CHECK (sum(9) == Dummy::checksum());
527 CHECK (0 == Dummy::checksum());
534 Elms
elements{cluster.getAllocator<Nummy>()};
539 const size_t EXPECT =
sizeof(Num<1>) +
sizeof(Num<3>);
540 CHECK (EXPECT == cluster.
numBytes());
541 CHECK (sum(5) == Dummy::checksum());
544 CHECK (1+2 ==
elements[1].getVal());
545 CHECK (3+4+5 ==
elements[0].getVal());
550 CHECK (0 == Dummy::checksum());
LinkedElements & reverse()
Mutate the complete list to change the order of elements.
IterQueue< T > elements(T const &elm)
convenience free function to build an iterable sequence
TY & emplace(ARGS &&...args)
prepend object of type TY, forwarding ctor args
Policy to use an Allocation cluster, but also to invoke all object destructors.
Memory management for the low-level model (render nodes network).
Intrusive single linked list, possibly taking ownership of node elements.
#define VERIFY_ERROR(ERROR_ID, ERRONEOUS_STATEMENT)
Macro to verify that a statement indeed raises an exception.
Iterator-Frontend to generate this series of objects.
Implementation namespace for support and library code.
void verify_customAllocator()
Derived specific exceptions within Lumiera's exception hierarchy.
Iteration source interface to abstract a data source, which then can be accessed through IterAdapter ...
Simplistic test class runner.
Another Lumiera Forward Iterator building block, based on incorporating a state type as »*State Core*...
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...
unittest helper code: test dummy objects to track instances.
Helper to produce a pre-determined series of objects to populate a LinkedElements list...
A collection of frequently used helper functions to support unit testing.
Intrusive single linked list with optional ownership.
A Dummy object for tests.
A pile of objects sharing common allocation and lifecycle.
TY & push(TY &elm) noexcept
accept the given element and prepend it to the list of elements; depending on the allocation policy...
void verify_RAII_safety()
to demonstrate holding subclasses
virtual Pos firstResult()
iteration start: prepare the first element.
virtual void nextResult(Pos &num)
iteration step: switch on to the next element.
void verify_nonOwnership()
Extension module to build an opaque data source, accessible as Lumiera Forward Iterator.
Test-Element, supporting intrusive linked list storage.
#define LUMIERA_ERROR_DEFINE(err, msg)
Definition and initialisation of an error constant.
bool isSameObject(A const &a, B const &b)
compare plain object identity, based directly on the referee's memory identities. ...