Add some skeleton for unit testing. Start with template objects.
This commit is contained in:
@@ -514,6 +514,7 @@ AC_CONFIG_FILES([
|
|||||||
upnp/Makefile
|
upnp/Makefile
|
||||||
upnp/doc/Makefile
|
upnp/doc/Makefile
|
||||||
upnp/sample/Makefile
|
upnp/sample/Makefile
|
||||||
|
upnp/unittest/Makefile
|
||||||
docs/dist/Makefile
|
docs/dist/Makefile
|
||||||
libupnp.pc
|
libupnp.pc
|
||||||
])
|
])
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
# Copyright (C) 2005 Rémi Turboult <r3mi@users.sourceforge.net>
|
# Copyright (C) 2005 Rémi Turboult <r3mi@users.sourceforge.net>
|
||||||
#
|
#
|
||||||
|
|
||||||
SUBDIRS = doc . sample
|
SUBDIRS = doc . sample unittest
|
||||||
|
|
||||||
AM_CPPFLAGS = \
|
AM_CPPFLAGS = \
|
||||||
-I$(srcdir)/inc \
|
-I$(srcdir)/inc \
|
||||||
|
|||||||
33
upnp/unittest/Makefile.am
Normal file
33
upnp/unittest/Makefile.am
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
#
|
||||||
|
# "Makefile.am" for "libupnp/upnp/unittest"
|
||||||
|
#
|
||||||
|
# Copyright (C) 2010 Marcelo Roberto Jimenez <mroberto@users.sourceforge.net>
|
||||||
|
#
|
||||||
|
|
||||||
|
AM_CPPFLAGS = \
|
||||||
|
-I$(top_srcdir)/upnp/inc \
|
||||||
|
-I$(top_srcdir)/threadutil/inc \
|
||||||
|
-I$(top_srcdir)/ixml/inc \
|
||||||
|
-I$(top_srcdir)/upnp/src/inc
|
||||||
|
|
||||||
|
LDADD = \
|
||||||
|
$(top_builddir)/upnp/libupnp.la \
|
||||||
|
$(top_builddir)/threadutil/libthreadutil.la \
|
||||||
|
$(top_builddir)/ixml/libixml.la
|
||||||
|
|
||||||
|
#unittest
|
||||||
|
noinst_PROGRAMS = unittest
|
||||||
|
|
||||||
|
unittest_CPPFLAGS = \
|
||||||
|
$(AM_CPPFLAGS)
|
||||||
|
|
||||||
|
unittest_SOURCES = \
|
||||||
|
main.c \
|
||||||
|
templates/FirstObject.c \
|
||||||
|
templates/FirstObject.h \
|
||||||
|
templates/templates.c \
|
||||||
|
templates/templates.h \
|
||||||
|
templates/SecondObject.c \
|
||||||
|
templates/SecondObject.h \
|
||||||
|
templates/TheStruct.h
|
||||||
|
|
||||||
29
upnp/unittest/main.c
Normal file
29
upnp/unittest/main.c
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include "templates/templates.h"
|
||||||
|
|
||||||
|
int (*tests[])(void) = {
|
||||||
|
templates,
|
||||||
|
};
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
int ret = 0;
|
||||||
|
int i;
|
||||||
|
int n = (sizeof tests) / (sizeof tests[0]);
|
||||||
|
int result;
|
||||||
|
|
||||||
|
for (i = 0; i < n; ++i) {
|
||||||
|
result = tests[i]();
|
||||||
|
printf("Test number %3d: %s.\n", i + 1, !result ? "PASS" : "FAIL");
|
||||||
|
ret += result;
|
||||||
|
}
|
||||||
|
printf("\n"
|
||||||
|
"Failed in %d tests.\n"
|
||||||
|
"Passed in %d tests.\n",
|
||||||
|
ret, n - ret);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
6
upnp/unittest/templates/FirstObject.c
Normal file
6
upnp/unittest/templates/FirstObject.c
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
|
#define TEMPLATE_GENERATE_SOURCE
|
||||||
|
#include "FirstObject.h"
|
||||||
|
|
||||||
44
upnp/unittest/templates/FirstObject.h
Normal file
44
upnp/unittest/templates/FirstObject.h
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
|
||||||
|
#ifndef FIRSTOBJECT_H
|
||||||
|
#define FIRSTOBJECT_H
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \file
|
||||||
|
*
|
||||||
|
* \brief Object used in unit testing of object templates.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/******************************************************************************/
|
||||||
|
|
||||||
|
#ifdef TEMPLATE_GENERATE_SOURCE
|
||||||
|
#undef TEMPLATE_GENERATE_SOURCE
|
||||||
|
|
||||||
|
#include "SecondObject.h"
|
||||||
|
|
||||||
|
#define TEMPLATE_GENERATE_SOURCE
|
||||||
|
#else /* TEMPLATE_GENERATE_SOURCE */
|
||||||
|
|
||||||
|
#include "SecondObject.h"
|
||||||
|
|
||||||
|
#endif /* TEMPLATE_GENERATE_SOURCE */
|
||||||
|
|
||||||
|
/******************************************************************************/
|
||||||
|
|
||||||
|
#include "TheStruct.h"
|
||||||
|
|
||||||
|
#define CLASS UnitFirstObject
|
||||||
|
|
||||||
|
#define EXPAND_CLASS_MEMBERS(CLASS) \
|
||||||
|
EXPAND_CLASS_MEMBER_INT(CLASS, TheInteger, int) \
|
||||||
|
EXPAND_CLASS_MEMBER_INT(CLASS, TheUnsignedLong, unsigned long) \
|
||||||
|
EXPAND_CLASS_MEMBER_INT(CLASS, TheCharPointer, char *) \
|
||||||
|
EXPAND_CLASS_MEMBER_BUFFER(CLASS, TheBuffer, struct TheStruct) \
|
||||||
|
EXPAND_CLASS_MEMBER_LIST(CLASS, TheList) \
|
||||||
|
EXPAND_CLASS_MEMBER_OBJECT(CLASS, TheSecondObject, UnitSecondObject) \
|
||||||
|
EXPAND_CLASS_MEMBER_STRING(CLASS, TheString) \
|
||||||
|
EXPAND_CLASS_MEMBER_DOMSTRING(CLASS, TheDomString)
|
||||||
|
|
||||||
|
#include "TemplateInclude.h"
|
||||||
|
|
||||||
|
#endif /* FIRSTOBJECT_H */
|
||||||
|
|
||||||
6
upnp/unittest/templates/SecondObject.c
Normal file
6
upnp/unittest/templates/SecondObject.c
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
|
#define TEMPLATE_GENERATE_SOURCE
|
||||||
|
#include "SecondObject.h"
|
||||||
|
|
||||||
44
upnp/unittest/templates/SecondObject.h
Normal file
44
upnp/unittest/templates/SecondObject.h
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
|
||||||
|
#ifndef SECONDOBJECT_H
|
||||||
|
#define SECONDOBJECT_H
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \file
|
||||||
|
*
|
||||||
|
* \brief Object used in unit testing of object templates.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/******************************************************************************/
|
||||||
|
|
||||||
|
#ifdef TEMPLATE_GENERATE_SOURCE
|
||||||
|
#undef TEMPLATE_GENERATE_SOURCE
|
||||||
|
|
||||||
|
/*#include "ThirdObject.h"*/
|
||||||
|
|
||||||
|
#define TEMPLATE_GENERATE_SOURCE
|
||||||
|
#else /* TEMPLATE_GENERATE_SOURCE */
|
||||||
|
|
||||||
|
/*#include "ThirdObject.h"*/
|
||||||
|
|
||||||
|
#endif /* TEMPLATE_GENERATE_SOURCE */
|
||||||
|
|
||||||
|
/******************************************************************************/
|
||||||
|
|
||||||
|
#include "TheStruct.h"
|
||||||
|
|
||||||
|
#define CLASS UnitSecondObject
|
||||||
|
|
||||||
|
#define EXPAND_CLASS_MEMBERS(CLASS) \
|
||||||
|
EXPAND_CLASS_MEMBER_INT(CLASS, TheInteger, int) \
|
||||||
|
EXPAND_CLASS_MEMBER_INT(CLASS, TheUnsignedLong, unsigned long) \
|
||||||
|
EXPAND_CLASS_MEMBER_INT(CLASS, TheCharPointer, char *) \
|
||||||
|
EXPAND_CLASS_MEMBER_BUFFER(CLASS, TheBuffer, struct TheStruct) \
|
||||||
|
EXPAND_CLASS_MEMBER_LIST(CLASS, TheList) \
|
||||||
|
/* EXPAND_CLASS_MEMBER_OBJECT(CLASS, TheThirdObject, ThirdObject) */ \
|
||||||
|
EXPAND_CLASS_MEMBER_STRING(CLASS, TheString) \
|
||||||
|
EXPAND_CLASS_MEMBER_DOMSTRING(CLASS, TheDomString)
|
||||||
|
|
||||||
|
#include "TemplateInclude.h"
|
||||||
|
|
||||||
|
#endif /* SECONDOBJECT_H */
|
||||||
|
|
||||||
11
upnp/unittest/templates/TheStruct.h
Normal file
11
upnp/unittest/templates/TheStruct.h
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
|
||||||
|
#ifndef THESTRUCT_H
|
||||||
|
#define THESTRUCT_H
|
||||||
|
|
||||||
|
struct TheStruct {
|
||||||
|
int a;
|
||||||
|
long b;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* THESTRUCT_H */
|
||||||
|
|
||||||
33
upnp/unittest/templates/compile.sh
Executable file
33
upnp/unittest/templates/compile.sh
Executable file
@@ -0,0 +1,33 @@
|
|||||||
|
#! /bin/bash
|
||||||
|
|
||||||
|
#
|
||||||
|
# The purpose of this file is to make it easier to find problems in
|
||||||
|
# Template Objects compilation.
|
||||||
|
#
|
||||||
|
# Because Template Objects are a result of preprocessing, the are normally
|
||||||
|
# invisible to the human eye. So, we paint him! Using the C pre-processor.
|
||||||
|
#
|
||||||
|
# The issue is that compilation error messages give all errors at the same
|
||||||
|
# lines. Using a combination of the pre-processor and indent, we are able
|
||||||
|
# to produce a good readable code, so that we can debug the templates.
|
||||||
|
#
|
||||||
|
|
||||||
|
if [[ "$1" == "" ]]; then
|
||||||
|
echo "Error: no file name given, please enter the C file name."
|
||||||
|
exit -1
|
||||||
|
fi
|
||||||
|
|
||||||
|
FILENAME=$(basename $1 .c)
|
||||||
|
|
||||||
|
top_srcdir=../../..
|
||||||
|
|
||||||
|
INCLUDES=
|
||||||
|
INCLUDES="${INCLUDES} -I${top_srcdir}"
|
||||||
|
INCLUDES="${INCLUDES} -I${top_srcdir}/ixml/inc"
|
||||||
|
INCLUDES="${INCLUDES} -I${top_srcdir}/threadutil/inc" \
|
||||||
|
INCLUDES="${INCLUDES} -I${top_srcdir}/upnp/inc" \
|
||||||
|
INCLUDES="${INCLUDES} -I${top_srcdir}/upnp/src/inc"
|
||||||
|
|
||||||
|
gcc ${INCLUDES} -E ${FILENAME}.c | grep -v ^# | indent -linux > ${FILENAME}_pp.c
|
||||||
|
gcc ${INCLUDES} -Wall -c ${FILENAME}_pp.c
|
||||||
|
|
||||||
13
upnp/unittest/templates/templates.c
Normal file
13
upnp/unittest/templates/templates.c
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
|
||||||
|
#include "templates.h"
|
||||||
|
|
||||||
|
#include "FirstObject.h"
|
||||||
|
#include "SecondObject.h"
|
||||||
|
|
||||||
|
int templates(void)
|
||||||
|
{
|
||||||
|
int ret = 0;
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
8
upnp/unittest/templates/templates.h
Normal file
8
upnp/unittest/templates/templates.h
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
|
||||||
|
#ifndef TEMPLATES_H
|
||||||
|
#define TEMPLATES_H
|
||||||
|
|
||||||
|
int templates(void);
|
||||||
|
|
||||||
|
#endif /* TEMPLATES_H */
|
||||||
|
|
||||||
Reference in New Issue
Block a user