]> git.saurik.com Git - apple/objc4.git/blob - test/load-image-notification.m
objc4-818.2.tar.gz
[apple/objc4.git] / test / load-image-notification.m
1 /*
2 TEST_BUILD
3 $C{COMPILE} -DCLASSNAME=Class1 $DIR/load-image-notification-dylib.m -o load-image-notification1.dylib -dynamiclib
4 $C{COMPILE} -DCLASSNAME=Class2 $DIR/load-image-notification-dylib.m -o load-image-notification2.dylib -dynamiclib
5 $C{COMPILE} -DCLASSNAME=Class3 $DIR/load-image-notification-dylib.m -o load-image-notification3.dylib -dynamiclib
6 $C{COMPILE} -DCLASSNAME=Class4 $DIR/load-image-notification-dylib.m -o load-image-notification4.dylib -dynamiclib
7 $C{COMPILE} -DCLASSNAME=Class5 $DIR/load-image-notification-dylib.m -o load-image-notification5.dylib -dynamiclib
8 $C{COMPILE} $DIR/load-image-notification.m -o load-image-notification.exe
9 END
10 */
11
12 #include "test.h"
13
14 #include <dlfcn.h>
15
16 #define ADD_IMAGE_CALLBACK(n) \
17 int called ## n = 0; \
18 static void add_image ## n(const struct mach_header * mh __unused) { \
19 called ## n++; \
20 }
21
22 ADD_IMAGE_CALLBACK(1)
23 ADD_IMAGE_CALLBACK(2)
24 ADD_IMAGE_CALLBACK(3)
25 ADD_IMAGE_CALLBACK(4)
26 ADD_IMAGE_CALLBACK(5)
27
28 int main()
29 {
30 objc_addLoadImageFunc(add_image1);
31 testassert(called1 > 0);
32 int oldcalled = called1;
33 void *handle = dlopen("load-image-notification1.dylib", RTLD_LAZY);
34 testassert(handle);
35 testassert(called1 > oldcalled);
36
37 objc_addLoadImageFunc(add_image2);
38 testassert(called2 == called1);
39 oldcalled = called1;
40 handle = dlopen("load-image-notification2.dylib", RTLD_LAZY);
41 testassert(handle);
42 testassert(called1 > oldcalled);
43 testassert(called2 == called1);
44
45 objc_addLoadImageFunc(add_image3);
46 testassert(called3 == called1);
47 oldcalled = called1;
48 handle = dlopen("load-image-notification3.dylib", RTLD_LAZY);
49 testassert(handle);
50 testassert(called1 > oldcalled);
51 testassert(called2 == called1);
52 testassert(called3 == called1);
53
54 objc_addLoadImageFunc(add_image4);
55 testassert(called4 == called1);
56 oldcalled = called1;
57 handle = dlopen("load-image-notification4.dylib", RTLD_LAZY);
58 testassert(handle);
59 testassert(called1 > oldcalled);
60 testassert(called2 == called1);
61 testassert(called3 == called1);
62 testassert(called4 == called1);
63
64 objc_addLoadImageFunc(add_image5);
65 testassert(called5 == called1);
66 oldcalled = called1;
67 handle = dlopen("load-image-notification5.dylib", RTLD_LAZY);
68 testassert(handle);
69 testassert(called1 > oldcalled);
70 testassert(called2 == called1);
71 testassert(called3 == called1);
72 testassert(called4 == called1);
73 testassert(called5 == called1);
74
75 succeed(__FILE__);
76 }