diff options
author | Andreas Baumann <abaumann@yahoo.com> | 2012-07-12 23:20:04 +0200 |
---|---|---|
committer | Andreas Baumann <abaumann@yahoo.com> | 2012-07-12 23:20:04 +0200 |
commit | a441d2f44ca233c9d3f0228e76b3072e9cdb7fda (patch) | |
tree | 1daedd331468d22477842fdb083b2dd5f2a2b3c1 /tests/libfetch | |
parent | 701352f84ddd204d738407c29a4b6e501694a59c (diff) | |
download | crawler-a441d2f44ca233c9d3f0228e76b3072e9cdb7fda.tar.gz crawler-a441d2f44ca233c9d3f0228e76b3072e9cdb7fda.tar.bz2 |
fixed tests and added a libfetch test
Diffstat (limited to 'tests/libfetch')
-rw-r--r-- | tests/libfetch/GNUmakefile | 36 | ||||
-rw-r--r-- | tests/libfetch/test1.c | 36 |
2 files changed, 72 insertions, 0 deletions
diff --git a/tests/libfetch/GNUmakefile b/tests/libfetch/GNUmakefile new file mode 100644 index 0000000..a8d7495 --- /dev/null +++ b/tests/libfetch/GNUmakefile @@ -0,0 +1,36 @@ +TOPDIR = ../.. + +SUBDIRS = + +INCLUDE_DIRS = \ + -I$(TOPDIR)/libfetch + +INCLUDE_LDFLAGS = + +INCLUDE_LIBS = \ + $(TOPDIR)/libfetch/libfetch.a + +# openssl +ifeq ($(WITH_SSL),1) + +INCLUDE_CFLAGS += \ + -DWITH_SSL + +INCLUDE_LIBS += \ + $(OPENSSL_LIBS) +endif + +TEST_BINS = \ + test1$(EXE) + +OBJS = + +-include $(TOPDIR)/makefiles/gmake/sub.mk + +local_all: + +local_clean: + +local_distclean: + +local_test: diff --git a/tests/libfetch/test1.c b/tests/libfetch/test1.c new file mode 100644 index 0000000..fd28563 --- /dev/null +++ b/tests/libfetch/test1.c @@ -0,0 +1,36 @@ +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> + +#include <fetch.h> + +int main( int argc, char *argv[] ) +{ + char *urlstring; + fetchIO *io; + char buf[1024]; + ssize_t res; + + if( argc != 2 ) { + fputs( "Usage: test1 <url>\n", stderr ); + exit( EXIT_FAILURE ); + } + + urlstring = argv[1]; + + fetchTimeout = 2; + + io = fetchGetURL( urlstring, "" ); + if( io == NULL ) { + fprintf( stderr, "ERROR: %s\n", fetchLastErrString ); + exit( EXIT_FAILURE ); + } + + while( ( res = fetchIO_read( io, buf, sizeof( buf ) ) ) != 0 ) { + puts( buf ); + } + + fetchIO_close( io ); + + exit( EXIT_SUCCESS ); +} |