Lumiera  0.pre.03
»edit your freedom«
iter-stack-test.cpp
Go to the documentation of this file.
1 /*
2  IterStack(Test) - verify stack-like iterator
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  typedef IterStack<int> IStack;
48 
49 
50 
51 
52  /*****************************************************************/
63  class IterStack_test : public Test
64  {
65 
66  virtual void
67  run (Arg)
68  {
69  IStack stack;
70  CHECK (isnil (stack));
71 
72  VERIFY_ERROR (ITER_EXHAUST, *stack );
73  VERIFY_ERROR (ITER_EXHAUST, ++stack );
74 
75  stack.push (1);
76  stack.push (3);
77  stack.push (5);
78  stack.push (7);
79  stack.push (9);
80 
81  CHECK (!isnil (stack));
82  CHECK (9 == *stack);
83 
84  ++stack;
85  CHECK (7 == *stack);
86 
87  CHECK (7 == stack.pop());
88  CHECK (5 == *stack);
89 
90  ++++stack;
91  CHECK (1 == *stack);
92  CHECK (1 == stack.pop());
93 
94  CHECK (isnil (stack));
95  VERIFY_ERROR (ITER_EXHAUST, *stack );
96  VERIFY_ERROR (ITER_EXHAUST, ++stack );
97  VERIFY_ERROR (ITER_EXHAUST, stack.pop() );
98 
99 
100  stack.push(23);
101  CHECK (23 == *stack);
102 
103  int i = stack.pop();
104  CHECK (i == 23);
105  VERIFY_ERROR (ITER_EXHAUST, *stack );
106  CHECK (isnil (stack));
107  }
108 
109  };
110 
111 
112  LAUNCHER (IterStack_test, "unit common");
113 
114 
115 }} // namespace lib::test
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.
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.