]> git.saurik.com Git - apple/dyld.git/blob - testing/test-cases/NSLookupSymbolInImage-basic.dtest/main.c
dyld-733.6.tar.gz
[apple/dyld.git] / testing / test-cases / NSLookupSymbolInImage-basic.dtest / main.c
1 // BUILD_ONLY: MacOSX
2
3 // BUILD: $CC main.c -o $BUILD_DIR/NSLookupSymbolInImage-basic.exe -Wno-deprecated-declarations
4
5 // RUN: ./NSLookupSymbolInImage-basic.exe
6
7
8 #include <stdio.h>
9 #include <string.h>
10 #include <dlfcn.h>
11 #include <mach-o/dyld.h>
12
13 extern struct mach_header __dso_handle;
14
15 int main(int argc, const char* argv[])
16 {
17 printf("[BEGIN] NSLookupSymbolInImage-basic\n");
18
19 // verify known symbol works
20 NSSymbol sym = NSLookupSymbolInImage(&__dso_handle, "_main", NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR);
21 if ( sym == NULL ) {
22 printf("[FAIL] NSLookupSymbolInImage-basic _main\n");
23 return 0;
24 }
25
26 // verify mode where NSLookupSymbolInImage() returns NULL if symbol not found
27 sym = NSLookupSymbolInImage(&__dso_handle, "_42hhg", NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR);
28 if ( sym != NULL ) {
29 printf("[FAIL] NSLookupSymbolInImage-basic _42hhg\n");
30 return 0;
31 }
32
33 // Note: NSLookupSymbolInImage is documented to abort if symbol not found and NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR not used,
34 // but dyld 2 just returned NULL, so no need to test that.
35
36 printf("[PASS] NSLookupSymbolInImage-basic\n");
37 return 0;
38 }
39