Lumiera 0.pre.04
»edit your freedom«
Loading...
Searching...
No Matches
command-use2-test.cpp
Go to the documentation of this file.
1/*
2 CommandUse2(Test) - usage aspects II
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
19#include "lib/test/run.hpp"
24#include "lib/format-string.hpp"
25#include "lib/format-obj.hpp"
26#include "lib/util.hpp"
27
29
30extern "C" {
32}
35
36#include <functional>
37#include <boost/ref.hpp>
38#include <boost/lexical_cast.hpp>
39#include <string>
40
41
42namespace steam {
43namespace control {
44namespace test {
45
46 using util::_Fmt;
47 using std::string;
48 using std::function;
49 using std::bind;
50 using std::ref;
51 using boost::lexical_cast;
52 using util::contains;
53
54 using LERR_(EXTERNAL);
55
56
62 template<typename TY>
63 inline bool
65 {
66 return contains ( command2::check_.str()
68 );
69 }
70
71
72
73
74 /***********************************************************************/
82 class CommandUse2_test : public Test
83 {
84
86
87 string randomTxt()
88 {
89 _Fmt fmt ("invoked( %2d )");
90
91 randVal_ = rani (100);
92 return fmt % randVal_;
93 }
94
95 bool blowUp_;
96
97
98 virtual void
99 run (Arg)
100 {
101 seedRand();
102 command2::check_.seekp(0);
103 uint cnt_defs = Command::definition_count();
104 uint cnt_inst = Command::instance_count();
105
106 function<string()> randFun = bind (&CommandUse2_test::randomTxt, this);
107
108 // prepare a command definition (prototype)
109 CommandDef ("test.command2")
111 .captureUndo (command2::capture)
112 .undoOperation (command2::undoIt)
113 .bind (randFun, &blowUp_);
114
115 //note : blowUp_ is bound via pointer,
116 // thus we can provoke an exception at will.
117 blowUp_ = false;
118
119
121// check_ThrowOnError(); //////////////////////////////////////////////////////////////////////TICKET #211
123
124
125 Command::remove ("test.command2");
126 Command::remove ("test.command2.1");
127 CHECK (cnt_defs == Command::definition_count());
128 CHECK (cnt_inst == Command::instance_count());
129 }
130
131
132
133 void
135 {
136 Command com = Command::get("test.command2");
137
138 CHECK (!protocolled("invoked"));
139
140 bool success = com();
141
142 CHECK (success);
143 CHECK (protocolled("invoked"));
145
146 success = com.undo();
147 CHECK (success); // UNDO invoked successfully
149 CHECK (protocolled("UNDO"));
150
151 blowUp_ = true;
152 string current = command2::check_.str();
153
154 success = com();
155 CHECK (not success); // NOT executed successfully (exception thrown and caught)
156 CHECK (command2::check_.str() == current);
157 CHECK (!lumiera_error_peek()); // already absorbed
158
159 success = com.undo();
160 CHECK (not success); // UNDO failed (exception thrown and caught)
161 CHECK (command2::check_.str() == current);
162
163 blowUp_ = false;
164 }
165
166
167
168 void
170 {
171 Command com = Command::get("test.command2");
172
173 blowUp_ = false;
176
177 blowUp_ = true;
178 string current = command2::check_.str();
180
181 VERIFY_ERROR( EXTERNAL, com.exec (doThrow) );
182 CHECK (command2::check_.str() == current);
183
184 // we can achieve the same effect,
185 // after changing the default HandlingPatern for this command instance
187 com.storeDef ("test.command2.1");
188
189 Command com2 = Command::get("test.command2.1");
190 VERIFY_ERROR( EXTERNAL, com2() );
191 CHECK (command2::check_.str() == current);
192
193 blowUp_ = false;
194 com2();
195 CHECK (command2::check_.str() > current);
197
198 com2.undo();
200 }
201
202
203
213 void
215 {
216 CHECK (not SteamDispatcher::instance().isRunning());
219#define __DELAY__ usleep(10000);
220
221 bool thread_has_ended{false};
222 SteamDispatcher::instance().start ([&] (string*) { thread_has_ended = true; });
223
224 CHECK (SteamDispatcher::instance().isRunning());
225 CHECK (not thread_has_ended);
226
227 //----Session-Loop-Thread-is-running------------------------
228
229 string cmdID {"test.command2"};
230 string prevExecLog = command2::check_.str();
231
232 // previous test cases prepared the arguments
233 // so that we can just trigger command execution.
234 // In the real application, this call is issued
235 // from CoreService when receiving a command
236 // invocation message over the UI-Bus
237 SessionCommand::facade().invoke(cmdID);
238
239 __DELAY__ // wait a moment for the other thread to dispatch the command...
241
242 //----Session-Loop-Thread-is-running------------------------
243
244 // shut down the SteamDispatcher...
245 CHECK (SteamDispatcher::instance().isRunning());
246 SteamDispatcher::instance().requestStop();
247
248 __DELAY__ // wait a moment for the other thread to terminate...
249 CHECK (not SteamDispatcher::instance().isRunning());
250 CHECK (thread_has_ended);
251
253 }
254 };
255
256
258 LAUNCHER (CommandUse2_test, "function controller");
259
260
261}}} // namespace steam::control::test
Helper class used solely for defining a Command-Object.
auto operation(FUN operation_to_define)
Handle object representing a single Command instance to be used by client code.
Definition command.hpp:120
HandlingPattern::ID setHandlingPattern(HandlingPattern::ID)
define a handling pattern to be used by default
Definition command.cpp:465
static size_t definition_count()
Definition command.cpp:289
static Command get(Symbol cmdID)
Access existing command for use.
Definition command.cpp:120
static bool remove(Symbol cmdID)
Definition command.cpp:241
Command storeDef(Symbol newCmdID) const
create a clone definition
Definition command.cpp:183
static size_t instance_count()
Definition command.cpp:298
Interface: Operation Skeleton how to invoke or undo a command.
static HandlingPattern const & get(ID id)
retrieve the pre-configured pattern
static lib::Depend< SessionCommand > facade
static storage for the facade access front-end
static lib::Depend< SteamDispatcher > instance
storage for Singleton access
A front-end for using printf-style formatting.
Actually defining a command and binding it to execution parameters.
#define __DELAY__
Steam-Layer command frontend.
lumiera_err lumiera_error_peek(void)
Check current error state without clearing it Please avoid this function and use lumiera_error() if p...
#define LERR_(_NAME_)
Definition error.hpp:45
Simple functions to represent objects, for debugging and diagnostics.
Front-end for printf-style string template interpolation.
Pre-defined command execution skeletons.
unsigned int uint
Definition integral.hpp:29
void lumiera_interfaceregistry_init(void)
Initialise the interface registry.
void lumiera_interfaceregistry_destroy(void)
Global registry for interfaces (extension points).
enable_if_c< Cond::value, T >::type enable_if
SFINAE helper to control the visibility of specialisations and overloads.
Definition meta/util.hpp:87
void throwOnError()
Check the lumiera error state, which maybe was set by C-code.
Definition error.hpp:234
void undoIt(FunS, bool *fail, string previousProtocol)
void operate(FunS func, bool *fail)
bool protocolled(TY val2check)
diagnostics: checks if the given value has been written to the test protocol (string stream) of comma...
Steam-Layer implementation namespace root.
Test runner and basic definitions for tests.
bool contains(MAP &map, typename MAP::key_type const &key)
shortcut for containment test on a map
Definition util.hpp:230
std::string toString(TY const &val) noexcept
get some string representation of any object, reliably.
Simplistic test class runner.
#define LAUNCHER(_TEST_CLASS_, _GROUPS_)
Definition run.hpp:116
Major public Interface to the Session subsystem of Lumiera GUI.
Dispatch and execute mutation operations on the High-level model.
Some dummy command functions used for building unit test cases.
A collection of frequently used helper functions to support unit testing.
#define VERIFY_ERROR(ERROR_ID, ERRONEOUS_STATEMENT)
Macro to verify that a statement indeed raises an exception.
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...