1 #include <ccan/foreach/foreach.h>
2 #include <ccan/failtest/failtest_override.h>
3 #include <ccan/failtest/failtest.h>
7 #define CCAN_RFC822_DEBUG
9 #include <ccan/rfc822/rfc822.h>
11 #include <ccan/rfc822/rfc822.c>
16 static void test_hdrbyname(const struct aexample *e, const char *buf, size_t len,
17 const char *exname, int crlf)
19 struct rfc822_msg *msg;
20 struct rfc822_header *h, *hx;
23 msg = rfc822_start(NULL, buf, len);
24 allocation_failure_check();
25 ok(msg, "opened %s", exname);
27 for (i = 0; i < e->nhdrs; i++) {
28 struct testhdr *eh = &e->hdrs[i];
30 h = rfc822_first_header_of_name(msg, eh->name);
31 hx = rfc822_next_header_of_name(msg, NULL, eh->name);
34 for (j = 0; h && j < eh->index; j++)
35 h = rfc822_next_header_of_name(msg, h, eh->name);
36 ok(h, "header \"%s\" (#%d) exists", eh->name, eh->index);
39 check_header(msg, h, eh->name, eh->val, eh->errors, crlf);
41 h = rfc822_next_header_of_name(msg, h, eh->name);
42 ok1((eh->index != eh->last) ^ !h);
45 h = rfc822_first_header_of_name(msg, NULL);
46 ok(!h, "Never match NULL name");
49 allocation_failure_check();
52 int main(int argc, char *argv[])
56 /* This is how many tests you plan to run */
57 plan_tests(6*num_aexamples() + 14*num_aexample_hdrs());
59 failtest_setup(argc, argv);
61 for_each_aexample(e) {
64 foreach_int(crlf, 0, 1) {
69 sprintf(exname, "%s[%s]", e->name, NLT(crlf));
71 buf = assemble_msg(e, &len, crlf);
72 ok((buf), "assembled %s", exname);
76 test_hdrbyname(e, buf, len, exname, crlf);
82 /* This exits depending on whether all tests passed */
83 failtest_exit(exit_status());