diff options
author | Andreas Baumann <mail@andreasbaumann.cc> | 2014-10-03 17:58:36 +0200 |
---|---|---|
committer | Andreas Baumann <mail@andreasbaumann.cc> | 2014-10-03 17:58:36 +0200 |
commit | 92ba06d58475fd4ab07d8e3b1efa6993f1f02340 (patch) | |
tree | 385a511835136fb2d190df05651b03c015690e91 /tests/libcurlpp | |
parent | ee52b3eab8cc7feb49fa6db964b94b35e2bc8bac (diff) | |
download | crawler-92ba06d58475fd4ab07d8e3b1efa6993f1f02340.tar.gz crawler-92ba06d58475fd4ab07d8e3b1efa6993f1f02340.tar.bz2 |
added an experimental curl fetcher
Diffstat (limited to 'tests/libcurlpp')
-rw-r--r-- | tests/libcurlpp/GNUmakefile | 29 | ||||
-rw-r--r-- | tests/libcurlpp/README | 4 | ||||
-rwxr-xr-x | tests/libcurlpp/exec_test | 21 | ||||
-rw-r--r-- | tests/libcurlpp/test1.MUST | 1 | ||||
-rw-r--r-- | tests/libcurlpp/test1.cpp | 66 | ||||
-rw-r--r-- | tests/libcurlpp/test2.MUST | 1 | ||||
-rw-r--r-- | tests/libcurlpp/test2.cpp | 85 |
7 files changed, 207 insertions, 0 deletions
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 <curlpp/cURLpp.hpp> +#include <curlpp/Easy.hpp> +#include <curlpp/Options.hpp> +#include <curlpp/Infos.hpp> +#include <curlpp/Types.hpp> + +#include <iostream> +#include <sys/types.h> +#include <cassert> +#include <cstring> +#include <cstdlib> + +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 <url>" << 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 <curlpp/cURLpp.hpp> +#include <curlpp/Easy.hpp> +#include <curlpp/Options.hpp> +#include <curlpp/Infos.hpp> +#include <curlpp/Types.hpp> + +#include <iostream> +#include <sys/types.h> +#include <cassert> +#include <cstring> +#include <cstdlib> + +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 <url>" << 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; +} |