]> git.saurik.com Git - apple/dyld.git/blob - testing/test-cases/env-DYLD_LIBRARY_PATH-cache.dtest/main.c
dyld-732.8.tar.gz
[apple/dyld.git] / testing / test-cases / env-DYLD_LIBRARY_PATH-cache.dtest / main.c
1
2 // BUILD: mkdir -p $BUILD_DIR/override
3 // BUILD: mkdir -p $BUILD_DIR/re-export-override
4 // BUILD: $CC myzlib.c -dynamiclib -o $BUILD_DIR/override/libz.1.dylib -install_name /usr/lib/libz.1.dylib -compatibility_version 1.0 -framework CoreFoundation
5 // BUILD: $CC reexported-myzlib.c -dynamiclib -o $BUILD_DIR/re-export-override/reexported.dylib -compatibility_version 1.0 -framework CoreFoundation -install_name $RUN_DIR/re-export-override/reexported.dylib
6 // BUILD: $CC reexporter.c -dynamiclib -o $BUILD_DIR/re-export-override/libz.1.dylib -install_name /usr/lib/libz.1.dylib -compatibility_version 1.0 -Wl,-reexport_library,$BUILD_DIR/re-export-override/reexported.dylib -Wl,-debug_variant
7 // BUILD: $CC main.c -o $BUILD_DIR/env-DYLD_LIBRARY_PATH-cache.exe -lz
8 // BUILD: $DYLD_ENV_VARS_ENABLE $BUILD_DIR/env-DYLD_LIBRARY_PATH-cache.exe
9
10 // RUN: ./env-DYLD_LIBRARY_PATH-cache.exe
11 // RUN: DYLD_LIBRARY_PATH=$RUN_DIR/override/ ./env-DYLD_LIBRARY_PATH-cache.exe
12 // RUN: DYLD_LIBRARY_PATH=$RUN_DIR/re-export-override/ ./env-DYLD_LIBRARY_PATH-cache.exe
13
14 #include <stdio.h>
15 #include <stdlib.h>
16 #include <string.h>
17 #include <zlib.h>
18 #include <stdbool.h>
19 #include <mach-o/dyld_priv.h>
20
21 // The test here is to override libz.1.dylib which is in the dyld cache with our own implementation.
22
23 int main()
24 {
25 bool expectMyDylib = (getenv("DYLD_LIBRARY_PATH") != NULL) && !_dyld_shared_cache_optimized();
26
27 printf("[BEGIN] env-DYLD_LIBRARY_PATH-cache, %s\n", expectMyDylib ? "my" : "os");
28
29 bool usingMyDylib = (strcmp(zlibVersion(), "my") == 0);
30
31 if ( usingMyDylib == expectMyDylib )
32 printf("[PASS] env-DYLD_LIBRARY_PATH-cache, %s\n", expectMyDylib ? "my" : "os");
33 else
34 printf("[FAIL] env-DYLD_LIBRARY_PATH-cache, %s\n", expectMyDylib ? "my" : "os");
35
36 return 0;
37 }
38