From 2d8a595038015b6afc23d0d86214377bb6e01284 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Tue, 4 Oct 2016 03:50:44 +0200 Subject: [PATCH] Finish AbstractTangible_test and the basic UI-Element protocol closes #975 and #992 --- src/gui/ctrl/bus-controller.cpp | 3 +- src/gui/ctrl/bus-term.hpp | 10 +++ src/gui/model/tangible.hpp | 12 ++- tests/51-gui-model.tests | 2 +- tests/gui/abstract-tangible-test.cpp | 128 ++++++++++++++++++++++----- tests/gui/test/mock-elm.hpp | 25 +++++- 6 files changed, 149 insertions(+), 31 deletions(-) diff --git a/src/gui/ctrl/bus-controller.cpp b/src/gui/ctrl/bus-controller.cpp index a17802663..1b0d6e8d1 100644 --- a/src/gui/ctrl/bus-controller.cpp +++ b/src/gui/ctrl/bus-controller.cpp @@ -211,7 +211,8 @@ namespace ctrl { void BusTerm::routeDetach(ID node) noexcept { - theBus_.routeDetach (node); + if (isConnected()) + theBus_.routeDetach (node); } diff --git a/src/gui/ctrl/bus-term.hpp b/src/gui/ctrl/bus-term.hpp index 38e21b4ef..f3e729ac3 100644 --- a/src/gui/ctrl/bus-term.hpp +++ b/src/gui/ctrl/bus-term.hpp @@ -136,6 +136,8 @@ namespace ctrl{ virtual BusTerm& routeAdd(ID,Tangible&); virtual void routeDetach(ID) noexcept; + + bool isConnected() const noexcept; }; @@ -148,6 +150,14 @@ namespace ctrl{ theBus_.note (this->endpointID_, mark); } + /** @internal tie break */ + inline bool + BusTerm::isConnected() const noexcept + { + return &theBus_ != this; + } + + }} // namespace gui::ctrl #endif /*GUI_CTRL_BUS_TERM_H*/ diff --git a/src/gui/model/tangible.hpp b/src/gui/model/tangible.hpp index a7147080f..1f9a6a4c8 100644 --- a/src/gui/model/tangible.hpp +++ b/src/gui/model/tangible.hpp @@ -214,7 +214,17 @@ namespace model { public: virtual void buildMutator (lib::diff::TreeMutator::Handle) =0; - private: + + + /** override default size traits for diff application. + * @remarks this value here is hard coded, base on what + * can be expected for diff application to UI elements. + */ + friend constexpr size_t + treeMutatorSize (const Tangible*) + { + return 256; + } }; diff --git a/tests/51-gui-model.tests b/tests/51-gui-model.tests index fc76131a0..e4df756ef 100644 --- a/tests/51-gui-model.tests +++ b/tests/51-gui-model.tests @@ -7,7 +7,7 @@ return: 0 END -PLANNED "the abstracted tangible UI element" AbstractTangible_test <>Scope>> b") // recursively mutate second child + .beforeEvent("diff","++Attib++ π = 3.1415927")); // insert new attribute π within nested scope + + + CHECK (nexusLog.verifyCall("routeAdd").arg(rootMock.getID(), memLocation(rootMock)) // rootMock was attached to Nexus + .beforeCall("change") .argMatch(rootMock.getID(), + "after.+ins.+ins.+set.+mut.+ins.+emu") // diff message sent via UI-Bus + .beforeCall("routeAdd").arg(childA.getID(), memLocation(childA)) // first new child was attached to Nexus + .beforeCall("routeAdd").arg(childB.getID(), memLocation(childB)) // second new child was attached to Nexus + .beforeEvent("applied diff to "+string(rootMock.getID())) + ); + cout << "____Event-Log_________________\n" << util::join(rootMock.getLog(), "\n") << "\n───╼━━━━━━━━━╾────────────────"<getID() == diffSrc.CHILD_1.idi); // children have the expected IDs - CHECK (rootMock.scope[1]->getID() == diffSrc.CHILD_2.idi); - CHECK (rootMock.scope[1]->attrib["π"] == "3.1415927"); // and the second child got attribute Pi + } + + + + static string + memLocation (Tangible& uiElm) + { + return lib::idi::instanceTypeID (&uiElm); } }; diff --git a/tests/gui/test/mock-elm.hpp b/tests/gui/test/mock-elm.hpp index 19bbf2289..374e70fc6 100644 --- a/tests/gui/test/mock-elm.hpp +++ b/tests/gui/test/mock-elm.hpp @@ -239,6 +239,9 @@ namespace test{ using lib::diff::collection; using lib::diff::render; ///////////TICKET #1009 + log_.call (this->identify(), "buildMutator"); + cout << this->identify() << " <-- DIFF" < PMockElm { - return std::make_unique(spec.idi, this->uiBus_); // create a child element wired via this Element's BusTerm + log_.event("diff", "create child \""+spec.idi.getSym()+"\""); + PMockElm child = std::make_unique(spec.idi, this->uiBus_); + child->joinLog(*this); // create a child element wired via this Element's BusTerm + return child; }) .buildChildMutator ([&](PMockElm& target, GenNode::ID const& subID, TreeMutator::Handle buff) -> bool { if (target->getID() != subID) return false; //require match on already existing child object target->buildMutator (buff); // delegate to child to build nested TreeMutator + log_.event("diff", ">>Scope>> "+subID.getSym()); return true; })) .attach (collection(attrib) .isApplicableIf ([&](GenNode const& spec) -> bool { - return spec.isNamed(); // »Selector« : accept anything attribute-like + return spec.isNamed() // »Selector« : accept attribute-like values + and not spec.data.isNested(); // but no nested objects }) .matchElement ([&](GenNode const& spec, Attrib const& elm) -> bool { @@ -271,15 +279,24 @@ namespace test{ }) .constructFrom ([&](GenNode const& spec) -> Attrib { - return {spec.idi.getSym(), render(spec.data)}; + string key{spec.idi.getSym()}, + val{render(spec.data)}; + log_.event("diff", "++Attib++ "+key+" = "+val); + return {key, val}; }) .assignElement ([&](Attrib& target, GenNode const& spec) -> bool { - target.second = render (spec.data); + string key{spec.idi.getSym()}, + newVal{render (spec.data)}; + log_.event("diff", "set Attib "+key+" <-"+newVal); + target.second = newVal; return true; }))); + + log_.event ("diff", getID().getSym() +" accepts mutation..."); } + protected: string identify() const