1 #include <ccan/foreach/foreach.h>
2 #include <ccan/failtest/failtest_override.h>
3 #include <ccan/failtest/failtest.h>
4 #include <ccan/tap/tap.h>
8 #define CCAN_RFC822_DEBUG
10 #include <ccan/rfc822/rfc822.h>
12 #include <ccan/rfc822/rfc822.c>
17 #define BAD_HEADER_STR "This is a bad header\n"
18 const char bad_header[] =
19 "Date: Tue, 22 Feb 2011 00:15:59 +1100\n"
21 "From: Mister From <from@example.com>\n"
22 "To: Mizz To <to@example.org>\n"
23 "Subject: Some subject\n"
24 "Message-ID: <20110221131559.GA28327@example>\n";
26 static void test_bad_header(const char *buf, size_t len)
28 struct rfc822_msg *msg;
29 struct rfc822_header *hdr;
30 struct bytestring hfull;
34 msg = rfc822_start(NULL, buf, len);
36 allocation_failure_check();
38 hdr = rfc822_first_header(msg);
39 allocation_failure_check();
41 ok(hdr && (rfc822_header_errors(msg, hdr) == 0), "First header valid");
42 allocation_failure_check();
44 hdr = rfc822_next_header(msg, hdr);
45 allocation_failure_check();
47 ok(hdr && (rfc822_header_errors(msg, hdr) == RFC822_HDR_NO_COLON),
48 "Second header invalid");
50 hfull = rfc822_header_raw_content(msg, hdr);
51 allocation_failure_check();
53 ok(bytestring_eq(hfull, BYTESTRING(BAD_HEADER_STR)),
54 "Invalid header content");
57 allocation_failure_check();
60 int main(int argc, char *argv[])
62 failtest_setup(argc, argv);
64 test_bad_header(bad_header, sizeof(bad_header));
66 /* This exits depending on whether all tests passed */
67 failtest_exit(exit_status());