#include <stdio.h>
#include <dlfcn.h>
#include "test_support.h"
int gInitialisersCalled = 0;
int main(int argc, const char* argv[], const char* envp[], const char* apple[]) {
int result;
void* fooHandle = 0;
{
fooHandle = dlopen(RUN_DIR "/libfoo.dylib", RTLD_LAZY);
if (!fooHandle) {
FAIL("dlopen(\"" RUN_DIR "/libfoo.dylib\") failed with error: %s", dlerror());
}
if (gInitialisersCalled != 1) {
FAIL("gInitialisersCalled != 1");
}
}
result = dlclose(fooHandle);
if (result != 0) {
FAIL("dlclose() returned %c", result);
}
{
fooHandle = dlopen(RUN_DIR "/libfoo.dylib", RTLD_LAZY);
if (!fooHandle) {
FAIL("dlopen failed with error: %s", dlerror());
}
if (gInitialisersCalled != 2) {
FAIL("gInitialisersCalled != 2");
}
}
void* barHandle = 0;
{
barHandle = dlopen(RUN_DIR "/libbar.dylib", RTLD_LAZY);
if (!barHandle) {
FAIL("dlopen(\"" RUN_DIR "/libbar.dylib\" failed with error: %s", dlerror());
}
if (gInitialisersCalled != 3) {
FAIL("gInitialisersCalled != 3");
}
}
result = dlclose(fooHandle);
if (result != 0) {
FAIL("dlclose(\"" RUN_DIR "/libfoo.dylib\") returned %c", result);
}
{
fooHandle = dlopen(RUN_DIR "/libfoo.dylib", RTLD_LAZY);
if (!fooHandle) {
FAIL("dlopen(\"" RUN_DIR "/libfoo.dylib\" failed with error: %s", dlerror());
}
if (gInitialisersCalled != 3) {
FAIL("gInitialisersCalled != 3");
}
}
PASS("Success");
}