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 * \ingroup ocam2KCtrl_files
6 */
7
8#include "../../../tests/testXWC.hpp"
9
10#include "../ocamUtils.hpp"
11
12using namespace MagAOX::app;
13
14namespace libXWCTest
15{
16
17/** \addtogroup ocam2KCtrl_unit_test
18 * \brief Additional utility tests for the ocam2KCtrl application.
19 *
20 * \ingroup application_unit_test
21 */
22
23/// Namespace for `ocam2KCtrl` utility unit tests.
24/** \ingroup ocam2KCtrl_unit_test
25 */
26namespace ocam2KCtrlTest
27{
28
29/// Verify `parseTemps()` accepts a valid OCAM temperature response and rejects truncated data.
30/**
31 * \ingroup ocam2KCtrl_unit_test
32 */
33TEST_CASE( "ocam2KCtrl utility helpers parse temperature responses", "[ocamUtils]" )
34{
35 // clang-format off
36 #ifdef OCAM2KCTRL_TEST_DOXYGEN_REF
37 parseTemps( *(ocamTemps *)nullptr, "" );
38 #endif
39 // clang-format on
40
41 SECTION( "valid temperature responses are parsed" )
42 {
43 std::string tstr = "Temperatures : CCD[26.3] CPU[41] POWER[34] BIAS[47] WATER[24.2] LEFT[33] RIGHT[38] "
44 "SET[200]\nCooling Power [102]mW.\n\n";
45 ocamTemps temps;
46 int rv = parseTemps( temps, tstr );
47
48 REQUIRE( rv == 0 );
49 REQUIRE( temps.CCD == (float)26.3 );
50 REQUIRE( temps.CPU == (float)41 );
51 REQUIRE( temps.POWER == (float)34 );
52 REQUIRE( temps.BIAS == (float)47 );
53 REQUIRE( temps.WATER == (float)24.2 );
54 REQUIRE( temps.LEFT == (float)33 );
55 REQUIRE( temps.RIGHT == (float)38 );
56 REQUIRE( temps.SET == (float)20.0 );
57 REQUIRE( temps.COOLING_POWER == (float)102 );
58 }
59
60 SECTION( "truncated temperature responses are rejected" )
61 {
62 std::string tstr = "Temperatures : CCD[26.3] CPU[41] POWER[34] BIAS[47] WATER[24.2] LEFT[33] RIGHT[38] "
63 "SET[200]\nCooling Power";
64 ocamTemps temps;
65 int rv = parseTemps( temps, tstr );
66
67 REQUIRE( rv == -1 );
68 }
69}
70
71/// Verify `parseEMGain()` accepts valid OCAM gain responses and rejects malformed strings.
72/**
73 * \ingroup ocam2KCtrl_unit_test
74 */
75TEST_CASE( "ocam2KCtrl utility helpers parse gain responses", "[ocamUtils]" )
76{
77 // clang-format off
78 #ifdef OCAM2KCTRL_TEST_DOXYGEN_REF
79 parseEMGain( *(unsigned *)nullptr, "" );
80 #endif
81 // clang-format on
82
83 SECTION( "valid gain responses are parsed" )
84 {
85 unsigned emgain = 1;
86 int rv = parseEMGain( emgain, "Gain set to 2 \n\n" );
87
88 REQUIRE( rv == 0 );
89 REQUIRE( emgain == 2 );
90 }
91
92 SECTION( "maximum supported gains are parsed" )
93 {
94 unsigned emgain = 1;
95 int rv = parseEMGain( emgain, "Gain set to 512 \n\n" );
96
97 REQUIRE( rv == 0 );
98 REQUIRE( emgain == 512 );
99 }
100
101 SECTION( "gain responses without the trailing delimiter are rejected" )
102 {
103 unsigned emgain = 1;
104 int rv = parseEMGain( emgain, "Gain set to 512\n\n" );
105
106 REQUIRE( rv == -1 );
107 REQUIRE( emgain == 0 );
108 }
109
110 SECTION( "gain responses without a numeric value are rejected" )
111 {
112 unsigned emgain = 1;
113 int rv = parseEMGain( emgain, "Gain set to \n\n" );
114
115 REQUIRE( rv == -1 );
116 REQUIRE( emgain == 0 );
117 }
118
119 SECTION( "gain responses with trailing junk are rejected" )
120 {
121 unsigned emgain = 1;
122 int rv = parseEMGain( emgain, "Gain set to 512 rubbish added\n\n" );
123
124 REQUIRE( rv == -1 );
125 REQUIRE( emgain == 0 );
126 }
127
128 SECTION( "gain responses below the supported range are rejected" )
129 {
130 unsigned emgain = 1;
131 int rv = parseEMGain( emgain, "Gain set to 0 \n\n" );
132
133 REQUIRE( rv == -1 );
134 REQUIRE( emgain == 0 );
135 }
136
137 SECTION( "gain responses above the supported range are rejected" )
138 {
139 unsigned emgain = 1;
140 int rv = parseEMGain( emgain, "Gain set to 601 \n\n" );
141
142 REQUIRE( rv == -1 );
143 REQUIRE( emgain == 0 );
144 }
145
146 SECTION( "gain responses with invalid tokens are rejected" )
147 {
148 unsigned emgain = 1;
149 int rv = parseEMGain( emgain, "Gain set to x \n\n" );
150
151 REQUIRE( rv == -1 );
152 REQUIRE( emgain == 0 );
153 }
154}
155
156} // namespace ocam2KCtrlTest
157
158} // namespace libXWCTest
TEST_CASE("ocam2KCtrl lifecycle entrypoints handle startup failures and POWERON logic", "[ocam2KCtrl]")
Verify lifecycle entrypoints cover startup failure handling and the POWERON fast-return path.
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.
Namespace for all libXWC tests.
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