invent a suicidal zombie terminal

yeah, it's X-mas time,
letz build a diagnostic network of deceased widgets...
This commit is contained in:
Fischlurch 2015-12-26 20:41:24 +01:00
parent f23b482d7d
commit 8cd31443b1
4 changed files with 124 additions and 8 deletions

View file

@ -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"));
}

View file

@ -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 <<endl;
else
cerr << "Unknown Error while logging shutdown of Mock-UI-Element." <<endl;
}
}
/* ==== special operations API ==== */
/** commit suicide.
* @warning admittedly a wonky operation
* @remarks here the mock emulates the act of dying,
* by snuffing the UI-Bus connection sneakily.
* We leave the dead corpse hanging around,
* just for sake of further investigation,
* of course.
*/
void
kill()
{
UNIMPLEMENTED ("suicide");
log_.call (this->identify(), "kill");
log_.destroy (getID().getSym());
Nexus::zombificate (this->uiBus_);
log_.event ("successfully connected to zombie bus");
}
/* ==== Query/Verification API ==== */
ID getID() const

View file

@ -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<ZombieNexus>("defunct-"+formerID), *this)
{ }
};
lib::Depend<TestNexus> 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

View file

@ -50,7 +50,7 @@
//#include "lib/diff/record.hpp"
#include <boost/noncopyable.hpp>
//#include <string>
#include <string>
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&);
};