Lumiera 0.pre.04
»edit your freedom«
Loading...
Searching...
No Matches
iter-queue-test.cpp
Go to the documentation of this file.
1/*
2 IterQueue(Test) - verify queue-like iterator and builder function
3
4 Copyright (C)
5 2012, Hermann Vosseler <Ichthyostega@web.de>
6
7  **Lumiera** is free software; you can redistribute it and/or modify it
8  under the terms of the GNU General Public License as published by the
9  Free Software Foundation; either version 2 of the License, or (at your
10  option) any later version. See the file COPYING for further details.
11
12* *****************************************************************/
13
20#include "lib/test/run.hpp"
22#include "lib/util.hpp"
23
24#include "lib/iter-stack.hpp"
25
26
27
28namespace lib {
29namespace test{
30
31 using ::Test;
32 using util::isnil;
33 using LERR_(ITER_EXHAUST);
34
35
36
37
38
39
40 /*****************************************************************/
51 class IterQueue_test : public Test
52 {
53
54 virtual void
55 run (Arg)
56 {
57 IterQueue<int> queue;
58 CHECK (isnil (queue));
59
60 VERIFY_ERROR (ITER_EXHAUST, *queue );
61 VERIFY_ERROR (ITER_EXHAUST, ++queue );
62
63 queue.feed (1);
64 queue.feed (3);
65 queue.feed (5);
66
67 CHECK (!isnil (queue));
68 CHECK (1 == *queue);
69
70 ++queue;
71 CHECK (3 == *queue);
72
73 CHECK (3 == queue.pop());
74 CHECK (5 == *queue);
75
76 ++queue;
77 CHECK (isnil (queue));
78 VERIFY_ERROR (ITER_EXHAUST, *queue );
79 VERIFY_ERROR (ITER_EXHAUST, ++queue );
80 VERIFY_ERROR (ITER_EXHAUST, queue.pop() );
81
82
83 // use the generic builder API to feed
84 // the contents of another iterator into the queue
85 queue = build(queue).usingSequence (elements (23,45));
86
87 int i = queue.pop();
88 CHECK (i == 23);
89 CHECK (45 == *queue);
90
91 // feeding new elements and pulling / iteration can be mixed
92 queue.feed(67);
93 CHECK (45 == *queue);
94 ++queue;
95 CHECK (67 == *queue);
96 ++queue;
97 CHECK (isnil (queue));
98 queue.feed(89);
99 CHECK (89 == *queue);
100 queue.pop();
101 VERIFY_ERROR (ITER_EXHAUST, *queue );
102 }
103
104 };
105
106
107 LAUNCHER (IterQueue_test, "unit common");
108
109
110}} // namespace lib::test
#define LERR_(_NAME_)
Definition error.hpp:45
Conveniently iterable stack and queue containers.
Implementation namespace for support and library code.
IterQueue< T > elements(T const &elm)
convenience free function to build an iterable sequence
Test runner and basic definitions for tests.
bool isnil(lib::time::Duration const &dur)
Simplistic test class runner.
#define LAUNCHER(_TEST_CLASS_, _GROUPS_)
Definition run.hpp:116
A Queue which can be pulled by iterating.
IterQueue & feed(TY const &elm)
A collection of frequently used helper functions to support unit testing.
#define VERIFY_ERROR(ERROR_ID, ERRONEOUS_STATEMENT)
Macro to verify that a statement indeed raises an exception.
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...