]> git.ozlabs.org Git - ccan/commitdiff
rfc822: Move check_header into helper.c
authorDavid Gibson <david@gibson.dropbear.id.au>
Wed, 3 Oct 2012 13:20:46 +0000 (23:20 +1000)
committerDavid Gibson <david@gibson.dropbear.id.au>
Wed, 3 Oct 2012 13:20:46 +0000 (23:20 +1000)
The check_header() test function will be useful to more than one testcase
so this patch moves it into the common helper.c file.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
ccan/rfc822/test/helper.c
ccan/rfc822/test/helper.h
ccan/rfc822/test/run-hdr-and-body.c

index 36a2a065f2607c283be3cdd1c1169494b0121a22..f16803e23a8336ec1c275d33def4d901f3e33bd4 100644 (file)
@@ -56,3 +56,43 @@ void failtest_setup(int argc, char *argv[])
        rfc822_set_allocation_failure_handler(allocation_failure_continue);
        talloc_set_allocator(malloc_wrapper, free_wrapper, realloc_wrapper);
 }
+
+void check_header(struct rfc822_msg *msg, struct rfc822_header *h,
+                 const char *name, const char *val,
+                 int crlf)
+{
+       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");
+       allocation_failure_check();
+
+       hname = rfc822_header_raw_name(msg, h);
+       allocation_failure_check();
+
+       ok(hname.ptr && bytestring_eq(hname, bytestring_from_string(name)),
+          "Header name \"%.*s\"", (int)hname.len, hname.ptr);
+
+       hvalue = rfc822_header_raw_value(msg, h);
+       allocation_failure_check();
+
+       ok(hvalue.ptr && ((valuelen + nln) == hvalue.len)
+          && (memcmp(val, hvalue.ptr, valuelen) == 0)
+          && (!crlf || (hvalue.ptr[hvalue.len - 2] == '\r'))
+          && (hvalue.ptr[hvalue.len - 1] == '\n'),
+          "Header value");
+
+       hfull = rfc822_header_raw_content(msg, h);
+       allocation_failure_check();
+
+       ok(hfull.ptr && (fulllen == hfull.len)
+          && (memcmp(name, hfull.ptr, namelen) == 0)
+          && (hfull.ptr[namelen] == ':')
+          && (memcmp(val, hfull.ptr + namelen + 1, valuelen) == 0)
+          && (!crlf || (hfull.ptr[fulllen-2] == '\r'))
+          && (hfull.ptr[fulllen-1] == '\n'),
+          "Full header");
+}
index 7e1e67b2098f61bec18143b32bdabce379ac9c2e..2bdb9c43cb05aa6f7ebcb4275436c8438528cb00 100644 (file)
@@ -1,2 +1,9 @@
+#include <ccan/tap/tap.h>
+
 void failtest_setup(int argc, char *argv[]);
 void allocation_failure_check(void);
+
+#define CHECK_HEADER_NUMTESTS  4
+void check_header(struct rfc822_msg *msg, struct rfc822_header *h,
+                 const char *name, const char *val,
+                 int crlf);
index fe4515a3a6768508804bb6021e31555768a223ca..956a6bd6e17392e264029556558fd9d5e6166dbf 100644 (file)
                } \
        } while (0)
 
-static void check_header(struct rfc822_msg *msg,
-                        struct rfc822_header *h,
-                        const char *name, const char *val,
-                        int crlf)
-{
-       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");
-       allocation_failure_check();
-
-       hname = rfc822_header_raw_name(msg, h);
-       allocation_failure_check();
-
-       ok(hname.ptr && bytestring_eq(hname, bytestring_from_string(name)),
-          "Header name \"%.*s\"", (int)hname.len, hname.ptr);
-
-       hvalue = rfc822_header_raw_value(msg, h);
-       allocation_failure_check();
-
-       ok(hvalue.ptr && ((valuelen + nln) == hvalue.len)
-          && (memcmp(val, hvalue.ptr, valuelen) == 0)
-          && (!crlf || (hvalue.ptr[hvalue.len - 2] == '\r'))
-          && (hvalue.ptr[hvalue.len - 1] == '\n'),
-          "Header value");
-
-       hfull = rfc822_header_raw_content(msg, h);
-       allocation_failure_check();
-
-       ok(hfull.ptr && (fulllen == hfull.len)
-          && (memcmp(name, hfull.ptr, namelen) == 0)
-          && (hfull.ptr[namelen] == ':')
-          && (memcmp(val, hfull.ptr + namelen + 1, valuelen) == 0)
-          && (!crlf || (hfull.ptr[fulllen-2] == '\r'))
-          && (hfull.ptr[fulllen-1] == '\n'),
-          "Full header");
-}
-
 static void test_bodyhdr(const struct aexample *e, const char *buf, size_t len,
                         const char *exname, int crlf)
 {
@@ -153,7 +112,8 @@ int main(int argc, char *argv[])
        struct aexample *e;
 
        /* This is how many tests you plan to run */
-       plan_tests(20*num_aexamples() + 40*num_aexample_hdrs());
+       plan_tests(20*num_aexamples()
+                  + (36 + CHECK_HEADER_NUMTESTS)*num_aexample_hdrs());
 
        failtest_setup(argc, argv);