11 #include <epicsUnitTest.h>
14 #include <pv/epicsException.h>
15 #include <pv/pvData.h>
19 template<
class C,
void (C::*M)()>
20 void test_method(
const char *kname,
const char *mname)
23 testDiag(
"------- %s::%s --------", kname, mname);
28 testAbort(
"unexpected exception: %s", e.
what());
35 const bool dotest, pass;
38 testPassx() :dotest(
false), pass(
false), alive(
true) {}
39 explicit testPassx(
bool r) :dotest(
true), pass(r), alive(
true) {}
54 template<
typename LHS,
typename RHS>
55 inline testPassx testEqualx(
const char *nLHS,
const char *nRHS,
const LHS& l,
const RHS& r)
57 return testPassx(l==r)<<nLHS<<
" ("<<l<<
") == "<<nRHS<<
" ("<<r<<
")";
60 template<
typename LHS,
typename RHS>
61 inline testPassx testNotEqualx(
const char *nLHS,
const char *nRHS,
const LHS& l,
const RHS& r)
63 return testPassx(l!=r)<<nLHS<<
" ("<<l<<
") != "<<nRHS<<
" ("<<r<<
")";
98 #define TEST_METHOD(klass, method) ::detail::test_method<klass, &klass::method>(#klass, #method)
110 #define testEqual(LHS, RHS) ::detail::testEqualx(#LHS, #RHS, LHS, RHS)
112 #define testNotEqual(LHS, RHS) ::detail::testNotEqualx(#LHS, #RHS, LHS, RHS)
124 #define testTrue(B) ::detail::testPassx(!!(B))<<#B
132 #define testThrows(EXC, CODE) try{ CODE; testFail("unexpected success of " #CODE); }catch(EXC& e){testPass("catch expected exception: %s", e.what());}
140 #define testShow() ::detail::testPassx()
149 template<
typename PVD>
151 testFieldEqual(
const std::tr1::shared_ptr<const epics::pvData::PVStructure>& val,
const char *name,
typename PVD::value_type expect)
154 return ::detail::testPassx(
false)<<
" null structure pointer";
156 typename PVD::const_shared_pointer fval(val->getSubField<PVD>(name));
160 fval = uval->get<PVD>();
163 return ::detail::testPassx(
false)<<
" field '"<<name<<
"' with type "<<
typeid(PVD).name()<<
" does not exist";
165 typename PVD::value_type actual(fval->get());
166 return ::detail::testPassx(actual==expect)<<name<<
" ("<<actual<<
") == "<<expect;
170 template<
typename PVD>
172 testFieldEqual(
const std::tr1::shared_ptr<const epics::pvData::PVStructure>& val,
const char *name,
typename PVD::const_svector expect)
175 return ::detail::testPassx(
false)<<
" null structure pointer";
177 typename PVD::const_shared_pointer fval(val->getSubField<PVD>(name));
179 return ::detail::testPassx(
false)<<
" field '"<<name<<
"' with type "<<
typeid(PVD).name()<<
" does not exist";
181 typename PVD::const_svector actual(fval->view());
182 return ::detail::testPassx(actual==expect)<<name<<
" ("<<actual<<
") == "<<expect;
188 #endif // PVUNITTEST_H
std::basic_ostream< _CharT, _Traits > & operator<<(std::basic_ostream< _CharT, _Traits > &__os, const std::bernoulli_distribution &__x)
virtual const char * what() const noexcept
constexpr complex< _Tp > & operator=(const _Tp &)
PVUnion has a single subfield.
::detail::testPassx testFieldEqual(const std::tr1::shared_ptr< const epics::pvData::PVStructure > &val, const char *name, typename PVD::value_type expect)