Lumiera  0.pre.03
»edityourfreedom«
Nexus Class Reference

#include "/Werk/devel/lumi/tests/gui/test/test-nexus.hpp"

Description

Mock UI backbone for unit testing.

In the absence of a real UI, this simulated UI-Bus can be used to wire a test probe and address it in unit testing.

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.
See also
abstract-tangible-test.cpp

Definition at line 76 of file test-nexus.hpp.

Public Types

using CommandHandler = std::function< void(lib::diff::GenNode const &)>
 
using StateMarkHandler = std::function< void(lib::idi::BareEntryID const &, lib::diff::GenNode const &)>
 

Static Public Member Functions

static lib::test::EventLog const & getLog ()
 
static ctrl::StateManagergetMockStateManager ()
 
template<typename... ARGS>
static Symbol prepareMockCmd ()
 Setup of test fixture: prepare a mocked Proc-Layer command, which accepts arguments with the denoted types. More...
 
static void setCommandHandler (CommandHandler=CommandHandler())
 install a closure (custom handler function) to deal with any command invocations encountered in the test-UI-Bus. More...
 
static void setStateMarkHandler (StateMarkHandler=StateMarkHandler())
 similar to the [custom command handler](Nexus::setCommandHandler) this hook allows to install a closure to intercept any "state mark" messages passed over the test-UI-Bus More...
 
static size_t size ()
 
static lib::test::EventLog const & startNewLog ()
 
static ctrl::BusTermtestUI ()
 get a connection point to a UI backbone faked for test More...
 
static ctrl::StateManageruseMockStateManager ()
 install a standard handler for state mark messages, which is actually backed by a mock implementation of the PresentationStateManager interface. More...
 
template<typename... ARGS>
static bool wasBound (Symbol, ARGS const &...args)
 Test predicate: verify by string match that the denoted command was actually bound against the given concrete arguments. More...
 
static bool wasInvoked (Symbol)
 Test predicate: verify at least one actual invocation happened for the given commend, without matching any concrete arguments. More...
 
template<typename... ARGS>
static bool wasInvoked (Symbol, ARGS const &...args)
 Test predicate: verify actual command invocation by string match on test log. More...
 
static void zombificate (ctrl::BusTerm &)
 kill the given [BusTerm] and implant a dead terminal in place More...
 

Static Private Member Functions

static void prepareDiagnosticCommandHandler ()
 

Additional Inherited Members

- Private Member Functions inherited from NonCopyable
 NonCopyable ()=default
 
 NonCopyable (NonCopyable const &)=delete
 
 ~NonCopyable ()=default
 
NonCopyableoperator= (NonCopyable const &)=delete
 

Member Typedef Documentation

◆ CommandHandler

using CommandHandler = std::function<void(lib::diff::GenNode const&)>

Definition at line 95 of file test-nexus.hpp.

◆ StateMarkHandler

using StateMarkHandler = std::function<void(lib::idi::BareEntryID const&, lib::diff::GenNode const&)>

Definition at line 96 of file test-nexus.hpp.

Member Function Documentation

◆ testUI()

ctrl::BusTerm & testUI ( )
static

get a connection point to a UI backbone faked for test

Returns
reference to a node of the test UI bus, which allows to hook up new nodes for test

Definition at line 375 of file test-nexus.cpp.

Referenced by BusTerm_test::attachNewBusTerm(), BusTerm_test::clearStates(), AbstractTangible_test::markState(), AbstractTangible_test::mutate(), AbstractTangible_test::notify(), BusTerm_test::pushDiff(), BusTerm_test::replayStateMark(), AbstractTangible_test::revealer(), and BusTerm_test::verifyNotifications().

+ Here is the caller graph for this function:

◆ zombificate()

void zombificate ( ctrl::BusTerm doomed)
static

kill the given [BusTerm] and implant a dead terminal in place

Returns
a defunct BusTerm with up-link to [ZombieNexus]
Remarks
useful to create zombie mock UI-Elements for testing.

Definition at line 593 of file test-nexus.cpp.

References BusTerm::getID(), and BusTerm::~BusTerm().

Referenced by MockElm::kill().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getLog()

lib::test::EventLog const & getLog ( )
static

Definition at line 381 of file test-nexus.cpp.

Referenced by BusTerm_test::attachNewBusTerm(), BusTerm_test::captureStateMark(), BusTerm_test::commandInvocation(), Nexus::prepareMockCmd(), Nexus::setStateMarkHandler(), AbstractTangible_test::verify_mockManipulation(), Nexus::wasBound(), and Nexus::wasInvoked().

+ Here is the caller graph for this function:

◆ startNewLog()

◆ size()

size_t size ( )
static

Definition at line 393 of file test-nexus.cpp.

Referenced by BusTerm_test::pushDiff().

+ Here is the caller graph for this function:

◆ setCommandHandler()

void setCommandHandler ( CommandHandler  newHandler = CommandHandler())
static

install a closure (custom handler function) to deal with any command invocations encountered in the test-UI-Bus.

In the real Lumiera-UI, the UI-Bus is wired with a core service handler, which processes command messages by actually triggering command invocation on the Session within Proc-Layer

