Lumiera  0.pre.03
»edityourfreedom«
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
command-binding-test.cpp
Go to the documentation of this file.
1 /*
2  CommandBinding(Test) - special cases of binding command arguments
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"
31 #include "lib/format-cout.hpp"
32 
33 
34 namespace proc {
35 namespace control {
36 namespace test {
37 
38 
39 
40 
41 
42 
43 
44  /*************************************************************************/
53  class CommandBinding_test : public Test
54  {
55 
56 
57  virtual void
58  run (Arg)
59  {
60  uint cnt_defs = Command::definition_count();
61  uint cnt_inst = Command::instance_count();
62 
64 
65  Command::remove("test.command3.1");
66  Command::remove("test.command3.2");
67 
68  CHECK (cnt_defs == Command::definition_count());
69  CHECK (cnt_inst == Command::instance_count());
70  }
71 
72 
73  void
75  {
76  command3::check_ = 0;
77 
78  CommandDef ("test.command3.1")
80  .captureUndo (command3::capture)
81  .undoOperation (command3::undoIt)
82  .bind() // spurious bind doesn't hurt
83  .execSync()
84  ;
85 
86  CHECK ( 1 == command3::check_);
87 
88  CommandDef ("test.command3.2")
90  .captureUndo (command3::capture)
91  .undoOperation (command3::undoIt)
92  ;
93  Command com ("test.command3.2");
94  CHECK (com.canExec());
95  cout << com << endl;
96 
97  com();
98  CHECK ( 2 == command3::check_);
99  com.undo();
100  CHECK ( 1 == command3::check_);
101 
102  Command commi = com.newInstance();
103  com();
104  com();
105  com();
106  CHECK ( 4 == command3::check_);
107 
108  commi.undo(); // it uses the inherited UNDO state
109  CHECK ( 1 == command3::check_);
110 
111  com.undo();
112  CHECK ( 3 == command3::check_);
113 
114  Command::get("test.command3.1").undo();
115  CHECK ( 0 == command3::check_);
116  }
117  };
118 
119 
120 
122  LAUNCHER (CommandBinding_test, "function controller");
123 
124 
125 }}} // namespace proc::control::test
auto operation(FUN operation_to_define)
static size_t definition_count()
Definition: command.cpp:296
Automatically use custom string conversion in C++ stream output.
Definition: run.hpp:49
ulong check_
< test command with zero arguments
Helper class used solely for defining a Command-Object.
Command newInstance() const
create independent (anonymous) clone copy of this command
Definition: command.cpp:207
std::vector< string > & Arg
Definition: run.hpp:54
Simple test class runner.
LAUNCHER(ArgumentTupleAccept_test,"unit controller")
Register this test class...
static size_t instance_count()
Definition: command.cpp:305
static Command get(Symbol cmdID)
Access existing command for use.
Definition: command.cpp:127
bool canExec() const
Definition: command.cpp:357
Some dummy command functions used for building unit test cases.
Handle object representing a single Command instance to be used by client code.
Definition: command.hpp:125
static bool remove(Symbol cmdID)
Definition: command.cpp:248
Proc-Layer implementation namespace root.
Definition: id-scheme.hpp:63
Actually defining a command and binding it to execution parameters.
ExecResult undo()
Definition: command.hpp:246