From 8cd31443b1a6f153c6479dd3600b7d4e0d36f14e Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Sat, 26 Dec 2015 20:41:24 +0100 Subject: [PATCH] invent a suicidal zombie terminal yeah, it's X-mas time, letz build a diagnostic network of deceased widgets... --- tests/gui/abstract-tangible-test.cpp | 4 +- tests/gui/test/mock-elm.hpp | 40 +++++++++++++- tests/gui/test/test-nexus.cpp | 83 +++++++++++++++++++++++++++- tests/gui/test/test-nexus.hpp | 5 +- 4 files changed, 124 insertions(+), 8 deletions(-) diff --git a/tests/gui/abstract-tangible-test.cpp b/tests/gui/abstract-tangible-test.cpp index 99441382c..affa3e4ae 100644 --- a/tests/gui/abstract-tangible-test.cpp +++ b/tests/gui/abstract-tangible-test.cpp @@ -195,8 +195,8 @@ namespace test { mock.kill(); foo.markMsg("dummy killed"); - CHECK (log.verifyEvent("dtor").on("dummy") - .beforeCall("noteMsg").on("foo")); + CHECK (log.verifyEvent("destroy","dummy") + .beforeCall("doMsg").on("foo")); } diff --git a/tests/gui/test/mock-elm.hpp b/tests/gui/test/mock-elm.hpp index 90fc49a0b..7cdd0e319 100644 --- a/tests/gui/test/mock-elm.hpp +++ b/tests/gui/test/mock-elm.hpp @@ -182,20 +182,54 @@ namespace test{ MockElm(ID identity, ctrl::BusTerm& nexus =Nexus::testUI()) : gui::model::Tangible(identity, nexus) { - log_.call(this->identify(), "ctor", identity, string(nexus)); - log_.create(getID().getSym()); + log_.call (this->identify(), "ctor", identity, string(nexus)); + log_.create (getID().getSym()); } + /** document our death in the diagnostic log. */ + ~MockElm() + { + try { + log_.call (this->identify(), "dtor"); + log_.destroy (getID().getSym()); + } + catch(...) + { + const char* errID = lumiera_error(); + if (errID) + cerr << "Error while logging shutdown of Mock-UI-Element: " << errID <identify(), "kill"); + log_.destroy (getID().getSym()); + + Nexus::zombificate (this->uiBus_); + log_.event ("successfully connected to zombie bus"); } + + /* ==== Query/Verification API ==== */ ID getID() const diff --git a/tests/gui/test/test-nexus.cpp b/tests/gui/test/test-nexus.cpp index 443a02054..8761bd329 100644 --- a/tests/gui/test/test-nexus.cpp +++ b/tests/gui/test/test-nexus.cpp @@ -52,6 +52,7 @@ using std::string; //using lib::idi::EntryID; using lib::diff::GenNode; +using gui::ctrl::BusTerm; //using util::contains; //using util::isnil; @@ -86,8 +87,8 @@ namespace test{ { UNIMPLEMENTED ("receive and handle presentation state note messages."); } - - + + virtual operator string() const { return lib::idi::instanceTypeID(this); @@ -99,6 +100,69 @@ namespace test{ { } }; + + /** + * @internal a defunct interface backbone. + * All UI-Bus operations are implemented NOP, but warning on STDRR + * and logging the invocation to the internal log of [TestNexus]. + * This allows to set up deceased entities within a test rigged UI. + */ + class ZombieNexus + : public BusTerm + { + + /* ==== defunct re-implementation of the BusTerm interface ==== */ + + virtual void + act (GenNode const& command) + { + UNIMPLEMENTED("act"); + } + + + virtual void + note (ID subject, GenNode const& mark) override + { + UNIMPLEMENTED ("note."); + } + + + virtual void + mark (ID subject, GenNode const& mark) override + { + UNIMPLEMENTED ("mark."); + } + + + virtual operator string() const + { + return lib::idi::instanceTypeID(this); + } + + + virtual BusTerm& + routeAdd (ID identity, Tangible& newNode) override + { + UNIMPLEMENTED ("routeAdd."); + } + + + virtual void + routeDetach (ID node) noexcept override + { + UNIMPLEMENTED ("routeDetach."); + } + + public: + /** fabricate a "dead terminal", marked as deceased. + * @note intentionally to be sliced right after generation. + * All operations on this object are defunct. + */ + ZombieNexus(string formerID) + : BusTerm(lib::idi::EntryID("defunct-"+formerID), *this) + { } + }; + lib::Depend testNexus; } // internal details @@ -119,5 +183,20 @@ namespace test{ { return testNexus(); } + + + /** + * @return a defunct BusTerm with up-link to [ZombieNexus] + * @remarks useful to create zombie mock UI-Elements for testing. + */ + void + Nexus::zombificate (BusTerm& doomed) + { + string lateName = doomed.getID().getSym(); + doomed.~BusTerm(); +// log_.destroy (lateName); + + new(&doomed) ZombieNexus{lateName}; + } }} // namespace gui::test diff --git a/tests/gui/test/test-nexus.hpp b/tests/gui/test/test-nexus.hpp index 7a08c3b0e..9640ffdc1 100644 --- a/tests/gui/test/test-nexus.hpp +++ b/tests/gui/test/test-nexus.hpp @@ -50,7 +50,7 @@ //#include "lib/diff/record.hpp" #include -//#include +#include namespace gui { @@ -78,6 +78,9 @@ namespace test{ public: /** get a connection point to a UI backbone faked for test */ static ctrl::BusTerm& testUI(); + + /** kill the given [BusTerm] and implant a dead terminal in place */ + static void zombificate(ctrl::BusTerm&); };