API
 
Loading...
Searching...
No Matches
rhusbMonParsers_test.cpp
Go to the documentation of this file.
1/** \file rhusbMonParsers_test.cpp
2 * \brief Catch2 tests for the parsers in the rhusbMon app.
3 * \author Jared R. Males (jaredmales@gmail.com)
4 *
5 * \ingroup rhusbMon_files
6 */
7
8#include "../../../tests/testXWC.hpp"
9
10#include "../rhusbMonParsers.hpp"
11
12using namespace MagAOX::app;
13
14namespace libXWCTest
15{
16
17/** \addtogroup rhusbMon_unit_test
18 * \brief Additional parser tests for the rhusbMon application.
19 *
20 * \ingroup application_unit_test
21 */
22
23/// Namespace for `rhusbMon` parser unit tests.
24/** \ingroup rhusbMon_unit_test
25 */
26namespace rhusbMonTest
27{
28
29/// Verify the RH USB parser helpers decode temperature and humidity replies and reject malformed input.
30/**
31 * \ingroup rhusbMon_unit_test
32 */
33SCENARIO( "Parsing the temp response", "[rhusbMonParsers]" )
34{
35 // clang-format off
36 #ifdef RHUSBMON_TEST_DOXYGEN_REF
37 RH::parseC( *(float *)nullptr, "" );
38 RH::parseH( *(float *)nullptr, "" );
39 #endif
40 // clang-format on
41
42 GIVEN( "A valid response to C from the RH USB probe" )
43 {
44 int rv;
45
46 WHEN( "Valid temp response, 20.0" )
47 {
48 std::string tstr = "20.0 C\r\n>";
49 float temp;
50
51 rv = RH::parseC( temp, tstr );
52
53 REQUIRE( rv == 0 );
54 REQUIRE( temp == (float)20.0 );
55 }
56
57 WHEN( "Valid temp response -1.2" )
58 {
59 std::string tstr = "-1.2 C\r\n>";
60 float temp;
61
62 rv = RH::parseC( temp, tstr );
63
64 REQUIRE( rv == 0 );
65 REQUIRE( temp == (float)-1.2 );
66 }
67
68 WHEN( "Valid temp response 1.2" )
69 {
70 std::string tstr = "1.2 C\r\n>";
71 float temp;
72
73 rv = RH::parseC( temp, tstr );
74
75 REQUIRE( rv == 0 );
76 REQUIRE( temp == (float)1.2 );
77 }
78
79 WHEN( "Valid temp response 01.2" )
80 {
81 std::string tstr = "01.2 C\r\n>";
82 float temp;
83
84 rv = RH::parseC( temp, tstr );
85
86 REQUIRE( rv == 0 );
87 REQUIRE( temp == (float)1.2 );
88 }
89 }
90
91 GIVEN( "Invalid responses to C from the RH USB probe" )
92 {
93 int rv;
94
95 WHEN( "Invalid temp response 20.0 C\r>" )
96 {
97 std::string tstr = "20.0 C\r>";
98 float temp;
99
100 rv = RH::parseC( temp, tstr );
101
102 REQUIRE( rv == -1 );
103 }
104
105 WHEN( "Invalid temp response 20.0C\r>" )
106 {
107 std::string tstr = "20.0 C\r>";
108 float temp;
109
110 rv = RH::parseC( temp, tstr );
111
112 REQUIRE( rv == -1 );
113 }
114
115 WHEN( "Invalid temp response 20.0 \r\n>" )
116 {
117 std::string tstr = "20.0 \r\n>";
118 float temp;
119
120 rv = RH::parseC( temp, tstr );
121
122 REQUIRE( rv == -1 );
123 }
124
125 WHEN( "Invalid temp response 20.0 >" )
126 {
127 std::string tstr = "20.0 >";
128 float temp;
129
130 rv = RH::parseC( temp, tstr );
131
132 REQUIRE( rv == -1 );
133 }
134
135 WHEN( "Invalid temp response ' C\r\n>'" )
136 {
137 std::string tstr = " C\r\n>";
138 float temp;
139
140 rv = RH::parseC( temp, tstr );
141
142 REQUIRE( rv == -2 );
143 }
144
145 WHEN( "Invalid temp response 'A C\r\n>'" )
146 {
147 std::string tstr = "A C\r\n>";
148 float temp;
149
150 rv = RH::parseC( temp, tstr );
151
152 REQUIRE( rv == -3 );
153 }
154 }
155}
156
157SCENARIO( "Parsing the humidity response", "[rhusbMonParsers]" )
158{
159 GIVEN( "A valid response to H from the RH USB probe" )
160 {
161 int rv;
162
163 WHEN( "Valid temp response" )
164 {
165 std::string tstr = "20.0 %RH\r\n>";
166 float temp;
167
168 rv = RH::parseH( temp, tstr );
169
170 REQUIRE( rv == 0 );
171 REQUIRE( temp == (float)20.0 );
172 }
173
174 WHEN( "Valid temp response" )
175 {
176 std::string tstr = "1.2 %RH\r\n>";
177 float temp;
178
179 rv = RH::parseH( temp, tstr );
180
181 REQUIRE( rv == 0 );
182 REQUIRE( temp == (float)1.2 );
183 }
184
185 WHEN( "Valid temp response" )
186 {
187 std::string tstr = "09.9 %RH\r\n>";
188 float temp;
189
190 rv = RH::parseH( temp, tstr );
191
192 REQUIRE( rv == 0 );
193 REQUIRE( temp == (float)9.9 );
194 }
195
196 WHEN( "Valid temp response" )
197 {
198 std::string tstr = "0.2 %RH\r\n>";
199 float temp;
200
201 rv = RH::parseH( temp, tstr );
202
203 REQUIRE( rv == 0 );
204 REQUIRE( temp == (float)0.2 );
205 }
206 }
207
208 GIVEN( "Invalid responses to H from the RH USB probe" )
209 {
210 int rv;
211
212 WHEN( "Invalid humidity response 20.0 %RH\r>" )
213 {
214 std::string tstr = "20.0 %RH\r>";
215 float temp;
216
217 rv = RH::parseH( temp, tstr );
218
219 REQUIRE( rv == -1 );
220 }
221
222 WHEN( "Invalid humidity response 20.0%RH\r>" )
223 {
224 std::string tstr = "20.0 %RH\r>";
225 float temp;
226
227 rv = RH::parseH( temp, tstr );
228
229 REQUIRE( rv == -1 );
230 }
231
232 WHEN( "Invalid humidity response 20.0 \r\n>" )
233 {
234 std::string tstr = "20.0 \r\n>";
235 float temp;
236
237 rv = RH::parseH( temp, tstr );
238
239 REQUIRE( rv == -1 );
240 }
241
242 WHEN( "Invalid humidity response 20.0 >" )
243 {
244 std::string tstr = "20.0 >";
245 float temp;
246
247 rv = RH::parseH( temp, tstr );
248
249 REQUIRE( rv == -1 );
250 }
251
252 WHEN( "Invalid humidity response ' %RH\r\n>'" )
253 {
254 std::string tstr = " %RH\r\n>";
255 float temp;
256
257 rv = RH::parseH( temp, tstr );
258
259 REQUIRE( rv == -2 );
260 }
261
262 WHEN( "Invalid humidity response 'A %RH\r\n>'" )
263 {
264 std::string tstr = "A %RH\r\n>";
265 float temp;
266
267 rv = RH::parseH( temp, tstr );
268
269 REQUIRE( rv == -3 );
270 }
271
272 WHEN( "Invalid humidity response '-1.2 %RH\r\n>'" )
273 {
274 std::string tstr = "-1.2 %RH\r\n>";
275 float temp;
276
277 rv = RH::parseH( temp, tstr );
278
279 REQUIRE( rv == -3 );
280 }
281 }
282}
283
284} // namespace rhusbMonTest
285
286} // namespace libXWCTest
SCENARIO("Parsing the temp response", "[rhusbMonParsers]")
Verify the RH USB parser helpers decode temperature and humidity replies and reject malformed input.
int parseH(float &humid, const std::string &str)
Parse the RH probe H humidity command.
int parseC(float &temp, const std::string &str)
Parse the RH probe C temp command.
Namespace for all libXWC tests.