dyld-750.5.tar.gz
[apple/dyld.git] / testing / test-cases / dlopen-basic.dtest / main.c
1
2 // BUILD: $CC foo.c -dynamiclib -o $BUILD_DIR/test.dylib
3 // BUILD: $CC foo.c -bundle -o $BUILD_DIR/test.bundle
4 // BUILD: $CC main.c -DRUN_DIR="$RUN_DIR" -o $BUILD_DIR/dlopen-basic.exe
5
6 // RUN: ./dlopen-basic.exe
7
8 #include <stdio.h>
9 #include <dlfcn.h>
10
11 #include "test_support.h"
12
13 static void tryImage(const char* path)
14 {
15 void* handle = dlopen(path, RTLD_LAZY);
16 if ( handle == NULL ) {
17 FAIL("dlopen(\"%s\"), dlerror()=%s", path, dlerror());
18 }
19
20 void* sym = dlsym(handle, "foo");
21 if ( sym == NULL ) {
22 FAIL("dlsym(\"foo\") for \"%s\" returned NULL, dlerror()=%s", path, dlerror());
23 }
24
25 int result = dlclose(handle);
26 if ( result != 0 ) {
27 FAIL("dlclose(\"%s\") returned %d, dlerror()=%s", path, result, dlerror());
28 }
29 }
30
31
32
33 int main(int argc, const char* argv[], const char* envp[], const char* apple[]) {
34 tryImage(RUN_DIR "/test.bundle");
35 tryImage(RUN_DIR "/test.dylib");
36 PASS("Success");
37 }
38