lumiera_/tests/core/steam/control/command-clone-builder-test.cpp
Ichthyostega 806db414dd 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

167 lines
5.1 KiB
C++
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
CommandCloneBuilder(Test) - verify building an implementation clone
Copyright (C)
2009, Hermann Vosseler <Ichthyostega@web.de>
  **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.
* *****************************************************************/
/** @file command-clone-builder-test.cpp
** unit test \ref CommandCloneBuilder_test
*/
#include "lib/test/run.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"
#include "lib/meta/tuple-helper.hpp"
#include "lib/symbol.hpp"
#include "lib/util.hpp"
#include "lib/p.hpp"
#include "steam/control/test-dummy-commands.hpp"
namespace steam {
namespace control {
namespace test {
using namespace lib::meta;
typedef lib::P<CommandImpl> PCmdImpl;
namespace { // test config...
HandlingPattern::ID TEST_HANDLING_PATTERN = HandlingPattern::DUMMY;
}
/****************************************************************************//**
* @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
* integration level, involving TypedAllocationManager, CommandRegistry,
* CommandImpl, CmdClosure, StorageHolder, UndoMutation, MementoTie.
* Closes: Ticket #298
*
* @see Command
* @see CommandRegistry
* @see command.cpp
* @see command-use1-test.cpp
*/
class CommandCloneBuilder_test : public Test
{
virtual void
run (Arg)
{
seedRand();
CommandRegistry& registry = CommandRegistry::instance();
CHECK (&registry);
uint cnt_inst = registry.instance_count();
{
PCmdImpl source = buildTestImplFrame (registry);
PCmdImpl clone = registry.createCloneImpl (*source);
verifySeparation (source, clone);
}
CHECK (cnt_inst == registry.instance_count());
}
PCmdImpl
buildTestImplFrame (CommandRegistry& registry)
{
// 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);
CHECK (o_Fun && c_Fun && u_Fun);
PCmdImpl cmd = registry.newCommandImpl(o_Fun,c_Fun,u_Fun);
// make ready for execution
bindRandArgument (*cmd);
CHECK (cmd->canExec());
return cmd;
}
/** Helper: create random command parameter binding */
void
bindRandArgument (CommandImpl& cmd)
{
typedef Types<int> ArgType;
TypedArguments<Tuple<ArgType>> arg (std::make_tuple (rani (10000)));
cmd.setArguments (arg);
CHECK (cmd.canExec());
}
/** @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)
{
CHECK (orig && copy);
CHECK (orig->canExec());
CHECK (copy->canExec());
// prepare for command invocation on implementation level....
HandlingPattern const& testExec = HandlingPattern::get(TEST_HANDLING_PATTERN);
command1::check_ = 0;
bindRandArgument (*orig);
CHECK ( orig->canExec());
CHECK (!orig->canUndo());
testExec.exec (*orig, "Execute original"); // EXEC 1
long state_after_exec1 = command1::check_;
CHECK (command1::check_ > 0);
CHECK (orig->canUndo());
CHECK (!copy->canUndo());
testExec.exec (*copy, "Execute clone"); // EXEC 2
CHECK (command1::check_ != state_after_exec1);
CHECK (copy->canUndo());
// invoke UNDO on the clone
testExec.undo (*copy, "Undo clone"); // UNDO 2
CHECK (command1::check_ == state_after_exec1);
// invoke UNDO on original
testExec.undo (*orig, "Undo original"); // UNDO 1
CHECK (command1::check_ ==0);
}
};
/** Register this test class... */
LAUNCHER (CommandCloneBuilder_test, "function controller");
}}} // namespace steam::control::test