This is the mail archive of the mauve-patches@sourceware.org mailing list for the Mauve project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

FYI: Additional DocFlavor mimetype parsing tests


Hi,

changelog says all. We fail these tests currently, patch is pending.

2006-02-12  Wolfgang Baer  <WBaer@gmx.de>

	* gnu/testlet/javax/print/DocFlavor/parseMimeType.java:
	Added additional tests to check for correct mimetype syntax.

Wolfgang

Index: parseMimeType.java
===================================================================
RCS file: /cvs/mauve/mauve/gnu/testlet/javax/print/DocFlavor/parseMimeType.java,v
retrieving revision 1.1
diff -u -r1.1 parseMimeType.java
--- parseMimeType.java	29 Apr 2004 17:42:24 -0000	1.1
+++ parseMimeType.java	12 Feb 2006 12:35:51 -0000
@@ -1,6 +1,7 @@
 // Tags: JDK1.4
 
 // Copyright (C) 2004 Michael Koch <konqueror@gmx.de>
+// Copyright (C) 2006 Wolfgang Baer <WBaer@gmx.de>
 
 // This file is part of Mauve.
 
@@ -27,21 +28,121 @@
 import javax.print.DocFlavor;
 
 /**
+ * Tests the mime type parsing behaviour of DocFlavor.
+ * 
  * @author Michael Koch (konqueror@gmx.de)
+ * @author Wolfgang Baer (WBaer@gmx.de) 
  */
 public class parseMimeType implements Testlet
 {
   public void test(TestHarness h)
   {
-    DocFlavor flavor = new DocFlavor("text/plain; charset=us-ascii", "java.io.InputStream");
+    // Check simple mimetype
+    DocFlavor simple = new DocFlavor("text/plain; charset=us-ascii", 
+                                     "java.io.InputStream");
+
+    h.checkPoint("Simple mimetype");
+    h.check(simple.getMediaType().equals("text"));
+    h.check(simple.getMediaSubtype().equals("plain"));
+    h.check(simple.getParameter("charset").equals("us-ascii"));
+    h.check(simple.getRepresentationClassName().equals("java.io.InputStream"));
+    // Check if mimetype can be correctly built together again.
+    h.check(simple.getMimeType().equals("text/plain; charset=\"us-ascii\""));
+    h.check(simple.toString().equals("text/plain; charset=\"us-ascii\"; " +
+                                     "class=\"java.io.InputStream\""));
+
+    // Check for mimetype with quoted parameter value
+    DocFlavor quoted = new DocFlavor("text/plain; charset=\"us-ascii\"", 
+                                     "java.io.InputStream");
 
-    // Check if mimetype can be correctly decoded.
-    h.check(flavor.getMediaType().equals("text"));
-    h.check(flavor.getMediaSubtype().equals("plain"));
-    h.check(flavor.getParameter("charset").equals("us-ascii"));
-    h.check(flavor.getRepresentationClassName().equals("java.io.InputStream"));
-    
+    h.checkPoint("Mimetype with quoted param values");
+    h.check(quoted.getParameter("charset").equals("us-ascii"));
     // Check if mimetype can be correctly built together again.
-    h.check(flavor.getMimeType().equals("text/plain; charset=\"us-ascii\""));    
+    h.check(quoted.getMimeType().equals("text/plain; charset=\"us-ascii\""));
+    h.check(simple.toString().equals("text/plain; charset=\"us-ascii\"; " +
+                                     "class=\"java.io.InputStream\""));
+
+    // Check for mimetype with multiple parameters
+    DocFlavor multipleParam = new DocFlavor("text/plain; " +
+      "charset=\"us-ascii\"; param=paramValue", "java.io.InputStream");
+
+    h.checkPoint("Mimetype with multiple parameters");
+    h.check(multipleParam.getParameter("charset").equals("us-ascii"));
+    h.check(multipleParam.getParameter("param").equals("paramValue"));
+    // Check if mimetype can be correctly built together again.
+    h.check(multipleParam.getMimeType().equals("text/plain; " +
+      "charset=\"us-ascii\"; param=\"paramValue\""));
+    h.check(multipleParam.toString().equals("text/plain; charset=\"us-ascii\";" +
+      " param=\"paramValue\"; class=\"java.io.InputStream\""));
+
+    // Check natural order for mimetype with multiple parameters
+    DocFlavor paramOrder = new DocFlavor("text/plain; " +
+      "charset=\"us-ascii\"; another=paramValue; charset3=something", 
+      "java.io.InputStream");
+
+    h.checkPoint("Multiple parameters output order");
+    // parameters are returned in natural key order 
+    // therefore another -> charset -> charset3
+    h.check(paramOrder.getMimeType().equals("text/plain; " +
+      "another=\"paramValue\"; charset=\"us-ascii\"; charset3=\"something\""));
+
+    // Check charset treatment
+    DocFlavor charset = new DocFlavor("text/plain; charset=US-ascii; " +
+      "nocharset=UoUo", "java.io.InputStream");
+
+    h.checkPoint("Test charset treatment");
+    h.check(charset.getParameter("charset").equals("us-ascii"));
+    h.check(charset.getParameter("nocharset").equals("UoUo"));
+
+    // Check for mimetype with comments
+    DocFlavor comments = new DocFlavor("text/plain(Comment); " +
+    "charset=\"us-ascii\" (Comment2)(Comment1)", "java.io.InputStream");
+
+    h.checkPoint("Mimetype with comments");
+    h.check(comments.getMediaSubtype().equals("plain"));
+    h.check(comments.getParameter("charset").equals("us-ascii"));
+
+    // Syntax checks
+    h.checkPoint("Syntax checks");
+    
+    // Lowercase treatment of media type and media subtype
+    DocFlavor lowercase = new DocFlavor("teXt/Plain; charset=US-ascii; " +
+      "nocharset=UoUo", "java.io.InputStream");
+    
+    h.check(lowercase.getMediaType().equals("text"));
+    h.check(lowercase.getMediaSubtype().equals("plain"));
+    
+    try
+      {
+        // wrongly quoted value
+        new DocFlavor("text/plain; charset=us-ascii\"", "java.io.InputStream");
+        h.check(false);
+      }
+    catch (IllegalArgumentException e)
+      {
+        h.check(true);
+      }
+    try
+      {
+        // wrongly character in unqouted value
+        new DocFlavor("text/plain; charset=?us-ascii", "java.io.InputStream");
+        h.check(false);
+      }
+    catch (IllegalArgumentException e)
+      {
+        h.check(true);
+      }
+    try
+      {
+        // character in qouted value
+        DocFlavor syntax = new DocFlavor("text/plain; param=\"?value.\"",
+            "java.io.InputStream");
+        h.check(syntax.getParameter("param").equals("?value."));
+      }
+    catch (IllegalArgumentException e)
+      {
+        h.check(false);
+      }
+     
   }
 }

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]