]> git.ozlabs.org Git - ccan/blobdiff - ccan/rfc822/test/helper.c
io: allow overriding poll function.
[ccan] / ccan / rfc822 / test / helper.c
index f16803e23a8336ec1c275d33def4d901f3e33bd4..cc62a6621e4caf4bd94bd09f4374f6935bdae584 100644 (file)
@@ -1,7 +1,6 @@
 #include <stdlib.h>
 #include <stdio.h>
 
-#include <ccan/talloc/talloc.h>
 #include <ccan/failtest/failtest_override.h>
 #include <ccan/failtest/failtest.h>
 
@@ -11,6 +10,7 @@
 
 /* failtest limitations mean we need these wrappers to test talloc
  * failure paths. */
+#ifndef TAL_USE_TALLOC
 static void *malloc_wrapper(size_t size)
 {
        return malloc(size);
@@ -25,6 +25,7 @@ static void *realloc_wrapper(void *ptr, size_t size)
 {
        return realloc(ptr, size);
 }
+#endif
 
 #if 0
 static void allocation_failure_exit(const char *s)
@@ -50,24 +51,45 @@ void allocation_failure_check(void)
        }
 }
 
+#ifdef TAL_USE_TALLOC
+#include <ccan/tal/talloc/talloc.h>
+#else
+#include <ccan/tal/tal.h>
+#endif
+
+/* Don't abort on allocation failures! */
+static void noabort_wrapper(const char *why)
+{
+       return;
+}
+
 void failtest_setup(int argc, char *argv[])
 {
        failtest_init(argc, argv);
        rfc822_set_allocation_failure_handler(allocation_failure_continue);
-       talloc_set_allocator(malloc_wrapper, free_wrapper, realloc_wrapper);
+#ifdef TAL_USE_TALLOC
+       /* FIXME: we can't inject allocation failures in talloc! */
+       tal_set_backend(NULL, NULL, NULL, noabort_wrapper);
+#else
+       tal_set_backend(malloc_wrapper, realloc_wrapper, free_wrapper,
+                       noabort_wrapper);
+#endif
 }
 
-void check_header(struct rfc822_msg *msg, struct rfc822_header *h,
+void check_header(struct rfc822_msg *msg,
+                 struct rfc822_header *h,
                  const char *name, const char *val,
-                 int crlf)
+                 enum rfc822_header_errors experr, int crlf)
 {
+       enum rfc822_header_errors errs;
        struct bytestring hname, hvalue, hfull;
        size_t namelen = strlen(name);
        size_t valuelen = strlen(val);
        size_t nln = crlf ? 2 : 1;
        size_t fulllen = namelen + valuelen + 1 + nln;
 
-       ok(rfc822_header_errors(msg, h) == 0, "Header valid");
+       errs = rfc822_header_errors(msg, h);
+       ok(errs == experr, "Header errors 0x%x != 0x%x", errs, experr);
        allocation_failure_check();
 
        hname = rfc822_header_raw_name(msg, h);