Lumiera  0.pre.03
»edit your freedom«
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) 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 
28 #include "lib/test/run.hpp"
29 #include "lib/test/test-helper.hpp"
37 #include "lib/format-cout.hpp"
38 #include "lib/symbol.hpp"
39 #include "lib/util.hpp"
40 
41 #include <functional>
42 #include <string>
43 #include <tuple>
44 
45 namespace steam {
46 namespace control {
47 namespace test {
48 
49 
50 
51  using namespace lib::meta;
52  using lib::Symbol;
53  using util::isnil;
54  using util::isSameObject;
55 
56  using std::function;
57  using std::bind;
58  using std::string;
59  using std::make_tuple;
60 
61 
62 
63  namespace {
64 
65  string check_;
66 
67  Symbol COMMAND1 ("test.equalityCommand1");
68  Symbol COMMAND2 ("test.equalityCommand2");
69 
70  const string MARK_1 ("|_1_");
71  const string MARK_2 ("|_2_");
72 
73  void oper_1 (char par) { check_ += MARK_1 + par; }
74  void oper_2 (char par) { check_ += MARK_2 + par; }
75 
76  string capt_1 (char par) { return check_ + MARK_1 + "|"+par+"|"; }
77  string capt_2 (char par) { return check_ + MARK_2 + "|"+par+"|"; }
78 
79  void undo_1 (char par, string mem) { check_ = mem + MARK_1 + par + "|";}
80  void undo_2 (char par, string mem) { check_ = mem + MARK_2 + par + "|";}
81 
82 
83  typedef void Sig_oper(char);
84  typedef string Sig_capt(char);
85  typedef void Sig_undo(char,string);
86 
87  typedef function<Sig_oper> Fun_o;
88  typedef function<Sig_capt> Fun_c;
89  typedef function<Sig_undo> Fun_u;
90 
91  using ArgTuple = Tuple<Types<char>>;
95  }
96 
97 
98 
99  /*************************************************************************************/
111  class CommandEquality_test : public Test
112  {
113 
114  virtual void
115  run (Arg)
116  {
117  CHECK (&oper_1 != &oper_2);
118  CHECK (&capt_1 != &capt_2);
119  CHECK (&undo_1 != &undo_2);
120 
121  CommandDef (COMMAND1)
122  .operation (oper_1)
123  .captureUndo (capt_1)
124  .undoOperation (undo_1)
125  ;
126  CommandDef (COMMAND2)
127  .operation (oper_2)
128  .captureUndo (capt_2)
129  .undoOperation (undo_2)
130  ;
131 
132  Command c1 = Command::get(COMMAND1);
133  Command c2 = Command::get(COMMAND2);
134  CHECK (c1 == c1);
135  CHECK (c1 != c2);
136  CHECK (c2 != c1);
137 
138  Command cx = c1;
139  CHECK (c1 == cx);
140  CHECK (cx == c1);
141  CHECK (!isSameObject (c1, c2));
142 
143  // verify equality matches behaviour
144  string protocol1 = execCommand(c1);
145  string protocolX = execCommand(cx);
146  string protocol2 = execCommand(c2);
147 
148  CHECK (protocol1 == protocolX);
149  CHECK (protocol1 != protocol2);
150  }
151 
152 
156  string
158  {
159  check_ = "(start)";
160  com.bind('o');
161  com();
162  cout << com << ":" << check_ << endl;
163  com.undo();
164  cout << com << ":" << check_ << endl;
165  return check_;
166  }
167  };
168 
169 
171  LAUNCHER (CommandEquality_test, "function controller");
172 
173 
174 }}} // namespace steam::control::test
Helper class used solely for defining a Command-Object.
Automatically use custom string conversion in C++ stream output.
typename BuildTupleType< TYPES >::Type Tuple
Build a std::tuple from types given as type sequence.
Definition: run.hpp:49
Core of a Steam-Layer command: functor containing the operation to be executed.
Implementation helper to bind Steam-Layer commands with arbitrary argument tuples.
Proof-of-concept implementation of CmdClosure.
static Command get(Symbol cmdID)
Access existing command for use.
Definition: command.cpp:129
Steam-Layer implementation namespace root.
closure to deal with the actual command operation.
Metaprogramming with tuples-of-types and the std::tuple record.
A special binding used by Steam-Layer commands for capturing UNDO state information.
Token or Atom with distinct identity.
Definition: symbol.hpp:126
Marker types to indicate a literal string and a Symbol.
Simple test class runner.
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...
string execCommand(Command com)
Helper: invoke and undo a command,.
Dummy / proof-of-concept implementation of CmdClosure.
A collection of frequently used helper functions to support unit testing.
Handle object representing a single Command instance to be used by client code.
Definition: command.hpp:124
RET bind()
Accept dummy binding (0 Arg)
Actually defining a command and binding it to execution parameters.
Binding together state capturing and execution of the undo operation.
Definition: memento-tie.hpp:88
bool isSameObject(A const &a, B const &b)
compare plain object identity, bypassing any custom comparison operators.
Definition: util.hpp:372
A passive container record holding the actual command arguments & UNDO state.