1 #ifndef RFC822_TESTDATA_H
2 #define RFC822_TESTDATA_H
4 #include <ccan/talloc/talloc.h>
5 #include <ccan/array_size/array_size.h>
6 #include <ccan/foreach/foreach.h>
9 const char *name, *val;
20 struct aexample s = { \
23 .nhdrs = ARRAY_SIZE(s##_hdrs), \
27 struct testhdr test_msg_1_hdrs[] = {
28 {"Date", "Tue, 22 Feb 2011 00:15:59 +1100"},
29 {"From", "Mister From <from@example.com>"},
30 {"To", "Mizz To <to@example.org>"},
31 {"Subject", "Some subject"},
32 {"Message-ID", "<20110221131559.GA28327@example>"},
33 {"MIME-Version", "1.0"},
34 {"Content-Type", "text/plain; charset=us-ascii"},
35 {"Content-Disposition", "inline"},
37 const char test_msg_1_body[] = "Test message\n";
40 #define test_msg_empty_body_hdrs test_msg_1_hdrs
41 const char test_msg_empty_body_body[] = "";
42 AEXAMPLE(test_msg_empty_body);
44 #define test_msg_nlnl_lf_hdrs test_msg_1_hdrs
45 const char test_msg_nlnl_lf_body[] = "Message containing \n\n inside body\n";
46 AEXAMPLE(test_msg_nlnl_lf);
48 #define test_msg_nlnl_crlf_hdrs test_msg_1_hdrs
49 const char test_msg_nlnl_crlf_body[] = "Message containing \r\n\r\n inside body\r\n";
50 AEXAMPLE(test_msg_nlnl_crlf);
52 #define test_msg_nlnl_mixed_hdrs test_msg_1_hdrs
53 const char test_msg_nlnl_mixed_body[] = "Message containing both \n\n and \r\n\r\n inside body\n\r\n";
54 AEXAMPLE(test_msg_nlnl_mixed);
57 #define for_each_aexample(_e) \
58 foreach_ptr((_e), &test_msg_1, &test_msg_empty_body, \
59 &test_msg_nlnl_lf, &test_msg_nlnl_crlf, \
62 #define for_each_aexample_buf(_e, _buf, _len) \
63 for_each_aexample((_e)) \
64 if (((_buf) = assemble_msg((_e), &(_len))) != NULL)
66 static inline int num_aexamples(void)
68 const struct aexample *e;
77 static inline int num_aexample_hdrs(void)
79 const struct aexample *e;
88 static inline const char *assemble_msg(const struct aexample *e,
89 size_t *len, int crlf)
91 const char *nl = crlf ? "\r\n" : "\n";
92 int nln = crlf ? 2 : 1;
97 msg = talloc_strdup(NULL, "");
101 for (i = 0; i < e->nhdrs; i++) {
102 amsg = talloc_asprintf_append(msg, "%s:%s%s", e->hdrs[i].name,
109 n += strlen(e->hdrs[i].name) + strlen(e->hdrs[i].val) + 1 + nln;
111 amsg = talloc_asprintf_append(msg, "%s%s", nl, e->body);
117 n += strlen(e->body) + nln;
122 #define NLT(crlf) ((crlf) ? "CRLF" : "LF")
124 #endif /* RFC822_TESTDATA_H */