PageRenderTime 55ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/core/externals/update-engine/externals/google-toolbox-for-mac/UnitTesting/GTMSenTestCase.h

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