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) Lumiera.org
5  2015, Hermann Vosseler <Ichthyostega@web.de>
6 
7  This program is free software; you can redistribute it and/or
8  modify it under the terms of the GNU General Public License as
9  published by the Free Software Foundation; either version 2 of
10  the License, or (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 
21 */
22 
23 
44 #ifndef STAGE_TEST_TEST_NEXUS_H
45 #define STAGE_TEST_TEST_NEXUS_H
46 
47 
48 #include "lib/error.hpp"
49 #include "lib/nocopy.hpp"
50 #include "stage/ctrl/bus-term.hpp"
51 #include "stage/model/tangible.hpp"
54 #include "lib/test/event-log.hpp"
55 #include "lib/diff/gen-node.hpp"
56 
57 #include <functional>
58 #include <string>
59 
60 
61 namespace stage {
62 namespace test{
63 
64 
76  class Nexus
78  {
79 
80  public:
82  static ctrl::BusTerm& testUI();
83 
85  static void zombificate(ctrl::BusTerm&);
86 
87  static lib::test::EventLog const& getLog();
88  static lib::test::EventLog const& startNewLog();
89 
90  static size_t size();
91 
92 
93  /* == allow to set custom handlers for commands and state changes == */
94 
95  using CommandHandler = std::function<void(lib::diff::GenNode const&)>;
96  using StateMarkHandler = std::function<void(lib::idi::BareEntryID const&, lib::diff::GenNode const&)>;
97 
98  static void setCommandHandler (CommandHandler =CommandHandler());
99  static void setStateMarkHandler (StateMarkHandler =StateMarkHandler());
100 
101 
103  static ctrl::StateManager& getMockStateManager();
104 
105 
106  template<typename...ARGS>
107  static Symbol prepareMockCmd();
108 
109  static bool wasInvoked (Symbol);
110 
111  template<typename...ARGS>
112  static bool wasBound (Symbol, ARGS const& ...args);
113 
114  template<typename...ARGS>
115  static bool wasInvoked (Symbol, ARGS const& ...args);
116 
117  private:
118  static void prepareDiagnosticCommandHandler();
119  };
120 
121 
122 
133  template<typename...ARGS>
134  inline Symbol
136  {
137  prepareDiagnosticCommandHandler();
139  .getID();
140  }
141 
142 
157  template<typename...ARGS>
158  inline bool
159  Nexus::wasBound (Symbol cmd, ARGS const& ...args)
160  {
161  using lib::diff::DataCap;
162 
163  return getLog()
164  .verifyMatch("TestNexus.+HANDLING Command-Message for .+" +cmd)
165  .beforeCall("bind-command").on("TestNexus")
166  .arg(string(DataCap(args))...);
167  }
168 
180  template<typename...ARGS>
181  inline bool
182  Nexus::wasInvoked (Symbol cmd, ARGS const& ...args)
183  {
184  return getLog()
185  .verifyMatch("TestNexus.+HANDLING Command-Message for .+" +cmd)
186  .beforeCall("exec-command").on("TestNexus").arg(cmd)
187  .beforeCall("exec").on("MockHandlingPattern")
188  .beforeCall("operate").arg(util::toString(args)...)
189  .beforeEvent("TestNexus", "SUCCESS handling "+cmd);
190  }
191 
196  inline bool
198  {
199  return getLog()
200  .verifyMatch("TestNexus.+HANDLING Command-Message for .+" +cmd)
201  .beforeCall("exec-command").on("TestNexus").arg(cmd)
202  .beforeCall("operate")
203  .beforeEvent("TestNexus", "SUCCESS handling "+cmd);
204  }
205 
206 
207 
208 }} // namespace stage::test
209 #endif /*STAGE_TEST_TEST_NEXUS_H*/
Abstraction: a tangible element of the User Interface.
connection point at the UI-Bus.
Definition: bus-term.hpp:105
Mock UI backbone for unit testing.
Definition: test-nexus.hpp:76
Support for verifying the occurrence of events from unit tests.
Definition: run.hpp:49
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:417
Any copy and copy construction prohibited.
Definition: nocopy.hpp:46
EventMatch & beforeCall(string match)
find a match for some function invocation after the current point of reference
Definition: event-log.cpp:447
Interface: a component to maintain persistent interface state.
Helper to log and verify the occurrence of events.
Definition: event-log.hpp:284
EventMatch & arg(ARGS const &...args)
refine filter to additionally require specific arguments
Definition: event-log.hpp:207
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:135
Attachment point to the UI-Bus.
Token or Atom with distinct identity.
Definition: symbol.hpp:126
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:562
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:426
Lumiera GTK UI implementation root.
Definition: guifacade.cpp:46
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:197
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:159
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:428
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:593
Lumiera error handling (C++ interface).
static ctrl::BusTerm & testUI()
get a connection point to a UI backbone faked for test
Definition: test-nexus.cpp:375
EventMatch verifyMatch(string regExp) const
start a query to match with a regular expression
Definition: event-log.cpp:770
EventMatch & on(string targetID)
refine filter to additionally match the &#39;this&#39; attribute
Definition: event-log.cpp:592