]> git.ozlabs.org Git - ccan/blob - ccan/rfc822/test/run-hdr-no-colon.c
2ad767f3a7683e7329a8b09f6fbe5172da8229e2
[ccan] / ccan / rfc822 / test / run-hdr-no-colon.c
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>
5 #include <stdlib.h>
6 #include <string.h>
7
8 #define CCAN_RFC822_DEBUG
9
10 #include <ccan/rfc822/rfc822.h>
11
12 #include <ccan/rfc822/rfc822.c>
13
14 #include "testdata.h"
15 #include "helper.h"
16
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"
20         NO_COLON_STR
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";
25
26 static void test_no_colon(const char *buf, size_t len)
27 {
28         struct rfc822_msg *msg;
29         struct rfc822_header *hdr;
30         struct bytestring hfull;
31
32         plan_tests(6);
33
34         msg = rfc822_start(NULL, buf, len);
35
36         allocation_failure_check();
37
38         hdr = rfc822_first_header(msg);
39         allocation_failure_check();
40
41         ok(hdr && (rfc822_header_errors(msg, hdr) == 0), "First header valid");
42         allocation_failure_check();
43
44         hdr = rfc822_next_header(msg, hdr);
45         allocation_failure_check();
46
47         ok(hdr && (rfc822_header_errors(msg, hdr) == RFC822_HDR_NO_COLON),
48            "Second header invalid");
49
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));
53
54         hfull = rfc822_header_raw_content(msg, hdr);
55         allocation_failure_check();
56
57         ok(bytestring_eq(hfull, BYTESTRING(NO_COLON_STR)),
58                 "Invalid header content");
59
60         rfc822_free(msg);
61         allocation_failure_check();
62 }
63
64 int main(int argc, char *argv[])
65 {
66         failtest_setup(argc, argv);
67
68         test_no_colon(no_colon_msg, sizeof(no_colon_msg));
69
70         /* This exits depending on whether all tests passed */
71         failtest_exit(exit_status());
72 }