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 */
34 #include <sys/types.h>
40 #include <sys/socket.h>
42 #include <netinet/in.h>
54 #include "inputline.h"
60 #include "selection.h"
67 #include "configuration.h"
73 extern int tests, errors;
74 extern int fail_first;
76 /** @brief Checks that @p expr is nonzero */
77 #define insist(expr) do { \
80 fprintf(stderr, "%s:%d: error checking %s\n", \
81 __FILE__, __LINE__, #expr); \
86 #define check_string(GOT, WANT) do { \
87 const char *got = GOT; \
88 const char *want = WANT; \
91 fprintf(stderr, "%s:%d: %s returned 0\n", \
92 __FILE__, __LINE__, #GOT); \
94 } else if(strcmp(want, got)) { \
95 fprintf(stderr, "%s:%d: %s returned:\n%s\nexpected:\n%s\n", \
96 __FILE__, __LINE__, #GOT, format(got), format(want)); \
102 #define check_string_prefix(GOT, WANT) do { \
103 const char *got = GOT; \
104 const char *want = WANT; \
107 fprintf(stderr, "%s:%d: %s returned 0\n", \
108 __FILE__, __LINE__, #GOT); \
110 } else if(strncmp(want, got, strlen(want))) { \
111 fprintf(stderr, "%s:%d: %s returned:\n%s\nexpected:\n%s...\n", \
112 __FILE__, __LINE__, #GOT, format(got), format(want)); \
118 #define check_integer(GOT, WANT) do { \
119 const intmax_t got = GOT, want = WANT; \
121 fprintf(stderr, "%s:%d: %s returned: %jd expected: %jd\n", \
122 __FILE__, __LINE__, #GOT, got, want); \
128 void count_error(void);
129 const char *format(const char *s);
130 const char *format_utf32(const uint32_t *s);
131 uint32_t *ucs4parse(const char *s);
132 const char *do_printf(const char *fmt, ...);
134 void test_addr(void);
135 void test_basen(void);
136 void test_cache(void);
137 void test_casefold(void);
138 void test_cookies(void);
139 void test_filepart(void);
140 void test_hash(void);
141 void test_heap(void);
144 void test_mime(void);
145 void test_printf(void);
146 void test_regsub(void);
147 void test_selection(void);
148 void test_signame(void);
149 void test_sink(void);
150 void test_split(void);
151 void test_unicode(void);
153 void test_utf8(void);
154 void test_words(void);
155 void test_wstat(void);