]> git.saurik.com Git - apple/security.git/blob - Security/regressions/test/testcpp.h
Security-57031.40.6.tar.gz
[apple/security.git] / Security / regressions / test / testcpp.h
1 /*
2 * Copyright (c) 2005-2007,2012 Apple Inc. All Rights Reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 *
23 * testcpp.h
24 */
25
26 #ifndef _TESTCPP_H_
27 #define _TESTCPP_H_ 1
28
29 #include "testmore.h"
30
31 #ifdef __cplusplus
32
33 #define no_throw(THIS, TESTNAME) \
34 ({ \
35 bool _this; \
36 try { THIS; _this = true; } catch (...) { _this = false; } \
37 test_ok(_this, TESTNAME, test_directive, test_reason, \
38 __FILE__, __LINE__, \
39 "# got: <unknown exception>\n" \
40 "# expected: <no throw>\n"); \
41 })
42 #define does_throw(THIS, TESTNAME) \
43 ({ \
44 bool _this; \
45 try { THIS; _this = false; } catch (...) { _this = true; } \
46 test_ok(_this, TESTNAME, test_directive, test_reason, \
47 __FILE__, __LINE__, \
48 "# got: <no throw>\n" \
49 "# expected: <any exception>\n"); \
50 })
51 #define is_throw(THIS, CLASS, METHOD, VALUE, TESTNAME) \
52 ({ \
53 bool _this; \
54 try \
55 { \
56 THIS; \
57 _this = test_ok(false, TESTNAME, test_directive, test_reason, \
58 __FILE__, __LINE__, \
59 "# got: <no throw>\n" \
60 "# expected: %s.%s == %s\n", \
61 #CLASS, #METHOD, #VALUE); \
62 } \
63 catch (const CLASS &_exception) \
64 { \
65 _this = test_ok(_exception.METHOD == (VALUE), TESTNAME, \
66 test_directive, test_reason, __FILE__, __LINE__, \
67 "# got: %d\n" \
68 "# expected: %s.%s == %s\n", \
69 _exception.METHOD, #CLASS, #METHOD, #VALUE); \
70 } \
71 catch (...) \
72 { \
73 _this = test_ok(false, TESTNAME, test_directive, test_reason, \
74 __FILE__, __LINE__, \
75 "# got: <unknown exception>\n" \
76 "# expected: %s.%s == %s\n", \
77 #CLASS, #METHOD, #VALUE); \
78 } \
79 _this; \
80 })
81 #endif /* __cplusplus */
82
83 #endif /* !_TESTCPP_H_ */