2 * This file is part of DisOrder.
3 * Copyright (C) 2005, 2007, 2008 Richard Kettlewell
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 /** @file libtests/test.c @brief Library tests */
24 long long tests, errors;
29 void count_error(void) {
35 const char *format(const char *s) {
41 while((c = (unsigned char)*s++)) {
42 if(c >= ' ' && c <= '~')
45 sprintf(buf, "\\x%02X", (unsigned)c);
46 dynstr_append_string(&d, buf);
53 const char *format_utf32(const uint32_t *s) {
60 sprintf(buf, " %04lX", (long)c);
61 dynstr_append_string(&d, buf);
67 uint32_t *ucs4parse(const char *s) {
74 dynstr_ucs4_append(&d, strtoul(s, &e, 0));
75 if(errno) fatal(errno, "strtoul (%s)", s);
78 dynstr_ucs4_terminate(&d);
82 const char *do_printf(const char *fmt, ...) {
88 rc = byte_vasprintf(&s, fmt, ap);
97 void test_exitfn(int rc) {
99 longjmp(fatal_env, rc);
102 static const struct option options[] = {
103 { "verbose", no_argument, 0, 'v' },
104 { "fail-first", no_argument, 0, 'F' },
105 { "help", no_argument, 0, 'h' },
106 { "version", no_argument, 0, 'V' },
109 /* display usage message and terminate */
110 static void help(void) {
114 " --help, -h Display usage message\n"
115 " --version, -V Display version number\n"
116 " --verbose, -v Verbose output\n"
117 " --fail-first, -F Stop on first failure\n",
123 void test_init(int argc, char **argv) {
128 while((n = getopt_long(argc, argv, "vFhV", options, 0)) >= 0) {
130 case 'v': verbose = 1; break;
131 case 'F': fail_first = 1; break;
133 case 'V': version(progname);
137 if(getenv("FAIL_FIRST"))