Lumiera  0.pre.03
»edit your freedom«
test-helper.hpp File Reference

Go to the source code of this file.

Description

A collection of frequently used helper functions to support unit testing.

Some are test data generators, some are diagnostics helpers to produce readable output. Some of these support meta programming to figure out the actual reference kind (value, lvalue, rvalue) of a template parameter instantiation. For GNU compatible compilers, we expose also the interface to the internal ABI for demangling type names.

Note
this header is included into a large number of tests.
See also
TestHelper_test
TestHelperDemangling_test

Definition in file test-helper.hpp.

#include "lib/symbol.hpp"
#include "lib/time/timevalue.hpp"
#include "lib/format-obj.hpp"
#include <boost/lexical_cast.hpp>
#include <typeinfo>
#include <cstdlib>
#include <string>

Classes

class  ExpectString
 Helper to produce better diagnostic messages when comparing to an expected result string. More...
 
struct  TypeDebugger< X >
 Helper to show types involved in metaprogramming. More...
 
struct  TypeDiagnostics< X >
 
struct  TypeDiagnostics< const X * >
 
struct  TypeDiagnostics< const X *const >
 
struct  TypeDiagnostics< const X >
 
struct  TypeDiagnostics< X & >
 
struct  TypeDiagnostics< X && >
 
struct  TypeDiagnostics< X * >
 
struct  TypeDiagnostics< X *const * >
 
struct  TypeDiagnostics< X *const >
 
struct  TypeDiagnostics< X const & >
 
struct  TypeDiagnostics< X const && >
 

Macros

#define MARK_TEST_FUN   cout << "|" << endl << "| »"<<__FUNCTION__<<"«" <<endl;
 Macro to mark the current test function in STDOUT. More...
 
#define VERIFY_ERROR(ERROR_ID, ERRONEOUS_STATEMENT)
 Macro to verify a statement indeed raises an exception. More...
 

Functions

lib::test::ExpectString operator""_expect (const char *lit, size_t siz)
 
string randStr (size_t len)
 create garbage string of given length More...
 
lib::time::Time randTime ()
 create a random but not insane Time value between 1s ... More...
 
template<typename R >
string showRefKind ()
 helper to discern the kind of reference of the argument type
 
string showSizeof (size_t siz, string name)
 for printing sizeof(). More...
 
template<typename T >
string showSizeof (T const *obj=0, const char *name=0)
 for printing sizeof(), possibly figuring out the type name automatically More...
 
template<typename T >
meta::disable_if< std::is_pointer< T >, string > showSizeof (T const &obj, const char *name=0)
 
template<typename T >
string showSizeof (const char *name)
 
template<typename X >
string showType ()
 diagnostic type output, including const and similar adornments More...
 
template<typename... EMPTY>
string showVariadicTypes ()
 helper for investigating a variadic argument pack More...
 
template<typename X , typename... XS>
string showVariadicTypes (X const &x, XS const &... xs)
 
template<typename X >
void typeDebugger (X &&x)
 

Namespaces

 lib
 Implementation namespace for support and library code.
 

Macro Definition Documentation

◆ VERIFY_ERROR

#define VERIFY_ERROR (   ERROR_ID,
  ERRONEOUS_STATEMENT 
)
Value:
try \
{ \
ERRONEOUS_STATEMENT ; \
NOTREACHED("expected '%s' failure in: %s", \
#ERROR_ID, #ERRONEOUS_STATEMENT); \
} \
catch (lumiera::Error& ex) \
{ \
CHECK (ex.getID() \
== lib::test::ExpectString{LUMIERA_ERROR_##ERROR_ID} );\
lumiera_error(); \
} \
catch (...) \
{ \
CHECK (lumiera_error_peek() \
== lib::test::ExpectString{LUMIERA_ERROR_##ERROR_ID} ); \
lumiera_error(); \
}
Helper to produce better diagnostic messages when comparing to an expected result string...
lumiera_err lumiera_error_peek(void)
Check current error state without clearing it Please avoid this function and use lumiera_error() if p...
Definition: error-state.c:142
Interface and Base definition for all Lumiera Exceptions.
Definition: error.hpp:69

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.

Definition at line 344 of file test-helper.hpp.

Referenced by CustomSharedPtr_test::check_ordering(), ScopePath_test::check_RefcountProtection(), EntryID_test::checkErasure(), TestHelper_test::checkThrowChecker(), TimeValue_test::checkTimeHash(), DiffIgnoreChanges_test::fail_or_ignore(), DispatcherInterface_test::resolveModelPort(), DiagnosticContext_test::verify_simpleAccess(), WLink_test::verify_standardUsage(), DependencyConfiguration_test::verify_SubclassSingleton(), and ItemWrapper_test::verifyFunctionResult().

◆ MARK_TEST_FUN

Function Documentation

◆ showSizeof() [1/2]

string showSizeof ( size_t  siz,
string  name 
)

for printing sizeof().

prints the given size and name literally, without any further magic

Examples:
/Werk/devel/lumi/src/lib/test/test-helper.hpp.

Definition at line 57 of file test-helper.cpp.

References lib::test::showSizeof().

Referenced by TestHelper_test::checkTypeDisplay(), and lib::test::showSizeof().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ showSizeof() [2/2]

string lib::test::showSizeof ( T const *  obj = 0,
const char *  name = 0 
)
inline

for printing sizeof(), possibly figuring out the type name automatically

Parameters
namewhen given, this name will be used for display, instead of auto detecting the type

Definition at line 76 of file test-helper.hpp.

◆ showVariadicTypes()

string lib::test::showVariadicTypes ( )
inline

helper for investigating a variadic argument pack

Warning
always spell out the template arguments explicitly when invoking this diagnostics, e.g. showVariadicTypes<ARGS...>(args...) otherwise the template argument matching for functions might mess up the kind of reference you'll see in the diagnostics.
See also
test-helper-variadic-test.cpp
Examples:
/Werk/devel/lumi/src/lib/test/test-helper.hpp.

Definition at line 118 of file test-helper.hpp.

Referenced by TestHelperVariadic_test::forwardFunction().

+ Here is the caller graph for this function:

◆ showType()

string lib::test::showType ( )
inline

diagnostic type output, including const and similar adornments

Warning
operates after-the-fact and relies on mangled type names plus several heuristics. Output might thus not be entirely correct, especially when several levels of const, pointer and references are involved. If in doubt, place the TypeDebugger<T> to reveal the type as the compiler sees it.
Remarks
the function lib::meta::typeStr removes adornments and does not work on all kinds of reference. This helper attempts to work around those limitations.
Examples:
/Werk/devel/lumi/src/lib/test/test-helper.hpp.

Definition at line 250 of file test-helper.hpp.

References lib::test::showType().

Referenced by lib::test::showType().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ randTime()

lib::time::Time lib::test::randTime ( )
inline

create a random but not insane Time value between 1s ...

10min + 500ms

Examples:
/Werk/devel/lumi/src/lib/test/test-helper.hpp.

Definition at line 265 of file test-helper.hpp.

References lib::test::randTime().

Referenced by lib::test::randTime().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ randStr()

string randStr ( size_t  len)

create garbage string of given length

Todo:
probably this can be done in a more clever way.

Anyone...?

Returns
string containing arbitrary lower case letters and numbers
Examples:
/Werk/devel/lumi/src/lib/test/test-helper.hpp.

Definition at line 69 of file test-helper.cpp.

References lib::test::randStr().

Referenced by TestHelper_test::checkTypeDisplay(), and lib::test::randStr().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: