diff options
author | Andreas Baumann <abaumann@yahoo.com> | 2012-08-21 16:48:33 +0200 |
---|---|---|
committer | Andreas Baumann <abaumann@yahoo.com> | 2012-08-21 16:48:33 +0200 |
commit | 8722ffd5fce48d304573820f551ca669c691dda9 (patch) | |
tree | 7352229e85ceee6db62ae0b7f19875e993beff85 /tests/modules | |
parent | 3296b2b47538ebef866a3b84e79b241f79a709f0 (diff) | |
download | crawler-8722ffd5fce48d304573820f551ca669c691dda9.tar.gz crawler-8722ffd5fce48d304573820f551ca669c691dda9.tar.bz2 |
added test for module loader in loaded module test (Linux)
Diffstat (limited to 'tests/modules')
-rwxr-xr-x | tests/modules/GNUmakefile | 6 | ||||
-rwxr-xr-x | tests/modules/Makefile.W32 | 9 | ||||
-rwxr-xr-x | tests/modules/test3.MUST | 5 | ||||
-rwxr-xr-x | tests/modules/test3.cpp | 36 | ||||
-rwxr-xr-x | tests/modules/testmod3/GNUmakefile | 39 | ||||
-rwxr-xr-x | tests/modules/testmod3/Makefile.W32 | 47 | ||||
-rwxr-xr-x | tests/modules/testmod3/TestMod3.cpp | 35 | ||||
-rwxr-xr-x | tests/modules/testmod3/TestMod3.hpp | 25 |
8 files changed, 198 insertions, 4 deletions
diff --git a/tests/modules/GNUmakefile b/tests/modules/GNUmakefile index 70a2a37..7a1ee57 100755 --- a/tests/modules/GNUmakefile +++ b/tests/modules/GNUmakefile @@ -1,6 +1,6 @@ TOPDIR = ../.. -SUBDIRS = testmod testmod2 +SUBDIRS = testmod testmod2 testmod3 INCLUDE_DIRS = \ -I. -I$(TOPDIR)/src @@ -11,7 +11,8 @@ INCLUDE_LIBS = TEST_CPP_BINS = \ test1$(EXE) \ - test2$(EXE) + test2$(EXE) \ + test3$(EXE) OBJS = @@ -27,3 +28,4 @@ local_distclean: local_test: @./exec_test test1 "Module loader" @./exec_test test2 "Module loader with singleton" + @./exec_test test3 "Load module in module" diff --git a/tests/modules/Makefile.W32 b/tests/modules/Makefile.W32 index 6dfa78b..1af8e7b 100755 --- a/tests/modules/Makefile.W32 +++ b/tests/modules/Makefile.W32 @@ -1,6 +1,6 @@ TOPDIR = ..\.. -SUBDIRS = testmod testmod2 +SUBDIRS = testmod testmod2 testmod3 !INCLUDE $(TOPDIR)\makefiles\nmake\platform.mk @@ -18,7 +18,8 @@ INCLUDE_LIBS = \ TEST_CPP_BINS = \ test1.exe \ - test2.exe + test2.exe \ + test3.exe OBJS = @@ -26,7 +27,10 @@ OBJS = test1.exe: test1.obj test2.exe: test2.obj +test3.exe: test3.obj +# must build test2.lib first becase it contains DDL exports for the +# Common singleton local_all: test2.exe local_clean: @@ -37,3 +41,4 @@ local_distclean: local_test: @-exec_test test1 "Module loader" @-exec_test test2 "Module loader with singleton" + @-exec_test test3 "Load module in module" diff --git a/tests/modules/test3.MUST b/tests/modules/test3.MUST new file mode 100755 index 0000000..9c01d20 --- /dev/null +++ b/tests/modules/test3.MUST @@ -0,0 +1,5 @@ +Created common object +test3: hello from main +test3: hello from module +test3: hello world from module +Destroyed common object diff --git a/tests/modules/test3.cpp b/tests/modules/test3.cpp new file mode 100755 index 0000000..17eac02 --- /dev/null +++ b/tests/modules/test3.cpp @@ -0,0 +1,36 @@ +#include "ModuleLoader.hpp" +#include "Base.hpp" +#include "Common.hpp" + +#include <vector> +#include <string> +#include <iostream> + +using namespace std; + +int main( void ) +{ + try { + Common &c = Common::instance( ); + c.setName( "test3" ); + + vector<string> modules; +#ifndef _WIN32 + modules.push_back( "./testmod3/mod_test3.so" ); +#else + modules.push_back( ".\\testmod3\\mod_test3.dll" ); +#endif + ModuleLoader<Base> loader( modules ); + + Base *obj = loader.create( "testmod3" ); + c.print( "hello from main" ); + obj->hello( ); + loader.destroy( obj ); + + } catch( exception &e ) { + cerr << "Module loader error: " << e.what( ); + return 1; + } + + return 0; +} diff --git a/tests/modules/testmod3/GNUmakefile b/tests/modules/testmod3/GNUmakefile new file mode 100755 index 0000000..4d296de --- /dev/null +++ b/tests/modules/testmod3/GNUmakefile @@ -0,0 +1,39 @@ +TOPDIR = ../../.. + +SUBDIRS = + +-include $(TOPDIR)/makefiles/gmake/platform.mk + +INCLUDE_DIRS = \ + -I. -I$(TOPDIR)/src -I.. + +INCLUDE_CXXFLAGS = \ + +INCLUDE_LDFLAGS = \ + +INCLUDE_LIBS = \ + $(TOPDIR)/src/libcrawler.a + +DYNAMIC_MODULE = \ + mod_test3.so + +STATIC_LIB = \ + libtest3.a + +CPP_OBJS = \ + TestMod3.o + +-include $(TOPDIR)/makefiles/gmake/sub.mk + +local_all: + +local_clean: + +local_distclean: + +local_install: + +local_uninstall: + +local_test: + diff --git a/tests/modules/testmod3/Makefile.W32 b/tests/modules/testmod3/Makefile.W32 new file mode 100755 index 0000000..0f1aac0 --- /dev/null +++ b/tests/modules/testmod3/Makefile.W32 @@ -0,0 +1,47 @@ +TOPDIR = ..\..\.. + +SUBDIRS = + +!INCLUDE $(TOPDIR)\makefiles\nmake\platform.mk + +INCLUDE_CXXFLAGS = \ + /D_WIN32_WINNT=0x504 + +INCLUDE_DIRS = \ + /I. \ + /I$(TOPDIR)\src \ + /I.. + +INCLUDE_LDFLAGS = \ + +INCLUDE_LIBS = \ + $(TOPDIR)\src\crawler.lib \ + ..\test2.lib + +DYNAMIC_MODULE = \ + mod_test3.dll + +STATIC_LIB = \ + test3.lib + +CPP_OBJS = \ + TestMod3.obj + +SHARED_CPP_OBJS = \ + TestMod3.dllobj + +!INCLUDE $(TOPDIR)\makefiles\nmake\sub.mk + +$(STATIC_LIB): $(CPP_OBJS) + $(LINK) /lib /nologo /out:$@ $(STATIC_LDFLAGS) $? + +$(DYNAMIC_MODULE): $(SHARED_CPP_OBJS) + $(LINK) /dll /nologo /out:$@ $(LDFLAGS) $(LIBS) $? + +local_all: $(STATIC_LIB) $(DYNAMIC_MODULE) + +local_clean: + +local_distclean: + +local_test: diff --git a/tests/modules/testmod3/TestMod3.cpp b/tests/modules/testmod3/TestMod3.cpp new file mode 100755 index 0000000..4962442 --- /dev/null +++ b/tests/modules/testmod3/TestMod3.cpp @@ -0,0 +1,35 @@ +#include "TestMod3.hpp" +#include "Common.hpp" + +#include <iostream> + +#include <vector> +#include <string> + +using namespace std; + +Derived::Derived( ) +{ + vector<string> modules; +#ifndef _WIN32 + modules.push_back( "./testmod2/mod_test2.so" ); +#else + modules.push_back( ".\\testmod2\\mod_test2.dll" ); +#endif + m_loader = new ModuleLoader<Base>( modules ); +} + +Derived::~Derived( ) +{ + delete m_loader; +} + +void Derived::hello( ) +{ + Base *obj = m_loader->create( "testmod2" ); + obj->hello( ); + m_loader->destroy( obj ); + Common::instance( ).print( "hello world from module" ); +} + +REGISTER_MODULE( "testmod3", Base, Derived ) diff --git a/tests/modules/testmod3/TestMod3.hpp b/tests/modules/testmod3/TestMod3.hpp new file mode 100755 index 0000000..d4d4d99 --- /dev/null +++ b/tests/modules/testmod3/TestMod3.hpp @@ -0,0 +1,25 @@ +#ifndef __TESTMOD_H +#define __TESTMOD_H + +#include "Base.hpp" + +#include "ModuleRegistry.hpp" + +#include "ModuleLoader.hpp" + +class Derived : public Base +{ + public: + Derived( ); + + virtual ~Derived( ); + + virtual void hello( ); + + private: + ModuleLoader<Base> *m_loader; +}; + +DECLARE_MODULE( Base ) + +#endif |