]> git.saurik.com Git - apple/objc4.git/blob - test/concurrentcat.m
objc4-756.2.tar.gz
[apple/objc4.git] / test / concurrentcat.m
1 /*
2 TEST_BUILD
3 $C{COMPILE} $DIR/concurrentcat.m -o concurrentcat.exe -framework Foundation
4
5 $C{COMPILE} -bundle -bundle_loader concurrentcat.exe -framework Foundation $DIR/concurrentcat_category.m -DTN=cc1 -o cc1.bundle
6 $C{COMPILE} -bundle -bundle_loader concurrentcat.exe -framework Foundation $DIR/concurrentcat_category.m -DTN=cc2 -o cc2.bundle
7 $C{COMPILE} -bundle -bundle_loader concurrentcat.exe -framework Foundation $DIR/concurrentcat_category.m -DTN=cc3 -o cc3.bundle
8 $C{COMPILE} -bundle -bundle_loader concurrentcat.exe -framework Foundation $DIR/concurrentcat_category.m -DTN=cc4 -o cc4.bundle
9 $C{COMPILE} -bundle -bundle_loader concurrentcat.exe -framework Foundation $DIR/concurrentcat_category.m -DTN=cc5 -o cc5.bundle
10 $C{COMPILE} -bundle -bundle_loader concurrentcat.exe -framework Foundation $DIR/concurrentcat_category.m -DTN=cc6 -o cc6.bundle
11 $C{COMPILE} -bundle -bundle_loader concurrentcat.exe -framework Foundation $DIR/concurrentcat_category.m -DTN=cc7 -o cc7.bundle
12 $C{COMPILE} -bundle -bundle_loader concurrentcat.exe -framework Foundation $DIR/concurrentcat_category.m -DTN=cc8 -o cc8.bundle
13 $C{COMPILE} -bundle -bundle_loader concurrentcat.exe -framework Foundation $DIR/concurrentcat_category.m -DTN=cc9 -o cc9.bundle
14 $C{COMPILE} -bundle -bundle_loader concurrentcat.exe -framework Foundation $DIR/concurrentcat_category.m -DTN=cc10 -o cc10.bundle
15 $C{COMPILE} -bundle -bundle_loader concurrentcat.exe -framework Foundation $DIR/concurrentcat_category.m -DTN=cc11 -o cc11.bundle
16 $C{COMPILE} -bundle -bundle_loader concurrentcat.exe -framework Foundation $DIR/concurrentcat_category.m -DTN=cc12 -o cc12.bundle
17 $C{COMPILE} -bundle -bundle_loader concurrentcat.exe -framework Foundation $DIR/concurrentcat_category.m -DTN=cc13 -o cc13.bundle
18 $C{COMPILE} -bundle -bundle_loader concurrentcat.exe -framework Foundation $DIR/concurrentcat_category.m -DTN=cc14 -o cc14.bundle
19 $C{COMPILE} -bundle -bundle_loader concurrentcat.exe -framework Foundation $DIR/concurrentcat_category.m -DTN=cc15 -o cc15.bundle
20 END
21 */
22
23 #include "test.h"
24 #include <objc/runtime.h>
25 #include <objc/objc-auto.h>
26 #include <dlfcn.h>
27 #include <unistd.h>
28 #include <pthread.h>
29 #include <Foundation/Foundation.h>
30
31 @interface TargetClass : NSObject
32 @end
33
34 @interface TargetClass(LoadedMethods)
35 - (void) m0;
36 - (void) m1;
37 - (void) m2;
38 - (void) m3;
39 - (void) m4;
40 - (void) m5;
41 - (void) m6;
42 - (void) m7;
43 - (void) m8;
44 - (void) m9;
45 - (void) m10;
46 - (void) m11;
47 - (void) m12;
48 - (void) m13;
49 - (void) m14;
50 - (void) m15;
51 @end
52
53 @implementation TargetClass
54 - (void) m0 { fail("shoulda been loaded!"); }
55 - (void) m1 { fail("shoulda been loaded!"); }
56 - (void) m2 { fail("shoulda been loaded!"); }
57 - (void) m3 { fail("shoulda been loaded!"); }
58 - (void) m4 { fail("shoulda been loaded!"); }
59 - (void) m5 { fail("shoulda been loaded!"); }
60 - (void) m6 { fail("shoulda been loaded!"); }
61 @end
62
63 void *threadFun(void *aTargetClassName) {
64 const char *className = (const char *)aTargetClassName;
65
66 PUSH_POOL {
67
68 Class targetSubclass = objc_getClass(className);
69 testassert(targetSubclass);
70
71 id target = [targetSubclass new];
72 testassert(target);
73
74 while(1) {
75 [target m0];
76 RETAIN(target);
77 [target addObserver: target forKeyPath: @"m3" options: 0 context: NULL];
78 [target addObserver: target forKeyPath: @"m4" options: 0 context: NULL];
79 [target m1];
80 RELEASE_VALUE(target);
81 [target m2];
82 AUTORELEASE(target);
83 [target m3];
84 RETAIN(target);
85 [target removeObserver: target forKeyPath: @"m4"];
86 [target addObserver: target forKeyPath: @"m5" options: 0 context: NULL];
87 [target m4];
88 RETAIN(target);
89 [target m5];
90 AUTORELEASE(target);
91 [target m6];
92 [target m7];
93 [target m8];
94 [target m9];
95 [target m10];
96 [target m11];
97 [target m12];
98 [target m13];
99 [target m14];
100 [target m15];
101 [target removeObserver: target forKeyPath: @"m3"];
102 [target removeObserver: target forKeyPath: @"m5"];
103 }
104 } POP_POOL;
105 return NULL;
106 }
107
108 int main()
109 {
110 int i;
111
112 void *dylib;
113
114 for(i=1; i<16; i++) {
115 pthread_t t;
116 char dlName[100];
117 sprintf(dlName, "cc%d.bundle", i);
118 dylib = dlopen(dlName, RTLD_LAZY);
119 char className[100];
120 sprintf(className, "cc%d", i);
121 pthread_create(&t, NULL, threadFun, strdup(className));
122 testassert(dylib);
123 }
124 sleep(1);
125
126 succeed(__FILE__);
127 }