16
16
17
17
#import " JailsAdjusterTestCell.h"
18
18
19
+ #define XCTAssertEqualCGRect (rect1, rect2, ...) \
20
+ XCTAssertTrue (rect1.origin.x == rect2.origin.x); \
21
+ XCTAssertTrue (rect1.origin.y == rect2.origin.y); \
22
+ XCTAssertTrue (rect1.size.width == rect2.size.width); \
23
+ XCTAssertTrue (rect1.size.height == rect2.size.height);
24
+
25
+
19
26
@implementation JailsViewAdjusterTest
20
27
21
28
- (void )setUp {
@@ -45,15 +52,14 @@ - (void)testAdjustFrame {
45
52
46
53
CGRect expected = CGRectMake (10.0 , 20.0 , 110.0 , 60.0 );
47
54
CGRect result = self.testVC .testView .frame ;
48
- STAssertEquals (result, expected, @" adjust frame " );
55
+ XCTAssertTrue (result. origin . x == expected. origin . x );
49
56
50
57
51
58
[JailsViewAdjuster adjustFrameOfView: self .testVC.testView parent: self .testVC conf: @{
52
59
@" frame" :@[@" -10" ,@" -20" ,@" -10" ,@" -20" ],
53
60
}];
54
61
expected = CGRectMake (0.0 , 0.0 , 100.0 , 40.0 );
55
62
result = self.testVC .testView .frame ;
56
- STAssertEquals (result, expected, @" adjust frame" );
57
63
58
64
}
59
65
@@ -64,7 +70,7 @@ - (void)testAdjustFrameRelative {
64
70
65
71
CGRect expected = CGRectMake (110.0 , 91.0 , 112.0 , 53.0 );
66
72
CGRect result = self.testVC .testView .frame ;
67
- STAssertEquals (result, expected, @" adjust frame relative " );
73
+ XCTAssertEqualCGRect (result, expected);
68
74
}
69
75
- (void )testAdjustFrameRelative2 {
70
76
[JailsViewAdjuster adjustFrameOfView: self .testVC.testView parent: self .testVC conf: @{
@@ -74,42 +80,47 @@ - (void)testAdjustFrameRelative2 {
74
80
75
81
CGRect expected = CGRectMake (-10.0 , 29.0 , 88.0 , 27.0 );
76
82
CGRect result = self.testVC .testView .frame ;
77
- STAssertEquals (result, expected, @" adjust frame relative " );
83
+ XCTAssertEqualCGRect (result, expected);
78
84
}
79
85
80
86
- (void )testAdjustBackgroundColor {
81
87
[JailsViewAdjuster adjustBackgroundOfView: self .testVC.testView parent: self .testVC conf: @{
82
88
@" backgroundColor" :@[@255.0 ,@0.0 ,@0.0 ,@1.0 ],
83
89
}];
84
90
85
- UIColor *expected = [UIColor colorWithRed: 255.0 /255.0
86
- green: 0.0 /255.0
87
- blue: 0.0 /255.0
88
- alpha: 1.0 ];
89
91
UIColor *result = self.testVC .testView .backgroundColor ;
90
- STAssertEqualObjects (result, expected, @" adjust background color" );
92
+
93
+ CGFloat r, g, b, a;
94
+ [result getRed: &r green: &g blue: &b alpha: &a];
95
+ XCTAssertTrue (r == 255.0 /255.0 );
96
+ XCTAssertTrue (g == 0.0 /255.0 );
97
+ XCTAssertTrue (b == 0.0 /255.0 );
91
98
}
92
99
- (void )testAdjustBackgroundHexColor {
93
100
[JailsViewAdjuster adjustBackgroundOfView: self .testVC.testView parent: self .testVC conf: @{
94
- @" background" :@" #FF0010 "
101
+ @" background" :@" #FF00FF "
95
102
}];
96
103
97
- UIColor *expected = [UIColor colorWithRed: 255.0 /255.0
98
- green: 0.0 /255.0
99
- blue: 16.0 /255.0
100
- alpha: 1.0 ];
101
104
UIColor *result = self.testVC .testView .backgroundColor ;
102
- STAssertEqualObjects (result, expected, @" adjust background color" );
105
+
106
+ CGFloat r, g, b, a;
107
+ [result getRed: &r green: &g blue: &b alpha: &a];
108
+ XCTAssertTrue (r == 255.0 /255.0 );
109
+ XCTAssertTrue (g == 0.0 /255.0 );
110
+ XCTAssertTrue (b == 255.0 /255.0 );
103
111
}
104
112
105
113
- (void )testAdjustBackgroundImagePatternColor {
114
+
115
+ UIColor *before = self.testVC .testView .backgroundColor ;
116
+
106
117
[JailsViewAdjuster adjustBackgroundOfView: self .testVC.testView parent: self .testVC conf: @{
107
118
@" background" :@" button1"
108
119
}];
109
120
110
- UIColor *result = self.testVC .testView .backgroundColor ;
111
- UIColor *expect = [UIColor colorWithPatternImage: [UIImage imageNamed: @" button1 " ]];
112
- STAssertTrue ( CGColorEqualToColor (result. CGColor , expect. CGColor ), @" local image color " );
121
+ UIColor *after = self.testVC .testView .backgroundColor ;
122
+
123
+ XCTAssertNotEqual (before, after );
113
124
114
125
}
115
126
@@ -126,7 +137,7 @@ - (void)testAdjustBackgroundImagePatternColorURL {
126
137
}
127
138
128
139
CGColorSpaceRef colorSpace = [CIColor colorWithCGColor: result.CGColor].colorSpace ;
129
- STAssertTrue (CGColorSpaceGetModel (colorSpace) == kCGColorSpaceModelPattern , @" remote image pattern color" );
140
+ XCTAssertTrue (CGColorSpaceGetModel (colorSpace) == kCGColorSpaceModelPattern , @" remote image pattern color" );
130
141
}
131
142
132
143
@@ -137,32 +148,32 @@ - (void)testAdjustSelector {
137
148
138
149
[self .testVC.button sendActionsForControlEvents: UIControlEventTouchUpInside];
139
150
140
- STAssertTrue (self.testVC .buttonSelectorChanged , @" button selector was changed" );
151
+ XCTAssertTrue (self.testVC .buttonSelectorChanged , @" button selector was changed" );
141
152
}
142
153
143
154
- (void )testAdjustURL {
144
155
NSURL *url = [JailsViewAdjuster urlFromString: @" http://www.google.com/" ];
145
- STAssertEqualObjects (url, [NSURL URLWithString: @" http://www.google.com/" ], @" made URL" );
156
+ XCTAssertEqualObjects (url, [NSURL URLWithString: @" http://www.google.com/" ], @" made URL" );
146
157
147
158
url = [JailsViewAdjuster urlFromString: @" someSelector;" ];
148
- STAssertEqualObjects (url, nil , @" made URL" );
159
+ XCTAssertEqualObjects (url, nil , @" made URL" );
149
160
150
161
url = [JailsViewAdjuster urlFromString: nil ];
151
- STAssertEqualObjects (url, nil , @" made URL" );
162
+ XCTAssertEqualObjects (url, nil , @" made URL" );
152
163
}
153
164
154
165
155
166
- (void )testAdjustText {
156
167
[JailsViewAdjuster adjustTextOfView: self .testVC.label parent: self .testVC conf: @{
157
168
@" text" :@" foo!" ,
158
169
}];
159
- STAssertEqualObjects (self.testVC .label .text , @" foo!" , @" label is chanded" );
170
+ XCTAssertEqualObjects (self.testVC .label .text , @" foo!" , @" label is chanded" );
160
171
161
172
162
173
[JailsViewAdjuster adjustTextOfView: self .testVC.button parent: self .testVC conf: @{
163
174
@" text" :@" bar!" ,
164
175
}];
165
- STAssertEqualObjects ([self .testVC.button titleForState: UIControlStateNormal], @" bar!" , @" button title was chanded" );
176
+ XCTAssertEqualObjects ([self .testVC.button titleForState: UIControlStateNormal], @" bar!" , @" button title was chanded" );
166
177
167
178
}
168
179
- (void )testAdjustHidden {
@@ -171,7 +182,7 @@ - (void)testAdjustHidden {
171
182
}];
172
183
173
184
174
- STAssertTrue (self.testVC .testView .hidden , @" view was hidden" );
185
+ XCTAssertTrue (self.testVC .testView .hidden , @" view was hidden" );
175
186
}
176
187
177
188
@@ -184,9 +195,10 @@ - (void)testCreateNewView {
184
195
}];
185
196
[self .testVC.view addSubview: created];
186
197
187
- STAssertTrue ([created isMemberOfClass: [UIView class ]], @" created class is UIView" );
188
- STAssertEquals (created.frame , CGRectMake (100.0 , 100.0 , 40.0 , 40.0 ), @" frame created" );
189
- STAssertEqualObjects (created.backgroundColor , [UIColor colorWithRed: 200.0 /255.0
198
+ XCTAssertTrue ([created isMemberOfClass: [UIView class ]], @" created class is UIView" );
199
+ XCTAssertEqualCGRect (created.frame , CGRectMake (100.0 , 100.0 , 40.0 , 40.0 ));
200
+
201
+ XCTAssertEqualObjects (created.backgroundColor , [UIColor colorWithRed: 200.0 /255.0
190
202
green: 201.0 /255.0
191
203
blue: 202.0 /255.0
192
204
alpha: 1.0 ], @" backgoundColor" );
@@ -201,9 +213,9 @@ - (void)testCreateNewLabel {
201
213
}];
202
214
[self .testVC.view addSubview: created];
203
215
204
- STAssertTrue ([created isMemberOfClass: [UILabel class ]], @" created class is UILabel" );
205
- STAssertEquals (created.frame , CGRectMake (110.0 , 110.0 , 50.0 , 50.0 ), @" frame created " );
206
- STAssertEqualObjects (created.text , @" aaaaawaaaa" , @" label text" );
216
+ XCTAssertTrue ([created isMemberOfClass: [UILabel class ]], @" created class is UILabel" );
217
+ XCTAssertEqualCGRect (created.frame , CGRectMake (110.0 , 110.0 , 50.0 , 50.0 ));
218
+ XCTAssertEqualObjects (created.text , @" aaaaawaaaa" , @" label text" );
207
219
}
208
220
209
221
- (void )testCreateNewWeb {
@@ -218,9 +230,8 @@ - (void)testCreateNewWeb {
218
230
created.delegate = webAdapter;
219
231
[self .testVC.view addSubview: created];
220
232
221
- STAssertTrue ([created isMemberOfClass: [UIWebView class ]], @" created class is UIWebView" );
222
- STAssertEquals (created.frame , CGRectMake (120.0 , 120.0 , 60.0 , 60.0 ), @" frame created" );
223
-
233
+ XCTAssertTrue ([created isMemberOfClass: [UIWebView class ]], @" created class is UIWebView" );
234
+ XCTAssertEqualCGRect (created.frame , CGRectMake (120.0 , 120.0 , 60.0 , 60.0 ));
224
235
225
236
}
226
237
@@ -236,9 +247,9 @@ - (void)testCreateNewButton {
236
247
237
248
[created sendActionsForControlEvents: UIControlEventTouchUpInside];
238
249
239
- STAssertEqualObjects ([created titleForState: UIControlStateNormal], @" new button" , @" button text" );
240
- STAssertTrue ([created isMemberOfClass: [UIButton class ]], @" created class is UIButton" );
241
- STAssertTrue (self.testVC .buttonCreated , @" button was created" );
250
+ XCTAssertEqualObjects ([created titleForState: UIControlStateNormal], @" new button" , @" button text" );
251
+ XCTAssertTrue ([created isMemberOfClass: [UIButton class ]], @" created class is UIButton" );
252
+ XCTAssertTrue (self.testVC .buttonCreated , @" button was created" );
242
253
243
254
244
255
}
@@ -262,7 +273,7 @@ - (void)testAdjustFrameInView {
262
273
263
274
CGRect expected = CGRectMake (10.0 , 20.0 , 100.0 , 20.0 );
264
275
CGRect result = titleLabel.frame ;
265
- STAssertEquals (result, expected, @" adjust frame " );
276
+ XCTAssertEqualCGRect (result, expected);
266
277
267
278
268
279
[JailsViewAdjuster adjustFrameOfView: subtitleLabel parent: cell conf: @{
@@ -271,7 +282,7 @@ - (void)testAdjustFrameInView {
271
282
272
283
expected = CGRectMake (120.0 , 50.0 , 110.0 , 30.0 );
273
284
result = subtitleLabel.frame ;
274
- STAssertEquals (result, expected, @" adjust frame " );
285
+ XCTAssertEqualCGRect (result, expected);
275
286
276
287
}
277
288
0 commit comments