From 92ba06d58475fd4ab07d8e3b1efa6993f1f02340 Mon Sep 17 00:00:00 2001 From: Andreas Baumann Date: Fri, 3 Oct 2014 17:58:36 +0200 Subject: added an experimental curl fetcher --- tests/GNUmakefile | 6 +++- tests/curl/GNUmakefile | 29 ---------------- tests/curl/README | 4 --- tests/curl/exec_test | 21 ----------- tests/curl/test1.MUST | 1 - tests/curl/test1.cpp | 66 ----------------------------------- tests/curl/test2.MUST | 1 - tests/curl/test2.cpp | 85 --------------------------------------------- tests/libcurlpp/GNUmakefile | 29 ++++++++++++++++ tests/libcurlpp/README | 4 +++ tests/libcurlpp/exec_test | 21 +++++++++++ tests/libcurlpp/test1.MUST | 1 + tests/libcurlpp/test1.cpp | 66 +++++++++++++++++++++++++++++++++++ tests/libcurlpp/test2.MUST | 1 + tests/libcurlpp/test2.cpp | 85 +++++++++++++++++++++++++++++++++++++++++++++ 15 files changed, 212 insertions(+), 208 deletions(-) delete mode 100644 tests/curl/GNUmakefile delete mode 100644 tests/curl/README delete mode 100755 tests/curl/exec_test delete mode 100644 tests/curl/test1.MUST delete mode 100644 tests/curl/test1.cpp delete mode 100644 tests/curl/test2.MUST delete mode 100644 tests/curl/test2.cpp create mode 100644 tests/libcurlpp/GNUmakefile create mode 100644 tests/libcurlpp/README create mode 100755 tests/libcurlpp/exec_test create mode 100644 tests/libcurlpp/test1.MUST create mode 100644 tests/libcurlpp/test1.cpp create mode 100644 tests/libcurlpp/test2.MUST create mode 100644 tests/libcurlpp/test2.cpp (limited to 'tests') diff --git a/tests/GNUmakefile b/tests/GNUmakefile index a21e409..ae574dd 100644 --- a/tests/GNUmakefile +++ b/tests/GNUmakefile @@ -1,9 +1,13 @@ TOPDIR = .. SUBDIRS = \ - utils logger modules url streamhtmlparser libfetch curl psql sqlite typedetect \ + utils logger modules url streamhtmlparser libfetch psql sqlite typedetect \ fetcher textwolf +ifeq ($(WITH_CURL),1) +SUBDIRS += libcurl +endif + -include $(TOPDIR)/makefiles/gmake/sub.mk local_all: diff --git a/tests/curl/GNUmakefile b/tests/curl/GNUmakefile deleted file mode 100644 index de0462a..0000000 --- a/tests/curl/GNUmakefile +++ /dev/null @@ -1,29 +0,0 @@ -TOPDIR = ../.. - -SUBDIRS = - -INCLUDE_DIRS = $(shell pkg-config --cflags curlpp) - -INCLUDE_LDFLAGS = $(shell pkg-config --libs-only-L curlpp) - -INCLUDE_LIBS = $(shell pkg-config --libs-only-l curlpp) - -TEST_CPP_BINS = \ - test1$(EXE) \ - test2$(EXE) - -OBJS = - --include $(TOPDIR)/makefiles/gmake/sub.mk - -local_all: - -local_clean: - -@rm -f *.RES *.DIFF - -local_distclean: - -local_test: - @./exec_test test1 "fetch simple test (function)" "$(PLATFORM)" "$(LINUX_DIST)" "$(LINUX_REV)" "http://localhost" - @./exec_test test2 "fetch simple test (method)" "$(PLATFORM)" "$(LINUX_DIST)" "$(LINUX_REV)" "http://localhost" - \ No newline at end of file diff --git a/tests/curl/README b/tests/curl/README deleted file mode 100644 index 747e9a6..0000000 --- a/tests/curl/README +++ /dev/null @@ -1,4 +0,0 @@ -test1 - using curlpp wrapper for curl, classic curl handler, easy - interface, callback for result stream, more or less in C - style, not-thread-safe! -test2 - trying with a class and a method functor (curlpp) diff --git a/tests/curl/exec_test b/tests/curl/exec_test deleted file mode 100755 index fce8214..0000000 --- a/tests/curl/exec_test +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/sh - -BINARY=$1 -TITLE=$2 -PLATFORM=$3 -LINUX_DIST=$4 -LINUX_REV=$5 - -if test "x${PLATFORM}" = "xLINUX"; then -SPECIAL="${PLATFORM}_${LINUX_DIST}_${LINUX_REV}" -else -SPECIAL="${PLATFORM}" -fi - -printf "$BINARY: $TITLE .. " -./$BINARY $6 | head -n 1 >$BINARY.RES 2>&1 -if test -f $BINARY.MUST.$SPECIAL; then - diff $BINARY.MUST.$SPECIAL $BINARY.RES > $BINARY.DIFF && printf "OK\n" || printf "ERROR\n" -else - diff $BINARY.MUST $BINARY.RES > $BINARY.DIFF && printf "OK\n" || printf "ERROR\n" -fi diff --git a/tests/curl/test1.MUST b/tests/curl/test1.MUST deleted file mode 100644 index 08839f6..0000000 --- a/tests/curl/test1.MUST +++ /dev/null @@ -1 +0,0 @@ -200 diff --git a/tests/curl/test1.cpp b/tests/curl/test1.cpp deleted file mode 100644 index d10ef02..0000000 --- a/tests/curl/test1.cpp +++ /dev/null @@ -1,66 +0,0 @@ -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -using namespace std; -using namespace cURLpp; - -static char *c = NULL; -static size_t c_size = 0; - -static size_t f( char *ptr, size_t s, size_t n ) { - size_t size = s * n; - - if( c_size == 0 ) - c = (char *)malloc( size + 1 ); - else - c = (char *)realloc( c, c_size + size + 1 ); - - assert( c != NULL ); - - memcpy( &c[c_size], ptr, size ); - c_size += size; - c[c_size] = '\0'; - - return size; -} - -int main( int argc, char *argv[] ) { - char *url; - Easy curl; - - if( argc != 2 ) { - cerr << "usage: test1 " << endl; - return EXIT_FAILURE; - } - url = argv[1]; - - curl.setOpt( Options::Url( url ) ); - //curl.setOpt( Options::Header( true ) ); - //curl.setOpt( Options::Verbose( true ) ); - - Types::WriteFunctionFunctor functor( f ); - Options::WriteFunction *wf = new Options::WriteFunction( f ); - curl.setOpt( wf ); - - curl.perform( ); - - cout << cURLpp::Infos::ResponseCode::get( curl ) << endl - << c_size << " " - << url << endl; - - cout << c << endl; - - assert( c != NULL ); - free( c ); - - return EXIT_SUCCESS; -} diff --git a/tests/curl/test2.MUST b/tests/curl/test2.MUST deleted file mode 100644 index 08839f6..0000000 --- a/tests/curl/test2.MUST +++ /dev/null @@ -1 +0,0 @@ -200 diff --git a/tests/curl/test2.cpp b/tests/curl/test2.cpp deleted file mode 100644 index 748da14..0000000 --- a/tests/curl/test2.cpp +++ /dev/null @@ -1,85 +0,0 @@ -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -using namespace std; -using namespace cURLpp; - -class MemoryWriter { - static const size_t initial_size = 100; - - protected: - char *c; - size_t c_size; - - public: - MemoryWriter( ) { - c = (char *)malloc( initial_size ); - c_size = 0; - } - - ~MemoryWriter( ) { - if( c != NULL ) - free( c ); - } - - size_t f( char *ptr, size_t s, size_t n ) { - size_t part_size = s * n; - - c = (char *)realloc( c, c_size + part_size + 1 ); - - assert( c != NULL ); - - memcpy( &c[c_size], ptr, part_size ); - c_size += part_size; - c[c_size] = '\0'; - - return part_size; - } - - char *str( ) { - return c; - } - - size_t size( ) { - return c_size; - } -}; - -int main( int argc, char *argv[] ) { - char *url; - Easy curl; - MemoryWriter w; - - if( argc != 2 ) { - cerr << "usage: test1 " << endl; - return EXIT_FAILURE; - } - url = argv[1]; - - curl.setOpt( Options::Url( url ) ); - //curl.setOpt( Options::Header( true ) ); - //curl.setOpt( Options::Verbose( true ) ); - - Types::WriteFunctionFunctor functor( &w, &MemoryWriter::f ); - Options::WriteFunction *wf = new Options::WriteFunction( functor ); - curl.setOpt( wf ); - - curl.perform( ); - - cout << cURLpp::Infos::ResponseCode::get( curl ) << endl - << w.size( ) << " " - << url << endl; - - cout << w.str( ) << endl; - - return EXIT_SUCCESS; -} diff --git a/tests/libcurlpp/GNUmakefile b/tests/libcurlpp/GNUmakefile new file mode 100644 index 0000000..de0462a --- /dev/null +++ b/tests/libcurlpp/GNUmakefile @@ -0,0 +1,29 @@ +TOPDIR = ../.. + +SUBDIRS = + +INCLUDE_DIRS = $(shell pkg-config --cflags curlpp) + +INCLUDE_LDFLAGS = $(shell pkg-config --libs-only-L curlpp) + +INCLUDE_LIBS = $(shell pkg-config --libs-only-l curlpp) + +TEST_CPP_BINS = \ + test1$(EXE) \ + test2$(EXE) + +OBJS = + +-include $(TOPDIR)/makefiles/gmake/sub.mk + +local_all: + +local_clean: + -@rm -f *.RES *.DIFF + +local_distclean: + +local_test: + @./exec_test test1 "fetch simple test (function)" "$(PLATFORM)" "$(LINUX_DIST)" "$(LINUX_REV)" "http://localhost" + @./exec_test test2 "fetch simple test (method)" "$(PLATFORM)" "$(LINUX_DIST)" "$(LINUX_REV)" "http://localhost" + \ No newline at end of file diff --git a/tests/libcurlpp/README b/tests/libcurlpp/README new file mode 100644 index 0000000..747e9a6 --- /dev/null +++ b/tests/libcurlpp/README @@ -0,0 +1,4 @@ +test1 - using curlpp wrapper for curl, classic curl handler, easy + interface, callback for result stream, more or less in C + style, not-thread-safe! +test2 - trying with a class and a method functor (curlpp) diff --git a/tests/libcurlpp/exec_test b/tests/libcurlpp/exec_test new file mode 100755 index 0000000..fce8214 --- /dev/null +++ b/tests/libcurlpp/exec_test @@ -0,0 +1,21 @@ +#!/bin/sh + +BINARY=$1 +TITLE=$2 +PLATFORM=$3 +LINUX_DIST=$4 +LINUX_REV=$5 + +if test "x${PLATFORM}" = "xLINUX"; then +SPECIAL="${PLATFORM}_${LINUX_DIST}_${LINUX_REV}" +else +SPECIAL="${PLATFORM}" +fi + +printf "$BINARY: $TITLE .. " +./$BINARY $6 | head -n 1 >$BINARY.RES 2>&1 +if test -f $BINARY.MUST.$SPECIAL; then + diff $BINARY.MUST.$SPECIAL $BINARY.RES > $BINARY.DIFF && printf "OK\n" || printf "ERROR\n" +else + diff $BINARY.MUST $BINARY.RES > $BINARY.DIFF && printf "OK\n" || printf "ERROR\n" +fi diff --git a/tests/libcurlpp/test1.MUST b/tests/libcurlpp/test1.MUST new file mode 100644 index 0000000..08839f6 --- /dev/null +++ b/tests/libcurlpp/test1.MUST @@ -0,0 +1 @@ +200 diff --git a/tests/libcurlpp/test1.cpp b/tests/libcurlpp/test1.cpp new file mode 100644 index 0000000..d10ef02 --- /dev/null +++ b/tests/libcurlpp/test1.cpp @@ -0,0 +1,66 @@ +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +using namespace std; +using namespace cURLpp; + +static char *c = NULL; +static size_t c_size = 0; + +static size_t f( char *ptr, size_t s, size_t n ) { + size_t size = s * n; + + if( c_size == 0 ) + c = (char *)malloc( size + 1 ); + else + c = (char *)realloc( c, c_size + size + 1 ); + + assert( c != NULL ); + + memcpy( &c[c_size], ptr, size ); + c_size += size; + c[c_size] = '\0'; + + return size; +} + +int main( int argc, char *argv[] ) { + char *url; + Easy curl; + + if( argc != 2 ) { + cerr << "usage: test1 " << endl; + return EXIT_FAILURE; + } + url = argv[1]; + + curl.setOpt( Options::Url( url ) ); + //curl.setOpt( Options::Header( true ) ); + //curl.setOpt( Options::Verbose( true ) ); + + Types::WriteFunctionFunctor functor( f ); + Options::WriteFunction *wf = new Options::WriteFunction( f ); + curl.setOpt( wf ); + + curl.perform( ); + + cout << cURLpp::Infos::ResponseCode::get( curl ) << endl + << c_size << " " + << url << endl; + + cout << c << endl; + + assert( c != NULL ); + free( c ); + + return EXIT_SUCCESS; +} diff --git a/tests/libcurlpp/test2.MUST b/tests/libcurlpp/test2.MUST new file mode 100644 index 0000000..08839f6 --- /dev/null +++ b/tests/libcurlpp/test2.MUST @@ -0,0 +1 @@ +200 diff --git a/tests/libcurlpp/test2.cpp b/tests/libcurlpp/test2.cpp new file mode 100644 index 0000000..983f1bd --- /dev/null +++ b/tests/libcurlpp/test2.cpp @@ -0,0 +1,85 @@ +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +using namespace std; +using namespace cURLpp; + +class MemoryWriter { + static const size_t initial_size = 100; + + protected: + char *c; + size_t c_size; + + public: + MemoryWriter( ) { + c = (char *)malloc( initial_size ); + c_size = 0; + } + + ~MemoryWriter( ) { + if( c != NULL ) + free( c ); + } + + size_t f( char *ptr, size_t s, size_t n ) { + size_t part_size = s * n; + + c = (char *)realloc( c, c_size + part_size + 1 ); + + assert( c != NULL ); + + memcpy( &c[c_size], ptr, part_size ); + c_size += part_size; + c[c_size] = '\0'; + + return part_size; + } + + char *str( ) { + return c; + } + + size_t size( ) { + return c_size; + } +}; + +int main( int argc, char *argv[] ) { + char *url; + Easy curl; + MemoryWriter w; + + if( argc != 2 ) { + cerr << "usage: test2 " << endl; + return EXIT_FAILURE; + } + url = argv[1]; + + curl.setOpt( Options::Url( url ) ); + //curl.setOpt( Options::Header( true ) ); + //curl.setOpt( Options::Verbose( true ) ); + + Types::WriteFunctionFunctor functor( &w, &MemoryWriter::f ); + Options::WriteFunction *wf = new Options::WriteFunction( functor ); + curl.setOpt( wf ); + + curl.perform( ); + + cout << cURLpp::Infos::ResponseCode::get( curl ) << endl + << w.size( ) << " " + << url << endl; + + cout << w.str( ) << endl; + + return EXIT_SUCCESS; +} -- cgit v1.2.3-54-g00ecf