Lumiera  0.pre.03
»edit your freedom«
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)
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"
22 #include "lib/format-cout.hpp"
23 
24 
25 namespace steam {
26 namespace control {
27 namespace test {
28 
29 
30 
31 
32 
33 
34 
35  /*************************************************************************/
44  class CommandBinding_test : public Test
45  {
46 
47 
48  virtual void
49  run (Arg)
50  {
51  uint cnt_defs = Command::definition_count();
52  uint cnt_inst = Command::instance_count();
53 
54  zeroArgumentCommand();
55 
56  Command::remove("test.command3.1");
57  Command::remove("test.command3.2");
58 
59  CHECK (cnt_defs == Command::definition_count());
60  CHECK (cnt_inst == Command::instance_count());
61  }
62 
63 
64  void
65  zeroArgumentCommand()
66  {
67  command3::check_ = 0;
68 
69  CommandDef ("test.command3.1")
70  .operation (command3::operate)
71  .captureUndo (command3::capture)
72  .undoOperation (command3::undoIt)
73  .bind() // spurious bind doesn't hurt
74  .execSync()
75  ;
76 
77  CHECK ( 1 == command3::check_);
78 
79  CommandDef ("test.command3.2")
80  .operation (command3::operate)
81  .captureUndo (command3::capture)
82  .undoOperation (command3::undoIt)
83  ;
84  Command com ("test.command3.2");
85  CHECK (com.canExec());
86  cout << com << endl;
87 
88  com();
89  CHECK ( 2 == command3::check_);
90  com.undo();
91  CHECK ( 1 == command3::check_);
92 
93  Command commi = com.newInstance();
94  com();
95  com();
96  com();
97  CHECK ( 4 == command3::check_);
98 
99  commi.undo(); // it uses the inherited UNDO state
100  CHECK ( 1 == command3::check_);
101 
102  com.undo();
103  CHECK ( 3 == command3::check_);
104 
105  Command::get("test.command3.1").undo();
106  CHECK ( 0 == command3::check_);
107  }
108  };
109 
110 
111 
113  LAUNCHER (CommandBinding_test, "function controller");
114 
115 
116 }}} // namespace steam::control::test
Helper class used solely for defining a Command-Object.
Automatically use custom string conversion in C++ stream output.
static size_t definition_count()
Definition: command.cpp:289
Definition: run.hpp:40
Command newInstance() const
create independent (anonymous) clone copy of this command
Definition: command.cpp:200
static Command get(Symbol cmdID)
Access existing command for use.
Definition: command.cpp:120
Steam-Layer implementation namespace root.
static size_t instance_count()
Definition: command.cpp:298
Simplistic test class runner.
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:115
Actually defining a command and binding it to execution parameters.