2015-11-27 19:24:00 +01:00
|
|
|
/*
|
2015-12-18 17:40:42 +01:00
|
|
|
TEST-NEXUS.hpp - fake user interface backbone for test support
|
2015-11-27 19:24:00 +01:00
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
2015-12-18 17:40:42 +01:00
|
|
|
/** @file test/test-nexus.hpp
|
2015-11-28 01:20:40 +01:00
|
|
|
** A fake UI backbone for investigations and unit testing.
|
2015-12-27 03:16:49 +01:00
|
|
|
** Any relevant element within the Lumiera GTK UI is connected to the [UI-Bus](ui-bus.hpp)
|
2015-11-28 01:20:40 +01:00
|
|
|
** So for testing and investigation we need a white room setup to provide an instrumented
|
2015-12-27 03:16:49 +01:00
|
|
|
** backbone to run any test probes against. The test::Nexus allows to [hook up](\ref testUI())
|
2015-11-28 01:20:40 +01:00
|
|
|
** a generic interface element, to participate in a simulated interface interaction.
|
2015-11-27 19:24:00 +01:00
|
|
|
**
|
2015-12-18 01:45:00 +01:00
|
|
|
** This class test::Nexus acts as front-end for unit tests, while the actual implementation
|
2015-12-27 01:58:15 +01:00
|
|
|
** of a test rigged mock interface backbone remains an implementation detail. The purpose
|
|
|
|
|
** of this setup is to capture messages sent from elements operated within a test setup
|
|
|
|
|
** and directed at "core services" (that is, towards a presentation state manager or
|
|
|
|
|
** towards the Proc-Layer for command invocation). Test code may then verify the
|
|
|
|
|
** proper shape and incidence of these messages.
|
2015-12-18 01:45:00 +01:00
|
|
|
**
|
2015-12-27 01:58:15 +01:00
|
|
|
** @see [abstract-tangible-test.cpp]
|
|
|
|
|
** @see [BusTerm_test]
|
2015-11-27 19:24:00 +01:00
|
|
|
**
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
2015-12-18 17:40:42 +01:00
|
|
|
#ifndef GUI_TEST_TEST_NEXUS_H
|
|
|
|
|
#define GUI_TEST_TEST_NEXUS_H
|
2015-11-27 19:24:00 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "lib/error.hpp"
|
2015-11-28 01:20:40 +01:00
|
|
|
#include "gui/ctrl/bus-term.hpp"
|
2016-01-03 03:23:39 +01:00
|
|
|
#include "gui/model/tangible.hpp"
|
2015-12-26 22:56:43 +01:00
|
|
|
#include "lib/test/event-log.hpp"
|
2016-01-03 03:23:39 +01:00
|
|
|
#include "lib/diff/gen-node.hpp"
|
2015-11-27 19:24:00 +01:00
|
|
|
|
|
|
|
|
#include <boost/noncopyable.hpp>
|
2016-01-03 03:23:39 +01:00
|
|
|
#include <functional>
|
2015-12-26 20:41:24 +01:00
|
|
|
#include <string>
|
2015-11-27 19:24:00 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace gui {
|
|
|
|
|
namespace test{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2015-11-28 01:20:40 +01:00
|
|
|
* Mock UI backbone for unit testing.
|
2015-12-27 03:16:49 +01:00
|
|
|
* In the absence of a real UI, this simulated [UI-Bus](ui-bus.hpp)
|
|
|
|
|
* can be used to wire a [test probe](\ref MockElm) and address it in unit testing.
|
2015-11-27 19:24:00 +01:00
|
|
|
*
|
2015-12-27 01:58:15 +01:00
|
|
|
* @note behind the scenes, this is a singleton. Use the provided
|
|
|
|
|
* attachment point testUI() in order to wire and hook up new
|
|
|
|
|
* interface elements. When using or deriving from [MockElm] this
|
|
|
|
|
* wiring happens automatically within the ctor.
|
2015-11-27 19:24:00 +01:00
|
|
|
* @see abstract-tangible-test.cpp
|
|
|
|
|
*/
|
|
|
|
|
class Nexus
|
|
|
|
|
: boost::noncopyable
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
public:
|
2015-11-28 01:20:40 +01:00
|
|
|
/** get a connection point to a UI backbone faked for test */
|
|
|
|
|
static ctrl::BusTerm& testUI();
|
2015-12-26 20:41:24 +01:00
|
|
|
|
|
|
|
|
/** kill the given [BusTerm] and implant a dead terminal in place */
|
|
|
|
|
static void zombificate(ctrl::BusTerm&);
|
2015-12-26 22:56:43 +01:00
|
|
|
|
|
|
|
|
static lib::test::EventLog const& getLog();
|
2016-01-02 02:00:07 +01:00
|
|
|
static lib::test::EventLog const& startNewLog();
|
2016-01-03 03:23:39 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/* == allow to set custom handlers for commands and state changes == */
|
|
|
|
|
|
|
|
|
|
using CommandHandler = std::function<void(lib::diff::GenNode const&)>;
|
|
|
|
|
using StateMarkHandler = std::function<void(lib::idi::BareEntryID, lib::diff::GenNode const&)>;
|
|
|
|
|
|
|
|
|
|
static void setCommandHandler (CommandHandler =CommandHandler());
|
|
|
|
|
static void setStateMarkHandler (StateMarkHandler =StateMarkHandler());
|
2016-01-15 04:57:49 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
using Cmd = interact::InvocationTrail;
|
|
|
|
|
|
|
|
|
|
template<typename...ARGS>
|
|
|
|
|
static Cmd prepareMockCmd();
|
|
|
|
|
|
|
|
|
|
static bool canInvoke(Cmd);
|
|
|
|
|
static bool wasInvoked (Cmd);
|
|
|
|
|
|
|
|
|
|
template<typename...ARGS>
|
|
|
|
|
static bool wasBound (Cmd, ARGS const& ...args);
|
|
|
|
|
|
|
|
|
|
template<typename...ARGS>
|
|
|
|
|
static bool wasInvoked (Cmd, ARGS const& ...args);
|
2015-11-27 19:24:00 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-01-15 04:57:49 +01:00
|
|
|
template<typename...ARGS>
|
|
|
|
|
inline interact::InvocationTrail
|
|
|
|
|
Nexus::prepareMockCmd()
|
|
|
|
|
{
|
|
|
|
|
UNIMPLEMENTED("pick up arbitrary types and fabricate a mock command accepting those types");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<typename...ARGS>
|
|
|
|
|
inline bool
|
|
|
|
|
Nexus::wasBound (Cmd cmd, ARGS const& ...args)
|
|
|
|
|
{
|
|
|
|
|
UNIMPLEMENTED("verify the denoted command was actually bound against the given concrete Arguments (String-match)");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<typename...ARGS>
|
|
|
|
|
inline bool
|
|
|
|
|
Nexus::wasInvoked (Cmd cmd, ARGS const& ...args)
|
|
|
|
|
{
|
|
|
|
|
UNIMPLEMENTED("verify the denoted command was indeed invoked and received the given concrete Arguments (String-match)");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-11-27 19:24:00 +01:00
|
|
|
}} // namespace gui::test
|
2015-12-18 17:40:42 +01:00
|
|
|
#endif /*GUI_TEST_TEST_NEXUS_H*/
|