2015-11-26 22:23:43 +01:00
|
|
|
|
/*
|
|
|
|
|
|
AbstractTangible(Test) - cover the operations of any tangible UI element
|
|
|
|
|
|
|
|
|
|
|
|
Copyright (C) Lumiera.org
|
|
|
|
|
|
2015, 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.
|
|
|
|
|
|
|
|
|
|
|
|
* *****************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** @file abstract-tangible-test.cpp
|
2015-12-18 01:02:19 +01:00
|
|
|
|
** Verify the common base shared by all interface elements of relevance.
|
2015-11-26 22:23:43 +01:00
|
|
|
|
** This test is not so much a test, than a test of the test support for testing
|
2015-12-27 03:16:49 +01:00
|
|
|
|
** [primary elements](\ref gui::model::Tangible) of the Lumiera GTK UI. Any such element
|
|
|
|
|
|
** is connected to the [UI-Bus](\ref gui::UiBus) and responds to some generic actions and
|
2015-11-26 22:23:43 +01:00
|
|
|
|
** interaction patterns. This is the foundation of any presentation state recording
|
|
|
|
|
|
** and restoration, and it serves to invoke any persistent action on the
|
|
|
|
|
|
** [Session] through a single channel and access point.
|
|
|
|
|
|
**
|
|
|
|
|
|
** What is covered here is actually a **test mock**. Which in turn enables us
|
|
|
|
|
|
** to cover interface interactions and behaviour in a generic fashion, without
|
|
|
|
|
|
** actually having to operate the interface.
|
|
|
|
|
|
**
|
|
|
|
|
|
** @note as of 11/2015 this is a draft into the blue...
|
|
|
|
|
|
** @todo WIP ///////////////////////TICKET #959
|
|
|
|
|
|
** @todo WIP ///////////////////////TICKET #956
|
|
|
|
|
|
** @todo WIP ///////////////////////TICKET #975
|
|
|
|
|
|
** @todo WIP ///////////////////////TICKET #961 : tests to pass...
|
|
|
|
|
|
**
|
|
|
|
|
|
** @see gui::UiBus
|
|
|
|
|
|
**
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "lib/test/run.hpp"
|
2015-11-27 02:38:23 +01:00
|
|
|
|
#include "lib/test/test-helper.hpp"
|
2015-11-28 23:50:56 +01:00
|
|
|
|
#include "lib/test/event-log.hpp"
|
2015-11-28 21:43:09 +01:00
|
|
|
|
#include "test/mock-elm.hpp"
|
2015-12-26 22:56:43 +01:00
|
|
|
|
#include "test/test-nexus.hpp"
|
2015-11-28 23:50:56 +01:00
|
|
|
|
#include "lib/idi/entry-id.hpp"
|
2016-01-12 02:14:06 +01:00
|
|
|
|
#include "proc/control/command-def.hpp"
|
2016-10-02 23:51:45 +02:00
|
|
|
|
#include "gui/ctrl/mutation-message.hpp"
|
2016-10-02 02:57:27 +02:00
|
|
|
|
#include "lib/iter-adapter-stl.hpp"
|
|
|
|
|
|
#include "lib/diff/tree-diff.hpp"
|
2016-02-11 20:48:21 +01:00
|
|
|
|
#include "lib/time/timevalue.hpp"
|
2016-01-07 03:58:29 +01:00
|
|
|
|
#include "lib/format-cout.hpp"
|
2016-01-12 02:14:06 +01:00
|
|
|
|
#include "lib/symbol.hpp"
|
2015-11-28 20:55:28 +01:00
|
|
|
|
#include "lib/error.hpp"
|
2016-02-14 00:23:24 +01:00
|
|
|
|
#include "lib/util.hpp"
|
2015-11-26 22:23:43 +01:00
|
|
|
|
|
2016-02-11 21:56:58 +01:00
|
|
|
|
#include <sigc++/signal.h>
|
2015-11-26 22:23:43 +01:00
|
|
|
|
|
|
|
|
|
|
|
2016-01-12 02:14:06 +01:00
|
|
|
|
using lib::Symbol;
|
2016-02-14 00:23:24 +01:00
|
|
|
|
using util::isnil;
|
2016-01-15 02:29:33 +01:00
|
|
|
|
using util::toString;
|
2016-02-11 20:48:21 +01:00
|
|
|
|
using lib::time::Time;
|
2015-11-28 23:50:56 +01:00
|
|
|
|
using gui::test::MockElm;
|
|
|
|
|
|
using lib::test::EventLog;
|
|
|
|
|
|
using lib::idi::EntryID;
|
2016-01-12 02:59:16 +01:00
|
|
|
|
using lib::diff::Rec;
|
|
|
|
|
|
using lib::diff::GenNode;
|
|
|
|
|
|
using lib::diff::DataCap;
|
2016-01-12 02:14:06 +01:00
|
|
|
|
using proc::control::Command;
|
|
|
|
|
|
using proc::control::CommandDef;
|
|
|
|
|
|
using gui::interact::InvocationTrail;
|
2016-10-02 22:21:17 +02:00
|
|
|
|
using gui::ctrl::MutationMessage;
|
2015-11-26 22:23:43 +01:00
|
|
|
|
|
2015-11-27 02:38:23 +01:00
|
|
|
|
|
2015-11-26 22:23:43 +01:00
|
|
|
|
|
|
|
|
|
|
namespace gui {
|
|
|
|
|
|
namespace model{
|
|
|
|
|
|
namespace test {
|
|
|
|
|
|
|
2016-02-11 16:19:24 +01:00
|
|
|
|
using lumiera::error::LUMIERA_ERROR_WRONG_TYPE;
|
|
|
|
|
|
using ID = lib::idi::BareEntryID const&;
|
|
|
|
|
|
|
2015-11-26 22:23:43 +01:00
|
|
|
|
namespace { // test fixture...
|
|
|
|
|
|
|
2016-01-12 02:14:06 +01:00
|
|
|
|
// dummy operation to be invoked through the command system
|
|
|
|
|
|
int dummyState = 0;
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
|
operate (int val)
|
|
|
|
|
|
{
|
|
|
|
|
|
dummyState = val;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
|
capture (int)
|
|
|
|
|
|
{
|
|
|
|
|
|
return dummyState;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
|
undoIt (int, int oldState)
|
|
|
|
|
|
{
|
|
|
|
|
|
dummyState = oldState;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-01-12 02:59:16 +01:00
|
|
|
|
|
|
|
|
|
|
|
2016-01-12 02:14:06 +01:00
|
|
|
|
const Symbol DUMMY_CMD_ID{"test.AbstractTangibleTest_dummy_command"};
|
|
|
|
|
|
|
2016-01-12 02:59:16 +01:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* dummy Command handler,
|
|
|
|
|
|
* which can be hooked up to the TestNexus
|
|
|
|
|
|
* and causes a real command invocation
|
|
|
|
|
|
* when receiving invocation messages
|
|
|
|
|
|
* @warning all hard wired -- works only for this command
|
|
|
|
|
|
*/
|
|
|
|
|
|
void
|
|
|
|
|
|
processCommandInvocation (GenNode const& commandMsg)
|
|
|
|
|
|
{
|
|
|
|
|
|
REQUIRE (string(DUMMY_CMD_ID) == commandMsg.idi.getSym());
|
|
|
|
|
|
|
|
|
|
|
|
class CommandBindingDetector
|
|
|
|
|
|
: public DataCap::Predicate
|
|
|
|
|
|
{
|
|
|
|
|
|
bool
|
|
|
|
|
|
handle (Rec const& binding) override
|
|
|
|
|
|
{
|
|
|
|
|
|
auto cmd = Command::get(DUMMY_CMD_ID);
|
|
|
|
|
|
auto arg = binding.scope()->data.get<int>();
|
|
|
|
|
|
|
|
|
|
|
|
cmd.bind (arg);
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
|
handle (int const&) override
|
|
|
|
|
|
{
|
|
|
|
|
|
auto cmd = Command::get(DUMMY_CMD_ID);
|
|
|
|
|
|
|
|
|
|
|
|
cmd();
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
commandInvoker;
|
|
|
|
|
|
|
|
|
|
|
|
commandMsg.data.accept (commandInvoker);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-11-26 22:23:43 +01:00
|
|
|
|
}//(End) test fixture
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************//**
|
|
|
|
|
|
* @test cover the basic operations of any tangible UI element,
|
|
|
|
|
|
* with the help of a mock UI element.
|
|
|
|
|
|
* - creation
|
|
|
|
|
|
* - destruction
|
|
|
|
|
|
* - command invocation
|
|
|
|
|
|
* - state mark
|
|
|
|
|
|
* - state mark replay
|
|
|
|
|
|
* - message casting
|
|
|
|
|
|
* - error state indication
|
|
|
|
|
|
*
|
2016-01-02 01:23:09 +01:00
|
|
|
|
* @see BusTerm_test
|
2015-11-26 22:23:43 +01:00
|
|
|
|
* @see SessionElementQuery_test
|
2016-01-02 01:23:09 +01:00
|
|
|
|
* @see tangible.hpp
|
|
|
|
|
|
* @see ui-bus.hpp
|
2015-11-26 22:23:43 +01:00
|
|
|
|
*/
|
|
|
|
|
|
class AbstractTangible_test : public Test
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
virtual void
|
|
|
|
|
|
run (Arg)
|
|
|
|
|
|
{
|
|
|
|
|
|
verify_mockManipulation();
|
|
|
|
|
|
invokeCommand();
|
2016-02-11 21:56:58 +01:00
|
|
|
|
markState();
|
2015-11-26 22:23:43 +01:00
|
|
|
|
notify();
|
|
|
|
|
|
mutate();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-12-16 02:16:53 +01:00
|
|
|
|
/** @test verify the UI widget unit test support framework.
|
|
|
|
|
|
* The generic backbone of the Lumiera UI offers a mock UI element,
|
|
|
|
|
|
* with the ability to stand-in for actual elements present in the real GUI.
|
|
|
|
|
|
* This allows us to rig a emulated test user interface to cover interactions
|
|
|
|
|
|
* involving some communication from or to interface elements. After setting up
|
2016-01-02 01:23:09 +01:00
|
|
|
|
* a [mock UI-element](\ref MockElm) with a suitable name / ID, we're able to
|
|
|
|
|
|
* operate this element programmatically and to send messages and responses
|
|
|
|
|
|
* from the core "up" to this mocked interface. And since this mock element
|
|
|
|
|
|
* embodies an [event log](\ref EventLog), the unit test code can verify
|
|
|
|
|
|
* the occurrence of expected events, invocations and responses.
|
2015-12-27 01:58:15 +01:00
|
|
|
|
*
|
2016-01-02 01:23:09 +01:00
|
|
|
|
* ### connectivity
|
2015-12-27 03:16:49 +01:00
|
|
|
|
* Any mock element will automatically connect against the [Test-Nexus](test/test-nexus.hpp),
|
2015-12-27 01:58:15 +01:00
|
|
|
|
* so to be suitably rigged for unit testing. This means, there is no _live connection_
|
|
|
|
|
|
* to the session, but any command- or other messages will be captured and can be
|
|
|
|
|
|
* retrieved or verified from the test code. Since lifecycle and robustness in
|
|
|
|
|
|
* "post mortem" situations tend to be tricky for UI code, we provide a dedicated
|
2016-01-02 01:23:09 +01:00
|
|
|
|
* ["zombification" feature](\ref gui::test::TestNexus::zombificate): a \ref MockElm can be
|
2016-09-08 18:49:27 +02:00
|
|
|
|
* turned into an _almost dead_ state, while still hanging around. It will be detached from
|
|
|
|
|
|
* the "living" Test-Nexus and re-wired to some special, hidden "Zombie Nexus", causing any
|
2015-12-27 01:58:15 +01:00
|
|
|
|
* further messaging activity to be logged and ignored.
|
2015-11-26 22:23:43 +01:00
|
|
|
|
*/
|
|
|
|
|
|
void
|
|
|
|
|
|
verify_mockManipulation ()
|
|
|
|
|
|
{
|
2016-02-11 22:13:36 +01:00
|
|
|
|
MARK_TEST_FUN
|
2015-11-27 02:38:23 +01:00
|
|
|
|
MockElm mock("dummy");
|
2015-11-28 23:50:56 +01:00
|
|
|
|
|
2015-12-16 02:16:53 +01:00
|
|
|
|
CHECK (mock.verify("ctor"));
|
2015-12-16 23:24:11 +01:00
|
|
|
|
CHECK (mock.verifyEvent("create","dummy"));
|
2015-12-25 00:41:14 +01:00
|
|
|
|
CHECK (mock.verify("ctor").arg("dummy","TestNexus").on(&mock));
|
2015-11-27 02:38:23 +01:00
|
|
|
|
|
|
|
|
|
|
CHECK ("dummy" == mock.getID().getSym());
|
2015-11-28 23:50:56 +01:00
|
|
|
|
CHECK (EntryID<MockElm>("dummy") == mock.getID());
|
2015-11-27 02:38:23 +01:00
|
|
|
|
|
2015-12-16 02:16:53 +01:00
|
|
|
|
CHECK (!mock.verifyCall("reset"));
|
2015-11-27 02:38:23 +01:00
|
|
|
|
|
2016-02-13 22:36:42 +01:00
|
|
|
|
// start manipulating state....
|
|
|
|
|
|
mock.slotExpand();
|
|
|
|
|
|
CHECK (mock.isExpanded());
|
|
|
|
|
|
|
2015-11-27 02:38:23 +01:00
|
|
|
|
mock.reset();
|
2015-12-16 02:16:53 +01:00
|
|
|
|
CHECK (mock.verify("reset"));
|
|
|
|
|
|
CHECK (mock.verifyCall("reset"));
|
2015-12-25 00:41:14 +01:00
|
|
|
|
CHECK (mock.verifyCall("reset").on(&mock));
|
2015-12-16 02:16:53 +01:00
|
|
|
|
CHECK (mock.verifyCall("reset").on("dummy"));
|
|
|
|
|
|
CHECK (mock.verifyEvent("reset"));
|
|
|
|
|
|
CHECK (mock.verify("reset").after("ctor"));
|
|
|
|
|
|
CHECK (mock.verify("ctor").before("reset"));
|
|
|
|
|
|
CHECK (mock.ensureNot("reset").before("ctor"));
|
|
|
|
|
|
CHECK (mock.ensureNot("ctor").after("reset"));
|
2015-11-27 02:38:23 +01:00
|
|
|
|
|
2015-12-16 02:16:53 +01:00
|
|
|
|
CHECK (mock.verify("reset").beforeEvent("reset"));
|
|
|
|
|
|
CHECK (mock.verifyCall("reset").beforeEvent("reset"));
|
|
|
|
|
|
CHECK (!mock.verifyCall("reset").afterEvent("reset"));
|
2015-11-27 02:38:23 +01:00
|
|
|
|
|
|
|
|
|
|
CHECK (!mock.isTouched());
|
|
|
|
|
|
CHECK (!mock.isExpanded());
|
|
|
|
|
|
|
2015-12-26 04:40:38 +01:00
|
|
|
|
mock.markMsg("qui dolorem ipsum quia dolor sit amet consectetur adipisci velit.");
|
|
|
|
|
|
CHECK (mock.verifyMark("Message", "dolor"));
|
|
|
|
|
|
CHECK (mock.verifyCall("doMsg"));
|
|
|
|
|
|
CHECK (mock.verifyCall("doMsg").arg("lorem ipsum"));
|
|
|
|
|
|
CHECK (mock.verifyCall("doMsg").argMatch("dolor.+dolor\\s+"));
|
|
|
|
|
|
CHECK (mock.verifyMatch("Rec\\(mark.+ID = Message.+\\{.+lorem ipsum"));
|
2015-11-27 02:38:23 +01:00
|
|
|
|
|
|
|
|
|
|
EventLog log = mock.getLog();
|
|
|
|
|
|
log.verify("ctor")
|
|
|
|
|
|
.before("reset")
|
|
|
|
|
|
.before("lorem ipsum");
|
|
|
|
|
|
|
2015-12-27 01:58:15 +01:00
|
|
|
|
// create further mock elements...
|
2015-11-28 23:50:56 +01:00
|
|
|
|
MockElm foo("foo"), bar("bar");
|
2015-11-27 02:38:23 +01:00
|
|
|
|
foo.verify("ctor").arg("foo");
|
2015-12-16 02:16:53 +01:00
|
|
|
|
bar.verify("ctor").arg("bar");
|
2015-11-27 02:38:23 +01:00
|
|
|
|
|
|
|
|
|
|
bar.ensureNot("foo");
|
|
|
|
|
|
log.ensureNot("foo");
|
|
|
|
|
|
mock.ensureNot("foo");
|
2015-12-16 02:16:53 +01:00
|
|
|
|
CHECK (!foo.ensureNot("foo"));
|
2015-11-27 02:38:23 +01:00
|
|
|
|
|
2015-12-27 01:58:15 +01:00
|
|
|
|
// now join the logs together,
|
|
|
|
|
|
// allowing to watch the combined events
|
2015-12-06 04:30:39 +01:00
|
|
|
|
bar.joinLog(mock);
|
|
|
|
|
|
foo.joinLog(mock);
|
2015-12-26 04:55:00 +01:00
|
|
|
|
CHECK (log.verifyEvent("logJoin","bar")
|
|
|
|
|
|
.beforeEvent("logJoin","foo"));
|
|
|
|
|
|
|
|
|
|
|
|
CHECK (mock.verifyEvent("logJoin","bar")
|
|
|
|
|
|
.beforeEvent("logJoin","foo"));
|
|
|
|
|
|
CHECK (mock.verifyEvent("create","foo"));
|
|
|
|
|
|
CHECK (log.verifyEvent("create","foo"));
|
|
|
|
|
|
CHECK (log.verifyEvent("create","dummy")
|
|
|
|
|
|
.beforeEvent("create","bar")
|
|
|
|
|
|
.beforeEvent("create","foo"));
|
2015-11-27 02:38:23 +01:00
|
|
|
|
|
2015-12-27 01:58:15 +01:00
|
|
|
|
|
2015-11-27 02:38:23 +01:00
|
|
|
|
mock.kill();
|
2015-12-16 02:16:53 +01:00
|
|
|
|
foo.markMsg("dummy killed");
|
2015-12-26 20:41:24 +01:00
|
|
|
|
CHECK (log.verifyEvent("destroy","dummy")
|
|
|
|
|
|
.beforeCall("doMsg").on("foo"));
|
2015-12-26 21:53:46 +01:00
|
|
|
|
|
2015-12-27 01:58:15 +01:00
|
|
|
|
// Access the log on the Test-Nexus hub
|
2015-12-26 22:56:43 +01:00
|
|
|
|
EventLog nexusLog = gui::test::Nexus::getLog();
|
|
|
|
|
|
CHECK (nexusLog.verifyEvent("destroy","dummy")
|
|
|
|
|
|
.beforeEvent("dummy successfully zombificated"));
|
|
|
|
|
|
|
2015-12-27 01:58:15 +01:00
|
|
|
|
mock.slotExpand(); // attempt to operate the zombie
|
2015-12-26 22:56:43 +01:00
|
|
|
|
CHECK (nexusLog.verifyEvent("dummy successfully zombificated")
|
2015-12-27 01:58:15 +01:00
|
|
|
|
.beforeCall("note").on("ZombieNexus").arg("defunct-dummy", "expand")
|
|
|
|
|
|
.beforeEvent("error","sent note message to ZombieNexus"));
|
2015-12-26 22:56:43 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cout << "____Event-Log_________________\n"
|
2015-12-26 21:53:46 +01:00
|
|
|
|
<< util::join(mock.getLog(), "\n")
|
|
|
|
|
|
<< "\n───╼━━━━━━━━━╾────────────────"<<endl;
|
2015-12-26 22:56:43 +01:00
|
|
|
|
|
|
|
|
|
|
cout << "____Nexus-Log_________________\n"
|
|
|
|
|
|
<< util::join(gui::test::Nexus::getLog(), "\n")
|
|
|
|
|
|
<< "\n───╼━━━━━━━━━╾────────────────"<<endl;
|
2015-11-26 22:23:43 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2015-11-27 02:38:23 +01:00
|
|
|
|
|
2016-01-12 02:14:06 +01:00
|
|
|
|
|
2015-11-26 22:23:43 +01:00
|
|
|
|
void
|
|
|
|
|
|
invokeCommand ()
|
|
|
|
|
|
{
|
2016-01-15 01:44:35 +01:00
|
|
|
|
MARK_TEST_FUN
|
2016-01-12 02:14:06 +01:00
|
|
|
|
EventLog nexusLog = gui::test::Nexus::startNewLog();
|
|
|
|
|
|
|
|
|
|
|
|
// Setup test stage: define an command/action "in Proc"
|
|
|
|
|
|
CommandDef (DUMMY_CMD_ID)
|
|
|
|
|
|
.operation (operate)
|
|
|
|
|
|
.captureUndo (capture)
|
|
|
|
|
|
.undoOperation (undoIt);
|
|
|
|
|
|
|
2016-01-12 02:59:16 +01:00
|
|
|
|
gui::test::Nexus::setCommandHandler (&processCommandInvocation);
|
|
|
|
|
|
|
2016-01-12 02:14:06 +01:00
|
|
|
|
// Usually it's the InvocationStateManager's job to
|
|
|
|
|
|
// prepare an "InvocationTrail", which is a prospective
|
|
|
|
|
|
// Command invocation about to happen soon.
|
2016-09-08 18:49:27 +02:00
|
|
|
|
InvocationTrail invoTrail (Command::get (DUMMY_CMD_ID));
|
2016-01-12 02:14:06 +01:00
|
|
|
|
|
|
|
|
|
|
// the UI element relevant for this command invocation
|
|
|
|
|
|
MockElm mock("uiElm");
|
|
|
|
|
|
|
|
|
|
|
|
int prevState = dummyState;
|
|
|
|
|
|
int concreteParam = 1 +rand() % 100;
|
|
|
|
|
|
|
2016-01-15 02:29:33 +01:00
|
|
|
|
// on bus no traces from this command yet...
|
|
|
|
|
|
CHECK (nexusLog.ensureNot(string(DUMMY_CMD_ID)));
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-01-12 02:14:06 +01:00
|
|
|
|
// now the ongoing interaction picks up parameter data
|
2016-09-08 18:49:27 +02:00
|
|
|
|
mock.prepareCommand (invoTrail, lib::diff::Rec({concreteParam}));
|
2016-01-15 02:29:33 +01:00
|
|
|
|
CHECK (nexusLog.verifyCall("act").arg("«int»|" +toString(concreteParam))
|
|
|
|
|
|
.beforeEvent("binding for command \""+DUMMY_CMD_ID));
|
2016-01-12 02:14:06 +01:00
|
|
|
|
|
|
|
|
|
|
CHECK (dummyState == prevState); // command was not yet invoked
|
2016-01-15 02:29:33 +01:00
|
|
|
|
CHECK (nexusLog.ensureNot("invoke command \""+DUMMY_CMD_ID));
|
|
|
|
|
|
|
2016-01-12 02:14:06 +01:00
|
|
|
|
|
|
|
|
|
|
// finally the command gets triggered
|
2016-09-08 18:49:27 +02:00
|
|
|
|
mock.issueCommand (invoTrail);
|
2016-01-12 02:14:06 +01:00
|
|
|
|
|
|
|
|
|
|
CHECK (dummyState == concreteParam); // command was indeed invoked
|
2016-01-15 02:29:33 +01:00
|
|
|
|
CHECK (nexusLog.verifyCall("act").arg("«int»|" +toString(concreteParam))
|
2016-02-11 15:47:16 +01:00
|
|
|
|
.beforeCall("act").arg("DataCap|«int»|" +toString(int(InvocationTrail::DO_IT))));
|
2016-01-15 02:29:33 +01:00
|
|
|
|
CHECK (nexusLog.verifyEvent("binding for command \""+DUMMY_CMD_ID)
|
|
|
|
|
|
.beforeEvent("invoke command \""+DUMMY_CMD_ID));
|
2016-01-12 02:14:06 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// verify proper binding, including UNDO state capture
|
|
|
|
|
|
Command::get (DUMMY_CMD_ID).undo();
|
|
|
|
|
|
CHECK (dummyState == prevState);
|
|
|
|
|
|
|
|
|
|
|
|
cout << "____Nexus-Log_________________\n"
|
|
|
|
|
|
<< util::join(nexusLog, "\n")
|
|
|
|
|
|
<< "\n───╼━━━━━━━━━╾────────────────"<<endl;
|
2016-01-12 02:59:16 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// reset to default (NOP) handler
|
|
|
|
|
|
gui::test::Nexus::setCommandHandler();
|
2015-11-26 22:23:43 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-02-11 21:56:58 +01:00
|
|
|
|
/** @test mark interface state.
|
|
|
|
|
|
* This test case performs an elementary UI operation, namely to
|
|
|
|
|
|
* expand / collapse an element, to verify both directions of state marking.
|
|
|
|
|
|
* Here »state marking« is a mechanism, where UI state changes get recorded
|
|
|
|
|
|
* at some central StateManager, to be able to restore interface state later.
|
|
|
|
|
|
* Thus, when we'll expand and collapse the mock, we expect the corresponding
|
|
|
|
|
|
* "state mark" notifications to appear at the UI-Bus.
|
|
|
|
|
|
*
|
|
|
|
|
|
* The second part of this test _replays_ such a state mark, which causes
|
|
|
|
|
|
* the`doMark()` operation on the UI element to be invoked.
|
|
|
|
|
|
* @todo maybe we'll even provide a default implementation for expand/collapse
|
|
|
|
|
|
* which then means that, by replaying the mentioned state marks, the
|
|
|
|
|
|
* `doExpand()` or `doCollapse()` should be re-invoked, of course
|
|
|
|
|
|
* without issuing a further notification
|
|
|
|
|
|
* @note this test does not cover or even emulate the operation of the
|
|
|
|
|
|
* "state manager", since the goal is to cover the _UI element_
|
|
|
|
|
|
* protocol. We'll just listen at the bus and replay messages.
|
|
|
|
|
|
*/
|
2015-11-26 22:23:43 +01:00
|
|
|
|
void
|
|
|
|
|
|
markState ()
|
|
|
|
|
|
{
|
2016-02-11 20:48:21 +01:00
|
|
|
|
MARK_TEST_FUN
|
|
|
|
|
|
EventLog nexusLog = gui::test::Nexus::startNewLog();
|
2016-02-11 21:56:58 +01:00
|
|
|
|
|
|
|
|
|
|
sigc::signal<void> trigger_expand;
|
|
|
|
|
|
sigc::signal<void> trigger_collapse;
|
|
|
|
|
|
|
2016-02-11 20:48:21 +01:00
|
|
|
|
MockElm mock("target");
|
2016-02-11 21:56:58 +01:00
|
|
|
|
ID targetID = mock.getID();
|
2016-02-11 20:48:21 +01:00
|
|
|
|
|
2016-02-11 21:56:58 +01:00
|
|
|
|
trigger_expand.connect (sigc::mem_fun(mock, &Tangible::slotExpand));
|
|
|
|
|
|
trigger_collapse.connect (sigc::mem_fun(mock, &Tangible::slotCollapse));
|
|
|
|
|
|
|
|
|
|
|
|
CHECK (not mock.isTouched());
|
|
|
|
|
|
CHECK (not mock.isExpanded());
|
|
|
|
|
|
CHECK (mock.ensureNot("expanded"));
|
|
|
|
|
|
CHECK (nexusLog.ensureNot("state-mark"));
|
|
|
|
|
|
|
|
|
|
|
|
trigger_expand(); // emit signal
|
|
|
|
|
|
|
|
|
|
|
|
CHECK (mock.isTouched());
|
|
|
|
|
|
CHECK (mock.isExpanded());
|
|
|
|
|
|
CHECK (mock.verifyCall("expand").arg(true)
|
|
|
|
|
|
.beforeEvent("expanded"));
|
|
|
|
|
|
|
|
|
|
|
|
// and now the important part: state mark notification was sent over the bus...
|
|
|
|
|
|
CHECK (nexusLog.verifyCall("note").arg(targetID, GenNode{"expand", true})
|
|
|
|
|
|
.before("handling state-mark"));
|
|
|
|
|
|
|
2016-02-11 22:13:36 +01:00
|
|
|
|
|
|
|
|
|
|
trigger_collapse(); // emit other signal
|
|
|
|
|
|
CHECK (not mock.isExpanded());
|
|
|
|
|
|
CHECK (mock.isTouched());
|
|
|
|
|
|
|
2016-02-13 22:36:42 +01:00
|
|
|
|
CHECK (mock.verifyEvent("create", "target")
|
|
|
|
|
|
.beforeEvent("expanded")
|
|
|
|
|
|
.beforeEvent("collapsed"));
|
2016-02-11 22:13:36 +01:00
|
|
|
|
CHECK (nexusLog.verifyCall("note").arg(targetID, GenNode{"expand", true})
|
|
|
|
|
|
.before("handling state-mark")
|
|
|
|
|
|
.beforeCall("note").arg(targetID, GenNode{"expand", false})
|
|
|
|
|
|
.before("handling state-mark"));
|
|
|
|
|
|
|
|
|
|
|
|
trigger_collapse();
|
|
|
|
|
|
CHECK (not mock.isExpanded());
|
2016-02-13 22:36:42 +01:00
|
|
|
|
|
|
|
|
|
|
// but note: redundant state changes do not cause sending of further state marks
|
|
|
|
|
|
CHECK (mock.ensureNot("collapsed")
|
|
|
|
|
|
.beforeCall("expand")
|
2016-02-11 22:13:36 +01:00
|
|
|
|
.beforeEvent("collapsed"));
|
2016-02-13 22:36:42 +01:00
|
|
|
|
CHECK (nexusLog.ensureNot("handling state-mark")
|
2016-02-11 22:13:36 +01:00
|
|
|
|
.beforeCall("note").arg(targetID, GenNode{"expand", false})
|
|
|
|
|
|
.before("handling state-mark")
|
2016-02-13 22:36:42 +01:00
|
|
|
|
.beforeCall("note").arg(targetID, GenNode{"expand", false}));
|
2016-02-11 22:13:36 +01:00
|
|
|
|
|
2016-02-12 01:31:51 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Second part: replay of a state mark via UI-Bus....
|
|
|
|
|
|
auto stateMark = GenNode{"expand", true};
|
|
|
|
|
|
auto& uiBus = gui::test::Nexus::testUI();
|
|
|
|
|
|
|
|
|
|
|
|
CHECK (not mock.isExpanded());
|
|
|
|
|
|
CHECK (mock.ensureNot("mark"));
|
|
|
|
|
|
|
|
|
|
|
|
uiBus.mark (targetID, stateMark);
|
|
|
|
|
|
|
|
|
|
|
|
CHECK (nexusLog.verifyCall("mark").arg(targetID, stateMark)
|
|
|
|
|
|
.before("delivered mark to "+string(targetID)).arg(stateMark));
|
|
|
|
|
|
|
|
|
|
|
|
CHECK (mock.verifyMark("expand", "true")
|
|
|
|
|
|
.beforeCall("expand").arg(true)
|
|
|
|
|
|
.beforeEvent("expanded"));
|
|
|
|
|
|
CHECK (mock.isExpanded());
|
|
|
|
|
|
CHECK (mock.isTouched());
|
|
|
|
|
|
|
|
|
|
|
|
// the default handler defined in model::Tangible
|
|
|
|
|
|
// already supports some rather generic state changes,
|
|
|
|
|
|
// like e.g. a reset to the element's default state.
|
|
|
|
|
|
// Note that the actual implementation doReset()
|
|
|
|
|
|
// is a virtual function, here implemented in MockElm.
|
|
|
|
|
|
uiBus.mark (targetID, GenNode{"reset", true});
|
|
|
|
|
|
// note: payload is irrelevant for "reset" mark
|
|
|
|
|
|
|
|
|
|
|
|
// and we're back to pristine state...
|
|
|
|
|
|
CHECK (not mock.isTouched());
|
|
|
|
|
|
CHECK (not mock.isExpanded());
|
|
|
|
|
|
CHECK (mock.verifyMark("reset", "true")
|
|
|
|
|
|
.afterEvent("expanded")
|
|
|
|
|
|
.beforeCall("reset")
|
|
|
|
|
|
.beforeEvent("reset"));
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-02-11 20:48:21 +01:00
|
|
|
|
cout << "____Event-Log_________________\n"
|
|
|
|
|
|
<< util::join(mock.getLog(), "\n")
|
|
|
|
|
|
<< "\n───╼━━━━━━━━━╾────────────────"<<endl;
|
|
|
|
|
|
|
|
|
|
|
|
cout << "____Nexus-Log_________________\n"
|
|
|
|
|
|
<< util::join(nexusLog, "\n")
|
|
|
|
|
|
<< "\n───╼━━━━━━━━━╾────────────────"<<endl;
|
2015-11-26 22:23:43 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-10-02 02:57:27 +02:00
|
|
|
|
/** @test receive various kinds of notifications.
|
2016-02-11 16:19:24 +01:00
|
|
|
|
* Send message, error and flash messages via Bus to the element
|
|
|
|
|
|
* and verify the doMsg, doErr or doFlash handlers were invoked.
|
|
|
|
|
|
*/
|
2015-11-26 22:23:43 +01:00
|
|
|
|
void
|
|
|
|
|
|
notify ()
|
|
|
|
|
|
{
|
2016-02-11 16:19:24 +01:00
|
|
|
|
MARK_TEST_FUN
|
|
|
|
|
|
EventLog nexusLog = gui::test::Nexus::startNewLog();
|
|
|
|
|
|
|
|
|
|
|
|
MockElm mock("target");
|
|
|
|
|
|
ID targetID = mock.getID();
|
|
|
|
|
|
auto& uiBus = gui::test::Nexus::testUI();
|
|
|
|
|
|
|
|
|
|
|
|
CHECK (mock.ensureNot("Flash"));
|
|
|
|
|
|
CHECK (mock.ensureNot("Error"));
|
|
|
|
|
|
CHECK (mock.ensureNot("Message"));
|
2016-02-14 00:23:24 +01:00
|
|
|
|
CHECK (isnil(mock.getMessage()));
|
|
|
|
|
|
CHECK (isnil(mock.getError()));
|
|
|
|
|
|
CHECK (not mock.isError());
|
2016-02-11 16:19:24 +01:00
|
|
|
|
|
2016-02-11 20:48:21 +01:00
|
|
|
|
// now send a "Flash" mark via UI-Bus....
|
2016-02-12 01:31:51 +01:00
|
|
|
|
uiBus.mark (targetID, GenNode{"Flash", true });
|
2016-02-11 20:48:21 +01:00
|
|
|
|
CHECK (mock.verifyMark("Flash"));
|
2016-02-11 16:19:24 +01:00
|
|
|
|
|
|
|
|
|
|
CHECK (mock.ensureNot("Error"));
|
|
|
|
|
|
CHECK (mock.ensureNot("Message"));
|
2016-02-14 00:23:24 +01:00
|
|
|
|
CHECK (isnil(mock.getMessage()));
|
|
|
|
|
|
CHECK (isnil(mock.getError()));
|
2016-02-11 16:19:24 +01:00
|
|
|
|
|
2016-02-12 01:31:51 +01:00
|
|
|
|
uiBus.mark (targetID, GenNode{"Error", "getting serious"});
|
2016-02-11 20:48:21 +01:00
|
|
|
|
CHECK (mock.verifyMark("Error", "serious"));
|
2016-02-14 00:23:24 +01:00
|
|
|
|
CHECK (mock.isError());
|
|
|
|
|
|
CHECK ("getting serious" == mock.getError());
|
|
|
|
|
|
CHECK (isnil(mock.getMessage()));
|
2016-02-11 16:19:24 +01:00
|
|
|
|
|
2016-02-12 01:31:51 +01:00
|
|
|
|
uiBus.mark (targetID, GenNode{"Message", "by mistake"});
|
2016-02-11 16:19:24 +01:00
|
|
|
|
CHECK (mock.verifyMark("Message", "mistake"));
|
2016-02-14 00:23:24 +01:00
|
|
|
|
CHECK ("by mistake" == mock.getMessage());
|
|
|
|
|
|
CHECK ("getting serious" == mock.getError());
|
2016-02-11 16:19:24 +01:00
|
|
|
|
|
|
|
|
|
|
CHECK (mock.verify("target")
|
2016-02-11 20:48:21 +01:00
|
|
|
|
.before("Flash")
|
2016-02-11 16:19:24 +01:00
|
|
|
|
.before("serious")
|
|
|
|
|
|
.before("mistake"));
|
|
|
|
|
|
|
2016-02-11 20:48:21 +01:00
|
|
|
|
// type mismatch: when receiving a "Message" mark, we expect a string payload
|
|
|
|
|
|
VERIFY_ERROR(WRONG_TYPE, uiBus.mark(targetID, GenNode{"Message", Time::NEVER }))
|
|
|
|
|
|
|
|
|
|
|
|
// the type error happens while resolving the payload,
|
|
|
|
|
|
// and thus the actual "doMsg()" function on the target was not invoked
|
|
|
|
|
|
CHECK (mock.ensureNot(string(Time::NEVER)));
|
|
|
|
|
|
CHECK (nexusLog.verifyCall("mark").arg(targetID, Time::NEVER));
|
|
|
|
|
|
CHECK (nexusLog.ensureNot("delivered mark").arg(Time::NEVER));
|
2016-02-14 00:23:24 +01:00
|
|
|
|
CHECK ("getting serious" == mock.getError());
|
|
|
|
|
|
|
|
|
|
|
|
mock.reset();
|
|
|
|
|
|
CHECK (isnil(mock.getMessage()));
|
|
|
|
|
|
CHECK (isnil(mock.getError()));
|
|
|
|
|
|
CHECK (not mock.isError());
|
2016-02-11 16:19:24 +01:00
|
|
|
|
|
2016-02-11 20:48:21 +01:00
|
|
|
|
|
|
|
|
|
|
cout << "____Event-Log_________________\n"
|
|
|
|
|
|
<< util::join(mock.getLog(), "\n")
|
|
|
|
|
|
<< "\n───╼━━━━━━━━━╾────────────────"<<endl;
|
|
|
|
|
|
|
|
|
|
|
|
cout << "____Nexus-Log_________________\n"
|
|
|
|
|
|
<< util::join(nexusLog, "\n")
|
|
|
|
|
|
<< "\n───╼━━━━━━━━━╾────────────────"<<endl;
|
2015-11-26 22:23:43 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-10-02 02:57:27 +02:00
|
|
|
|
/** @test mutate the mock element through diff messages */
|
2015-11-26 22:23:43 +01:00
|
|
|
|
void
|
|
|
|
|
|
mutate ()
|
|
|
|
|
|
{
|
2016-10-02 02:57:27 +02:00
|
|
|
|
MARK_TEST_FUN
|
|
|
|
|
|
EventLog nexusLog = gui::test::Nexus::startNewLog();
|
|
|
|
|
|
|
|
|
|
|
|
MockElm rootMock("root");
|
|
|
|
|
|
ID rootID = rootMock.getID();
|
|
|
|
|
|
|
2016-10-02 22:21:17 +02:00
|
|
|
|
rootMock.attrib["α"] = "Centauri";
|
|
|
|
|
|
CHECK ("Centauri" == rootMock.attrib["α"]);
|
2016-10-02 02:57:27 +02:00
|
|
|
|
CHECK (isnil (rootMock.scope));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct : lib::diff::TreeDiffLanguage
|
|
|
|
|
|
{
|
|
|
|
|
|
const GenNode
|
|
|
|
|
|
ATTRIB_AL = GenNode("α", "quadrant"),
|
|
|
|
|
|
ATTRIB_PI = GenNode("π", 3.14159265),
|
|
|
|
|
|
CHILD_1 = GenNode("a"),
|
|
|
|
|
|
CHILD_2 = GenNode('b');
|
|
|
|
|
|
|
|
|
|
|
|
auto
|
|
|
|
|
|
generateDiff()
|
|
|
|
|
|
{
|
|
|
|
|
|
using lib::iter_stl::snapshot;
|
|
|
|
|
|
using lib::diff::Ref;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return snapshot({after(Ref::ATTRIBS)
|
|
|
|
|
|
, ins(CHILD_1)
|
|
|
|
|
|
, ins(CHILD_2)
|
|
|
|
|
|
, set(ATTRIB_AL)
|
|
|
|
|
|
, mut(CHILD_2)
|
|
|
|
|
|
, ins(ATTRIB_PI)
|
|
|
|
|
|
, emu(CHILD_2)
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
diffSrc;
|
|
|
|
|
|
|
|
|
|
|
|
MutationMessage mutabor{diffSrc.generateDiff()};
|
|
|
|
|
|
|
|
|
|
|
|
auto& uiBus = gui::test::Nexus::testUI();
|
|
|
|
|
|
|
|
|
|
|
|
uiBus.change(rootID, mutabor);
|
|
|
|
|
|
cout << "____Event-Log_________________\n"
|
|
|
|
|
|
<< util::join(rootMock.getLog(), "\n")
|
|
|
|
|
|
<< "\n───╼━━━━━━━━━╾────────────────"<<endl;
|
|
|
|
|
|
|
|
|
|
|
|
cout << "____Nexus-Log_________________\n"
|
|
|
|
|
|
<< util::join(nexusLog, "\n")
|
|
|
|
|
|
<< "\n───╼━━━━━━━━━╾────────────────"<<endl;
|
|
|
|
|
|
|
|
|
|
|
|
CHECK (2 == rootMock.scope.size()); // we've got two children now
|
2016-10-02 22:21:17 +02:00
|
|
|
|
CHECK (rootMock.attrib["α"] == "quadrant"); // alpha attribute has been reassigned
|
2016-10-02 02:57:27 +02:00
|
|
|
|
CHECK (rootMock.scope[0].getID() == diffSrc.CHILD_1.idi); // children have the expected IDs
|
|
|
|
|
|
CHECK (rootMock.scope[1].getID() == diffSrc.CHILD_2.idi);
|
2016-10-02 22:21:17 +02:00
|
|
|
|
CHECK (rootMock.scope[1].attrib["π"] == "3.1415927"); // and the second child got attribute Pi
|
2015-11-26 22:23:43 +01:00
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** Register this test class... */
|
|
|
|
|
|
LAUNCHER (AbstractTangible_test, "unit gui");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}}} // namespace gui::model::test
|