2014-01-06 11:32:39 +00:00
|
|
|
#import "Testing.h"
|
|
|
|
#import <Foundation/NSAutoreleasePool.h>
|
|
|
|
#import <Foundation/NSObject.h>
|
|
|
|
#import <Foundation/NSString.h>
|
|
|
|
|
|
|
|
/* Only do associated objects test if they are supported by the runtime.
|
|
|
|
*/
|
2015-05-26 10:05:51 +00:00
|
|
|
#if OBJC2RUNTIME && defined(OBJC_ASSOCIATION_RETAIN)
|
2014-01-06 11:32:39 +00:00
|
|
|
|
|
|
|
static BOOL AssociatedObjectDeallocCalled = NO;
|
|
|
|
static const char* objc_setAssociatedObjectKey = "objc_setAssociatedObjectKey";
|
|
|
|
|
|
|
|
@interface associatedObjectTestAssociatedObject : NSObject
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation associatedObjectTestAssociatedObject
|
|
|
|
|
|
|
|
- (void) dealloc
|
|
|
|
{
|
|
|
|
AssociatedObjectDeallocCalled = YES;
|
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
@interface associatedObjectTestAllocatedObject : NSObject
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation associatedObjectTestAllocatedObject
|
|
|
|
@end
|
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
|
|
|
associatedObjectTestAllocatedObject* object =
|
|
|
|
[associatedObjectTestAllocatedObject new];
|
|
|
|
|
|
|
|
associatedObjectTestAssociatedObject *info =
|
2014-01-07 10:37:20 +00:00
|
|
|
[associatedObjectTestAssociatedObject new];
|
2014-01-06 11:32:39 +00:00
|
|
|
objc_setAssociatedObject(object, &objc_setAssociatedObjectKey, info,
|
|
|
|
OBJC_ASSOCIATION_RETAIN);
|
2014-01-07 10:37:20 +00:00
|
|
|
[info release];
|
2014-01-06 11:32:39 +00:00
|
|
|
[object release];
|
|
|
|
|
|
|
|
PASS(AssociatedObjectDeallocCalled == YES,
|
|
|
|
"'objc_setAssociatedObject' was released");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
|
|
|
return 0; // Nothing to test
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|