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)
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"
20 #include "lib/test/test-helper.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 
36 namespace steam {
37 namespace control {
38 namespace test {
39 
40 
41 
42  using namespace lib::meta;
43  using lib::Symbol;
44  using util::isnil;
45  using util::isSameObject;
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 
78  typedef function<Sig_oper> Fun_o;
79  typedef function<Sig_capt> Fun_c;
80  typedef function<Sig_undo> Fun_u;
81 
82  using ArgTuple = Tuple<Types<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 
139  CHECK (protocol1 == protocolX);
140  CHECK (protocol1 != protocol2);
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
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:40
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:120
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:117
Marker types to indicate a literal string and a Symbol.
Simplistic 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:115
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:79
bool isSameObject(A const &a, B const &b)
compare plain object identity, based directly on the referee&#39;s memory identities. ...
Definition: util.hpp:421
A passive container record holding the actual command arguments & UNDO state.