API
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  * History:
6  */
7 #include "../../../tests/catch2/catch.hpp"
8 
9 #include "../rhusbMonParsers.hpp"
10 
11 using namespace MagAOX::app;
12 
14 {
15 
16 SCENARIO( "Parsing the temp response", "[rhusbMonParsers]" )
17 {
18  GIVEN("A valid response to C from the RH USB probe")
19  {
20  int rv;
21 
22  WHEN("Valid temp response, 20.0")
23  {
24  std::string tstr = "20.0 C\r\n>";
25  float temp;
26 
27  rv = RH::parseC(temp, tstr);
28 
29  REQUIRE(rv == 0);
30  REQUIRE(temp == (float) 20.0);
31  }
32 
33  WHEN("Valid temp response -1.2")
34  {
35  std::string tstr = "-1.2 C\r\n>";
36  float temp;
37 
38  rv = RH::parseC(temp, tstr);
39 
40  REQUIRE(rv == 0);
41  REQUIRE(temp == (float) -1.2);
42  }
43 
44  WHEN("Valid temp response 1.2")
45  {
46  std::string tstr = "1.2 C\r\n>";
47  float temp;
48 
49  rv = RH::parseC(temp, tstr);
50 
51  REQUIRE(rv == 0);
52  REQUIRE(temp == (float) 1.2);
53  }
54 
55  WHEN("Valid temp response 01.2")
56  {
57  std::string tstr = "01.2 C\r\n>";
58  float temp;
59 
60  rv = RH::parseC(temp, tstr);
61 
62  REQUIRE(rv == 0);
63  REQUIRE(temp == (float) 1.2);
64  }
65  }
66 
67  GIVEN("Invalid responses to C from the RH USB probe")
68  {
69  int rv;
70 
71  WHEN("Invalid temp response 20.0 C\r>")
72  {
73  std::string tstr = "20.0 C\r>";
74  float temp;
75 
76  rv = RH::parseC(temp, tstr);
77 
78  REQUIRE(rv == -1);
79  }
80 
81  WHEN("Invalid temp response 20.0C\r>")
82  {
83  std::string tstr = "20.0 C\r>";
84  float temp;
85 
86  rv = RH::parseC(temp, tstr);
87 
88  REQUIRE(rv == -1);
89  }
90 
91  WHEN("Invalid temp response 20.0 \r\n>")
92  {
93  std::string tstr = "20.0 \r\n>";
94  float temp;
95 
96  rv = RH::parseC(temp, tstr);
97 
98  REQUIRE(rv == -1);
99  }
100 
101  WHEN("Invalid temp response 20.0 >")
102  {
103  std::string tstr = "20.0 >";
104  float temp;
105 
106  rv = RH::parseC(temp, tstr);
107 
108  REQUIRE(rv == -1);
109  }
110 
111  WHEN("Invalid temp response ' C\r\n>'")
112  {
113  std::string tstr = " C\r\n>";
114  float temp;
115 
116  rv = RH::parseC(temp, tstr);
117 
118  REQUIRE(rv == -2);
119  }
120 
121  WHEN("Invalid temp response 'A C\r\n>'")
122  {
123  std::string tstr = "A C\r\n>";
124  float temp;
125 
126  rv = RH::parseC(temp, tstr);
127 
128  REQUIRE(rv == -3);
129  }
130  }
131 }
132 
133 SCENARIO( "Parsing the humidity response", "[rhusbMonParsers]" )
134 {
135  GIVEN("A valid response to H from the RH USB probe")
136  {
137  int rv;
138 
139  WHEN("Valid temp response")
140  {
141  std::string tstr = "20.0 %RH\r\n>";
142  float temp;
143 
144  rv = RH::parseH(temp, tstr);
145 
146  REQUIRE(rv == 0);
147  REQUIRE(temp == (float) 20.0);
148  }
149 
150  WHEN("Valid temp response")
151  {
152  std::string tstr = "1.2 %RH\r\n>";
153  float temp;
154 
155  rv = RH::parseH(temp, tstr);
156 
157  REQUIRE(rv == 0);
158  REQUIRE(temp == (float) 1.2);
159  }
160 
161  WHEN("Valid temp response")
162  {
163  std::string tstr = "09.9 %RH\r\n>";
164  float temp;
165 
166  rv = RH::parseH(temp, tstr);
167 
168  REQUIRE(rv == 0);
169  REQUIRE(temp == (float) 9.9);
170  }
171 
172  WHEN("Valid temp response")
173  {
174  std::string tstr = "0.2 %RH\r\n>";
175  float temp;
176 
177  rv = RH::parseH(temp, tstr);
178 
179  REQUIRE(rv == 0);
180  REQUIRE(temp == (float) 0.2);
181  }
182  }
183 
184  GIVEN("Invalid responses to H from the RH USB probe")
185  {
186  int rv;
187 
188  WHEN("Invalid humidity response 20.0 %RH\r>")
189  {
190  std::string tstr = "20.0 %RH\r>";
191  float temp;
192 
193  rv = RH::parseH(temp, tstr);
194 
195  REQUIRE(rv == -1);
196  }
197 
198  WHEN("Invalid humidity response 20.0%RH\r>")
199  {
200  std::string tstr = "20.0 %RH\r>";
201  float temp;
202 
203  rv = RH::parseH(temp, tstr);
204 
205  REQUIRE(rv == -1);
206  }
207 
208  WHEN("Invalid humidity response 20.0 \r\n>")
209  {
210  std::string tstr = "20.0 \r\n>";
211  float temp;
212 
213  rv = RH::parseH(temp, tstr);
214 
215  REQUIRE(rv == -1);
216  }
217 
218  WHEN("Invalid humidity response 20.0 >")
219  {
220  std::string tstr = "20.0 >";
221  float temp;
222 
223  rv = RH::parseH(temp, tstr);
224 
225  REQUIRE(rv == -1);
226  }
227 
228  WHEN("Invalid humidity response ' %RH\r\n>'")
229  {
230  std::string tstr = " %RH\r\n>";
231  float temp;
232 
233  rv = RH::parseH(temp, tstr);
234 
235  REQUIRE(rv == -2);
236  }
237 
238  WHEN("Invalid humidity response 'A %RH\r\n>'")
239  {
240  std::string tstr = "A %RH\r\n>";
241  float temp;
242 
243  rv = RH::parseH(temp, tstr);
244 
245  REQUIRE(rv == -3);
246  }
247 
248  WHEN("Invalid humidity response '-1.2 %RH\r\n>'")
249  {
250  std::string tstr = "-1.2 %RH\r\n>";
251  float temp;
252 
253  rv = RH::parseH(temp, tstr);
254 
255  REQUIRE(rv == -3);
256  }
257  }
258 }
259 
260 } //namespace ocamUtils_test
#define GIVEN(desc)
Definition: catch.hpp:17763
#define WHEN(desc)
Definition: catch.hpp:17765
#define REQUIRE(...)
Definition: catch.hpp:17676
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.
SCENARIO("Parsing the humidity response", "[rhusbMonParsers]")