mirror of
https://github.com/moparisthebest/curl
synced 2024-12-22 08:08:50 -05:00
unittest: framework for unit-testing
This is the first approach at doing fairly clean and easy to write and debug unit tests.
This commit is contained in:
parent
45cea71968
commit
35e1d6538a
@ -5,7 +5,7 @@
|
||||
# | (__| |_| | _ <| |___
|
||||
# \___|\___/|_| \_\_____|
|
||||
#
|
||||
# Copyright (C) 1998 - 2010, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
# Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
#
|
||||
# This software is licensed as described in the file COPYING, which
|
||||
# you should have received as part of this distribution. The terms
|
||||
@ -2911,6 +2911,7 @@ AC_CONFIG_FILES([Makefile \
|
||||
tests/data/Makefile \
|
||||
tests/server/Makefile \
|
||||
tests/libtest/Makefile \
|
||||
tests/unit/Makefile \
|
||||
packages/Makefile \
|
||||
packages/Win32/Makefile \
|
||||
packages/Win32/cygwin/Makefile \
|
||||
|
@ -5,7 +5,7 @@
|
||||
# | (__| |_| | _ <| |___
|
||||
# \___|\___/|_| \_\_____|
|
||||
#
|
||||
# Copyright (C) 1998 - 2010, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
# Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
#
|
||||
# This software is licensed as described in the file COPYING, which
|
||||
# you should have received as part of this distribution. The terms
|
||||
@ -29,7 +29,7 @@ EXTRA_DIST = ftpserver.pl httpserver.pl secureserver.pl runtests.pl getpart.pm \
|
||||
CMakeLists.txt certs/scripts/*.sh certs/Server* certs/EdelCurlRoot* \
|
||||
serverhelp.pm tftpserver.pl rtspserver.pl directories.pm symbol-scan.pl
|
||||
|
||||
SUBDIRS = data server libtest
|
||||
SUBDIRS = data server libtest unit
|
||||
|
||||
PERLFLAGS = -I$(srcdir)
|
||||
|
||||
|
@ -68,7 +68,7 @@ EXTRA_DIST = test1 test108 test117 test127 test20 test27 test34 test46 \
|
||||
test1108 test1109 test1110 test1111 test1112 test129 test567 test568 \
|
||||
test569 test570 test571 test572 test804 test805 test806 test807 test573 \
|
||||
test313 test1115 test578 test579 test1116 test1200 test1201 test1202 \
|
||||
test1203 test1117 test1118 test1119 test1120
|
||||
test1203 test1117 test1118 test1119 test1120 test1300
|
||||
|
||||
filecheck:
|
||||
@mkdir test-place; \
|
||||
|
30
tests/data/test1300
Normal file
30
tests/data/test1300
Normal file
@ -0,0 +1,30 @@
|
||||
<testcase>
|
||||
<info>
|
||||
<keywords>
|
||||
unittest
|
||||
</keywords>
|
||||
</info>
|
||||
|
||||
#
|
||||
# Client-side
|
||||
<client>
|
||||
<server>
|
||||
none
|
||||
</server>
|
||||
<name>
|
||||
llist unit tests
|
||||
</name>
|
||||
<tool>
|
||||
unit1300
|
||||
</tool>
|
||||
<command>
|
||||
unit1300
|
||||
</command>
|
||||
</client>
|
||||
|
||||
#
|
||||
# Verify data after the test has been "shot"
|
||||
<verify>
|
||||
|
||||
</verify>
|
||||
</testcase>
|
@ -164,3 +164,4 @@ lib573_SOURCES = lib573.c $(SUPPORTFILES) $(TESTUTIL)
|
||||
lib578_SOURCES = lib578.c $(SUPPORTFILES)
|
||||
|
||||
lib579_SOURCES = lib579.c $(SUPPORTFILES)
|
||||
|
||||
|
@ -37,7 +37,7 @@ char *libtest_arg2=NULL;
|
||||
char *libtest_arg3=NULL;
|
||||
int test_argc;
|
||||
char **test_argv;
|
||||
|
||||
int unitfail; /* for unittests */
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
|
@ -6,7 +6,7 @@
|
||||
# | (__| |_| | _ <| |___
|
||||
# \___|\___/|_| \_\_____|
|
||||
#
|
||||
# Copyright (C) 1998 - 2010, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
# Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
#
|
||||
# This software is licensed as described in the file COPYING, which
|
||||
# you should have received as part of this distribution. The terms
|
||||
@ -145,6 +145,7 @@ my $DBGCURL=$CURL; #"../src/.libs/curl"; # alternative for debugging
|
||||
my $LOGDIR="log";
|
||||
my $TESTDIR="$srcdir/data";
|
||||
my $LIBDIR="./libtest";
|
||||
my $UNITDIR="./unit";
|
||||
my $SERVERIN="$LOGDIR/server.input"; # what curl sent the server
|
||||
my $SERVER2IN="$LOGDIR/server2.input"; # what curl sent the second server
|
||||
my $CURLLOG="$LOGDIR/curl.log"; # all command lines run
|
||||
@ -2630,7 +2631,13 @@ sub singletest {
|
||||
$cmdargs = " $cmd"; # $cmd is the command line for the test file
|
||||
$CURLOUT = $STDOUT; # sends received data to stdout
|
||||
|
||||
if($tool =~ /^lib/) {
|
||||
$CMDLINE="$LIBDIR/$tool";
|
||||
}
|
||||
elsif($tool =~ /^unit/) {
|
||||
$CMDLINE="$UNITDIR/$tool";
|
||||
}
|
||||
|
||||
if(! -f $CMDLINE) {
|
||||
print "The tool set in the test case for this: '$tool' does not exist\n";
|
||||
timestampskippedevents($testnum);
|
||||
|
68
tests/unit/Makefile.am
Normal file
68
tests/unit/Makefile.am
Normal file
@ -0,0 +1,68 @@
|
||||
#***************************************************************************
|
||||
# _ _ ____ _
|
||||
# Project ___| | | | _ \| |
|
||||
# / __| | | | |_) | |
|
||||
# | (__| |_| | _ <| |___
|
||||
# \___|\___/|_| \_\_____|
|
||||
#
|
||||
# Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
#
|
||||
# This software is licensed as described in the file COPYING, which
|
||||
# you should have received as part of this distribution. The terms
|
||||
# are also available at http://curl.haxx.se/docs/copyright.html.
|
||||
#
|
||||
# You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
||||
# copies of the Software, and permit persons to whom the Software is
|
||||
# furnished to do so, under the terms of the COPYING file.
|
||||
#
|
||||
# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||
# KIND, either express or implied.
|
||||
#
|
||||
###########################################################################
|
||||
AUTOMAKE_OPTIONS = foreign nostdinc
|
||||
|
||||
# Specify our include paths here, and do it relative to $(top_srcdir) and
|
||||
# $(top_builddir), to ensure that these paths which belong to the library
|
||||
# being currently built and tested are searched before the library which
|
||||
# might possibly already be installed in the system.
|
||||
#
|
||||
# $(top_builddir)/include/curl for generated curlbuild.h included from curl.h
|
||||
# $(top_builddir)/include for generated curlbuild.h included from lib/setup.h
|
||||
# $(top_srcdir)/include is for libcurl's external include files
|
||||
# $(top_builddir)/lib is for libcurl's generated lib/curl_config.h file
|
||||
# $(top_srcdir)/lib is for libcurl's lib/setup.h and other "borrowed" files
|
||||
# $(top_builddir)/ares is for in-tree c-ares's generated ares_build.h file
|
||||
# $(top_srcdir)/ares is for in-tree c-ares's external include files
|
||||
|
||||
if USE_EMBEDDED_ARES
|
||||
INCLUDES = -I$(top_builddir)/include/curl \
|
||||
-I$(top_builddir)/include \
|
||||
-I$(top_srcdir)/include \
|
||||
-I$(top_builddir)/lib \
|
||||
-I$(top_srcdir)/lib \
|
||||
-I$(top_srcdir)/tests/libtest \
|
||||
-I$(top_builddir)/ares \
|
||||
-I$(top_srcdir)/ares
|
||||
else
|
||||
INCLUDES = -I$(top_builddir)/include/curl \
|
||||
-I$(top_builddir)/include \
|
||||
-I$(top_srcdir)/include \
|
||||
-I$(top_builddir)/lib \
|
||||
-I$(top_srcdir)/lib \
|
||||
-I$(top_srcdir)/tests/libtest
|
||||
endif
|
||||
|
||||
EXTRA_DIST = Makefile.inc
|
||||
|
||||
LDADD = $(top_srcdir)/tests/libtest/first.o $(top_builddir)/lib/libcurl.la \
|
||||
@CURL_LIBS@
|
||||
DEPENDENCIES = $(top_builddir)/lib/libcurl.la
|
||||
|
||||
# Makefile.inc provides the source defines (TESTUTIL, SUPPORTFILES,
|
||||
# noinst_PROGRAMS, lib*_SOURCES, and lib*_CFLAGS)
|
||||
include Makefile.inc
|
||||
|
||||
if NO_UNDEFINED
|
||||
# The -no-undefined flag is crucial to build fine on some platforms
|
||||
UNDEF = -no-undefined
|
||||
endif
|
8
tests/unit/Makefile.inc
Normal file
8
tests/unit/Makefile.inc
Normal file
@ -0,0 +1,8 @@
|
||||
# these files are used in every single unit test program
|
||||
|
||||
UNITFILES = curlcheck.h
|
||||
|
||||
# These are all unit test programs
|
||||
noinst_PROGRAMS = unit1300
|
||||
|
||||
unit1300_SOURCES = unit1300.c $(UNITFILES)
|
31
tests/unit/curlcheck.h
Normal file
31
tests/unit/curlcheck.h
Normal file
@ -0,0 +1,31 @@
|
||||
/*****************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
*/
|
||||
|
||||
#include "test.h"
|
||||
|
||||
#define fail_unless(expr, msg) \
|
||||
if(!(expr)) { \
|
||||
fprintf(stderr, "%s:%d Assertion '%s' failed: %s" , \
|
||||
__FILE__, __LINE__, #expr, msg); \
|
||||
unitfail++; \
|
||||
}
|
||||
|
||||
extern int unitfail;
|
||||
|
||||
#define UNITTEST_START \
|
||||
int test(char *unused) \
|
||||
{ \
|
||||
(void)unused; \
|
||||
unit_setup();
|
||||
|
||||
#define UNITTEST_STOP \
|
||||
unit_stop(); \
|
||||
return unitfail; \
|
||||
}
|
||||
|
34
tests/unit/unit1300.c
Normal file
34
tests/unit/unit1300.c
Normal file
@ -0,0 +1,34 @@
|
||||
#include <stdlib.h>
|
||||
#include "curl_config.h"
|
||||
#include "setup.h"
|
||||
|
||||
#include "llist.h"
|
||||
#include "curlcheck.h"
|
||||
|
||||
struct curl_llist *llist;
|
||||
|
||||
static void test_curl_llist_dtor(void *key , void *value)
|
||||
{
|
||||
/* used by the llist API, does nothing here */
|
||||
(void)key;
|
||||
(void)value;
|
||||
}
|
||||
|
||||
static void unit_setup( void )
|
||||
{
|
||||
llist = Curl_llist_alloc( test_curl_llist_dtor );
|
||||
}
|
||||
|
||||
static void unit_stop( void )
|
||||
{
|
||||
Curl_llist_destroy( llist, NULL );
|
||||
}
|
||||
|
||||
UNITTEST_START
|
||||
|
||||
fail_unless( llist->size == 0 , "list initial size should be zero" );
|
||||
fail_unless( llist->head == NULL , "list head should initiate to NULL" );
|
||||
fail_unless( llist->tail == NULL , "list tail should intiate to NULL" );
|
||||
fail_unless( llist->dtor == test_curl_llist_dtor , "list dtor shold initiate to test_curl_llist_dtor" );
|
||||
|
||||
UNITTEST_STOP
|
Loading…
Reference in New Issue
Block a user