]> git.saurik.com Git - apple/dyld.git/blob - testing/test-cases/NSAddressOfSymbol-basic.dtest/main.c
dyld-750.6.tar.gz
[apple/dyld.git] / testing / test-cases / NSAddressOfSymbol-basic.dtest / main.c
1 // BUILD_ONLY: MacOSX
2
3 // BUILD: $CC main.c -o $BUILD_DIR/NSAddressOfSymbol-basic.exe -Wno-deprecated-declarations
4
5 // RUN: ./NSAddressOfSymbol-basic.exe
6
7
8
9 #include <stdio.h>
10 #include <string.h>
11 #include <dlfcn.h>
12 #include <mach-o/dyld.h>
13
14 #include "test_support.h"
15
16 extern struct mach_header __dso_handle;
17
18 int main(int argc, const char* argv[], const char* envp[], const char* apple[]) {
19 NSSymbol sym = NSLookupSymbolInImage(&__dso_handle, "_main", NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR);
20 if ( sym == NULL ) {
21 FAIL("can't find main");
22 }
23 void* mainAddr = NSAddressOfSymbol(sym);
24 if ( mainAddr != &main ) {
25 FAIL("address returned %p is not &main=%p", mainAddr, &main);
26 }
27
28 // verify NULL works
29 if ( NSAddressOfSymbol(NULL) != NULL ) {
30 FAIL("NULL not handle");
31 }
32
33 PASS("Success");
34 }
35