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 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * 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, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 /** @file lib/test.h @brief Library tests */
29 #include <sys/types.h>
35 #include <sys/socket.h>
37 #include <netinet/in.h>
49 #include "inputline.h"
55 #include "selection.h"
62 #include "configuration.h"
68 extern long long tests, errors;
69 extern int fail_first;
72 /** @brief Checks that @p expr is nonzero */
73 #define insist(expr) do { \
76 fprintf(stderr, "%s:%d: error checking %s\n", \
77 __FILE__, __LINE__, #expr); \
82 #define check_string(GOT, WANT) do { \
83 const char *got = GOT; \
84 const char *want = WANT; \
87 fprintf(stderr, "%s:%d: %s returned 0\n", \
88 __FILE__, __LINE__, #GOT); \
90 } else if(strcmp(want, got)) { \
91 fprintf(stderr, "%s:%d: %s returned:\n%s\nexpected:\n%s\n", \
92 __FILE__, __LINE__, #GOT, format(got), format(want)); \
98 #define check_string_prefix(GOT, WANT) do { \
99 const char *got = GOT; \
100 const char *want = WANT; \
103 fprintf(stderr, "%s:%d: %s returned 0\n", \
104 __FILE__, __LINE__, #GOT); \
106 } else if(strncmp(want, got, strlen(want))) { \
107 fprintf(stderr, "%s:%d: %s returned:\n%s\nexpected:\n%s...\n", \
108 __FILE__, __LINE__, #GOT, format(got), format(want)); \
114 #define check_integer(GOT, WANT) do { \
115 const intmax_t got = GOT, want = WANT; \
117 fprintf(stderr, "%s:%d: %s returned: %jd expected: %jd\n", \
118 __FILE__, __LINE__, #GOT, got, want); \
124 void count_error(void);
125 const char *format(const char *s);
126 const char *format_utf32(const uint32_t *s);
127 uint32_t *ucs4parse(const char *s);
128 const char *do_printf(const char *fmt, ...);
129 void test_init(int argc, char **argv);
132 int main(int argc, char **argv) { \
133 test_init(argc, argv); \
135 if(errors || verbose) \
136 fprintf(stderr, "test_"#name": %lld errors out of %lld tests\n", \
141 struct swallow_semicolon