diff options
author | Andreas Baumann <abaumann@yahoo.com> | 2012-07-13 14:23:33 +0200 |
---|---|---|
committer | Andreas Baumann <abaumann@yahoo.com> | 2012-07-13 14:23:33 +0200 |
commit | b00e07aecce60a9c975aa8f2cf2f085c5ea34783 (patch) | |
tree | a94ff7f167590994dbc0151fe7d9cc01a1e4bb6e /tests/libfetch | |
parent | 1f9e20cab94eb0e9bced570cbc425c804d7d32d2 (diff) | |
download | crawler-b00e07aecce60a9c975aa8f2cf2f085c5ea34783.tar.gz crawler-b00e07aecce60a9c975aa8f2cf2f085c5ea34783.tar.bz2 |
added test for libfetch_stream
Diffstat (limited to 'tests/libfetch')
-rw-r--r-- | tests/libfetch/test2.cpp | 43 |
1 files changed, 30 insertions, 13 deletions
diff --git a/tests/libfetch/test2.cpp b/tests/libfetch/test2.cpp index 41d7aae..2a49f85 100644 --- a/tests/libfetch/test2.cpp +++ b/tests/libfetch/test2.cpp @@ -60,10 +60,36 @@ streambuf::int_type libfetch_buffer::underflow( ) return traits_type::to_int_type( *gptr( ) ); } +class libfetch_istream : public istream +{ + public: + libfetch_istream( const char *url ); + ~libfetch_istream( ); + + private: + fetchIO *m_io; + libfetch_buffer *m_buf; +}; + +libfetch_istream::libfetch_istream( const char *url ) +{ + m_io = fetchGetURL( url, "" ); + if( m_io == NULL ) { + // TODO: handle error bit + } + m_buf = new libfetch_buffer( m_io ); + rdbuf( m_buf ); +} + +libfetch_istream::~libfetch_istream( ) +{ + delete m_buf; + fetchIO_close( m_io ); +} + int main( int argc, char *argv[] ) { char *urlstring; - fetchIO *io; if( argc != 2 ) { cerr << "Usage: test2 <url>" << endl; @@ -73,23 +99,14 @@ int main( int argc, char *argv[] ) urlstring = argv[1]; fetchTimeout = 2; - - io = fetchGetURL( urlstring, "" ); - if( io == NULL ) { - cerr << "ERROR: " << fetchLastErrString << endl; - return 1; - } - - libfetch_buffer buf( io ); - istream is( &buf ); + + libfetch_istream is( urlstring ); string s; while( !is.eof( ) ) { getline( is, s ); cout << s << endl; } - - fetchIO_close( io ); - + return 0; } |