From 4d1fcd6dcb735aa6323612342b465d1b6a361feb Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Fri, 25 Dec 2015 00:41:14 +0100 Subject: [PATCH] implement logging/identification of mock UI elements --- src/gui/ctrl/bus-controller.cpp | 8 +++++++- src/gui/ctrl/bus-term.hpp | 2 ++ src/gui/ctrl/nexus.hpp | 8 ++++++++ src/lib/idi/entry-id.hpp | 21 +++++++++++++++++---- tests/gui/abstract-tangible-test.cpp | 3 ++- tests/gui/test/mock-elm.hpp | 16 +++++++++++++--- tests/gui/test/test-nexus.cpp | 11 +++++++++-- 7 files changed, 58 insertions(+), 11 deletions(-) diff --git a/src/gui/ctrl/bus-controller.cpp b/src/gui/ctrl/bus-controller.cpp index f4b5c2f17..2398eb131 100644 --- a/src/gui/ctrl/bus-controller.cpp +++ b/src/gui/ctrl/bus-controller.cpp @@ -176,7 +176,13 @@ namespace ctrl { { theBus_.routeDetach (node); } - + + + BusTerm::operator string() const + { + return "BusTerm-" + string(endpointID_); + } + }} // namespace gui::ctrl diff --git a/src/gui/ctrl/bus-term.hpp b/src/gui/ctrl/bus-term.hpp index e3847ff80..2237d82fc 100644 --- a/src/gui/ctrl/bus-term.hpp +++ b/src/gui/ctrl/bus-term.hpp @@ -110,6 +110,8 @@ namespace ctrl{ virtual void note (ID subject, GenNode const& mark); virtual void mark (ID subject, GenNode const& mark); + virtual operator string() const; + void note (GenNode const& mark); ID getID() const { return endpointID_; } diff --git a/src/gui/ctrl/nexus.hpp b/src/gui/ctrl/nexus.hpp index 0129e3d62..2890b63dc 100644 --- a/src/gui/ctrl/nexus.hpp +++ b/src/gui/ctrl/nexus.hpp @@ -40,6 +40,7 @@ #include "lib/error.hpp" //#include "lib/idi/entry-id.hpp" +#include "lib/idi/genfunc.hpp" #include "gui/ctrl/bus-term.hpp" #include "gui/model/tangible.hpp" //#include "lib/util.hpp" @@ -121,6 +122,13 @@ namespace ctrl{ routingTable_.erase (node); } + + virtual operator string() const + { + return lib::idi::instanceTypeID(this); + } + + public: explicit Nexus (BusTerm& uplink_to_CoreService, ID identity =lib::idi::EntryID()) diff --git a/src/lib/idi/entry-id.hpp b/src/lib/idi/entry-id.hpp index f11c0d5dc..2ad062f5f 100644 --- a/src/lib/idi/entry-id.hpp +++ b/src/lib/idi/entry-id.hpp @@ -174,6 +174,8 @@ namespace idi { return hash_; } + operator string() const; + /** using BareEntryID derived objects as keys within tr1::unordered_map */ struct UseEmbeddedHash @@ -252,10 +254,7 @@ namespace idi { } - operator string () const - { - return "ID<"+typeSymbol()+">-"+EntryID::getSym(); - } + operator string() const; friend ostream& operator<< (ostream& os, EntryID const& id) { return os << string(id); } friend bool operator< (EntryID const& i1, EntryID const& i2) { return i1.getSym() < i2.getSym(); } @@ -290,6 +289,20 @@ namespace idi { } + inline + BareEntryID::operator string() const + { + return "bID-"+lib::idi::format::instance_hex_format(symbol_, hash_); + } + + template + inline + EntryID::operator string() const + { + return "ID<"+typeSymbol()+">-"+EntryID::getSym(); + } + + }} // namespace lib::idi #endif /*LIB_IDI_ENTRY_ID_H*/ diff --git a/tests/gui/abstract-tangible-test.cpp b/tests/gui/abstract-tangible-test.cpp index 8ac433ed7..6c1cdad1f 100644 --- a/tests/gui/abstract-tangible-test.cpp +++ b/tests/gui/abstract-tangible-test.cpp @@ -131,7 +131,7 @@ namespace test { CHECK (mock.verify("ctor")); CHECK (mock.verifyEvent("create","dummy")); - CHECK (mock.verify("ctor").arg("dummy").on(&mock)); + CHECK (mock.verify("ctor").arg("dummy","TestNexus").on(&mock)); CHECK ("dummy" == mock.getID().getSym()); CHECK (EntryID("dummy") == mock.getID()); @@ -141,6 +141,7 @@ namespace test { mock.reset(); CHECK (mock.verify("reset")); CHECK (mock.verifyCall("reset")); + CHECK (mock.verifyCall("reset").on(&mock)); CHECK (mock.verifyCall("reset").on("dummy")); CHECK (mock.verifyEvent("reset")); CHECK (mock.verify("reset").after("ctor")); diff --git a/tests/gui/test/mock-elm.hpp b/tests/gui/test/mock-elm.hpp index 501d03336..65b863c9c 100644 --- a/tests/gui/test/mock-elm.hpp +++ b/tests/gui/test/mock-elm.hpp @@ -48,6 +48,7 @@ #include "lib/test/event-log.hpp" #include "gui/model/tangible.hpp" #include "lib/diff/record.hpp" +#include "lib/idi/genfunc.hpp" #include "test/test-nexus.hpp" #include @@ -86,13 +87,15 @@ namespace test{ EventLog log_{this}; + bool virgin_{true}; + /* ==== Tangible interface ==== */ virtual void doReset() override { - log_.call(this, "reset"); - // _Par::doReset(); + log_.call(this->identify(), "reset"); + virgin_ = true; log_.event("reset"); } @@ -128,6 +131,13 @@ namespace test{ protected: + string + identify() const + { + return lib::idi::instanceTypeID(this) +"-"+getID().getSym(); + } + + public: explicit MockElm(string id) @@ -138,7 +148,7 @@ namespace test{ MockElm(ID identity, ctrl::BusTerm& nexus =Nexus::testUI()) : gui::model::Tangible(identity, nexus) { - log_.call(this, "ctor", identity, nexus); + log_.call(this->identify(), "ctor", identity, string(nexus)); log_.create(getID().getSym()); } diff --git a/tests/gui/test/test-nexus.cpp b/tests/gui/test/test-nexus.cpp index 502109400..443a02054 100644 --- a/tests/gui/test/test-nexus.cpp +++ b/tests/gui/test/test-nexus.cpp @@ -40,14 +40,15 @@ #include "gui/ctrl/nexus.hpp" #include "lib/diff/gen-node.hpp" #include "lib/idi/entry-id.hpp" +#include "lib/idi/genfunc.hpp" #include "lib/depend.hpp" //#include -//#include +#include //#include //using std::map; -//using std::string; +using std::string; //using lib::idi::EntryID; using lib::diff::GenNode; @@ -85,6 +86,12 @@ namespace test{ { UNIMPLEMENTED ("receive and handle presentation state note messages."); } + + + virtual operator string() const + { + return lib::idi::instanceTypeID(this); + } public: TestNexus()