API
testMacrosINDI.hpp
Go to the documentation of this file.
1 
2 #ifndef testMacrosINDI_hpp
3 #define testMacrosINDI_hpp
4 
5 /// This turns on the success-return in the callback validator
6 /** See \ref INDI_VALIDATE_CALLBACK_PROPS and \ref INDI_VALIDATE_CALLBACK_PROPS_DERIVED
7  *
8  * \ingroup test_indi
9  */
10 #define XWCTEST_INDI_CALLBACK_VALIDATION
11 
12 /// Make an indi property variable name
13 /** This takes m_indiP_ and voltage and creates m_indiP_voltage, which is the standard way
14  * to name an INDI property which takes new requests.
15  *
16  * \param stub [in] the first part of the variable name, e.g. m_indiP_
17  * \param propname [in] the property name, e.g. voltage
18  *
19  * \ingroup test_indi
20  */
21 #define XWCTEST_MAKE_INDI_PROP( stub, \
22  propname \
23  ) \
24  stub ## propname
25 
26 #define XWCTEST_SETUP_INDI_NEW_PROP( propname ) \
27  XWCTEST_MAKE_INDI_PROP(m_indiP_, propname).setDevice(m_configName); \
28  XWCTEST_MAKE_INDI_PROP(m_indiP_, propname).setName(#propname);
29 
30 #define XWCTEST_SETUP_INDI_ARB_NEW_PROP(varname, propname) \
31  varname.setDevice(m_configName); \
32  varname.setName(#propname);
33 
34 #define XWCTEST_SETUP_INDI_ARB_PROP( varname, device, propname ) \
35  varname.setDevice(#device); \
36  varname.setName(#propname);
37 
38 #define XWCTEST_MAKE_INDI_CALLBACK( stub, callback) stub ## callback
39 
40 /// Catch-2 tests for whether a NEW callback properly validates the input property properly.
41 /**
42  * \param testclass [in] the name of class being tested
43  * \param propname [in] the in-INDI name of the property
44  *
45  * \ingroup test_indi
46  */
47 #define XWCTEST_INDI_NEW_CALLBACK( testclass, \
48  propname \
49  ) \
50  GIVEN("A New Callback for " # propname ) \
51  { \
52  WHEN("Wrong Device") \
53  { \
54  testclass ## _test sdgt("right"); \
55  pcf::IndiProperty ip; \
56  ip.setDevice("wrong"); \
57  ip.setName( #propname ); \
58  int rv = sdgt.XWCTEST_MAKE_INDI_CALLBACK(newCallBack_m_indiP_,propname)(ip); \
59  REQUIRE(rv == -1); \
60  } \
61  WHEN("Wrong name") \
62  { \
63  testclass ## _test sdgt("right"); \
64  pcf::IndiProperty ip; \
65  ip.setDevice("right"); \
66  ip.setName("wrong"); \
67  int rv = sdgt.XWCTEST_MAKE_INDI_CALLBACK(newCallBack_m_indiP_,propname)(ip); \
68  REQUIRE(rv == -1); \
69  } \
70  WHEN("Right Device.Name") \
71  { \
72  testclass ## _test sdgt("right"); \
73  pcf::IndiProperty ip; \
74  ip.setDevice("right"); \
75  ip.setName( #propname ); \
76  int rv = sdgt.XWCTEST_MAKE_INDI_CALLBACK(newCallBack_m_indiP_,propname)(ip); \
77  REQUIRE(rv == 0); \
78  } \
79  }
80 
81 /// Catch-2 tests for whether a SET callback properly validates the input property properly.
82 /**
83  * \param testclass [in] the class being tested
84  * \param varname [in] the in-class variable name
85  * \param device [in] the device source of the property
86  * \param propname [in] the in-INDI name of the property
87  *
88  * \ingroup test_indi
89  */
90 #define XWCTEST_INDI_SET_CALLBACK( testclass, \
91  varname, \
92  device, \
93  propname \
94  ) \
95  GIVEN("A Set Callback for " # propname ) \
96  { \
97  WHEN("Wrong Device") \
98  { \
99  testclass ## _test sdgt("right"); \
100  pcf::IndiProperty ip; \
101  ip.setDevice("wrong"); \
102  ip.setName( #propname ); \
103  int rv = sdgt.XWCTEST_MAKE_INDI_CALLBACK(setCallBack_,varname)(ip); \
104  REQUIRE(rv == -1); \
105  } \
106  WHEN("Wrong name") \
107  { \
108  testclass ## _test sdgt("right"); \
109  pcf::IndiProperty ip; \
110  ip.setDevice(#device); \
111  ip.setName("wrong"); \
112  int rv = sdgt.XWCTEST_MAKE_INDI_CALLBACK(setCallBack_,varname)(ip); \
113  REQUIRE(rv == -1); \
114  } \
115  WHEN("Right Device.Name") \
116  { \
117  testclass ## _test sdgt("right"); \
118  pcf::IndiProperty ip; \
119  ip.setDevice(#device); \
120  ip.setName( #propname ); \
121  int rv = sdgt.XWCTEST_MAKE_INDI_CALLBACK(setCallBack_,varname)(ip); \
122  REQUIRE(rv == 0); \
123  } \
124  }
125 
126 
127 /// Catch-2 tests for whether an arbitrary callback properly validates the input property properly.
128 /**
129  * \param testclass [in] the class being tested
130  * \param callback [in] the name of the callback
131  * \param device [in] the device source of the property
132  * \param propname [in] the in-INDI name of the property
133  *
134  * \ingroup test_indi
135  */
136 #define XWCTEST_INDI_ARBNEW_CALLBACK( testclass, \
137  callback, \
138  propname \
139  ) \
140  GIVEN("A Callback for " # propname ) \
141  { \
142  WHEN("Wrong Device") \
143  { \
144  testclass ## _test sdgt("right"); \
145  pcf::IndiProperty ip; \
146  ip.setDevice("wrong"); \
147  ip.setName( #propname ); \
148  int rv = sdgt. callback (ip); \
149  REQUIRE(rv == -1); \
150  } \
151  WHEN("Wrong name") \
152  { \
153  testclass ## _test sdgt("right"); \
154  pcf::IndiProperty ip; \
155  ip.setDevice("right"); \
156  ip.setName("wrong" #propname ); \
157  int rv = sdgt. callback (ip); \
158  REQUIRE(rv == -1); \
159  } \
160  WHEN("Right Device.Name") \
161  { \
162  testclass ## _test sdgt("right"); \
163  pcf::IndiProperty ip; \
164  ip.setDevice("right"); \
165  ip.setName( #propname ); \
166  int rv = sdgt. callback (ip); \
167  REQUIRE(rv == 0); \
168  } \
169  }
170 #endif