2009-10-09 17:54:31 +02:00
|
|
|
|
/*
|
|
|
|
|
|
CommandCloneBuilder(Test) - verify building an implementation clone
|
2010-12-17 23:28:49 +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-17 23:28:49 +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-17 23:28:49 +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-10-09 17:54:31 +02:00
|
|
|
|
|
2017-02-22 01:54:20 +01:00
|
|
|
|
/** @file command-clone-builder-test.cpp
|
2017-02-22 03:17:18 +01:00
|
|
|
|
** unit test \ref CommandCloneBuilder_test
|
2016-11-03 18:20:10 +01:00
|
|
|
|
*/
|
|
|
|
|
|
|
2009-10-09 17:54:31 +02:00
|
|
|
|
|
|
|
|
|
|
#include "lib/test/run.hpp"
|
2018-11-15 23:42:43 +01:00
|
|
|
|
#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-17 23:55:41 +01:00
|
|
|
|
#include "lib/meta/tuple-helper.hpp"
|
2009-10-09 17:54:31 +02:00
|
|
|
|
#include "lib/symbol.hpp"
|
|
|
|
|
|
#include "lib/util.hpp"
|
2009-10-09 19:04:23 +02:00
|
|
|
|
#include "lib/p.hpp"
|
2009-10-09 17:54:31 +02:00
|
|
|
|
|
2018-11-15 23:42:43 +01:00
|
|
|
|
#include "steam/control/test-dummy-commands.hpp"
|
2009-10-09 17:54:31 +02:00
|
|
|
|
|
|
|
|
|
|
|
2018-11-15 23:55:13 +01:00
|
|
|
|
namespace steam {
|
2009-10-09 17:54:31 +02:00
|
|
|
|
namespace control {
|
|
|
|
|
|
namespace test {
|
|
|
|
|
|
|
2011-12-03 02:56:50 +01:00
|
|
|
|
using namespace lib::meta;
|
2009-10-09 17:54:31 +02:00
|
|
|
|
|
2011-12-02 17:50:44 +01:00
|
|
|
|
typedef lib::P<CommandImpl> PCmdImpl;
|
2009-10-10 05:00:02 +02:00
|
|
|
|
|
2009-10-09 17:54:31 +02:00
|
|
|
|
|
2009-10-10 05:00:02 +02:00
|
|
|
|
namespace { // test config...
|
2009-10-09 19:04:23 +02:00
|
|
|
|
HandlingPattern::ID TEST_HANDLING_PATTERN = HandlingPattern::DUMMY;
|
2009-10-09 17:54:31 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2009-10-10 05:00:02 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-10-09 17:54:31 +02:00
|
|
|
|
|
|
|
|
|
|
|
2013-10-24 23:06:36 +02:00
|
|
|
|
/****************************************************************************//**
|
2009-10-09 17:54:31 +02:00
|
|
|
|
* @test check creation of a command implementation clone from top level,
|
|
|
|
|
|
* without disclosing specific type information about the involved closure.
|
|
|
|
|
|
* This includes verifying sane allocation management.
|
|
|
|
|
|
* @note this test covers a very specific low-level perspective, but on an
|
2009-10-10 05:00:02 +02:00
|
|
|
|
* integration level, involving TypedAllocationManager, CommandRegistry,
|
2016-02-06 16:29:06 +01:00
|
|
|
|
* CommandImpl, CmdClosure, StorageHolder, UndoMutation, MementoTie.
|
2009-10-09 17:54:31 +02:00
|
|
|
|
* Closes: Ticket #298
|
|
|
|
|
|
*
|
|
|
|
|
|
* @see Command
|
|
|
|
|
|
* @see CommandRegistry
|
|
|
|
|
|
* @see command.cpp
|
|
|
|
|
|
* @see command-use1-test.cpp
|
|
|
|
|
|
*/
|
|
|
|
|
|
class CommandCloneBuilder_test : public Test
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
virtual void
|
|
|
|
|
|
run (Arg)
|
|
|
|
|
|
{
|
2024-11-13 02:23:23 +01:00
|
|
|
|
seedRand();
|
2009-10-09 17:54:31 +02:00
|
|
|
|
CommandRegistry& registry = CommandRegistry::instance();
|
2010-12-10 02:55:40 +01:00
|
|
|
|
CHECK (®istry);
|
2009-10-09 19:04:23 +02:00
|
|
|
|
uint cnt_inst = registry.instance_count();
|
2009-10-09 17:54:31 +02:00
|
|
|
|
|
2009-10-09 19:04:23 +02:00
|
|
|
|
{
|
|
|
|
|
|
PCmdImpl source = buildTestImplFrame (registry);
|
2009-10-10 05:00:02 +02:00
|
|
|
|
PCmdImpl clone = registry.createCloneImpl (*source);
|
2009-10-09 19:04:23 +02:00
|
|
|
|
|
|
|
|
|
|
verifySeparation (source, clone);
|
|
|
|
|
|
}
|
2009-10-09 17:54:31 +02:00
|
|
|
|
|
2010-12-10 02:55:40 +01:00
|
|
|
|
CHECK (cnt_inst == registry.instance_count());
|
2009-10-09 17:54:31 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-10-09 19:04:23 +02:00
|
|
|
|
PCmdImpl
|
|
|
|
|
|
buildTestImplFrame (CommandRegistry& registry)
|
2009-10-09 17:54:31 +02:00
|
|
|
|
{
|
|
|
|
|
|
// simulate what normally happens within a CommandDef
|
|
|
|
|
|
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-10-09 19:04:23 +02:00
|
|
|
|
PCmdImpl cmd = registry.newCommandImpl(o_Fun,c_Fun,u_Fun);
|
2009-10-09 17:54:31 +02:00
|
|
|
|
|
2009-10-09 19:04:23 +02:00
|
|
|
|
// make ready for execution
|
|
|
|
|
|
bindRandArgument (*cmd);
|
2010-12-10 02:55:40 +01:00
|
|
|
|
CHECK (cmd->canExec());
|
2009-10-09 19:04:23 +02:00
|
|
|
|
return cmd;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** Helper: create random command parameter binding */
|
|
|
|
|
|
void
|
|
|
|
|
|
bindRandArgument (CommandImpl& cmd)
|
|
|
|
|
|
{
|
2025-06-07 18:04:59 +02:00
|
|
|
|
TypedArguments<std::tuple<int>> arg {std::make_tuple (rani (10000))};
|
2009-10-09 19:04:23 +02:00
|
|
|
|
cmd.setArguments (arg);
|
2010-12-10 02:55:40 +01:00
|
|
|
|
CHECK (cmd.canExec());
|
2009-10-09 19:04:23 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** @test verify the two command implementation frames are
|
|
|
|
|
|
* indeed separate objects without interconnection.
|
|
|
|
|
|
* Performing an simulated command execution-undo
|
|
|
|
|
|
* cycle on both instances and verify difference.
|
|
|
|
|
|
*/
|
|
|
|
|
|
void
|
|
|
|
|
|
verifySeparation (PCmdImpl orig, PCmdImpl copy)
|
|
|
|
|
|
{
|
2025-06-07 18:04:59 +02:00
|
|
|
|
CHECK (orig and copy);
|
2010-12-10 02:55:40 +01:00
|
|
|
|
CHECK (orig->canExec());
|
|
|
|
|
|
CHECK (copy->canExec());
|
2009-10-09 19:04:23 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// prepare for command invocation on implementation level....
|
|
|
|
|
|
HandlingPattern const& testExec = HandlingPattern::get(TEST_HANDLING_PATTERN);
|
|
|
|
|
|
command1::check_ = 0;
|
|
|
|
|
|
|
|
|
|
|
|
bindRandArgument (*orig);
|
2010-12-10 02:55:40 +01:00
|
|
|
|
CHECK ( orig->canExec());
|
|
|
|
|
|
CHECK (!orig->canUndo());
|
2016-01-22 15:25:08 +01:00
|
|
|
|
testExec.exec (*orig, "Execute original"); // EXEC 1
|
2009-10-09 19:04:23 +02:00
|
|
|
|
long state_after_exec1 = command1::check_;
|
2010-12-10 02:55:40 +01:00
|
|
|
|
CHECK (command1::check_ > 0);
|
|
|
|
|
|
CHECK (orig->canUndo());
|
2009-10-09 19:04:23 +02:00
|
|
|
|
|
2010-12-10 02:55:40 +01:00
|
|
|
|
CHECK (!copy->canUndo());
|
2016-01-22 15:25:08 +01:00
|
|
|
|
testExec.exec (*copy, "Execute clone"); // EXEC 2
|
2010-12-10 02:55:40 +01:00
|
|
|
|
CHECK (command1::check_ != state_after_exec1);
|
|
|
|
|
|
CHECK (copy->canUndo());
|
2009-10-09 19:04:23 +02:00
|
|
|
|
|
|
|
|
|
|
// invoke UNDO on the clone
|
2016-01-22 15:25:08 +01:00
|
|
|
|
testExec.undo (*copy, "Undo clone"); // UNDO 2
|
2010-12-10 02:55:40 +01:00
|
|
|
|
CHECK (command1::check_ == state_after_exec1);
|
2009-10-09 19:04:23 +02:00
|
|
|
|
|
|
|
|
|
|
// invoke UNDO on original
|
2016-01-22 15:25:08 +01:00
|
|
|
|
testExec.undo (*orig, "Undo original"); // UNDO 1
|
2010-12-10 02:55:40 +01:00
|
|
|
|
CHECK (command1::check_ ==0);
|
2009-10-09 17:54:31 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** Register this test class... */
|
|
|
|
|
|
LAUNCHER (CommandCloneBuilder_test, "function controller");
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-11-15 23:55:13 +01:00
|
|
|
|
}}} // namespace steam::control::test
|