PVData C++ 8.0.9
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.

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:96

Definition at line 96 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"
#define testEqual(LHS, RHS)
Definition pvUnitTest.h:108

Definition at line 108 of file pvUnitTest.h.

◆ testNotEqual

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

Definition at line 110 of file pvUnitTest.h.

◆ testShow

#define testShow ( )
Value:

Print test output w/o testing

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

Definition at line 138 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:130

Definition at line 130 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:122

Definition at line 122 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 170 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:149

Definition at line 149 of file pvUnitTest.h.