API
 
Loading...
Searching...
No Matches
ocamUtils_test.cpp
Go to the documentation of this file.
1/** \file ocamUtils_test.cpp
2 * \brief Catch2 tests for the ocamUtils in the ocam2KCtrl app.
3 * \author Jared R. Males (jaredmales@gmail.com)
4 *
5 * History:
6 */
7#include "../../../tests/catch2/catch.hpp"
8
9#include "../ocamUtils.hpp"
10
11using namespace MagAOX::app;
12
14{
15
16/** \test Scenario: Parsing the temp response
17 *
18 * \anchor tests_MagAOX_app_ocamUtils_parse_temp_response
19 */
20SCENARIO( "Parsing the temp response", "[ocamUtils]" )
21{
22 GIVEN( "A valid response to temp from the OCAM" )
23 {
24 int rv;
25
26 WHEN( "Valid temp response" )
27 {
28 std::string tstr = "Temperatures : CCD[26.3] CPU[41] POWER[34] BIAS[47] WATER[24.2] LEFT[33] RIGHT[38] "
29 "SET[200]\nCooling Power [102]mW.\n\n";
30 ocamTemps temps;
31
32 rv = parseTemps( temps, tstr );
33
34 REQUIRE( rv == 0 );
35 REQUIRE( temps.CCD == (float)26.3 );
36 REQUIRE( temps.CPU == (float)41 );
37 REQUIRE( temps.POWER == (float)34 );
38 REQUIRE( temps.BIAS == (float)47 );
39 REQUIRE( temps.WATER == (float)24.2 );
40 REQUIRE( temps.LEFT == (float)33 );
41 REQUIRE( temps.RIGHT == (float)38 );
42 REQUIRE( temps.SET == (float)20.0 );
43 REQUIRE( temps.COOLING_POWER == (float)102 );
44 }
45 }
46
47 GIVEN( "An invalid response to temp from the OCAM, too short" )
48 {
49 int rv;
50
51 WHEN( "Temp response is too short" )
52 {
53 std::string tstr = "Temperatures : CCD[26.3] CPU[41] POWER[34] BIAS[47] WATER[24.2] LEFT[33] RIGHT[38] "
54 "SET[200]\nCooling Power";
55 ocamTemps temps;
56
57 rv = parseTemps( temps, tstr );
58
59 REQUIRE( rv == -1 );
60 }
61 }
62}
63
64/** \test Scenario: Parsing the gain response
65 *
66 * \anchor tests_MagAOX_app_ocamUtils_parse_gain_response
67 */
68SCENARIO( "Parsing the gain response", "[ocamUtils]" )
69{
70 GIVEN( "A valid response to gain from the OCAM" )
71 {
72 int rv;
73
74 WHEN( "Valid gain response, gain=2" )
75 {
76 std::string tstr = "Gain set to 2 \n\n";
77
78 unsigned emgain = 1;
79
80 rv = parseEMGain( emgain, tstr );
81
82 REQUIRE( rv == 0 );
83 REQUIRE( emgain == 2 );
84 }
85 }
86
87 GIVEN( "A valid response to gain from the OCAM" )
88 {
89 int rv;
90
91 WHEN( "Valid gain response, gain=512" )
92 {
93 std::string tstr = "Gain set to 512 \n\n";
94
95 unsigned emgain = 1;
96
97 rv = parseEMGain( emgain, tstr );
98
99 REQUIRE( rv == 0 );
100 REQUIRE( emgain == 512 );
101 }
102 }
103
104 GIVEN( "An invalid response to gain from the OCAM" )
105 {
106 int rv;
107
108 WHEN( "Invalid gain response, too short, no trailing space" )
109 {
110 std::string tstr = "Gain set to 512\n\n";
111
112 unsigned emgain = 1;
113
114 rv = parseEMGain( emgain, tstr );
115
116 REQUIRE( rv == -1 );
117 REQUIRE( emgain == 0 );
118 }
119
120 WHEN( "Invalid gain response, too short, no gain" )
121 {
122 std::string tstr = "Gain set to \n\n";
123
124 unsigned emgain = 1;
125
126 rv = parseEMGain( emgain, tstr );
127
128 REQUIRE( rv == -1 );
129 REQUIRE( emgain == 0 );
130 }
131
132 WHEN( "Invalid gain response, too long" )
133 {
134 std::string tstr = "Gain set to 512 rubbish added\n\n";
135
136 unsigned emgain = 1;
137
138 rv = parseEMGain( emgain, tstr );
139
140 REQUIRE( rv == -1 );
141 REQUIRE( emgain == 0 );
142 }
143
144 WHEN( "Invalid gain response, low gain" )
145 {
146 std::string tstr = "Gain set to 0 \n\n";
147
148 unsigned emgain = 1;
149
150 rv = parseEMGain( emgain, tstr );
151
152 REQUIRE( rv == -1 );
153 REQUIRE( emgain == 0 );
154 }
155
156 WHEN( "Invalid gain response, high gain" )
157 {
158 std::string tstr = "Gain set to 601 \n\n";
159
160 unsigned emgain = 1;
161
162 rv = parseEMGain( emgain, tstr );
163
164 REQUIRE( rv == -1 );
165 REQUIRE( emgain == 0 );
166 }
167
168 WHEN( "Invalid gain response, bad gain" )
169 {
170 std::string tstr = "Gain set to x \n\n";
171
172 unsigned emgain = 1;
173
174 rv = parseEMGain( emgain, tstr );
175
176 REQUIRE( rv == -1 );
177 REQUIRE( emgain == 0 );
178 }
179 }
180}
181
182} // namespace ocamUtils_test
#define GIVEN(desc)
Definition catch.hpp:17763
#define WHEN(desc)
Definition catch.hpp:17765
#define SCENARIO(...)
Definition catch.hpp:17760
#define REQUIRE(...)
Definition catch.hpp:17676
int parseTemps(ocamTemps &temps, const std::string &tstr)
Parse the OCAM temp query and fill the ocamTemps structure.
Definition ocamUtils.hpp:71
int parseEMGain(unsigned &emGain, const std::string &fstr)
Parse the EM gain response.
Structure to hold the OCAM camera temperature readings returned by the device.
Definition ocamUtils.hpp:22
float WATER
Cooling water temperature.
Definition ocamUtils.hpp:27
float COOLING_POWER
the cooling power in 100 mw.
Definition ocamUtils.hpp:31
float BIAS
Bias temperature.
Definition ocamUtils.hpp:26
float SET
The CCD set temeperature.
Definition ocamUtils.hpp:30
float CCD
The detector temperature.
Definition ocamUtils.hpp:23
float POWER
Power supply temperature.
Definition ocamUtils.hpp:25
float CPU
The CPU temperature.
Definition ocamUtils.hpp:24
float LEFT
The left amplifier temperature.
Definition ocamUtils.hpp:28
float RIGHT
The right amplifier temperature.
Definition ocamUtils.hpp:29