From 45d8d199d5efd9978674b515228579ec48d5796d Mon Sep 17 00:00:00 2001
From: Stephan Bosch <stephan@rename-it.nl>
Date: Sun, 11 Oct 2009 12:08:02 +0200
Subject: [PATCH] Test suite: restructured tests for body extension.

---
 tests/extensions/body/basic.svtest   | 91 ----------------------------
 tests/extensions/body/content.svtest | 83 ++++++++++++++++++++++++-
 2 files changed, 81 insertions(+), 93 deletions(-)

diff --git a/tests/extensions/body/basic.svtest b/tests/extensions/body/basic.svtest
index 7f886435f..050ea76f6 100644
--- a/tests/extensions/body/basic.svtest
+++ b/tests/extensions/body/basic.svtest
@@ -95,94 +95,3 @@ test "No body" {
 		test_fail "matched against non-existant body (:matches \"*\")";
 	}
 }
-
-/*
- *
- */
-
-test_set "message" text:
-From: Whomever <whomever@domain.dom>
-To: Someone <someone@domain.com>
-Date: Fri, 08 Aug 2008 10:14:34 -0700
-Subject: whatever
-Content-Type: multipart/mixed; boundary=outer
-
-This is a multi-part message in MIME format.
-
---outer
-Content-Type: multipart/alternative; boundary=inner
-
-This is a nested multi-part message in MIME format.
-
---inner
-Content-Type: text/plain; charset="us-ascii"
-
-Hello
-
---inner
-Content-Type: text/html; charset="us-ascii"
-
-<html><body>Hello</body></html>
-
---inner--
-
-This is the end of the inner MIME multipart.
-
---outer
-Content-Type: message/rfc822
-From: Someone Else <someone.else@domain.dom>
-Subject: hello request
-
-Please say Hello
-
---outer--
-
-This is the end of the outer MIME multipart.
-.
-;
-
-test "RFC nested example - :content \"text\"" {
-	if not body :content "text" :contains "html" {
-		test_fail "failed to acquire nested MIME body part (1)";	
-	}
-
-	if not body :content "text/html" :contains "hello" {
-		test_fail "failed to acquire nested MIME body part (2)";	
-	}
-	
-	if not body :content "text/plain" :contains "hello" {
-        test_fail "failed to acquire nested MIME body part (3)";
-    }
-
-	if not body :content "text" :contains "hello" {
-        test_fail "failed to acquire nested MIME body part (4)";
-    }
-
-/* FIXME: fails
-	if not body :content "text" :count "eq" :comparator "i;ascii-numeric" "2" {
-		test_fail "matched wrong number of \"text/*\" body parts";
-	}*/
-}
-
-/* FIXME: fails
-test "RFC nested example - :content \"multipart\"" {
-	if not body :content "multipart" :contains
-		"This is a multi-part message in MIME format" {
-		test_fail "missed first multipart body part";
-	}
-
-	if not body :content "multipart" :contains
-		"This is a nested multi-part message in MIME format" {
-		test_fail "missed second multipart body part";
-	}
-	
-	if not body :content "multipart" :contains
-		"This is the end of the inner MIME multipart" {
-		test_fail "missed third multipart body part";
-	}
-
-	if not body :content "multipart" :contains
-		"This is the end of the outer MIME multipart." {
-		test_fail "missed fourth multipart body part";
-	}	
-}*/
diff --git a/tests/extensions/body/content.svtest b/tests/extensions/body/content.svtest
index 28fd9ac26..cc783e497 100644
--- a/tests/extensions/body/content.svtest
+++ b/tests/extensions/body/content.svtest
@@ -1,4 +1,7 @@
 require "vnd.dovecot.testsuite";
+require "relational";
+require "comparator-i;ascii-numeric";
+
 require "body";
 
 /*
@@ -18,16 +21,20 @@ Content-Type: text/plain
 
 Plain Text
 
+--donkey
+Content-Type: text/stupid
+
+Stupid Text
+
 --donkey
 Content-Type: text/plain/stupid
 
-Plain stupid
+Plain Stupid Text
 
 --donkey--
 .
 ;
 
-
 /*
  * RFC5173, Section 5.2:
  *  If an individual content type begins or ends with a '/' (slash) or
@@ -35,6 +42,20 @@ Plain stupid
  *  ...
  */
 
+test "Basic Match" {
+	if not body :content "text/plain" :matches "Plain Text*" {
+		test_fail "failed to match (1)";
+	}
+
+	if not body :content "text/plain" :contains "" {
+		test_fail "failed to match (2)";
+	}
+
+	if not body :content "text/stupid" :contains "" {
+		test_fail "failed to match (3)";
+	}
+}
+
 test "Begin Slash" {
 	if body :content "/plain" :contains "" {
 		test_fail "matched :content \"/plain\"";
@@ -218,7 +239,65 @@ test "Nested Search" {
 	if body :content "text/html" :matches "Hello*" {
 		test_fail "erroneously matched text/plain content";
 	}
+
+	if not body :content "text" :contains "html" {
+		test_fail "failed match text content (1)";	
+	}
+
+	if not body :content "text" :contains "hello" {
+		test_fail "failed match text content (2)";
+	}
+
+	if not body :content "text/plain" :contains "please say hello" {
+		test_fail "failed match nested message content as text/plain";
+	}
+
+	if not body :content "text" :contains "please say hello" {
+		test_fail "failed match nested message content as text/*";
+	}
+	
+	if not body :content "text" :count "eq" :comparator "i;ascii-numeric" "3" {
+		test_fail "matched wrong number of \"text/*\" body parts";
+	}
 }
 
+/* RFC5173, Section 5.2:
+ *
+ *  If the :content specification matches a multipart MIME part, only the
+ *  prologue and epilogue sections of the part will be searched for the
+ *  key strings, treating the entire prologue and the entire epilogue as
+ *  separate strings; the contents of nested parts are only searched if
+ *  their respective types match the :content specification.
+ *
+ *  If the :content specification matches a message/rfc822 MIME part,
+ *  only the header of the nested message will be searched for the key
+ *  strings, treating the header as a single string; the contents of the
+ *  nested message body parts are only searched if their content type
+ *  matches the :content specification.
+ */
+
+/* FIXME: fails
+test "Multipart Content" {
+	if not body :content "multipart" :contains
+		"This is a multi-part message in MIME format" {
+		test_fail "missed first multipart body part";
+	}
+
+	if not body :content "multipart" :contains
+		"This is a nested multi-part message in MIME format" {
+		test_fail "missed second multipart body part";
+	}
+	
+	if not body :content "multipart" :contains
+		"This is the end of the inner MIME multipart" {
+		test_fail "missed third multipart body part";
+	}
+
+	if not body :content "multipart" :contains
+		"This is the end of the outer MIME multipart." {
+		test_fail "missed fourth multipart body part";
+	}	
+}*/
+
 
 
-- 
GitLab