15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
*/
#include "config.h"
#import "OFString.h"
#import "OFAutoreleasePool.h"
#import "TestsAppDelegate.h"
static OFString *module = @"Runtime";
@interface RuntimeTest: OFObject
{
OFString *_foo, *_bar;
}
@property (copy, nonatomic) OFString *foo;
@property (retain) OFString *bar;
@end
@implementation RuntimeTest
@synthesize foo = _foo;
@synthesize bar = _bar;
- (void)dealloc
{
[_foo release];
[_bar release];
[super dealloc];
}
@end
@implementation TestsAppDelegate (RuntimeTests)
- (void)runtimeTests
{
OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
RuntimeTest *rt = [[[RuntimeTest alloc] init] autorelease];
OFString *t = [OFMutableString stringWithString: @"foo"];
OFString *foo = @"foo";
[rt setFoo: t];
TEST(@"copy, nonatomic properties", [[rt foo] isEqual: foo] &&
[rt foo] != foo && [[rt foo] retainCount] == 1)
[rt setBar: t];
TEST(@"retain, atomic properties",
[rt bar] == t && [t retainCount] == 3)
[pool drain];
}
@end
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
|
|
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
*/
#include "config.h"
#import "OFString.h"
#import "OFAutoreleasePool.h"
#import "OFNotImplementedException.h"
#import "TestsAppDelegate.h"
static OFString *module = @"Runtime";
@interface OFObject (SuperTest)
- (id)superTest;
@end
@interface RuntimeTest: OFObject
{
OFString *_foo, *_bar;
}
@property (copy, nonatomic) OFString *foo;
@property (retain) OFString *bar;
- (id)nilSuperTest;
@end
@implementation RuntimeTest
@synthesize foo = _foo;
@synthesize bar = _bar;
- (void)dealloc
{
[_foo release];
[_bar release];
[super dealloc];
}
- (id)superTest
{
return [super superTest];
}
- (id)nilSuperTest
{
self = nil;
return [self superTest];
}
@end
@implementation TestsAppDelegate (RuntimeTests)
- (void)runtimeTests
{
OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
RuntimeTest *rt = [[[RuntimeTest alloc] init] autorelease];
OFString *t, *foo;
EXPECT_EXCEPTION(@"Calling a non-existant method via super",
OFNotImplementedException, [rt superTest])
TEST(@"Calling a method via a super with self == nil",
[rt nilSuperTest] == nil)
t = [OFMutableString stringWithString: @"foo"];
foo = @"foo";
[rt setFoo: t];
TEST(@"copy, nonatomic properties", [[rt foo] isEqual: foo] &&
[rt foo] != foo && [[rt foo] retainCount] == 1)
[rt setBar: t];
TEST(@"retain, atomic properties",
[rt bar] == t && [t retainCount] == 3)
[pool drain];
}
@end
|