WIP: arrange some elements needed for MockElm implementation
This commit is contained in:
parent
25805635ff
commit
d04e6d74d8
12 changed files with 855 additions and 17 deletions
|
|
@ -106,7 +106,7 @@ namespace ctrl{
|
|||
virtual void note (EntryID subject, GenNode mark) =0;
|
||||
virtual void mark (EntryID subject, GenNode mark) =0;
|
||||
|
||||
BusTerm attach (EntryID newAddress);
|
||||
BusTerm&& attach (EntryID newAddress);
|
||||
|
||||
protected:
|
||||
BusTerm(EntryID identity, BusTerm& attached_to =*this)
|
||||
|
|
|
|||
77
src/gui/model/tangible.cpp
Normal file
77
src/gui/model/tangible.cpp
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
/*
|
||||
Tangible - common implementation base of all relevant interface elements
|
||||
|
||||
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 tangible.hpp
|
||||
** Abstraction: a tangible element of the User Interface.
|
||||
** This header defines the basics of...
|
||||
**
|
||||
** @note as of X/2015 this is complete bs
|
||||
** @todo WIP ///////////////////////TICKET #
|
||||
**
|
||||
** @see ////TODO_test usage example
|
||||
** @see element.cpp implementation
|
||||
**
|
||||
*/
|
||||
|
||||
|
||||
//#include "lib/util.hpp"
|
||||
//#include "lib/symbol.hpp"
|
||||
//#include "include/logging.h"
|
||||
#include "gui/model/tangible.hpp"
|
||||
|
||||
//#include <boost/noncopyable.hpp>
|
||||
#include <string>
|
||||
#include <map>
|
||||
|
||||
using std::map;
|
||||
using std::string;
|
||||
|
||||
using util::contains;
|
||||
using util::isnil;
|
||||
|
||||
namespace gui {
|
||||
namespace model {
|
||||
|
||||
namespace { // internal details
|
||||
|
||||
} // internal details
|
||||
|
||||
|
||||
|
||||
//NA::~NA() { }
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
string
|
||||
fun (string& id)
|
||||
{
|
||||
return "x"+id;
|
||||
}
|
||||
|
||||
}} // namespace gui::model
|
||||
|
|
@ -37,6 +37,8 @@
|
|||
|
||||
|
||||
#include "lib/error.hpp"
|
||||
#include "gui/ctrl/bus-term.hpp"
|
||||
#include "lib/idi/entry-id.hpp"
|
||||
//#include "lib/symbol.hpp"
|
||||
//#include "lib/util.hpp"
|
||||
|
||||
|
|
@ -53,18 +55,28 @@ namespace model {
|
|||
|
||||
|
||||
/**
|
||||
* Interface common to all UI elements of relevance for the Lumiera application.
|
||||
* Any non-local and tangible interface interaction will at some point pass through
|
||||
* this foundation element, which forms the joint and attachment to the UI backbone,
|
||||
* which is the [UI-Bus][ui-bus.hpp]. Any tangible element acquires a distinct identity
|
||||
* and has to be formed starting from an already existing bus nexus.
|
||||
*
|
||||
* @todo write type comment...
|
||||
*/
|
||||
class Tangible
|
||||
: boost::noncopyable
|
||||
{
|
||||
string nothing_;
|
||||
protected:
|
||||
ctrl::BusTerm uiBus_;
|
||||
|
||||
Tangible(EntryID identity, ctrl::BusTerm nexus)
|
||||
: uiBus_(nexus.attach(identity))
|
||||
{ }
|
||||
|
||||
public:
|
||||
Tangible();
|
||||
~Tangible();
|
||||
virtual ~Tangible(); ///< this is an interface
|
||||
|
||||
protected:
|
||||
private:
|
||||
string maybe () const;
|
||||
};
|
||||
|
||||
|
|
|
|||
131
src/lib/test/event-log.cpp
Normal file
131
src/lib/test/event-log.cpp
Normal file
|
|
@ -0,0 +1,131 @@
|
|||
/*
|
||||
Test-Helper - collection of functions supporting unit testing
|
||||
|
||||
Copyright (C) Lumiera.org
|
||||
2009, 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.
|
||||
|
||||
* *****************************************************/
|
||||
|
||||
|
||||
#include "lib/test/test-helper.hpp"
|
||||
#include "lib/test/testdummy.hpp"
|
||||
#include "lib/format-string.hpp"
|
||||
#include "lib/unique-malloc-owner.hpp"
|
||||
|
||||
#ifdef __GNUG__
|
||||
#include <cxxabi.h>
|
||||
#endif
|
||||
|
||||
#include <string>
|
||||
|
||||
using std::string;
|
||||
|
||||
namespace lib {
|
||||
namespace test{
|
||||
|
||||
|
||||
string
|
||||
showSizeof (size_t siz, const char* name)
|
||||
{
|
||||
static util::_Fmt fmt ("sizeof( %s ) %|30t|= %3d");
|
||||
return string (fmt % (name? name:"?") % siz);
|
||||
}
|
||||
|
||||
|
||||
#ifdef __GNUG__
|
||||
/**
|
||||
* \par Implementation notes
|
||||
* GCC / G++ subscribes to a cross-vendor ABI for C++, sometimes called the IA64 ABI
|
||||
* because it happens to be the native ABI for that platform. It is summarised at
|
||||
* \link http://www.codesourcery.com/cxx-abi/ mentor-embedded \endlink
|
||||
* along with the current specification. For users of GCC greater than or equal to 3.x,
|
||||
* entry points are exposed through the standard library in \c <cxxabi.h>
|
||||
*
|
||||
* This implementation relies on a vendor neutral ABI for C++ compiled programs
|
||||
*
|
||||
* char* abi::__cxa_demangle(const char* mangled_name,
|
||||
* char* output_buffer, size_t* length,
|
||||
* int* status)
|
||||
*
|
||||
* Parameters:
|
||||
* - \c mangled_name
|
||||
* NUL-terminated character string containing the name to be demangled.
|
||||
* - \c output_buffer
|
||||
* region of memory, allocated with \c malloc, of `*length` bytes,
|
||||
* into which the demangled name is stored. If \c output_buffer is not long enough,
|
||||
* it is expanded using \c realloc. output_buffer may instead be NULL; in that case,
|
||||
* the demangled name is placed in a region of memory allocated with \c malloc.
|
||||
* - \c length
|
||||
* If length is non-NULL, the length of the buffer containing the demangled name is placed in `*length`.
|
||||
* - \c status
|
||||
* error flag: `*status` is set to one of the following values:
|
||||
*
|
||||
* 0: The demangling operation succeeded.
|
||||
* -1: A memory allocation failure occurred.
|
||||
* -2: mangled_name is not a valid name under the C++ ABI mangling rules.
|
||||
* -3: One of the arguments is invalid.
|
||||
*
|
||||
* The function returns a pointer to the start of the NUL-terminated demangled name,
|
||||
* or NULL if the demangling fails. The caller is responsible for deallocating
|
||||
* this memory using \c free.
|
||||
*/
|
||||
string
|
||||
demangleCxx (Literal rawName)
|
||||
{
|
||||
int error = -4;
|
||||
UniqueMallocOwner<char> demangled (abi::__cxa_demangle (rawName,
|
||||
NULL,
|
||||
NULL,
|
||||
&error));
|
||||
return 0==error? demangled.get()
|
||||
: string(rawName);
|
||||
}
|
||||
|
||||
#else
|
||||
string
|
||||
demangleCxx (Literal rawName)
|
||||
{
|
||||
return string (rawName);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/** @todo probably this can be done in a more clever way. Anyone...?
|
||||
*/
|
||||
string
|
||||
randStr (size_t len)
|
||||
{
|
||||
static const string alpha ("aaaabbccddeeeeffgghiiiijjkkllmmnnooooppqqrrssttuuuuvvwwxxyyyyzz0123456789");
|
||||
static const size_t MAXAL (alpha.size());
|
||||
|
||||
string garbage(len,'\0');
|
||||
size_t p = len;
|
||||
while (p)
|
||||
garbage[--p] = alpha[rand() % MAXAL];
|
||||
return garbage;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/** storage for test-dummy flags */
|
||||
|
||||
long Dummy::_local_checksum = 0;
|
||||
bool Dummy::_throw_in_ctor = false;
|
||||
|
||||
|
||||
}} // namespace lib::test
|
||||
218
src/lib/test/event-log.hpp
Normal file
218
src/lib/test/event-log.hpp
Normal file
|
|
@ -0,0 +1,218 @@
|
|||
/*
|
||||
TEST-HELPER.hpp - collection of functions supporting unit testing
|
||||
|
||||
Copyright (C) Lumiera.org
|
||||
2009, 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.
|
||||
|
||||
*/
|
||||
|
||||
|
||||
#ifndef LIB_TEST_TEST_HELPER_H
|
||||
#define LIB_TEST_TEST_HELPER_H
|
||||
|
||||
|
||||
#include "lib/symbol.hpp"
|
||||
#include "lib/time/timevalue.hpp"
|
||||
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <typeinfo>
|
||||
#include <cstdlib>
|
||||
#include <string>
|
||||
|
||||
|
||||
|
||||
namespace lib {
|
||||
namespace test{
|
||||
|
||||
using lib::Literal;
|
||||
using std::string;
|
||||
using std::rand;
|
||||
|
||||
|
||||
|
||||
/** get a sensible display for a type or object
|
||||
* @param obj object of the type in question
|
||||
* @param name optional name to be used literally
|
||||
* @return either the literal name without any further magic,
|
||||
* or the result of compile-time or run time
|
||||
* type identification as implemented by the compiler.
|
||||
*/
|
||||
template<typename T>
|
||||
inline Literal
|
||||
showType (T const& obj, Literal name=0)
|
||||
{
|
||||
return name? name : Literal(typeid(obj).name());
|
||||
}
|
||||
|
||||
/** get a sensible display for a type
|
||||
* @param name optional name to be used literally
|
||||
* @return either the literal name without any further magic,
|
||||
* or the result of compile-time or run time
|
||||
* type identification as implemented by the compiler.
|
||||
*/
|
||||
template<typename T>
|
||||
inline Literal
|
||||
showType (Literal name=0)
|
||||
{
|
||||
return name? name : Literal(typeid(T).name());
|
||||
}
|
||||
|
||||
|
||||
/** reverse the effect of C++ name mangling.
|
||||
* @return string in language-level form of a C++ type or object name,
|
||||
* or a string with the original input if demangling fails.
|
||||
* @warning implementation relies on the cross vendor C++ ABI in use
|
||||
* by GCC and compatible compilers, so portability is limited.
|
||||
* The implementation is accessed through libStdC++
|
||||
* Name representation in emitted object code and type IDs is
|
||||
* essentially an implementation detail and subject to change.
|
||||
*/
|
||||
string
|
||||
demangleCxx (Literal rawName);
|
||||
|
||||
|
||||
/** short yet distinct name identifying the given type.
|
||||
* @return demangled type-id without any scopes. */
|
||||
template<typename TY>
|
||||
string
|
||||
tyAbbr()
|
||||
{
|
||||
string typeStr = demangleCxx (showType<TY>());
|
||||
size_t pos = typeStr.rfind("::");
|
||||
if (pos != string::npos)
|
||||
typeStr = typeStr.substr(pos+2);
|
||||
return typeStr;
|
||||
}
|
||||
|
||||
template<typename TY>
|
||||
string
|
||||
tyAbbr(TY&&)
|
||||
{
|
||||
return tyAbbr<TY>();
|
||||
}
|
||||
|
||||
|
||||
/** for printing sizeof().
|
||||
* prints the given size and name literally, without any further magic */
|
||||
string
|
||||
showSizeof (size_t siz, const char* name);
|
||||
|
||||
/** for printing sizeof(), trying to figure out the type name automatically */
|
||||
template<typename T>
|
||||
inline string
|
||||
showSizeof(const char* name=0)
|
||||
{
|
||||
return showSizeof (sizeof (T), showType<T> (name));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline string
|
||||
showSizeof(T const& obj, const char* name=0)
|
||||
{
|
||||
return showSizeof (sizeof (obj), showType (obj,name));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline string
|
||||
showSizeof(T *obj, const char* name=0)
|
||||
{
|
||||
return obj? showSizeof (*obj, name)
|
||||
: showSizeof<T> (name);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/** helper to discern the kind of reference of the argument type */
|
||||
template<typename R>
|
||||
string
|
||||
showRefKind()
|
||||
{
|
||||
return std::is_lvalue_reference<R>::value? "REF"
|
||||
: std::is_rvalue_reference<R>::value? "MOV"
|
||||
: "VAL";
|
||||
}
|
||||
|
||||
/** helper for investigating a variadic argument pack
|
||||
* @warning always spell out the template arguments explicitly
|
||||
* when invoking this diagnostics, e.g. \c showVariadicTypes<ARGS...>(args...)
|
||||
* otherwise the template argument matching for functions might mess up the
|
||||
* kind of reference you'll see in the diagnostics.
|
||||
* @see test-helper-variadic-test.cpp
|
||||
*/
|
||||
template<typename... EMPTY>
|
||||
inline string
|
||||
showVariadicTypes ()
|
||||
{
|
||||
return " :.";
|
||||
}
|
||||
|
||||
template<typename X, typename... XS>
|
||||
inline string
|
||||
showVariadicTypes (X const& x, XS const&... xs)
|
||||
{
|
||||
return " :---#"
|
||||
+ boost::lexical_cast<string>(1 + sizeof...(xs))
|
||||
+ " -- Type: " + showType<X>()
|
||||
+ " " + showRefKind<X>()
|
||||
+ " Address* " + boost::lexical_cast<string>(&x)
|
||||
+ "\n"
|
||||
+ showVariadicTypes<XS...> (xs...);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/** create a random but not insane Time value */
|
||||
inline lib::time::Time
|
||||
randTime ()
|
||||
{
|
||||
return lib::time::Time (500 * (rand() % 2), (rand() % 600) + 1);
|
||||
}
|
||||
|
||||
/** create garbage string of given length
|
||||
* @return string containing arbitrary lower case letters and numbers
|
||||
*/
|
||||
string randStr (size_t len);
|
||||
|
||||
|
||||
}} // namespace lib::test
|
||||
|
||||
|
||||
|
||||
|
||||
/* === test helper macros === */
|
||||
|
||||
/**
|
||||
* Macro to verify a statement indeed raises an exception.
|
||||
* If no exception is thrown, the #NOTREACHED macro will trigger
|
||||
* an assertion failure. In case of an exception, the #lumiera_error
|
||||
* state is checked, cleared and verified.
|
||||
*/
|
||||
#define VERIFY_ERROR(ERROR_ID, ERRONEOUS_STATEMENT) \
|
||||
try \
|
||||
{ \
|
||||
ERRONEOUS_STATEMENT ; \
|
||||
NOTREACHED("expected '%s' failure in: %s", \
|
||||
#ERROR_ID, #ERRONEOUS_STATEMENT); \
|
||||
} \
|
||||
catch (...) \
|
||||
{ \
|
||||
CHECK (lumiera_error_expect (LUMIERA_ERROR_##ERROR_ID));\
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -21,6 +21,15 @@
|
|||
* *****************************************************/
|
||||
|
||||
|
||||
/** @file test-helper.cpp
|
||||
** definition of some widely used test helper functions.
|
||||
**
|
||||
** @see TestHelper_test
|
||||
** @see TestHelperDemangling_test
|
||||
**
|
||||
*/
|
||||
|
||||
|
||||
#include "lib/test/test-helper.hpp"
|
||||
#include "lib/test/testdummy.hpp"
|
||||
#include "lib/format-string.hpp"
|
||||
|
|
@ -53,7 +62,7 @@ namespace test{
|
|||
* because it happens to be the native ABI for that platform. It is summarised at
|
||||
* \link http://www.codesourcery.com/cxx-abi/ mentor-embedded \endlink
|
||||
* along with the current specification. For users of GCC greater than or equal to 3.x,
|
||||
* entry points are exposed through the standard library in \c <cxxabi.h>
|
||||
* entry points are exposed through the standard library in `<cxxabi.h>`
|
||||
*
|
||||
* This implementation relies on a vendor neutral ABI for C++ compiled programs
|
||||
*
|
||||
|
|
@ -123,7 +132,6 @@ namespace test{
|
|||
|
||||
|
||||
/** storage for test-dummy flags */
|
||||
|
||||
long Dummy::_local_checksum = 0;
|
||||
bool Dummy::_throw_in_ctor = false;
|
||||
|
||||
|
|
|
|||
|
|
@ -21,8 +21,23 @@
|
|||
*/
|
||||
|
||||
|
||||
#ifndef LIB_TEST_TEST_HELPER_H
|
||||
#define LIB_TEST_TEST_HELPER_H
|
||||
/** @file test-helper.hpp
|
||||
** A collection of frequently used helper functions to support unit testing.
|
||||
** Mostly, these are diagnostics helpers to produce readable output, especially
|
||||
** for types. Some of these support meta programming to figure out the \em actual
|
||||
** reference kind (value, lvalue, rvalue) of a template parameter instantiation.
|
||||
** For GNU compatible compilers, we define here also an interface to the internal
|
||||
** ABI for [demangling type names][demangleCxx].
|
||||
**
|
||||
** @note this header is included into a large number of tests.
|
||||
** @see TestHelper_test
|
||||
** @see TestHelperDemangling_test
|
||||
**
|
||||
*/
|
||||
|
||||
|
||||
#ifndef LIB_TEST_TEST_HELPER_H_
|
||||
#define LIB_TEST_TEST_HELPER_H_
|
||||
|
||||
|
||||
#include "lib/symbol.hpp"
|
||||
|
|
@ -44,7 +59,7 @@ namespace test{
|
|||
|
||||
|
||||
|
||||
/** get a sensible display for a type or object
|
||||
/** get a sensible display for a type or object
|
||||
* @param obj object of the type in question
|
||||
* @param name optional name to be used literally
|
||||
* @return either the literal name without any further magic,
|
||||
|
|
@ -58,7 +73,7 @@ namespace test{
|
|||
return name? name : Literal(typeid(obj).name());
|
||||
}
|
||||
|
||||
/** get a sensible display for a type
|
||||
/** get a sensible display for a type
|
||||
* @param name optional name to be used literally
|
||||
* @return either the literal name without any further magic,
|
||||
* or the result of compile-time or run time
|
||||
|
|
@ -215,4 +230,4 @@ namespace test{
|
|||
CHECK (lumiera_error_expect (LUMIERA_ERROR_##ERROR_ID));\
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif /*LIB_TEST_TEST_HELPER_H_*/
|
||||
|
|
|
|||
|
|
@ -14,6 +14,11 @@ out: sizeof.+lib.+test.+test.+Wrmrmpft.+Murpf.+ = 1
|
|||
END
|
||||
|
||||
|
||||
TEST "Helper for event registration and verification" TestEventLog_test <<END
|
||||
return: 0
|
||||
END
|
||||
|
||||
|
||||
TEST "Helper to show demangled C++ names" TestHelperDemangling_test <<END
|
||||
out: .+lib.test.test.Space.+Outer.+Inner
|
||||
out-lit: lib::test::test::Space const* (*)(lib::test::test::Outer<lib::test::test::Space>::Inner const&&)
|
||||
|
|
|
|||
110
tests/gui/test/mock-elm.hpp
Normal file
110
tests/gui/test/mock-elm.hpp
Normal file
|
|
@ -0,0 +1,110 @@
|
|||
/*
|
||||
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
|
||||
**
|
||||
*/
|
||||
|
||||
|
||||
#ifndef GUI_TEST_MOCK_ELM_H_
|
||||
#define GUI_TEST_MOCK_ELM_H_
|
||||
|
||||
|
||||
#include "lib/error.hpp"
|
||||
#include "lib/idi/entry-id.hpp"
|
||||
//#include "lib/util.hpp"
|
||||
#include "gui/model/tangible.hpp"
|
||||
#include "lib/diff/record.hpp"
|
||||
|
||||
//#include <boost/noncopyable.hpp>
|
||||
#include <string>
|
||||
|
||||
|
||||
namespace gui {
|
||||
namespace test{
|
||||
|
||||
// using lib::HashVal;
|
||||
// using util::isnil;
|
||||
using lib::idi::EntryID;
|
||||
using lib::diff::Record;
|
||||
using std::string;
|
||||
|
||||
|
||||
/**
|
||||
* 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
|
||||
{
|
||||
|
||||
/* ==== Tangible interface ==== */
|
||||
|
||||
virtual void
|
||||
act (GenNode command) override
|
||||
{
|
||||
UNIMPLEMENTED ("");
|
||||
}
|
||||
virtual void note (GenNode mark) =0;
|
||||
virtual void mark (GenNode mark) =0;
|
||||
|
||||
virtual void act (EntryID subject, GenNode command) =0;
|
||||
virtual void note (EntryID subject, GenNode mark) =0;
|
||||
virtual void mark (EntryID subject, GenNode mark) =0;
|
||||
|
||||
|
||||
protected:
|
||||
public:
|
||||
explicit
|
||||
MockElm(string id)
|
||||
: gui::model::Tangible(TODO_generate_identity, TestNexus::hook())
|
||||
{ }
|
||||
|
||||
explicit
|
||||
MockElm(EntryID identity, ctrl::BusTerm&& nexus =TestNexus::hook())
|
||||
{ }
|
||||
};
|
||||
|
||||
|
||||
|
||||
}} // namespace gui::test
|
||||
#endif /*GUI_TEST_MOCK_ELM_H_*/
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
gui::model::Element - a generic element in the UI-Model
|
||||
test::Nexus - implementation base for test user interface backbone
|
||||
|
||||
Copyright (C) Lumiera.org
|
||||
2015, Hermann Vosseler <Ichthyostega@web.de>
|
||||
|
|
@ -21,8 +21,8 @@
|
|||
* *****************************************************/
|
||||
|
||||
|
||||
/** @file element.cpp
|
||||
** Service for element.
|
||||
/** @file test/nexus.cpp
|
||||
** Abstraction: a tangible element of the User Interface.
|
||||
** This header defines the basics of...
|
||||
**
|
||||
** @note as of X/2015 this is complete bs
|
||||
|
|
@ -34,10 +34,10 @@
|
|||
*/
|
||||
|
||||
|
||||
#include "lib/util.hpp"
|
||||
//#include "lib/util.hpp"
|
||||
//#include "lib/symbol.hpp"
|
||||
//#include "include/logging.h"
|
||||
#include "gui/model/element.hpp"
|
||||
#include "gui/test/nexus.hpp"
|
||||
|
||||
//#include <boost/noncopyable.hpp>
|
||||
#include <string>
|
||||
110
tests/gui/test/nexus.hpp
Normal file
110
tests/gui/test/nexus.hpp
Normal file
|
|
@ -0,0 +1,110 @@
|
|||
/*
|
||||
test/NEXUS.hpp - fake user interface backbone for test support
|
||||
|
||||
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 test/nexus.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
|
||||
**
|
||||
*/
|
||||
|
||||
|
||||
#ifndef GUI_TEST_NEXUS_H_
|
||||
#define GUI_TEST_NEXUS_H_
|
||||
|
||||
|
||||
#include "lib/error.hpp"
|
||||
#include "lib/idi/entry-id.hpp"
|
||||
//#include "lib/util.hpp"
|
||||
#include "gui/model/tangible.hpp"
|
||||
#include "lib/diff/record.hpp"
|
||||
|
||||
#include <boost/noncopyable.hpp>
|
||||
#include <string>
|
||||
|
||||
|
||||
namespace gui {
|
||||
namespace test{
|
||||
|
||||
// using lib::HashVal;
|
||||
// using util::isnil;
|
||||
using lib::idi::EntryID;
|
||||
using lib::diff::Record;
|
||||
using std::string;
|
||||
|
||||
|
||||
/**
|
||||
* 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 Nexus
|
||||
: boost::noncopyable
|
||||
{
|
||||
|
||||
/* ==== Tangible interface ==== */
|
||||
|
||||
virtual void
|
||||
act (GenNode command) override
|
||||
{
|
||||
UNIMPLEMENTED ("");
|
||||
}
|
||||
virtual void note (GenNode mark) =0;
|
||||
virtual void mark (GenNode mark) =0;
|
||||
|
||||
virtual void act (EntryID subject, GenNode command) =0;
|
||||
virtual void note (EntryID subject, GenNode mark) =0;
|
||||
virtual void mark (EntryID subject, GenNode mark) =0;
|
||||
|
||||
|
||||
protected:
|
||||
public:
|
||||
explicit
|
||||
MockElm(string id)
|
||||
: gui::model::Tangible(TODO_generate_identity, TestNexus::hook())
|
||||
{ }
|
||||
|
||||
explicit
|
||||
MockElm(EntryID identity, ctrl::BusTerm&& nexus =TestNexus::hook())
|
||||
{ }
|
||||
};
|
||||
|
||||
|
||||
|
||||
}} // namespace gui::test
|
||||
#endif /*GUI_TEST_NEXUS_H_*/
|
||||
152
tests/library/test/test-event-log-test.cpp
Normal file
152
tests/library/test/test-event-log-test.cpp
Normal file
|
|
@ -0,0 +1,152 @@
|
|||
/*
|
||||
TestEventLog(Test) - helper for event registration and verification
|
||||
|
||||
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.
|
||||
|
||||
* *****************************************************/
|
||||
|
||||
|
||||
#include "lib/test/run.hpp"
|
||||
#include "lib/test/test-helper.hpp"
|
||||
#include "lib/error.hpp"
|
||||
#include "lib/util-foreach.hpp"
|
||||
|
||||
#include <boost/algorithm/string.hpp>
|
||||
#include <functional>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
using util::for_each;
|
||||
using lumiera::Error;
|
||||
using lumiera::LUMIERA_ERROR_EXCEPTION;
|
||||
using lumiera::error::LUMIERA_ERROR_ASSERTION;
|
||||
|
||||
using boost::algorithm::is_lower;
|
||||
using boost::algorithm::is_digit;
|
||||
using std::function;
|
||||
using std::string;
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
|
||||
|
||||
namespace lib {
|
||||
namespace test{
|
||||
namespace test{
|
||||
|
||||
template<class T>
|
||||
class Wrmrmpft
|
||||
{
|
||||
T tt_;
|
||||
};
|
||||
|
||||
struct Murpf { };
|
||||
|
||||
|
||||
void doThrow() { throw Error("because I feel like it"); }
|
||||
int dontThrow() { return 2+2; }
|
||||
|
||||
|
||||
/*********************************************//**
|
||||
* verifies the proper working of helper functions
|
||||
* frequently used within the Lumiera testsuite.
|
||||
* @see test-helper.hpp
|
||||
*/
|
||||
class TestEventLog_test : public Test
|
||||
{
|
||||
void
|
||||
run (Arg)
|
||||
{
|
||||
checkGarbageStr();
|
||||
checkTypeDisplay();
|
||||
checkThrowChecker();
|
||||
}
|
||||
|
||||
|
||||
/** @test prints "sizeof()" including some type name. */
|
||||
void
|
||||
checkTypeDisplay ()
|
||||
{
|
||||
std::cout << "Displaying types and sizes....\n";
|
||||
|
||||
typedef Wrmrmpft<Murpf> Wrmpf1;
|
||||
typedef Wrmrmpft<char[2]> Wrmpf2;
|
||||
typedef Wrmrmpft<char[3]> Wrmpf3;
|
||||
|
||||
Wrmpf1 rmpf1;
|
||||
Wrmpf2 rmpf2;
|
||||
Wrmpf3 rmpf3;
|
||||
Murpf murpf;
|
||||
|
||||
CHECK (1 == sizeof (rmpf1));
|
||||
CHECK (2 == sizeof (rmpf2));
|
||||
CHECK (3 == sizeof (rmpf3));
|
||||
|
||||
cout << showSizeof((size_t)42, "theUniverse") << endl;
|
||||
cout << showSizeof<char>("just a char") << endl;
|
||||
cout << showSizeof(murpf) << endl;
|
||||
cout << showSizeof(rmpf1) << endl;
|
||||
cout << showSizeof(rmpf2) << endl;
|
||||
cout << showSizeof<Wrmpf3>() << endl;
|
||||
|
||||
Wrmpf1 *p1 = &rmpf1;
|
||||
Wrmpf1 *p2 = 0;
|
||||
cout << showSizeof(p1) << endl;
|
||||
cout << showSizeof(p2) << endl;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void
|
||||
checkGarbageStr()
|
||||
{
|
||||
string garN = randStr(0);
|
||||
CHECK (0 == garN.size());
|
||||
|
||||
typedef function<bool(string::value_type)> ChPredicate;
|
||||
ChPredicate is_OK (is_lower() || is_digit());
|
||||
|
||||
string garM = randStr(1000000);
|
||||
for_each (garM, is_OK);
|
||||
|
||||
cout << randStr(80) << endl;
|
||||
}
|
||||
|
||||
|
||||
/** @test check the VERIFY_ERROR macro,
|
||||
* which ensures a given error is raised.
|
||||
*/
|
||||
void
|
||||
checkThrowChecker()
|
||||
{
|
||||
// verify the exception is indeed raised
|
||||
VERIFY_ERROR (EXCEPTION, doThrow() );
|
||||
|
||||
#if false ///////////////////////////////////////////////////////////////////////////////////////////////TICKET #537 : restore throwing ASSERT
|
||||
// and when actually no exception is raised, this is an ASSERTION failure
|
||||
VERIFY_ERROR (ASSERTION, VERIFY_ERROR (EXCEPTION, dontThrow() ));
|
||||
#endif ///////////////////////////////////////////////////////////////////////////////////////////////TICKET #537 : restore throwing ASSERT
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
LAUNCHER (TestEventLog_test, "unit common");
|
||||
|
||||
|
||||
}}} // namespace lib::test::test
|
||||
|
||||
Loading…
Reference in a new issue