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
16SCENARIO( "Parsing the temp response", "[ocamUtils]" )
17{
18 GIVEN("A valid response to temp from the OCAM")
19 {
20 int rv;
21
22 WHEN("Valid temp response")
23 {
24 std::string tstr = "Temperatures : CCD[26.3] CPU[41] POWER[34] BIAS[47] WATER[24.2] LEFT[33] RIGHT[38] SET[200]\nCooling Power [102]mW.\n\n";
25 ocamTemps temps;
26
27 rv = parseTemps(temps, tstr);
28
29 REQUIRE(rv == 0);
30 REQUIRE(temps.CCD == (float) 26.3);
31 REQUIRE(temps.CPU == (float) 41);
32 REQUIRE(temps.POWER == (float) 34);
33 REQUIRE(temps.BIAS == (float) 47);
34 REQUIRE(temps.WATER == (float) 24.2);
35 REQUIRE(temps.LEFT == (float) 33);
36 REQUIRE(temps.RIGHT == (float) 38);
37 REQUIRE(temps.SET == (float) 20.0);
38 REQUIRE(temps.COOLING_POWER == (float) 102);
39 }
40
41
42 }
43
44 GIVEN("An invalid response to temp from the OCAM, too short")
45 {
46 int rv;
47
48 WHEN("Temp response is too short")
49 {
50 std::string tstr = "Temperatures : CCD[26.3] CPU[41] POWER[34] BIAS[47] WATER[24.2] LEFT[33] RIGHT[38] SET[200]\nCooling Power";
51 ocamTemps temps;
52
53 rv = parseTemps(temps, tstr);
54
55 REQUIRE(rv == -1);
56 }
57
58
59 }
60}
61
62SCENARIO( "Parsing the gain response", "[ocamUtils]" )
63{
64 GIVEN("A valid response to gain from the OCAM")
65 {
66 int rv;
67
68 WHEN("Valid gain response, gain=2")
69 {
70 std::string tstr = "Gain set to 2 \n\n";
71
72 unsigned emgain = 1;
73
74 rv = parseEMGain(emgain, tstr);
75
76 REQUIRE(rv == 0);
77 REQUIRE(emgain == 2);
78 }
79
80
81 }
82
83 GIVEN("A valid response to gain from the OCAM")
84 {
85 int rv;
86
87 WHEN("Valid gain response, gain=512")
88 {
89 std::string tstr = "Gain set to 512 \n\n";
90
91 unsigned emgain = 1;
92
93 rv = parseEMGain(emgain, tstr);
94
95 REQUIRE(rv == 0);
96 REQUIRE(emgain == 512);
97 }
98
99
100
101 }
102
103 GIVEN("An invalid response to gain from the OCAM")
104 {
105 int rv;
106
107 WHEN("Invalid gain response, too short, no trailing space")
108 {
109 std::string tstr = "Gain set to 512\n\n";
110
111 unsigned emgain = 1;
112
113 rv = parseEMGain(emgain, tstr);
114
115 REQUIRE(rv == -1);
116 REQUIRE(emgain == 0);
117 }
118
119 WHEN("Invalid gain response, too short, no gain")
120 {
121 std::string tstr = "Gain set to \n\n";
122
123 unsigned emgain = 1;
124
125 rv = parseEMGain(emgain, tstr);
126
127 REQUIRE(rv == -1);
128 REQUIRE(emgain == 0);
129 }
130
131 WHEN("Invalid gain response, too long")
132 {
133 std::string tstr = "Gain set to 512 rubbish added\n\n";
134
135 unsigned emgain = 1;
136
137 rv = parseEMGain(emgain, tstr);
138
139 REQUIRE(rv == -1);
140 REQUIRE(emgain == 0);
141 }
142
143 WHEN("Invalid gain response, low gain")
144 {
145 std::string tstr = "Gain set to 0 \n\n";
146
147 unsigned emgain = 1;
148
149 rv = parseEMGain(emgain, tstr);
150
151 REQUIRE(rv == -1);
152 REQUIRE(emgain == 0);
153 }
154
155 WHEN("Invalid gain response, high gain")
156 {
157 std::string tstr = "Gain set to 601 \n\n";
158
159 unsigned emgain = 1;
160
161 rv = parseEMGain(emgain, tstr);
162
163 REQUIRE(rv == -1);
164 REQUIRE(emgain == 0);
165 }
166
167 WHEN("Invalid gain response, bad gain")
168 {
169 std::string tstr = "Gain set to x \n\n";
170
171 unsigned emgain = 1;
172
173 rv = parseEMGain(emgain, tstr);
174
175 REQUIRE(rv == -1);
176 REQUIRE(emgain == 0);
177 }
178 }
179}
180
181} //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:64
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:20
float WATER
Cooling water temperature.
Definition ocamUtils.hpp:25
float COOLING_POWER
the cooling power in 100 mw.
Definition ocamUtils.hpp:29
float BIAS
Bias temperature.
Definition ocamUtils.hpp:24
float SET
The CCD set temeperature.
Definition ocamUtils.hpp:28
float CCD
The detector temperature.
Definition ocamUtils.hpp:21
float POWER
Power supply temperature.
Definition ocamUtils.hpp:23
float CPU
The CPU temperature.
Definition ocamUtils.hpp:22
float LEFT
The left amplifier temperature.
Definition ocamUtils.hpp:26
float RIGHT
The right amplifier temperature.
Definition ocamUtils.hpp:27