API
 
Loading...
Searching...
No Matches
observerCtrl_targetLogic_test.cpp
Go to the documentation of this file.
1/** \file observerCtrl_test.cpp
2 * \brief Catch2 tests for the observerCtrl app.
3 * \author Jared R. Males (jaredmales@gmail.com)
4 *
5 * History:
6 */
7
8
9
10#include "../../../tests/catch2/catch.hpp"
11#include "../../tests/testMacrosINDI.hpp"
12#undef XWCTEST_INDI_CALLBACK_VALIDATION
13
14#include "../observerCtrl.hpp"
15
16using namespace MagAOX::app;
17
18namespace SMCTEST
19{
20
21class observerCtrl_test : public observerCtrl
22{
23
24public:
47
48 bool & observing()
49 {
50 return m_observing;
51 }
52
53 std::string & catObj()
54 {
55 return m_catObj;
56 }
57
58 std::string & target()
59 {
60 return m_target;
61 }
62
64 {
65 return m_newTargetBlock;
66 }
67
68 bool & newPointing()
69 {
70 return m_newPointing;
71 }
72
73};
74
75
76/// Changing target and catObj name
77/** Test changing target and catalog-object names via INDI
78 *
79 * \ingroup observerCtrl_tests
80 */
81TEST_CASE( "Changing target and catObj name", "[observerCtrl]" )
82{
83 //test that catalog callback fails if no "object" element
84 SECTION( "Catalog updates, no object in INDI prop" )
85 {
86 pcf::IndiProperty ip( pcf::IndiProperty::Text );
87
88 ip.setDevice( "tcsi" );
89 ip.setName( "catalog" );
90 ip.add( pcf::IndiElement( "noobject" ) );
91
92 ip["noobject"] = "target0";
93
94 observerCtrl_test obs("observers");
95
96 int rv = obs.setCallBack_m_indiP_catalog(ip);
97
98 REQUIRE( rv == -1);
99 }
100
101 //test that target callback fails if no current or target element
102 SECTION( "setting target, no current or target" )
103 {
104 pcf::IndiProperty ip( pcf::IndiProperty::Text );
105
106 ip.setDevice( "observers" );
107 ip.setName( "target" );
108 ip.add( pcf::IndiElement( "novalid" ) );
109
110 ip["novalid"] = "target1";
111
112 observerCtrl_test obs("observers");
113
114 int rv = obs.newCallBack_m_indiP_target(ip);
115
116 REQUIRE( rv == -1);
117 }
118
119 //test that tcsTarget callback fails if no current or target element
120 SECTION( "setting tcsTarget, no request" )
121 {
122 pcf::IndiProperty ip( pcf::IndiProperty::Switch );
123
124 ip.setDevice( "observers" );
125 ip.setName( "tcsTarget" );
126 ip.add( pcf::IndiElement( "norequest" ) );
127
128 ip["norequest"].setSwitchState(pcf::IndiElement::On);
129
130 observerCtrl_test obs("observers");
131
132 int rv = obs.newCallBack_m_indiP_tcsTarget(ip);
133
134 REQUIRE( rv == -1);
135 }
136
137 //Set catobj from catalog, target from target, then synchronize
138 SECTION( "Catalog and target, while not observing" )
139 {
140 observerCtrl_test obs("observers");
141 obs.observing() = false;
142 obs.newTargetBlock() = false; //as if an observation has already taken place
143
144 pcf::IndiProperty ip( pcf::IndiProperty::Text );
145
146 ip.setDevice( "tcsi" );
147 ip.setName( "catalog" );
148 ip.add( pcf::IndiElement( "object" ) );
149
150 ip["object"] = "target0";
151
152 int rv = obs.setCallBack_m_indiP_catalog(ip);
153
154 REQUIRE( rv == 0);
155 REQUIRE( obs.catObj() == "target0");
156 REQUIRE( obs.newTargetBlock() == false);
157 REQUIRE( obs.newPointing() == true );
158
159 pcf::IndiProperty ip2( pcf::IndiProperty::Text );
160
161 ip2.setDevice( "observers" );
162 ip2.setName( "target" );
163 ip2.add( pcf::IndiElement( "target" ) );
164
165 ip2["target"] = "target1";
166
167 rv = obs.newCallBack_m_indiP_target(ip2);
168
169 REQUIRE( rv == 0);
170 REQUIRE( obs.target() == "target1");
171 REQUIRE( obs.newTargetBlock() == true);
172 REQUIRE( obs.newPointing() == false );
173
174 pcf::IndiProperty ip3( pcf::IndiProperty::Switch );
175
176 ip3.setDevice( "observers" );
177 ip3.setName( "tcsTarget" );
178 ip3.add( pcf::IndiElement( "request" ) );
179
180 obs.newTargetBlock() = false; //reset to make sure they are toggle correctly
181 obs.newPointing() = true;
182 ip3["request"].setSwitchState(pcf::IndiElement::Off); //Start off
183
184
185 rv = obs.newCallBack_m_indiP_tcsTarget(ip3);
186
187 REQUIRE( rv == 0);
188 REQUIRE( obs.catObj() == "target0");
189 REQUIRE( obs.target() == "target1");
190 REQUIRE( obs.newTargetBlock() == false);
191 REQUIRE( obs.newPointing() == true );
192
193 //now trigger change
194 ip3["request"].setSwitchState(pcf::IndiElement::On);
195
196 rv = obs.newCallBack_m_indiP_tcsTarget(ip3);
197
198 REQUIRE( rv == 0);
199 REQUIRE( obs.catObj() == "target0");
200 REQUIRE( obs.target() == "target0");
201 REQUIRE( obs.newTargetBlock() == true);
202 REQUIRE( obs.newPointing() == false );
203
204 }
205
206 //Set catobj from catalog, target from target, then synchronize
207 SECTION( "Catalog and target, while observing" )
208 {
209 observerCtrl_test obs("observers");
210 obs.observing() = true;
211 obs.newTargetBlock() = false; //as if an observation has already taken place
212
213 pcf::IndiProperty ip( pcf::IndiProperty::Text );
214
215 ip.setDevice( "tcsi" );
216 ip.setName( "catalog" );
217 ip.add( pcf::IndiElement( "object" ) );
218
219 ip["object"] = "target0";
220
221 int rv = obs.setCallBack_m_indiP_catalog(ip);
222
223 REQUIRE( rv == 0);
224 REQUIRE( obs.catObj() == "target0");
225 REQUIRE( obs.newTargetBlock() == false);
226 REQUIRE( obs.newPointing() == true );
227
228 pcf::IndiProperty ip2( pcf::IndiProperty::Text );
229
230 ip2.setDevice( "observers" );
231 ip2.setName( "target" );
232 ip2.add( pcf::IndiElement( "target" ) );
233
234 ip2["target"] = "target1";
235
236 rv = obs.newCallBack_m_indiP_target(ip2);
237
238 REQUIRE( rv == -2);
239 REQUIRE( obs.catObj() == "target0");
240 REQUIRE( obs.target() == "");
241 REQUIRE( obs.newTargetBlock() == false);
242 REQUIRE( obs.newPointing() == true ); //still true
243
244 pcf::IndiProperty ip3( pcf::IndiProperty::Switch );
245
246 ip3.setDevice( "observers" );
247 ip3.setName( "tcsTarget" );
248 ip3.add( pcf::IndiElement( "request" ) );
249
250 //Start off
251 ip3["request"].setSwitchState(pcf::IndiElement::Off);
252
253 rv = obs.newCallBack_m_indiP_tcsTarget(ip3);
254
255 REQUIRE( rv == 0);
256 REQUIRE( obs.catObj() == "target0");
257 REQUIRE( obs.target() == "");
258
259 //now trigger change
260 ip3["request"].setSwitchState(pcf::IndiElement::On);
261
262 rv = obs.newCallBack_m_indiP_tcsTarget(ip3);
263
264 REQUIRE( rv == -2);
265 REQUIRE( obs.catObj() == "target0");
266 REQUIRE( obs.target() == "");
267
268 }
269
270
271}
272
273
274} //namespace observerCtrl_test
std::string m_configName
The name of the configuration file (minus .conf).
static int log(const typename logT::messageT &msg, logPrioT level=logPrio::LOG_DEFAULT)
Make a log entry.
The MagAO-X Observer Controller.
pcf::IndiProperty m_indiP_labMode
Tracks whether TCS is in lab mode.
pcf::IndiProperty m_indiP_catalog
Catalog text data.
bool m_observing
Flag indicating whether or not we are in an observation.
pcf::IndiProperty m_indiP_catdata
Catalog numeric data.
pcf::IndiProperty m_indiP_teldata
Telescope data (for parang)
observerCtrl_test(const std::string device)
TEST_CASE("observerCtrl INDI Callback Input Validation", "[observerCtrl]")
observerCtrl INDI Callback Input Validation
#define XWCTEST_SETUP_INDI_ARB_PROP(varname, device, propname)
#define XWCTEST_SETUP_INDI_NEW_PROP(propname)