Add module test for AQH_Vars
This commit is contained in:
@@ -19,6 +19,7 @@
|
||||
|
||||
#include "aqhome/aqhome.h"
|
||||
#include "aqhome/data/path-t.h"
|
||||
#include "aqhome/data/vars-t.h"
|
||||
|
||||
#include <gwenhywfar/gwenhywfar.h>
|
||||
#include <gwenhywfar/args.h>
|
||||
@@ -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);
|
||||
|
||||
@@ -87,6 +87,8 @@
|
||||
<extradist>
|
||||
path-t.h
|
||||
path-t.c
|
||||
vars-t.h
|
||||
vars-t.c
|
||||
</extradist>
|
||||
|
||||
|
||||
|
||||
127
aqhome/data/vars-t.c
Normal file
127
aqhome/data/vars-t.c
Normal file
@@ -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 <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
|
||||
25
aqhome/data/vars-t.h
Normal file
25
aqhome/data/vars-t.h
Normal file
@@ -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 <gwenhywfar/gwenhywfarapi.h>
|
||||
#include <gwenhywfar/testframework.h>
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Tests for "Vars" module.
|
||||
*/
|
||||
AQHOME_API int AQH_Vars_AddTests(GWEN_TEST_MODULE *mod);
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user