chiark / gitweb /
document new choose screen properly
[disorder] / lib / t-mime.c
index eb5ee7ca2b609b340507609c8240cd5ba353e61a..7f56c5d3ff0cea7c6095ac745ef745bedf14c0a3 100644 (file)
@@ -34,15 +34,13 @@ static int header_callback(const char *name, const char *value,
   return 0;
 }
 
-void test_mime(void) {
+static void test_mime(void) {
   char *t, *n, *v;
   struct vector parts[1];
   struct kvp *k;
   const char *s, *cs, *enc;
   hash *h;
 
-  fprintf(stderr, "test_mime\n");
-
   t = 0;
   k = 0;
   insist(!mime_content_type("text/plain", &t, &k));
@@ -191,7 +189,37 @@ void test_mime(void) {
                "Content-Description: jpeg-1\r\n"
                "\r\n"
                "<jpeg data>");
+
+  /* Bogus inputs to mime_multipart() */
+  fprintf(stderr, "expect two mime_multipart errors:\n");
+  insist(mime_multipart("--inner\r\n"
+                        "Content-Type: text/plain\r\n"
+                        "Content-Disposition: inline\r\n"
+                        "Content-Description: text-part-2\r\n"
+                        "\r\n"
+                        "Some more text here.\r\n"
+                        "\r\n"
+                        "--inner\r\n"
+                        "Content-Type: image/jpeg\r\n"
+                        "Content-Disposition: attachment\r\n"
+                        "Content-Description: jpeg-1\r\n"
+                        "\r\n"
+                        "<jpeg data>\r\n",
+                        test_multipart_callback,
+                        "inner",
+                        parts) == -1);
+  insist(mime_multipart("--wrong\r\n"
+                        "Content-Type: text/plain\r\n"
+                        "Content-Disposition: inline\r\n"
+                        "Content-Description: text-part-2\r\n"
+                        "\r\n"
+                        "Some more text here.\r\n"
+                        "\r\n"
+                        "--inner--\r\n",
+                        test_multipart_callback,
+                        "inner",
+                        parts) == -1);
+    
   /* XXX mime_parse */
 
   check_string(mime_qp(""), "");
@@ -220,7 +248,9 @@ void test_mime(void) {
               "Now's the time for all folk to come to the aid of their country.");
 
 #define check_base64(encoded, decoded) do {                     \
-    check_string(mime_base64(encoded, 0), decoded);             \
+    size_t ns;                                                  \
+    check_string(mime_base64(encoded, &ns), decoded);           \
+    insist(ns == (sizeof decoded) - 1);                         \
     check_string(mime_to_base64((const uint8_t *)decoded,       \
                                          (sizeof decoded) - 1), \
                  encoded);                                      \
@@ -335,6 +365,8 @@ void test_mime(void) {
   check_string(enc, "quoted-printable");
 }
 
+TEST(mime);
+
 /*
 Local Variables:
 c-basic-offset:2