]> git.saurik.com Git - apple/dyld.git/blob - testing/test-cases/dyld-insert-library-double.dtest/main.cpp
dyld-750.5.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: $CXX 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 #include "test_support.h"
20
21 bool gFoundLibrary = false;
22 const char* gLibraryName = NULL;
23
24 bool wasImageLoaded(const char* libraryName) {
25 gFoundLibrary = false;
26 gLibraryName = libraryName;
27 _dyld_register_for_image_loads([](const mach_header* mh, const char* path, bool unloadable) {
28 if ( strstr(path, gLibraryName) != NULL ) {
29 gFoundLibrary = true;
30 }
31 });
32 if (!gFoundLibrary)
33 FAIL("Expected insert to pass for '%s'", libraryName);
34 return gFoundLibrary;
35 }
36
37 int main(int argc, const char* argv[], const char* envp[], const char* apple[]) {
38 if (!wasImageLoaded("libfoo.dylib") || !wasImageLoaded("libbar.dylib")) {
39 return 0;
40 }
41
42 PASS("Success");
43 }