Lumiera  0.pre.03
»edit your freedom«
test-dummy-commands.hpp
Go to the documentation of this file.
1 /*
2  TEST-DUMMY-COMMANDS.hpp - dummy functions used to build test commands
3 
4  Copyright (C) Lumiera.org
5  2009, 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 
23 
38 #ifndef COMMAND_TEST_DUMMY_COMMANDS_H
39 #define COMMAND_TEST_DUMMY_COMMANDS_H
40 
41 #include "lib/error.hpp"
42 #include "lib/test/test-helper.hpp"
44 
45 #include <functional>
46 #include <sstream>
47 #include <string>
48 
49 
50 namespace steam {
51 namespace control {
52 namespace test {
53 
54  using std::ostringstream;
55  using std::function;
56  using std::string;
57 
58 
59 
60 
61  namespace command1 {
62 
63  extern int64_t check_;
64 
65 
66  inline void
67  operate (int someVal)
68  {
69  check_ += someVal;
70  }
71 
72  inline int64_t
73  capture (int)
74  {
75  return check_;
76  }
77 
78  inline void
79  undoIt (int, int64_t oldVal)
80  {
81  check_ = oldVal;
82  }
83 
84  }
85 
86 
87 
88 
89 
90  namespace command2 {
91 
93 
94 
95  extern ostringstream check_;
96 
97 
98  typedef function<string()> FunS;
99 
100  inline void
101  operate (FunS func, bool *fail)
102  {
103  if (fail and *fail) throw External("simulated exception");
104 
105  check_ << func();
106  }
107 
108  inline string
109  capture (FunS, bool*)
110  {
111  return check_.str();
112  }
113 
114  inline void
115  undoIt (FunS, bool *fail, string previousProtocol)
116  {
117  if (fail and *fail) throw External("simulated exception in UNDO");
118 
119  check_.str("");
120  check_ << previousProtocol << "|UNDO|";
121  }
122 
123  }
124 
125 
126 
127 
128 
129  namespace command3 {
130 
131  extern ulong check_;
132 
133 
134  inline void
135  operate ()
136  {
137  ++check_;
138  }
139 
140  inline ulong
141  capture ()
142  {
143  return check_;
144  }
145 
146  inline void
147  undoIt (ulong oldVal)
148  {
149  check_ = oldVal;
150  }
151 
152  }
153 
154 
155  /* ==== global static prototype definitions for these commands ==== */
156 
158  extern CommandSetup test_Dummy_command1;
159 
162  extern CommandSetup test_Dummy_command2;
163 
165  extern CommandSetup test_Dummy_command3;
166 
167 
168 }}} // namespace steam::control::test
169 #endif
CommandSetup test_Dummy_command3
test dummy command to increment a global variable; no arguments
Definition: run.hpp:49
CommandSetup test_Dummy_command1
test dummy command to add the argument to a global variable
Steam-Layer implementation namespace root.
Derived specific exceptions within Lumiera&#39;s exception hierarchy.
Definition: error.hpp:199
CommandSetup test_Dummy_command2
test dummy command to invoke the given functor and append the result onto a global log string buffer ...
Provision for setup of concrete commands for use by the UI.
A collection of frequently used helper functions to support unit testing.
Lumiera error handling (C++ interface).