From 9a7a7e75f93911f194b10eb46bda550f2d9d3b10 Mon Sep 17 00:00:00 2001 From: Martin Preuss Date: Tue, 18 Mar 2025 22:56:10 +0100 Subject: [PATCH] aqhome-react: enable unit tests. --- apps/aqhome-react/main.c | 55 +++++++++++++++++++++++++++++++++++----- 1 file changed, 49 insertions(+), 6 deletions(-) diff --git a/apps/aqhome-react/main.c b/apps/aqhome-react/main.c index c125576..6d9e351 100644 --- a/apps/aqhome-react/main.c +++ b/apps/aqhome-react/main.c @@ -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 #include @@ -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; + } +}