2009-09-29 18:09:34 +02:00
|
|
|
|
/*
|
|
|
|
|
|
HandlingPatternBasics(Test) - verify elementary operation of a command handling pattern
|
2010-12-10 02:55:40 +01:00
|
|
|
|
|
Copyright: clarify and simplify the file headers
* Lumiera source code always was copyrighted by individual contributors
* there is no entity "Lumiera.org" which holds any copyrights
* Lumiera source code is provided under the GPL Version 2+
== Explanations ==
Lumiera as a whole is distributed under Copyleft, GNU General Public License Version 2 or above.
For this to become legally effective, the ''File COPYING in the root directory is sufficient.''
The licensing header in each file is not strictly necessary, yet considered good practice;
attaching a licence notice increases the likeliness that this information is retained
in case someone extracts individual code files. However, it is not by the presence of some
text, that legally binding licensing terms become effective; rather the fact matters that a
given piece of code was provably copyrighted and published under a license. Even reformatting
the code, renaming some variables or deleting parts of the code will not alter this legal
situation, but rather creates a derivative work, which is likewise covered by the GPL!
The most relevant information in the file header is the notice regarding the
time of the first individual copyright claim. By virtue of this initial copyright,
the first author is entitled to choose the terms of licensing. All further
modifications are permitted and covered by the License. The specific wording
or format of the copyright header is not legally relevant, as long as the
intention to publish under the GPL remains clear. The extended wording was
based on a recommendation by the FSF. It can be shortened, because the full terms
of the license are provided alongside the distribution, in the file COPYING.
2024-11-17 23:42:55 +01:00
|
|
|
|
Copyright (C)
|
|
|
|
|
|
2009, Hermann Vosseler <Ichthyostega@web.de>
|
2010-12-10 02:55:40 +01:00
|
|
|
|
|
Copyright: clarify and simplify the file headers
* Lumiera source code always was copyrighted by individual contributors
* there is no entity "Lumiera.org" which holds any copyrights
* Lumiera source code is provided under the GPL Version 2+
== Explanations ==
Lumiera as a whole is distributed under Copyleft, GNU General Public License Version 2 or above.
For this to become legally effective, the ''File COPYING in the root directory is sufficient.''
The licensing header in each file is not strictly necessary, yet considered good practice;
attaching a licence notice increases the likeliness that this information is retained
in case someone extracts individual code files. However, it is not by the presence of some
text, that legally binding licensing terms become effective; rather the fact matters that a
given piece of code was provably copyrighted and published under a license. Even reformatting
the code, renaming some variables or deleting parts of the code will not alter this legal
situation, but rather creates a derivative work, which is likewise covered by the GPL!
The most relevant information in the file header is the notice regarding the
time of the first individual copyright claim. By virtue of this initial copyright,
the first author is entitled to choose the terms of licensing. All further
modifications are permitted and covered by the License. The specific wording
or format of the copyright header is not legally relevant, as long as the
intention to publish under the GPL remains clear. The extended wording was
based on a recommendation by the FSF. It can be shortened, because the full terms
of the license are provided alongside the distribution, in the file COPYING.
2024-11-17 23:42:55 +01:00
|
|
|
|
**Lumiera** 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. See the file COPYING for further details.
|
2010-12-10 02:55:40 +01:00
|
|
|
|
|
Copyright: clarify and simplify the file headers
* Lumiera source code always was copyrighted by individual contributors
* there is no entity "Lumiera.org" which holds any copyrights
* Lumiera source code is provided under the GPL Version 2+
== Explanations ==
Lumiera as a whole is distributed under Copyleft, GNU General Public License Version 2 or above.
For this to become legally effective, the ''File COPYING in the root directory is sufficient.''
The licensing header in each file is not strictly necessary, yet considered good practice;
attaching a licence notice increases the likeliness that this information is retained
in case someone extracts individual code files. However, it is not by the presence of some
text, that legally binding licensing terms become effective; rather the fact matters that a
given piece of code was provably copyrighted and published under a license. Even reformatting
the code, renaming some variables or deleting parts of the code will not alter this legal
situation, but rather creates a derivative work, which is likewise covered by the GPL!
The most relevant information in the file header is the notice regarding the
time of the first individual copyright claim. By virtue of this initial copyright,
the first author is entitled to choose the terms of licensing. All further
modifications are permitted and covered by the License. The specific wording
or format of the copyright header is not legally relevant, as long as the
intention to publish under the GPL remains clear. The extended wording was
based on a recommendation by the FSF. It can be shortened, because the full terms
of the license are provided alongside the distribution, in the file COPYING.
2024-11-17 23:42:55 +01:00
|
|
|
|
* *****************************************************************/
|
2009-09-29 18:09:34 +02:00
|
|
|
|
|
2017-02-22 01:54:20 +01:00
|
|
|
|
/** @file handling-pattern-basics-test.cpp
|
2017-02-22 03:17:18 +01:00
|
|
|
|
** unit test \ref HandlingPatternBasics_test
|
2016-11-03 18:20:10 +01:00
|
|
|
|
*/
|
|
|
|
|
|
|
2009-09-29 18:09:34 +02:00
|
|
|
|
|
|
|
|
|
|
#include "lib/test/run.hpp"
|
2018-11-15 23:42:43 +01:00
|
|
|
|
#include "steam/control/command.hpp"
|
|
|
|
|
|
#include "steam/control/command-impl.hpp"
|
|
|
|
|
|
#include "steam/control/command-registry.hpp"
|
|
|
|
|
|
#include "steam/control/argument-erasure.hpp"
|
|
|
|
|
|
#include "steam/control/handling-pattern.hpp"
|
2016-01-22 17:17:31 +01:00
|
|
|
|
#include "lib/test/event-log.hpp"
|
2009-09-29 18:09:34 +02:00
|
|
|
|
|
2018-11-15 23:42:43 +01:00
|
|
|
|
#include "steam/control/test-dummy-commands.hpp"
|
2009-09-29 18:09:34 +02:00
|
|
|
|
|
|
|
|
|
|
|
2024-11-13 02:23:23 +01:00
|
|
|
|
namespace steam {
|
|
|
|
|
|
namespace control{
|
|
|
|
|
|
namespace test {
|
2009-10-02 15:26:11 +02:00
|
|
|
|
|
2014-04-03 22:42:48 +02:00
|
|
|
|
using std::function;
|
2009-09-29 18:09:34 +02:00
|
|
|
|
|
2016-01-22 17:17:31 +01:00
|
|
|
|
namespace { // test fixture...
|
2010-12-17 22:51:27 +01:00
|
|
|
|
|
2016-01-22 17:17:31 +01:00
|
|
|
|
string TEST_CMD = "test.command1.handling";
|
2009-09-29 18:09:34 +02:00
|
|
|
|
HandlingPattern::ID TEST_PATTERN = HandlingPattern::DUMMY;
|
2016-01-22 17:17:31 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class CustomHandler
|
|
|
|
|
|
: public HandlingPattern
|
|
|
|
|
|
{
|
|
|
|
|
|
mutable
|
|
|
|
|
|
lib::test::EventLog log_{"custom command handler"};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* ==== HandlingPattern - Interface ==== */
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
|
performExec (CommandImpl& command) const override
|
|
|
|
|
|
{
|
|
|
|
|
|
log_.call (TEST_CMD, "exec");
|
|
|
|
|
|
command.invokeCapture();
|
|
|
|
|
|
command.invokeOperation();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
|
performUndo (CommandImpl& command) const override
|
|
|
|
|
|
{
|
|
|
|
|
|
log_.call (TEST_CMD, "undo");
|
|
|
|
|
|
command.invokeUndo();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
|
isValid() const override
|
|
|
|
|
|
{
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
bool
|
|
|
|
|
|
invokedExec()
|
|
|
|
|
|
{
|
|
|
|
|
|
return log_.verifyCall("exec").on(TEST_CMD);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
|
invokedUndo()
|
|
|
|
|
|
{
|
|
|
|
|
|
return log_.verifyCall("undo").on(TEST_CMD)
|
|
|
|
|
|
.afterCall("exec");
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
}//(End) test fixture
|
2009-09-29 18:09:34 +02:00
|
|
|
|
|
|
|
|
|
|
typedef shared_ptr<CommandImpl> PCommandImpl;
|
|
|
|
|
|
typedef HandlingPattern const& HaPatt;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-01-22 17:17:31 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-10-24 23:06:36 +02:00
|
|
|
|
/******************************************************************************//**
|
2009-09-29 18:09:34 +02:00
|
|
|
|
* @test operate and verify a simple dummy command handling pattern.
|
|
|
|
|
|
* @note this test covers mainly the behaviour of a handling pattern as a concept,
|
2009-10-02 15:26:11 +02:00
|
|
|
|
* not so much the behaviour of the (standard) handling pattern implementations.
|
2009-09-29 18:09:34 +02:00
|
|
|
|
*
|
|
|
|
|
|
* @see HandlingPattern
|
2009-10-02 15:26:11 +02:00
|
|
|
|
* @see BasicHandlingPattern
|
2009-09-29 18:09:34 +02:00
|
|
|
|
* @see command.hpp
|
|
|
|
|
|
* @see command-basic-test.cpp
|
|
|
|
|
|
*/
|
|
|
|
|
|
class HandlingPatternBasics_test : public Test
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
uint cnt_inst;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
virtual void
|
2010-12-10 02:55:40 +01:00
|
|
|
|
run (Arg)
|
2009-09-29 18:09:34 +02:00
|
|
|
|
{
|
2024-11-13 02:23:23 +01:00
|
|
|
|
seedRand();
|
2009-09-29 18:09:34 +02:00
|
|
|
|
CommandRegistry& registry = CommandRegistry::instance();
|
2010-12-10 02:55:40 +01:00
|
|
|
|
CHECK (®istry);
|
2009-09-29 18:09:34 +02:00
|
|
|
|
|
|
|
|
|
|
cnt_inst = registry.instance_count();
|
2010-12-17 22:51:27 +01:00
|
|
|
|
|
2009-09-29 18:09:34 +02:00
|
|
|
|
{
|
|
|
|
|
|
PCommandImpl pCom = buildTestCommand(registry);
|
|
|
|
|
|
checkExec (pCom);
|
|
|
|
|
|
checkUndo (pCom);
|
2016-01-22 17:17:31 +01:00
|
|
|
|
|
|
|
|
|
|
useCustomHandler (pCom);
|
2009-09-29 18:09:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2010-12-10 02:55:40 +01:00
|
|
|
|
CHECK (cnt_inst == registry.instance_count());
|
2009-09-29 18:09:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** create a command implementation frame usable for tests.
|
|
|
|
|
|
* This simulates what normally happens within a CommandDef.
|
|
|
|
|
|
* The created CommandImpl isn't registered, and thus will
|
|
|
|
|
|
* just go away when the smart-ptr leaves scope.
|
|
|
|
|
|
*/
|
|
|
|
|
|
PCommandImpl
|
|
|
|
|
|
buildTestCommand (CommandRegistry& registry)
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
typedef void Sig_oper(int);
|
|
|
|
|
|
typedef long Sig_capt(int);
|
|
|
|
|
|
typedef void Sig_undo(int,long);
|
|
|
|
|
|
|
|
|
|
|
|
function<Sig_oper> o_Fun (command1::operate);
|
|
|
|
|
|
function<Sig_capt> c_Fun (command1::capture);
|
|
|
|
|
|
function<Sig_undo> u_Fun (command1::undoIt);
|
|
|
|
|
|
|
2010-12-10 02:55:40 +01:00
|
|
|
|
CHECK (o_Fun && c_Fun && u_Fun);
|
2009-09-29 18:09:34 +02:00
|
|
|
|
|
|
|
|
|
|
// when the CommandDef is complete, it issues the
|
|
|
|
|
|
// allocation call to the registry behind the scenes....
|
|
|
|
|
|
|
|
|
|
|
|
PCommandImpl pImpl = registry.newCommandImpl(o_Fun,c_Fun,u_Fun);
|
2010-12-10 02:55:40 +01:00
|
|
|
|
CHECK (pImpl);
|
|
|
|
|
|
CHECK (*pImpl);
|
2009-09-29 18:09:34 +02:00
|
|
|
|
return pImpl;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-12-25 18:49:57 +01:00
|
|
|
|
/** @test verify the Handling pattern API: execute a command */
|
2009-09-29 18:09:34 +02:00
|
|
|
|
void
|
|
|
|
|
|
checkExec (PCommandImpl com)
|
|
|
|
|
|
{
|
2010-12-10 02:55:40 +01:00
|
|
|
|
CHECK (com);
|
|
|
|
|
|
CHECK (!com->canExec());
|
2009-09-29 18:09:34 +02:00
|
|
|
|
|
2025-06-02 02:24:09 +02:00
|
|
|
|
typedef TyOLD<int> ArgType;
|
2024-11-13 02:23:23 +01:00
|
|
|
|
const int ARGR{1 + rani (1000)};
|
2016-12-25 18:49:57 +01:00
|
|
|
|
Tuple<ArgType> tuple(ARGR);
|
2016-12-23 04:23:03 +01:00
|
|
|
|
TypedArguments<Tuple<ArgType>> arg(tuple);
|
2009-09-29 18:09:34 +02:00
|
|
|
|
com->setArguments(arg);
|
|
|
|
|
|
|
2010-12-10 02:55:40 +01:00
|
|
|
|
CHECK (com->canExec());
|
|
|
|
|
|
CHECK (!com->canUndo());
|
2009-09-29 18:09:34 +02:00
|
|
|
|
command1::check_ = 0;
|
|
|
|
|
|
|
|
|
|
|
|
HaPatt patt = HandlingPattern::get(TEST_PATTERN);
|
2016-01-22 17:17:31 +01:00
|
|
|
|
ExecResult res = patt.exec (*com, TEST_CMD);
|
2009-09-29 18:09:34 +02:00
|
|
|
|
|
2010-12-10 02:55:40 +01:00
|
|
|
|
CHECK (res);
|
2016-12-25 18:49:57 +01:00
|
|
|
|
CHECK (ARGR == command1::check_);
|
2010-12-10 02:55:40 +01:00
|
|
|
|
CHECK (com->canUndo());
|
2009-09-29 18:09:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-12-25 18:49:57 +01:00
|
|
|
|
/** @test verify the Handling pattern API: undo a command */
|
2009-09-29 18:09:34 +02:00
|
|
|
|
void
|
|
|
|
|
|
checkUndo (PCommandImpl com)
|
|
|
|
|
|
{
|
2010-12-10 02:55:40 +01:00
|
|
|
|
CHECK (com);
|
|
|
|
|
|
CHECK (com->canExec());
|
|
|
|
|
|
CHECK (com->canUndo());
|
2009-09-29 18:09:34 +02:00
|
|
|
|
|
2010-12-10 02:55:40 +01:00
|
|
|
|
CHECK (command1::check_ > 0);
|
2009-09-29 18:09:34 +02:00
|
|
|
|
|
|
|
|
|
|
HaPatt ePatt = HandlingPattern::get(TEST_PATTERN);
|
2016-01-22 17:17:31 +01:00
|
|
|
|
ExecResult res = ePatt.undo (*com, TEST_CMD);
|
2009-09-29 18:09:34 +02:00
|
|
|
|
|
2010-12-10 02:55:40 +01:00
|
|
|
|
CHECK (res);
|
|
|
|
|
|
CHECK (command1::check_ == 0);
|
2009-09-29 18:09:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2016-01-22 17:17:31 +01:00
|
|
|
|
|
2016-12-25 18:49:57 +01:00
|
|
|
|
/** @test use custom implementation of the HandlingPattern interface,
|
|
|
|
|
|
* rigged to verify the functions are actually invoked.
|
|
|
|
|
|
*/
|
2016-01-22 17:17:31 +01:00
|
|
|
|
void
|
|
|
|
|
|
useCustomHandler (PCommandImpl com)
|
|
|
|
|
|
{
|
|
|
|
|
|
CustomHandler specialHandler;
|
|
|
|
|
|
|
|
|
|
|
|
CHECK (com->canExec());
|
|
|
|
|
|
CHECK (not specialHandler.invokedExec());
|
|
|
|
|
|
|
|
|
|
|
|
specialHandler.exec (*com, TEST_CMD);
|
|
|
|
|
|
CHECK ( specialHandler.invokedExec());
|
|
|
|
|
|
CHECK (not specialHandler.invokedUndo());
|
|
|
|
|
|
|
|
|
|
|
|
specialHandler.undo (*com, TEST_CMD);
|
|
|
|
|
|
CHECK ( specialHandler.invokedExec());
|
|
|
|
|
|
}
|
2009-09-29 18:09:34 +02:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** Register this test class... */
|
|
|
|
|
|
LAUNCHER (HandlingPatternBasics_test, "function controller");
|
2009-10-02 15:26:11 +02:00
|
|
|
|
|
|
|
|
|
|
|
2018-11-15 23:55:13 +01:00
|
|
|
|
}}} // namespace steam::control::test
|