mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-22 16:33:29 +00:00
add test for release of associated objects
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@37541 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
955bf169c2
commit
9fbd816b5a
1 changed files with 58 additions and 0 deletions
58
Tests/base/NSObject/test03.m
Normal file
58
Tests/base/NSObject/test03.m
Normal file
|
@ -0,0 +1,58 @@
|
|||
#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.
|
||||
*/
|
||||
#if defined(OBJC_ASSOCIATION_RETAIN)
|
||||
|
||||
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()
|
||||
{
|
||||
NSAutoreleasePool *arp = [NSAutoreleasePool new];
|
||||
associatedObjectTestAllocatedObject* object =
|
||||
[associatedObjectTestAllocatedObject new];
|
||||
|
||||
associatedObjectTestAssociatedObject *info =
|
||||
[[associatedObjectTestAssociatedObject new] autorelease];
|
||||
// silence -Wunused-variable
|
||||
[info description];
|
||||
objc_setAssociatedObject(object, &objc_setAssociatedObjectKey, info,
|
||||
OBJC_ASSOCIATION_RETAIN);
|
||||
[object release];
|
||||
|
||||
PASS(AssociatedObjectDeallocCalled == YES,
|
||||
"'objc_setAssociatedObject' was released");
|
||||
return 0;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
int main()
|
||||
{
|
||||
return 0; // Nothing to test
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Reference in a new issue