#include <stdio.h>
#include <dlfcn.h>
#include <stdlib.h>
#include "test_support.h"
extern bool foo(bool* ptr);
int main(int argc, const char* argv[], const char* envp[], const char* apple[]) {
void* h = dlopen(RUN_DIR "/libfoo.dylib", RTLD_NOW);
if (h == NULL) {
FAIL("dlerror = %s", dlerror());
}
void* fooSym = dlsym(RTLD_DEFAULT, "foo");
if ( fooSym == NULL ) {
FAIL("dlsym failure");
}
bool ranTerm = false;
bool ranInit = ((__typeof(&foo))fooSym)(&ranTerm);
if (!ranInit) {
FAIL("didn't run init");
}
if ( dlclose(h) != 0 ) {
FAIL("didn't dlclose");
}
if (!ranTerm) {
FAIL("didn't run term");
}
PASS("Success");
}