]> git.saurik.com Git - apple/security.git/blob - SecurityTests/regressions/test/testmore.h
Security-57740.1.18.tar.gz
[apple/security.git] / SecurityTests / regressions / test / testmore.h
1 /*
2 * Copyright (c) 2005-2006 Apple Computer, 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 * testmore.h
24 */
25
26 #ifndef _TESTMORE_H_
27 #define _TESTMORE_H_ 1
28
29 #include <errno.h>
30 #include <string.h>
31 #include <stdio.h>
32 #include <CoreServices/../Frameworks/CarbonCore.framework/Headers/MacTypes.h>
33
34 #ifdef __cplusplus
35 extern "C" {
36 #endif
37
38 #define ok(THIS, TESTNAME) \
39 test_ok(!!(THIS), TESTNAME, test_directive, test_reason, \
40 __FILE__, __LINE__, NULL)
41 #define is(THIS, THAT, TESTNAME) \
42 ({ \
43 __typeof__(THIS) _this = (THIS); \
44 __typeof__(THAT) _that = (THAT); \
45 test_ok((_this == _that), TESTNAME, test_directive, test_reason, \
46 __FILE__, __LINE__, \
47 "# got: '%d'\n" \
48 "# expected: '%d'\n", \
49 _this, _that); \
50 })
51 #define isnt(THIS, THAT, TESTNAME) \
52 cmp_ok((THIS), !=, (THAT), (TESTNAME))
53 #define diag(MSG, ARGS...) \
54 test_diag(test_directive, test_reason, __FILE__, __LINE__, MSG, ## ARGS)
55 #define cmp_ok(THIS, OP, THAT, TESTNAME) \
56 ({ \
57 __typeof__(THIS) _this = (THIS); \
58 __typeof__(THAT) _that = (THAT); \
59 test_ok((_this OP _that), TESTNAME, test_directive, test_reason, \
60 __FILE__, __LINE__, \
61 "# '%d'\n" \
62 "# " #OP "\n" \
63 "# '%d'\n", \
64 _this, _that); \
65 })
66 #define eq_string(THIS, THAT, TESTNAME) \
67 ({ \
68 const char *_this = (THIS); \
69 const char *_that = (THAT); \
70 test_ok(!strcmp(_this, _that), TESTNAME, test_directive, test_reason, \
71 __FILE__, __LINE__, \
72 "# '%s'\n" \
73 "# eq\n" \
74 "# '%s'\n", \
75 _this, _that); \
76 })
77 #define eq_stringn(THIS, THISLEN, THAT, THATLEN, TESTNAME) \
78 ({ \
79 __typeof__(THISLEN) _thislen = (THISLEN); \
80 __typeof__(THATLEN) _thatlen = (THATLEN); \
81 const char *_this = (THIS); \
82 const char *_that = (THAT); \
83 test_ok(_thislen == _thatlen && !strncmp(_this, _that, _thislen), \
84 TESTNAME, test_directive, test_reason, \
85 __FILE__, __LINE__, \
86 "# '%.*s'\n" \
87 "# eq\n" \
88 "# '%.*s'\n", \
89 (int)_thislen, _this, (int)_thatlen, _that); \
90 })
91 #define like(THIS, REGEXP, TESTNAME) like_not_yet_implemented()
92 #define unlike(THIS, REGEXP, TESTNAME) unlike_not_yet_implemented()
93 #define is_deeply(STRUCT1, STRUCT2, TESTNAME) is_deeply_not_yet_implemented()
94 #define TODO switch(0) default
95 #define SKIP switch(0) default
96 #define SETUP switch(0) default
97 #define todo(REASON) const char *test_directive __attribute__((unused)) = "TODO", \
98 *test_reason __attribute__((unused)) = (REASON)
99 #define skip(WHY, HOW_MANY, UNLESS) if (!(UNLESS)) \
100 { test_skip((WHY), (HOW_MANY), 0); break; }
101 #define setup(REASON) const char *test_directive = "SETUP", \
102 *test_reason = (REASON)
103 #define pass(TESTNAME) ok(1, (TESTNAME))
104 #define fail(TESTNAME) ok(0, (TESTNAME))
105 #define BAIL_OUT(WHY) test_bail_out(WHY, __FILE__, __LINE__)
106 #define plan_skip_all(REASON) test_plan_skip_all(REASON)
107 #define plan_tests(COUNT) test_plan_tests(COUNT, __FILE__, __LINE__)
108
109 #define ok_status(THIS, TESTNAME) \
110 ({ \
111 OSStatus _this = (THIS); \
112 test_ok(!_this, TESTNAME, test_directive, test_reason, \
113 __FILE__, __LINE__, \
114 "# status: %s(%ld)\n", \
115 sec_errstr(_this), _this); \
116 })
117 #define is_status(THIS, THAT, TESTNAME) \
118 ({ \
119 OSStatus _this = (THIS); \
120 OSStatus _that = (THAT); \
121 test_ok(_this == _that, TESTNAME, test_directive, test_reason, \
122 __FILE__, __LINE__, \
123 "# got: %s(%ld)\n" \
124 "# expected: %s(%ld)\n", \
125 sec_errstr(_this), _this, sec_errstr(_that), _that); \
126 })
127 #define ok_unix(THIS, TESTNAME) \
128 ({ \
129 int _this = (THIS) < 0 ? errno : 0; \
130 test_ok(!_this, TESTNAME, test_directive, test_reason, \
131 __FILE__, __LINE__, \
132 "# got: %s(%d)\n", \
133 strerror(_this), _this); \
134 })
135 #define is_unix(THIS, THAT, TESTNAME) \
136 ({ \
137 int _result = (THIS); \
138 int _this = _result < 0 ? errno : 0; \
139 int _that = (THAT); \
140 _that && _result < 0 \
141 ? test_ok(_this == _that, TESTNAME, test_directive, test_reason, \
142 __FILE__, __LINE__, \
143 "# got: %s(%d)\n" \
144 "# expected: %s(%d)\n", \
145 strerror(_this), _this, strerror(_that), _that) \
146 : test_ok(_this == _that, TESTNAME, test_directive, test_reason, \
147 __FILE__, __LINE__, \
148 "# got: %d\n" \
149 "# expected errno: %s(%d)\n", \
150 _result, strerror(_that), _that); \
151 })
152
153
154 extern const char *test_directive;
155 extern const char *test_reason;
156
157 void test_bail_out(const char *reason, const char *file, unsigned line);
158 int test_diag(const char *directive, const char *reason,
159 const char *file, unsigned line, const char *fmt, ...);
160 int test_ok(int passed, const char *description, const char *directive,
161 const char *reason, const char *file, unsigned line, const char *fmt, ...);
162 void test_plan_skip_all(const char *reason);
163 void test_plan_tests(int count, const char *file, unsigned line);
164 void test_skip(const char *reason, int how_many, int unless);
165
166 const char *sec_errstr(int err);
167
168 #ifdef __cplusplus
169 }
170 #endif /* __cplusplus */
171
172 #endif /* !_TESTMORE_H_ */