From 540151b56b01b5ef94cfddce025e934be36ca7b1 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Sun, 3 Jan 2016 03:23:39 +0100 Subject: [PATCH] provide a mock handler for commands and state marks in the real system, this will be the task of the CoreService, while here, in test mode, we allow to install handling closures from the unit-test-code --- src/gui/ctrl/nexus.hpp | 4 ++ src/lib/test/event-log.hpp | 10 +-- tests/gui/bus-term-test.cpp | 9 +-- tests/gui/test/test-nexus.cpp | 114 ++++++++++++++++++++++++++++------ tests/gui/test/test-nexus.hpp | 12 ++++ 5 files changed, 121 insertions(+), 28 deletions(-) diff --git a/src/gui/ctrl/nexus.hpp b/src/gui/ctrl/nexus.hpp index b99d604ec..3f0c7b08e 100644 --- a/src/gui/ctrl/nexus.hpp +++ b/src/gui/ctrl/nexus.hpp @@ -103,8 +103,12 @@ namespace ctrl{ /** add a new down-link connection to the routing table * @param identity the [endpoint-ID](\ref BusTerm::endpointID_) used * to address the new element to be connected to the bus. + * @param newNode to add the address (!) into the routing table * @return backlink for the new Tangible's BusTerm to * attach itself to the Nexus. + * @note at call time, the second param, the newNode will typically + * be just a Tangible (and not a subclass yet), + * since this function is invoked from ctor. */ virtual BusTerm& routeAdd (ID identity, Tangible& newNode) override diff --git a/src/lib/test/event-log.hpp b/src/lib/test/event-log.hpp index 9eb22c2c4..4f822399c 100644 --- a/src/lib/test/event-log.hpp +++ b/src/lib/test/event-log.hpp @@ -193,6 +193,7 @@ namespace test{ or entry.getType() == "destroy" or entry.getType() == "logJoin" ) + and !isnil(entry.scope()) and contains (*entry.scope(), match); }; } @@ -210,6 +211,7 @@ namespace test{ or entry.getType() == classifier or (entry.hasAttribute("ID") and contains (entry.get("ID"), classifier)) ) + and !isnil(entry.scope()) and contains (*entry.scope(), match); }; } @@ -682,9 +684,9 @@ namespace test{ EventLog& event (string text) { - log({"type=event", text}); - return *this; - } + log ("event", ArgSeq{}, ArgSeq{text}); // we use this ctor variant to ensure + return *this; // that text is not misinterpreted as attribute, + } // which might happen when text contains a '=' /** log some event, with additional ID or classifier * @param classifier info to be saved into the `ID` attribute @@ -693,7 +695,7 @@ namespace test{ EventLog& event (string classifier, string text) { - log({"type=event", "ID="+classifier, text}); + log ("event", ArgSeq{"ID="+classifier}, ArgSeq{text}); return *this; } diff --git a/tests/gui/bus-term-test.cpp b/tests/gui/bus-term-test.cpp index e27ae5b56..b6b3e0235 100644 --- a/tests/gui/bus-term-test.cpp +++ b/tests/gui/bus-term-test.cpp @@ -36,6 +36,7 @@ //#include using lib::idi::EntryID; +using lib::idi::BareEntryID; using gui::test::MockElm; using lib::diff::GenNode; //using boost::lexical_cast; @@ -111,14 +112,14 @@ namespace test { attachNewBusTerm () { // our dummy will be linked with this identity - EntryID elmID{"zeitgeist"}; + BareEntryID elmID = EntryID{"zeitgeist"}; // Access the log on the Test-Nexus hub EventLog nexusLog = gui::test::Nexus::startNewLog(); CHECK (nexusLog.ensureNot("zeitgeist")); MockElm mock(elmID); - CHECK (nexusLog.verifyCall("routeAdd").on("TestNexus").arg(elmID,"MockElm") + CHECK (nexusLog.verifyCall("routeAdd").on("TestNexus").arg(elmID,"Tangible") // Note: invoked from ctor, so it is just a tangible at the moment .beforeEvent("TestNexus", "added route to bID-zeitgeist")); EventLog elmLog = mock.getLog(); @@ -135,7 +136,7 @@ namespace test { // invoke action on element to cause upstream message (with a "state mark") mock.slotCollapse(); CHECK (elmLog.verifyEvent("collapsed")); - CHECK (nexusLog.verifyCall("note").on("TestNexus").arg("zeitgeist", "collapse")); + CHECK (nexusLog.verifyCall("note").on("TestNexus").arg(elmID, "collapse")); // send a state mark down to the mock element gui::test::Nexus::testUI().mark (elmID, GenNode("Flash", 23)); @@ -159,7 +160,7 @@ namespace test { cout << "____Probe-Log_________________\n" - << util::join(mock.getLog(), "\n") + << util::join(elmLog, "\n") << "\n───╼━━━━━━━━━╾────────────────"<("mock-UI")) - { } + { + installCommandHandler(); + installStateMarkHandler(); + } // standard copy operations @@ -190,6 +200,33 @@ namespace test{ { return log_; } + + void + installCommandHandler (CommandHandler newHandler =CommandHandler()) + { + if (newHandler) + commandHandler_ = newHandler; + else + commandHandler_ = + [=](GenNode const& cmd) + { + log_.warn(_Fmt("NOT handling command-message %s in test-mode") % cmd); + }; + } + + void + installStateMarkHandler (StateMarkHandler newHandler =StateMarkHandler()) + { + if (newHandler) + stateMarkHandler_ = newHandler; + else + stateMarkHandler_ = + [=](ID subject, GenNode const& mark) + { + log_.warn(_Fmt("NOT handling state-mark %s passed from %s in test-mode") + % mark % subject); + }; + } }; /** singleton instance of the [TestNexus] @@ -198,6 +235,7 @@ namespace test{ + /** * @internal a defunct interface backbone. * All UI-Bus operations are implemented NOP, but warning on STDRR @@ -244,11 +282,6 @@ namespace test{ cerr << "mark message -> ZombieNexus" < ZombieNexus" < +#include #include @@ -81,6 +84,15 @@ namespace test{ static lib::test::EventLog const& getLog(); static lib::test::EventLog const& startNewLog(); + + + /* == allow to set custom handlers for commands and state changes == */ + + using CommandHandler = std::function; + using StateMarkHandler = std::function; + + static void setCommandHandler (CommandHandler =CommandHandler()); + static void setStateMarkHandler (StateMarkHandler =StateMarkHandler()); };