dyld-832.7.1.tar.gz
[apple/dyld.git] / testing / test-cases / _dyld_shared_cache_real_path.dtest / main.c
1
2 // BUILD: $CC main.c -o $BUILD_DIR/_dyld_shared_cache_real_path.exe
3
4 // RUN: ./_dyld_shared_cache_real_path.exe
5
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <string.h>
9 #include <mach-o/dyld_priv.h>
10 #include <dlfcn.h>
11
12 #include "test_support.h"
13
14 int main(int argc, const char* argv[], const char* envp[], const char* apple[])
15 {
16 size_t length;
17 bool hasCache = ( _dyld_get_shared_cache_range(&length) != NULL );
18 if ( hasCache ) {
19 const char* path = _dyld_shared_cache_real_path("/usr/lib/libSystem.dylib");
20 if ( path == NULL )
21 FAIL("libSystem.dylib is not in dyld cache");
22 else if ( strcmp(path, "/usr/lib/libSystem.B.dylib") != 0 )
23 FAIL("libSystem.B.dylib != %s", path);
24
25 #if TARGET_OS_OSX
26 // actual path
27 path = _dyld_shared_cache_real_path("/System/Library/Frameworks/Foundation.framework/Versions/C/Foundation");
28 if ( path == NULL )
29 FAIL("Foundation is not in dyld cache");
30 else if ( strcmp(path, "/System/Library/Frameworks/Foundation.framework/Versions/C/Foundation") != 0 )
31 FAIL("Foundation != %s", path);
32
33 // symlink inside the shared cache
34 path = _dyld_shared_cache_real_path("/System/Library/Frameworks/Foundation.framework/Foundation");
35 if ( path == NULL )
36 FAIL("Foundation is not in dyld cache");
37 else if ( strcmp(path, "/System/Library/Frameworks/Foundation.framework/Versions/C/Foundation") != 0 )
38 FAIL("Foundation != %s", path);
39
40 // symlink not in the shared cache (as we don't handle directory symlinks today)
41 path = _dyld_shared_cache_real_path("/System/Library/Frameworks/Foundation.framework/Versions/Current/Foundation");
42 if ( path == NULL )
43 FAIL("Foundation is not in dyld cache");
44 else if ( strcmp(path, "/System/Library/Frameworks/Foundation.framework/Versions/C/Foundation") != 0 )
45 FAIL("Foundation != %s", path);
46 #endif
47 } else {
48 const char* path = _dyld_shared_cache_real_path("/usr/lib/libSystem.B.dylib");
49 if ( path != NULL )
50 FAIL("no cache, but libSystem.B.dylib is in dyld cache");
51 }
52
53 #if 0
54 if ( != hasCache ) {
55 if ( hasCache )
56 FAIL("libSystem.B.dylib is not in dyld cache");
57 else
58 FAIL("no cache, but libSystem.B.dylib is in dyld cache");
59 }
60
61 if ( _dyld_shared_cache_real_path("/System/Library/Frameworks/Foundation.framework/Foundation") != hasCache ) {
62 if ( hasCache )
63 FAIL("Foundation.framework is not in dyld cache");
64 else
65 FAIL("no cache, but Foundation.framework is in dyld cache");
66 }
67
68 #if TARGET_OS_OSX
69 if ( _dyld_shared_cache_real_path("/System/Library/Frameworks/Foundation.framework/Versions/Current/Foundation") != hasCache ) {
70 if ( hasCache )
71 FAIL("Current/Foundation.framework is not in dyld cache");
72 else
73 FAIL("no cache, but Current/Foundation.framework is in dyld cache");
74 }
75 #endif
76
77 #endif
78
79 PASS("SUCCESS");
80 }
81