mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-22 16:33:29 +00:00
Added test for properties.
Richard: I've probably put this in a slightly silly place - feel free to move it. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@32340 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
c0c5b77bc8
commit
d03e9a18b3
1 changed files with 110 additions and 0 deletions
110
Tests/base/Functions/properties.m
Normal file
110
Tests/base/Functions/properties.m
Normal file
|
@ -0,0 +1,110 @@
|
|||
#import "Testing.h"
|
||||
#ifndef OBJC_NEW_PROPERTIES
|
||||
int main(void)
|
||||
{
|
||||
unsupported("Your compiler does not support declared properties");
|
||||
return 0;
|
||||
}
|
||||
#else
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@interface A : NSObject
|
||||
{
|
||||
@private
|
||||
NSObject *n;
|
||||
NSObject *a;
|
||||
}
|
||||
@property (nonatomic,readwrite,retain) NSObject *n;
|
||||
@property (readwrite,retain) NSObject *a;
|
||||
@end
|
||||
|
||||
@implementation A
|
||||
- (NSObject *)n
|
||||
{
|
||||
return [[n retain] autorelease];
|
||||
}
|
||||
- (void)setN:(NSObject *)newN
|
||||
{
|
||||
if (n != newN)
|
||||
{
|
||||
[n release];
|
||||
n = [newN retain];
|
||||
}
|
||||
}
|
||||
- (NSObject *)a
|
||||
{
|
||||
return [[a retain] autorelease];
|
||||
}
|
||||
- (void)setA:(NSObject *)newA
|
||||
{
|
||||
@synchronized(self)
|
||||
{
|
||||
if (a != newA)
|
||||
{
|
||||
[a release];
|
||||
a = [newA retain];
|
||||
}
|
||||
}
|
||||
}
|
||||
- (void)dealloc
|
||||
{
|
||||
[a release];
|
||||
[n release];
|
||||
[super dealloc];
|
||||
}
|
||||
@end
|
||||
@interface B : NSObject
|
||||
// If we've got non-fragile ABI support, try not declaring the ivars
|
||||
#if !__has_feature(objc_nonfragile_abi)
|
||||
{
|
||||
id a, b, c, d;
|
||||
}
|
||||
#endif
|
||||
@property (nonatomic,readwrite,retain) NSObject *a;
|
||||
@property (readwrite,retain) NSObject *b;
|
||||
@property (nonatomic,readwrite,copy) NSObject *c;
|
||||
@property (readwrite,copy) NSObject *d;
|
||||
@end
|
||||
@implementation B
|
||||
@synthesize a,b,c,d;
|
||||
- (void)dealloc
|
||||
{
|
||||
[a release];
|
||||
[b release];
|
||||
[c release];
|
||||
[d release];
|
||||
[super dealloc];
|
||||
}
|
||||
@end
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
id testObject = [@"str" mutableCopy];
|
||||
|
||||
A *a = [[A alloc] init];
|
||||
// Note: use of dot syntax here is only for testing purposes. This case -
|
||||
// in the test suite and outside of the main code - does not invoke
|
||||
// requirement to buy all of the other GNUstep developers a beer.
|
||||
a.a = testObject;
|
||||
PASS(a.a == testObject, "Setting manually created atomic property");
|
||||
a.n = testObject;
|
||||
PASS(a.n == testObject, "Setting manually created nonatomic property");
|
||||
DESTROY(a);
|
||||
B *b = [B new];
|
||||
b.a = testObject;
|
||||
PASS(b.a == testObject, "Setting synthesized atomic property");
|
||||
b.b = testObject;
|
||||
PASS(b.b == testObject, "Setting synthesized nonatomic property");
|
||||
b.c = testObject;
|
||||
PASS(b.c != testObject, "Synthesized nonatomic copy method did not do simple assign");
|
||||
PASS([testObject isEqualToString: b.c], "Synthesized nonatomic copy method did copy");
|
||||
b.d = testObject;
|
||||
PASS(b.d != testObject, "Synthesized atomic copy method did not do simple assign");
|
||||
PASS([testObject isEqualToString: b.d], "Synthesized atomic copy method did copy");
|
||||
[b release];
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
Loading…
Reference in a new issue