Commit 043b3358a91a5e9bef707fd3720f60552e0b9569

Timothy Gu 2014-02-10T03:35:19

test: add forgotten test "Open library again (without closing it first) with RTLD_GLOBAL"

diff --git a/test.c b/test.c
index 8977fbc..b8f6c9e 100644
--- a/test.c
+++ b/test.c
@@ -49,7 +49,6 @@
  * - Get symbol from library through library object <- works
  * - Run function if it worked
  * - Get symbol from library through global object  <- fails
- * - Run function if it worked
  * - Open library again (without closing it first) with RTLD_GLOBAL
  * - Get symbol from library through global object  <- works
  * - Close library
@@ -167,6 +166,33 @@ int main()
     else
         printf( "SUCCESS\tDid not get local symbol from global handle.\n" );
 
+    library = dlopen( "testdll.dll", RTLD_GLOBAL );
+    if( !library )
+    {
+        error = dlerror( );
+        printf( "ERROR\tCould not open library globally without closing it first: %s\n", error ? error : "" );
+        CLOSE_LIB;
+        CLOSE_GLOBAL;
+        RETURN_ERROR;
+    }
+    else
+        printf( "SUCCESS\tOpened library globally without closing it first: %p\n", library );
+
+    function = dlsym( global, "function" );
+    if( !function )
+    {
+        error = dlerror( );
+        printf( "ERROR\tCould not get symbol from global handle: %s\n",
+                error ? error : "" );
+        CLOSE_LIB;
+        CLOSE_GLOBAL;
+        RETURN_ERROR;
+    }
+    else
+        printf( "SUCCESS\tGot symbol from global handle: %p\n", function );
+
+    RUNFUNC;
+
     ret = dlclose( library );
     if( ret )
     {