]>
git.saurik.com Git - apple/security.git/blob - SecurityTests/regressions/test/testmore.c
2 * Copyright (c) 2005 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@
31 #include <sys/types.h>
33 #include <AvailabilityMacros.h>
34 #include <Security/cssmapple.h>
38 static int test_num
= 0;
39 static int test_fails
= 0;
40 static int test_cases
= 0;
42 const char *test_directive
= NULL
;
43 const char *test_reason
= NULL
;
45 void test_skip(const char *reason
, int how_many
, int unless
)
51 for (done
= 0; done
< how_many
; ++done
)
52 test_ok(1, NULL
, "skip", reason
, __FILE__
, __LINE__
, NULL
);
55 void test_bail_out(const char *reason
, const char *file
, unsigned line
)
57 printf("BAIL OUT! (%s at line %u) %s\n", file
, line
, reason
);
62 void test_plan_skip_all(const char *reason
)
64 if (test_num
> test_cases
)
66 test_skip(reason
, test_cases
- test_num
, 0);
67 exit(test_fails
> 255 ? 255 : test_fails
);
71 static void test_plan_exit(void)
80 fprintf(stderr
, "# No tests run!\n");
85 fprintf(stderr
, "# Looks like your test died before it could "
86 "output anything.\n");
90 else if (test_num
< test_cases
)
92 fprintf(stderr
, "# Looks like you planned %d tests but only ran %d.\n",
93 test_cases
, test_num
);
94 status
= test_fails
+ test_cases
- test_num
;
96 else if (test_num
> test_cases
)
98 fprintf(stderr
, "# Looks like you planned %d tests but ran %d extra.\n",
99 test_cases
, test_num
- test_cases
);
104 fprintf(stderr
, "# Looks like you failed %d tests of %d.\n",
105 test_fails
, test_cases
);
111 _exit(status
> 255 ? 255 : status
);
114 void test_plan_tests(int count
, const char *file
, unsigned line
)
116 if (atexit(test_plan_exit
) < 0)
118 fprintf(stderr
, "failed to setup atexit handler: %s\n",
127 "You tried to plan twice! Second plan at %s line %u\n",
136 fprintf(stderr
, "You said to run 0 tests! You've got to run "
143 printf("1..%d\n", test_cases
);
149 test_diag(const char *directive
, const char *reason
,
150 const char *file
, unsigned line
, const char *fmt
, ...)
152 int is_todo
= directive
&& !strcmp(directive
, "TODO");
170 vfprintf(stderr
, fmt
, args
);
181 test_ok(int passed
, const char *description
, const char *directive
,
182 const char *reason
, const char *file
, unsigned line
,
183 const char *fmt
, ...)
185 int is_todo
= !passed
&& directive
&& !strcmp(directive
, "TODO");
186 int is_setup
= directive
&& !is_todo
&& !strcmp(directive
, "SETUP");
193 fprintf(stderr
, "# SETUP not ok%s%s%s%s\n",
194 description
? " - " : "",
195 description
? description
: "",
197 reason
? reason
: "");
204 atexit(test_plan_exit
);
205 fprintf(stderr
, "You tried to run a test without a plan! "
206 "Gotta have a plan. at %s line %u\n", file
, line
);
212 if (test_num
> test_cases
|| (!passed
&& !is_todo
))
215 printf("%sok %d%s%s%s%s%s%s\n", passed
? "" : "not ", test_num
,
216 description
? " - " : "",
217 description
? description
: "",
218 directive
? " # " : "",
219 directive
? directive
: "",
221 reason
? reason
: "");
234 printf("# Failed (TODO) test (%s at line %u)\n", file
, line
);
242 fprintf(stderr
, "# Failed test (%s at line %u)\n", file
, line
);
244 vfprintf(stderr
, fmt
, args
);
258 if (err
>= errSecErrnoBase
&& err
<= errSecErrnoLimit
)
259 return strerror(err
- 100000);
261 #ifdef MAC_OS_X_VERSION_10_4
262 /* AvailabilityMacros.h would only define this if we are on a
263 Tiger or later machine. */
264 extern const char *cssmErrorString(long);
265 return cssmErrorString(err
);
268 extern const char *_ZN8Security15cssmErrorStringEl(long);
269 return _ZN8Security15cssmErrorStringEl(err
);