diff options
author | Andreas Baumann <abaumann@yahoo.com> | 2012-08-07 08:51:53 +0200 |
---|---|---|
committer | Andreas Baumann <abaumann@yahoo.com> | 2012-08-07 08:51:53 +0200 |
commit | e41aee814d41ada4bb9651f8837d1d7b272820f9 (patch) | |
tree | 72e193ef99519794d251dc5864c92d8e494eba4a /tests/url | |
parent | 6c8d62160c3a5d744f797f06d8c505c5bb8f2622 (diff) | |
download | crawler-e41aee814d41ada4bb9651f8837d1d7b272820f9.tar.gz crawler-e41aee814d41ada4bb9651f8837d1d7b272820f9.tar.bz2 |
cleaned up url normalizer tests and made them use module loader
Diffstat (limited to 'tests/url')
-rw-r--r-- | tests/url/GNUmakefile | 8 | ||||
-rw-r--r-- | tests/url/test1.cpp | 21 | ||||
-rw-r--r-- | tests/url/test2.cpp | 20 |
3 files changed, 21 insertions, 28 deletions
diff --git a/tests/url/GNUmakefile b/tests/url/GNUmakefile index 62ca063..5a3ca08 100644 --- a/tests/url/GNUmakefile +++ b/tests/url/GNUmakefile @@ -3,16 +3,12 @@ TOPDIR = ../.. SUBDIRS = INCLUDE_DIRS = \ - -I$(TOPDIR)/src \ - -I$(TOPDIR)/src/modules/urlnormalizer/simpleurl \ - -I$(TOPDIR)/src/modules/urlnormalizer/googleurl + -I$(TOPDIR)/src INCLUDE_LDFLAGS = INCLUDE_LIBS = \ - $(TOPDIR)/src/libcrawlingwolf.a \ - $(TOPDIR)/googleurl/libgoogleurl.a \ - -licui18n -licuuc + $(TOPDIR)/src/libcrawlingwolf.a TEST_CPP_BINS = \ test1$(EXE) \ diff --git a/tests/url/test1.cpp b/tests/url/test1.cpp index 5fd3e90..732d52e 100644 --- a/tests/url/test1.cpp +++ b/tests/url/test1.cpp @@ -1,7 +1,8 @@ #include "URL.hpp" -#include "SimpleURLNormalizer.hpp" -#include "GoogleURLNormalizer.hpp" +#include "URLNormalizer.hpp" +#include "ModuleLoader.hpp" +#include <vector> #include <iostream> #include <string> #include <cstring> @@ -17,18 +18,16 @@ int main( int argc, char *argv[] ) char *method = argv[1]; char *urlstring = argv[2]; + + vector<string> modules; + modules.push_back( "../../src/modules/urlnormalizer/simpleurl/mod_urlnormalizer_simple.so" ); + modules.push_back( "../../src/modules/urlnormalizer/googleurl/mod_urlnormalizer_googleurl.so" ); + ModuleLoader<URLNormalizer> urlNormalizers( modules ); - URLNormalizer *normalizer; - if( strcmp( method, "simple" ) == 0 ) { - normalizer = new SimpleURLNormalizer( ); - } else if( strcmp( method, "google" ) == 0 ) { - normalizer = new GoogleURLNormalizer( ); - } else { - cerr << "illegal method '" << method << "'" << endl; - } + URLNormalizer *normalizer = urlNormalizers.create( method ); URL url = normalizer->parseUrl( urlstring ); - delete normalizer; + urlNormalizers.destroy( normalizer ); if( url == URL::Null ) { cerr << "Illegal URL!" << endl; diff --git a/tests/url/test2.cpp b/tests/url/test2.cpp index fb660a3..1d57629 100644 --- a/tests/url/test2.cpp +++ b/tests/url/test2.cpp @@ -1,6 +1,6 @@ #include "URL.hpp" -#include "SimpleURLNormalizer.hpp" -#include "GoogleURLNormalizer.hpp" +#include "URLNormalizer.hpp" +#include "ModuleLoader.hpp" #include <iostream> #include <string> @@ -19,14 +19,12 @@ int main( int argc, char *argv[] ) char *baseUrlString = argv[2]; char *partialUrlString = argv[3]; - URLNormalizer *normalizer; - if( strcmp( method, "simple" ) == 0 ) { - normalizer = new SimpleURLNormalizer( ); - } else if( strcmp( method, "google" ) == 0 ) { - normalizer = new GoogleURLNormalizer( ); - } else { - cerr << "illegal method '" << method << "'" << endl; - } + vector<string> modules; + modules.push_back( "../../src/modules/urlnormalizer/simpleurl/mod_urlnormalizer_simple.so" ); + modules.push_back( "../../src/modules/urlnormalizer/googleurl/mod_urlnormalizer_googleurl.so" ); + ModuleLoader<URLNormalizer> urlNormalizers( modules ); + + URLNormalizer *normalizer = urlNormalizers.create( method ); URL baseUrl = normalizer->parseUrl( baseUrlString ); @@ -41,7 +39,7 @@ int main( int argc, char *argv[] ) cout << "URL: " << url << endl; - delete normalizer; + urlNormalizers.destroy( normalizer ); return 0; } |