#include <stdio.h> // fprintf(), NULL
#include <stdlib.h> // exit(), EXIT_SUCCESS
#include <dlfcn.h>
#include "test.h" // PASS(), FAIL(), XPASS(), XFAIL()
int main()
{
void* handle1 = dlopen("test.bundle", RTLD_LAZY);
if ( handle1 == NULL ) {
FAIL("dlclose-bundle-unload: dlopen(\"test.bundle\", RTLD_LAZY) failed with dlerror()=%s", dlerror());
exit(0);
}
void* handle2 = dlopen("test.bundle", RTLD_LAZY);
if ( handle2 == NULL ) {
FAIL("dlclose-bundle-unload: dlopen(\"test.bundle\", RTLD_LAZY) failed with dlerror()=%s", dlerror());
exit(0);
}
void* handle3 = dlopen("test.bundle", RTLD_LAZY);
if ( handle3 == NULL ) {
FAIL("dlclose-bundle-unload: dlopen(\"test.bundle\", RTLD_LAZY) failed with dlerror()=%s", dlerror());
exit(0);
}
void* sym = dlsym(handle1, "foo");
if ( sym == NULL ) {
FAIL("dlclose-bundle-unload: dlsym(handle1, \"foo\") failed");
exit(0);
}
if ( dlclose(handle3) != 0 ) {
FAIL("dlclose-bundle-unload: dlclose(handle3) != 0, dlerrr()=%s", dlerror());
exit(0);
}
if ( dlclose(handle2) != 0 ) {
FAIL("dlclose-bundle-unload: dlclose(handle2) != 0, dlerrr()=%s", dlerror());
exit(0);
}
if ( dlclose(handle1) != 0 ) {
FAIL("dlclose-bundle-unload: dlclose(handle1) != 0, dlerrr()=%s", dlerror());
exit(0);
}
if ( dlclose(handle1) == 0 ) {
FAIL("dlclose-bundle-unload: dlclose(handle4) == 0, but should have failed");
exit(0);
}
PASS("dlclose-bundle-unload");
return EXIT_SUCCESS;
}