Lumiera  0.pre.03
»edit your freedom«
Nexus Class Reference

#include "/Werk/devel/lumi/tests/stage/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 Steam-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 this hook allows to install a closure to intercept any "state mark" messages passed over the test-UI-Bus
 
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.
 
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 (NonCopyable const &)=delete
 
NonCopyableoperator= (NonCopyable const &)=delete
 

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.

References stage::test::anonymous_namespace{test-nexus.cpp}::testNexus.

Referenced by BusTerm_test::attachNewBusTerm(), MockElm::buildMutator(), BusTerm_test::clearStates(), AbstractTangible_test::markState(), AbstractTangible_test::notify(), 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 stage::test::anonymous_namespace{test-nexus.cpp}::testNexus, and BusTerm::~BusTerm().

Referenced by MockElm::kill().

+ Here is the call graph for this function:
+ 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 Steam-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.

References stage::test::anonymous_namespace{test-nexus.cpp}::testNexus.

◆ 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.

◆ prepareMockCmd()

Symbol prepareMockCmd ( )
inlinestatic

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

Note
this call installs the command mock into the Steam-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.

◆ 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(), EventMatch::on(), and EventLog::verifyMatch().

+ Here is the call graph for this function:

◆ wasInvoked()

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(), EventMatch::on(), and EventLog::verifyMatch().

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

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