]> git.saurik.com Git - apple/objc4.git/blob - test/associationForbidden.h
objc4-756.2.tar.gz
[apple/objc4.git] / test / associationForbidden.h
1 #include "testroot.i"
2
3 @interface Normal : TestRoot
4 @end
5 @implementation Normal
6 @end
7
8 @interface Forbidden : TestRoot
9 @end
10 @implementation Forbidden
11 @end
12
13 struct minimal_unrealized_class {
14 void *isa;
15 void *superclass;
16 void *cachePtr;
17 uintptr_t maskAndOccupied;
18 struct minimal_class_ro *ro;
19 };
20
21 struct minimal_class_ro {
22 uint32_t flags;
23 };
24
25 extern struct minimal_unrealized_class OBJC_CLASS_$_Forbidden;
26
27 #define RO_FORBIDS_ASSOCIATED_OBJECTS (1<<10)
28
29 static void *key = &key;
30
31 static void test(void);
32
33 int main()
34 {
35 struct minimal_unrealized_class *localForbidden = &OBJC_CLASS_$_Forbidden;
36 localForbidden->ro->flags |= RO_FORBIDS_ASSOCIATED_OBJECTS;
37 test();
38 }
39
40 static inline void ShouldSucceed(id obj) {
41 objc_setAssociatedObject(obj, key, obj, OBJC_ASSOCIATION_ASSIGN);
42 id assoc = objc_getAssociatedObject(obj, key);
43 fprintf(stderr, "Associated object is %p\n", assoc);
44 testassert(obj == assoc);
45 }
46
47 static inline void ShouldFail(id obj) {
48 objc_setAssociatedObject(obj, key, obj, OBJC_ASSOCIATION_ASSIGN);
49 fail("should have crashed trying to set the associated object");
50 }