Files
aqhomecontrol/aqhome/data/vars-t.c
2024-05-09 14:57:12 +02:00

128 lines
3.2 KiB
C

/****************************************************************************
* 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 <gwenhywfar/testframework.h>
#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