1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/crashreporter/google-breakpad/src/common/mac/testing/GTMSenTestCase.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,1110 @@ 1.4 +// 1.5 +// GTMSenTestCase.h 1.6 +// 1.7 +// Copyright 2007-2008 Google Inc. 1.8 +// 1.9 +// Licensed under the Apache License, Version 2.0 (the "License"); you may not 1.10 +// use this file except in compliance with the License. You may obtain a copy 1.11 +// of the License at 1.12 +// 1.13 +// http://www.apache.org/licenses/LICENSE-2.0 1.14 +// 1.15 +// Unless required by applicable law or agreed to in writing, software 1.16 +// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 1.17 +// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 1.18 +// License for the specific language governing permissions and limitations under 1.19 +// the License. 1.20 +// 1.21 + 1.22 +// Portions of this file fall under the following license, marked with 1.23 +// SENTE_BEGIN - SENTE_END 1.24 +// 1.25 +// Copyright (c) 1997-2005, Sen:te (Sente SA). All rights reserved. 1.26 +// 1.27 +// Use of this source code is governed by the following license: 1.28 +// 1.29 +// Redistribution and use in source and binary forms, with or without modification, 1.30 +// are permitted provided that the following conditions are met: 1.31 +// 1.32 +// (1) Redistributions of source code must retain the above copyright notice, 1.33 +// this list of conditions and the following disclaimer. 1.34 +// 1.35 +// (2) Redistributions in binary form must reproduce the above copyright notice, 1.36 +// this list of conditions and the following disclaimer in the documentation 1.37 +// and/or other materials provided with the distribution. 1.38 +// 1.39 +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' 1.40 +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 1.41 +// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 1.42 +// IN NO EVENT SHALL Sente SA OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 1.43 +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 1.44 +// OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 1.45 +// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 1.46 +// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 1.47 +// EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 1.48 +// 1.49 +// Note: this license is equivalent to the FreeBSD license. 1.50 +// 1.51 +// This notice may not be removed from this file. 1.52 + 1.53 +// Some extra test case macros that would have been convenient for SenTestingKit 1.54 +// to provide. I didn't stick GTM in front of the Macro names, so that they would 1.55 +// be easy to remember. 1.56 + 1.57 +#import "GTMDefines.h" 1.58 + 1.59 +#if (!GTM_IPHONE_SDK) || (GTM_IPHONE_USE_SENTEST) 1.60 +#import <SenTestingKit/SenTestingKit.h> 1.61 +#else 1.62 +#import <Foundation/Foundation.h> 1.63 +#ifdef __cplusplus 1.64 +extern "C" { 1.65 +#endif 1.66 + 1.67 +#if defined __clang__ 1.68 +// gcc and gcc-llvm do not allow you to use STAssert(blah, nil) with nil 1.69 +// as a description if you have the NS_FORMAT_FUNCTION on. 1.70 +// clang however will not compile without warnings if you don't have it. 1.71 +NSString *STComposeString(NSString *, ...) NS_FORMAT_FUNCTION(1, 2); 1.72 +#else 1.73 +NSString *STComposeString(NSString *, ...); 1.74 +#endif // __clang__ 1.75 + 1.76 +#ifdef __cplusplus 1.77 +} 1.78 +#endif 1.79 + 1.80 +#endif // !GTM_IPHONE_SDK || GTM_IPHONE_USE_SENTEST 1.81 + 1.82 +// Generates a failure when a1 != noErr 1.83 +// Args: 1.84 +// a1: should be either an OSErr or an OSStatus 1.85 +// description: A format string as in the printf() function. Can be nil or 1.86 +// an empty string but must be present. 1.87 +// ...: A variable number of arguments to the format string. Can be absent. 1.88 +#define STAssertNoErr(a1, description, ...) \ 1.89 +do { \ 1.90 + @try { \ 1.91 + OSStatus a1value = (a1); \ 1.92 + if (a1value != noErr) { \ 1.93 + NSString *_expression = [NSString stringWithFormat:@"Expected noErr, got %ld for (%s)", (long)a1value, #a1]; \ 1.94 + [self failWithException:([NSException failureInCondition:_expression \ 1.95 + isTrue:NO \ 1.96 + inFile:[NSString stringWithUTF8String:__FILE__] \ 1.97 + atLine:__LINE__ \ 1.98 + withDescription:@"%@", STComposeString(description, ##__VA_ARGS__)])]; \ 1.99 + } \ 1.100 + } \ 1.101 + @catch (id anException) { \ 1.102 + [self failWithException:[NSException failureInRaise:[NSString stringWithFormat:@"(%s) == noErr fails", #a1] \ 1.103 + exception:anException \ 1.104 + inFile:[NSString stringWithUTF8String:__FILE__] \ 1.105 + atLine:__LINE__ \ 1.106 + withDescription:@"%@", STComposeString(description, ##__VA_ARGS__)]]; \ 1.107 + } \ 1.108 +} while(0) 1.109 + 1.110 +// Generates a failure when a1 != a2 1.111 +// Args: 1.112 +// a1: received value. Should be either an OSErr or an OSStatus 1.113 +// a2: expected value. Should be either an OSErr or an OSStatus 1.114 +// description: A format string as in the printf() function. Can be nil or 1.115 +// an empty string but must be present. 1.116 +// ...: A variable number of arguments to the format string. Can be absent. 1.117 +#define STAssertErr(a1, a2, description, ...) \ 1.118 +do { \ 1.119 + @try { \ 1.120 + OSStatus a1value = (a1); \ 1.121 + OSStatus a2value = (a2); \ 1.122 + if (a1value != a2value) { \ 1.123 + NSString *_expression = [NSString stringWithFormat:@"Expected %s(%ld) but got %ld for (%s)", #a2, (long)a2value, (long)a1value, #a1]; \ 1.124 + [self failWithException:([NSException failureInCondition:_expression \ 1.125 + isTrue:NO \ 1.126 + inFile:[NSString stringWithUTF8String:__FILE__] \ 1.127 + atLine:__LINE__ \ 1.128 + withDescription:@"%@", STComposeString(description, ##__VA_ARGS__)])]; \ 1.129 + } \ 1.130 + } \ 1.131 + @catch (id anException) { \ 1.132 + [self failWithException:[NSException failureInRaise:[NSString stringWithFormat:@"(%s) == (%s) fails", #a1, #a2] \ 1.133 + exception:anException \ 1.134 + inFile:[NSString stringWithUTF8String:__FILE__] \ 1.135 + atLine:__LINE__ \ 1.136 + withDescription:@"%@", STComposeString(description, ##__VA_ARGS__)]]; \ 1.137 + } \ 1.138 +} while(0) 1.139 + 1.140 + 1.141 +// Generates a failure when a1 is NULL 1.142 +// Args: 1.143 +// a1: should be a pointer (use STAssertNotNil for an object) 1.144 +// description: A format string as in the printf() function. Can be nil or 1.145 +// an empty string but must be present. 1.146 +// ...: A variable number of arguments to the format string. Can be absent. 1.147 +#define STAssertNotNULL(a1, description, ...) \ 1.148 +do { \ 1.149 + @try { \ 1.150 + __typeof__(a1) a1value = (a1); \ 1.151 + if (a1value == (__typeof__(a1))NULL) { \ 1.152 + NSString *_expression = [NSString stringWithFormat:@"((%s) != NULL)", #a1]; \ 1.153 + [self failWithException:([NSException failureInCondition:_expression \ 1.154 + isTrue:NO \ 1.155 + inFile:[NSString stringWithUTF8String:__FILE__] \ 1.156 + atLine:__LINE__ \ 1.157 + withDescription:@"%@", STComposeString(description, ##__VA_ARGS__)])]; \ 1.158 + } \ 1.159 + } \ 1.160 + @catch (id anException) { \ 1.161 + [self failWithException:[NSException failureInRaise:[NSString stringWithFormat:@"(%s) != NULL fails", #a1] \ 1.162 + exception:anException \ 1.163 + inFile:[NSString stringWithUTF8String:__FILE__] \ 1.164 + atLine:__LINE__ \ 1.165 + withDescription:@"%@", STComposeString(description, ##__VA_ARGS__)]]; \ 1.166 + } \ 1.167 +} while(0) 1.168 + 1.169 +// Generates a failure when a1 is not NULL 1.170 +// Args: 1.171 +// a1: should be a pointer (use STAssertNil for an object) 1.172 +// description: A format string as in the printf() function. Can be nil or 1.173 +// an empty string but must be present. 1.174 +// ...: A variable number of arguments to the format string. Can be absent. 1.175 +#define STAssertNULL(a1, description, ...) \ 1.176 +do { \ 1.177 + @try { \ 1.178 + __typeof__(a1) a1value = (a1); \ 1.179 + if (a1value != (__typeof__(a1))NULL) { \ 1.180 + NSString *_expression = [NSString stringWithFormat:@"((%s) == NULL)", #a1]; \ 1.181 + [self failWithException:([NSException failureInCondition:_expression \ 1.182 + isTrue:NO \ 1.183 + inFile:[NSString stringWithUTF8String:__FILE__] \ 1.184 + atLine:__LINE__ \ 1.185 + withDescription:@"%@", STComposeString(description, ##__VA_ARGS__)])]; \ 1.186 + } \ 1.187 + } \ 1.188 + @catch (id anException) { \ 1.189 + [self failWithException:[NSException failureInRaise:[NSString stringWithFormat:@"(%s) == NULL fails", #a1] \ 1.190 + exception:anException \ 1.191 + inFile:[NSString stringWithUTF8String:__FILE__] \ 1.192 + atLine:__LINE__ \ 1.193 + withDescription:@"%@", STComposeString(description, ##__VA_ARGS__)]]; \ 1.194 + } \ 1.195 +} while(0) 1.196 + 1.197 +// Generates a failure when a1 is equal to a2. This test is for C scalars, 1.198 +// structs and unions. 1.199 +// Args: 1.200 +// a1: argument 1 1.201 +// a2: argument 2 1.202 +// description: A format string as in the printf() function. Can be nil or 1.203 +// an empty string but must be present. 1.204 +// ...: A variable number of arguments to the format string. Can be absent. 1.205 +#define STAssertNotEquals(a1, a2, description, ...) \ 1.206 +do { \ 1.207 + @try { \ 1.208 + if (strcmp(@encode(__typeof__(a1)), @encode(__typeof__(a2)))) { \ 1.209 + [self failWithException:[NSException failureInFile:[NSString stringWithUTF8String:__FILE__] \ 1.210 + atLine:__LINE__ \ 1.211 + withDescription:@"Type mismatch -- %@", STComposeString(description, ##__VA_ARGS__)]]; \ 1.212 + } else { \ 1.213 + __typeof__(a1) a1value = (a1); \ 1.214 + __typeof__(a2) a2value = (a2); \ 1.215 + NSValue *a1encoded = [NSValue value:&a1value withObjCType:@encode(__typeof__(a1))]; \ 1.216 + NSValue *a2encoded = [NSValue value:&a2value withObjCType:@encode(__typeof__(a2))]; \ 1.217 + if ([a1encoded isEqualToValue:a2encoded]) { \ 1.218 + NSString *_expression = [NSString stringWithFormat:@"((%s) != (%s))", #a1, #a2]; \ 1.219 + [self failWithException:([NSException failureInCondition:_expression \ 1.220 + isTrue:NO \ 1.221 + inFile:[NSString stringWithUTF8String:__FILE__] \ 1.222 + atLine:__LINE__ \ 1.223 + withDescription:@"%@", STComposeString(description, ##__VA_ARGS__)])]; \ 1.224 + }\ 1.225 + } \ 1.226 + } \ 1.227 + @catch (id anException) { \ 1.228 + [self failWithException:[NSException failureInRaise:[NSString stringWithFormat:@"(%s) != (%s)", #a1, #a2] \ 1.229 + exception:anException \ 1.230 + inFile:[NSString stringWithUTF8String:__FILE__] \ 1.231 + atLine:__LINE__ \ 1.232 + withDescription:@"%@", STComposeString(description, ##__VA_ARGS__)]]; \ 1.233 + } \ 1.234 +} while(0) 1.235 + 1.236 +// Generates a failure when a1 is equal to a2. This test is for objects. 1.237 +// Args: 1.238 +// a1: argument 1. object. 1.239 +// a2: argument 2. object. 1.240 +// description: A format string as in the printf() function. Can be nil or 1.241 +// an empty string but must be present. 1.242 +// ...: A variable number of arguments to the format string. Can be absent. 1.243 +#define STAssertNotEqualObjects(a1, a2, description, ...) \ 1.244 +do { \ 1.245 + @try {\ 1.246 + id a1value = (a1); \ 1.247 + id a2value = (a2); \ 1.248 + if ( (strcmp(@encode(__typeof__(a1value)), @encode(id)) == 0) && \ 1.249 + (strcmp(@encode(__typeof__(a2value)), @encode(id)) == 0) && \ 1.250 + (![(id)a1value isEqual:(id)a2value]) ) continue; \ 1.251 + [self failWithException:([NSException failureInEqualityBetweenObject:a1value \ 1.252 + andObject:a2value \ 1.253 + inFile:[NSString stringWithUTF8String:__FILE__] \ 1.254 + atLine:__LINE__ \ 1.255 + withDescription:@"%@", STComposeString(description, ##__VA_ARGS__)])]; \ 1.256 + }\ 1.257 + @catch (id anException) {\ 1.258 + [self failWithException:([NSException failureInRaise:[NSString stringWithFormat:@"(%s) != (%s)", #a1, #a2] \ 1.259 + exception:anException \ 1.260 + inFile:[NSString stringWithUTF8String:__FILE__] \ 1.261 + atLine:__LINE__ \ 1.262 + withDescription:@"%@", STComposeString(description, ##__VA_ARGS__)])]; \ 1.263 + }\ 1.264 +} while(0) 1.265 + 1.266 +// Generates a failure when a1 is not 'op' to a2. This test is for C scalars. 1.267 +// Args: 1.268 +// a1: argument 1 1.269 +// a2: argument 2 1.270 +// op: operation 1.271 +// description: A format string as in the printf() function. Can be nil or 1.272 +// an empty string but must be present. 1.273 +// ...: A variable number of arguments to the format string. Can be absent. 1.274 +#define STAssertOperation(a1, a2, op, description, ...) \ 1.275 +do { \ 1.276 + @try { \ 1.277 + if (strcmp(@encode(__typeof__(a1)), @encode(__typeof__(a2)))) { \ 1.278 + [self failWithException:[NSException failureInFile:[NSString stringWithUTF8String:__FILE__] \ 1.279 + atLine:__LINE__ \ 1.280 + withDescription:@"Type mismatch -- %@", STComposeString(description, ##__VA_ARGS__)]]; \ 1.281 + } else { \ 1.282 + __typeof__(a1) a1value = (a1); \ 1.283 + __typeof__(a2) a2value = (a2); \ 1.284 + if (!(a1value op a2value)) { \ 1.285 + double a1DoubleValue = a1value; \ 1.286 + double a2DoubleValue = a2value; \ 1.287 + NSString *_expression = [NSString stringWithFormat:@"(%s (%lg) %s %s (%lg))", #a1, a1DoubleValue, #op, #a2, a2DoubleValue]; \ 1.288 + [self failWithException:([NSException failureInCondition:_expression \ 1.289 + isTrue:NO \ 1.290 + inFile:[NSString stringWithUTF8String:__FILE__] \ 1.291 + atLine:__LINE__ \ 1.292 + withDescription:@"%@", STComposeString(description, ##__VA_ARGS__)])]; \ 1.293 + } \ 1.294 + } \ 1.295 + } \ 1.296 + @catch (id anException) { \ 1.297 + [self failWithException:[NSException \ 1.298 + failureInRaise:[NSString stringWithFormat:@"(%s) %s (%s)", #a1, #op, #a2] \ 1.299 + exception:anException \ 1.300 + inFile:[NSString stringWithUTF8String:__FILE__] \ 1.301 + atLine:__LINE__ \ 1.302 + withDescription:@"%@", STComposeString(description, ##__VA_ARGS__)]]; \ 1.303 + } \ 1.304 +} while(0) 1.305 + 1.306 +// Generates a failure when a1 is not > a2. This test is for C scalars. 1.307 +// Args: 1.308 +// a1: argument 1 1.309 +// a2: argument 2 1.310 +// op: operation 1.311 +// description: A format string as in the printf() function. Can be nil or 1.312 +// an empty string but must be present. 1.313 +// ...: A variable number of arguments to the format string. Can be absent. 1.314 +#define STAssertGreaterThan(a1, a2, description, ...) \ 1.315 + STAssertOperation(a1, a2, >, description, ##__VA_ARGS__) 1.316 + 1.317 +// Generates a failure when a1 is not >= a2. This test is for C scalars. 1.318 +// Args: 1.319 +// a1: argument 1 1.320 +// a2: argument 2 1.321 +// op: operation 1.322 +// description: A format string as in the printf() function. Can be nil or 1.323 +// an empty string but must be present. 1.324 +// ...: A variable number of arguments to the format string. Can be absent. 1.325 +#define STAssertGreaterThanOrEqual(a1, a2, description, ...) \ 1.326 + STAssertOperation(a1, a2, >=, description, ##__VA_ARGS__) 1.327 + 1.328 +// Generates a failure when a1 is not < a2. This test is for C scalars. 1.329 +// Args: 1.330 +// a1: argument 1 1.331 +// a2: argument 2 1.332 +// op: operation 1.333 +// description: A format string as in the printf() function. Can be nil or 1.334 +// an empty string but must be present. 1.335 +// ...: A variable number of arguments to the format string. Can be absent. 1.336 +#define STAssertLessThan(a1, a2, description, ...) \ 1.337 + STAssertOperation(a1, a2, <, description, ##__VA_ARGS__) 1.338 + 1.339 +// Generates a failure when a1 is not <= a2. This test is for C scalars. 1.340 +// Args: 1.341 +// a1: argument 1 1.342 +// a2: argument 2 1.343 +// op: operation 1.344 +// description: A format string as in the printf() function. Can be nil or 1.345 +// an empty string but must be present. 1.346 +// ...: A variable number of arguments to the format string. Can be absent. 1.347 +#define STAssertLessThanOrEqual(a1, a2, description, ...) \ 1.348 + STAssertOperation(a1, a2, <=, description, ##__VA_ARGS__) 1.349 + 1.350 +// Generates a failure when string a1 is not equal to string a2. This call 1.351 +// differs from STAssertEqualObjects in that strings that are different in 1.352 +// composition (precomposed vs decomposed) will compare equal if their final 1.353 +// representation is equal. 1.354 +// ex O + umlaut decomposed is the same as O + umlaut composed. 1.355 +// Args: 1.356 +// a1: string 1 1.357 +// a2: string 2 1.358 +// description: A format string as in the printf() function. Can be nil or 1.359 +// an empty string but must be present. 1.360 +// ...: A variable number of arguments to the format string. Can be absent. 1.361 +#define STAssertEqualStrings(a1, a2, description, ...) \ 1.362 +do { \ 1.363 + @try { \ 1.364 + id a1value = (a1); \ 1.365 + id a2value = (a2); \ 1.366 + if (a1value == a2value) continue; \ 1.367 + if ([a1value isKindOfClass:[NSString class]] && \ 1.368 + [a2value isKindOfClass:[NSString class]] && \ 1.369 + [a1value compare:a2value options:0] == NSOrderedSame) continue; \ 1.370 + [self failWithException:[NSException failureInEqualityBetweenObject:a1value \ 1.371 + andObject:a2value \ 1.372 + inFile:[NSString stringWithUTF8String:__FILE__] \ 1.373 + atLine:__LINE__ \ 1.374 + withDescription:@"%@", STComposeString(description, ##__VA_ARGS__)]]; \ 1.375 + } \ 1.376 + @catch (id anException) { \ 1.377 + [self failWithException:[NSException failureInRaise:[NSString stringWithFormat:@"(%s) == (%s)", #a1, #a2] \ 1.378 + exception:anException \ 1.379 + inFile:[NSString stringWithUTF8String:__FILE__] \ 1.380 + atLine:__LINE__ \ 1.381 + withDescription:@"%@", STComposeString(description, ##__VA_ARGS__)]]; \ 1.382 + } \ 1.383 +} while(0) 1.384 + 1.385 +// Generates a failure when string a1 is equal to string a2. This call 1.386 +// differs from STAssertEqualObjects in that strings that are different in 1.387 +// composition (precomposed vs decomposed) will compare equal if their final 1.388 +// representation is equal. 1.389 +// ex O + umlaut decomposed is the same as O + umlaut composed. 1.390 +// Args: 1.391 +// a1: string 1 1.392 +// a2: string 2 1.393 +// description: A format string as in the printf() function. Can be nil or 1.394 +// an empty string but must be present. 1.395 +// ...: A variable number of arguments to the format string. Can be absent. 1.396 +#define STAssertNotEqualStrings(a1, a2, description, ...) \ 1.397 +do { \ 1.398 + @try { \ 1.399 + id a1value = (a1); \ 1.400 + id a2value = (a2); \ 1.401 + if ([a1value isKindOfClass:[NSString class]] && \ 1.402 + [a2value isKindOfClass:[NSString class]] && \ 1.403 + [a1value compare:a2value options:0] != NSOrderedSame) continue; \ 1.404 + [self failWithException:[NSException failureInEqualityBetweenObject:a1value \ 1.405 + andObject:a2value \ 1.406 + inFile:[NSString stringWithUTF8String:__FILE__] \ 1.407 + atLine:__LINE__ \ 1.408 + withDescription:@"%@", STComposeString(description, ##__VA_ARGS__)]]; \ 1.409 + } \ 1.410 + @catch (id anException) { \ 1.411 + [self failWithException:[NSException failureInRaise:[NSString stringWithFormat:@"(%s) != (%s)", #a1, #a2] \ 1.412 + exception:anException \ 1.413 + inFile:[NSString stringWithUTF8String:__FILE__] \ 1.414 + atLine:__LINE__ \ 1.415 + withDescription:@"%@", STComposeString(description, ##__VA_ARGS__)]]; \ 1.416 + } \ 1.417 +} while(0) 1.418 + 1.419 +// Generates a failure when c-string a1 is not equal to c-string a2. 1.420 +// Args: 1.421 +// a1: string 1 1.422 +// a2: string 2 1.423 +// description: A format string as in the printf() function. Can be nil or 1.424 +// an empty string but must be present. 1.425 +// ...: A variable number of arguments to the format string. Can be absent. 1.426 +#define STAssertEqualCStrings(a1, a2, description, ...) \ 1.427 +do { \ 1.428 + @try { \ 1.429 + const char* a1value = (a1); \ 1.430 + const char* a2value = (a2); \ 1.431 + if (a1value == a2value) continue; \ 1.432 + if (strcmp(a1value, a2value) == 0) continue; \ 1.433 + [self failWithException:[NSException failureInEqualityBetweenObject:[NSString stringWithUTF8String:a1value] \ 1.434 + andObject:[NSString stringWithUTF8String:a2value] \ 1.435 + inFile:[NSString stringWithUTF8String:__FILE__] \ 1.436 + atLine:__LINE__ \ 1.437 + withDescription:@"%@", STComposeString(description, ##__VA_ARGS__)]]; \ 1.438 + } \ 1.439 + @catch (id anException) { \ 1.440 + [self failWithException:[NSException failureInRaise:[NSString stringWithFormat:@"(%s) == (%s)", #a1, #a2] \ 1.441 + exception:anException \ 1.442 + inFile:[NSString stringWithUTF8String:__FILE__] \ 1.443 + atLine:__LINE__ \ 1.444 + withDescription:@"%@", STComposeString(description, ##__VA_ARGS__)]]; \ 1.445 + } \ 1.446 +} while(0) 1.447 + 1.448 +// Generates a failure when c-string a1 is equal to c-string a2. 1.449 +// Args: 1.450 +// a1: string 1 1.451 +// a2: string 2 1.452 +// description: A format string as in the printf() function. Can be nil or 1.453 +// an empty string but must be present. 1.454 +// ...: A variable number of arguments to the format string. Can be absent. 1.455 +#define STAssertNotEqualCStrings(a1, a2, description, ...) \ 1.456 +do { \ 1.457 + @try { \ 1.458 + const char* a1value = (a1); \ 1.459 + const char* a2value = (a2); \ 1.460 + if (strcmp(a1value, a2value) != 0) continue; \ 1.461 + [self failWithException:[NSException failureInEqualityBetweenObject:[NSString stringWithUTF8String:a1value] \ 1.462 + andObject:[NSString stringWithUTF8String:a2value] \ 1.463 + inFile:[NSString stringWithUTF8String:__FILE__] \ 1.464 + atLine:__LINE__ \ 1.465 + withDescription:@"%@", STComposeString(description, ##__VA_ARGS__)]]; \ 1.466 + } \ 1.467 + @catch (id anException) { \ 1.468 + [self failWithException:[NSException failureInRaise:[NSString stringWithFormat:@"(%s) != (%s)", #a1, #a2] \ 1.469 + exception:anException \ 1.470 + inFile:[NSString stringWithUTF8String:__FILE__] \ 1.471 + atLine:__LINE__ \ 1.472 + withDescription:@"%@", STComposeString(description, ##__VA_ARGS__)]]; \ 1.473 + } \ 1.474 +} while(0) 1.475 + 1.476 +/*" Generates a failure when a1 is not equal to a2 within + or - accuracy is false. 1.477 + This test is for GLKit types (GLKVector, GLKMatrix) where small differences 1.478 + could make these items not exactly equal. Do not use this version directly. 1.479 + Use the explicit STAssertEqualGLKVectors and STAssertEqualGLKMatrices defined 1.480 + below. 1.481 + _{a1 The GLKType on the left.} 1.482 + _{a2 The GLKType on the right.} 1.483 + _{accuracy The maximum difference between a1 and a2 for these values to be 1.484 + considered equal.} 1.485 + _{description A format string as in the printf() function. Can be nil or 1.486 + an empty string but must be present.} 1.487 + _{... A variable number of arguments to the format string. Can be absent.} 1.488 +"*/ 1.489 + 1.490 +#define STInternalAssertEqualGLKVectorsOrMatrices(a1, a2, accuracy, description, ...) \ 1.491 +do { \ 1.492 + @try { \ 1.493 + if (strcmp(@encode(__typeof__(a1)), @encode(__typeof__(a2)))) { \ 1.494 + [self failWithException:[NSException failureInFile:[NSString stringWithUTF8String:__FILE__] \ 1.495 + atLine:__LINE__ \ 1.496 + withDescription:@"Type mismatch -- %@", STComposeString(description, ##__VA_ARGS__)]]; \ 1.497 + } else { \ 1.498 + __typeof__(a1) a1GLKValue = (a1); \ 1.499 + __typeof__(a2) a2GLKValue = (a2); \ 1.500 + __typeof__(accuracy) accuracyvalue = (accuracy); \ 1.501 + float *a1FloatValue = ((float*)&a1GLKValue); \ 1.502 + float *a2FloatValue = ((float*)&a2GLKValue); \ 1.503 + for (size_t i = 0; i < sizeof(__typeof__(a1)) / sizeof(float); ++i) { \ 1.504 + float a1value = a1FloatValue[i]; \ 1.505 + float a2value = a2FloatValue[i]; \ 1.506 + if (STAbsoluteDifference(a1value, a2value) > accuracyvalue) { \ 1.507 + NSMutableArray *strings = [NSMutableArray arrayWithCapacity:sizeof(a1) / sizeof(float)]; \ 1.508 + NSString *string; \ 1.509 + for (size_t j = 0; j < sizeof(__typeof__(a1)) / sizeof(float); ++j) { \ 1.510 + string = [NSString stringWithFormat:@"(%0.3f == %0.3f)", a1FloatValue[j], a2FloatValue[j]]; \ 1.511 + [strings addObject:string]; \ 1.512 + } \ 1.513 + string = [strings componentsJoinedByString:@", "]; \ 1.514 + NSString *desc = STComposeString(description, ##__VA_ARGS__); \ 1.515 + desc = [NSString stringWithFormat:@"%@ With Accuracy %0.3f: %@", string, (float)accuracyvalue, desc]; \ 1.516 + [self failWithException:[NSException failureInFile:[NSString stringWithUTF8String:__FILE__] \ 1.517 + atLine:__LINE__ \ 1.518 + withDescription:@"%@", desc]]; \ 1.519 + break; \ 1.520 + } \ 1.521 + } \ 1.522 + } \ 1.523 + } \ 1.524 + @catch (id anException) { \ 1.525 + [self failWithException:[NSException failureInRaise:[NSString stringWithFormat:@"(%s) == (%s)", #a1, #a2] \ 1.526 + exception:anException \ 1.527 + inFile:[NSString stringWithUTF8String:__FILE__] \ 1.528 + atLine:__LINE__ \ 1.529 + withDescription:@"%@", STComposeString(description, ##__VA_ARGS__)]]; \ 1.530 + } \ 1.531 +} while(0) 1.532 + 1.533 +#define STAssertEqualGLKVectors(a1, a2, accuracy, description, ...) \ 1.534 + STInternalAssertEqualGLKVectorsOrMatrices(a1, a2, accuracy, description, ##__VA_ARGS__) 1.535 + 1.536 +#define STAssertEqualGLKMatrices(a1, a2, accuracy, description, ...) \ 1.537 + STInternalAssertEqualGLKVectorsOrMatrices(a1, a2, accuracy, description, ##__VA_ARGS__) 1.538 + 1.539 +#define STAssertEqualGLKQuaternions(a1, a2, accuracy, description, ...) \ 1.540 + STInternalAssertEqualGLKVectorsOrMatrices(a1, a2, accuracy, description, ##__VA_ARGS__) 1.541 + 1.542 +#if GTM_IPHONE_SDK && !GTM_IPHONE_USE_SENTEST 1.543 +// When not using the Xcode provided version, define everything ourselves. 1.544 + 1.545 +// SENTE_BEGIN 1.546 +/*" Generates a failure when !{ [a1 isEqualTo:a2] } is false 1.547 + (or one is nil and the other is not). 1.548 + _{a1 The object on the left.} 1.549 + _{a2 The object on the right.} 1.550 + _{description A format string as in the printf() function. Can be nil or 1.551 + an empty string but must be present.} 1.552 + _{... A variable number of arguments to the format string. Can be absent.} 1.553 +"*/ 1.554 +#define STAssertEqualObjects(a1, a2, description, ...) \ 1.555 +do { \ 1.556 + @try { \ 1.557 + id a1value = (a1); \ 1.558 + id a2value = (a2); \ 1.559 + if (a1value == a2value) continue; \ 1.560 + if ((strcmp(@encode(__typeof__(a1value)), @encode(id)) == 0) && \ 1.561 + (strcmp(@encode(__typeof__(a2value)), @encode(id)) == 0) && \ 1.562 + [(id)a1value isEqual:(id)a2value]) continue; \ 1.563 + [self failWithException:[NSException failureInEqualityBetweenObject:a1value \ 1.564 + andObject:a2value \ 1.565 + inFile:[NSString stringWithUTF8String:__FILE__] \ 1.566 + atLine:__LINE__ \ 1.567 + withDescription:@"%@", STComposeString(description, ##__VA_ARGS__)]]; \ 1.568 + } \ 1.569 + @catch (id anException) { \ 1.570 + [self failWithException:[NSException failureInRaise:[NSString stringWithFormat:@"(%s) == (%s)", #a1, #a2] \ 1.571 + exception:anException \ 1.572 + inFile:[NSString stringWithUTF8String:__FILE__] \ 1.573 + atLine:__LINE__ \ 1.574 + withDescription:@"%@", STComposeString(description, ##__VA_ARGS__)]]; \ 1.575 + } \ 1.576 +} while(0) 1.577 + 1.578 + 1.579 +/*" Generates a failure when a1 is not equal to a2. This test is for 1.580 + C scalars, structs and unions. 1.581 + _{a1 The argument on the left.} 1.582 + _{a2 The argument on the right.} 1.583 + _{description A format string as in the printf() function. Can be nil or 1.584 + an empty string but must be present.} 1.585 + _{... A variable number of arguments to the format string. Can be absent.} 1.586 +"*/ 1.587 +#define STAssertEquals(a1, a2, description, ...) \ 1.588 +do { \ 1.589 + @try { \ 1.590 + if (strcmp(@encode(__typeof__(a1)), @encode(__typeof__(a2)))) { \ 1.591 + [self failWithException:[NSException failureInFile:[NSString stringWithUTF8String:__FILE__] \ 1.592 + atLine:__LINE__ \ 1.593 + withDescription:@"Type mismatch -- %@", STComposeString(description, ##__VA_ARGS__)]]; \ 1.594 + } else { \ 1.595 + __typeof__(a1) a1value = (a1); \ 1.596 + __typeof__(a2) a2value = (a2); \ 1.597 + NSValue *a1encoded = [NSValue value:&a1value withObjCType:@encode(__typeof__(a1))]; \ 1.598 + NSValue *a2encoded = [NSValue value:&a2value withObjCType:@encode(__typeof__(a2))]; \ 1.599 + if (![a1encoded isEqualToValue:a2encoded]) { \ 1.600 + [self failWithException:[NSException failureInEqualityBetweenValue:a1encoded \ 1.601 + andValue:a2encoded \ 1.602 + withAccuracy:nil \ 1.603 + inFile:[NSString stringWithUTF8String:__FILE__] \ 1.604 + atLine:__LINE__ \ 1.605 + withDescription:@"%@", STComposeString(description, ##__VA_ARGS__)]]; \ 1.606 + } \ 1.607 + } \ 1.608 + } \ 1.609 + @catch (id anException) { \ 1.610 + [self failWithException:[NSException failureInRaise:[NSString stringWithFormat:@"(%s) == (%s)", #a1, #a2] \ 1.611 + exception:anException \ 1.612 + inFile:[NSString stringWithUTF8String:__FILE__] \ 1.613 + atLine:__LINE__ \ 1.614 + withDescription:@"%@", STComposeString(description, ##__VA_ARGS__)]]; \ 1.615 + } \ 1.616 +} while(0) 1.617 + 1.618 +#define STAbsoluteDifference(left,right) (MAX(left,right)-MIN(left,right)) 1.619 + 1.620 + 1.621 +/*" Generates a failure when a1 is not equal to a2 within + or - accuracy is false. 1.622 + This test is for scalars such as floats and doubles where small differences 1.623 + could make these items not exactly equal, but also works for all scalars. 1.624 + _{a1 The scalar on the left.} 1.625 + _{a2 The scalar on the right.} 1.626 + _{accuracy The maximum difference between a1 and a2 for these values to be 1.627 + considered equal.} 1.628 + _{description A format string as in the printf() function. Can be nil or 1.629 + an empty string but must be present.} 1.630 + _{... A variable number of arguments to the format string. Can be absent.} 1.631 +"*/ 1.632 + 1.633 +#define STAssertEqualsWithAccuracy(a1, a2, accuracy, description, ...) \ 1.634 +do { \ 1.635 + @try { \ 1.636 + if (strcmp(@encode(__typeof__(a1)), @encode(__typeof__(a2)))) { \ 1.637 + [self failWithException:[NSException failureInFile:[NSString stringWithUTF8String:__FILE__] \ 1.638 + atLine:__LINE__ \ 1.639 + withDescription:@"Type mismatch -- %@", STComposeString(description, ##__VA_ARGS__)]]; \ 1.640 + } else { \ 1.641 + __typeof__(a1) a1value = (a1); \ 1.642 + __typeof__(a2) a2value = (a2); \ 1.643 + __typeof__(accuracy) accuracyvalue = (accuracy); \ 1.644 + if (STAbsoluteDifference(a1value, a2value) > accuracyvalue) { \ 1.645 + NSValue *a1encoded = [NSValue value:&a1value withObjCType:@encode(__typeof__(a1))]; \ 1.646 + NSValue *a2encoded = [NSValue value:&a2value withObjCType:@encode(__typeof__(a2))]; \ 1.647 + NSValue *accuracyencoded = [NSValue value:&accuracyvalue withObjCType:@encode(__typeof__(accuracy))]; \ 1.648 + [self failWithException:[NSException failureInEqualityBetweenValue:a1encoded \ 1.649 + andValue:a2encoded \ 1.650 + withAccuracy:accuracyencoded \ 1.651 + inFile:[NSString stringWithUTF8String:__FILE__] \ 1.652 + atLine:__LINE__ \ 1.653 + withDescription:@"%@", STComposeString(description, ##__VA_ARGS__)]]; \ 1.654 + } \ 1.655 + } \ 1.656 + } \ 1.657 + @catch (id anException) { \ 1.658 + [self failWithException:[NSException failureInRaise:[NSString stringWithFormat:@"(%s) == (%s)", #a1, #a2] \ 1.659 + exception:anException \ 1.660 + inFile:[NSString stringWithUTF8String:__FILE__] \ 1.661 + atLine:__LINE__ \ 1.662 + withDescription:@"%@", STComposeString(description, ##__VA_ARGS__)]]; \ 1.663 + } \ 1.664 +} while(0) 1.665 + 1.666 + 1.667 + 1.668 +/*" Generates a failure unconditionally. 1.669 + _{description A format string as in the printf() function. Can be nil or 1.670 + an empty string but must be present.} 1.671 + _{... A variable number of arguments to the format string. Can be absent.} 1.672 +"*/ 1.673 +#define STFail(description, ...) \ 1.674 +[self failWithException:[NSException failureInFile:[NSString stringWithUTF8String:__FILE__] \ 1.675 + atLine:__LINE__ \ 1.676 + withDescription:@"%@", STComposeString(description, ##__VA_ARGS__)]] 1.677 + 1.678 + 1.679 + 1.680 +/*" Generates a failure when a1 is not nil. 1.681 + _{a1 An object.} 1.682 + _{description A format string as in the printf() function. Can be nil or 1.683 + an empty string but must be present.} 1.684 + _{... A variable number of arguments to the format string. Can be absent.} 1.685 +"*/ 1.686 +#define STAssertNil(a1, description, ...) \ 1.687 +do { \ 1.688 + @try { \ 1.689 + id a1value = (a1); \ 1.690 + if (a1value != nil) { \ 1.691 + NSString *_a1 = [NSString stringWithUTF8String:#a1]; \ 1.692 + NSString *_expression = [NSString stringWithFormat:@"((%@) == nil)", _a1]; \ 1.693 + [self failWithException:[NSException failureInCondition:_expression \ 1.694 + isTrue:NO \ 1.695 + inFile:[NSString stringWithUTF8String:__FILE__] \ 1.696 + atLine:__LINE__ \ 1.697 + withDescription:@"%@", STComposeString(description, ##__VA_ARGS__)]]; \ 1.698 + } \ 1.699 + } \ 1.700 + @catch (id anException) { \ 1.701 + [self failWithException:[NSException failureInRaise:[NSString stringWithFormat:@"(%s) == nil fails", #a1] \ 1.702 + exception:anException \ 1.703 + inFile:[NSString stringWithUTF8String:__FILE__] \ 1.704 + atLine:__LINE__ \ 1.705 + withDescription:@"%@", STComposeString(description, ##__VA_ARGS__)]]; \ 1.706 + } \ 1.707 +} while(0) 1.708 + 1.709 + 1.710 +/*" Generates a failure when a1 is nil. 1.711 + _{a1 An object.} 1.712 + _{description A format string as in the printf() function. Can be nil or 1.713 + an empty string but must be present.} 1.714 + _{... A variable number of arguments to the format string. Can be absent.} 1.715 +"*/ 1.716 +#define STAssertNotNil(a1, description, ...) \ 1.717 +do { \ 1.718 + @try { \ 1.719 + id a1value = (a1); \ 1.720 + if (a1value == nil) { \ 1.721 + NSString *_a1 = [NSString stringWithUTF8String:#a1]; \ 1.722 + NSString *_expression = [NSString stringWithFormat:@"((%@) != nil)", _a1]; \ 1.723 + [self failWithException:[NSException failureInCondition:_expression \ 1.724 + isTrue:NO \ 1.725 + inFile:[NSString stringWithUTF8String:__FILE__] \ 1.726 + atLine:__LINE__ \ 1.727 + withDescription:@"%@", STComposeString(description, ##__VA_ARGS__)]]; \ 1.728 + } \ 1.729 + } \ 1.730 + @catch (id anException) { \ 1.731 + [self failWithException:[NSException failureInRaise:[NSString stringWithFormat:@"(%s) != nil fails", #a1] \ 1.732 + exception:anException \ 1.733 + inFile:[NSString stringWithUTF8String:__FILE__] \ 1.734 + atLine:__LINE__ \ 1.735 + withDescription:@"%@", STComposeString(description, ##__VA_ARGS__)]]; \ 1.736 + } \ 1.737 +} while(0) 1.738 + 1.739 + 1.740 +/*" Generates a failure when expression evaluates to false. 1.741 + _{expr The expression that is tested.} 1.742 + _{description A format string as in the printf() function. Can be nil or 1.743 + an empty string but must be present.} 1.744 + _{... A variable number of arguments to the format string. Can be absent.} 1.745 +"*/ 1.746 +#define STAssertTrue(expr, description, ...) \ 1.747 +do { \ 1.748 + BOOL _evaluatedExpression = (expr); \ 1.749 + if (!_evaluatedExpression) { \ 1.750 + NSString *_expression = [NSString stringWithUTF8String:#expr]; \ 1.751 + [self failWithException:[NSException failureInCondition:_expression \ 1.752 + isTrue:NO \ 1.753 + inFile:[NSString stringWithUTF8String:__FILE__] \ 1.754 + atLine:__LINE__ \ 1.755 + withDescription:@"%@", STComposeString(description, ##__VA_ARGS__)]]; \ 1.756 + } \ 1.757 +} while (0) 1.758 + 1.759 + 1.760 +/*" Generates a failure when expression evaluates to false and in addition will 1.761 + generate error messages if an exception is encountered. 1.762 + _{expr The expression that is tested.} 1.763 + _{description A format string as in the printf() function. Can be nil or 1.764 + an empty string but must be present.} 1.765 + _{... A variable number of arguments to the format string. Can be absent.} 1.766 +"*/ 1.767 +#define STAssertTrueNoThrow(expr, description, ...) \ 1.768 +do { \ 1.769 + @try { \ 1.770 + BOOL _evaluatedExpression = (expr); \ 1.771 + if (!_evaluatedExpression) { \ 1.772 + NSString *_expression = [NSString stringWithUTF8String:#expr]; \ 1.773 + [self failWithException:[NSException failureInCondition:_expression \ 1.774 + isTrue:NO \ 1.775 + inFile:[NSString stringWithUTF8String:__FILE__] \ 1.776 + atLine:__LINE__ \ 1.777 + withDescription:@"%@", STComposeString(description, ##__VA_ARGS__)]]; \ 1.778 + } \ 1.779 + } \ 1.780 + @catch (id anException) { \ 1.781 + [self failWithException:[NSException failureInRaise:[NSString stringWithFormat:@"(%s) ", #expr] \ 1.782 + exception:anException \ 1.783 + inFile:[NSString stringWithUTF8String:__FILE__] \ 1.784 + atLine:__LINE__ \ 1.785 + withDescription:@"%@", STComposeString(description, ##__VA_ARGS__)]]; \ 1.786 + } \ 1.787 +} while (0) 1.788 + 1.789 + 1.790 +/*" Generates a failure when the expression evaluates to true. 1.791 + _{expr The expression that is tested.} 1.792 + _{description A format string as in the printf() function. Can be nil or 1.793 + an empty string but must be present.} 1.794 + _{... A variable number of arguments to the format string. Can be absent.} 1.795 +"*/ 1.796 +#define STAssertFalse(expr, description, ...) \ 1.797 +do { \ 1.798 + BOOL _evaluatedExpression = (expr); \ 1.799 + if (_evaluatedExpression) { \ 1.800 + NSString *_expression = [NSString stringWithUTF8String:#expr]; \ 1.801 + [self failWithException:[NSException failureInCondition:_expression \ 1.802 + isTrue:YES \ 1.803 + inFile:[NSString stringWithUTF8String:__FILE__] \ 1.804 + atLine:__LINE__ \ 1.805 + withDescription:@"%@", STComposeString(description, ##__VA_ARGS__)]]; \ 1.806 + } \ 1.807 +} while (0) 1.808 + 1.809 + 1.810 +/*" Generates a failure when the expression evaluates to true and in addition 1.811 + will generate error messages if an exception is encountered. 1.812 + _{expr The expression that is tested.} 1.813 + _{description A format string as in the printf() function. Can be nil or 1.814 + an empty string but must be present.} 1.815 + _{... A variable number of arguments to the format string. Can be absent.} 1.816 +"*/ 1.817 +#define STAssertFalseNoThrow(expr, description, ...) \ 1.818 +do { \ 1.819 + @try { \ 1.820 + BOOL _evaluatedExpression = (expr); \ 1.821 + if (_evaluatedExpression) { \ 1.822 + NSString *_expression = [NSString stringWithUTF8String:#expr]; \ 1.823 + [self failWithException:[NSException failureInCondition:_expression \ 1.824 + isTrue:YES \ 1.825 + inFile:[NSString stringWithUTF8String:__FILE__] \ 1.826 + atLine:__LINE__ \ 1.827 + withDescription:@"%@", STComposeString(description, ##__VA_ARGS__)]]; \ 1.828 + } \ 1.829 + } \ 1.830 + @catch (id anException) { \ 1.831 + [self failWithException:[NSException failureInRaise:[NSString stringWithFormat:@"!(%s) ", #expr] \ 1.832 + exception:anException \ 1.833 + inFile:[NSString stringWithUTF8String:__FILE__] \ 1.834 + atLine:__LINE__ \ 1.835 + withDescription:@"%@", STComposeString(description, ##__VA_ARGS__)]]; \ 1.836 + } \ 1.837 +} while (0) 1.838 + 1.839 + 1.840 +/*" Generates a failure when expression does not throw an exception. 1.841 + _{expression The expression that is evaluated.} 1.842 + _{description A format string as in the printf() function. Can be nil or 1.843 + an empty string but must be present.} 1.844 + _{... A variable number of arguments to the format string. Can be absent. 1.845 +"*/ 1.846 +#define STAssertThrows(expr, description, ...) \ 1.847 +do { \ 1.848 + @try { \ 1.849 + (expr); \ 1.850 + } \ 1.851 + @catch (id anException) { \ 1.852 + continue; \ 1.853 + } \ 1.854 + [self failWithException:[NSException failureInRaise:[NSString stringWithUTF8String:#expr] \ 1.855 + exception:nil \ 1.856 + inFile:[NSString stringWithUTF8String:__FILE__] \ 1.857 + atLine:__LINE__ \ 1.858 + withDescription:@"%@", STComposeString(description, ##__VA_ARGS__)]]; \ 1.859 +} while (0) 1.860 + 1.861 + 1.862 +/*" Generates a failure when expression does not throw an exception of a 1.863 + specific class. 1.864 + _{expression The expression that is evaluated.} 1.865 + _{specificException The specified class of the exception.} 1.866 + _{description A format string as in the printf() function. Can be nil or 1.867 + an empty string but must be present.} 1.868 + _{... A variable number of arguments to the format string. Can be absent.} 1.869 +"*/ 1.870 +#define STAssertThrowsSpecific(expr, specificException, description, ...) \ 1.871 +do { \ 1.872 + @try { \ 1.873 + (expr); \ 1.874 + } \ 1.875 + @catch (specificException *anException) { \ 1.876 + continue; \ 1.877 + } \ 1.878 + @catch (id anException) { \ 1.879 + NSString *_descrip = STComposeString(@"(Expected exception: %@) %@", NSStringFromClass([specificException class]), description); \ 1.880 + [self failWithException:[NSException failureInRaise:[NSString stringWithUTF8String:#expr] \ 1.881 + exception:anException \ 1.882 + inFile:[NSString stringWithUTF8String:__FILE__] \ 1.883 + atLine:__LINE__ \ 1.884 + withDescription:@"%@", STComposeString(_descrip, ##__VA_ARGS__)]]; \ 1.885 + continue; \ 1.886 + } \ 1.887 + NSString *_descrip = STComposeString(@"(Expected exception: %@) %@", NSStringFromClass([specificException class]), description); \ 1.888 + [self failWithException:[NSException failureInRaise:[NSString stringWithUTF8String:#expr] \ 1.889 + exception:nil \ 1.890 + inFile:[NSString stringWithUTF8String:__FILE__] \ 1.891 + atLine:__LINE__ \ 1.892 + withDescription:@"%@", STComposeString(_descrip, ##__VA_ARGS__)]]; \ 1.893 +} while (0) 1.894 + 1.895 + 1.896 +/*" Generates a failure when expression does not throw an exception of a 1.897 + specific class with a specific name. Useful for those frameworks like 1.898 + AppKit or Foundation that throw generic NSException w/specific names 1.899 + (NSInvalidArgumentException, etc). 1.900 + _{expression The expression that is evaluated.} 1.901 + _{specificException The specified class of the exception.} 1.902 + _{aName The name of the specified exception.} 1.903 + _{description A format string as in the printf() function. Can be nil or 1.904 + an empty string but must be present.} 1.905 + _{... A variable number of arguments to the format string. Can be absent.} 1.906 + 1.907 +"*/ 1.908 +#define STAssertThrowsSpecificNamed(expr, specificException, aName, description, ...) \ 1.909 +do { \ 1.910 + @try { \ 1.911 + (expr); \ 1.912 + } \ 1.913 + @catch (specificException *anException) { \ 1.914 + if ([aName isEqualToString:[anException name]]) continue; \ 1.915 + NSString *_descrip = STComposeString(@"(Expected exception: %@ (name: %@)) %@", NSStringFromClass([specificException class]), aName, description); \ 1.916 + [self failWithException: \ 1.917 + [NSException failureInRaise:[NSString stringWithUTF8String:#expr] \ 1.918 + exception:anException \ 1.919 + inFile:[NSString stringWithUTF8String:__FILE__] \ 1.920 + atLine:__LINE__ \ 1.921 + withDescription:@"%@", STComposeString(_descrip, ##__VA_ARGS__)]]; \ 1.922 + continue; \ 1.923 + } \ 1.924 + @catch (id anException) { \ 1.925 + NSString *_descrip = STComposeString(@"(Expected exception: %@) %@", NSStringFromClass([specificException class]), description); \ 1.926 + [self failWithException: \ 1.927 + [NSException failureInRaise:[NSString stringWithUTF8String:#expr] \ 1.928 + exception:anException \ 1.929 + inFile:[NSString stringWithUTF8String:__FILE__] \ 1.930 + atLine:__LINE__ \ 1.931 + withDescription:@"%@", STComposeString(_descrip, ##__VA_ARGS__)]]; \ 1.932 + continue; \ 1.933 + } \ 1.934 + NSString *_descrip = STComposeString(@"(Expected exception: %@) %@", NSStringFromClass([specificException class]), description); \ 1.935 + [self failWithException: \ 1.936 + [NSException failureInRaise:[NSString stringWithUTF8String:#expr] \ 1.937 + exception:nil \ 1.938 + inFile:[NSString stringWithUTF8String:__FILE__] \ 1.939 + atLine:__LINE__ \ 1.940 + withDescription:@"%@", STComposeString(_descrip, ##__VA_ARGS__)]]; \ 1.941 +} while (0) 1.942 + 1.943 + 1.944 +/*" Generates a failure when expression does throw an exception. 1.945 + _{expression The expression that is evaluated.} 1.946 + _{description A format string as in the printf() function. Can be nil or 1.947 + an empty string but must be present.} 1.948 + _{... A variable number of arguments to the format string. Can be absent.} 1.949 +"*/ 1.950 +#define STAssertNoThrow(expr, description, ...) \ 1.951 +do { \ 1.952 + @try { \ 1.953 + (expr); \ 1.954 + } \ 1.955 + @catch (id anException) { \ 1.956 + [self failWithException:[NSException failureInRaise:[NSString stringWithUTF8String:#expr] \ 1.957 + exception:anException \ 1.958 + inFile:[NSString stringWithUTF8String:__FILE__] \ 1.959 + atLine:__LINE__ \ 1.960 + withDescription:@"%@", STComposeString(description, ##__VA_ARGS__)]]; \ 1.961 + } \ 1.962 +} while (0) 1.963 + 1.964 + 1.965 +/*" Generates a failure when expression does throw an exception of the specitied 1.966 + class. Any other exception is okay (i.e. does not generate a failure). 1.967 + _{expression The expression that is evaluated.} 1.968 + _{specificException The specified class of the exception.} 1.969 + _{description A format string as in the printf() function. Can be nil or 1.970 + an empty string but must be present.} 1.971 + _{... A variable number of arguments to the format string. Can be absent.} 1.972 +"*/ 1.973 +#define STAssertNoThrowSpecific(expr, specificException, description, ...) \ 1.974 +do { \ 1.975 + @try { \ 1.976 + (expr); \ 1.977 + } \ 1.978 + @catch (specificException *anException) { \ 1.979 + [self failWithException:[NSException failureInRaise:[NSString stringWithUTF8String:#expr] \ 1.980 + exception:anException \ 1.981 + inFile:[NSString stringWithUTF8String:__FILE__] \ 1.982 + atLine:__LINE__ \ 1.983 + withDescription:@"%@", STComposeString(description, ##__VA_ARGS__)]]; \ 1.984 + } \ 1.985 + @catch (id anythingElse) { \ 1.986 + ; \ 1.987 + } \ 1.988 +} while (0) 1.989 + 1.990 + 1.991 +/*" Generates a failure when expression does throw an exception of a 1.992 + specific class with a specific name. Useful for those frameworks like 1.993 + AppKit or Foundation that throw generic NSException w/specific names 1.994 + (NSInvalidArgumentException, etc). 1.995 + _{expression The expression that is evaluated.} 1.996 + _{specificException The specified class of the exception.} 1.997 + _{aName The name of the specified exception.} 1.998 + _{description A format string as in the printf() function. Can be nil or 1.999 + an empty string but must be present.} 1.1000 + _{... A variable number of arguments to the format string. Can be absent.} 1.1001 + 1.1002 +"*/ 1.1003 +#define STAssertNoThrowSpecificNamed(expr, specificException, aName, description, ...) \ 1.1004 +do { \ 1.1005 + @try { \ 1.1006 + (expr); \ 1.1007 + } \ 1.1008 + @catch (specificException *anException) { \ 1.1009 + if ([aName isEqualToString:[anException name]]) { \ 1.1010 + NSString *_descrip = STComposeString(@"(Expected exception: %@ (name: %@)) %@", NSStringFromClass([specificException class]), aName, description); \ 1.1011 + [self failWithException: \ 1.1012 + [NSException failureInRaise:[NSString stringWithUTF8String:#expr] \ 1.1013 + exception:anException \ 1.1014 + inFile:[NSString stringWithUTF8String:__FILE__] \ 1.1015 + atLine:__LINE__ \ 1.1016 + withDescription:@"%@", STComposeString(_descrip, ##__VA_ARGS__)]]; \ 1.1017 + } \ 1.1018 + continue; \ 1.1019 + } \ 1.1020 + @catch (id anythingElse) { \ 1.1021 + ; \ 1.1022 + } \ 1.1023 +} while (0) 1.1024 + 1.1025 + 1.1026 + 1.1027 +@interface NSException (GTMSenTestAdditions) 1.1028 ++ (NSException *)failureInFile:(NSString *)filename 1.1029 + atLine:(int)lineNumber 1.1030 + withDescription:(NSString *)formatString, ... NS_FORMAT_FUNCTION(3, 4); 1.1031 ++ (NSException *)failureInCondition:(NSString *)condition 1.1032 + isTrue:(BOOL)isTrue 1.1033 + inFile:(NSString *)filename 1.1034 + atLine:(int)lineNumber 1.1035 + withDescription:(NSString *)formatString, ... NS_FORMAT_FUNCTION(5, 6); 1.1036 ++ (NSException *)failureInEqualityBetweenObject:(id)left 1.1037 + andObject:(id)right 1.1038 + inFile:(NSString *)filename 1.1039 + atLine:(int)lineNumber 1.1040 + withDescription:(NSString *)formatString, ... NS_FORMAT_FUNCTION(5, 6); 1.1041 ++ (NSException *)failureInEqualityBetweenValue:(NSValue *)left 1.1042 + andValue:(NSValue *)right 1.1043 + withAccuracy:(NSValue *)accuracy 1.1044 + inFile:(NSString *)filename 1.1045 + atLine:(int) ineNumber 1.1046 + withDescription:(NSString *)formatString, ... NS_FORMAT_FUNCTION(6, 7); 1.1047 ++ (NSException *)failureInRaise:(NSString *)expression 1.1048 + inFile:(NSString *)filename 1.1049 + atLine:(int)lineNumber 1.1050 + withDescription:(NSString *)formatString, ... NS_FORMAT_FUNCTION(4, 5); 1.1051 ++ (NSException *)failureInRaise:(NSString *)expression 1.1052 + exception:(NSException *)exception 1.1053 + inFile:(NSString *)filename 1.1054 + atLine:(int)lineNumber 1.1055 + withDescription:(NSString *)formatString, ... NS_FORMAT_FUNCTION(5, 6); 1.1056 +@end 1.1057 + 1.1058 +// SENTE_END 1.1059 + 1.1060 +@protocol SenTestCase 1.1061 ++ (id)testCaseWithInvocation:(NSInvocation *)anInvocation; 1.1062 +- (id)initWithInvocation:(NSInvocation *)anInvocation; 1.1063 +- (void)setUp; 1.1064 +- (void)invokeTest; 1.1065 +- (void)tearDown; 1.1066 +- (void)performTest; 1.1067 +- (void)failWithException:(NSException*)exception; 1.1068 +- (NSInvocation *)invocation; 1.1069 +- (SEL)selector; 1.1070 ++ (NSArray *)testInvocations; 1.1071 +@end 1.1072 + 1.1073 +@interface SenTestCase : NSObject<SenTestCase> { 1.1074 + @private 1.1075 + NSInvocation *invocation_; 1.1076 +} 1.1077 +@end 1.1078 + 1.1079 +GTM_EXTERN NSString *const SenTestFailureException; 1.1080 + 1.1081 +GTM_EXTERN NSString *const SenTestFilenameKey; 1.1082 +GTM_EXTERN NSString *const SenTestLineNumberKey; 1.1083 + 1.1084 +#endif // GTM_IPHONE_SDK && !GTM_IPHONE_USE_SENTEST 1.1085 + 1.1086 +// All unittest cases in GTM should inherit from GTMTestCase. It makes sure 1.1087 +// to set up our logging system correctly to verify logging calls. 1.1088 +// See GTMUnitTestDevLog.h for details 1.1089 +@interface GTMTestCase : SenTestCase 1.1090 + 1.1091 +// Returns YES if this is an abstract testCase class as opposed to a concrete 1.1092 +// testCase class that you want tests run against. SenTestCase is not designed 1.1093 +// out of the box to handle an abstract class hierarchy descending from it with 1.1094 +// some concrete subclasses. In some cases we want all the "concrete" 1.1095 +// subclasses of an abstract subclass of SenTestCase to run a test, but we don't 1.1096 +// want that test to be run against an instance of an abstract subclass itself. 1.1097 +// By returning "YES" here, the tests defined by this class won't be run against 1.1098 +// an instance of this class. As an example class hierarchy: 1.1099 +// 1.1100 +// FooExtensionTestCase 1.1101 +// GTMTestCase <- ExtensionAbstractTestCase < 1.1102 +// BarExtensionTestCase 1.1103 +// 1.1104 +// So FooExtensionTestCase and BarExtensionTestCase inherit from 1.1105 +// ExtensionAbstractTestCase (and probably FooExtension and BarExtension inherit 1.1106 +// from a class named Extension). We want the tests in ExtensionAbstractTestCase 1.1107 +// to be run as part of FooExtensionTestCase and BarExtensionTestCase, but we 1.1108 +// don't want them run against ExtensionAbstractTestCase. The default 1.1109 +// implementation checks to see if the name of the class contains the word 1.1110 +// "AbstractTest" (case sensitive). 1.1111 ++ (BOOL)isAbstractTestCase; 1.1112 + 1.1113 +@end