aqhome-react: enable unit tests.

This commit is contained in:
Martin Preuss
2025-03-18 22:56:10 +01:00
parent a14c2c892c
commit 9a7a7e75f9

View File

@@ -14,13 +14,13 @@
#include "./net_read.h"
#include "aqhome-react/units/u_timer.h"
#include "aqhome-react/types/prgrule.h"
//#include "aqhome-react/types/prgrule-t.h"
#include "aqhome-react/types/prgrule-t.h"
#include "aqhome/aqhome.h"
#include "aqhome/data/path-t.h"
#include "aqhome/data/vars-t.h"
//#include "aqhome/data/vars_dbread-t.h"
//#include "aqhome/data/vars_dbwrite-t.h"
#include "aqhome/data/vars_dbread-t.h"
#include "aqhome/data/vars_dbwrite-t.h"
#include <gwenhywfar/gwenhywfar.h>
#include <gwenhywfar/args.h>
@@ -69,7 +69,8 @@
static void _runService(AQH_OBJECT *aqh, AQH_EVENT_LOOP *eventLoop);
static int _diffInSeconds(time_t t1, time_t t0);
//static int _testModules(int argc, char **argv);
static int _testModules(int argc, char **argv);
static int _test(int argc, char **argv);
#ifdef HAVE_SIGNAL_H
static int _setSignalHandlers(void);
@@ -126,6 +127,26 @@ int main(int argc, char **argv)
gui=GWEN_Gui_CGui_new();
GWEN_Gui_SetGui(gui);
if (argc>1) {
const char *cmd;
cmd=argv[1];
if (cmd && *cmd) {
if (strcasecmp(cmd, "unittest")==0) {
rv=_testModules(argc, argv);
GWEN_Gui_SetGui(NULL);
GWEN_Gui_free(gui);
return rv;
}
else if (strcasecmp(cmd, "test")==0) {
rv=_test(argc, argv);
GWEN_Gui_SetGui(NULL);
GWEN_Gui_free(gui);
return rv;
}
}
}
eventLoop=AQH_EventLoop_new();
aqh=AQH_ReactServer_new(eventLoop);
rv=AQH_ReactServer_Init(aqh, argc, argv);
@@ -287,7 +308,7 @@ void _signalHandler(int s)
}
#if 0
int _testModules(int argc, char **argv)
{
GWEN_GUI *gui;
@@ -344,7 +365,29 @@ int _testModules(int argc, char **argv)
GWEN_Gui_free(gui);
return 0;
}
#endif
int _test(int argc, char **argv)
{
if (argc>2) {
AQHREACT_PRGRULE_LIST *ruleList;
GWEN_Logger_SetLevel(0, GWEN_LoggerLevel_Info);
ruleList=AQHREACT_PrgRule_ReadRules(argv[2]);
if (ruleList==NULL) {
DBG_ERROR(NULL, "Error in rules");
return 2;
}
DBG_ERROR(NULL, "Rules ok (%d)", AQHREACT_PrgRule_List_GetCount(ruleList));
AQHREACT_PrgRule_List_free(ruleList);
return 0;
}
else {
DBG_ERROR(NULL, "No rules");
return 2;
}
}