PVData C++ 8.0.7
Loading...
Searching...
No Matches
Unit testing helpers

Macros

#define TEST_METHOD(klass, method)
 
#define testEqual(LHS, RHS)
 
#define testNotEqual(LHS, RHS)
 
#define testTrue(B)
 
#define testThrows(EXC, CODE)
 
#define testShow()
 

Functions

template<typename PVD >
::detail::testPassx testFieldEqual (const std::tr1::shared_ptr< const epics::pvData::PVStructure > &val, const char *name, typename PVD::value_type expect)
 
template<typename PVD >
::detail::testPassx testFieldEqual (const std::tr1::shared_ptr< const epics::pvData::PVStructure > &val, const char *name, typename PVD::const_svector expect)
 

Detailed Description

Helper functions for writing unit tests.

/*
* Copyright information and license terms for this software can be
* found in the file LICENSE that is included with the distribution
*/
/* c++ unittest skeleton */
#include <stdexcept>
#include <testMain.h>
#include <pv/pvUnitTest.h>
#include <pv/epicsException.h>
namespace {
void testCase1() {
testEqual(1+1, 2);
}
} // namespace
MAIN(testUnitTest)
{
testPlan(1);
try {
testCase1();
}catch(std::exception& e){
PRINT_EXCEPTION(e); // print stack trace if thrown with THROW_EXCEPTION()
testAbort("Unhandled exception: %s", e.what());
}
return testDone();
}
virtual const char * what() const noexcept
#define testEqual(LHS, RHS)
Definition pvUnitTest.h:110

Macro Definition Documentation

◆ TEST_METHOD

#define TEST_METHOD ( klass,
method )
Value:
::detail::test_method<klass, &klass::method>(#klass, #method)

Run a class method as a test.

Each invocation of TEST_METHOD() constructs a new instance of 'klass' on the stack. Thus constructor and destructor can be used for common test setup and tear down.

namespace { // anon
struct MyTest {
MyTest() { } // setup
~MyTest() { } // tear down
void test1() {}
void test2() {}
};
} // namespace anon
MAIN(somename) {
testPlan(0);
TEST_METHOD(MyTest, test1)
TEST_METHOD(MyTest, test2)
return testDone();
}
#define TEST_METHOD(klass, method)
Definition pvUnitTest.h:98

Definition at line 98 of file pvUnitTest.h.

◆ testEqual

#define testEqual ( LHS,
RHS )
Value:
::detail::testEqualx(#LHS, #RHS, LHS, RHS)

Compare equality. print left and right hand values and expression strings

int x=5;
testEqual(x, 5);
// prints "ok 1 - x (5) == 5 (5)\n"
testEqual(x, 6)<<" oops";
// prints "not ok 1 - x (5) == 6 (6) oops\n"

Definition at line 110 of file pvUnitTest.h.

◆ testNotEqual

#define testNotEqual ( LHS,
RHS )
Value:
::detail::testNotEqualx(#LHS, #RHS, LHS, RHS)

Definition at line 112 of file pvUnitTest.h.

◆ testShow

#define testShow ( )
Value:

Print test output w/o testing

testShow()<<"Foo";
#define testShow()
Definition pvUnitTest.h:140

Definition at line 140 of file pvUnitTest.h.

◆ testThrows

#define testThrows ( EXC,
CODE )
Value:
try{ CODE; testFail("unexpected success of " #CODE); }catch(EXC& e){testPass("catch expected exception: %s", e.what());}

Test that a given block throws an exception

#define testThrows(EXC, CODE)
Definition pvUnitTest.h:132

Definition at line 132 of file pvUnitTest.h.

◆ testTrue

#define testTrue ( B)
Value:

Pass/fail from boolean

bool y=true;
// prints "ok 1 - y\n"
testTrue(!y)<<" oops";
// prints "not ok 1 - !y oops\n"
#define testTrue(B)
Definition pvUnitTest.h:124

Definition at line 124 of file pvUnitTest.h.

Function Documentation

◆ testFieldEqual() [1/2]

template<typename PVD >
::detail::testPassx testFieldEqual ( const std::tr1::shared_ptr< const epics::pvData::PVStructure > & val,
const char * name,
typename PVD::const_svector expect )

Definition at line 172 of file pvUnitTest.h.

◆ testFieldEqual() [2/2]

template<typename PVD >
::detail::testPassx testFieldEqual ( const std::tr1::shared_ptr< const epics::pvData::PVStructure > & val,
const char * name,
typename PVD::value_type expect )

Compare value of PVStructure field

PVStructurePtr x(.....);
testFieldEqual<epics::pvData::PVInt>(x, "alarm.severity", 1);
::detail::testPassx testFieldEqual(const std::tr1::shared_ptr< const epics::pvData::PVStructure > &val, const char *name, typename PVD::value_type expect)
Definition pvUnitTest.h:151

Definition at line 151 of file pvUnitTest.h.