LUMIERA.clone/tests/core/proc/control/command-binding-test.cpp
Ichthyostega ada5cefaaf re-arrange tests according to layer structure
the buildsystem will now pick up and link
all test cases according to the layer, e.g.
backend tests will automatically be linked
against the backend + library solely.
2013-01-07 05:43:01 +01:00

126 lines
3.5 KiB
C++

/*
CommandBinding(Test) - special cases of binding command arguments
Copyright (C) Lumiera.org
2009, Hermann Vosseler <Ichthyostega@web.de>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of
the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
* *****************************************************/
#include "lib/test/run.hpp"
#include "proc/control/command-def.hpp"
#include "proc/control/test-dummy-commands.hpp"
#include <iostream>
namespace proc {
namespace control {
namespace test {
using std::cout;
using std::endl;
/*****************************************************************************
* @test coverage for some specific situations when binding command arguments.
*
* @todo add more test cases...
*
* @see Command
* @see command-basic-test.cpp (simple usage example)
* @see command-use1-test.cpp (various aspects of command use)
*/
class CommandBinding_test : public Test
{
virtual void
run (Arg)
{
uint cnt_defs = Command::definition_count();
uint cnt_inst = Command::instance_count();
zeroArgumentCommand();
Command::remove("test.command3.1");
Command::remove("test.command3.2");
CHECK (cnt_defs == Command::definition_count());
CHECK (cnt_inst == Command::instance_count());
}
void
zeroArgumentCommand()
{
command3::check_ = 0;
CommandDef ("test.command3.1")
.operation (command3::operate)
.captureUndo (command3::capture)
.undoOperation (command3::undoIt)
.bind() // spurious bind doesn't hurt
.execSync()
;
CHECK ( 1 == command3::check_);
CommandDef ("test.command3.2")
.operation (command3::operate)
.captureUndo (command3::capture)
.undoOperation (command3::undoIt)
;
Command com ("test.command3.2");
CHECK (com.canExec());
cout << string(com) << endl;
com();
CHECK ( 2 == command3::check_);
com.undo();
CHECK ( 1 == command3::check_);
Command commi = com.newInstance();
com();
com();
com();
CHECK ( 4 == command3::check_);
commi.undo(); // it uses the inherited UNDO state
CHECK ( 1 == command3::check_);
com.undo();
CHECK ( 3 == command3::check_);
Command::get("test.command3.1").undo();
CHECK ( 0 == command3::check_);
}
};
/** Register this test class... */
LAUNCHER (CommandBinding_test, "function controller");
}}} // namespace proc::control::test