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 const char no_body[] =
18 "Date: Tue, 22 Feb 2011 00:15:59 +1100\n"
19 "From: Mister From <from@example.com>\n"
20 "To: Mizz To <to@example.org>\n"
21 "Subject: Some subject\n"
22 "Message-ID: <20110221131559.GA28327@example>\n";
24 const char truncated[] =
25 "Date: Tue, 22 Feb 2011 00:15:59 +1100\n"
26 "From: Mister From <from@example.com>\n"
29 static int test_no_body(const char *buf, size_t len)
31 struct rfc822_msg *msg;
32 struct bytestring body;
35 msg = rfc822_start(NULL, buf, len);
36 allocation_failure_check();
38 body = rfc822_body(msg);
39 allocation_failure_check();
44 allocation_failure_check();
48 static int test_truncated(const char *buf, size_t len)
50 struct rfc822_msg *msg;
51 struct rfc822_header *h = NULL;
52 struct bytestring body;
55 msg = rfc822_start(NULL, buf, len);
56 allocation_failure_check();
59 h = rfc822_next_header(msg, h);
60 allocation_failure_check();
63 body = rfc822_body(msg);
64 allocation_failure_check();
69 allocation_failure_check();
73 int main(int argc, char *argv[])
75 failtest_setup(argc, argv);
77 /* This is how many tests you plan to run */
80 ok1(test_no_body(no_body, sizeof(no_body)));
81 ok1(test_no_body(truncated, sizeof(truncated)));
82 ok1(test_truncated(truncated, sizeof(truncated)));
84 /* This exits depending on whether all tests passed */
85 failtest_exit(exit_status());