9 objc_AssociationPolicy sawPolicy;
11 objc_hook_setAssociatedObject originalSetAssociatedObject;
13 void hook(id _Nonnull object, const void * _Nonnull key, id _Nullable value, objc_AssociationPolicy policy) {
18 originalSetAssociatedObject(object, key, value, policy);
22 id obj = [TestRoot new];
23 id value = [TestRoot new];
24 const void *key = "key";
25 objc_setAssociatedObject(obj, key, value, OBJC_ASSOCIATION_RETAIN);
26 testassert(sawObject == nil);
27 testassert(sawKey == nil);
28 testassert(sawValue == nil);
29 testassert(sawPolicy == 0);
31 id out = objc_getAssociatedObject(obj, key);
32 testassert(out == value);
34 objc_setHook_setAssociatedObject(hook, &originalSetAssociatedObject);
37 objc_setAssociatedObject(obj, key, value, OBJC_ASSOCIATION_RETAIN);
38 testassert(sawObject == obj);
39 testassert(sawKey == key);
40 testassert(sawValue == value);
41 testassert(sawPolicy == OBJC_ASSOCIATION_RETAIN);
43 out = objc_getAssociatedObject(obj, key);
44 testassert(out == value);