summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAndreas Baumann <abaumann@yahoo.com>2010-05-20 17:04:48 +0200
committerAndreas Baumann <abaumann@yahoo.com>2010-05-20 17:04:48 +0200
commit89ed8b193485c94b65eb8ba1014f6832d23707e1 (patch)
treee6c7a82ef2a08e287f0211810c095132c32ad6f4 /tests
parent34a193a606ce61f7d84e4417b198a5a05b9c8e38 (diff)
downloadwolfbones-89ed8b193485c94b65eb8ba1014f6832d23707e1.tar.gz
wolfbones-89ed8b193485c94b65eb8ba1014f6832d23707e1.tar.bz2
loader works on windows
Diffstat (limited to 'tests')
-rw-r--r--tests/library/Makefile.W3211
-rw-r--r--tests/library/test_loader.c19
-rw-r--r--tests/library/testlib.c8
3 files changed, 34 insertions, 4 deletions
diff --git a/tests/library/Makefile.W32 b/tests/library/Makefile.W32
index 4ebcab9..7c44d8d 100644
--- a/tests/library/Makefile.W32
+++ b/tests/library/Makefile.W32
@@ -13,11 +13,20 @@ INCLUDE_LIBS = \
TEST_BINS = \
test_loader.exe
+TEST_OBJS = \
+ testlib.obj
+
+TEST_LIBRARIES = \
+ testlib.dll
+
!INCLUDE $(TOPDIR)\makefiles\nmake\sub.mk
+testlib.dll: $(TEST_OBJS)
+ $(LINK) /DLL /nologo /out:$@ $(LDFLAGS) $(LIBS) $?
+
test_loader.exe: test_loader.obj $(TOPDIR)\src\wolf.lib
-local_all:
+local_all: $(TEST_LIBRARIES)
local_clean:
diff --git a/tests/library/test_loader.c b/tests/library/test_loader.c
index 0eef9f2..6fd5d2e 100644
--- a/tests/library/test_loader.c
+++ b/tests/library/test_loader.c
@@ -21,6 +21,12 @@
#include <stdio.h> /* for fprintf */
#include <assert.h> /* for assert */
+#ifdef _WIN32
+#define LIBRARY_NAME "testlib.dll"
+#else
+#define LIBRARY_NAME "./testlib.so.0.0.0"
+#endif
+
int main( void ) {
wolf_library_p library;
wolf_error_t error;
@@ -32,7 +38,7 @@ int main( void ) {
int res = 0;
/* open the libray */
- library = wolf_library_load( "./testlib.so.0.0.0", &error );
+ library = wolf_library_load( LIBRARY_NAME, &error );
if( error != WOLF_OK ) {
fprintf( stderr, "Error %d loading the library: %s\n",
error, wolf_library_errmsg( error, library, errbuf, 512 ) );
@@ -44,9 +50,18 @@ int main( void ) {
* http://en.wikipedia.org/wiki/Dynamic_loading
*/
symbol = wolf_library_get_func( library, "multiply_by_two", &error );
+ if( error != WOLF_OK ) {
+ fprintf( stderr, "Error %d fetching a function from the library: %s\n",
+ error, wolf_library_errmsg( error, library, errbuf, 512 ) );
+ return EXIT_FAILURE;
+ }
+#if !defined _WIN32
alias.obj = symbol;
func = alias.func;
-
+#else
+ func = (multiply_by_two_func)symbol;
+#endif
+
/* call it */
res = func( 7 );
assert( res == 14 );
diff --git a/tests/library/testlib.c b/tests/library/testlib.c
index f8e457a..b240819 100644
--- a/tests/library/testlib.c
+++ b/tests/library/testlib.c
@@ -1,4 +1,10 @@
-int multiply_by_two( int a );
+#ifdef _WIN32
+#define DLLEXPORT __declspec( dllexport )
+#else
+#define DLLEXPORT
+#endif
+
+DLLEXPORT int multiply_by_two( int a );
int multiply_by_two( int a ) {
return a * 2;