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)
5  2009, 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 
14 
29 #ifndef COMMAND_TEST_DUMMY_COMMANDS_H
30 #define COMMAND_TEST_DUMMY_COMMANDS_H
31 
32 #include "lib/error.hpp"
33 #include "lib/test/test-helper.hpp"
35 
36 #include <functional>
37 #include <sstream>
38 #include <string>
39 
40 
41 namespace steam {
42 namespace control {
43 namespace test {
44 
45  using std::ostringstream;
46  using std::function;
47  using std::string;
48 
49 
50 
51 
52  namespace command1 {
53 
54  extern int64_t check_;
55 
56 
57  inline void
58  operate (int someVal)
59  {
60  check_ += someVal;
61  }
62 
63  inline int64_t
64  capture (int)
65  {
66  return check_;
67  }
68 
69  inline void
70  undoIt (int, int64_t oldVal)
71  {
72  check_ = oldVal;
73  }
74 
75  }
76 
77 
78 
79 
80 
81  namespace command2 {
82 
84 
85 
86  extern ostringstream check_;
87 
88 
89  typedef function<string()> FunS;
90 
91  inline void
92  operate (FunS func, bool *fail)
93  {
94  if (fail and *fail) throw External("simulated exception");
95 
96  check_ << func();
97  }
98 
99  inline string
100  capture (FunS, bool*)
101  {
102  return check_.str();
103  }
104 
105  inline void
106  undoIt (FunS, bool *fail, string previousProtocol)
107  {
108  if (fail and *fail) throw External("simulated exception in UNDO");
109 
110  check_.str("");
111  check_ << previousProtocol << "|UNDO|";
112  }
113 
114  }
115 
116 
117 
118 
119 
120  namespace command3 {
121 
122  extern ulong check_;
123 
124 
125  inline void
126  operate ()
127  {
128  ++check_;
129  }
130 
131  inline ulong
132  capture ()
133  {
134  return check_;
135  }
136 
137  inline void
138  undoIt (ulong oldVal)
139  {
140  check_ = oldVal;
141  }
142 
143  }
144 
145 
146  /* ==== global static prototype definitions for these commands ==== */
147 
149  extern CommandSetup test_Dummy_command1;
150 
153  extern CommandSetup test_Dummy_command2;
154 
156  extern CommandSetup test_Dummy_command3;
157 
158 
159 }}} // namespace steam::control::test
160 #endif
CommandSetup test_Dummy_command3
test dummy command to increment a global variable; no arguments
Definition: run.hpp:40
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:190
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).