API
 
Loading...
Searching...
No Matches
tcsInterface_test.cpp
Go to the documentation of this file.
1/** \file tcsInterface_test.cpp
2 * \brief Catch2 tests for the tcsInterface 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
13#include "../tcsInterface.hpp"
14
15using namespace MagAOX::app;
16
17namespace TCSITEST
18{
19
43
44
45SCENARIO( "INDI Callbacks", "[tcsInterface]" )
46{
59
60 //XWCTEST_INDI_SET_CALLBACK( tcsInterface, m_indiP_teldata, tcsi, zd);
61
62}
63
64SCENARIO( "Parsing times in x:m:s format", "[tcsInterface]" )
65{
66 GIVEN("A valid x:m:s string")
67 {
68 int rv;
69
70 WHEN("Positive, double digit integers")
71 {
72 tcsInterface_test tit("tcsi");
73
74 std::string tstr = "12:20:50";
75
76 double x;
77 double m;
78 double s;
79
80 rv = tit.parse_xms(x, m, s, tstr);
81
82 REQUIRE(rv == 0);
86 }
87
88 WHEN("Negative, double digit integers")
89 {
90 tcsInterface_test tit("tcsi");
91
92 std::string tstr = "-22:30:48";
93
94 double x;
95 double m;
96 double s;
97
98 rv = tit.parse_xms(x, m, s, tstr);
99
100 REQUIRE(rv == 0);
104 }
105
106 WHEN("Positive, double digit, decimal seconds")
107 {
108 tcsInterface_test tit("tcsi");
109
110 std::string tstr = "12:20:50.267849";
111
112 double x;
113 double m;
114 double s;
115
116 rv = tit.parse_xms(x, m, s, tstr);
117
118 REQUIRE(rv == 0);
121 REQUIRE_THAT(s, Catch::Matchers::WithinAbs(50.267849, 1e-10));
122 }
123
124 WHEN("Negative, double digit integers")
125 {
126 tcsInterface_test tit("tcsi");
127
128 std::string tstr = "-22:30:48.8771819";
129
130 double x;
131 double m;
132 double s;
133
134 rv = tit.parse_xms(x, m, s, tstr);
135
136 REQUIRE(rv == 0);
139 REQUIRE_THAT(s, Catch::Matchers::WithinAbs(-48.8771819, 1e-10));
140 }
141 }
142
143 GIVEN("Invalid x:m:s strings")
144 {
145 int rv;
146
147 WHEN("empty")
148 {
149 tcsInterface_test tit("tcsi");
150
151 std::string tstr = "";
152
153 double x;
154 double m;
155 double s;
156
157 rv = tit.parse_xms(x, m, s, tstr);
158
159 REQUIRE(rv == -1);
160 }
161
162 WHEN("no :")
163 {
164 tcsInterface_test tit("tcsi");
165
166 std::string tstr = "12-20-50";
167
168 double x;
169 double m;
170 double s;
171
172 rv = tit.parse_xms(x, m, s, tstr);
173
174 REQUIRE(rv == -1);
175 }
176
177 WHEN("only one :")
178 {
179 tcsInterface_test tit("tcsi");
180
181 std::string tstr = "12:20-50";
182
183 double x;
184 double m;
185 double s;
186
187 rv = tit.parse_xms(x, m, s, tstr);
188
189 REQUIRE(rv == -1);
190 }
191
192 WHEN("two :, but one at beginning")
193 {
194 tcsInterface_test tit("tcsi");
195
196 std::string tstr = ":12:20";
197
198 double x;
199 double m;
200 double s;
201
202 rv = tit.parse_xms(x, m, s, tstr);
203
204 REQUIRE(rv == -1);
205 }
206
207 WHEN("two :, but no m")
208 {
209 tcsInterface_test tit("tcsi");
210
211 std::string tstr = "12::20";
212
213 double x;
214 double m;
215 double s;
216
217 rv = tit.parse_xms(x, m, s, tstr);
218
219 REQUIRE(rv == -1);
220 }
221
222 WHEN("two :, but one at end")
223 {
224 tcsInterface_test tit("tcsi");
225
226 std::string tstr = "12:20:";
227
228 double x;
229 double m;
230 double s;
231
232 rv = tit.parse_xms(x, m, s, tstr);
233
234 REQUIRE(rv == -1);
235 }
236
237 WHEN("invalid x")
238 {
239 tcsInterface_test tit("tcsi");
240
241 std::string tstr = "x:20:80";
242
243 double x;
244 double m;
245 double s;
246
247 rv = tit.parse_xms(x, m, s, tstr);
248
249 REQUIRE(rv == -1);
250 }
251
252 WHEN("invalid -x")
253 {
254 tcsInterface_test tit("tcsi");
255
256 std::string tstr = "-x:20:80";
257
258 double x;
259 double m;
260 double s;
261
262 rv = tit.parse_xms(x, m, s, tstr);
263
264 REQUIRE(rv == -1);
265 }
266
267 WHEN("invalid m")
268 {
269 tcsInterface_test tit("tcsi");
270
271 std::string tstr = "20:m:80";
272
273 double x;
274 double m;
275 double s;
276
277 rv = tit.parse_xms(x, m, s, tstr);
278
279 REQUIRE(rv == -1);
280 }
281
282 WHEN("invalid -m")
283 {
284 tcsInterface_test tit("tcsi");
285
286 std::string tstr = "-12:m:80";
287
288 double x;
289 double m;
290 double s;
291
292 rv = tit.parse_xms(x, m, s, tstr);
293
294 REQUIRE(rv == -1);
295 }
296
297 WHEN("invalid s")
298 {
299 tcsInterface_test tit("tcsi");
300
301 std::string tstr = "20:23:s.ssy";
302
303 double x;
304 double m;
305 double s;
306
307 rv = tit.parse_xms(x, m, s, tstr);
308
309 REQUIRE(rv == -1);
310 }
311
312 WHEN("invalid -s")
313 {
314 tcsInterface_test tit("tcsi");
315
316 std::string tstr = "-12:23:s.sye";
317
318 double x;
319 double m;
320 double s;
321
322 rv = tit.parse_xms(x, m, s, tstr);
323
324 REQUIRE(rv == -1);
325 }
326 }
327}
328
329} //namespace tcsInterface_test
#define GIVEN(desc)
Definition catch.hpp:17763
#define WHEN(desc)
Definition catch.hpp:17765
#define REQUIRE_THAT(arg, matcher)
Definition catch.hpp:17704
#define SCENARIO(...)
Definition catch.hpp:17760
#define REQUIRE(...)
Definition catch.hpp:17676
std::string m_configName
The name of the configuration file (minus .conf).
Definition MagAOXApp.hpp:83
static int log(const typename logT::messageT &msg, logPrioT level=logPrio::LOG_DEFAULT)
Make a log entry.
The MagAO-X Clay Telescope TCS Interface.
int parse_xms(double &x, double &m, double &s, const std::string &xmsstr)
tcsInterface_test(const std::string device)
#define XWCTEST_INDI_NEW_CALLBACK(testclass, propname)
Catch-2 tests for whether a NEW callback properly validates the input property properly.
Floating::WithinAbsMatcher WithinAbs(double target, double margin)
#define XWCTEST_SETUP_INDI_NEW_PROP(propname)