Note
when called without arguments, a default handler will be installed, which just logs and discards any command invocation message.
Warning
when you install a closure from within unit test code, be sure to re-install the default handler prior to leaving the definition scope; since the "test nexus" is actually implemented as singleton, an installed custom handler will outlive the immediate usage scope, possibly leading to segfault

Definition at line 417 of file test-nexus.cpp.

Referenced by BusTerm_test::commandInvocation(), and AbstractTangible_test::invokeCommand().

+ Here is the caller graph for this function:

◆ setStateMarkHandler()

void setStateMarkHandler ( StateMarkHandler  newHandler = StateMarkHandler())
static

similar to the [custom command handler](Nexus::setCommandHandler) this hook allows to install a closure to intercept any "state mark" messages passed over the test-UI-Bus

Definition at line 428 of file test-nexus.cpp.

References lib::append_all(), Command::bindArg(), EventLog::call(), GenNode::data, EventLog::event(), Command::exec(), DataCap::get(), Command::getID(), Nexus::getLog(), BareEntryID::getSym(), GenNode::idi, CommandImpl::invokeCapture(), CommandImpl::invokeOperation(), CommandImpl::invokeUndo(), util::isValid(), lib::transformIterator(), and EventLog::warn().

Referenced by BusTerm_test::clearStates().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ useMockStateManager()

ctrl::StateManager & useMockStateManager ( )
static

install a standard handler for state mark messages, which is actually backed by a mock implementation of the PresentationStateManager interface.

This mock is based on the same implementation techniques as the full fledged state manager in the Lumiera GTK UI; any state mark notification messages appearing after that point at the test-UI-Bus will be accounted for.

Definition at line 562 of file test-nexus.cpp.

References StateManager::clearState().

Referenced by BusTerm_test::captureStateMark().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getMockStateManager()

ctrl::StateManager & getMockStateManager ( )
static

Definition at line 578 of file test-nexus.cpp.

Referenced by BusTerm_test::clearStates(), and BusTerm_test::replayStateMark().

+ Here is the caller graph for this function:

◆ prepareMockCmd()

Symbol prepareMockCmd ( )
inlinestatic

Setup of test fixture: prepare a mocked Proc-Layer command, which accepts arguments with the denoted types.

Note
this call installs the command mock into the Proc-Layer command registry, where it remains in place until shutdown. The can be accessed through the generated command ID. Besides, this call also installs a command handler into the Test-Nexus, causing "`act`" messages to be processed and logged.
Returns
the ID of the generated mock command.

Definition at line 135 of file test-nexus.hpp.

References PlaceholderCommand< ARGS >::fabricateNewInstance(), Command::getID(), Nexus::getLog(), and Nexus::prepareDiagnosticCommandHandler().

+ Here is the call graph for this function:

◆ wasInvoked() [1/2]

bool wasInvoked ( Symbol  cmd)
inlinestatic

Test predicate: verify at least one actual invocation happened for the given commend, without matching any concrete arguments.

Definition at line 197 of file test-nexus.hpp.

References EventMatch::arg(), EventMatch::beforeCall(), EventMatch::beforeEvent(), Nexus::getLog(), EventMatch::on(), and EventLog::verifyMatch().

Referenced by BusTerm_test::commandInvocation().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ wasBound()

bool wasBound ( Symbol  cmd,
ARGS const &...  args 
)
inlinestatic

Test predicate: verify by string match that the denoted command was actually bound against the given concrete arguments.

Actually, we'll match against the Test-Nexus log, where the processing of the corresponding "bind" message should have logged all parameter values

Remarks
The difficulty here is that the whole command machinery was made to work opaque (type-erased), and that the bind message is also opaque, to allow to send arbitrary binding data. The remedy is to rely on diff::DataCap's operator string(), so we can at least match with the transport format of the Data. A precise and complete matching would only possible after actually invoking our probe-command, since we're controlling the implementation of that probe-command. Right now (2016) this implementation was deemed adequate

Definition at line 159 of file test-nexus.hpp.

References EventMatch::arg(), EventMatch::beforeCall(), Nexus::getLog(), EventMatch::on(), and EventLog::verifyMatch().

Referenced by BusTerm_test::commandInvocation().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ wasInvoked() [2/2]

bool wasInvoked ( Symbol  cmd,
ARGS const &...  args 
)
inlinestatic

Test predicate: verify actual command invocation by string match on test log.

This match ensures that

  • first the installed command handler processed the 'act' message
  • then the installed (mock) command handling pattern triggered invocation
  • and finally our installed mock command function received the call
    Remarks
    again arguments are verified by string match; but now we're looking on the concrete arguments as seen from within the command operate function. These may differ from the transport values, which are used to initialise the concrete arguments.

Definition at line 182 of file test-nexus.hpp.

References EventMatch::arg(), EventMatch::beforeCall(), EventMatch::beforeEvent(), Nexus::getLog(), EventMatch::on(), util::toString(), and EventLog::verifyMatch().

+ Here is the call graph for this function:

◆ prepareDiagnosticCommandHandler()

void prepareDiagnosticCommandHandler ( )
staticprivate

Definition at line 516 of file test-nexus.cpp.

Referenced by Nexus::prepareMockCmd().

+ Here is the caller graph for this function:
+ Inheritance diagram for Nexus:
+ Collaboration diagram for Nexus:

The documentation for this class was generated from the following files: