]>
git.saurik.com Git - apple/security.git/blob - SecurityTests/regressions/test/testmore.h
2 * Copyright (c) 2005-2006 Apple Computer, Inc. All Rights Reserved.
4 * @APPLE_LICENSE_HEADER_START@
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
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.
21 * @APPLE_LICENSE_HEADER_END@
27 #define _TESTMORE_H_ 1
32 #include <CoreServices/../Frameworks/CarbonCore.framework/Headers/MacTypes.h>
38 #define ok(THIS, TESTNAME) \
39 test_ok(!!(THIS), TESTNAME, test_directive, test_reason, \
40 __FILE__, __LINE__, NULL)
41 #define is(THIS, THAT, TESTNAME) \
43 __typeof__(THIS) _this = (THIS); \
44 __typeof__(THAT) _that = (THAT); \
45 test_ok((_this == _that), TESTNAME, test_directive, test_reason, \
48 "# expected: '%d'\n", \
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) \
57 __typeof__(THIS) _this = (THIS); \
58 __typeof__(THAT) _that = (THAT); \
59 test_ok((_this OP _that), TESTNAME, test_directive, test_reason, \
66 #define eq_string(THIS, THAT, TESTNAME) \
68 const char *_this = (THIS); \
69 const char *_that = (THAT); \
70 test_ok(!strcmp(_this, _that), TESTNAME, test_directive, test_reason, \
77 #define eq_stringn(THIS, THISLEN, THAT, THATLEN, TESTNAME) \
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, \
89 (int)_thislen, _this, (int)_thatlen, _that); \
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__)
109 #define ok_status(THIS, TESTNAME) \
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); \
117 #define is_status(THIS, THAT, TESTNAME) \
119 OSStatus _this = (THIS); \
120 OSStatus _that = (THAT); \
121 test_ok(_this == _that, TESTNAME, test_directive, test_reason, \
122 __FILE__, __LINE__, \
124 "# expected: %s(%ld)\n", \
125 sec_errstr(_this), _this, sec_errstr(_that), _that); \
127 #define ok_unix(THIS, TESTNAME) \
129 int _this = (THIS) < 0 ? errno : 0; \
130 test_ok(!_this, TESTNAME, test_directive, test_reason, \
131 __FILE__, __LINE__, \
133 strerror(_this), _this); \
135 #define is_unix(THIS, THAT, TESTNAME) \
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__, \
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__, \
149 "# expected errno: %s(%d)\n", \
150 _result, strerror(_that), _that); \
154 extern const char *test_directive
;
155 extern const char *test_reason
;
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
);
166 const char *sec_errstr(int err
);
170 #endif /* __cplusplus */
172 #endif /* !_TESTMORE_H_ */