forked from jspahrsummers/libextobjc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
EXTSynthesizeTest.m
120 lines (87 loc) · 3.48 KB
/
EXTSynthesizeTest.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
//
// EXTSynthesizeTest.m
// extobjc
//
// Created by Justin Spahr-Summers on 2012-09-04.
// Copyright (C) 2012 Justin Spahr-Summers.
// Released under the MIT license.
//
#import "EXTSynthesizeTest.h"
#import "EXTSynthesize.h"
@interface NSObject (EXTSynthesizeTest)
@property (nonatomic, unsafe_unretained) id testNonatomicAssignProperty;
@property (unsafe_unretained) id testAtomicAssignProperty;
@property (nonatomic, strong) id testNonatomicRetainProperty;
@property (strong) id testAtomicRetainProperty;
@property (nonatomic, copy) id testNonatomicCopyProperty;
@property (copy) id testAtomicCopyProperty;
@end
@implementation NSObject (EXTSynthesizeTest)
@synthesizeAssociation(NSObject, testNonatomicAssignProperty);
@synthesizeAssociation(NSObject, testAtomicAssignProperty);
@synthesizeAssociation(NSObject, testNonatomicRetainProperty);
@synthesizeAssociation(NSObject, testAtomicRetainProperty);
@synthesizeAssociation(NSObject, testNonatomicCopyProperty);
@synthesizeAssociation(NSObject, testAtomicCopyProperty);
@end
@implementation EXTSynthesizeTest
- (void)testAssignProperties {
NSObject *owner = [[NSObject alloc] init];
__weak id weakValue = nil;
@autoreleasepool {
id value __attribute__((objc_precise_lifetime)) = [@"foobar" mutableCopy];
weakValue = value;
XCTAssertNotNil(weakValue, @"");
owner.testNonatomicAssignProperty = value;
XCTAssertEqual(owner.testNonatomicAssignProperty, value, @"");
owner.testAtomicAssignProperty = value;
XCTAssertEqual(owner.testAtomicAssignProperty, value, @"");
}
XCTAssertNil(weakValue, @"");
}
- (void)testStrongProperties {
NSObject *owner = [[NSObject alloc] init];
__weak id weakValue = nil;
@autoreleasepool {
id value __attribute__((objc_precise_lifetime)) = [@"foobar" mutableCopy];
weakValue = value;
XCTAssertNotNil(weakValue, @"");
owner.testNonatomicRetainProperty = value;
XCTAssertEqual(owner.testNonatomicRetainProperty, value, @"");
owner.testAtomicRetainProperty = value;
XCTAssertEqual(owner.testAtomicRetainProperty, value, @"");
}
XCTAssertNotNil(weakValue, @"");
XCTAssertEqual(owner.testNonatomicRetainProperty, weakValue, @"");
XCTAssertEqual(owner.testAtomicRetainProperty, weakValue, @"");
}
- (void)testCopyProperties {
NSObject *owner = [[NSObject alloc] init];
__weak id weakValue = nil;
@autoreleasepool {
id value __attribute__((objc_precise_lifetime)) = [@"foobar" mutableCopy];
weakValue = value;
XCTAssertNotNil(weakValue, @"");
owner.testNonatomicCopyProperty = value;
XCTAssertFalse(owner.testNonatomicCopyProperty == value, @"");
XCTAssertEqualObjects(owner.testNonatomicCopyProperty, value, @"");
owner.testAtomicCopyProperty = value;
XCTAssertFalse(owner.testAtomicCopyProperty == value, @"");
XCTAssertEqualObjects(owner.testAtomicCopyProperty, value, @"");
}
XCTAssertNil(weakValue, @"");
XCTAssertEqualObjects(owner.testNonatomicCopyProperty, @"foobar", @"");
XCTAssertEqualObjects(owner.testAtomicCopyProperty, @"foobar", @"");
}
- (void)testMultiplePropertiesUsage {
NSObject *owner = [[NSObject alloc] init];
id value1 = [@"foobar" mutableCopy];
id value2 = [@"bardoo" mutableCopy];
owner.testNonatomicRetainProperty = value1;
XCTAssertEqualObjects(owner.testNonatomicRetainProperty, value1, @"");
owner.testAtomicRetainProperty = value2;
XCTAssertEqualObjects(owner.testAtomicRetainProperty, value2, @"");
XCTAssertEqualObjects(owner.testNonatomicRetainProperty, value1, @"");
XCTAssertEqualObjects(owner.testAtomicRetainProperty, value2, @"");
}
@end