Lumiera  0.pre.03
»edit your freedom«
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"
41 #include "stage/ctrl/bus-term.hpp"
42 #include "stage/model/tangible.hpp"
45 #include "lib/test/event-log.hpp"
46 #include "lib/diff/gen-node.hpp"
47 
48 #include <functional>
49 #include <string>
50 
51 
52 namespace stage {
53 namespace 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 
89  static void setCommandHandler (CommandHandler =CommandHandler());
90  static void setStateMarkHandler (StateMarkHandler =StateMarkHandler());
91 
92 
94  static ctrl::StateManager& getMockStateManager();
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:
109  static void prepareDiagnosticCommandHandler();
110  };
111 
112 
113 
124  template<typename...ARGS>
125  inline Symbol
127  {
128  prepareDiagnosticCommandHandler();
130  .getID();
131  }
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*/
Abstraction: a tangible element of the User Interface.
connection point at the UI-Bus.
Definition: bus-term.hpp:96
Mock UI backbone for unit testing.
Definition: test-nexus.hpp:67
Support for verifying the occurrence of events from unit tests.
Definition: run.hpp:40
static void setCommandHandler(CommandHandler=CommandHandler())
install a closure (custom handler function) to deal with any command invocations encountered in the t...
Definition: test-nexus.cpp:408
Any copy and copy construction prohibited.
Definition: nocopy.hpp:37
EventMatch & beforeCall(string match)
find a match for some function invocation after the current point of reference
Definition: event-log.cpp:438
Interface: a component to maintain persistent interface state.
Helper to log and verify the occurrence of events.
Definition: event-log.hpp:275
EventMatch & arg(ARGS const &...args)
refine filter to additionally require specific arguments
Definition: event-log.hpp:198
Generate fake commands with stub operations and the ability to verify invocation. ...
static Symbol prepareMockCmd()
Setup of test fixture: prepare a mocked Steam-Layer command, which accepts arguments with the denoted...
Definition: test-nexus.hpp:126
Attachment point to the UI-Bus.
Token or Atom with distinct identity.
Definition: symbol.hpp:117
Set of stub command operations.
static ctrl::StateManager & useMockStateManager()
install a standard handler for state mark messages, which is actually backed by a mock implementation...
Definition: test-nexus.cpp:553
Mix-Ins to allow or prohibit various degrees of copying and cloning.
EventMatch & beforeEvent(string match)
find a match for an "event" after the current point of reference
Definition: event-log.cpp:417
Lumiera GTK UI implementation root.
Definition: guifacade.cpp:37
static bool wasInvoked(Symbol)
Test predicate: verify at least one actual invocation happened for the given commend, without matching any concrete arguments.
Definition: test-nexus.hpp:188
static bool wasBound(Symbol, ARGS const &...args)
Test predicate: verify by string match that the denoted command was actually bound against the given ...
Definition: test-nexus.hpp:150
Generic building block for tree shaped (meta)data structures.
static void setStateMarkHandler(StateMarkHandler=StateMarkHandler())
similar to the custom command handler this hook allows to install a closure to intercept any "state m...
Definition: test-nexus.cpp:419
Interface: handling of persistent interface state.
static void zombificate(ctrl::BusTerm &)
kill the given [BusTerm] and implant a dead terminal in place
Definition: test-nexus.cpp:584
Lumiera error handling (C++ interface).
static ctrl::BusTerm & testUI()
get a connection point to a UI backbone faked for test
Definition: test-nexus.cpp:366
EventMatch verifyMatch(string regExp) const
start a query to match with a regular expression
Definition: event-log.cpp:761
EventMatch & on(string targetID)
refine filter to additionally match the &#39;this&#39; attribute
Definition: event-log.cpp:583