API
 
Loading...
Searching...
No Matches
stateCodes_test.cpp
Go to the documentation of this file.
1//#define CATCH_CONFIG_MAIN
2#include "../../../tests/catch2/catch.hpp"
3
4#include <mx/sys/timeUtils.hpp>
5
6#include "../stateCodes.hpp"
7
8
9using namespace MagAOX::app;
10
11SCENARIO( "Getting State Strings From Codes", "[stateCodes]" )
12{
13 GIVEN("a valid state code")
14 {
15 std::string str;
16
18 REQUIRE(str == "FAILURE");
19
21 REQUIRE(str == "ERROR");
22
24 REQUIRE(str == "UNINITIALIZED");
25
27 REQUIRE(str == "INITIALIZED");
28
30 REQUIRE(str == "NODEVICE");
31
33 REQUIRE(str == "POWEROFF");
34
36 REQUIRE(str == "POWERON");
37
39 REQUIRE(str == "NOTCONNECTED");
40
42 REQUIRE(str == "CONNECTED");
43
45 REQUIRE(str == "LOGGEDIN");
46
48 REQUIRE(str == "CONFIGURING");
49
51 REQUIRE(str == "NOTHOMED");
52
54 REQUIRE(str == "HOMING");
55
57 REQUIRE(str == "OPERATING");
58
60 REQUIRE(str == "READY");
61
63 REQUIRE(str == "SHUTDOWN");
64
65 str = stateCodes::codeText(static_cast<stateCodes::stateCodeT>(std::numeric_limits<stateCodes::stateCodeT>::max()));
66 REQUIRE(str == "UNKNOWN");
67 }
68}
69
70SCENARIO( "Getting State Codes From Strings", "[stateCodes]" )
71{
72 GIVEN("a string using stateCodeFast")
73 {
74 WHEN("valid strings")
75 {
77
78 sc = stateCodes::str2CodeFast("FAILURE");
79 REQUIRE(sc == stateCodes::FAILURE);
80
81 sc = stateCodes::str2CodeFast("ERROR");
82 REQUIRE(sc == stateCodes::ERROR);
83
84 sc = stateCodes::str2CodeFast("UNINITIALIZED");
85 REQUIRE(sc == stateCodes::UNINITIALIZED);
86
87 sc = stateCodes::str2CodeFast("INITIALIZED");
88 REQUIRE(sc == stateCodes::INITIALIZED);
89
90 sc = stateCodes::str2CodeFast("NODEVICE");
91 REQUIRE(sc == stateCodes::NODEVICE);
92
93 sc = stateCodes::str2CodeFast("POWEROFF");
94 REQUIRE(sc == stateCodes::POWEROFF);
95
96 sc = stateCodes::str2CodeFast("POWERON");
97 REQUIRE(sc == stateCodes::POWERON);
98
99 sc = stateCodes::str2CodeFast("NOTCONNECTED");
100 REQUIRE(sc == stateCodes::NOTCONNECTED);
101
102 sc = stateCodes::str2CodeFast("CONNECTED");
103 REQUIRE(sc == stateCodes::CONNECTED);
104
105 sc = stateCodes::str2CodeFast("LOGGEDIN");
106 REQUIRE(sc == stateCodes::LOGGEDIN);
107
108 sc = stateCodes::str2CodeFast("CONFIGURING");
109 REQUIRE(sc == stateCodes::CONFIGURING);
110
111 sc = stateCodes::str2CodeFast("NOTHOMED");
112 REQUIRE(sc == stateCodes::NOTHOMED);
113
114 sc = stateCodes::str2CodeFast("HOMING");
115 REQUIRE(sc == stateCodes::HOMING);
116
117 sc = stateCodes::str2CodeFast("OPERATING");
118 REQUIRE(sc == stateCodes::OPERATING);
119
120 sc = stateCodes::str2CodeFast("READY");
121 REQUIRE(sc == stateCodes::READY);
122
123 sc = stateCodes::str2CodeFast("SHUTDOWN");
124 REQUIRE(sc == stateCodes::SHUTDOWN);
125
126 }
127
128 WHEN("strings too short")
129 {
131
132 sc = stateCodes::str2CodeFast("CON");
133 REQUIRE(sc == -999);
134
135 sc = stateCodes::str2CodeFast("CO");
136 REQUIRE(sc == -999);
137
138 sc = stateCodes::str2CodeFast("NOD");
139 REQUIRE(sc == -999);
140
141 sc = stateCodes::str2CodeFast("NOT");
142 REQUIRE(sc == -999);
143
144 sc = stateCodes::str2CodeFast("NO");
145 REQUIRE(sc == -999);
146
147 sc = stateCodes::str2CodeFast("POWER");
148 REQUIRE(sc == -999);
149
150 sc = stateCodes::str2CodeFast("POW");
151 REQUIRE(sc == -999);
152
153 }
154
155 WHEN("invalid strings")
156 {
158
159 sc = stateCodes::str2CodeFast("CONZECTED");
160 REQUIRE(sc == -999);
161
162 sc = stateCodes::str2CodeFast("NOTZOMED");
163 REQUIRE(sc == -999);
164
165 sc = stateCodes::str2CodeFast("POWEROZ");
166 REQUIRE(sc == -999);
167
168 sc = stateCodes::str2CodeFast("ZZZZZZZZZZZZZZZ");
169 REQUIRE(sc == -999);
170 }
171 }
172
173 GIVEN("a string using stateCode")
174 {
175 WHEN("valid strings")
176 {
178
179 sc = stateCodes::str2Code("FAILURE");
180 REQUIRE(sc == stateCodes::FAILURE);
181
182 sc = stateCodes::str2Code("ERROR");
183 REQUIRE(sc == stateCodes::ERROR);
184
185 sc = stateCodes::str2Code("UNINITIALIZED");
186 REQUIRE(sc == stateCodes::UNINITIALIZED);
187
188 sc = stateCodes::str2Code("INITIALIZED");
189 REQUIRE(sc == stateCodes::INITIALIZED);
190
191 sc = stateCodes::str2Code("NODEVICE");
192 REQUIRE(sc == stateCodes::NODEVICE);
193
194 sc = stateCodes::str2Code("POWEROFF");
195 REQUIRE(sc == stateCodes::POWEROFF);
196
197 sc = stateCodes::str2Code("POWERON");
198 REQUIRE(sc == stateCodes::POWERON);
199
200 sc = stateCodes::str2Code("NOTCONNECTED");
201 REQUIRE(sc == stateCodes::NOTCONNECTED);
202
203 sc = stateCodes::str2Code("CONNECTED");
204 REQUIRE(sc == stateCodes::CONNECTED);
205
206 sc = stateCodes::str2Code("LOGGEDIN");
207 REQUIRE(sc == stateCodes::LOGGEDIN);
208
209 sc = stateCodes::str2Code("CONFIGURING");
210 REQUIRE(sc == stateCodes::CONFIGURING);
211
212 sc = stateCodes::str2Code("NOTHOMED");
213 REQUIRE(sc == stateCodes::NOTHOMED);
214
215 sc = stateCodes::str2Code("HOMING");
216 REQUIRE(sc == stateCodes::HOMING);
217
218 sc = stateCodes::str2Code("OPERATING");
219 REQUIRE(sc == stateCodes::OPERATING);
220
221 sc = stateCodes::str2Code("READY");
222 REQUIRE(sc == stateCodes::READY);
223
224 sc = stateCodes::str2Code("SHUTDOWN");
225 REQUIRE(sc == stateCodes::SHUTDOWN);
226
227 }
228
229 WHEN("invalid strings")
230 {
232
233 sc = stateCodes::str2Code("FAILUR");
234 REQUIRE(sc == -999);
235
236 sc = stateCodes::str2Code("ERRR");
237 REQUIRE(sc == -999);
238
239 sc = stateCodes::str2Code("UNIITIALIZED");
240 REQUIRE(sc == -999);
241
242 sc = stateCodes::str2Code("INITALIZED");
243 REQUIRE(sc == -999);
244
245 sc = stateCodes::str2Code("NODVICE");
246 REQUIRE(sc == -999);
247
248 sc = stateCodes::str2Code("POEROFF");
249 REQUIRE(sc == -999);
250
251 sc = stateCodes::str2Code("POWRON");
252 REQUIRE(sc == -999);
253
254 sc = stateCodes::str2Code("NOTCNNECTED");
255 REQUIRE(sc == -999);
256
257 sc = stateCodes::str2Code("CONNETED");
258 REQUIRE(sc == -999);
259
260 sc = stateCodes::str2Code("LOGGEIN");
261 REQUIRE(sc == -999);
262
263 sc = stateCodes::str2Code("CONFIURING");
264 REQUIRE(sc == -999);
265
266 sc = stateCodes::str2Code("NOHOMED");
267 REQUIRE(sc == -999);
268
269 sc = stateCodes::str2Code("HOMNG");
270 REQUIRE(sc == -999);
271
272 sc = stateCodes::str2Code("OPETING");
273 REQUIRE(sc == -999);
274
275 sc = stateCodes::str2Code("REDY");
276 REQUIRE(sc == -999);
277
278 sc = stateCodes::str2Code("SHTDOWN");
279 REQUIRE(sc == -999);
280
281 }
282 }
283}
284
@ OPERATING
The device is operating, other than homing.
@ POWEROFF
The device power is off.
@ NODEVICE
No device exists for the application to control.
@ SHUTDOWN
The application has shutdown, set just after calling appShutdown().
@ NOTHOMED
The device has not been homed.
@ HOMING
The device is homing.
@ FAILURE
The application has failed, should be used when m_shutdown is set for an error.
@ CONFIGURING
The application is configuring the device.
@ ERROR
The application has encountered an error, from which it is recovering (with or without intervention)
@ READY
The device is ready for operation, but is not operating.
@ LOGGEDIN
The application has logged into the device or service.
@ CONNECTED
The application has connected to the device or service.
@ UNINITIALIZED
The application is unitialized, the default.
@ INITIALIZED
The application has been initialized, set just before calling appStartup().
@ NOTCONNECTED
The application is not connected to the device or service.
@ POWERON
The device power is on.
SCENARIO("Getting State Strings From Codes", "[stateCodes]")
static stateCodeT str2CodeFast(const std::string &stateStr)
Get the stateCode corresponding to an ASCII string with minimal checks.
int16_t stateCodeT
The type of the state code.
static stateCodeT str2Code(const std::string &stateStr)
Get the stateCode corresponding to an ASCII string.
static std::string codeText(const stateCodeT &stateCode)
Get an ASCII string corresponding to an application stateCode.