]> git.ozlabs.org Git - ccan/blobdiff - ccan/rfc822/test/run-default-alloc-failure.c
rfc822: new module.
[ccan] / ccan / rfc822 / test / run-default-alloc-failure.c
diff --git a/ccan/rfc822/test/run-default-alloc-failure.c b/ccan/rfc822/test/run-default-alloc-failure.c
new file mode 100644 (file)
index 0000000..7fc0393
--- /dev/null
@@ -0,0 +1,56 @@
+#include <ccan/tap/tap.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <signal.h>
+#include <errno.h>
+
+#define CCAN_RFC822_DEBUG
+
+#include <ccan/rfc822/rfc822.h>
+
+#include <ccan/rfc822/rfc822.c>
+
+#include "testdata.h"
+
+static void *failing_malloc(size_t size)
+{
+       return NULL;
+}
+
+static void abort_handler(int signum)
+{
+       ok(1, "Aborted");
+       exit(0);
+}
+
+int main(int argc, char *argv[])
+{
+       const char *buf;
+       size_t len;
+       struct rfc822_msg *msg;
+       struct sigaction sa = {
+               .sa_handler = abort_handler,
+       };
+       int ret;
+
+       plan_tests(2);
+
+       ret = sigaction(SIGABRT, &sa, NULL);
+       ok(ret, "Couldn't install signal handler: %s", strerror(errno));
+
+       buf = assemble_msg(&test_msg_1, &len, 0);
+
+       msg = rfc822_start(NULL, buf, len);
+
+       talloc_set_allocator(failing_malloc, free, realloc);
+
+       (void) rfc822_next_header(msg, NULL);
+
+       ok(0, "Didn't get SIGABRT");
+
+       rfc822_free(msg);
+       talloc_free(buf);
+
+       exit(exit_status());
+}