dyld-750.5.tar.gz
[apple/dyld.git] / testing / test-cases / interpose-weak.dtest / main.c
1 // BUILD: $CC foo.c -dynamiclib -o $BUILD_DIR/libfoo.dylib -install_name $RUN_DIR/libfoo.dylib
2 // BUILD: $CC main.c $BUILD_DIR/libfoo.dylib -o $BUILD_DIR/interpose-weak-present.exe
3 // BUILD: $DYLD_ENV_VARS_ENABLE $BUILD_DIR/interpose-weak-present.exe
4 // BUILD: $CC interposer.c -dynamiclib $BUILD_DIR/libfoo.dylib -o $BUILD_DIR/libinterposer.dylib -install_name libinterposer.dylib
5
6 // BUILD: $CC foo.c -dynamiclib -o $BUILD_DIR/foo34/libfoo2.dylib -install_name $RUN_DIR/libfoo2.dylib
7 // BUILD: $CC foo.c -DNO_FOO34 -dynamiclib -o $BUILD_DIR/libfoo2.dylib -install_name $RUN_DIR/libfoo2.dylib
8 // BUILD: $CC main.c -DNO_FOO34 $BUILD_DIR/foo34/libfoo2.dylib -o $BUILD_DIR/interpose-weak-missing.exe
9 // BUILD: $DYLD_ENV_VARS_ENABLE $BUILD_DIR/interpose-weak-missing.exe
10 // BUILD: $CC interposer.c -dynamiclib $BUILD_DIR/foo34/libfoo2.dylib -o $BUILD_DIR/libinterposer2.dylib -install_name libinterposer.dylib
11
12 // BUILD: $SKIP_INSTALL $BUILD_DIR/foo34/libfoo2.dylib
13
14 // RUN: DYLD_INSERT_LIBRARIES=libinterposer.dylib ./interpose-weak-present.exe
15 // RUN: DYLD_INSERT_LIBRARIES=libinterposer2.dylib ./interpose-weak-missing.exe
16
17
18
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <string.h>
22
23 #include "test_support.h"
24
25 extern int foo1();
26 extern int foo2();
27 extern int foo3() __attribute__((weak_import));
28 extern int foo4() __attribute__((weak_import));
29
30 #ifndef NO_FOO34
31 #define MODE "present"
32 #else
33 #define MODE "missing"
34 #endif
35
36 int main(int argc, const char* argv[], const char* envp[], const char* apple[]) {
37 if ( foo1() != 1 ) {
38 FAIL(MODE ", foo1() != 1");
39 }
40
41 if ( foo2() != 12 ) {
42 FAIL(MODE ", foo2() != 12");
43 }
44
45 #ifndef NO_FOO34
46 if ( foo3() != 3 ) {
47 FAIL(MODE ", foo3() != 3");
48 }
49
50 if ( foo4() != 14 ) {
51 FAIL(MODE ", foo4() != 14");
52 }
53 #else
54 if ( &foo3 != NULL ) {
55 FAIL(MODE ", &foo3 != NULL");
56 }
57
58 if ( &foo4 != NULL ) {
59 FAIL(MODE ", &foo4 != NULL");
60 }
61 #endif
62
63 PASS("Success");
64 }