8#include "../../../tests/testXWC.hpp"
10#include "../cred2Utils.hpp"
26namespace cred2CtrlTest
33TEST_CASE(
"cred2Ctrl utility helpers clean CLI responses",
"[cred2Utils]" )
36 #ifdef CRED2CTRL_TEST_DOXYGEN_REF
41 SECTION(
"responses without prompts are trimmed" )
45 REQUIRE( clean ==
"400" );
48 SECTION(
"responses with prompts are trimmed" )
52 REQUIRE( clean ==
"400" );
60TEST_CASE(
"cred2Ctrl utility helpers parse float responses",
"[cred2Utils]" )
63 #ifdef CRED2CTRL_TEST_DOXYGEN_REF
68 SECTION(
"valid float responses are parsed" )
74 REQUIRE( value == Approx( -15.5f ) );
77 SECTION(
"non-numeric responses are rejected" )
90TEST_CASE(
"cred2Ctrl utility helpers parse float-vector responses",
"[cred2Utils]" )
93 #ifdef CRED2CTRL_TEST_DOXYGEN_REF
98 SECTION(
"valid delimited float responses are parsed" )
100 std::vector<float> values;
104 REQUIRE( values.size() == 6 );
105 REQUIRE( values[0] == Approx( 40.50f ) );
106 REQUIRE( values[1] == Approx( 37.00f ) );
107 REQUIRE( values[2] == Approx( 40.25f ) );
108 REQUIRE( values[3] == Approx( -14.92f ) );
109 REQUIRE( values[4] == Approx( 2.29f ) );
110 REQUIRE( values[5] == Approx( 27.50f ) );
113 SECTION(
"mismatched element counts are rejected" )
115 std::vector<float> values;
119 REQUIRE( values.empty() );
127TEST_CASE(
"cred2Ctrl utility helpers parse range responses",
"[cred2Utils]" )
130 #ifdef CRED2CTRL_TEST_DOXYGEN_REF
137 int rv =
cred2ParseRange( firstValue, secondValue,
"0-639\r\nfli-cli>" );
140 REQUIRE( firstValue == 0 );
141 REQUIRE( secondValue == 639 );
148TEST_CASE(
"cred2Ctrl utility helpers parse boolean responses",
"[cred2Utils]" )
151 #ifdef CRED2CTRL_TEST_DOXYGEN_REF
160 REQUIRE( value ==
true );
167TEST_CASE(
"cred2Ctrl utility helpers parse crop responses",
"[cred2Utils]" )
170 #ifdef CRED2CTRL_TEST_DOXYGEN_REF
171 cred2ParseCropState( *(
bool *)
nullptr, *(
int *)
nullptr, *(
int *)
nullptr, *(
int *)
nullptr, *(
int *)
nullptr,
"" );
175 bool enabled =
false;
180 int rv =
cred2ParseCropState( enabled, startColumn, endColumn, startRow, endRow,
"on:192-447:128-383\r\n" );
183 REQUIRE( enabled ==
true );
184 REQUIRE( startColumn == 192 );
185 REQUIRE( endColumn == 447 );
186 REQUIRE( startRow == 128 );
187 REQUIRE( endRow == 383 );
194TEST_CASE(
"cred2Ctrl utility helpers format ROI commands",
"[cred2Utils]" )
197 #ifdef CRED2CTRL_TEST_DOXYGEN_REF
205 SECTION(
"full-frame centers expand to the detector corners" )
214 REQUIRE( roi.
endRow == 511 );
218 SECTION(
"subframe centers convert to C-RED 2 row and column specifications" )
229 SECTION(
"corner-defined subframes convert back to a MagAO-X center and size" )
242 int rv =
cred2RoiToCenter( centerX, centerY, width, height, roi, 640, 512 );
245 REQUIRE( centerX == Approx( 319.5f ) );
246 REQUIRE( centerY == Approx( 255.5f ) );
247 REQUIRE( width == 256 );
248 REQUIRE( height == 256 );
TEST_CASE("cred2Ctrl lifecycle entrypoints handle startup failures and success", "[cred2Ctrl]")
Verify lifecycle entrypoints cover startup failure handling and successful startup cleanup.
bool fullFrame
True when the ROI spans the full detector.
int endRow
Last included row.
int startRow
First included row.
int endColumn
Last included column.
int startColumn
First included column.
C-RED 2 ROI expressed as 0-based inclusive column and row limits.
std::string cred2ColumnsSpec(const cred2Roi &roi)
Format the column command payload for set cropping columns.
std::string cred2CleanResponse(const std::string &response)
Strip an optional prompt and surrounding whitespace from a C-RED 2 CLI response.
int cred2ParseRange(int &firstValue, int &secondValue, const std::string &response)
Parse a raw range response such as 0-639.
int cred2RoiToCenter(float ¢erX, float ¢erY, int &width, int &height, const cred2Roi &roi, int fullWidth, int fullHeight)
Convert C-RED 2 ROI corners into a MagAO-X ROI center/size description.
int cred2ParseCropState(bool &enabled, int &startColumn, int &endColumn, int &startRow, int &endRow, const std::string &response)
Parse a raw cropping status response such as on or on:192-447:128-383.
int cred2RoiFromCenter(cred2Roi &roi, float centerX, float centerY, int width, int height, int fullWidth, int fullHeight)
Convert a MagAO-X ROI center/size description into C-RED 2 corners.
int cred2ParseFloatVector(std::vector< float > &values, const std::string &response, size_t expectedValues)
Parse a delimited list of raw numeric responses into a float vector.
std::string cred2RowsSpec(const cred2Roi &roi)
Format the row command payload for set cropping rows.
int cred2ParseFloat(float &value, const std::string &response)
Parse a raw numeric response into a float.
int cred2ParseBool(bool &value, const std::string &response)
Parse a raw on/off response into a boolean.
Namespace for all libXWC tests.