Pothos  0.1.1
The Pothos dataflow programming software suite
 All Classes Namespaces Files Functions Variables Typedefs Friends Macros
Classes | Namespaces | Macros
Testing.hpp File Reference
#include <Pothos/Config.hpp>
#include <Pothos/Plugin.hpp>
#include <Pothos/Callable.hpp>
#include <Pothos/Exception.hpp>
#include <sstream>
#include <memory>
#include <string>

Go to the source code of this file.

Classes

struct  Pothos::TestingBase
 

Namespaces

 Pothos
 

Macros

#define POTHOS_TEST_BLOCK(path, name)
 
#define POTHOS_TEST_CHECKPOINT()   Pothos::TestingBase::current().report("checkpoint", "", "", __LINE__, __FILE__)
 Checkpoint macro to track last successful line executed. More...
 
#define __POTHOS_TEST_STATEMENT(message, statement)
 Private macro to test a statement for exceptions. More...
 
#define __POTHOS_TEST_ASSERT(message, statement)
 Private macro to assert on a statement's truth. More...
 
#define POTHOS_TEST_TRUE(statement)
 Test if statement is true. More...
 
#define POTHOS_TEST_EQUAL(lhs, rhs)
 Test if an equality operation is true. More...
 
#define POTHOS_TEST_EQUALV(lhs, rhs)
 Test two vectors for equality. More...
 
#define POTHOS_TEST_THROWS(statement, expectedException)
 Test that a statement throws a particular exception. More...
 

Detailed Description

Macros for creating self-test plugins. Self tests are installed into the registry and executed at runtime. The test macros are loosely based on the Boost unit test suite.

Macro Definition Documentation

#define __POTHOS_TEST_ASSERT (   message,
  statement 
)
Value:
{ \
__POTHOS_TEST_STATEMENT(message, if (statement) {} else throw std::string("statement \"" #statement "\" evaluated false");); \
}
#define __POTHOS_TEST_STATEMENT(message, statement)
Private macro to test a statement for exceptions.
Definition: Testing.hpp:63

Private macro to assert on a statement's truth.

#define __POTHOS_TEST_STATEMENT (   message,
  statement 
)
Value:
{ \
Pothos::TestingBase::current().report(message, #statement, "", __LINE__, __FILE__); \
try{statement;} \
catch(const std::string &ex){Pothos::TestingBase::current().report(message, #statement, ex, __LINE__, __FILE__);} \
catch(const Pothos::Exception &ex){Pothos::TestingBase::current().report(message, #statement, ex.displayText(), __LINE__, __FILE__);} \
catch(const std::exception &ex){Pothos::TestingBase::current().report(message, #statement, ex.what(), __LINE__, __FILE__);} \
catch(...){Pothos::TestingBase::current().report(message, #statement, "unknown", __LINE__, __FILE__);} \
}
std::string displayText() const
Returns the exception code if defined.
static TestingBase & current(void)
Definition: Exception.hpp:65
void report(const std::string &message, const std::string &statement, const std::string &error, const int line, const std::string &file)

Private macro to test a statement for exceptions.

#define POTHOS_TEST_BLOCK (   path,
  name 
)
Value:
struct name : Pothos::TestingBase \
{ \
void runTestsImpl(void); \
void runTestsImpl_(void); \
}; \
{ \
std::shared_ptr<Pothos::TestingBase> testObj(new name()); \
Pothos::PluginPath(path).join(#name), Pothos::Object(testObj))); \
} \
void name::runTestsImpl(void) \
{ \
this->runTestsImpl_(); \
} \
void name::runTestsImpl_(void)
#define POTHOS_TEST_CHECKPOINT()
Checkpoint macro to track last successful line executed.
Definition: Testing.hpp:59
static void add(const Plugin &plugin)
#define pothos_static_block(name)
Definition: Static.hpp:46
Definition: Object.hpp:55
Definition: Testing.hpp:116
Definition: Path.hpp:24
Definition: Plugin.hpp:23
virtual void runTestsImpl()=0

Declare a unit test block of code inside a plugin.

The unit test will be installed into /path/name in the PluginRegistry. Once installed, this unit test can be checked with the test utility.

Parameters
patha valid PluginPath
namea valid function name

Example usage:

POTHOS_TEST_BLOCK("/sys/foo", test_bar)
{
}
#define POTHOS_TEST_CHECKPOINT ( )    Pothos::TestingBase::current().report("checkpoint", "", "", __LINE__, __FILE__)

Checkpoint macro to track last successful line executed.

#define POTHOS_TEST_EQUAL (   lhs,
  rhs 
)
Value:
{ \
" == " + Pothos::TestingBase::current().toString(rhs), (lhs) == (rhs)); \
}
#define __POTHOS_TEST_ASSERT(message, statement)
Private macro to assert on a statement's truth.
Definition: Testing.hpp:74
static TestingBase & current(void)

Test if an equality operation is true.

#define POTHOS_TEST_EQUALV (   lhs,
  rhs 
)
Value:
{ \
POTHOS_TEST_EQUAL((lhs).size(), (rhs).size()); \
for (size_t i = 0; i < (lhs).size(); i++) \
{ \
"index " + Pothos::TestingBase::current().toString(i) + \
" asserts " + Pothos::TestingBase::current().toString((lhs)[i]) + \
" == " + Pothos::TestingBase::current().toString((rhs)[i]), (lhs)[i] == (rhs)[i]); \
} \
}
#define __POTHOS_TEST_ASSERT(message, statement)
Private macro to assert on a statement's truth.
Definition: Testing.hpp:74
static TestingBase & current(void)
#define POTHOS_TEST_EQUAL(lhs, rhs)
Test if an equality operation is true.
Definition: Testing.hpp:86

Test two vectors for equality.

#define POTHOS_TEST_THROWS (   statement,
  expectedException 
)
Value:
{ \
Pothos::TestingBase::current().report(#statement, #statement, "", __LINE__, __FILE__); \
__POTHOS_TEST_STATEMENT(#statement " must throw " #expectedException, \
try{statement;throw std::string("statement \"" #statement "\" did not throw");} \
catch(const expectedException &){}); \
}
static TestingBase & current(void)
#define __POTHOS_TEST_STATEMENT(message, statement)
Private macro to test a statement for exceptions.
Definition: Testing.hpp:63
void report(const std::string &message, const std::string &statement, const std::string &error, const int line, const std::string &file)

Test that a statement throws a particular exception.

#define POTHOS_TEST_TRUE (   statement)
Value:
{ \
__POTHOS_TEST_ASSERT(#statement, statement) \
}
#define __POTHOS_TEST_ASSERT(message, statement)
Private macro to assert on a statement's truth.
Definition: Testing.hpp:74

Test if statement is true.