API
 
Loading...
Searching...
No Matches
stdMotionStage_test.cpp
Go to the documentation of this file.
1/** \file stdMotionStage_test.cpp
2 * \brief Catch2 tests for the stdMotionStage helper.
3 * \author Jared R. Males (jaredmales@gmail.com)
4 *
5 */
6
7#include "../../../../tests/testXWC.hpp"
8
9#include "../../MagAOXApp.hpp"
10#include "../stdMotionStage.hpp"
11
12using namespace MagAOX::app;
13
14namespace libXWCTest
15{
16namespace appTest
17{
18namespace devTest
19{
20
21/** \defgroup stdMotionStage_tests libXWC::app::dev::stdMotionStage Unit Tests
22 * \ingroup app_dev_unit_tests
23 */
24
25/// Test harness for exercising stdMotionStage preset-name callbacks without the INDI validation short-circuit.
26/** \ingroup stdMotionStage_tests
27 */
28class stdMotionStageHarness : public MagAOXApp<false>, public dev::stdMotionStage<stdMotionStageHarness>
29{
31
32 protected:
33 float m_lastMoveTarget{ -1.0f }; ///< Last target passed to moveTo by the helper.
34
35 int m_moveCalls{ 0 }; ///< Number of motion requests issued by the helper.
36
37 static std::string s_lastLogMessage; ///< Most recent text log message captured from stdMotionStage.
38
39 static logPrioT s_lastLogLevel; ///< Most recent log priority captured from stdMotionStage.
40
41 static int s_logCount; ///< Number of captured stdMotionStage log messages.
42
43 public:
44 /// Construct a stdMotionStage test harness with a presetName callback property.
46
47 /// Destroy the stdMotionStage test harness.
49
50 /// Reset the captured stdMotionStage logging state shared across harness instances.
51 static void resetLogState();
52
53 /// Configure the preset-name list and notation used by stdMotionStage.
54 void
55 configurePresets( const std::vector<std::string> &presetNames /**< [in] configured preset names */,
56 const std::string &presetNotation /**< [in] singular preset notation such as preset or filter */
57 );
58
59 /// Apply a presetName request property to the stdMotionStage callback under test.
61 const std::vector<std::pair<std::string, pcf::IndiElement::SwitchStateType>> &elements /**< [in] requested
62 switch
63 elements and
64 states */
65 );
66
67 /// Get the number of move requests accepted by stdMotionStage.
68 int moveCalls() const;
69
70 /// Get the last move target accepted by stdMotionStage.
71 float lastMoveTarget() const;
72
73 /// Get the most recent stdMotionStage text log message captured by the harness.
74 static const std::string &lastLogMessage();
75
76 /// Get the most recent stdMotionStage log priority captured by the harness.
78
79 /// Get the number of stdMotionStage log messages captured by the harness.
80 static int logCount();
81
82 /// Capture stdMotionStage log messages instead of sending them to the normal logger.
83 template <typename logT, int retval = 0>
84 static int log( const typename logT::messageT &msg /**< [in] the logged message */,
85 logPrioT level = logPrio::LOG_DEFAULT /**< [in] the logged priority */
86 );
87
88 /// No-op startup implementation required by MagAOXApp for testing.
89 int appStartup() override;
90
91 /// No-op logic implementation required by MagAOXApp for testing.
92 int appLogic() override;
93
94 /// No-op shutdown implementation required by MagAOXApp for testing.
96
97 /// No-op stop implementation required by stdMotionStage for testing.
98 int stop();
99
100 /// No-op homing implementation required by stdMotionStage for testing.
101 int startHoming();
102
103 /// Return a fixed preset number for testing paths that query the current preset.
104 float presetNumber();
105
106 /// Record a requested move target when stdMotionStage accepts a motion request.
107 int moveTo( float target /**< [in] the accepted move target */ );
108};
109
111
112logPrioT stdMotionStageHarness::s_lastLogLevel = logPrio::LOG_DEFAULT;
113
115
117{
118 m_configName = "stest";
119
120 m_indiP_presetName = pcf::IndiProperty( pcf::IndiProperty::Switch );
121 m_indiP_presetName.setDevice( m_configName );
122 m_indiP_presetName.setName( "presetName" );
123
125}
126
128
135
136void stdMotionStageHarness::configurePresets( const std::vector<std::string> &presetNames,
137 const std::string &presetNotation )
138{
141}
142
144 const std::vector<std::pair<std::string, pcf::IndiElement::SwitchStateType>> &elements )
145{
146 pcf::IndiProperty ip( pcf::IndiProperty::Switch );
147 ip.setDevice( m_configName );
148 ip.setName( "presetName" );
149
150 for( const auto &element : elements )
151 {
152 ip.add( pcf::IndiElement( element.first ) );
153 ip[element.first].setSwitchState( element.second );
154 }
155
157}
158
160{
161 return m_moveCalls;
162}
163
165{
166 return m_lastMoveTarget;
167}
168
170{
171 return s_lastLogMessage;
172}
173
178
180{
181 return s_logCount;
182}
183
184template <typename logT, int retval>
185int stdMotionStageHarness::log( const typename logT::messageT &msg, logPrioT level )
186{
188 logT::msgString( const_cast<uint8_t *>( msg.builder.GetBufferPointer() ), msg.builder.GetSize() );
190 ++s_logCount;
191
192 return retval;
193}
194
196{
197 return 0;
198}
199
201{
202 return 0;
203}
204
206{
207 return 0;
208}
209
211{
212 return 0;
213}
214
216{
217 return 0;
218}
219
221{
222 return 0.0f;
223}
224
226{
228 ++m_moveCalls;
229
230 return 0;
231}
232
233/// Verify stdMotionStage logs and rejects invalid preset-name selections before issuing motion requests.
234/**
235 * \ingroup stdMotionStage_tests
236 */
237TEST_CASE( "stdMotionStage rejects invalid preset-name selections", "[dev::stdMotionStage]" )
238{
239 // clang-format off
240 #ifdef STDMOTIONSTAGE_TEST_DOXYGEN_REF
242 #endif
243 // clang-format on
244
245 SECTION( "quoted preset names are logged and rejected" )
246 {
248
249 app.configurePresets( { "open", "focus" }, "preset" );
251
252 REQUIRE( app.applyPresetNameRequest( { { "\"focus\"", pcf::IndiElement::On } } ) == -1 );
255 REQUIRE( stdMotionStageHarness::lastLogMessage() == "Unknown presetName selected: \"focus\"" );
256 REQUIRE( app.moveCalls() == 0 );
257 REQUIRE( app.lastMoveTarget() == -1.0f );
258 }
259
260 SECTION( "invalid names are rejected even when a valid preset is also selected" )
261 {
263
264 app.configurePresets( { "open", "focus" }, "filter" );
266
268 { { "open", pcf::IndiElement::On }, { "bogus", pcf::IndiElement::On } } ) == -1 );
271 REQUIRE( stdMotionStageHarness::lastLogMessage() == "Unknown filterName selected: bogus" );
272 REQUIRE( app.moveCalls() == 0 );
273 REQUIRE( app.lastMoveTarget() == -1.0f );
274 }
275}
276
277} // namespace devTest
278} // namespace appTest
279} // namespace libXWCTest
The base-class for XWCTk applications.
std::string m_configName
The name of the configuration file (minus .conf).
MagAO-X standard motion stage interface.
std::vector< std::string > m_presetNames
The names of each position on the stage.
std::string m_presetNotation
Notation used to refer to a preset, should be singular, as in "preset" or "filter".
pcf::IndiProperty m_indiP_presetName
The name of the active preset selection.
int newCallBack_m_indiP_presetName(const pcf::IndiProperty &ipRecv)
Callback to process a NEW preset name request.
Test harness for exercising stdMotionStage preset-name callbacks without the INDI validation short-ci...
static int logCount()
Get the number of stdMotionStage log messages captured by the harness.
int stop()
No-op stop implementation required by stdMotionStage for testing.
static std::string s_lastLogMessage
Most recent text log message captured from stdMotionStage.
int appStartup() override
No-op startup implementation required by MagAOXApp for testing.
static void resetLogState()
Reset the captured stdMotionStage logging state shared across harness instances.
stdMotionStageHarness()
Construct a stdMotionStage test harness with a presetName callback property.
void configurePresets(const std::vector< std::string > &presetNames, const std::string &presetNotation)
Configure the preset-name list and notation used by stdMotionStage.
int moveTo(float target)
Record a requested move target when stdMotionStage accepts a motion request.
static logPrioT lastLogLevel()
Get the most recent stdMotionStage log priority captured by the harness.
int startHoming()
No-op homing implementation required by stdMotionStage for testing.
int moveCalls() const
Get the number of move requests accepted by stdMotionStage.
int m_moveCalls
Number of motion requests issued by the helper.
static int log(const typename logT::messageT &msg, logPrioT level=logPrio::LOG_DEFAULT)
Capture stdMotionStage log messages instead of sending them to the normal logger.
static logPrioT s_lastLogLevel
Most recent log priority captured from stdMotionStage.
float m_lastMoveTarget
Last target passed to moveTo by the helper.
int appShutdown() override
No-op shutdown implementation required by MagAOXApp for testing.
float lastMoveTarget() const
Get the last move target accepted by stdMotionStage.
static const std::string & lastLogMessage()
Get the most recent stdMotionStage text log message captured by the harness.
~stdMotionStageHarness() noexcept override
Destroy the stdMotionStage test harness.
float presetNumber()
Return a fixed preset number for testing paths that query the current preset.
static int s_logCount
Number of captured stdMotionStage log messages.
int appLogic() override
No-op logic implementation required by MagAOXApp for testing.
int applyPresetNameRequest(const std::vector< std::pair< std::string, pcf::IndiElement::SwitchStateType > > &elements)
Apply a presetName request property to the stdMotionStage callback under test.
int8_t logPrioT
The type of the log priority code.
Definition logDefs.hpp:21
TEST_CASE("stdMotionStage rejects invalid preset-name selections", "[dev::stdMotionStage]")
Verify stdMotionStage logs and rejects invalid preset-name selections before issuing motion requests.
std::stringstream msg
static constexpr logPrioT LOG_ERROR
An error has occured which the software will attempt to correct.
static constexpr logPrioT LOG_DEFAULT
Used to denote "use the default level for this log type".
Namespace for all libXWC tests.