Lumiera 0.pre.04~rc.1
»edit your freedom«
Loading...
Searching...
No Matches
command-equality-test.cpp
Go to the documentation of this file.
1/*
2 CommandEquality(Test) - verify equality comparisons on command's subsystems
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"
28#include "lib/format-cout.hpp"
29#include "lib/symbol.hpp"
30#include "lib/util.hpp"
31
32#include <functional>
33#include <string>
34#include <tuple>
35
36namespace steam {
37namespace control {
38namespace test {
39
40
41
42 using namespace lib::meta;
43 using lib::Symbol;
44 using util::isnil;
46
47 using std::function;
48 using std::bind;
49 using std::string;
50 using std::make_tuple;
51
52
53
54 namespace {
55
56 string check_;
57
58 Symbol COMMAND1 ("test.equalityCommand1");
59 Symbol COMMAND2 ("test.equalityCommand2");
60
61 const string MARK_1 ("|_1_");
62 const string MARK_2 ("|_2_");
63
64 void oper_1 (char par) { check_ += MARK_1 + par; }
65 void oper_2 (char par) { check_ += MARK_2 + par; }
66
67 string capt_1 (char par) { return check_ + MARK_1 + "|"+par+"|"; }
68 string capt_2 (char par) { return check_ + MARK_2 + "|"+par+"|"; }
69
70 void undo_1 (char par, string mem) { check_ = mem + MARK_1 + par + "|";}
71 void undo_2 (char par, string mem) { check_ = mem + MARK_2 + par + "|";}
72
73
74 typedef void Sig_oper(char);
75 typedef string Sig_capt(char);
76 typedef void Sig_undo(char,string);
77
81
82 using ArgTuple = std::tuple<char>;
86 }
87
88
89
90 /*************************************************************************************/
102 class CommandEquality_test : public Test
103 {
104
105 virtual void
106 run (Arg)
107 {
108 CHECK (&oper_1 != &oper_2);
109 CHECK (&capt_1 != &capt_2);
110 CHECK (&undo_1 != &undo_2);
111
112 CommandDef (COMMAND1)
113 .operation (oper_1)
114 .captureUndo (capt_1)
115 .undoOperation (undo_1)
116 ;
117 CommandDef (COMMAND2)
118 .operation (oper_2)
119 .captureUndo (capt_2)
120 .undoOperation (undo_2)
121 ;
122
123 Command c1 = Command::get(COMMAND1);
124 Command c2 = Command::get(COMMAND2);
125 CHECK (c1 == c1);
126 CHECK (c1 != c2);
127 CHECK (c2 != c1);
128
129 Command cx = c1;
130 CHECK (c1 == cx);
131 CHECK (cx == c1);
132 CHECK (!isSameObject (c1, c2));
133
134 // verify equality matches behaviour
135 string protocol1 = execCommand(c1);
136 string protocolX = execCommand(cx);
137 string protocol2 = execCommand(c2);
138
141 }
142
143
147 string
149 {
150 check_ = "(start)";
151 com.bind('o');
152 com();
153 cout << com << ":" << check_ << endl;
154 com.undo();
155 cout << com << ":" << check_ << endl;
156 return check_;
157 }
158 };
159
160
162 LAUNCHER (CommandEquality_test, "function controller");
163
164
165}}} // namespace steam::control::test
Implementation helper to bind Steam-Layer commands with arbitrary argument tuples.
Token or Atom with distinct identity.
Definition symbol.hpp:120
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
static Command get(Symbol cmdID)
Access existing command for use.
Definition command.cpp:120
string execCommand(Command com)
Helper: invoke and undo a command,.
Actually defining a command and binding it to execution parameters.
Core of a Steam-Layer command: functor containing the operation to be executed.
Proof-of-concept implementation of CmdClosure.
A passive container record holding the actual command arguments & UNDO state.
Automatically use custom string conversion in C++ stream output.
A special binding used by Steam-Layer commands for capturing UNDO state information.
enable_if_c< Cond::value, T >::type enable_if
SFINAE helper to control the visibility of specialisations and overloads.
Definition meta/util.hpp:87
Steam-Layer implementation namespace root.
Test runner and basic definitions for tests.
bool isSameObject(A const &a, B const &b)
compare plain object identity, based directly on the referee's memory identities.
Definition util.hpp:421
bool isnil(lib::time::Duration const &dur)
Simplistic test class runner.
#define LAUNCHER(_TEST_CLASS_, _GROUPS_)
Definition run.hpp:116
Marker types to indicate a literal string and a Symbol.
A collection of frequently used helper functions to support unit testing.
Metaprogramming with tuples-of-types and the std::tuple record.
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...