2015-11-27 19:24:00 +01:00
|
|
|
/*
|
|
|
|
|
MOCK-ELM.hpp - generic mock UI element for unit testing
|
|
|
|
|
|
|
|
|
|
Copyright (C) Lumiera.org
|
|
|
|
|
2015, Hermann Vosseler <Ichthyostega@web.de>
|
|
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
|
modify it under the terms of the GNU General Public License as
|
|
|
|
|
published by the Free Software Foundation; either version 2 of
|
|
|
|
|
the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** @file mock-elm.hpp
|
|
|
|
|
** A generic interface element instrumented for unit testing.
|
|
|
|
|
** All relevant building blocks within the Lumiera GTK UI are based on
|
|
|
|
|
** gui::model::Tangible, meaning that any generic effect of interface interactions
|
|
|
|
|
** can be expressed in terms of this interface contract. As far as the UI participates
|
|
|
|
|
** in interactions with the lower layers, like e.g. command invocation, structure updates
|
|
|
|
|
** and state notifications, these processes can be modelled and verified with the help
|
|
|
|
|
** of a specially prepared Tangible instance. This gui::test::MockElm provides the
|
|
|
|
|
** necessary instrumentation to observe what has been invoked and received.
|
|
|
|
|
**
|
|
|
|
|
** @todo initial draft and WIP-WIP-WIP as of 11/2015
|
|
|
|
|
**
|
|
|
|
|
** @see abstract-tangible-test.cpp
|
|
|
|
|
**
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
2015-11-28 18:36:35 +01:00
|
|
|
#ifndef GUI_TEST_MOCK_ELM_H
|
|
|
|
|
#define GUI_TEST_MOCK_ELM_H
|
2015-11-27 19:24:00 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "lib/error.hpp"
|
2015-11-28 23:50:56 +01:00
|
|
|
//#include "lib/idi/entry-id.hpp"
|
2015-11-27 19:24:00 +01:00
|
|
|
//#include "lib/util.hpp"
|
2015-11-28 23:50:56 +01:00
|
|
|
#include "lib/test/event-log.hpp"
|
2015-11-27 19:24:00 +01:00
|
|
|
#include "gui/model/tangible.hpp"
|
|
|
|
|
#include "lib/diff/record.hpp"
|
2015-12-25 00:41:14 +01:00
|
|
|
#include "lib/idi/genfunc.hpp"
|
2015-12-18 17:40:42 +01:00
|
|
|
#include "test/test-nexus.hpp"
|
2015-12-26 04:40:38 +01:00
|
|
|
#include "lib/symbol.hpp"
|
|
|
|
|
|
|
|
|
|
#include <iostream>
|
2015-11-27 19:24:00 +01:00
|
|
|
#include <string>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace gui {
|
2015-11-28 21:43:09 +01:00
|
|
|
namespace error = lumiera::error;
|
|
|
|
|
using error::LUMIERA_ERROR_ASSERTION;
|
2015-11-28 23:50:56 +01:00
|
|
|
using lib::test::EventLog;
|
|
|
|
|
using lib::test::EventMatch;
|
2015-11-28 21:43:09 +01:00
|
|
|
|
2015-11-27 19:24:00 +01:00
|
|
|
namespace test{
|
|
|
|
|
|
2015-11-28 21:43:09 +01:00
|
|
|
|
2015-11-27 19:24:00 +01:00
|
|
|
// using lib::HashVal;
|
|
|
|
|
// using util::isnil;
|
2015-11-28 23:50:56 +01:00
|
|
|
// using lib::idi::EntryID;
|
|
|
|
|
// using lib::diff::Record;
|
2015-12-26 04:40:38 +01:00
|
|
|
using lib::Symbol;
|
2015-11-27 19:24:00 +01:00
|
|
|
using std::string;
|
2015-12-26 04:40:38 +01:00
|
|
|
using std::cout;
|
|
|
|
|
using std::cerr;
|
|
|
|
|
using std::endl;
|
2015-11-27 19:24:00 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Mock UI element or controller.
|
|
|
|
|
* Within Lumiera, all interface components of relevance are based
|
|
|
|
|
* on the [Tangible] interface, which we mock here for unit testing.
|
|
|
|
|
* This special implementation is instrumented to [log][lib::test::EventLog]
|
|
|
|
|
* any invocation and any messages sent or received through the UI Backbone,
|
|
|
|
|
* which is formed by the [UiBus].
|
|
|
|
|
*
|
|
|
|
|
* @todo some usage details
|
|
|
|
|
* @see abstract-tangible-test.cpp
|
|
|
|
|
*/
|
|
|
|
|
class MockElm
|
|
|
|
|
: public gui::model::Tangible
|
|
|
|
|
{
|
2015-12-16 23:24:11 +01:00
|
|
|
using _Par = gui::model::Tangible;
|
|
|
|
|
|
2015-12-26 04:55:00 +01:00
|
|
|
EventLog log_{this->identify()};
|
2015-11-27 19:24:00 +01:00
|
|
|
|
2015-12-25 00:41:14 +01:00
|
|
|
bool virgin_{true};
|
2015-12-25 03:53:26 +01:00
|
|
|
bool expanded_{false};
|
2015-12-25 00:41:14 +01:00
|
|
|
|
2015-12-16 23:24:11 +01:00
|
|
|
|
2015-11-27 19:24:00 +01:00
|
|
|
/* ==== Tangible interface ==== */
|
|
|
|
|
|
2015-12-25 03:53:26 +01:00
|
|
|
virtual void
|
|
|
|
|
doReset() override
|
2015-11-28 21:43:09 +01:00
|
|
|
{
|
2015-12-25 00:41:14 +01:00
|
|
|
log_.call(this->identify(), "reset");
|
2015-12-25 03:53:26 +01:00
|
|
|
expanded_ = false;
|
2015-12-25 00:41:14 +01:00
|
|
|
virgin_ = true;
|
2015-12-16 23:24:11 +01:00
|
|
|
log_.event("reset");
|
2015-11-28 21:43:09 +01:00
|
|
|
}
|
|
|
|
|
|
2015-12-26 00:59:16 +01:00
|
|
|
virtual bool
|
2015-12-25 03:53:26 +01:00
|
|
|
doExpand (bool yes) override
|
2015-11-27 19:24:00 +01:00
|
|
|
{
|
2015-12-25 03:53:26 +01:00
|
|
|
log_.call(this->identify(), "expand", yes);
|
|
|
|
|
virgin_ = false;
|
|
|
|
|
expanded_ = yes;
|
2015-12-26 04:40:38 +01:00
|
|
|
log_.event (expanded_? "expanded" : "collapsed");
|
2015-12-26 00:59:16 +01:00
|
|
|
return true;
|
2015-11-27 19:24:00 +01:00
|
|
|
}
|
|
|
|
|
|
2015-12-25 03:53:26 +01:00
|
|
|
virtual void
|
|
|
|
|
doReveal (ID child) override
|
2015-11-28 21:43:09 +01:00
|
|
|
{
|
|
|
|
|
UNIMPLEMENTED ("mock doReveal");
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-25 03:53:26 +01:00
|
|
|
virtual void
|
|
|
|
|
doRevealYourself() override
|
|
|
|
|
{
|
|
|
|
|
UNIMPLEMENTED ("mock doRevealYourself");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
virtual void
|
|
|
|
|
doMsg (string text) override
|
2015-11-28 21:43:09 +01:00
|
|
|
{
|
2015-12-26 04:40:38 +01:00
|
|
|
log_.call (this->identify(), "doMsg", text);
|
|
|
|
|
cout << this->identify() << " <-- Message(\""<<text<<"\")" <<endl;
|
|
|
|
|
log_.note ("type=mark", "ID=Message", text);
|
2015-11-28 21:43:09 +01:00
|
|
|
}
|
|
|
|
|
|
2015-12-25 03:53:26 +01:00
|
|
|
virtual void
|
|
|
|
|
doErr (string text) override
|
2015-11-28 21:43:09 +01:00
|
|
|
{
|
2015-12-26 04:40:38 +01:00
|
|
|
log_.call (this->identify(), "doErr", text);
|
|
|
|
|
cerr << this->identify() << " <-- Error(\""<<text<<"\")" <<endl;
|
|
|
|
|
log_.note ("type=mark", "ID=Error", text);
|
2015-11-28 21:43:09 +01:00
|
|
|
}
|
|
|
|
|
|
2015-12-25 03:53:26 +01:00
|
|
|
virtual void
|
|
|
|
|
doFlash() override
|
2015-11-28 21:43:09 +01:00
|
|
|
{
|
2015-12-26 04:40:38 +01:00
|
|
|
log_.call (this->identify(), "doFlash");
|
|
|
|
|
cout << this->identify() << " <-- Flash!" <<endl;
|
|
|
|
|
log_.note ("type=mark", "ID=Flash");
|
2015-11-28 21:43:09 +01:00
|
|
|
}
|
|
|
|
|
|
2015-12-25 03:53:26 +01:00
|
|
|
virtual void
|
|
|
|
|
doMark (GenNode const& mark) override
|
2015-11-28 21:43:09 +01:00
|
|
|
{
|
2015-12-26 22:56:43 +01:00
|
|
|
log_.call (this->identify(), "doMark", mark);
|
2015-12-26 04:40:38 +01:00
|
|
|
cout << this->identify() << " <-- state-mark = "<< string(mark) <<endl;
|
|
|
|
|
log_.note ("type=mark", "ID="+mark.idi.getSym(), mark);
|
2015-11-28 21:43:09 +01:00
|
|
|
}
|
2015-11-27 19:24:00 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
protected:
|
2015-12-25 00:41:14 +01:00
|
|
|
string
|
|
|
|
|
identify() const
|
|
|
|
|
{
|
2015-12-26 04:40:38 +01:00
|
|
|
return getID().getSym() +"."+ lib::idi::instanceTypeID(this);
|
2015-12-25 00:41:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2015-11-27 19:24:00 +01:00
|
|
|
public:
|
|
|
|
|
explicit
|
|
|
|
|
MockElm(string id)
|
2015-11-28 23:50:56 +01:00
|
|
|
: MockElm(lib::idi::EntryID<MockElm>(id))
|
2015-11-27 19:24:00 +01:00
|
|
|
{ }
|
|
|
|
|
|
|
|
|
|
explicit
|
2015-11-28 21:43:09 +01:00
|
|
|
MockElm(ID identity, ctrl::BusTerm& nexus =Nexus::testUI())
|
|
|
|
|
: gui::model::Tangible(identity, nexus)
|
2015-12-16 23:24:11 +01:00
|
|
|
{
|
2015-12-26 20:41:24 +01:00
|
|
|
log_.call (this->identify(), "ctor", identity, string(nexus));
|
|
|
|
|
log_.create (getID().getSym());
|
2015-12-16 23:24:11 +01:00
|
|
|
}
|
2015-11-28 23:50:56 +01:00
|
|
|
|
|
|
|
|
|
2015-12-26 20:41:24 +01:00
|
|
|
/** 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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-11-28 23:50:56 +01:00
|
|
|
/* ==== special operations API ==== */
|
|
|
|
|
|
2015-12-26 20:41:24 +01:00
|
|
|
/** 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.
|
|
|
|
|
*/
|
2015-11-28 23:50:56 +01:00
|
|
|
void
|
|
|
|
|
kill()
|
|
|
|
|
{
|
2015-12-26 20:41:24 +01:00
|
|
|
log_.call (this->identify(), "kill");
|
|
|
|
|
log_.destroy (getID().getSym());
|
|
|
|
|
|
|
|
|
|
Nexus::zombificate (this->uiBus_);
|
|
|
|
|
log_.event ("successfully connected to zombie bus");
|
2015-11-28 23:50:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2015-12-26 20:41:24 +01:00
|
|
|
|
|
|
|
|
|
2015-11-28 23:50:56 +01:00
|
|
|
/* ==== Query/Verification API ==== */
|
|
|
|
|
|
|
|
|
|
ID getID() const
|
|
|
|
|
{
|
|
|
|
|
return uiBus_.getID();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
isTouched() const
|
|
|
|
|
{
|
2015-12-25 03:53:26 +01:00
|
|
|
return not virgin_;
|
2015-11-28 23:50:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
isExpanded() const
|
|
|
|
|
{
|
2015-12-25 03:53:26 +01:00
|
|
|
return expanded_;
|
2015-11-28 23:50:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
EventMatch
|
2015-12-06 04:37:41 +01:00
|
|
|
verify (string match) const
|
2015-11-28 23:50:56 +01:00
|
|
|
{
|
|
|
|
|
return getLog().verify(match);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
EventMatch
|
2015-12-06 04:37:41 +01:00
|
|
|
verifyMatch (string regExp) const
|
2015-11-28 23:50:56 +01:00
|
|
|
{
|
|
|
|
|
return getLog().verifyMatch(regExp);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
EventMatch
|
2015-12-06 04:37:41 +01:00
|
|
|
verifyEvent (string match) const
|
2015-11-28 23:50:56 +01:00
|
|
|
{
|
|
|
|
|
return getLog().verifyEvent(match);
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-16 23:24:11 +01:00
|
|
|
EventMatch
|
|
|
|
|
verifyEvent (string classifier, string match) const
|
|
|
|
|
{
|
|
|
|
|
return getLog().verifyEvent (classifier,match);
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-28 23:50:56 +01:00
|
|
|
EventMatch
|
2015-12-06 04:37:41 +01:00
|
|
|
verifyCall (string match) const
|
2015-11-28 23:50:56 +01:00
|
|
|
{
|
|
|
|
|
return getLog().verifyCall(match);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
EventMatch
|
2015-12-06 04:37:41 +01:00
|
|
|
ensureNot (string match) const
|
2015-11-28 23:50:56 +01:00
|
|
|
{
|
|
|
|
|
return getLog().ensureNot(match);
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-26 04:40:38 +01:00
|
|
|
/** special verification match on a "state mark" message to this element */
|
|
|
|
|
EventMatch
|
|
|
|
|
verifyMark (string msgContentMatch) const
|
|
|
|
|
{
|
|
|
|
|
return getLog().verifyEvent("mark", msgContentMatch);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** verification match on a specific "state mark" message
|
|
|
|
|
* @param id the ID-symbol used, identifying the kind of notification message
|
|
|
|
|
* @param payloadMatch to be applied to the payload of the message solely
|
|
|
|
|
*/
|
2015-11-28 23:50:56 +01:00
|
|
|
EventMatch
|
2015-12-26 04:40:38 +01:00
|
|
|
verifyMark (string id, string payloadMatch) const
|
2015-11-28 23:50:56 +01:00
|
|
|
{
|
2015-12-26 04:40:38 +01:00
|
|
|
return getLog().verifyEvent("mark", payloadMatch).type("mark").id(id);
|
2015-11-28 23:50:56 +01:00
|
|
|
}
|
2015-12-06 04:37:41 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
EventLog const&
|
|
|
|
|
getLog() const
|
|
|
|
|
{
|
|
|
|
|
return log_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
EventLog&
|
|
|
|
|
joinLog (MockElm& otherMock)
|
|
|
|
|
{
|
2015-12-09 01:18:15 +01:00
|
|
|
log_.joinInto (otherMock.log_);
|
2015-12-06 04:37:41 +01:00
|
|
|
return log_;
|
|
|
|
|
}
|
2015-11-27 19:24:00 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}} // namespace gui::test
|
2015-11-28 18:36:35 +01:00
|
|
|
#endif /*GUI_TEST_MOCK_ELM_H*/
|