PVData C++
8.0.9
Toggle main menu visibility
Loading...
Searching...
No Matches
misc
pv
pvUnitTest.h
1
/*
2
* Copyright information and license terms for this software can be
3
* found in the file LICENSE that is included with the distribution
4
*/
5
#ifndef PVUNITTEST_H
6
#define PVUNITTEST_H
7
8
#include <
sstream
>
9
#include <
typeinfo
>
10
11
#include <epicsUnitTest.h>
12
13
#include <
pv/sharedPtr.h
>
14
#include <pv/epicsException.h>
15
#include <pv/pvData.h>
16
17
namespace
detail {
18
19
template
<
class
C,
void
(C::*M)()>
20
void
test_method(
const
char
*kname,
const
char
*mname)
21
{
22
try
{
23
testDiag(
"------- %s::%s --------"
, kname, mname);
24
C inst;
25
(inst.*M)();
26
}
catch
(std::exception& e) {
27
PRINT_EXCEPTION(e);
28
testAbort(
"unexpected exception: %s"
, e.
what
());
29
}
30
}
31
32
class
epicsShareClass testPassx
33
{
34
std::ostringstream
strm;
35
const
bool
dotest, pass;
36
bool
alive;
37
public
:
38
testPassx() :dotest(
false
), pass(
false
), alive(
true
) {}
39
explicit
testPassx(
bool
r) :dotest(
true
), pass(r), alive(
true
) {}
40
~testPassx();
41
template
<
typename
T>
42
inline
testPassx& operator<<(
const
T& v) {
43
strm<<v;
44
return
*
this
;
45
}
46
47
// allow testPassx to be returned
48
// move ctor masquerading as copy ctor
49
testPassx(testPassx& o);
50
private
:
51
testPassx&
operator=
(
const
testPassx&);
52
};
53
54
template
<
typename
LHS,
typename
RHS>
55
inline
testPassx
testEqualx(
const
char
*nLHS,
const
char
*nRHS,
const
LHS& l,
const
RHS& r)
56
{
57
return
testPassx
(l==r)<<nLHS<<
" ("
<<l<<
") == "
<<nRHS<<
" ("
<<r<<
")"
;
58
}
59
60
template
<
typename
LHS,
typename
RHS>
61
inline
testPassx testNotEqualx(
const
char
*nLHS,
const
char
*nRHS,
const
LHS& l,
const
RHS& r)
62
{
63
return
testPassx(l!=r)<<nLHS<<
" ("
<<l<<
") != "
<<nRHS<<
" ("
<<r<<
")"
;
64
}
65
66
}
//namespace detail
67
74
96
#define TEST_METHOD(klass, method) ::detail::test_method<klass, &klass::method>(#klass, #method)
97
108
#define testEqual(LHS, RHS) ::detail::testEqualx(#LHS, #RHS, LHS, RHS)
109
110
#define testNotEqual(LHS, RHS) ::detail::testNotEqualx(#LHS, #RHS, LHS, RHS)
111
122
#define testTrue(B) ::detail::testPassx(!!(B))<<#B
123
130
#define testThrows(EXC, CODE) try{ CODE; testFail("unexpected success of " #CODE); }catch(EXC& e){testPass("catch expected exception: %s", e.what());}
131
138
#define testShow() ::detail::testPassx()
139
147
template
<
typename
PVD>
148
::detail::testPassx
149
testFieldEqual
(
const
std::tr1::shared_ptr<const epics::pvData::PVStructure>& val,
const
char
*name,
typename
PVD::value_type expect)
150
{
151
if
(!val) {
152
return ::detail::testPassx(
false
)<<
" null structure pointer"
;
153
}
154
typename
PVD::const_shared_pointer fval(val->getSubField<PVD>(name));
155
if
(!fval) {
156
epics::pvData::PVUnion::const_shared_pointer uval(val->getSubField<
epics::pvData::PVUnion
>(name));
157
if
(uval)
158
fval = uval->get<PVD>();
159
}
160
if
(!fval) {
161
return ::detail::testPassx(
false
)<<
" field '"
<<name<<
"' with type "
<<
typeid
(PVD).name()<<
" does not exist"
;
162
}
else
{
163
typename
PVD::value_type actual(fval->get());
164
return ::detail::testPassx(actual==expect)<<name<<
" ("
<<actual<<
") == "
<<expect;
165
}
166
}
167
168
template
<
typename
PVD>
169
::detail::testPassx
170
testFieldEqual
(
const
std::tr1::shared_ptr<const epics::pvData::PVStructure>& val,
const
char
*name,
typename
PVD::const_svector expect)
171
{
172
if
(!val) {
173
return ::detail::testPassx(
false
)<<
" null structure pointer"
;
174
}
175
typename
PVD::const_shared_pointer fval(val->getSubField<PVD>(name));
176
if
(!fval) {
177
return ::detail::testPassx(
false
)<<
" field '"
<<
name
<<
"' with type "
<<
typeid
(PVD).
name
()<<
" does not exist"
;
178
}
else
{
179
typename
PVD::const_svector actual(fval->view());
180
return ::detail::testPassx(actual==expect)<<
name
<<
" ("
<<actual<<
") == "
<<expect;
181
}
182
}
183
185
186
#endif
// PVUNITTEST_H
typeinfo
sstream
operator=
constexpr complex< _Tp > & operator=(const _Tp &)
std::ostringstream
basic_ostringstream< char > ostringstream
std::exception::what
virtual const char * what() const noexcept
detail::testPassx
Definition
pvUnitTest.h:33
epics::pvData::PVUnion
PVUnion has a single subfield.
Definition
pvData.h:945
testFieldEqual
::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
epics::pvData::TypeFunc::name
const char * name(Type type)
sharedPtr.h
Generated on
for PVData C++ by
1.17.0