]> git.ozlabs.org Git - ccan/blobdiff - ccan/rfc822/test/run-hdr-and-body.c
rfc822: Allow test infrastructure to handle headers with minor errors
[ccan] / ccan / rfc822 / test / run-hdr-and-body.c
index fe4515a3a6768508804bb6021e31555768a223ca..25e66cc2fd1330b2f31ccc3e51cdfc4778cd0f63 100644 (file)
                        if (!(_h)) \
                                break; \
                        check_header((_msg), (_h), (_e)->hdrs[_i].name, \
-                                    (_e)->hdrs[_i].val, crlf); \
+                                    (_e)->hdrs[_i].val,                \
+                                    (_e)->hdrs[_i].errors, crlf);      \
                } \
        } 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 +113,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);