public inbox for mauve-patches@sourceware.org
 help / color / mirror / Atom feed
* FYI: Additional DocFlavor mimetype parsing tests
@ 2006-02-12 12:38 Wolfgang Baer
  0 siblings, 0 replies; only message in thread
From: Wolfgang Baer @ 2006-02-12 12:38 UTC (permalink / raw)
  To: mauve-patches

[-- Attachment #1: Type: text/plain, Size: 248 bytes --]

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


[-- Attachment #2: Mauve_DocFlavor.patch --]
[-- Type: text/x-patch, Size: 5841 bytes --]

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);
+      }
+     
   }
 }

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2006-02-12 12:38 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-02-12 12:38 FYI: Additional DocFlavor mimetype parsing tests Wolfgang Baer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).