Lumiera 0.pre.04
»edit your freedom«
Loading...
Searching...
No Matches
test-nexus.hpp
Go to the documentation of this file.
1/*
2 TEST-NEXUS.hpp - fake user interface backbone for test support
3
4 Copyright (C)
5 2015, Hermann Vosseler <Ichthyostega@web.de>
6
7  **Lumiera** is free software; you can redistribute it and/or modify it
8  under the terms of the GNU General Public License as published by the
9  Free Software Foundation; either version 2 of the License, or (at your
10  option) any later version. See the file COPYING for further details.
11
12*/
13
14
35#ifndef STAGE_TEST_TEST_NEXUS_H
36#define STAGE_TEST_TEST_NEXUS_H
37
38
39#include "lib/error.hpp"
40#include "lib/nocopy.hpp"
46#include "lib/diff/gen-node.hpp"
47
48#include <functional>
49#include <string>
50
51
52namespace stage {
53namespace test{
54
55
67 class Nexus
69 {
70
71 public:
73 static ctrl::BusTerm& testUI();
74
76 static void zombificate(ctrl::BusTerm&);
77
78 static lib::test::EventLog const& getLog();
79 static lib::test::EventLog const& startNewLog();
80
81 static size_t size();
82
83
84 /* == allow to set custom handlers for commands and state changes == */
85
86 using CommandHandler = std::function<void(lib::diff::GenNode const&)>;
87 using StateMarkHandler = std::function<void(lib::idi::BareEntryID const&, lib::diff::GenNode const&)>;
88
91
92
95
96
97 template<typename...ARGS>
98 static Symbol prepareMockCmd();
99
100 static bool wasInvoked (Symbol);
101
102 template<typename...ARGS>
103 static bool wasBound (Symbol, ARGS const& ...args);
104
105 template<typename...ARGS>
106 static bool wasInvoked (Symbol, ARGS const& ...args);
107
108 private:
110 };
111
112
113
124 template<typename...ARGS>
125 inline Symbol
132
133
148 template<typename...ARGS>
149 inline bool
150 Nexus::wasBound (Symbol cmd, ARGS const& ...args)
151 {
152 using lib::diff::DataCap;
153
154 return getLog()
155 .verifyMatch("TestNexus.+HANDLING Command-Message for .+" +cmd)
156 .beforeCall("bind-command").on("TestNexus")
157 .arg(string(DataCap(args))...);
158 }
159
171 template<typename...ARGS>
172 inline bool
173 Nexus::wasInvoked (Symbol cmd, ARGS const& ...args)
174 {
175 return getLog()
176 .verifyMatch("TestNexus.+HANDLING Command-Message for .+" +cmd)
177 .beforeCall("exec-command").on("TestNexus").arg(cmd)
178 .beforeCall("exec").on("MockHandlingPattern")
179 .beforeCall("operate").arg(util::toString(args)...)
180 .beforeEvent("TestNexus", "SUCCESS handling "+cmd);
181 }
182
187 inline bool
189 {
190 return getLog()
191 .verifyMatch("TestNexus.+HANDLING Command-Message for .+" +cmd)
192 .beforeCall("exec-command").on("TestNexus").arg(cmd)
193 .beforeCall("operate")
194 .beforeEvent("TestNexus", "SUCCESS handling "+cmd);
195 }
196
197
198
199}} // namespace stage::test
200#endif /*STAGE_TEST_TEST_NEXUS_H*/
Attachment point to the UI-Bus.
Token or Atom with distinct identity.
Definition symbol.hpp:120
type erased baseclass for building a combined hash and symbolic ID.
Definition entry-id.hpp:134
Helper to log and verify the occurrence of events.
EventMatch verifyMatch(string regExp) const
start a query to match with a regular expression
EventMatch & arg(ARGS const &...args)
refine filter to additionally require specific arguments
EventMatch & beforeEvent(string match)
find a match for an "event" after the current point of reference
EventMatch & on(string targetID)
refine filter to additionally match the ‘'this’` attribute
EventMatch & beforeCall(string match)
find a match for some function invocation after the current point of reference
connection point at the UI-Bus.
Definition bus-term.hpp:98
Interface: handling of persistent interface state.
Mock UI backbone for unit testing.
static size_t size()
static ctrl::BusTerm & testUI()
get a connection point to a UI backbone faked for test
static void prepareDiagnosticCommandHandler()
std::function< void(lib::idi::BareEntryID const &, lib::diff::GenNode const &)> StateMarkHandler
static void zombificate(ctrl::BusTerm &)
kill the given [BusTerm] and implant a dead terminal in place
static ctrl::StateManager & getMockStateManager()
std::function< void(lib::diff::GenNode const &)> CommandHandler
static void setStateMarkHandler(StateMarkHandler=StateMarkHandler())
similar to the custom command handler this hook allows to install a closure to intercept any "state m...
static void setCommandHandler(CommandHandler=CommandHandler())
install a closure (custom handler function) to deal with any command invocations encountered in the t...
static bool wasInvoked(Symbol)
Test predicate: verify at least one actual invocation happened for the given commend,...
static Symbol prepareMockCmd()
Setup of test fixture: prepare a mocked Steam-Layer command, which accepts arguments with the denoted...
static lib::test::EventLog const & getLog()
static ctrl::StateManager & useMockStateManager()
install a standard handler for state mark messages, which is actually backed by a mock implementation...
static lib::test::EventLog const & startNewLog()
static bool wasBound(Symbol, ARGS const &...args)
Test predicate: verify by string match that the denoted command was actually bound against the given ...
static steam::control::Command fabricateNewInstance(lib::test::EventLog const &invocationLog)
Symbol getID() const noexcept
Definition command.cpp:366
Any copy and copy construction prohibited.
Definition nocopy.hpp:38
Lumiera error handling (C++ interface).
Support for verifying the occurrence of events from unit tests.
Generic building block for tree shaped (meta)data structures.
Lumiera GTK UI implementation root.
Definition guifacade.cpp:37
Test runner and basic definitions for tests.
std::string toString(TY const &val) noexcept
get some string representation of any object, reliably.
Mix-Ins to allow or prohibit various degrees of copying and cloning.
Generate fake commands with stub operations and the ability to verify invocation.
Interface: a component to maintain persistent interface state.
generic data element node within a tree
Definition gen-node.hpp:224
Abstraction: a tangible element of the User Interface.