chiark / gitweb /
Macro expansion (untested). Tests for most builtin expansions.
[disorder] / lib / t-mime.c
index 05ae8b5aea9537336dfe5a235a1b9f2dec6dd878..65000c7b0e9d9e0e2d704985e5b2c07cf6694ff0 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;
+  const char *s, *cs, *enc;
   hash *h;
 
-  fprintf(stderr, "test_mime\n");
-
   t = 0;
   k = 0;
   insist(!mime_content_type("text/plain", &t, &k));
@@ -220,7 +218,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);                                      \
@@ -308,8 +308,35 @@ void test_mime(void) {
   check_string(*(char **)hash_find(h, "content-type"), "text/plain");
   check_string(*(char **)hash_find(h, "content-transfer-encoding"), "BASE64");
   check_string(s, "wibble\r\n");
+
+#define CHECK_QUOTE(INPUT, EXPECT) do {                 \
+  s = quote822(INPUT, 0);                               \
+  insist(s != 0);                                       \
+  check_string(s, EXPECT);                              \
+  s = mime_parse_word(s, &t, mime_http_separator);      \
+  check_string(t, INPUT);                               \
+} while(0)
+  CHECK_QUOTE("wibble", "wibble");
+  CHECK_QUOTE("wibble spong", "\"wibble spong\"");
+  CHECK_QUOTE("wibble\\spong", "\"wibble\\\\spong\"");
+  CHECK_QUOTE("wibble\"spong", "\"wibble\\\"spong\"");
+  CHECK_QUOTE("(wibble)", "\"(wibble)\"");
+
+  s = mime_encode_text("wibble\n", &cs, &enc);
+  insist(s != 0);
+  check_string(s, "wibble\n");
+  check_string(cs, "us-ascii");
+  check_string(enc, "7bit");
+
+  s = mime_encode_text("wibble\xC3\xB7\n", &cs, &enc);
+  insist(s != 0);
+  check_string(s, "wibble=C3=B7\n");
+  check_string(cs, "utf-8");
+  check_string(enc, "quoted-printable");
 }
 
+TEST(mime);
+
 /*
 Local Variables:
 c-basic-offset:2