API
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 
9 using namespace MagAOX::app;
10 
11 SCENARIO( "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 }
66 
67 SCENARIO( "Getting State Codes From Strings", "[stateCodes]" )
68 {
69  GIVEN("a string using stateCodeFast")
70  {
71  WHEN("valid strings")
72  {
74 
75  sc = stateCodes::str2CodeFast("FAILURE");
77 
78  sc = stateCodes::str2CodeFast("ERROR");
80 
81  sc = stateCodes::str2CodeFast("UNINITIALIZED");
83 
84  sc = stateCodes::str2CodeFast("INITIALIZED");
86 
87  sc = stateCodes::str2CodeFast("NODEVICE");
89 
90  sc = stateCodes::str2CodeFast("POWEROFF");
92 
93  sc = stateCodes::str2CodeFast("POWERON");
95 
96  sc = stateCodes::str2CodeFast("NOTCONNECTED");
98 
99  sc = stateCodes::str2CodeFast("CONNECTED");
101 
102  sc = stateCodes::str2CodeFast("LOGGEDIN");
104 
105  sc = stateCodes::str2CodeFast("CONFIGURING");
107 
108  sc = stateCodes::str2CodeFast("NOTHOMED");
110 
111  sc = stateCodes::str2CodeFast("HOMING");
113 
114  sc = stateCodes::str2CodeFast("OPERATING");
116 
117  sc = stateCodes::str2CodeFast("READY");
118  REQUIRE(sc == stateCodes::READY);
119 
120  sc = stateCodes::str2CodeFast("SHUTDOWN");
122 
123  }
124 
125  WHEN("strings too short")
126  {
128 
129  sc = stateCodes::str2CodeFast("CON");
130  REQUIRE(sc == -999);
131 
132  sc = stateCodes::str2CodeFast("CO");
133  REQUIRE(sc == -999);
134 
135  sc = stateCodes::str2CodeFast("NOD");
136  REQUIRE(sc == -999);
137 
138  sc = stateCodes::str2CodeFast("NOT");
139  REQUIRE(sc == -999);
140 
141  sc = stateCodes::str2CodeFast("NO");
142  REQUIRE(sc == -999);
143 
144  sc = stateCodes::str2CodeFast("POWER");
145  REQUIRE(sc == -999);
146 
147  sc = stateCodes::str2CodeFast("POW");
148  REQUIRE(sc == -999);
149 
150  }
151  }
152 
153  GIVEN("a string using stateCode")
154  {
155  WHEN("valid strings")
156  {
158 
159  sc = stateCodes::str2Code("FAILURE");
161 
162  sc = stateCodes::str2Code("ERROR");
163  REQUIRE(sc == stateCodes::ERROR);
164 
165  sc = stateCodes::str2Code("UNINITIALIZED");
167 
168  sc = stateCodes::str2Code("INITIALIZED");
170 
171  sc = stateCodes::str2Code("NODEVICE");
173 
174  sc = stateCodes::str2Code("POWEROFF");
176 
177  sc = stateCodes::str2Code("POWERON");
179 
180  sc = stateCodes::str2Code("NOTCONNECTED");
182 
183  sc = stateCodes::str2Code("CONNECTED");
185 
186  sc = stateCodes::str2Code("LOGGEDIN");
188 
189  sc = stateCodes::str2Code("CONFIGURING");
191 
192  sc = stateCodes::str2Code("NOTHOMED");
194 
195  sc = stateCodes::str2Code("HOMING");
197 
198  sc = stateCodes::str2Code("OPERATING");
200 
201  sc = stateCodes::str2Code("READY");
202  REQUIRE(sc == stateCodes::READY);
203 
204  sc = stateCodes::str2Code("SHUTDOWN");
206 
207  }
208 
209  WHEN("invalid strings")
210  {
212 
213  sc = stateCodes::str2Code("FAILUR");
214  REQUIRE(sc == -999);
215 
216  sc = stateCodes::str2Code("ERRR");
217  REQUIRE(sc == -999);
218 
219  sc = stateCodes::str2Code("UNIITIALIZED");
220  REQUIRE(sc == -999);
221 
222  sc = stateCodes::str2Code("INITALIZED");
223  REQUIRE(sc == -999);
224 
225  sc = stateCodes::str2Code("NODVICE");
226  REQUIRE(sc == -999);
227 
228  sc = stateCodes::str2Code("POEROFF");
229  REQUIRE(sc == -999);
230 
231  sc = stateCodes::str2Code("POWRON");
232  REQUIRE(sc == -999);
233 
234  sc = stateCodes::str2Code("NOTCNNECTED");
235  REQUIRE(sc == -999);
236 
237  sc = stateCodes::str2Code("CONNETED");
238  REQUIRE(sc == -999);
239 
240  sc = stateCodes::str2Code("LOGGEIN");
241  REQUIRE(sc == -999);
242 
243  sc = stateCodes::str2Code("CONFIURING");
244  REQUIRE(sc == -999);
245 
246  sc = stateCodes::str2Code("NOHOMED");
247  REQUIRE(sc == -999);
248 
249  sc = stateCodes::str2Code("HOMNG");
250  REQUIRE(sc == -999);
251 
252  sc = stateCodes::str2Code("OPETING");
253  REQUIRE(sc == -999);
254 
255  sc = stateCodes::str2Code("REDY");
256  REQUIRE(sc == -999);
257 
258  sc = stateCodes::str2Code("SHTDOWN");
259  REQUIRE(sc == -999);
260 
261  }
262  }
263 }
264 
#define GIVEN(desc)
Definition: catch.hpp:17763
#define WHEN(desc)
Definition: catch.hpp:17765
#define REQUIRE(...)
Definition: catch.hpp:17676
@ OPERATING
The device is operating, other than homing.
Definition: stateCodes.hpp:55
@ POWEROFF
The device power is off.
Definition: stateCodes.hpp:47
@ NODEVICE
No device exists for the application to control.
Definition: stateCodes.hpp:46
@ SHUTDOWN
The application has shutdown, set just after calling appShutdown().
Definition: stateCodes.hpp:57
@ NOTHOMED
The device has not been homed.
Definition: stateCodes.hpp:53
@ HOMING
The device is homing.
Definition: stateCodes.hpp:54
@ FAILURE
The application has failed, should be used when m_shutdown is set for an error.
Definition: stateCodes.hpp:42
@ CONFIGURING
The application is configuring the device.
Definition: stateCodes.hpp:52
@ ERROR
The application has encountered an error, from which it is recovering (with or without intervention)
Definition: stateCodes.hpp:43
@ READY
The device is ready for operation, but is not operating.
Definition: stateCodes.hpp:56
@ LOGGEDIN
The application has logged into the device or service.
Definition: stateCodes.hpp:51
@ CONNECTED
The application has connected to the device or service.
Definition: stateCodes.hpp:50
@ UNINITIALIZED
The application is unitialized, the default.
Definition: stateCodes.hpp:44
@ INITIALIZED
The application has been initialized, set just before calling appStartup().
Definition: stateCodes.hpp:45
@ NOTCONNECTED
The application is not connected to the device or service.
Definition: stateCodes.hpp:49
@ POWERON
The device power is on.
Definition: stateCodes.hpp:48
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.
Definition: stateCodes.cpp:133
int16_t stateCodeT
The type of the state code.
Definition: stateCodes.hpp:35
static stateCodeT str2Code(const std::string &stateStr)
Get the stateCode corresponding to an ASCII string.
Definition: stateCodes.cpp:59
static std::string codeText(const stateCodeT &stateCode)
Get an ASCII string corresponding to an application stateCode.
Definition: stateCodes.cpp:16