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 NO_COLON_STR "This is a bad header\n"
18 const char no_colon_msg[] =
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_no_colon(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 ok1(hdr && !rfc822_header_is(msg, hdr, NULL));
51 ok1(hdr && !rfc822_header_is(msg, hdr, ""));
52 ok1(hdr && !rfc822_header_is(msg, hdr, NO_COLON_STR));
54 hfull = rfc822_header_raw_content(msg, hdr);
55 allocation_failure_check();
57 ok(bytestring_eq(hfull, BYTESTRING(NO_COLON_STR)),
58 "Invalid header content");
61 allocation_failure_check();
64 int main(int argc, char *argv[])
66 failtest_setup(argc, argv);
68 test_no_colon(no_colon_msg, sizeof(no_colon_msg));
70 /* This exits depending on whether all tests passed */
71 failtest_exit(exit_status());