diff --git a/apps/aqhome-react/main.c b/apps/aqhome-react/main.c index 24b9321..f20b4db 100644 --- a/apps/aqhome-react/main.c +++ b/apps/aqhome-react/main.c @@ -19,6 +19,7 @@ #include "aqhome/aqhome.h" #include "aqhome/data/path-t.h" +#include "aqhome/data/vars-t.h" #include #include @@ -315,6 +316,12 @@ int _testModules(int argc, char **argv) return 2; } + rv=AQH_Vars_AddTests(TestFramework_GetModulesRoot(tf)); + if (rv<0) { + fprintf(stderr, "Adding module \"vars\" failed.\n"); + return 2; + } + argc--; argv++; rv=TestFramework_Run(tf, argc, argv); diff --git a/aqhome/data/0BUILD b/aqhome/data/0BUILD index c0fdb7a..61d5297 100644 --- a/aqhome/data/0BUILD +++ b/aqhome/data/0BUILD @@ -87,6 +87,8 @@ path-t.h path-t.c + vars-t.h + vars-t.c diff --git a/aqhome/data/vars-t.c b/aqhome/data/vars-t.c new file mode 100644 index 0000000..e36ca32 --- /dev/null +++ b/aqhome/data/vars-t.c @@ -0,0 +1,127 @@ +/**************************************************************************** + * This file is part of the project Gwenhywfar. + * AqHome (c) by 2024 Martin Preuss, all rights reserved. + * + * The license for this file can be found in the file COPYING which you + * should have received along with this file. + ****************************************************************************/ + +/* This file is included by "path.c" */ + + +#include +#include "vars-t.h" + + +#ifdef AQHOME_ENABLE_TESTCODE + + +/* ------------------------------------------------------------------------------------------------ + * forward declarations + * ------------------------------------------------------------------------------------------------ + */ + +static int GWENHYWFAR_CB test1(GWEN_TEST_MODULE *mod); + + + +/* ------------------------------------------------------------------------------------------------ + * implementations + * ------------------------------------------------------------------------------------------------ + */ + +int AQH_Vars_AddTests(GWEN_TEST_MODULE *mod) +{ + GWEN_TEST_MODULE *newMod; + + newMod=GWEN_Test_Module_AddModule(mod, "AQH_Vars", NULL); + + GWEN_Test_Module_AddTest(newMod, "test 1: setCharValue", test1, NULL); + + return 0; +} + + + +int test1(GWEN_UNUSED GWEN_TEST_MODULE *mod) +{ + AQH_VARS *vtRoot; + AQH_VARS *vtVar; + AQH_VARS *vtValue; + int rv; + + vtRoot=AQH_Vars_CreateGroup("Root"); + rv=AQH_Vars_SetCharValue(vtRoot, 0, "var1", "value1"); + if (rv<0) { + DBG_ERROR(AQH_LOGDOMAIN, "here (%d)", rv); + return rv; + } + + vtVar=AQH_Vars_Tree2_GetFirstChild(vtRoot); + if (vtVar==NULL) { + DBG_ERROR(AQH_LOGDOMAIN, "No variable"); + AQH_Vars_free(vtRoot); + return GWEN_ERROR_GENERIC; + } + + if (AQH_Vars_Tree2_GetNext(vtVar)) { + DBG_ERROR(AQH_LOGDOMAIN, "More than one child"); + AQH_Vars_free(vtRoot); + return GWEN_ERROR_GENERIC; + } + + if (vtVar->dataType!=AQH_Vars_DataType_Variable) { + DBG_ERROR(AQH_LOGDOMAIN, "First child of root node is not a variable"); + AQH_Vars_free(vtRoot); + return GWEN_ERROR_GENERIC; + } + + if (!(vtVar->data.dataString && -1!=strcasecmp(vtVar->data.dataString, "var1"))) { + DBG_ERROR(AQH_LOGDOMAIN, "First child of root node is not the variable we set"); + AQH_Vars_free(vtRoot); + return GWEN_ERROR_GENERIC; + } + + + vtValue=AQH_Vars_Tree2_GetFirstChild(vtVar); + if (vtValue==NULL) { + DBG_ERROR(AQH_LOGDOMAIN, "No value"); + AQH_Vars_free(vtRoot); + return GWEN_ERROR_GENERIC; + } + + if (AQH_Vars_Tree2_GetNext(vtValue)) { + DBG_ERROR(AQH_LOGDOMAIN, "More than one value"); + AQH_Vars_free(vtRoot); + return GWEN_ERROR_GENERIC; + } + + if (vtValue->dataType!=AQH_Vars_DataType_ValueString) { + DBG_ERROR(AQH_LOGDOMAIN, "First child of root node is not a string value"); + AQH_Vars_free(vtRoot); + return GWEN_ERROR_GENERIC; + } + + if (!(vtValue->data.dataString && -1!=strcasecmp(vtValue->data.dataString, "value1"))) { + DBG_ERROR(AQH_LOGDOMAIN, "First child of variable node is not the value we set"); + AQH_Vars_free(vtRoot); + return GWEN_ERROR_GENERIC; + } + + AQH_Vars_free(vtRoot); + + return 0; +} + + + +#else + +int AQH_Vars_AddTests(GWEN_TEST_MODULE *mod) +{ + DBG_ERROR(GWEN_LOGDOMAIN, "AqHome was compiled without test code enabled."); + return GWEN_ERROR_GENERIC; +} + + +#endif diff --git a/aqhome/data/vars-t.h b/aqhome/data/vars-t.h new file mode 100644 index 0000000..902cc4e --- /dev/null +++ b/aqhome/data/vars-t.h @@ -0,0 +1,25 @@ +/**************************************************************************** + * This file is part of the project Gwenhywfar. + * AqHome (c) by 2024 Martin Preuss, all rights reserved. + * + * The license for this file can be found in the file COPYING which you + * should have received along with this file. + ****************************************************************************/ + +#ifndef AQH_VARS_T_H +#define AQH_VARS_T_H + + +#include +#include + + + +/** + * Tests for "Vars" module. + */ +AQHOME_API int AQH_Vars_AddTests(GWEN_TEST_MODULE *mod); + + + +#endif