OLD | NEW |
| (Empty) |
1 // | |
2 // GTMSenTestCase.h | |
3 // | |
4 // Copyright 2007-2008 Google Inc. | |
5 // | |
6 // Licensed under the Apache License, Version 2.0 (the "License"); you may not | |
7 // use this file except in compliance with the License. You may obtain a copy | |
8 // of the License at | |
9 // | |
10 // http://www.apache.org/licenses/LICENSE-2.0 | |
11 // | |
12 // Unless required by applicable law or agreed to in writing, software | |
13 // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | |
14 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | |
15 // License for the specific language governing permissions and limitations unde
r | |
16 // the License. | |
17 // | |
18 | |
19 // Portions of this file fall under the following license, marked with | |
20 // SENTE_BEGIN - SENTE_END | |
21 // | |
22 // Copyright (c) 1997-2005, Sen:te (Sente SA). All rights reserved. | |
23 // | |
24 // Use of this source code is governed by the following license: | |
25 // | |
26 // Redistribution and use in source and binary forms, with or without modificati
on, | |
27 // are permitted provided that the following conditions are met: | |
28 // | |
29 // (1) Redistributions of source code must retain the above copyright notice, | |
30 // this list of conditions and the following disclaimer. | |
31 // | |
32 // (2) Redistributions in binary form must reproduce the above copyright notice,
| |
33 // this list of conditions and the following disclaimer in the documentation | |
34 // and/or other materials provided with the distribution. | |
35 // | |
36 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
| |
37 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMP
LIED | |
38 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLA
IMED. | |
39 // IN NO EVENT SHALL Sente SA OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT
, INCIDENTAL, | |
40 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT | |
41 // OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS I
NTERRUPTION) | |
42 // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LI
ABILITY, | |
43 // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, | |
44 // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
45 // | |
46 // Note: this license is equivalent to the FreeBSD license. | |
47 // | |
48 // This notice may not be removed from this file. | |
49 | |
50 // Some extra test case macros that would have been convenient for SenTestingKit
| |
51 // to provide. I didn't stick GTM in front of the Macro names, so that they woul
d | |
52 // be easy to remember. | |
53 | |
54 #import "GTMDefines.h" | |
55 | |
56 #if (!GTM_IPHONE_SDK) | |
57 #import <SenTestingKit/SenTestingKit.h> | |
58 #else | |
59 #import <Foundation/Foundation.h> | |
60 NSString *STComposeString(NSString *, ...); | |
61 #endif | |
62 | |
63 // Generates a failure when a1 != noErr | |
64 // Args: | |
65 // a1: should be either an OSErr or an OSStatus | |
66 // description: A format string as in the printf() function. Can be nil or | |
67 // an empty string but must be present. | |
68 // ...: A variable number of arguments to the format string. Can be absent. | |
69 #define STAssertNoErr(a1, description, ...) \ | |
70 do { \ | |
71 @try {\ | |
72 OSStatus a1value = (a1); \ | |
73 if (a1value != noErr) { \ | |
74 NSString *_expression = [NSString stringWithFormat:@"Expected noErr, got %
ld for (%s)", a1value, #a1]; \ | |
75 if (description) { \ | |
76 _expression = [NSString stringWithFormat:@"%@: %@", _expression, STCompo
seString(description, ##__VA_ARGS__)]; \ | |
77 } \ | |
78 [self failWithException:[NSException failureInFile:[NSString stringWithUTF
8String:__FILE__] \ | |
79 atLine:__LINE__ \ | |
80 withDescription:_expression]]; \ | |
81 } \ | |
82 }\ | |
83 @catch (id anException) {\ | |
84 [self failWithException:[NSException failureInRaise:[NSString stringWithForm
at:@"(%s) == noErr fails", #a1] \ | |
85 exception:anException \ | |
86 inFile:[NSString stringWithUTF8
String:__FILE__] \ | |
87 atLine:__LINE__ \ | |
88 withDescription:STComposeString(descript
ion, ##__VA_ARGS__)]]; \ | |
89 }\ | |
90 } while(0) | |
91 | |
92 // Generates a failure when a1 != a2 | |
93 // Args: | |
94 // a1: received value. Should be either an OSErr or an OSStatus | |
95 // a2: expected value. Should be either an OSErr or an OSStatus | |
96 // description: A format string as in the printf() function. Can be nil or | |
97 // an empty string but must be present. | |
98 // ...: A variable number of arguments to the format string. Can be absent. | |
99 #define STAssertErr(a1, a2, description, ...) \ | |
100 do { \ | |
101 @try {\ | |
102 OSStatus a1value = (a1); \ | |
103 OSStatus a2value = (a2); \ | |
104 if (a1value != a2value) { \ | |
105 NSString *_expression = [NSString stringWithFormat:@"Expected %s(%ld) but
got %ld for (%s)", #a2, a2value, a1value, #a1]; \ | |
106 if (description) { \ | |
107 _expression = [NSString stringWithFormat:@"%@: %@", _expression, STCompo
seString(description, ##__VA_ARGS__)]; \ | |
108 } \ | |
109 [self failWithException:[NSException failureInFile:[NSString stringWithUTF
8String:__FILE__] \ | |
110 atLine:__LINE__ \ | |
111 withDescription:_expression]]; \ | |
112 } \ | |
113 }\ | |
114 @catch (id anException) {\ | |
115 [self failWithException:[NSException failureInRaise:[NSString stringWithForm
at:@"(%s) == (%s) fails", #a1, #a2] \ | |
116 exception:anException \ | |
117 inFile:[NSString stringWithUTF8
String:__FILE__] \ | |
118 atLine:__LINE__ \ | |
119 withDescription:STComposeString(descript
ion, ##__VA_ARGS__)]]; \ | |
120 }\ | |
121 } while(0) | |
122 | |
123 | |
124 // Generates a failure when a1 is NULL | |
125 // Args: | |
126 // a1: should be a pointer (use STAssertNotNil for an object) | |
127 // description: A format string as in the printf() function. Can be nil or | |
128 // an empty string but must be present. | |
129 // ...: A variable number of arguments to the format string. Can be absent. | |
130 #define STAssertNotNULL(a1, description, ...) \ | |
131 do { \ | |
132 @try {\ | |
133 const void* a1value = (a1); \ | |
134 if (a1value == NULL) { \ | |
135 NSString *_expression = [NSString stringWithFormat:@"(%s) != NULL", #a1];
\ | |
136 if (description) { \ | |
137 _expression = [NSString stringWithFormat:@"%@: %@", _expression, STCompo
seString(description, ##__VA_ARGS__)]; \ | |
138 } \ | |
139 [self failWithException:[NSException failureInFile:[NSString stringWithUTF
8String:__FILE__] \ | |
140 atLine:__LINE__ \ | |
141 withDescription:_expression]]; \ | |
142 } \ | |
143 }\ | |
144 @catch (id anException) {\ | |
145 [self failWithException:[NSException failureInRaise:[NSString stringWithForm
at:@"(%s) != NULL fails", #a1] \ | |
146 exception:anException \ | |
147 inFile:[NSString stringWithUTF8
String:__FILE__] \ | |
148 atLine:__LINE__ \ | |
149 withDescription:STComposeString(descript
ion, ##__VA_ARGS__)]]; \ | |
150 }\ | |
151 } while(0) | |
152 | |
153 // Generates a failure when a1 is not NULL | |
154 // Args: | |
155 // a1: should be a pointer (use STAssertNil for an object) | |
156 // description: A format string as in the printf() function. Can be nil or | |
157 // an empty string but must be present. | |
158 // ...: A variable number of arguments to the format string. Can be absent. | |
159 #define STAssertNULL(a1, description, ...) \ | |
160 do { \ | |
161 @try {\ | |
162 const void* a1value = (a1); \ | |
163 if (a1value != NULL) { \ | |
164 NSString *_expression = [NSString stringWithFormat:@"(%s) == NULL", #a1];
\ | |
165 if (description) { \ | |
166 _expression = [NSString stringWithFormat:@"%@: %@", _expression, STCompo
seString(description, ##__VA_ARGS__)]; \ | |
167 } \ | |
168 [self failWithException:[NSException failureInFile:[NSString stringWithUTF
8String:__FILE__] \ | |
169 atLine:__LINE__ \ | |
170 withDescription:_expression]]; \ | |
171 } \ | |
172 }\ | |
173 @catch (id anException) {\ | |
174 [self failWithException:[NSException failureInRaise:[NSString stringWithForm
at:@"(%s) == NULL fails", #a1] \ | |
175 exception:anException \ | |
176 inFile:[NSString stringWithUTF8
String:__FILE__] \ | |
177 atLine:__LINE__ \ | |
178 withDescription:STComposeString(descript
ion, ##__VA_ARGS__)]]; \ | |
179 }\ | |
180 } while(0) | |
181 | |
182 // Generates a failure when a1 is equal to a2. This test is for C scalars, | |
183 // structs and unions. | |
184 // Args: | |
185 // a1: argument 1 | |
186 // a2: argument 2 | |
187 // description: A format string as in the printf() function. Can be nil or | |
188 // an empty string but must be present. | |
189 // ...: A variable number of arguments to the format string. Can be absent. | |
190 #define STAssertNotEquals(a1, a2, description, ...) \ | |
191 do { \ | |
192 @try {\ | |
193 if (@encode(__typeof__(a1)) != @encode(__typeof__(a2))) { \ | |
194 [self failWithException:[NSException failureInFile:[NSString stringWithUTF
8String:__FILE__] \ | |
195 atLine:__LINE__ \ | |
196 withDescription:[[[NSString stringWithF
ormat:@"Type mismatch (%@/%@) -- ",@encode(__typeof__(a1)),@encode(__typeof__(a2
))] stringByAppendingString:STComposeString(description, ##__VA_ARGS__)]]]; \ | |
197 } else { \ | |
198 __typeof__(a1) a1value = (a1); \ | |
199 __typeof__(a2) a2value = (a2); \ | |
200 NSValue *a1encoded = [NSValue value:&a1value withObjCType:@encode(__typeof
__(a1))]; \ | |
201 NSValue *a2encoded = [NSValue value:&a2value withObjCType:@encode(__typeof
__(a2))]; \ | |
202 if ([a1encoded isEqualToValue:a2encoded]) { \ | |
203 NSString *_expression = [NSString stringWithFormat:@"(%s) != (%s)", #a1,
#a2]; \ | |
204 if (description) { \ | |
205 _expression = [NSString stringWithFormat:@"%@: %@", _expression, STCom
poseString(description, ##__VA_ARGS__)]; \ | |
206 } \ | |
207 [self failWithException:[NSException failureInFile:[NSString stringWithU
TF8String:__FILE__] \ | |
208 atLine:__LINE__ \ | |
209 withDescription:_expression]]; \ | |
210 } \ | |
211 } \ | |
212 } \ | |
213 @catch (id anException) {\ | |
214 [self failWithException:[NSException failureInRaise:[NSString stringWithForm
at:@"(%s) != (%s)", #a1, #a2] \ | |
215 exception:anException \ | |
216 inFile:[NSString stringWithUTF8
String:__FILE__] \ | |
217 atLine:__LINE__ \ | |
218 withDescription:STComposeString(description, ##__VA_ARGS__)]]; \ | |
219 }\ | |
220 } while(0) | |
221 | |
222 // Generates a failure when a1 is equal to a2. This test is for objects. | |
223 // Args: | |
224 // a1: argument 1. object. | |
225 // a2: argument 2. object. | |
226 // description: A format string as in the printf() function. Can be nil or | |
227 // an empty string but must be present. | |
228 // ...: A variable number of arguments to the format string. Can be absent. | |
229 #define STAssertNotEqualObjects(a1, a2, desc, ...) \ | |
230 do { \ | |
231 @try {\ | |
232 id a1value = (a1); \ | |
233 id a2value = (a2); \ | |
234 if ( (@encode(__typeof__(a1value)) == @encode(id)) && \ | |
235 (@encode(__typeof__(a2value)) == @encode(id)) && \ | |
236 ![(id)a1value isEqual:(id)a2value] ) continue; \ | |
237 NSString *_expression = [NSString stringWithFormat:@"%s('%@') != %s('%@
')", #a1, [a1 description], #a2, [a2 description]]; \ | |
238 if (desc) { \ | |
239 _expression = [NSString stringWithFormat:@"%@: %@", _expression, STCo
mposeString(desc, ##__VA_ARGS__)]; \ | |
240 } \ | |
241 [self failWithException:[NSException failureInFile:[NSString stringWith
UTF8String:__FILE__] \ | |
242 atLine:__LINE__ \ | |
243 withDescription:_expression]]; \ | |
244 }\ | |
245 @catch (id anException) {\ | |
246 [self failWithException:[NSException failureInRaise:[NSString stringWithForm
at: @"(%s) != (%s)", #a1, #a2] \ | |
247 exception:anException \ | |
248 inFile:[NSString stringWithUTF8
String:__FILE__] \ | |
249 atLine:__LINE__ \ | |
250 withDescription:STComposeString(desc, ##
__VA_ARGS__)]]; \ | |
251 }\ | |
252 } while(0) | |
253 | |
254 // Generates a failure when a1 is not 'op' to a2. This test is for C scalars. | |
255 // Args: | |
256 // a1: argument 1 | |
257 // a2: argument 2 | |
258 // op: operation | |
259 // description: A format string as in the printf() function. Can be nil or | |
260 // an empty string but must be present. | |
261 // ...: A variable number of arguments to the format string. Can be absent. | |
262 #define STAssertOperation(a1, a2, op, description, ...) \ | |
263 do { \ | |
264 @try {\ | |
265 if (@encode(__typeof__(a1)) != @encode(__typeof__(a2))) { \ | |
266 [self failWithException:[NSException failureInFile:[NSString stringWithUTF
8String:__FILE__] \ | |
267 atLine:__LINE__ \ | |
268 withDescription:[[[NSString stringWithF
ormat:@"Type mismatch (%@/%@) -- ",@encode(__typeof__(a1)),@encode(__typeof__(a2
))] stringByAppendingString:STComposeString(description, ##__VA_ARGS__)]]]; \ | |
269 } else { \ | |
270 __typeof__(a1) a1value = (a1); \ | |
271 __typeof__(a2) a2value = (a2); \ | |
272 if (!(a1value op a2value)) { \ | |
273 double a1DoubleValue = a1value; \ | |
274 double a2DoubleValue = a2value; \ | |
275 NSString *_expression = [NSString stringWithFormat:@"%s (%lg) %s %s (%lg
)", #a1, a1DoubleValue, #op, #a2, a2DoubleValue]; \ | |
276 if (description) { \ | |
277 _expression = [NSString stringWithFormat:@"%@: %@", _expression, STCom
poseString(description, ##__VA_ARGS__)]; \ | |
278 } \ | |
279 [self failWithException:[NSException failureInFile:[NSString stringWithU
TF8String:__FILE__] \ | |
280 atLine:__LINE__ \ | |
281 withDescription:_expression]]; \ | |
282 } \ | |
283 } \ | |
284 } \ | |
285 @catch (id anException) {\ | |
286 [self failWithException:[NSException \ | |
287 failureInRaise:[NSString stringWithFormat:@"(%s) %s (%s)", #a1, #op
, #a2] \ | |
288 exception:anException \ | |
289 inFile:[NSString stringWithUTF8String:__FILE__] \ | |
290 atLine:__LINE__ \ | |
291 withDescription:STComposeString(description, ##__VA_ARGS__)]]; \ | |
292 }\ | |
293 } while(0) | |
294 | |
295 // Generates a failure when a1 is not > a2. This test is for C scalars. | |
296 // Args: | |
297 // a1: argument 1 | |
298 // a2: argument 2 | |
299 // op: operation | |
300 // description: A format string as in the printf() function. Can be nil or | |
301 // an empty string but must be present. | |
302 // ...: A variable number of arguments to the format string. Can be absent. | |
303 #define STAssertGreaterThan(a1, a2, description, ...) \ | |
304 STAssertOperation(a1, a2, >, description, ##__VA_ARGS__) | |
305 | |
306 // Generates a failure when a1 is not >= a2. This test is for C scalars. | |
307 // Args: | |
308 // a1: argument 1 | |
309 // a2: argument 2 | |
310 // op: operation | |
311 // description: A format string as in the printf() function. Can be nil or | |
312 // an empty string but must be present. | |
313 // ...: A variable number of arguments to the format string. Can be absent. | |
314 #define STAssertGreaterThanOrEqual(a1, a2, description, ...) \ | |
315 STAssertOperation(a1, a2, >=, description, ##__VA_ARGS__) | |
316 | |
317 // Generates a failure when a1 is not < a2. This test is for C scalars. | |
318 // Args: | |
319 // a1: argument 1 | |
320 // a2: argument 2 | |
321 // op: operation | |
322 // description: A format string as in the printf() function. Can be nil or | |
323 // an empty string but must be present. | |
324 // ...: A variable number of arguments to the format string. Can be absent. | |
325 #define STAssertLessThan(a1, a2, description, ...) \ | |
326 STAssertOperation(a1, a2, <, description, ##__VA_ARGS__) | |
327 | |
328 // Generates a failure when a1 is not <= a2. This test is for C scalars. | |
329 // Args: | |
330 // a1: argument 1 | |
331 // a2: argument 2 | |
332 // op: operation | |
333 // description: A format string as in the printf() function. Can be nil or | |
334 // an empty string but must be present. | |
335 // ...: A variable number of arguments to the format string. Can be absent. | |
336 #define STAssertLessThanOrEqual(a1, a2, description, ...) \ | |
337 STAssertOperation(a1, a2, <=, description, ##__VA_ARGS__) | |
338 | |
339 // Generates a failure when string a1 is not equal to string a2. This call | |
340 // differs from STAssertEqualObjects in that strings that are different in | |
341 // composition (precomposed vs decomposed) will compare equal if their final | |
342 // representation is equal. | |
343 // ex O + umlaut decomposed is the same as O + umlaut composed. | |
344 // Args: | |
345 // a1: string 1 | |
346 // a2: string 2 | |
347 // description: A format string as in the printf() function. Can be nil or | |
348 // an empty string but must be present. | |
349 // ...: A variable number of arguments to the format string. Can be absent. | |
350 #define STAssertEqualStrings(a1, a2, description, ...) \ | |
351 do { \ | |
352 @try {\ | |
353 id a1value = (a1); \ | |
354 id a2value = (a2); \ | |
355 if (a1value == a2value) continue; \ | |
356 if ([a1value isKindOfClass:[NSString class]] && \ | |
357 [a2value isKindOfClass:[NSString class]] && \ | |
358 [a1value compare:a2value options:0] == NSOrderedSame) continue; \ | |
359 [self failWithException:[NSException failureInEqualityBetweenObject: a1valu
e \ | |
360 andObject: a2valu
e \ | |
361 inFile: [NSStr
ing stringWithUTF8String:__FILE__] \ | |
362 atLine: __LINE
__ \ | |
363 withDescription: STComp
oseString(description, ##__VA_ARGS__)]]; \ | |
364 }\ | |
365 @catch (id anException) {\ | |
366 [self failWithException:[NSException failureInRaise:[NSString stringWithForm
at: @"(%s) == (%s)", #a1, #a2] \ | |
367 exception:anException \ | |
368 inFile:[NSString stringWithUTF8
String:__FILE__] \ | |
369 atLine:__LINE__ \ | |
370 withDescription:STComposeString(descript
ion, ##__VA_ARGS__)]]; \ | |
371 }\ | |
372 } while(0) | |
373 | |
374 // Generates a failure when string a1 is equal to string a2. This call | |
375 // differs from STAssertEqualObjects in that strings that are different in | |
376 // composition (precomposed vs decomposed) will compare equal if their final | |
377 // representation is equal. | |
378 // ex O + umlaut decomposed is the same as O + umlaut composed. | |
379 // Args: | |
380 // a1: string 1 | |
381 // a2: string 2 | |
382 // description: A format string as in the printf() function. Can be nil or | |
383 // an empty string but must be present. | |
384 // ...: A variable number of arguments to the format string. Can be absent. | |
385 #define STAssertNotEqualStrings(a1, a2, description, ...) \ | |
386 do { \ | |
387 @try {\ | |
388 id a1value = (a1); \ | |
389 id a2value = (a2); \ | |
390 if ([a1value isKindOfClass:[NSString class]] && \ | |
391 [a2value isKindOfClass:[NSString class]] && \ | |
392 [a1value compare:a2value options:0] != NSOrderedSame) continue; \ | |
393 [self failWithException:[NSException failureInEqualityBetweenObject: a1valu
e \ | |
394 andObject: a2valu
e \ | |
395 inFile: [NSStr
ing stringWithUTF8String:__FILE__] \ | |
396 atLine: __LINE
__ \ | |
397 withDescription: STComp
oseString(description, ##__VA_ARGS__)]]; \ | |
398 }\ | |
399 @catch (id anException) {\ | |
400 [self failWithException:[NSException failureInRaise:[NSString stringWithForm
at: @"(%s) != (%s)", #a1, #a2] \ | |
401 exception:anException \ | |
402 inFile:[NSString stringWithUTF8
String:__FILE__] \ | |
403 atLine:__LINE__ \ | |
404 withDescription:STComposeString(descript
ion, ##__VA_ARGS__)]]; \ | |
405 }\ | |
406 } while(0) | |
407 | |
408 // Generates a failure when c-string a1 is not equal to c-string a2. | |
409 // Args: | |
410 // a1: string 1 | |
411 // a2: string 2 | |
412 // description: A format string as in the printf() function. Can be nil or | |
413 // an empty string but must be present. | |
414 // ...: A variable number of arguments to the format string. Can be absent. | |
415 #define STAssertEqualCStrings(a1, a2, description, ...) \ | |
416 do { \ | |
417 @try {\ | |
418 const char* a1value = (a1); \ | |
419 const char* a2value = (a2); \ | |
420 if (a1value == a2value) continue; \ | |
421 if (strcmp(a1value, a2value) == 0) continue; \ | |
422 [self failWithException:[NSException failureInEqualityBetweenObject: [NSStri
ng stringWithUTF8String:a1value] \ | |
423 andObject: [NSStri
ng stringWithUTF8String:a2value] \ | |
424 inFile: [NSStri
ng stringWithUTF8String:__FILE__] \ | |
425 atLine: __LINE_
_ \ | |
426 withDescription: STCompo
seString(description, ##__VA_ARGS__)]]; \ | |
427 }\ | |
428 @catch (id anException) {\ | |
429 [self failWithException:[NSException failureInRaise:[NSString stringWithForm
at: @"(%s) == (%s)", #a1, #a2] \ | |
430 exception:anException \ | |
431 inFile:[NSString stringWithUTF8
String:__FILE__] \ | |
432 atLine:__LINE__ \ | |
433 withDescription:STComposeString(descript
ion, ##__VA_ARGS__)]]; \ | |
434 }\ | |
435 } while(0) | |
436 | |
437 // Generates a failure when c-string a1 is equal to c-string a2. | |
438 // Args: | |
439 // a1: string 1 | |
440 // a2: string 2 | |
441 // description: A format string as in the printf() function. Can be nil or | |
442 // an empty string but must be present. | |
443 // ...: A variable number of arguments to the format string. Can be absent. | |
444 #define STAssertNotEqualCStrings(a1, a2, description, ...) \ | |
445 do { \ | |
446 @try {\ | |
447 const char* a1value = (a1); \ | |
448 const char* a2value = (a2); \ | |
449 if (strcmp(a1value, a2value) != 0) continue; \ | |
450 [self failWithException:[NSException failureInEqualityBetweenObject: [NSStri
ng stringWithUTF8String:a1value] \ | |
451 andObject: [NSStri
ng stringWithUTF8String:a2value] \ | |
452 inFile: [NSStri
ng stringWithUTF8String:__FILE__] \ | |
453 atLine: __LINE_
_ \ | |
454 withDescription: STCompo
seString(description, ##__VA_ARGS__)]]; \ | |
455 }\ | |
456 @catch (id anException) {\ | |
457 [self failWithException:[NSException failureInRaise:[NSString stringWithForm
at: @"(%s) != (%s)", #a1, #a2] \ | |
458 exception:anException \ | |
459 inFile:[NSString stringWithUTF8
String:__FILE__] \ | |
460 atLine:__LINE__ \ | |
461 withDescription:STComposeString(descript
ion, ##__VA_ARGS__)]]; \ | |
462 }\ | |
463 } while(0) | |
464 | |
465 #if GTM_IPHONE_SDK | |
466 | |
467 // SENTE_BEGIN | |
468 /*" Generates a failure when !{ [a1 isEqualTo:a2] } is false | |
469 (or one is nil and the other is not). | |
470 _{a1 The object on the left.} | |
471 _{a2 The object on the right.} | |
472 _{description A format string as in the printf() function. Can be nil or | |
473 an empty string but must be present.} | |
474 _{... A variable number of arguments to the format string. Can be absent
.} | |
475 "*/ | |
476 #define STAssertEqualObjects(a1, a2, description, ...) \ | |
477 do { \ | |
478 @try {\ | |
479 id a1value = (a1); \ | |
480 id a2value = (a2); \ | |
481 if (a1value == a2value) continue; \ | |
482 if ( (@encode(__typeof__(a1value)) == @encode(id)) && \ | |
483 (@encode(__typeof__(a2value)) == @encode(id)) && \ | |
484 [(id)a1value isEqual: (id)a2value] ) continue; \ | |
485 [self failWithException:[NSException failureInEqualityBetweenObject: a1value
\ | |
486 andObject: a2value
\ | |
487 inFile: [NSStri
ng stringWithUTF8String:__FILE__] \ | |
488 atLine: __LINE_
_ \ | |
489 withDescription: STCompo
seString(description, ##__VA_ARGS__)]]; \ | |
490 }\ | |
491 @catch (id anException) {\ | |
492 [self failWithException:[NSException failureInRaise:[NSString stringWithForm
at: @"(%s) == (%s)", #a1, #a2] \ | |
493 exception:anException \ | |
494 inFile:[NSString stringWithUTF8
String:__FILE__] \ | |
495 atLine:__LINE__ \ | |
496 withDescription:STComposeString(descript
ion, ##__VA_ARGS__)]]; \ | |
497 }\ | |
498 } while(0) | |
499 | |
500 | |
501 /*" Generates a failure when a1 is not equal to a2. This test is for | |
502 C scalars, structs and unions. | |
503 _{a1 The argument on the left.} | |
504 _{a2 The argument on the right.} | |
505 _{description A format string as in the printf() function. Can be nil or | |
506 an empty string but must be present.} | |
507 _{... A variable number of arguments to the format string. Can be absent.} | |
508 "*/ | |
509 #define STAssertEquals(a1, a2, description, ...) \ | |
510 do { \ | |
511 @try {\ | |
512 if (@encode(__typeof__(a1)) != @encode(__typeof__(a2))) { \ | |
513 [self failWithException:[NSException failureInFile:[NSString stringWithUTF
8String:__FILE__] \ | |
514
atLine:__LINE__ \ | |
515 withDescription:[[NSString stringWithFormat:@"Typ
e mismatch (%@/%@) -- ",@encode(__typeof__(a1)),@encode(__typeof__(a2))] stringB
yAppendingString:STComposeString(description, ##__VA_ARGS__)]]]; \ | |
516 } else { \ | |
517 __typeof__(a1) a1value = (a1); \ | |
518 __typeof__(a2) a2value = (a2); \ | |
519 NSValue *a1encoded = [NSValue value:&a1value withObjCType: @encode(__typeo
f__(a1))]; \ | |
520 NSValue *a2encoded = [NSValue value:&a2value withObjCType: @encode(__typeo
f__(a2))]; \ | |
521 if (![a1encoded isEqualToValue:a2encoded]) { \ | |
522 [self failWithException:[NSException failureInEqualityBetweenValue: a1en
coded \ | |
523 andValue: a2en
coded \ | |
524 withAccuracy: nil
\ | |
525 inFile: [NSS
tring stringWithUTF8String:__FILE__] \ | |
526 atLine: __LI
NE__ \ | |
527 withDescription: STCo
mposeString(description, ##__VA_ARGS__)]]; \ | |
528 } \ | |
529 } \ | |
530 } \ | |
531 @catch (id anException) {\ | |
532 [self failWithException:[NSException failureInRaise:[NSString stringWithForm
at: @"(%s) == (%s)", #a1, #a2] \ | |
533 exception:anException \ | |
534 inFile:[NSString stringWithUTF8
String:__FILE__] \ | |
535 atLine:__LINE__ \ | |
536 withDescription:STComposeString(descript
ion, ##__VA_ARGS__)]]; \ | |
537 }\ | |
538 } while(0) | |
539 | |
540 #define STAbsoluteDifference(left,right) (MAX(left,right)-MIN(left,right)) | |
541 | |
542 | |
543 /*" Generates a failure when a1 is not equal to a2 within + or - accuracy is fal
se. | |
544 This test is for scalars such as floats and doubles where small differences | |
545 could make these items not exactly equal, but also works for all scalars. | |
546 _{a1 The scalar on the left.} | |
547 _{a2 The scalar on the right.} | |
548 _{accuracy The maximum difference between a1 and a2 for these values to be | |
549 considered equal.} | |
550 _{description A format string as in the printf() function. Can be nil or | |
551 an empty string but must be present.} | |
552 _{... A variable number of arguments to the format string. Can be absent.} | |
553 "*/ | |
554 | |
555 #define STAssertEqualsWithAccuracy(a1, a2, accuracy, description, ...) \ | |
556 do { \ | |
557 @try {\ | |
558 if (@encode(__typeof__(a1)) != @encode(__typeof__(a2))) { \ | |
559 [self failWithException:[NSException failureInFile:[NSString stringWithUTF
8String:__FILE__] \ | |
560
atLine:__LINE__ \ | |
561 withDesc
ription:[[[NSString stringWithFormat:@"Type mismatch (%@/%@) -- ",@encode(__type
of__(a1)),@encode(__typeof__(a2))] stringByAppendingString:STComposeString(descr
iption, ##__VA_ARGS__)]]]; \ | |
562 } else { \ | |
563 __typeof__(a1) a1value = (a1); \ | |
564 __typeof__(a2) a2value = (a2); \ | |
565 __typeof__(accuracy) accuracyvalue = (accuracy); \ | |
566 if (STAbsoluteDifference(a1value, a2value) > accuracyvalue) { \ | |
567 NSValue *a1encoded = [NSValue value:&a1value withObjCType:@encode(
__typeof__(a1))]; \ | |
568 NSValue *a2encoded = [NSValue value:&a2value withObjCType:@encode(
__typeof__(a2))]; \ | |
569 NSValue *accuracyencoded = [NSValue value:&accuracyvalue withObjCT
ype:@encode(__typeof__(accuracy))]; \ | |
570 [self failWithException:[NSException failureInEqualityBetweenValue
: a1encoded \ | |
571 andValue
: a2encoded \ | |
572 withAccuracy
: accuracyencoded \ | |
573 inFile
: [NSString stringWithUTF8String:__FILE__] \ | |
574 atLine
: __LINE__ \ | |
575 withDescription
: STComposeString(description, ##__VA_ARGS__)]]; \ | |
576 } \ | |
577 } \ | |
578 } \ | |
579 @catch (id anException) {\ | |
580 [self failWithException:[NSException failureInRaise:[NSString stringWithForm
at: @"(%s) == (%s)", #a1, #a2] \ | |
581 excepti
on:anException \ | |
582 inFi
le:[NSString stringWithUTF8String:__FILE__] \ | |
583 atLi
ne:__LINE__ \ | |
584 withDescripti
on:STComposeString(description, ##__VA_ARGS__)]]; \ | |
585 }\ | |
586 } while(0) | |
587 | |
588 | |
589 | |
590 /*" Generates a failure unconditionally. | |
591 _{description A format string as in the printf() function. Can be nil or | |
592 an empty string but must be present.} | |
593 _{... A variable number of arguments to the format string. Can be absent.} | |
594 "*/ | |
595 #define STFail(description, ...) \ | |
596 [self failWithException:[NSException failureInFile: [NSString stringWithUTF8Stri
ng:__FILE__] \ | |
597 atLine: __LINE__ \ | |
598 withDescription: STComposeString(description,
##__VA_ARGS__)]] | |
599 | |
600 | |
601 | |
602 /*" Generates a failure when a1 is not nil. | |
603 _{a1 An object.} | |
604 _{description A format string as in the printf() function. Can be nil or | |
605 an empty string but must be present.} | |
606 _{... A variable number of arguments to the format string. Can be absent.} | |
607 "*/ | |
608 #define STAssertNil(a1, description, ...) \ | |
609 do { \ | |
610 @try {\ | |
611 id a1value = (a1); \ | |
612 if (a1value != nil) { \ | |
613 NSString *_a1 = [NSString stringWithUTF8String: #a1]; \ | |
614 NSString *_expression = [NSString stringWithFormat:@"((%@) == nil)", _a1];
\ | |
615 [self failWithException:[NSException failureInCondition: _expression \ | |
616 isTrue: NO \ | |
617 inFile: [NSString stringW
ithUTF8String:__FILE__] \ | |
618 atLine: __LINE__ \ | |
619 withDescription: STComposeString(d
escription, ##__VA_ARGS__)]]; \ | |
620 } \ | |
621 }\ | |
622 @catch (id anException) {\ | |
623 [self failWithException:[NSException failureInRaise:[NSString stringWithForm
at: @"(%s) == nil fails", #a1] \ | |
624 exception:anException \ | |
625 inFile:[NSString stringWithUTF8
String:__FILE__] \ | |
626 atLine:__LINE__ \ | |
627 withDescription:STComposeString(descript
ion, ##__VA_ARGS__)]]; \ | |
628 }\ | |
629 } while(0) | |
630 | |
631 | |
632 /*" Generates a failure when a1 is nil. | |
633 _{a1 An object.} | |
634 _{description A format string as in the printf() function. Can be nil or | |
635 an empty string but must be present.} | |
636 _{... A variable number of arguments to the format string. Can be absent.} | |
637 "*/ | |
638 #define STAssertNotNil(a1, description, ...) \ | |
639 do { \ | |
640 @try {\ | |
641 id a1value = (a1); \ | |
642 if (a1value == nil) { \ | |
643 NSString *_a1 = [NSString stringWithUTF8String: #a1]; \ | |
644 NSString *_expression = [NSString stringWithFormat:@"((%@) != nil)", _a1];
\ | |
645 [self failWithException:[NSException failureInCondition: _expression \ | |
646 isTrue: NO \ | |
647 inFile: [NSString stringW
ithUTF8String:__FILE__] \ | |
648 atLine: __LINE__ \ | |
649 withDescription: STComposeString(d
escription, ##__VA_ARGS__)]]; \ | |
650 } \ | |
651 }\ | |
652 @catch (id anException) {\ | |
653 [self failWithException:[NSException failureInRaise:[NSString stringWithForm
at: @"(%s) != nil fails", #a1] \ | |
654 exception:anException \ | |
655 inFile:[NSString stringWithUTF8
String:__FILE__] \ | |
656 atLine:__LINE__ \ | |
657 withDescription:STComposeString(descript
ion, ##__VA_ARGS__)]]; \ | |
658 }\ | |
659 } while(0) | |
660 | |
661 | |
662 /*" Generates a failure when expression evaluates to false. | |
663 _{expr The expression that is tested.} | |
664 _{description A format string as in the printf() function. Can be nil or | |
665 an empty string but must be present.} | |
666 _{... A variable number of arguments to the format string. Can be absent.} | |
667 "*/ | |
668 #define STAssertTrue(expr, description, ...) \ | |
669 do { \ | |
670 BOOL _evaluatedExpression = (expr);\ | |
671 if (!_evaluatedExpression) {\ | |
672 NSString *_expression = [NSString stringWithUTF8String: #expr];\ | |
673 [self failWithException:[NSException failureInCondition: _expression \ | |
674 isTrue: NO \ | |
675 inFile: [NSString stringWit
hUTF8String:__FILE__] \ | |
676 atLine: __LINE__ \ | |
677 withDescription: STComposeString(des
cription, ##__VA_ARGS__)]]; \ | |
678 } \ | |
679 } while (0) | |
680 | |
681 | |
682 /*" Generates a failure when expression evaluates to false and in addition will | |
683 generate error messages if an exception is encountered. | |
684 _{expr The expression that is tested.} | |
685 _{description A format string as in the printf() function. Can be nil or | |
686 an empty string but must be present.} | |
687 _{... A variable number of arguments to the format string. Can be absent.} | |
688 "*/ | |
689 #define STAssertTrueNoThrow(expr, description, ...) \ | |
690 do { \ | |
691 @try {\ | |
692 BOOL _evaluatedExpression = (expr);\ | |
693 if (!_evaluatedExpression) {\ | |
694 NSString *_expression = [NSString stringWithUTF8String: #expr];\ | |
695 [self failWithException:[NSException failureInCondition: _expression \ | |
696 isTrue: NO \ | |
697 inFile: [NSString stringW
ithUTF8String:__FILE__] \ | |
698 atLine: __LINE__ \ | |
699 withDescription: STComposeString(d
escription, ##__VA_ARGS__)]]; \ | |
700 } \ | |
701 } \ | |
702 @catch (id anException) {\ | |
703 [self failWithException:[NSException failureInRaise:[NSString stringWithForm
at: @"(%s) ", #expr] \ | |
704 exception:anException \ | |
705 inFile:[NSString stringWithUTF8
String:__FILE__] \ | |
706 atLine:__LINE__ \ | |
707 withDescription:STComposeString(descript
ion, ##__VA_ARGS__)]]; \ | |
708 }\ | |
709 } while (0) | |
710 | |
711 | |
712 /*" Generates a failure when the expression evaluates to true. | |
713 _{expr The expression that is tested.} | |
714 _{description A format string as in the printf() function. Can be nil or | |
715 an empty string but must be present.} | |
716 _{... A variable number of arguments to the format string. Can be absent.} | |
717 "*/ | |
718 #define STAssertFalse(expr, description, ...) \ | |
719 do { \ | |
720 BOOL _evaluatedExpression = (expr);\ | |
721 if (_evaluatedExpression) {\ | |
722 NSString *_expression = [NSString stringWithUTF8String: #expr];\ | |
723 [self failWithException:[NSException failureInCondition: _expression \ | |
724 isTrue: YES \ | |
725 inFile: [NSString stringWit
hUTF8String:__FILE__] \ | |
726 atLine: __LINE__ \ | |
727 withDescription: STComposeString(des
cription, ##__VA_ARGS__)]]; \ | |
728 } \ | |
729 } while (0) | |
730 | |
731 | |
732 /*" Generates a failure when the expression evaluates to true and in addition | |
733 will generate error messages if an exception is encountered. | |
734 _{expr The expression that is tested.} | |
735 _{description A format string as in the printf() function. Can be nil or | |
736 an empty string but must be present.} | |
737 _{... A variable number of arguments to the format string. Can be absent.} | |
738 "*/ | |
739 #define STAssertFalseNoThrow(expr, description, ...) \ | |
740 do { \ | |
741 @try {\ | |
742 BOOL _evaluatedExpression = (expr);\ | |
743 if (_evaluatedExpression) {\ | |
744 NSString *_expression = [NSString stringWithUTF8String: #expr];\ | |
745 [self failWithException:[NSException failureInCondition: _expression \ | |
746 isTrue: YES \ | |
747 inFile: [NSString stringW
ithUTF8String:__FILE__] \ | |
748 atLine: __LINE__ \ | |
749 withDescription: STComposeString(d
escription, ##__VA_ARGS__)]]; \ | |
750 } \ | |
751 } \ | |
752 @catch (id anException) {\ | |
753 [self failWithException:[NSException failureInRaise:[NSString stringWithForm
at: @"!(%s) ", #expr] \ | |
754 exception:anException \ | |
755 inFile:[NSString stringWithUTF8
String:__FILE__] \ | |
756 atLine:__LINE__ \ | |
757 withDescription:STComposeString(descript
ion, ##__VA_ARGS__)]]; \ | |
758 }\ | |
759 } while (0) | |
760 | |
761 | |
762 /*" Generates a failure when expression does not throw an exception. | |
763 _{expression The expression that is evaluated.} | |
764 _{description A format string as in the printf() function. Can be nil or | |
765 an empty string but must be present.} | |
766 _{... A variable number of arguments to the format string. Can be absent. | |
767 "*/ | |
768 #define STAssertThrows(expr, description, ...) \ | |
769 do { \ | |
770 @try { \ | |
771 (expr);\ | |
772 } \ | |
773 @catch (id anException) { \ | |
774 continue; \ | |
775 }\ | |
776 [self failWithException:[NSException failureInRaise: [NSString stringWithUTF8S
tring:#expr] \ | |
777 exception: nil \ | |
778 inFile: [NSString stringWithUTF8S
tring:__FILE__] \ | |
779 atLine: __LINE__ \ | |
780 withDescription: STComposeString(descripti
on, ##__VA_ARGS__)]]; \ | |
781 } while (0) | |
782 | |
783 | |
784 /*" Generates a failure when expression does not throw an exception of a | |
785 specific class. | |
786 _{expression The expression that is evaluated.} | |
787 _{specificException The specified class of the exception.} | |
788 _{description A format string as in the printf() function. Can be nil or | |
789 an empty string but must be present.} | |
790 _{... A variable number of arguments to the format string. Can be absent.} | |
791 "*/ | |
792 #define STAssertThrowsSpecific(expr, specificException, description, ...) \ | |
793 do { \ | |
794 @try { \ | |
795 (expr);\ | |
796 } \ | |
797 @catch (specificException *anException) { \ | |
798 continue; \ | |
799 }\ | |
800 @catch (id anException) {\ | |
801 NSString *_descrip = STComposeString(@"(Expected exception: %@) %@", NSStrin
gFromClass([specificException class]), description);\ | |
802 [self failWithException:[NSException failureInRaise: [NSString stringWithUTF
8String:#expr] \ | |
803 exception: anException \ | |
804 inFile: [NSString stringWithUTF
8String:__FILE__] \ | |
805 atLine: __LINE__ \ | |
806 withDescription: STComposeString(_descri
p, ##__VA_ARGS__)]]; \ | |
807 continue; \ | |
808 }\ | |
809 NSString *_descrip = STComposeString(@"(Expected exception: %@) %@", NSStringF
romClass([specificException class]), description);\ | |
810 [self failWithException:[NSException failureInRaise: [NSString stringWithUTF8S
tring:#expr] \ | |
811 exception: nil \ | |
812 inFile: [NSString stringWithUTF8S
tring:__FILE__] \ | |
813 atLine: __LINE__ \ | |
814 withDescription: STComposeString(_descrip,
##__VA_ARGS__)]]; \ | |
815 } while (0) | |
816 | |
817 | |
818 /*" Generates a failure when expression does not throw an exception of a | |
819 specific class with a specific name. Useful for those frameworks like | |
820 AppKit or Foundation that throw generic NSException w/specific names | |
821 (NSInvalidArgumentException, etc). | |
822 _{expression The expression that is evaluated.} | |
823 _{specificException The specified class of the exception.} | |
824 _{aName The name of the specified exception.} | |
825 _{description A format string as in the printf() function. Can be nil or | |
826 an empty string but must be present.} | |
827 _{... A variable number of arguments to the format string. Can be absent.} | |
828 | |
829 "*/ | |
830 #define STAssertThrowsSpecificNamed(expr, specificException, aName, description,
...) \ | |
831 do { \ | |
832 @try { \ | |
833 (expr);\ | |
834 } \ | |
835 @catch (specificException *anException) { \ | |
836 if ([aName isEqualToString: [anException name]]) continue; \ | |
837 NSString *_descrip = STComposeString(@"(Expected exception: %@ (name: %@)) %
@", NSStringFromClass([specificException class]), aName, description);\ | |
838 [self failWithException: \ | |
839 [NSException failureInRaise: [NSString stringWithUTF8String:#expr] \ | |
840 exception: anException \ | |
841 inFile: [NSString stringWithUTF8String:__FILE__] \ | |
842 atLine: __LINE__ \ | |
843 withDescription: STComposeString(_descrip, ##__VA_ARGS__)]]; \ | |
844 continue; \ | |
845 }\ | |
846 @catch (id anException) {\ | |
847 NSString *_descrip = STComposeString(@"(Expected exception: %@) %@", NSStrin
gFromClass([specificException class]), description);\ | |
848 [self failWithException: \ | |
849 [NSException failureInRaise: [NSString stringWithUTF8String:#expr] \ | |
850 exception: anException \ | |
851 inFile: [NSString stringWithUTF8String:__FILE__] \ | |
852 atLine: __LINE__ \ | |
853 withDescription: STComposeString(_descrip, ##__VA_ARGS__)]]; \ | |
854 continue; \ | |
855 }\ | |
856 NSString *_descrip = STComposeString(@"(Expected exception: %@) %@", NSStringF
romClass([specificException class]), description);\ | |
857 [self failWithException: \ | |
858 [NSException failureInRaise: [NSString stringWithUTF8String:#expr] \ | |
859 exception: nil \ | |
860 inFile: [NSString stringWithUTF8String:__FILE__] \ | |
861 atLine: __LINE__ \ | |
862 withDescription: STComposeString(_descrip, ##__VA_ARGS__)]]; \ | |
863 } while (0) | |
864 | |
865 | |
866 /*" Generates a failure when expression does throw an exception. | |
867 _{expression The expression that is evaluated.} | |
868 _{description A format string as in the printf() function. Can be nil or | |
869 an empty string but must be present.} | |
870 _{... A variable number of arguments to the format string. Can be absent.} | |
871 "*/ | |
872 #define STAssertNoThrow(expr, description, ...) \ | |
873 do { \ | |
874 @try { \ | |
875 (expr);\ | |
876 } \ | |
877 @catch (id anException) { \ | |
878 [self failWithException:[NSException failureInRaise: [NSString stringWithUTF
8String:#expr] \ | |
879 exception: anException \ | |
880 inFile: [NSString stringWithUTF
8String:__FILE__] \ | |
881 atLine: __LINE__ \ | |
882 withDescription: STComposeString(descrip
tion, ##__VA_ARGS__)]]; \ | |
883 }\ | |
884 } while (0) | |
885 | |
886 | |
887 /*" Generates a failure when expression does throw an exception of the specitied | |
888 class. Any other exception is okay (i.e. does not generate a failure). | |
889 _{expression The expression that is evaluated.} | |
890 _{specificException The specified class of the exception.} | |
891 _{description A format string as in the printf() function. Can be nil or | |
892 an empty string but must be present.} | |
893 _{... A variable number of arguments to the format string. Can be absent.} | |
894 "*/ | |
895 #define STAssertNoThrowSpecific(expr, specificException, description, ...) \ | |
896 do { \ | |
897 @try { \ | |
898 (expr);\ | |
899 } \ | |
900 @catch (specificException *anException) { \ | |
901 [self failWithException:[NSException failureInRaise: [NSString stringWithUTF
8String:#expr] \ | |
902 exception: anException \ | |
903 inFile: [NSString stringWithUTF
8String:__FILE__] \ | |
904 atLine: __LINE__ \ | |
905 withDescription: STComposeString(descrip
tion, ##__VA_ARGS__)]]; \ | |
906 }\ | |
907 @catch (id anythingElse) {\ | |
908 ; \ | |
909 }\ | |
910 } while (0) | |
911 | |
912 | |
913 /*" Generates a failure when expression does throw an exception of a | |
914 specific class with a specific name. Useful for those frameworks like | |
915 AppKit or Foundation that throw generic NSException w/specific names | |
916 (NSInvalidArgumentException, etc). | |
917 _{expression The expression that is evaluated.} | |
918 _{specificException The specified class of the exception.} | |
919 _{aName The name of the specified exception.} | |
920 _{description A format string as in the printf() function. Can be nil or | |
921 an empty string but must be present.} | |
922 _{... A variable number of arguments to the format string. Can be absent.} | |
923 | |
924 "*/ | |
925 #define STAssertNoThrowSpecificNamed(expr, specificException, aName, description
, ...) \ | |
926 do { \ | |
927 @try { \ | |
928 (expr);\ | |
929 } \ | |
930 @catch (specificException *anException) { \ | |
931 if ([aName isEqualToString: [anException name]]) { \ | |
932 NSString *_descrip = STComposeString(@"(Expected exception: %@ (name: %@))
%@", NSStringFromClass([specificException class]), aName, description);\ | |
933 [self failWithException: \ | |
934 [NSException failureInRaise: [NSString stringWithUTF8String:#expr] \ | |
935 exception: anException \ | |
936 inFile: [NSString stringWithUTF8String:__FILE__] \ | |
937 atLine: __LINE__ \ | |
938 withDescription: STComposeString(_descrip, ##__VA_ARGS__)]];
\ | |
939 } \ | |
940 continue; \ | |
941 }\ | |
942 @catch (id anythingElse) {\ | |
943 ; \ | |
944 }\ | |
945 } while (0) | |
946 | |
947 | |
948 | |
949 @interface NSException (GTMSenTestAdditions) | |
950 + (NSException *)failureInFile:(NSString *)filename | |
951 atLine:(int)lineNumber | |
952 withDescription:(NSString *)formatString, ...; | |
953 + (NSException *)failureInCondition:(NSString *)condition | |
954 isTrue:(BOOL)isTrue | |
955 inFile:(NSString *)filename | |
956 atLine:(int)lineNumber | |
957 withDescription:(NSString *)formatString, ...; | |
958 + (NSException *)failureInEqualityBetweenObject:(id)left | |
959 andObject:(id)right | |
960 inFile:(NSString *)filename | |
961 atLine:(int)lineNumber | |
962 withDescription:(NSString *)formatString, ...; | |
963 + (NSException *)failureInEqualityBetweenValue:(NSValue *)left | |
964 andValue:(NSValue *)right | |
965 withAccuracy:(NSValue *)accuracy | |
966 inFile:(NSString *)filename | |
967 atLine:(int) ineNumber | |
968 withDescription:(NSString *)formatString, ...; | |
969 + (NSException *)failureInRaise:(NSString *)expression | |
970 inFile:(NSString *)filename | |
971 atLine:(int)lineNumber | |
972 withDescription:(NSString *)formatString, ...; | |
973 + (NSException *)failureInRaise:(NSString *)expression | |
974 exception:(NSException *)exception | |
975 inFile:(NSString *)filename | |
976 atLine:(int)lineNumber | |
977 withDescription:(NSString *)formatString, ...; | |
978 @end | |
979 | |
980 // SENTE_END | |
981 | |
982 @interface SenTestCase : NSObject { | |
983 SEL currentSelector_; | |
984 } | |
985 | |
986 - (void)setUp; | |
987 - (void)invokeTest; | |
988 - (void)tearDown; | |
989 - (void)performTest:(SEL)sel; | |
990 - (void)failWithException:(NSException*)exception; | |
991 @end | |
992 | |
993 GTM_EXTERN NSString *const SenTestFailureException; | |
994 | |
995 GTM_EXTERN NSString *const SenTestFilenameKey; | |
996 GTM_EXTERN NSString *const SenTestLineNumberKey; | |
997 | |
998 #endif // GTM_IPHONE_SDK | |
999 | |
1000 // All unittest cases in GTM should inherit from GTMTestCase. It makes sure | |
1001 // to set up our logging system correctly to verify logging calls. | |
1002 // See GTMUnitTestDevLog.h for details | |
1003 @interface GTMTestCase : SenTestCase | |
1004 @end | |
OLD | NEW |