API
MagAOXApp_test.cpp
Go to the documentation of this file.
1 //#define CATCH_CONFIG_MAIN
2 #include "../../../tests/catch2/catch.hpp"
3 
4 #include <mx/sys/timeUtils.hpp>
5 
6 #include "../MagAOXApp.hpp"
7 
8 namespace MagAOXApp_tests
9 {
10 
12 {
13  MagAOXApp_test() : MagAOXApp("sha1",false){}
14 
15  virtual int appStartup(){return 0;}
16  virtual int appLogic(){return 0;}
17  virtual int appShutdown(){return 0;}
18 
19  std::string configName()
20  {
22  }
23 
24  void configName(const std::string & cn)
25  {
26  m_configName = cn;
27 
29  }
30 
31  int called_back {0};
32 };
33 
34 int callback( void * app, const pcf::IndiProperty &ipRecv)
35 {
36  static_cast<void>(ipRecv); //be unused
37 
38  MagAOXApp_test * appt = static_cast<MagAOXApp_test*>(app);
39 
40  appt->called_back = 1;
41 
42  return 0;
43 }
44 
45 SCENARIO( "MagAOXApp INDI NewProperty", "[MagAOXApp]" )
46 {
47  GIVEN("a new property request")
48  {
49  WHEN("a wrong device name")
50  {
51  MagAOXApp_test app;
52 
53  app.configName("test");
54 
55  REQUIRE(app.configName() == "test");
56 
57  pcf::IndiProperty prop;
58  app.registerIndiPropertyNew(prop, "nprop", pcf::IndiProperty::Number, pcf::IndiProperty::ReadWrite, pcf::IndiProperty::Idle, callback);
59 
60  pcf::IndiProperty nprop;
61 
62  //First test the right device name
63  nprop.setDevice("test");
64  nprop.setName("nprop");
65 
66  app.handleNewProperty(nprop);
67 
68  REQUIRE(app.called_back == 1);
69 
70  app.called_back = 0;
71 
72  //Now test the wrong device name
73  nprop.setDevice("wrong");
74 
75  app.handleNewProperty(nprop);
76 
77  REQUIRE(app.called_back == 0);
78 
79  }
80  }
81 }
82 
83 
84 } //namespace MagAOXApp_tests
#define GIVEN(desc)
Definition: catch.hpp:17763
#define WHEN(desc)
Definition: catch.hpp:17765
#define REQUIRE(...)
Definition: catch.hpp:17676
The base-class for MagAO-X applications.
Definition: MagAOXApp.hpp:73
std::string m_configName
The name of the configuration file (minus .conf).
Definition: MagAOXApp.hpp:83
int registerIndiPropertyNew(pcf::IndiProperty &prop, int(*)(void *, const pcf::IndiProperty &))
Register an INDI property which is exposed for others to request a New Property for.
indiDriver< MagAOXApp > * m_indiDriver
The INDI driver wrapper. Constructed and initialized by execute, which starts and stops communication...
Definition: MagAOXApp.hpp:542
void handleNewProperty(const pcf::IndiProperty &ipRecv)
Handler for the new INDI property request.
Definition: MagAOXApp.hpp:3064
MagAOXApp()=delete
Default c'tor is deleted.
std::string configName()
Get the config name.
Definition: MagAOXApp.hpp:3477
int callback(void *app, const pcf::IndiProperty &ipRecv)
SCENARIO("MagAOXApp INDI NewProperty", "[MagAOXApp]")
const pcf::IndiProperty & ipRecv
Definition: MagAOXApp.hpp:3434
virtual int appStartup()
Any tasks to perform prior to the main event loop go here.
virtual int appLogic()
This is where derived applications implement their main FSM logic.
void configName(const std::string &cn)
virtual int appShutdown()
Any tasks to perform after main loop exit go here.