[complement-svn] SF.net SVN: complement: [1779] trunk/complement/explore/app/intercessor/ unit
Status: Pre-Alpha
Brought to you by:
complement
From: <com...@us...> - 2007-10-26 16:02:46
|
Revision: 1779 http://complement.svn.sourceforge.net/complement/?rev=1779&view=rev Author: complement Date: 2007-10-26 09:02:33 -0700 (Fri, 26 Oct 2007) Log Message: ----------- replace boost unit test framework by exam; separate http tests and intercessor tests Modified Paths: -------------- trunk/complement/explore/app/intercessor/unit/Makefile trunk/complement/explore/app/intercessor/unit/Makefile.inc trunk/complement/explore/app/intercessor/unit/dummy_srv.cc trunk/complement/explore/app/intercessor/unit/unit_test.cc Added Paths: ----------- trunk/complement/explore/app/intercessor/unit/http_test.cc trunk/complement/explore/app/intercessor/unit/http_test.h trunk/complement/explore/app/intercessor/unit/intercessor_test.cc trunk/complement/explore/app/intercessor/unit/intercessor_test.h trunk/complement/explore/app/intercessor/unit/intercessor_test_suite.cc trunk/complement/explore/app/intercessor/unit/intercessor_test_suite.h Modified: trunk/complement/explore/app/intercessor/unit/Makefile =================================================================== --- trunk/complement/explore/app/intercessor/unit/Makefile 2007-10-26 09:39:51 UTC (rev 1778) +++ trunk/complement/explore/app/intercessor/unit/Makefile 2007-10-26 16:02:33 UTC (rev 1779) @@ -6,15 +6,38 @@ include Makefile.inc include ${SRCROOT}/Makefiles/gmake/top.mak -# DEFS += -DUNIT_TEST +DEFS += -D__FIT_EXAM + +LIBMT_DIR = ${CoMT_DIR}/lib/mt +LIBSOCK_DIR = ${CoMT_DIR}/lib/sockios +LIBSTEM_DIR = ${CoMT_DIR}/lib/stem +LIBEXAM_DIR = ${CoMT_DIR}/lib/exam +LIBBOOSTFS_DIR = ${CoMT_DIR}/../extern/custom/boost/libs/filesystem +LIBBOOSTRE_DIR = ${CoMT_DIR}/../extern/custom/boost/libs/regex + +ifeq ($(OSNAME),linux) + +release-shared: LDSEARCH += -L${LIBMT_DIR}/${OUTPUT_DIR} -L${LIBEXAM_DIR}/${OUTPUT_DIR} -L${LIBSOCK_DIR}/${OUTPUT_DIR} -L${LIBSTEM_DIR}/${OUTPUT_DIR} -L${LIBBOOSTFS_DIR}/${OUTPUT_DIR} -L${LIBBOOSTRE_DIR}/${OUTPUT_DIR} -Wl,--rpath=${LIBMT_DIR}/${OUTPUT_DIR}:${LIBEXAM_DIR}/${OUTPUT_DIR}:${LIBSOCK_DIR}/${OUTPUT_DIR}:${LIBSTEM_DIR}/${OUTPUT_DIR}:${LIBBOOSTFS_DIR}/${OUTPUT_DIR}:${LIBBOOSTRE_DIR}/${OUTPUT_DIR}:${STLPORT_LIB_DIR} + +ifndef WITHOUT_STLPORT + +stldbg-shared: LDSEARCH += -L${LIBMT_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBEXAM_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBSOCK_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBSTEM_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBBOOSTFS_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBBOOSTRE_DIR}/${OUTPUT_DIR_STLDBG} -Wl,--rpath=${LIBMT_DIR}/${OUTPUT_DIR_STLDBG}:${LIBEXAM_DIR}/${OUTPUT_DIR_STLDBG}:${LIBSOCK_DIR}/${OUTPUT_DIR_STLDBG}:${LIBSTEM_DIR}/${OUTPUT_DIR_STLDBG}:${LIBBOOSTFS_DIR}/${OUTPUT_DIR_STLDBG}:${LIBBOOSTRE_DIR}/${OUTPUT_DIR_STLDBG}:${STLPORT_LIB_DIR} + +endif + +dbg-shared: LDSEARCH += -L${LIBMT_DIR}/${OUTPUT_DIR_DBG} -L${LIBEXAM_DIR}/${OUTPUT_DIR_DBG} -L${LIBSOCK_DIR}/${OUTPUT_DIR_DBG} -L${LIBSTEM_DIR}/${OUTPUT_DIR_DBG} -L${LIBBOOSTFS_DIR}/${OUTPUT_DIR_DBG} -L${LIBBOOSTRE_DIR}/${OUTPUT_DIR_DBG} -Wl,--rpath=${LIBMT_DIR}/${OUTPUT_DIR_DBG}:${LIBEXAM_DIR}/${OUTPUT_DIR_DBG}:${LIBSOCK_DIR}/${OUTPUT_DIR_DBG}:${LIBSTEM_DIR}/${OUTPUT_DIR_DBG}:${LIBBOOSTFS_DIR}/${OUTPUT_DIR_DBG}:${LIBBOOSTRE_DIR}/${OUTPUT_DIR_DBG}:${STLPORT_LIB_DIR} + +endif + + INCLUDES += -I${CoMT_INCLUDE_DIR} -I${BOOST_INCLUDE_DIR} -I.. -LDFLAGS += -L${INSTALL_LIB_DIR} -Wl,-rpath=${INSTALL_LIB_DIR} +release-shared: PROJECT_LIBS = -lxmt -lsockios -lstem -lboost_regex -lboost_fs -lexam +dbg-shared: PROJECT_LIBS = -lxmtg -lsockiosg -lstemg -lboost_regexg -lboost_fsg -lexamg +ifndef WITHOUT_STLPORT +stldbg-shared: PROJECT_LIBS = -lxmtstlg -lsockiosstlg -lstemstlg -lboost_regexstlg -lboost_fsstlg -lexamstlg +endif -release-shared: PROJECT_LIBS = -lxmt -lsockios -lstem -lboost_regex -lboost_test_utf -lboost_fs -dbg-shared: PROJECT_LIBS = -lxmtg -lsockiosg -lstemg -lboost_regexg -lboost_test_utfg -lboost_fsg -stldbg-shared: PROJECT_LIBS = -lxmtstlg -lsockiosstlg -lstemstlg -lboost_regexstlg -lboost_test_utfstlg -lboost_fsstlg - LDLIBS = ${PROJECT_LIBS} check: all-shared Modified: trunk/complement/explore/app/intercessor/unit/Makefile.inc =================================================================== --- trunk/complement/explore/app/intercessor/unit/Makefile.inc 2007-10-26 09:39:51 UTC (rev 1778) +++ trunk/complement/explore/app/intercessor/unit/Makefile.inc 2007-10-26 16:02:33 UTC (rev 1779) @@ -5,4 +5,7 @@ dummy_srv.cc \ ../http.cc \ ../intercessor.cc \ - ../server.cc \ No newline at end of file + ../server.cc \ + http_test.cc \ + intercessor_test.cc \ + intercessor_test_suite.cc Modified: trunk/complement/explore/app/intercessor/unit/dummy_srv.cc =================================================================== --- trunk/complement/explore/app/intercessor/unit/dummy_srv.cc 2007-10-26 09:39:51 UTC (rev 1778) +++ trunk/complement/explore/app/intercessor/unit/dummy_srv.cc 2007-10-26 16:02:33 UTC (rev 1779) @@ -10,7 +10,7 @@ #include <iostream> #include <boost/regex.hpp> -#include <boost/test/unit_test.hpp> +#include <exam/suite.h> #include "http.h" @@ -30,7 +30,7 @@ { // cerr << "DummyHttpSrv::connect " << pthread_self() << endl; - BOOST_CHECK( s.good() ); + EXAM_CHECK_ASYNC( s.good() ); http::request rq; @@ -45,7 +45,7 @@ (s << http::body( true ) << rs).flush(); - BOOST_CHECK( s.good() ); + EXAM_CHECK_ASYNC( s.good() ); } else if ( rq.head().value() == http::command::POST ) { http::response rs; @@ -54,7 +54,7 @@ (s << http::body( true ) << rs).flush(); - BOOST_CHECK( s.good() ); + EXAM_CHECK_ASYNC( s.good() ); } } @@ -73,7 +73,7 @@ void DummyHttpSrvNeg::connect( std::sockstream& s ) { - BOOST_CHECK( s.good() ); + EXAM_CHECK_ASYNC( s.good() ); http::request rq; @@ -88,7 +88,7 @@ (s << http::body( true ) << rs).flush(); - BOOST_CHECK( s.good() ); + EXAM_CHECK_ASYNC( s.good() ); } else if ( rq.head().value() == http::command::POST ) { http::response rs; rs.head().code( 410 ); @@ -96,7 +96,7 @@ (s << http::body( true ) << rs).flush(); - BOOST_CHECK( s.good() ); + EXAM_CHECK_ASYNC( s.good() ); } } Added: trunk/complement/explore/app/intercessor/unit/http_test.cc =================================================================== --- trunk/complement/explore/app/intercessor/unit/http_test.cc (rev 0) +++ trunk/complement/explore/app/intercessor/unit/http_test.cc 2007-10-26 16:02:33 UTC (rev 1779) @@ -0,0 +1,171 @@ +// -*- C++ -*- Time-stamp: <07/03/07 16:38:24 ptr> + +/* + * + * Copyright (c) 2007 + * Petr Ovtchenkov + * + */ + +// #include <boost/filesystem/operations.hpp> +// #include <boost/filesystem/path.hpp> +#include "http_test.h" +#include <boost/lexical_cast.hpp> + +#include <string> +#include <iostream> + +#include <sstream> +// #include <fstream> +#include <iterator> +#include <unistd.h> + +#include "http.h" +// #include "intercessor.h" +// #include "server.h" + +// #include "dummy_srv.h" +// #include <sockios/sockmgr.h> +// #include <mt/lfstream.h> + +// boost::filesystem::path dir( boost::filesystem::initial_path() ); +// unsigned rq_timeout = 3; + +using namespace std; +using namespace http; + +int EXAM_IMPL(http_test::header_io) +{ + header h; + string rq = "Content-Length: 100\r\n"; + stringstream s( rq ); + + s >> h; + + EXAM_CHECK( !s.fail() ); + EXAM_CHECK( h.key() == "Content-Length" ); + EXAM_CHECK( h.value() == "100" ); + + stringstream o; + + o << h; + + EXAM_CHECK( !o.fail() ); + EXAM_CHECK( o.str() == "Content-Length: 100\r\n" ); + + return EXAM_RESULT; +} + +int EXAM_IMPL(http_test::header_sp) +{ + header h; + string rq = "Header: fields here \r\n"; + stringstream s( rq ); + + s >> h; + + EXAM_CHECK( !s.fail() ); + EXAM_CHECK( h.key() == "Header" ); + EXAM_CHECK( h.value() == "fields here" ); + + stringstream o; + + o << h; + + EXAM_CHECK( !o.fail() ); + EXAM_CHECK( o.str() == "Header: fields here\r\n" ); + + return EXAM_RESULT; +} + +int EXAM_IMPL(http_test::command) +{ + string cmd = "GET http://myhost.com HTTP/1.1\r\n"; + stringstream s( cmd ); + http::command c; + + s >> c; + + EXAM_CHECK( !s.fail() ); + EXAM_CHECK( c.value() == command::GET ); + EXAM_CHECK( c.URL() == "http://myhost.com" ); + EXAM_CHECK( c.protocol() == command::HTTP11 ); + + stringstream o; + + o << c; + + EXAM_CHECK( !o.fail() ); + EXAM_CHECK( o.str() == "GET http://myhost.com HTTP/1.1\r\n" ); + + return EXAM_RESULT; +} + +int EXAM_IMPL(http_test::base_response) +{ + string rs = "HTTP/1.1 202 Accepted\r\n"; + stringstream s( rs ); + http::base_response r; + + s >> r; + + EXAM_CHECK( !s.fail() ); + EXAM_CHECK( r.code() == 202 ); + EXAM_CHECK( r.protocol() == http::command::HTTP11 ); + + stringstream o; + + o << r; + + EXAM_CHECK( !o.fail() ); + EXAM_CHECK( o.str() == "HTTP/1.1 202 Accepted\r\n" ); + + return EXAM_RESULT; +} + +int EXAM_IMPL(http_test::request) +{ + string rq = "GET /index.html HTTP/1.1\r\n" + "Host: myhost.com\r\n" + "X-Header: test\r\n" + "\r\n"; + stringstream s( rq ); + http::request r; + + s >> r; + + EXAM_CHECK( !s.fail() ); + EXAM_CHECK( r.head().protocol() == http::command::HTTP11 ); + EXAM_CHECK( r.head().value() == http::command::GET ); + EXAM_CHECK( r.head().URL() == "/index.html" ); + EXAM_CHECK( r.headers().size() == 2 ); + EXAM_CHECK( r.headers().begin()->key() == "Host" ); + EXAM_CHECK( r.headers().begin()->value() == "myhost.com" ); + + EXAM_CHECK( r.search( "Host" ) == r.headers().begin() ); + + return EXAM_RESULT; +} + +int EXAM_IMPL(http_test::response) +{ + string rq = "HTTP/1.1 202 Accepted\r\n" + "Content-Length: 100\r\n" + "\r\n"; + stringstream s( rq ); + http::response r; + + s >> r; + + EXAM_CHECK( !s.fail() ); + EXAM_CHECK( r.head().protocol() == http::command::HTTP11 ); + EXAM_CHECK( r.head().code() == 202 ); + EXAM_CHECK( r.headers().size() == 1 ); + EXAM_CHECK( r.headers().begin()->key() == "Content-Length" ); + EXAM_CHECK( boost::lexical_cast<int>( r.headers().begin()->value() ) == 100 ); + + EXAM_CHECK( r.search( "Content-Length" ) == r.headers().begin() ); + + return EXAM_RESULT; +} + Added: trunk/complement/explore/app/intercessor/unit/http_test.h =================================================================== --- trunk/complement/explore/app/intercessor/unit/http_test.h (rev 0) +++ trunk/complement/explore/app/intercessor/unit/http_test.h 2007-10-26 16:02:33 UTC (rev 1779) @@ -0,0 +1,29 @@ +// -*- C++ -*- Time-stamp: <07/10/19 18:38:53 yeti> + +/* + * + * Copyright (c) 2007 + * Petr Ovtchenkov + * + */ + +#ifndef __http_test_h +#define __http_test_h + +#include <exam/suite.h> + +class http_test +{ + public: + + int EXAM_DECL(header_io); + int EXAM_DECL(header_sp); + int EXAM_DECL(command); + int EXAM_DECL(base_response); + int EXAM_DECL(request); + int EXAM_DECL(response); + + private: +}; + +#endif // __http_test_h Added: trunk/complement/explore/app/intercessor/unit/intercessor_test.cc =================================================================== --- trunk/complement/explore/app/intercessor/unit/intercessor_test.cc (rev 0) +++ trunk/complement/explore/app/intercessor/unit/intercessor_test.cc 2007-10-26 16:02:33 UTC (rev 1779) @@ -0,0 +1,318 @@ +// -*- C++ -*- Time-stamp: <07/03/07 16:38:24 ptr> + +/* + * + * Copyright (c) 2007 + * Petr Ovtchenkov + * + */ + +#include <boost/filesystem/operations.hpp> +#include <boost/filesystem/path.hpp> +#include "intercessor_test.h" +#include <boost/lexical_cast.hpp> + +#include <string> +#include <iostream> + +#include <sstream> +#include <fstream> +#include <iterator> +#include <unistd.h> + +#include "http.h" +#include "intercessor.h" +#include "server.h" + +#include "dummy_srv.h" +#include <sockios/sockmgr.h> +#include <mt/lfstream.h> + +boost::filesystem::path dir( boost::filesystem::initial_path() ); +unsigned rq_timeout = 3; + +using namespace std; +using namespace http; + +void files_content( bool remove = true ) +{ + { + ifstream file( "/tmp/test.xxx" ); + + EXAM_CHECK_ASYNC( file.good() ); + + string str1; + // file.lock_sh(); + getline( file, str1 ); + // file.unlock(); + + EXAM_CHECK_ASYNC( str1 == "1234567" ); + } + + // cerr << "'" << str1 << "'" << endl; + { + ifstream headers( "/tmp/test.xxx.head" ); + istreambuf_iterator<char> istr( headers.rdbuf() ); + + string str1; + + // headers.lock_sh(); + while ( istr != istreambuf_iterator<char>() ) { + str1 += *istr; + ++istr; + } + // headers.unlock(); + + string ref_string = "HTTP/1.1 200 Ok\r\n" + "Content-Length: 8\r\n" + "\r\n"; + + EXAM_CHECK_ASYNC( str1 == ref_string ); + } + + if ( remove ) { + ::unlink( "/tmp/test.xxx" ); + ::unlink( "/tmp/test.xxx.head" ); + } +} + +int EXAM_IMPL(intercessor_test::base) +{ + dir = boost::filesystem::system_complete( boost::filesystem::path( "/tmp", boost::filesystem::native ) ); + + string rq = "GET http://localhost:8090/test.php?var=123 HTTP/1.1\r\n" + "Host: localhost:8090\r\n" + "X-API-ReportFileName: test.xxx\r\n" + "\r\n"; + + stringstream s( rq ); + request r; + + s >> r; + + EXAM_CHECK( r.search( "X-API-ReportFileName" ) != r.headers().end() ); + EXAM_CHECK( r.search( "X-API-ReportFileName" )->value() == "test.xxx" ); + + test::DummyHttpSrv::cnd.set( false ); + + sockmgr_stream_MP<test::DummyHttpSrv> mgr( 8090 ); + mgr.setoptions( sock_base::so_keepalive, true ); + mgr.setoptions( sock_base::so_reuseaddr, true ); + + EXAM_CHECK( mgr.good() ); + +#if 0 + { // Dummy connect, to be sure that mgr already listen port + sockstream first_dummy( "localhost", 8080 ); + + first_dummy << "dummy string" << endl; + + BOOST_CHECK( !first_dummy.fail() ); + } + + test::DummyHttpSrv::cnd.try_wait(); + + test::DummyHttpSrv::cnd.set( false ); +#endif + + intr::Intercessor intercessor; + + stem::Event_base<intr::httprq> ev( 0x702 ); + ev.dest( intercessor.self_id() ); + ev.value().rq = r; + intercessor.Send( ev ); + + test::DummyHttpSrv::cnd.try_wait(); + + mgr.close(); + mgr.wait(); + + files_content(); + + return EXAM_RESULT; +} + +int EXAM_IMPL(intercessor_test::processor) +{ + { + intr::Intercessor intercessor(0); + sockmgr_stream_MP<intr::IncomeHttpRqProcessor> mgr( 8091 ); + + // mgr.setoptions( sock_base::so_keepalive, true ); + mgr.setoptions( sock_base::so_reuseaddr, true ); + + sockmgr_stream_MP<test::DummyHttpSrv> dummy_mgr( 8092 ); + + // dummy_mgr.setoptions( sock_base::so_keepalive, true ); + dummy_mgr.setoptions( sock_base::so_reuseaddr, true ); + +#if 0 + for ( int i = 0; i < 10; ++i ) { + test::DummyHttpSrv::cnd.set( false ); + { // Dummy connect, to be sure that mgr already listen port + sockstream first_dummy( "localhost", 8092 ); + + first_dummy << "dummy string" << endl; + + cerr << "{" << i << ", " << first_dummy.good() << endl; + BOOST_CHECK( !first_dummy.fail() ); + } + test::DummyHttpSrv::cnd.try_wait(); + } + +#endif + EXAM_CHECK( mgr.good() ); + EXAM_CHECK( dummy_mgr.good() ); + + test::DummyHttpSrv::cnd.set( false ); + + system( "curl -x localhost:8091 -H \"X-API-ReportFileName: test.xxx\" http://localhost:8092/test.php?var=123" ); + + test::DummyHttpSrv::cnd.try_wait(); + + dummy_mgr.close(); + dummy_mgr.wait(); + + mgr.close(); + mgr.wait(); + } + + files_content(); + + return EXAM_RESULT; +} + +int EXAM_IMPL(intercessor_test::processor_post) +{ + { + intr::Intercessor intercessor(0); + sockmgr_stream_MP<intr::IncomeHttpRqProcessor> mgr( 8091 ); + // mgr.setoptions( sock_base::so_keepalive, true ); + // mgr.setoptions( sock_base::so_reuseaddr, true ); + + sockmgr_stream_MP<test::DummyHttpSrv> dummy_mgr( 8092 ); + + // dummy_mgr.setoptions( sock_base::so_keepalive, true ); + // dummy_mgr.setoptions( sock_base::so_reuseaddr, true ); + +#if 0 + test::DummyHttpSrv::cnd.set( false ); + { // Dummy connect, to be sure that mgr already listen port + sockstream first_dummy( "localhost", 8080 ); + + first_dummy << "dummy string" << endl; + + BOOST_CHECK( !first_dummy.fail() ); + } + test::DummyHttpSrv::cnd.try_wait(); +#endif + EXAM_CHECK( mgr.good() ); + EXAM_CHECK( dummy_mgr.good() ); + + test::DummyHttpSrv::cnd.set( false ); + + system( "curl -x localhost:8091 -H \"X-API-ReportFileName: test.xxx\" \ +-d 'xmlrequest=<?xml version=\"1.0\"?>\ +<RWRequest><REQUEST domain=\"network\" service=\"ComplexReport\" nocache=\"n\" \ +contact_id=\"1267\" entity=\"1\" filter_entity_id=\"1\" \ +clientName=\"ui.ent\"><ROWS><ROW type=\"group\" priority=\"1\" ref=\"entity_id\" \ +includeascolumn=\"n\"/><ROW type=\"group\" priority=\"2\" \ +ref=\"advertiser_line_item_id\" includeascolumn=\"n\"/><ROW type=\"total\"/></ROWS><COLUMNS><COLUMN \ +ref=\"advertiser_line_item_name\"/><COLUMN ref=\"seller_imps\"/><COLUMN \ +ref=\"seller_clicks\"/><COLUMN ref=\"seller_convs\"/><COLUMN \ +ref=\"click_rate\"/><COLUMN ref=\"conversion_rate\"/><COLUMN ref=\"roi\"/><COLUMN \ +ref=\"network_revenue\"/><COLUMN ref=\"network_gross_cost\"/><COLUMN \ +ref=\"network_gross_profit\"/><COLUMN ref=\"network_revenue_ecpm\"/><COLUMN \ +ref=\"network_gross_cost_ecpm\"/><COLUMN \ +ref=\"network_gross_profit_ecpm\"/></COLUMNS><FILTERS><FILTER ref=\"time\" \ +macro=\"yesterday\"/></FILTERS></REQUEST></RWRequest>' http://localhost:8092/test.php" ); + + test::DummyHttpSrv::cnd.try_wait(); + + dummy_mgr.close(); + dummy_mgr.wait(); + + mgr.close(); + dummy_mgr.wait(); + + mgr.close(); + mgr.wait(); + } + + files_content(); + + return EXAM_RESULT; +} + +int EXAM_IMPL(intercessor_test::processor_external_post) +{ + { + intr::Intercessor intercessor(0); + sockmgr_stream_MP<intr::IncomeHttpRqProcessor> mgr( 8095 ); + // mgr.setoptions( sock_base::so_keepalive, true ); + // mgr.setoptions( sock_base::so_reuseaddr, true ); + EXAM_REQUIRE( mgr.good() ); + + system( "curl -x localhost:8095 -H \"X-API-ReportFileName: test.xxx\" \ +-d 'xmlrequest=<?xml version=\"1.0\"?>\ +<RWRequest><REQUEST domain=\"network\" service=\"ComplexReport\" nocache=\"n\" \ +contact_id=\"1267\" entity=\"1\" filter_entity_id=\"1\" \ +clientName=\"ui.ent\"><ROWS><ROW type=\"group\" priority=\"1\" ref=\"entity_id\" \ +includeascolumn=\"n\"/><ROW type=\"group\" priority=\"2\" \ +ref=\"advertiser_line_item_id\" includeascolumn=\"n\"/><ROW type=\"total\"/></ROWS><COLUMNS><COLUMN \ +ref=\"advertiser_line_item_name\"/><COLUMN ref=\"seller_imps\"/><COLUMN \ +ref=\"seller_clicks\"/><COLUMN ref=\"seller_convs\"/><COLUMN \ +ref=\"click_rate\"/><COLUMN ref=\"conversion_rate\"/><COLUMN ref=\"roi\"/><COLUMN \ +ref=\"network_revenue\"/><COLUMN ref=\"network_gross_cost\"/><COLUMN \ +ref=\"network_gross_profit\"/><COLUMN ref=\"network_revenue_ecpm\"/><COLUMN \ +ref=\"network_gross_cost_ecpm\"/><COLUMN \ +ref=\"network_gross_profit_ecpm\"/></COLUMNS><FILTERS><FILTER ref=\"time\" \ +macro=\"yesterday\"/></FILTERS></REQUEST></RWRequest>' http://ses0316:8080/rpt" ); + + mgr.wait(); + } + + return EXAM_RESULT; +} + +int EXAM_IMPL(intercessor_test::negative) +{ + string rq = "GET http://localhost:8092/test.php?var=123 HTTP/1.1\r\n" + "Host: localhost:8092\r\n" + "Proxy-Connection: localhost:8091\r\n" + "X-API-ReportFileName: test.xxx\r\n" + "\r\n"; + + { + intr::Intercessor intercessor(0); + sockmgr_stream_MP<intr::IncomeHttpRqProcessor> mgr( 8091 ); + sockmgr_stream_MP<test::DummyHttpSrvNeg> dummy_mgr( 8092 ); + + EXAM_CHECK( mgr.good() ); + EXAM_CHECK( dummy_mgr.good() ); + + test::DummyHttpSrvNeg::cnd.set( false ); + + { + string rs; + sockstream client( "localhost", 8091 ); + EXAM_CHECK( client.good() ); + + (client << rq).flush(); + getline( client, rs ); + + EXAM_CHECK( rs == "HTTP/1.1 410 Gone\r" ); + } + + test::DummyHttpSrvNeg::cnd.try_wait(); + + dummy_mgr.close(); + dummy_mgr.wait(); + + mgr.close(); + mgr.wait(); + } + + return EXAM_RESULT; +} + Added: trunk/complement/explore/app/intercessor/unit/intercessor_test.h =================================================================== --- trunk/complement/explore/app/intercessor/unit/intercessor_test.h (rev 0) +++ trunk/complement/explore/app/intercessor/unit/intercessor_test.h 2007-10-26 16:02:33 UTC (rev 1779) @@ -0,0 +1,28 @@ +// -*- C++ -*- Time-stamp: <07/10/19 18:38:53 yeti> + +/* + * + * Copyright (c) 2007 + * Petr Ovtchenkov + * + */ + +#ifndef __intercessor_test_h +#define __intercessor_test_h + +#include <exam/suite.h> + +class intercessor_test +{ + public: + + int EXAM_DECL(base); + int EXAM_DECL(processor); + int EXAM_DECL(processor_post); + int EXAM_DECL(processor_external_post); + int EXAM_DECL(negative); + + private: +}; + +#endif // __intercessor_test_h Added: trunk/complement/explore/app/intercessor/unit/intercessor_test_suite.cc =================================================================== --- trunk/complement/explore/app/intercessor/unit/intercessor_test_suite.cc (rev 0) +++ trunk/complement/explore/app/intercessor/unit/intercessor_test_suite.cc 2007-10-26 16:02:33 UTC (rev 1779) @@ -0,0 +1,43 @@ +// -*- C++ -*- Time-stamp: <07/10/22 18:19:19 yeti> + +/* + * + * Copyright (c) 2007 + * Petr Ovtchenkov + * + */ + +#include "intercessor_test_suite.h" +#include "http_test.h" +#include "intercessor_test.h" + +int EXAM_IMPL(http_test_suite) +{ + exam::test_suite t( "http test" ); + + http_test test; + + t.add( &http_test::header_io, test, "" ); + t.add( &http_test::header_sp, test, "" ); + t.add( &http_test::command, test, "" ); + t.add( &http_test::base_response, test, "" ); + t.add( &http_test::request, test, "" ); + t.add( &http_test::response, test, "" ); + + return t.girdle(); +} + +int EXAM_IMPL(intercessor_test_suite) +{ + exam::test_suite t( "intercessor test" ); + + intercessor_test test; + + t.add( &intercessor_test::base, test, "intercessor_test::base" ); + t.add( &intercessor_test::processor, test, "intercessor_test::base" ); + t.add( &intercessor_test::processor_post, test, "intercessor_test::base" ); + // t.add( &intercessor::processor_external_post, test, "intercessor_test::base" ); + t.add( &intercessor_test::negative, test, "intercessor_test::base" ); + + return t.girdle(); +} Added: trunk/complement/explore/app/intercessor/unit/intercessor_test_suite.h =================================================================== --- trunk/complement/explore/app/intercessor/unit/intercessor_test_suite.h (rev 0) +++ trunk/complement/explore/app/intercessor/unit/intercessor_test_suite.h 2007-10-26 16:02:33 UTC (rev 1779) @@ -0,0 +1,18 @@ +// -*- C++ -*- Time-stamp: <07/10/19 18:38:53 yeti> + +/* + * + * Copyright (c) 2007 + * Petr Ovtchenkov + * + */ + +#ifndef __intercessor_test_suite_h +#define __intercessor_test_suite_h + +#include <exam/suite.h> + +int EXAM_DECL(http_test_suite); +int EXAM_DECL(intercessor_test_suite); + +#endif // __intercessor_test_suite_h Modified: trunk/complement/explore/app/intercessor/unit/unit_test.cc =================================================================== --- trunk/complement/explore/app/intercessor/unit/unit_test.cc 2007-10-26 09:39:51 UTC (rev 1778) +++ trunk/complement/explore/app/intercessor/unit/unit_test.cc 2007-10-26 16:02:33 UTC (rev 1779) @@ -1,445 +1,15 @@ // -*- C++ -*- Time-stamp: <07/03/07 16:38:24 ptr> -#include <boost/test/unit_test.hpp> +#include "intercessor_test_suite.h" -#include <boost/filesystem/operations.hpp> -#include <boost/filesystem/path.hpp> -#include <boost/lexical_cast.hpp> - -#include <string> -#include <iostream> - -#include <sstream> -#include <fstream> -#include <iterator> -#include <unistd.h> - -#include "http.h" -#include "intercessor.h" -#include "server.h" - -#include "dummy_srv.h" -#include <sockios/sockmgr.h> -#include <mt/lfstream.h> - -using namespace boost::unit_test_framework; - -using namespace std; -using namespace http; - -boost::filesystem::path dir( boost::filesystem::initial_path() ); -unsigned rq_timeout = 3; - -void http_header_io_test() +int main( int, char ** ) { - header h; - string rq = "Content-Length: 100\r\n"; - stringstream s( rq ); + // dir = boost::filesystem::system_complete( boost::filesystem::path( "/tmp", boost::filesystem::native ) ); + int ret = 0; - s >> h; - - BOOST_CHECK( !s.fail() ); - BOOST_CHECK( h.key() == "Content-Length" ); - BOOST_CHECK( h.value() == "100" ); - - stringstream o; - - o << h; - - BOOST_CHECK( !o.fail() ); - BOOST_CHECK( o.str() == "Content-Length: 100\r\n" ); -} - -void http_header_sp_test() -{ - header h; - string rq = "Header: fields here \r\n"; - stringstream s( rq ); - - s >> h; - - BOOST_CHECK( !s.fail() ); - BOOST_CHECK( h.key() == "Header" ); - BOOST_CHECK( h.value() == "fields here" ); - - stringstream o; - - o << h; - - BOOST_CHECK( !o.fail() ); - BOOST_CHECK( o.str() == "Header: fields here\r\n" ); -} - -void http_command_test() -{ - string cmd = "GET http://myhost.com HTTP/1.1\r\n"; - stringstream s( cmd ); - command c; - - s >> c; - - BOOST_CHECK( !s.fail() ); - BOOST_CHECK( c.value() == command::GET ); - BOOST_CHECK( c.URL() == "http://myhost.com" ); - BOOST_CHECK( c.protocol() == command::HTTP11 ); - - stringstream o; - - o << c; - - BOOST_CHECK( !o.fail() ); - BOOST_CHECK( o.str() == "GET http://myhost.com HTTP/1.1\r\n" ); -} - -void http_base_response_test() -{ - string rs = "HTTP/1.1 202 Accepted\r\n"; - stringstream s( rs ); - base_response r; - - s >> r; - - BOOST_CHECK( !s.fail() ); - BOOST_CHECK( r.code() == 202 ); - BOOST_CHECK( r.protocol() == command::HTTP11 ); - - stringstream o; - - o << r; - - BOOST_CHECK( !o.fail() ); - BOOST_CHECK( o.str() == "HTTP/1.1 202 Accepted\r\n" ); -} - -void http_request_test() -{ - string rq = "GET /index.html HTTP/1.1\r\n" - "Host: myhost.com\r\n" - "X-Header: test\r\n" - "\r\n"; - stringstream s( rq ); - request r; - - s >> r; - - BOOST_CHECK( !s.fail() ); - BOOST_CHECK( r.head().protocol() == command::HTTP11 ); - BOOST_CHECK( r.head().value() == command::GET ); - BOOST_CHECK( r.head().URL() == "/index.html" ); - BOOST_CHECK( r.headers().size() == 2 ); - BOOST_CHECK( r.headers().begin()->key() == "Host" ); - BOOST_CHECK( r.headers().begin()->value() == "myhost.com" ); - - BOOST_CHECK( r.search( "Host" ) == r.headers().begin() ); -} - -void http_response_test() -{ - string rq = "HTTP/1.1 202 Accepted\r\n" - "Content-Length: 100\r\n" - "\r\n"; - stringstream s( rq ); - response r; - - s >> r; - - BOOST_CHECK( !s.fail() ); - BOOST_CHECK( r.head().protocol() == command::HTTP11 ); - BOOST_CHECK( r.head().code() == 202 ); - BOOST_CHECK( r.headers().size() == 1 ); - BOOST_CHECK( r.headers().begin()->key() == "Content-Length" ); - BOOST_CHECK( boost::lexical_cast<int>( r.headers().begin()->value() ) == 100 ); - - BOOST_CHECK( r.search( "Content-Length" ) == r.headers().begin() ); -} - -void files_content( bool remove = true ) -{ - { - ifstream file( "/tmp/test.xxx" ); - - BOOST_CHECK( file.good() ); - - string str1; - // file.lock_sh(); - getline( file, str1 ); - // file.unlock(); - - BOOST_CHECK( str1 == "1234567" ); + if ( ret = http_test_suite(0) ) { + return ret; } - // cerr << "'" << str1 << "'" << endl; - { - ifstream headers( "/tmp/test.xxx.head" ); - istreambuf_iterator<char> istr( headers.rdbuf() ); - - string str1; - - // headers.lock_sh(); - while ( istr != istreambuf_iterator<char>() ) { - str1 += *istr; - ++istr; - } - // headers.unlock(); - - string ref_string = "HTTP/1.1 200 Ok\r\n" - "Content-Length: 8\r\n" - "\r\n"; - - BOOST_CHECK( str1 == ref_string ); - } - - if ( remove ) { - ::unlink( "/tmp/test.xxx" ); - ::unlink( "/tmp/test.xxx.head" ); - } + return intercessor_test_suite(0); } - -void intercessor_test() -{ - string rq = "GET http://localhost:8090/test.php?var=123 HTTP/1.1\r\n" - "Host: localhost:8090\r\n" - "X-API-ReportFileName: test.xxx\r\n" - "\r\n"; - - stringstream s( rq ); - request r; - - s >> r; - - BOOST_CHECK( r.search( "X-API-ReportFileName" ) != r.headers().end() ); - BOOST_CHECK( r.search( "X-API-ReportFileName" )->value() == "test.xxx" ); - - test::DummyHttpSrv::cnd.set( false ); - - sockmgr_stream_MP<test::DummyHttpSrv> mgr( 8090 ); - mgr.setoptions( sock_base::so_keepalive, true ); - mgr.setoptions( sock_base::so_reuseaddr, true ); - - BOOST_CHECK( mgr.good() ); - -#if 0 - { // Dummy connect, to be sure that mgr already listen port - sockstream first_dummy( "localhost", 8080 ); - - first_dummy << "dummy string" << endl; - - BOOST_CHECK( !first_dummy.fail() ); - } - - test::DummyHttpSrv::cnd.try_wait(); - - test::DummyHttpSrv::cnd.set( false ); -#endif - - intr::Intercessor intercessor; - - stem::Event_base<intr::httprq> ev( 0x702 ); - ev.dest( intercessor.self_id() ); - ev.value().rq = r; - intercessor.Send( ev ); - - test::DummyHttpSrv::cnd.try_wait(); - - mgr.close(); - mgr.wait(); - - files_content(); -} - -void http_processor_test() -{ - { - intr::Intercessor intercessor(0); - sockmgr_stream_MP<intr::IncomeHttpRqProcessor> mgr( 8091 ); - - // mgr.setoptions( sock_base::so_keepalive, true ); - mgr.setoptions( sock_base::so_reuseaddr, true ); - - sockmgr_stream_MP<test::DummyHttpSrv> dummy_mgr( 8092 ); - - // dummy_mgr.setoptions( sock_base::so_keepalive, true ); - dummy_mgr.setoptions( sock_base::so_reuseaddr, true ); - -#if 0 - for ( int i = 0; i < 10; ++i ) { - test::DummyHttpSrv::cnd.set( false ); - { // Dummy connect, to be sure that mgr already listen port - sockstream first_dummy( "localhost", 8092 ); - - first_dummy << "dummy string" << endl; - - cerr << "{" << i << ", " << first_dummy.good() << endl; - BOOST_CHECK( !first_dummy.fail() ); - } - test::DummyHttpSrv::cnd.try_wait(); - } - -#endif - BOOST_CHECK( mgr.good() ); - BOOST_CHECK( dummy_mgr.good() ); - - test::DummyHttpSrv::cnd.set( false ); - - system( "curl -x localhost:8091 -H \"X-API-ReportFileName: test.xxx\" http://localhost:8092/test.php?var=123" ); - - test::DummyHttpSrv::cnd.try_wait(); - - dummy_mgr.close(); - dummy_mgr.wait(); - - mgr.close(); - mgr.wait(); - } - - files_content(); -} - -void http_processor_post_test() -{ - { - intr::Intercessor intercessor(0); - sockmgr_stream_MP<intr::IncomeHttpRqProcessor> mgr( 8091 ); - // mgr.setoptions( sock_base::so_keepalive, true ); - // mgr.setoptions( sock_base::so_reuseaddr, true ); - - sockmgr_stream_MP<test::DummyHttpSrv> dummy_mgr( 8092 ); - - // dummy_mgr.setoptions( sock_base::so_keepalive, true ); - // dummy_mgr.setoptions( sock_base::so_reuseaddr, true ); - -#if 0 - test::DummyHttpSrv::cnd.set( false ); - { // Dummy connect, to be sure that mgr already listen port - sockstream first_dummy( "localhost", 8080 ); - - first_dummy << "dummy string" << endl; - - BOOST_CHECK( !first_dummy.fail() ); - } - test::DummyHttpSrv::cnd.try_wait(); -#endif - BOOST_CHECK( mgr.good() ); - BOOST_CHECK( dummy_mgr.good() ); - - test::DummyHttpSrv::cnd.set( false ); - - system( "curl -x localhost:8091 -H \"X-API-ReportFileName: test.xxx\" \ --d 'xmlrequest=<?xml version=\"1.0\"?>\ -<RWRequest><REQUEST domain=\"network\" service=\"ComplexReport\" nocache=\"n\" \ -contact_id=\"1267\" entity=\"1\" filter_entity_id=\"1\" \ -clientName=\"ui.ent\"><ROWS><ROW type=\"group\" priority=\"1\" ref=\"entity_id\" \ -includeascolumn=\"n\"/><ROW type=\"group\" priority=\"2\" \ -ref=\"advertiser_line_item_id\" includeascolumn=\"n\"/><ROW type=\"total\"/></ROWS><COLUMNS><COLUMN \ -ref=\"advertiser_line_item_name\"/><COLUMN ref=\"seller_imps\"/><COLUMN \ -ref=\"seller_clicks\"/><COLUMN ref=\"seller_convs\"/><COLUMN \ -ref=\"click_rate\"/><COLUMN ref=\"conversion_rate\"/><COLUMN ref=\"roi\"/><COLUMN \ -ref=\"network_revenue\"/><COLUMN ref=\"network_gross_cost\"/><COLUMN \ -ref=\"network_gross_profit\"/><COLUMN ref=\"network_revenue_ecpm\"/><COLUMN \ -ref=\"network_gross_cost_ecpm\"/><COLUMN \ -ref=\"network_gross_profit_ecpm\"/></COLUMNS><FILTERS><FILTER ref=\"time\" \ -macro=\"yesterday\"/></FILTERS></REQUEST></RWRequest>' http://localhost:8092/test.php" ); - - test::DummyHttpSrv::cnd.try_wait(); - - dummy_mgr.close(); - dummy_mgr.wait(); - - mgr.close(); - mgr.wait(); - } - - files_content(); -} - -void http_processor_external_post_test() -{ - { - intr::Intercessor intercessor(0); - sockmgr_stream_MP<intr::IncomeHttpRqProcessor> mgr( 8095 ); - // mgr.setoptions( sock_base::so_keepalive, true ); - // mgr.setoptions( sock_base::so_reuseaddr, true ); - if ( !mgr.good() ) { - cerr << "Not good" << endl; - return; - } - - system( "curl -x localhost:8095 -H \"X-API-ReportFileName: test.xxx\" \ --d 'xmlrequest=<?xml version=\"1.0\"?>\ -<RWRequest><REQUEST domain=\"network\" service=\"ComplexReport\" nocache=\"n\" \ -contact_id=\"1267\" entity=\"1\" filter_entity_id=\"1\" \ -clientName=\"ui.ent\"><ROWS><ROW type=\"group\" priority=\"1\" ref=\"entity_id\" \ -includeascolumn=\"n\"/><ROW type=\"group\" priority=\"2\" \ -ref=\"advertiser_line_item_id\" includeascolumn=\"n\"/><ROW type=\"total\"/></ROWS><COLUMNS><COLUMN \ -ref=\"advertiser_line_item_name\"/><COLUMN ref=\"seller_imps\"/><COLUMN \ -ref=\"seller_clicks\"/><COLUMN ref=\"seller_convs\"/><COLUMN \ -ref=\"click_rate\"/><COLUMN ref=\"conversion_rate\"/><COLUMN ref=\"roi\"/><COLUMN \ -ref=\"network_revenue\"/><COLUMN ref=\"network_gross_cost\"/><COLUMN \ -ref=\"network_gross_profit\"/><COLUMN ref=\"network_revenue_ecpm\"/><COLUMN \ -ref=\"network_gross_cost_ecpm\"/><COLUMN \ -ref=\"network_gross_profit_ecpm\"/></COLUMNS><FILTERS><FILTER ref=\"time\" \ -macro=\"yesterday\"/></FILTERS></REQUEST></RWRequest>' http://ses0316:8080/rpt" ); - - mgr.wait(); - } -} - -void intercessor_negative() -{ - string rq = "GET http://localhost:8092/test.php?var=123 HTTP/1.1\r\n" - "Host: localhost:8092\r\n" - "Proxy-Connection: localhost:8091\r\n" - "X-API-ReportFileName: test.xxx\r\n" - "\r\n"; - - { - intr::Intercessor intercessor(0); - sockmgr_stream_MP<intr::IncomeHttpRqProcessor> mgr( 8091 ); - sockmgr_stream_MP<test::DummyHttpSrvNeg> dummy_mgr( 8092 ); - - BOOST_CHECK( mgr.good() ); - BOOST_CHECK( dummy_mgr.good() ); - - test::DummyHttpSrvNeg::cnd.set( false ); - - { - string rs; - sockstream client( "localhost", 8091 ); - BOOST_CHECK( client.good() ); - - (client << rq).flush(); - getline( client, rs ); - - BOOST_CHECK( rs == "HTTP/1.1 410 Gone\r" ); - } - - test::DummyHttpSrvNeg::cnd.try_wait(); - - dummy_mgr.close(); - dummy_mgr.wait(); - - mgr.close(); - mgr.wait(); - } -} - -test_suite *init_unit_test_suite( int argc, char** const argv ) -{ - dir = boost::filesystem::system_complete( boost::filesystem::path( "/tmp", boost::filesystem::native ) ); - - test_suite *ts = BOOST_TEST_SUITE( "intercessor test" ); - - ts->add( BOOST_TEST_CASE( &http_header_io_test ) ); - ts->add( BOOST_TEST_CASE( &http_header_sp_test ) ); - ts->add( BOOST_TEST_CASE( &http_command_test ) ); - ts->add( BOOST_TEST_CASE( &http_base_response_test ) ); - ts->add( BOOST_TEST_CASE( &http_request_test ) ); - ts->add( BOOST_TEST_CASE( &http_response_test ) ); - ts->add( BOOST_TEST_CASE( &intercessor_test ), 0, 7 ); - ts->add( BOOST_TEST_CASE( &http_processor_test ), 0, 7 ); - ts->add( BOOST_TEST_CASE( &http_processor_post_test ), 0, 7 ); - // ts->add( BOOST_TEST_CASE( &http_processor_external_post_test ), 0, 60 ); - ts->add( BOOST_TEST_CASE( &intercessor_negative ), 0, 7 ); - - return ts; -} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |