dyld-732.8.tar.gz
[apple/dyld.git] / testing / test-cases / dyld-insert-library-double.dtest / main.cpp
1
2 // BOOT_ARGS: dyld_flags=2
3
4 // BUILD: $CC main.cpp -std=c++11 -o $BUILD_DIR/double_insert_main.exe
5 // BUILD: $CC foo.c -dynamiclib -install_name $RUN_DIR/libfoo.dylib -o $BUILD_DIR/libfoo.dylib
6 // BUILD: $CC bar.c -dynamiclib -install_name $RUN_DIR/libbar.dylib -o $BUILD_DIR/libbar.dylib
7 // BUILD: $DYLD_ENV_VARS_ENABLE $BUILD_DIR/double_insert_main.exe
8
9 // Load foo and bar at the same time to ensure that paths separated by ':'' are working
10
11 // RUN: DYLD_INSERT_LIBRARIES="$RUN_DIR/libfoo.dylib:$RUN_DIR/libbar.dylib" ./double_insert_main.exe
12
13 #include <stdlib.h>
14 #include <stdio.h>
15 #include <stdbool.h>
16 #include <string.h>
17 #include <mach-o/dyld_priv.h>
18
19 bool gFoundLibrary = false;
20 const char* gLibraryName = NULL;
21
22 bool wasImageLoaded(const char* libraryName) {
23 gFoundLibrary = false;
24 gLibraryName = libraryName;
25 _dyld_register_for_image_loads([](const mach_header* mh, const char* path, bool unloadable) {
26 if ( strstr(path, gLibraryName) != NULL ) {
27 gFoundLibrary = true;
28 }
29 });
30 if (!gFoundLibrary)
31 printf("[FAIL] dyld-insert-library-double: expected insert to pass for '%s'\n", libraryName);
32 return gFoundLibrary;
33 }
34
35 int main()
36 {
37 printf("[BEGIN] dyld-insert-library-double\n");
38
39 if (!wasImageLoaded("libfoo.dylib") || !wasImageLoaded("libbar.dylib")) {
40 return 0;
41 }
42
43 printf("[PASS] dyld-insert-library-double\n");
44
45 return 0;
46 }