Lumiera  0.pre.03
»edit your freedom«
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) Lumiera.org
5  2012, Hermann Vosseler <Ichthyostega@web.de>
6 
7  This program is free software; you can redistribute it and/or
8  modify it under the terms of the GNU General Public License as
9  published by the Free Software Foundation; either version 2 of
10  the License, or (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 
21 * *****************************************************/
22 
29 #include "lib/test/run.hpp"
30 #include "lib/test/test-helper.hpp"
31 #include "lib/util.hpp"
32 
33 #include "lib/iter-stack.hpp"
34 
35 
36 
37 namespace lib {
38 namespace test{
39 
40  using ::Test;
41  using util::isnil;
42  using LERR_(ITER_EXHAUST);
43 
44 
45 
46 
47 
48 
49  /*****************************************************************/
60  class IterQueue_test : public Test
61  {
62 
63  virtual void
64  run (Arg)
65  {
66  IterQueue<int> queue;
67  CHECK (isnil (queue));
68 
69  VERIFY_ERROR (ITER_EXHAUST, *queue );
70  VERIFY_ERROR (ITER_EXHAUST, ++queue );
71 
72  queue.feed (1);
73  queue.feed (3);
74  queue.feed (5);
75 
76  CHECK (!isnil (queue));
77  CHECK (1 == *queue);
78 
79  ++queue;
80  CHECK (3 == *queue);
81 
82  CHECK (3 == queue.pop());
83  CHECK (5 == *queue);
84 
85  ++queue;
86  CHECK (isnil (queue));
87  VERIFY_ERROR (ITER_EXHAUST, *queue );
88  VERIFY_ERROR (ITER_EXHAUST, ++queue );
89  VERIFY_ERROR (ITER_EXHAUST, queue.pop() );
90 
91 
92  // use the generic builder API to feed
93  // the contents of another iterator into the queue
94  queue = build(queue).usingSequence (elements (23,45));
95 
96  int i = queue.pop();
97  CHECK (i == 23);
98  CHECK (45 == *queue);
99 
100  // feeding new elements and pulling / iteration can be mixed
101  queue.feed(67);
102  CHECK (45 == *queue);
103  ++queue;
104  CHECK (67 == *queue);
105  ++queue;
106  CHECK (isnil (queue));
107  queue.feed(89);
108  CHECK (89 == *queue);
109  queue.pop();
110  VERIFY_ERROR (ITER_EXHAUST, *queue );
111  }
112 
113  };
114 
115 
116  LAUNCHER (IterQueue_test, "unit common");
117 
118 
119 }} // namespace lib::test
IterQueue< T > elements(T const &elm)
convenience free function to build an iterable sequence
Definition: iter-stack.hpp:301
Definition: run.hpp:49
Conveniently iterable stack and queue containers.
#define VERIFY_ERROR(ERROR_ID, ERRONEOUS_STATEMENT)
Macro to verify that a statement indeed raises an exception.
Implementation namespace for support and library code.
A Queue which can be pulled by iterating.
Definition: iter-stack.hpp:197
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.