]> git.ozlabs.org Git - ccan/blobdiff - ccan/rfc822/test/testdata.h
Merge branch 'io'
[ccan] / ccan / rfc822 / test / testdata.h
index 4ef07095474cef88fa940a466f2798e4f7ec79cd..ada262b5f544300653a301f566785e1fcaa6011b 100644 (file)
@@ -1,12 +1,14 @@
 #ifndef RFC822_TESTDATA_H
 #define RFC822_TESTDATA_H
 
-#include <ccan/talloc/talloc.h>
+#include <ccan/tal/str/str.h>
 #include <ccan/array_size/array_size.h>
 #include <ccan/foreach/foreach.h>
 
 struct testhdr {
        const char *name, *val;
+       int index, last;
+       enum rfc822_header_errors errors;
 };
 
 struct aexample {
@@ -57,11 +59,42 @@ AEXAMPLE(test_msg_nlnl_mixed);
 const char test_msg_space_body_body[] = " Message with LWS at start of body\n";
 AEXAMPLE(test_msg_space_body);
 
+struct testhdr bad_hdrs_hdrs[] = {
+       {"From", "Mister From <from@example.com>"},
+       {"To", "Mizz To <to@example.org>"},
+       {"X-Bad-\bName", "This header field has bad characters in the name",
+                .errors = RFC822_HDR_BAD_NAME_CHARS},
+       {"Subject", "Some subject"},
+       {"Message-ID", "<20110221131559.GA28327@example>"},
+};
+#define bad_hdrs_body test_msg_1_body
+AEXAMPLE(bad_hdrs)
+
+struct testhdr repeated_hdrs_1_hdrs[] = {
+       {"X-Repeated-Header", "#1", 0, 4},
+       {"x-repeated-header", "#2", 1, 4},
+       {"X-REPEATED-HEADER", "#3", 2, 4},
+       {"x-rEpEaTeD-hEaDeR", "#4", 3, 4},
+       {"X-Repeated-Header", "#5", 4, 4},
+};
+#define repeated_hdrs_1_body test_msg_1_body
+AEXAMPLE(repeated_hdrs_1);
+
+struct testhdr prefix_hdr_hdrs[] = {
+       {"X-Prefix", "Prefix", 0},
+       {"X-Prefix-and-Suffix", "Suffix", 0},
+};
+#define prefix_hdr_body test_msg_1_body
+AEXAMPLE(prefix_hdr);
+
 #define for_each_aexample(_e)                               \
        foreach_ptr((_e), &test_msg_1, &test_msg_empty_body, \
                    &test_msg_nlnl_lf, &test_msg_nlnl_crlf, \
                    &test_msg_nlnl_mixed, \
-                   &test_msg_space_body)
+                   &test_msg_space_body, \
+                   &bad_hdrs,            \
+                   &repeated_hdrs_1,     \
+                   &prefix_hdr)
 
 #define for_each_aexample_buf(_e, _buf, _len)  \
        for_each_aexample((_e))                 \
@@ -94,30 +127,26 @@ static inline const char *assemble_msg(const struct aexample *e,
 {
        const char *nl = crlf ? "\r\n" : "\n";
        int nln = crlf ? 2 : 1;
-       char *msg, *amsg;
+       char *msg;
        size_t n = 0;
        int i;
 
-       msg = talloc_strdup(NULL, "");
+       msg = tal_strdup(NULL, "");
        if (!msg)
                return NULL;
 
        for (i = 0; i < e->nhdrs; i++) {
-               amsg = talloc_asprintf_append(msg, "%s:%s%s", e->hdrs[i].name,
-                                             e->hdrs[i].val, nl);
-               if (!amsg) {
-                       talloc_free(msg);
+               if (!tal_append_fmt(&msg, "%s:%s%s", e->hdrs[i].name,
+                                   e->hdrs[i].val, nl)) {
+                       tal_free(msg);
                        return NULL;
                }
-               msg = amsg;
                n += strlen(e->hdrs[i].name) + strlen(e->hdrs[i].val) + 1 + nln;
        }
-       amsg = talloc_asprintf_append(msg, "%s%s", nl, e->body);
-       if (!amsg) {
-               talloc_free(msg);
+       if (!tal_append_fmt(&msg, "%s%s", nl, e->body)) {
+               tal_free(msg);
                return NULL;
        }
-       msg = amsg;
        n += strlen(e->body) + nln;
        *len = n;
        return msg;