dyld-832.7.1.tar.gz
[apple/dyld.git] / testing / test-cases / NSLookupSymbolInImage-basic.dtest / main.c
1 // BUILD(macos): $CC main.c -o $BUILD_DIR/NSLookupSymbolInImage-basic.exe -Wno-deprecated-declarations
2
3 // BUILD(ios,tvos,watchos,bridgeos):
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 #include "test_support.h"
14
15 extern struct mach_header __dso_handle;
16
17 int main(int argc, const char* argv[], const char* envp[], const char* apple[]) {
18 // verify known symbol works
19 NSSymbol sym = NSLookupSymbolInImage(&__dso_handle, "_main", NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR);
20 if ( sym == NULL ) {
21 FAIL("Did not find symnbol _main");
22 }
23
24 // verify mode where NSLookupSymbolInImage() returns NULL if symbol not found
25 sym = NSLookupSymbolInImage(&__dso_handle, "_42hhg", NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR);
26 if ( sym != NULL ) {
27 FAIL("Did not find symnbol _42hhg");
28 }
29
30 // Note: NSLookupSymbolInImage is documented to abort if symbol not found and NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR not used,
31 // but dyld 2 just returned NULL, so no need to test that.
32
33 PASS("Success");
34 }
35