From 1ab42b298d66c095a9085de60fe2203d370ff9fa Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Sat, 1 Sep 2018 15:42:36 +0200 Subject: [PATCH] UiElement: add unit test to cover the doRevealYourself functionality ...which is now kind-of specified and we're providing a default implementation, so it should be documented in AbstractTangible_test --- tests/gui/abstract-tangible-test.cpp | 83 ++++++++++++++++++++++++++-- 1 file changed, 77 insertions(+), 6 deletions(-) diff --git a/tests/gui/abstract-tangible-test.cpp b/tests/gui/abstract-tangible-test.cpp index 7e1f178dd..735b14c18 100644 --- a/tests/gui/abstract-tangible-test.cpp +++ b/tests/gui/abstract-tangible-test.cpp @@ -179,8 +179,9 @@ namespace test { verify_mockManipulation(); invokeCommand(); markState(); - notify(); - mutate(); + revealer(); +// notify(); +// mutate(); } @@ -362,10 +363,6 @@ namespace test { * * The second part of this test _replays_ such a state mark, which causes * the`doMark()` operation on the UI element to be invoked. - * @todo maybe we'll even provide a default implementation for expand/collapse - * which then means that, by replaying the mentioned state marks, the - * `doExpand()` or `doCollapse()` should be re-invoked, of course - * without issuing a further notification * @note this test does not cover or even emulate the operation of the * "state manager", since the goal is to cover the _UI element_ * protocol. We'll just listen at the bus and replay messages. @@ -473,6 +470,80 @@ namespace test { } + /** @test configure a handler for the (optional) "revealYourself" functionality. + * We install a lambda to supply the actual implementation action, which can then + * either be triggered by a signal/slot invocation, or by sending a "state mark". + */ + void + revealer () + { + MARK_TEST_FUN + EventLog nexusLog = gui::test::Nexus::startNewLog(); + + MockElm mock("target"); + ID targetID = mock.getID(); + + sigc::signal trigger_reveal; + trigger_reveal.connect (sigc::mem_fun(mock, &Tangible::slotReveal)); + + CHECK (not mock.isTouched()); + CHECK (not mock.isExpanded()); + CHECK (mock.ensureNot("reveal")); + CHECK (mock.ensureNot("expanded")); + CHECK (nexusLog.ensureNot("state-mark")); + + bool revealed = false; + mock.installRevealer([&]() + { // NOTE: our mock "implementation" of the revealYourself functionality + mock.slotExpand(); // explicitly prompts the element to expand itself, + revealed = true; // and then via closure sets a flag we can verify. + }); + + trigger_reveal(); + + CHECK (true == revealed); + CHECK (mock.isExpanded()); + CHECK (mock.verifyEvent("create","target") + .beforeCall("revealYourself") + .beforeCall("expand").arg(true) + .beforeEvent("expanded")); + + // invoking the slotExpand() also emitted a state mark to persist that expansion state... + CHECK (nexusLog.verifyCall("note").arg(targetID, GenNode{"expand", true}) + .before("handling state-mark")); + + + // second test: the same can be achieved via UI-Bus message... + revealed = false; + auto stateMark = GenNode{"revealYourself", 47}; // (payload argument irrelevant) + auto& uiBus = gui::test::Nexus::testUI(); + CHECK (nexusLog.ensureNot("revealYourself")); + + uiBus.mark (targetID, stateMark); // send the state mark message to reveal the element + + CHECK (true == revealed); + CHECK (mock.verifyMark("revealYourself", 47) + .afterEvent("expanded") + .beforeCall("revealYourself") + .beforeCall("expand").arg(true)); + + CHECK (nexusLog.verifyCall("mark").arg(targetID, stateMark) + .after("handling state-mark") + .before("revealYourself") + .beforeEvent("delivered mark")); + + + + cout << "____Event-Log_________________\n" + << util::join(mock.getLog(), "\n") + << "\n───╼━━━━━━━━━╾────────────────"<