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)
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"
21 #include "lib/test/test-helper.hpp"
22 #include "lib/util.hpp"
23 
24 #include "lib/iter-stack.hpp"
25 
26 
27 
28 namespace lib {
29 namespace 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
IterQueue< T > elements(T const &elm)
convenience free function to build an iterable sequence
Definition: iter-stack.hpp:292
Definition: run.hpp:40
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:188
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.