]> git.ozlabs.org Git - ccan/blob - ccan/rfc822/test/run-default-alloc-failure.c
rfc822: Allow test infrastructure to handle headers with minor errors
[ccan] / ccan / rfc822 / test / run-default-alloc-failure.c
1 #include <ccan/tap/tap.h>
2 #include <stdlib.h>
3 #include <string.h>
4
5 #include <signal.h>
6 #include <errno.h>
7
8 #define CCAN_RFC822_DEBUG
9
10 #include <ccan/rfc822/rfc822.h>
11
12 #include <ccan/rfc822/rfc822.c>
13
14 #include "testdata.h"
15
16 static void *failing_malloc(size_t size)
17 {
18         return NULL;
19 }
20
21 static void abort_handler(int signum)
22 {
23         ok(1, "Aborted");
24         exit(0);
25 }
26
27 int main(int argc, char *argv[])
28 {
29         const char *buf;
30         size_t len;
31         struct rfc822_msg *msg;
32         struct sigaction sa = {
33                 .sa_handler = abort_handler,
34         };
35         int ret;
36
37         plan_tests(2);
38
39         ret = sigaction(SIGABRT, &sa, NULL);
40         ok(ret, "Couldn't install signal handler: %s", strerror(errno));
41
42         buf = assemble_msg(&test_msg_1, &len, 0);
43
44         msg = rfc822_start(NULL, buf, len);
45
46         talloc_set_allocator(failing_malloc, free, realloc);
47
48         (void) rfc822_next_header(msg, NULL);
49
50         ok(0, "Didn't get SIGABRT");
51
52         rfc822_free(msg);
53         talloc_free(buf);
54
55         exit(exit_status());
56 }