xmlgraphics-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From me...@apache.org
Subject svn commit: r1365650 [2/2] - in /xmlgraphics/commons/trunk: ./ test/java/org/apache/xmlgraphics/ test/java/org/apache/xmlgraphics/fonts/ test/java/org/apache/xmlgraphics/image/codec/png/ test/java/org/apache/xmlgraphics/image/loader/ test/java/org/apac...
Date Wed, 25 Jul 2012 15:59:32 GMT
Modified: xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/ps/PSEscapeTestCase.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/ps/PSEscapeTestCase.java?rev=1365650&r1=1365649&r2=1365650&view=diff
==============================================================================
--- xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/ps/PSEscapeTestCase.java (original)
+++ xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/ps/PSEscapeTestCase.java Wed Jul 25 15:59:30 2012
@@ -19,15 +19,16 @@
 
 package org.apache.xmlgraphics.ps;
 
-import org.apache.xmlgraphics.ps.PSGenerator;
+import org.junit.Test;
 
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
 
 /**
  * Tests literal text string escaping.
  */
-public class PSEscapeTestCase extends TestCase {
+public class PSEscapeTestCase {
 
+    @Test
     public void testBasics() throws Exception {
         StringBuffer sb = new StringBuffer();
 
@@ -50,6 +51,7 @@ public class PSEscapeTestCase extends Te
         assertEquals("0\\t\\(x\\)\\n\\036\\344?", sb.toString());
     }
 
+    @Test
     public void testStringToDSC() throws Exception {
         String escaped;
         escaped = PSGenerator.convertStringToDSC("0\t(x)\n\u001E\u00E4\u20AC");

Modified: xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/ps/dsc/ListenerTestCase.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/ps/dsc/ListenerTestCase.java?rev=1365650&r1=1365649&r2=1365650&view=diff
==============================================================================
--- xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/ps/dsc/ListenerTestCase.java (original)
+++ xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/ps/dsc/ListenerTestCase.java Wed Jul 25 15:59:30 2012
@@ -23,7 +23,10 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.util.Map;
 
-import junit.framework.TestCase;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
 
 import org.apache.commons.io.IOUtils;
 
@@ -35,12 +38,13 @@ import org.apache.xmlgraphics.ps.dsc.eve
 /**
  * Tests the listener functionality on the DSC parser.
  */
-public class ListenerTestCase extends TestCase {
+public class ListenerTestCase {
 
     /**
      * Tests {@link DSCParser#setFilter(DSCFilter)}.
      * @throws Exception if an error occurs
      */
+    @Test
     public void testFilter() throws Exception {
         InputStream in = getClass().getResourceAsStream("test1.txt");
         try {
@@ -69,6 +73,7 @@ public class ListenerTestCase extends Te
      * Tests listeners on DSCParser.
      * @throws Exception if an error occurs
      */
+    @Test
     public void testListeners() throws Exception {
         InputStream in = getClass().getResourceAsStream("test1.txt");
         try {
@@ -104,7 +109,7 @@ public class ListenerTestCase extends Te
                 public void processEvent(DSCEvent event, DSCParser parser)
                         throws IOException, DSCException {
                     if (event instanceof DSCCommentLanguageLevel) {
-                        DSCCommentLanguageLevel level = (DSCCommentLanguageLevel)event;
+                        DSCCommentLanguageLevel level = (DSCCommentLanguageLevel) event;
                         results.put("level", new Integer(level.getLanguageLevel()));
                     }
                 }

Modified: xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/ps/dsc/events/DSCCommentBoundingBoxTestCase.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/ps/dsc/events/DSCCommentBoundingBoxTestCase.java?rev=1365650&r1=1365649&r2=1365650&view=diff
==============================================================================
--- xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/ps/dsc/events/DSCCommentBoundingBoxTestCase.java (original)
+++ xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/ps/dsc/events/DSCCommentBoundingBoxTestCase.java Wed Jul 25 15:59:30 2012
@@ -22,28 +22,31 @@ package org.apache.xmlgraphics.ps.dsc.ev
 import java.awt.Rectangle;
 import java.awt.geom.Rectangle2D;
 
-import junit.framework.TestCase;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
 
 import org.apache.xmlgraphics.ps.dsc.DSCCommentFactory;
 
-public class DSCCommentBoundingBoxTestCase extends TestCase {
+public class DSCCommentBoundingBoxTestCase {
 
+    @Test
     public void testBoundingBox() throws Exception {
         DSCComment comment = DSCCommentFactory.createDSCCommentFor("BoundingBox");
-        DSCCommentBoundingBox bbox = (DSCCommentBoundingBox)comment;
+        DSCCommentBoundingBox bbox = (DSCCommentBoundingBox) comment;
         bbox.parseValue("289 412 306 429");
         Rectangle refRect = new Rectangle(289, 412, 306 - 289, 429 - 412);
         assertEquals(refRect, bbox.getBoundingBox());
 
         comment = DSCCommentFactory.createDSCCommentFor("BoundingBox");
-        bbox = (DSCCommentBoundingBox)comment;
+        bbox = (DSCCommentBoundingBox) comment;
         bbox.parseValue("289.12 412.2 306.777 429.11");
         Rectangle2D refRect2D = new Rectangle2D.Double(
                 289.12, 412.2, 306.777 - 289.12, 429.11 - 412.2);
         assertEquals(refRect2D, bbox.getBoundingBox());
 
         comment = DSCCommentFactory.createDSCCommentFor("HiResBoundingBox");
-        bbox = (DSCCommentHiResBoundingBox)comment;
+        bbox = (DSCCommentHiResBoundingBox) comment;
         bbox.parseValue("289.12 412.2 306.777 429.11");
         refRect2D = new Rectangle2D.Double(
                 289.12, 412.2, 306.777 - 289.12, 429.11 - 412.2);

Modified: xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/ps/dsc/events/DSCValueParserTestCase.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/ps/dsc/events/DSCValueParserTestCase.java?rev=1365650&r1=1365649&r2=1365650&view=diff
==============================================================================
--- xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/ps/dsc/events/DSCValueParserTestCase.java (original)
+++ xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/ps/dsc/events/DSCValueParserTestCase.java Wed Jul 25 15:59:30 2012
@@ -21,16 +21,17 @@ package org.apache.xmlgraphics.ps.dsc.ev
 
 import java.util.List;
 
-import org.apache.xmlgraphics.ps.dsc.events.DSCCommentBeginResource;
+import org.junit.Test;
 
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
 
-public class DSCValueParserTestCase extends TestCase {
+public class DSCValueParserTestCase {
 
     private String[] toArray(List params) {
-        return (String[])params.toArray(new String[params.size()]);
+        return (String[]) params.toArray(new String[params.size()]);
     }
 
+    @Test
     public void testText() throws Exception {
         DSCCommentBeginResource obj = new DSCCommentBeginResource();
         String[] res = toArray(obj.splitParams("procset Test"));
@@ -44,6 +45,7 @@ public class DSCValueParserTestCase exte
         assertEquals("Test", res[1]);
     }
 
+    @Test
     public void testParentheseText() throws Exception {
         DSCCommentBeginResource obj = new DSCCommentBeginResource();
         String[] res = toArray(obj.splitParams("procset (Hello World!)"));

Modified: xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/ps/dsc/tools/DSCToolsTestCase.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/ps/dsc/tools/DSCToolsTestCase.java?rev=1365650&r1=1365649&r2=1365650&view=diff
==============================================================================
--- xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/ps/dsc/tools/DSCToolsTestCase.java (original)
+++ xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/ps/dsc/tools/DSCToolsTestCase.java Wed Jul 25 15:59:30 2012
@@ -19,16 +19,20 @@
 
 package org.apache.xmlgraphics.ps.dsc.tools;
 
+import org.junit.Test;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
 import org.apache.xmlgraphics.ps.dsc.events.DSCCommentEndComments;
 import org.apache.xmlgraphics.ps.dsc.events.DSCCommentPages;
 import org.apache.xmlgraphics.ps.dsc.events.DSCEvent;
 import org.apache.xmlgraphics.ps.dsc.events.PostScriptComment;
 import org.apache.xmlgraphics.ps.dsc.events.PostScriptLine;
 
-import junit.framework.TestCase;
-
-public class DSCToolsTestCase extends TestCase {
+public class DSCToolsTestCase {
 
+    @Test
     public void testEndComment() throws Exception {
         DSCEvent event;
 

Added: xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/util/ClasspathResourceTestCase.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/util/ClasspathResourceTestCase.java?rev=1365650&view=auto
==============================================================================
--- xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/util/ClasspathResourceTestCase.java (added)
+++ xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/util/ClasspathResourceTestCase.java Wed Jul 25 15:59:30 2012
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.xmlgraphics.util;
+
+import java.net.URL;
+import java.util.Iterator;
+import java.util.List;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertTrue;
+
+/**
+ * Test for the Service class.
+ */
+public class ClasspathResourceTestCase {
+
+    /**
+     * Tests whether the file /sample.txt with mime-type text/plain exists.
+     *
+     * @throws Exception
+     *             in case of an error
+     */
+    @Test
+    public void testSampleResource() throws Exception {
+        final List list = ClasspathResource.getInstance()
+                .listResourcesOfMimeType("text/plain");
+        boolean found = false;
+        final Iterator i = list.iterator();
+        while (i.hasNext()) {
+            final URL u = (URL) i.next();
+            if (u.getPath().endsWith("sample.txt")) {
+                found = true;
+            }
+        }
+        assertTrue(found);
+    }
+
+    /**
+     * Tests the mode where Service returns class names.
+     *
+     * @throws Exception
+     *             in case of an error
+     */
+    @Test
+    public void testNonexistingResource() throws Exception {
+        final List list = ClasspathResource.getInstance()
+                .listResourcesOfMimeType("nota/mime-type");
+        assertTrue(list.isEmpty());
+    }
+}

Propchange: xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/util/ClasspathResourceTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/util/DateFormatUtilTestCase.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/util/DateFormatUtilTestCase.java?rev=1365650&r1=1365649&r2=1365650&view=diff
==============================================================================
--- xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/util/DateFormatUtilTestCase.java (original)
+++ xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/util/DateFormatUtilTestCase.java Wed Jul 25 15:59:30 2012
@@ -24,19 +24,23 @@ import java.util.Date;
 import java.util.Locale;
 import java.util.TimeZone;
 
-import org.apache.xmlgraphics.xmp.XMPSchemaAdapter;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
 
-import junit.framework.TestCase;
+import org.apache.xmlgraphics.xmp.XMPSchemaAdapter;
 
 /**
  * Tests date formatting for XMP.
  */
-public class DateFormatUtilTestCase extends TestCase {
+public class DateFormatUtilTestCase {
 
     /**
      * Checks date formatting for XMP.
      * @throws Exception if an error occurs
      */
+    @Test
     public void testDateFormattingISO8601() throws Exception {
         Date dt = createTestDate();
 
@@ -69,6 +73,7 @@ public class DateFormatUtilTestCase exte
         return dt;
     }
 
+    @Test
     public void testDateFormattingPDF() throws Exception {
         Date dt = createTestDate();
 
@@ -88,14 +93,17 @@ public class DateFormatUtilTestCase exte
         assertEquals("D:20080207041107-11'00'", s);
     }
 
+    @Test
     public void testParseInvalidDateNoColonUTC() {
         testInvalidDate("2008-02-07T151107Z");
     }
 
+    @Test
     public void testParseInvalidDateNoColonLocal() {
         testInvalidDate("2008-02-07T151107+0000");
     }
 
+    @Test
     public void testParseInvalidDateColonLast() {
         testInvalidDate("2008-02-07T151107Z:");
     }

Added: xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/util/DoubleFormatUtilTestCase.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/util/DoubleFormatUtilTestCase.java?rev=1365650&view=auto
==============================================================================
--- xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/util/DoubleFormatUtilTestCase.java (added)
+++ xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/util/DoubleFormatUtilTestCase.java Wed Jul 25 15:59:30 2012
@@ -0,0 +1,594 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.xmlgraphics.util;
+
+import java.math.BigDecimal;
+import java.text.DecimalFormat;
+import java.text.DecimalFormatSymbols;
+import java.util.Locale;
+import java.util.Random;
+
+import org.junit.Ignore;
+import org.junit.Test;
+
+import static org.junit.Assert.assertTrue;
+
+/**
+ * Test class of DoubleFormatUtil
+ */
+public class DoubleFormatUtilTestCase {
+
+    /**
+     * Test simple values as specified in the format contract.
+     * <p>
+     * Note: Some of these tests will fail if formatFast is used.
+     */
+    @Test
+    public void testSimple() {
+        int decimals = 4;
+        int precision = 8;
+
+        double value = 0.0;
+        String expected = "0";
+        String actual = format(value, decimals, precision);
+        assertEquals(value, decimals, precision, expected, actual);
+
+        value = 0.1;
+        expected = "0.1";
+        actual = format(value, decimals, precision);
+        assertEquals(value, decimals, precision, expected, actual);
+
+        value = 1234.1;
+        expected = "1234.1";
+        actual = format(value, decimals, precision);
+        assertEquals(value, decimals, precision, expected, actual);
+
+        // rounding
+        value = 1234.1234567;
+        expected = "1234.1235";
+        actual = format(value, decimals, precision);
+        assertEquals(value, decimals, precision, expected, actual);
+
+        value = 1234.99995;
+        expected = "1235";
+        actual = format(value, decimals, precision);
+        assertEquals(value, decimals, precision, expected, actual);
+
+        value = -1234.99995;
+        expected = "-1235";
+        actual = format(value, decimals, precision);
+        assertEquals(value, decimals, precision, expected, actual);
+
+        value = 1234.99994999;
+        expected = "1234.9999";
+        actual = format(value, decimals, precision);
+        assertEquals(value, decimals, precision, expected, actual);
+
+        // decimals / precision switch
+        value = 0.00000001;
+        expected = "0.00000001";
+        actual = format(value, decimals, precision);
+        assertEquals(value, decimals, precision, expected, actual);
+
+        value = -0.00000001;
+        expected = "-0.00000001";
+        actual = format(value, decimals, precision);
+        assertEquals(value, decimals, precision, expected, actual);
+
+        value = 72.00001234;
+        expected = "72";
+        actual = format(value, decimals, precision);
+        assertEquals(value, decimals, precision, expected, actual);
+
+        // limit precision
+        value = 0.000000001;
+        expected = "0";
+        actual = format(value, decimals, precision);
+        assertEquals(value, decimals, precision, expected, actual);
+
+        value = 5.0e-9;
+        expected = "0.00000001";
+        actual = format(value, decimals, precision);
+        assertEquals(value, decimals, precision, expected, actual);
+
+        value = 4.9999999999e-9;
+        expected = "0";
+        actual = format(value, decimals, precision);
+        assertEquals(value, decimals, precision, expected, actual);
+
+        value = 2.0005e-5;
+        expected = "0.00002001";
+        actual = format(value, decimals, precision);
+        assertEquals(value, decimals, precision, expected, actual);
+
+        value = 2.00049999999999e-5;
+        expected = "0.00002";
+        actual = format(value, decimals, precision);
+        assertEquals(value, decimals, precision, expected, actual);
+
+        // Test added after bug #43940 was reopened
+        value = 0.005859375;
+        expected = "0.00585938";
+        actual = format(value, 8, 8);
+        assertEquals(value, 8, 8, expected, actual);
+
+        value = 5.22534294505995E-4;
+        expected = "0.000522534294506";
+        actual = format(value, 17, 17);
+        assertEquals(value, 17, 17, expected, actual);
+
+        value = 4.9E-324;
+        expected = "0";
+        actual = format(value, 309, 309);
+        assertEquals(value, 309, 309, expected, actual);
+
+        value = 7.003868765287485E-280;
+        expected = refFormat(value, 294, 294);
+        actual = format(value, 294, 294);
+        assertEquals(value, 294, 294, expected, actual);
+
+        value = 5E-304;
+        expected = refFormat(value, 303, 303);
+        actual = format(value, 303, 303);
+        assertEquals(value, 303, 303, expected, actual);
+
+        value = 9.999999999999999E-250;
+        expected = refFormat(value, 265, 265);
+        actual = format(value, 265, 265);
+        assertEquals(value, 265, 265, expected, actual);
+    }
+
+    @Test
+    public void testLimits() {
+        int decimals = 19;
+        int precision = 19;
+
+        double value = Double.NaN;
+        String expected = "NaN";
+        String actual = format(value, decimals, precision);
+        assertEquals(value, decimals, precision, expected, actual);
+
+        value = Double.POSITIVE_INFINITY;
+        expected = "Infinity";
+        actual = format(value, decimals, precision);
+        assertEquals(value, decimals, precision, expected, actual);
+
+        value = Double.NEGATIVE_INFINITY;
+        expected = "-Infinity";
+        actual = format(value, decimals, precision);
+        assertEquals(value, decimals, precision, expected, actual);
+
+        value = 1e-3 + Double.MIN_VALUE;
+        expected = "0.001";
+        actual = format(value, decimals, precision);
+        assertEquals(value, decimals, precision, expected, actual);
+
+        value = 1e-3 - Double.MIN_VALUE;
+        expected = "0.001";
+        actual = format(value, decimals, precision);
+        assertEquals(value, decimals, precision, expected, actual);
+
+        value = 1e-3;
+        expected = "0.001";
+        actual = format(value, decimals, precision);
+        assertEquals(value, decimals, precision, expected, actual);
+
+        value = 0.0010000000000000002; // == Math.nextAfter(1e-3, Double.POSITIVE_INFINITY);
+        expected = "0.0010000000000000002";
+        actual = format(value, decimals, precision);
+        assertEquals(value, decimals, precision, expected, actual);
+        expected = "0.001";
+        actual = format(value, 18, 18);
+        assertEquals(value, 18, 18, expected, actual);
+
+        value = 0.0009999999999999998; // == Math.nextAfter(1e-3, Double.NEGATIVE_INFINITY);
+        expected = "0.0009999999999999998";
+        actual = format(value, decimals, precision);
+        assertEquals(value, decimals, precision, expected, actual);
+        expected = "0.001";
+        actual = format(value, 18, 18);
+        assertEquals(value, 18, 18, expected, actual);
+
+        value = 1e7 + Double.MIN_VALUE;
+        expected = "10000000";
+        actual = format(value, decimals, precision);
+        assertEquals(value, decimals, precision, expected, actual);
+
+        value = 1e7 - Double.MIN_VALUE;
+        expected = "10000000";
+        actual = format(value, decimals, precision);
+        assertEquals(value, decimals, precision, expected, actual);
+
+        value = 1e7;
+        expected = "10000000";
+        actual = format(value, decimals, precision);
+        assertEquals(value, decimals, precision, expected, actual);
+
+        value = 1.0000000000000002E7; // == Math.nextAfter(1e7, Double.POSITIVE_INFINITY);
+        expected = "10000000.000000002";
+        actual = format(value, decimals, precision);
+        assertEquals(value, decimals, precision, expected, actual);
+        expected = "10000000";
+        actual = format(value, 8, 8);
+        assertEquals(value, 8, 8, expected, actual);
+
+        value = 9999999.999999998; // == Math.nextAfter(1e7, Double.NEGATIVE_INFINITY);
+        expected = "9999999.999999998";
+        actual = format(value, decimals, precision);
+        assertEquals(value, decimals, precision, expected, actual);
+        expected = "10000000";
+        actual = format(value, 8, 8);
+        assertEquals(value, 8, 8, expected, actual);
+
+        value = 0.000009999999999999997; // Check higher precision
+        expected = "0.000009999999999999997";
+        actual = format(value, 21, 21);
+        assertEquals(value, 21, 21, expected, actual);
+        expected = "0.00001";
+        actual = format(value, 20, 20);
+        assertEquals(value, 20, 20, expected, actual);
+    }
+
+    /**
+     * AssertEquals with a more detailed message
+     */
+    private static void assertEquals(double value, int decimals, int precision, String expected, String actual) {
+        assertTrue("value: " + value + ", decimals: " + decimals + ", precision: " + precision,
+                expected.equals(actual));
+    }
+
+    /**
+     * The buffer used to format
+     */
+    private StringBuffer buf = new StringBuffer();
+
+    /**
+     * Formats using FormatUtil#formatDouble method
+     */
+    private String format(double value, int decimals, int precision) {
+        buf.setLength(0);
+        DoubleFormatUtil.formatDouble(value, decimals, precision, buf);
+        return buf.toString();
+    }
+
+    /**
+     * Formats using FormatUtil#formatDoublePrecise method
+     */
+    private String formatPrecise(double value, int decimals, int precision) {
+        buf.setLength(0);
+        DoubleFormatUtil.formatDoublePrecise(value, decimals, precision, buf);
+        return buf.toString();
+    }
+
+    /**
+     * Formats using FormatUtil#formatDoubleFast method
+     */
+    private String formatFast(double value, int decimals, int precision) {
+        buf.setLength(0);
+        DoubleFormatUtil.formatDoubleFast(value, decimals, precision, buf);
+        return buf.toString();
+    }
+
+    /**
+     * Formats using a BigDecimal. This is the reference (always returns the correct format)
+     * whereas DecimalFormat may have some formating errors regarding the last digit.
+     */
+    private String refFormat(double value, int decimals, int precision) {
+        if (Double.isNaN(value) || Double.isInfinite(value)) {
+            return Double.toString(value);
+        }
+        buf.setLength(0);
+        BigDecimal bg = new BigDecimal(Double.toString(value));
+        int scale = Math.abs(value) < 1.0 ? precision : decimals;
+        bg = bg.setScale(scale, BigDecimal.ROUND_HALF_UP);
+        //buf.append(bg.toString()); // Java 1.4
+        buf.append(bg.toPlainString()); // Java 1.5 and more !
+        if (buf.indexOf(".") >= 0) {
+            for (int i = buf.length() - 1; i > 1 && buf.charAt(i) == '0'; i--) {
+                buf.setLength(i);
+            }
+            if (buf.charAt(buf.length() - 1) == '.') {
+                buf.setLength(buf.length() - 1);
+            }
+        }
+        return buf.toString();
+    }
+
+    /**
+     * The decimal format used within formatDf method
+     */
+    private DecimalFormat df = new DecimalFormat("0", new DecimalFormatSymbols(Locale.US));
+
+    /**
+     * Formats using DecimalFormat#format method
+     */
+    private String formatDf(double value, int decimals, int precision) {
+        int scale = Math.abs(value) < 1.0 ? precision : decimals;
+        df.setMaximumFractionDigits(scale);
+        return df.format(value);
+    }
+
+    /**
+     * The maximum power of ten to use when testing high values double
+     */
+    private static final int maxPow = 12;
+
+    /**
+     * Tests the formatPrecise method against the reference, with random values
+     */
+    @Test
+    public void testPrecise() {
+        long seed = System.currentTimeMillis();
+        Random r = new Random();
+        r.setSeed(seed);
+
+        double value, highValue, lowValue;
+        int nbTest = 10000;
+        int maxDecimals = 12;
+
+        String actual, expected;
+        for (int i = nbTest; i > 0; i--) {
+            int decimals = r.nextInt(maxDecimals);
+            int precision = decimals + 3;
+            value = 1 + r.nextDouble(); // Use decimals and not precision
+            expected = refFormat(value, decimals, precision);
+            actual = formatPrecise(value, decimals, precision);
+            assertEquals(value, decimals, precision, expected, actual);
+
+            highValue = value * DoubleFormatUtil.tenPow(r.nextInt(maxPow));
+            expected = refFormat(highValue, decimals, precision);
+            actual = formatPrecise(highValue, decimals, precision);
+            assertEquals(highValue, decimals, precision, expected, actual);
+
+            lowValue = (value - 1) / 1000;
+            expected = refFormat(lowValue, decimals, precision);
+            actual = formatPrecise(lowValue, decimals, precision);
+            assertEquals(lowValue, decimals, precision, expected, actual);
+        }
+    }
+
+    /**
+     * Tests the format method against the reference, with random values
+     */
+    @Test
+    public void testFormat() {
+        long seed = System.currentTimeMillis();
+        Random r = new Random();
+        r.setSeed(seed);
+
+        double value, highValue, lowValue;
+        int nbTest = 10000;
+        int maxDecimals = 12;
+
+        String actual, expected;
+        for (int i = nbTest; i > 0; i--) {
+            int decimals = r.nextInt(maxDecimals);
+            int precision = decimals + 3;
+            value = 1 + r.nextDouble(); // Use decimals and not precision
+            expected = refFormat(value, decimals, precision);
+            actual = format(value, decimals, precision);
+            assertEquals(value, decimals, precision, expected, actual);
+
+            highValue = value * DoubleFormatUtil.tenPow(r.nextInt(maxPow));
+            expected = refFormat(highValue, decimals, precision);
+            actual = format(highValue, decimals, precision);
+            assertEquals(highValue, decimals, precision, expected, actual);
+
+            lowValue = (value - 1) / 1000;
+            expected = refFormat(lowValue, decimals, precision);
+            actual = format(lowValue, decimals, precision);
+            assertEquals(lowValue, decimals, precision, expected, actual);
+        }
+    }
+
+    /**
+     * Tests the formatFast method against the reference, with random values.
+     * Disabled since the formatFast method is not accurate.
+     */
+    @Test
+    @Ignore("Disabled since the formatFast method is not accurate.")
+    public void fast() {
+        long seed = System.currentTimeMillis();
+        Random r = new Random();
+        r.setSeed(seed);
+
+        double value, highValue, lowValue;
+        int nbTest = 10000;
+        int maxDecimals = 12;
+
+        String actual, expected;
+        for (int i = nbTest; i > 0; i--) {
+            int decimals = r.nextInt(maxDecimals);
+            int precision = decimals + 3;
+            value = 1 + r.nextDouble(); // Use decimals and not precision
+            expected = refFormat(value, decimals, precision);
+            actual = formatFast(value, decimals, precision);
+            assertEquals(value, decimals, precision, expected, actual);
+
+            highValue = value * DoubleFormatUtil.tenPow(r.nextInt(maxPow));
+            expected = refFormat(highValue, decimals, precision);
+            actual = formatFast(highValue, decimals, precision);
+            System.out.println(expected);
+            System.out.println(actual);
+            assertEquals(highValue, decimals, precision, expected, actual);
+
+            lowValue = (value - 1) / 1000;
+            expected = refFormat(lowValue, decimals, precision);
+            actual = formatFast(lowValue, decimals, precision);
+            assertEquals(lowValue, decimals, precision, expected, actual);
+        }
+    }
+
+    /**
+     * Performance comparison of the differents formatXXX methods,
+     * to see which one is the fastest in the same conditions.
+     */
+    @Test
+    public void performanceCompare() {
+        // Rename this method in testPerformanceCompare to run it within JUnit tests
+        // This method is quite long (depends of the value of nbTest).
+        long seed = System.currentTimeMillis();
+        Random r = new Random();
+        r.setSeed(seed);
+
+        double value, highValue, lowValue;
+        long start = System.currentTimeMillis();
+        int nbTest = 1000000;
+        int maxDecimals = 16;
+
+        r.setSeed(seed);
+        start = System.currentTimeMillis();
+        for (int i = nbTest; i > 0; i--) {
+            int decimals = r.nextInt(maxDecimals);
+            int precision = decimals + 3;
+            value = 1 + r.nextDouble(); // Use decimals and not precision
+            format(value, decimals, precision);
+
+            highValue = value * DoubleFormatUtil.tenPow(r.nextInt(maxPow));
+            format(highValue, decimals, precision);
+
+            lowValue = (value - 1) / 1000;
+            format(lowValue, decimals, precision);
+        }
+        long formatDuration = System.currentTimeMillis() - start;
+        System.out.println("Format duration: " + formatDuration + "ms to format " + (3 * nbTest) + " doubles");
+
+        r.setSeed(seed);
+        start = System.currentTimeMillis();
+        for (int i = nbTest; i > 0; i--) {
+            int decimals = r.nextInt(maxDecimals);
+            int precision = decimals + 3;
+            value = 1 + r.nextDouble(); // Use decimals and not precision
+            formatPrecise(value, decimals, precision);
+
+            highValue = value * DoubleFormatUtil.tenPow(r.nextInt(maxPow));
+            formatPrecise(highValue, decimals, precision);
+
+            lowValue = (value - 1) / 1000;
+            formatPrecise(lowValue, decimals, precision);
+        }
+        long preciseFormatDuration = System.currentTimeMillis() - start;
+        System.out.println("Format Precise duration: " + preciseFormatDuration + "ms to format " + (3 * nbTest) + " doubles");
+
+        r.setSeed(seed);
+        start = System.currentTimeMillis();
+        for (int i = nbTest; i > 0; i--) {
+            int decimals = r.nextInt(maxDecimals);
+            int precision = decimals + 3;
+            value = 1 + r.nextDouble(); // Use decimals and not precision
+            formatFast(value, decimals, precision);
+
+            highValue = value * DoubleFormatUtil.tenPow(r.nextInt(maxPow));
+            formatFast(highValue, decimals, precision);
+
+            lowValue = (value - 1) / 1000;
+            formatFast(lowValue, decimals, precision);
+        }
+        long fastFormatDuration = System.currentTimeMillis() - start;
+        System.out.println("Fast Format duration: " + fastFormatDuration + "ms to format " + (3 * nbTest) + " doubles");
+
+        r.setSeed(seed);
+        start = System.currentTimeMillis();
+        for (int i = nbTest; i > 0; i--) {
+            int decimals = r.nextInt(maxDecimals);
+            int precision = decimals + 3;
+            value = 1 + r.nextDouble(); // Use decimals and not precision
+            refFormat(value, decimals, precision);
+
+            highValue = value * DoubleFormatUtil.tenPow(r.nextInt(maxPow));
+            refFormat(highValue, decimals, precision);
+
+            lowValue = (value - 1) / 1000;
+            refFormat(lowValue, decimals, precision);
+        }
+        long bgDuration = System.currentTimeMillis() - start;
+        System.out.println("BigDecimal format duration: " + bgDuration + "ms to format " + (3 * nbTest) + " doubles");
+
+        r.setSeed(seed);
+        start = System.currentTimeMillis();
+        for (int i = nbTest; i > 0; i--) {
+            int decimals = r.nextInt(maxDecimals);
+            int precision = decimals + 3;
+            value = 1 + r.nextDouble(); // Use decimals and not precision
+            formatDf(value, decimals, precision);
+
+            highValue = value * DoubleFormatUtil.tenPow(r.nextInt(maxPow));
+            formatDf(highValue, decimals, precision);
+
+            lowValue = (value - 1) / 1000;
+            formatDf(lowValue, decimals, precision);
+        }
+        long dfDuration = System.currentTimeMillis() - start;
+        System.out.println("DecimalFormat duration: " + dfDuration + "ms to format " + (3 * nbTest) + " doubles");
+
+        r.setSeed(seed);
+        start = System.currentTimeMillis();
+        for (int i = nbTest; i > 0; i--) {
+            int decimals = r.nextInt(maxDecimals);
+            int precision = decimals + 3;
+            precision++; // Avoid warning unused local variable
+            value = 1 + r.nextDouble(); // Use decimals and not precision
+            Double.toString(value);
+
+            highValue = value * DoubleFormatUtil.tenPow(r.nextInt(maxPow));
+            Double.toString(highValue);
+
+            lowValue = (value - 1) / 1000;
+            Double.toString(lowValue);
+        }
+        long toStringDuration = System.currentTimeMillis() - start;
+        System.out.println("toString duration: " + toStringDuration + "ms to format " + (3 * nbTest) + " doubles");
+    }
+
+    @Test
+    public void testAllDoubleRanges() {
+        double[] values = {0, 1, 5, 4.9999, 5.0001, 9.9999, 1234567890, 0 /* The last one is random */};
+        Random r = new Random();
+        double value;
+        String expected, actual;
+        int minScale, maxScale;
+        for (int i = -330; i <= 315; i++) {
+            values[values.length - 1] = r.nextDouble();
+            double pow = Math.pow(10.0, i);
+            for (double d : values) {
+                value = d * pow;
+                minScale = 1;
+                maxScale = 350;
+                // Reduce scales (unnecessary tests)
+                if (i < -30) {
+                    minScale = -i - 30;
+                    maxScale = -i + 30;
+                } else if (i <= 0) {
+                    minScale = 1;
+                    maxScale = -i + 30;
+                } else {
+                    minScale = 1;
+                    maxScale = 30;
+                }
+                for (int scale = minScale; scale <= maxScale; scale++) {
+                    expected = refFormat(value, scale, scale);
+                    actual = format(value, scale, scale);
+                    assertEquals(value, scale, scale, expected, actual);
+                }
+            }
+
+        }
+    }
+}

Propchange: xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/util/DoubleFormatUtilTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/util/HexUtil.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/util/HexUtil.java?rev=1365650&r1=1365649&r2=1365650&view=diff
==============================================================================
--- xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/util/HexUtil.java (original)
+++ xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/util/HexUtil.java Wed Jul 25 15:59:30 2012
@@ -22,7 +22,10 @@ package org.apache.xmlgraphics.util;
 /**
  * Provides helper functions for converting hexadecimal strings.
  */
-public class HexUtil {
+public final class HexUtil {
+
+    private HexUtil() {
+    }
 
     private static final char[] DIGITS =
         {'0', '1', '2', '3', '4', '5', '6', '7',
@@ -33,7 +36,7 @@ public class HexUtil {
      * @param data the data to encode
      * @return String the resulting String
      */
-    public static final String toHex(byte[] data) {
+    public static String toHex(byte[] data) {
         final StringBuffer sb = new StringBuffer(data.length * 2);
         for (int i = 0; i < data.length; i++) {
             sb.append(DIGITS[(data[i] >>> 4) & 0x0F]);

Added: xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/util/ServiceTestCase.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/util/ServiceTestCase.java?rev=1365650&view=auto
==============================================================================
--- xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/util/ServiceTestCase.java (added)
+++ xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/util/ServiceTestCase.java Wed Jul 25 15:59:30 2012
@@ -0,0 +1,112 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.xmlgraphics.util;
+
+import java.util.Iterator;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import org.apache.xmlgraphics.image.writer.ImageWriter;
+
+/**
+ * Test for the Service class.
+ */
+public class ServiceTestCase {
+
+    /**
+     * Tests the mode where Service returns instances.
+     * @throws Exception in case of an error
+     */
+    @Test
+    public void testWithInstances() throws Exception {
+        Class cls = ImageWriter.class;
+        boolean found = false;
+        Object writer1 = null;
+        Object writer2 = null;
+
+        //First run: Find a writer implementation (one of the two must be available)
+        Iterator iter = Service.providers(cls);
+        while (iter.hasNext()) {
+            Object obj = iter.next();
+            assertNotNull(obj);
+            String className = obj.getClass().getName();
+            if ("org.apache.xmlgraphics.image.writer.internal.PNGImageWriter".equals(className)) {
+                writer1 = obj;
+                found = true;
+                break;
+            } else if ("org.apache.xmlgraphics.image.writer.imageio.ImageIOPNGImageWriter".equals(
+                    className)) {
+                writer2 = obj;
+                found = true;
+                break;
+            }
+        }
+        assertTrue("None of the expected classes found", found);
+
+        //Second run: verify that the same instances are returned
+        iter = Service.providers(cls);
+        while (iter.hasNext()) {
+            Object obj = iter.next();
+            assertNotNull(obj);
+            String className = obj.getClass().getName();
+            if ("org.apache.xmlgraphics.image.writer.internal.PNGImageWriter".equals(className)) {
+                assertTrue(obj == writer1);
+                break;
+            } else if ("org.apache.xmlgraphics.image.writer.imageio.ImageIOPNGImageWriter".equals(
+                    className)) {
+                assertTrue(obj == writer2);
+                break;
+            }
+        }
+    }
+
+    /**
+     * Tests the mode where Service returns class names.
+     * @throws Exception in case of an error
+     */
+    @Test
+    public void testWithClassNames() throws Exception {
+        Class cls = ImageWriter.class;
+        boolean found = true;
+        Iterator iter = Service.providerNames(cls);
+        while (iter.hasNext()) {
+            Object obj = iter.next();
+            assertNotNull(obj);
+            assertTrue("Returned object must be a class name", obj instanceof String);
+            if ("org.apache.xmlgraphics.image.writer.internal.PNGImageWriter".equals(obj)
+                    || ("org.apache.xmlgraphics.image.writer.imageio.ImageIOPNGImageWriter".equals(
+                                obj))) {
+                found = true;
+            }
+        }
+        assertTrue("None of the expected classes found", found);
+
+        //Do it a second time to make sure the cache works as expected
+        iter = Service.providerNames(cls);
+        while (iter.hasNext()) {
+            Object obj = iter.next();
+            assertNotNull(obj);
+            assertTrue("Returned object must be a class name", obj instanceof String);
+        }
+    }
+}

Propchange: xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/util/ServiceTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/util/UnitConvTestCase.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/util/UnitConvTestCase.java?rev=1365650&r1=1365649&r2=1365650&view=diff
==============================================================================
--- xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/util/UnitConvTestCase.java (original)
+++ xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/util/UnitConvTestCase.java Wed Jul 25 15:59:30 2012
@@ -19,19 +19,20 @@
 
 package org.apache.xmlgraphics.util;
 
-import org.apache.xmlgraphics.util.UnitConv;
+import org.junit.Test;
 
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
 
 /**
  * Test class for UnitConv.
  */
-public class UnitConvTestCase extends TestCase {
+public class UnitConvTestCase {
 
     /**
      * Test all kinds of unit conversions.
      * @throws Exception if the test fails
      */
+    @Test
     public void testConversions() throws Exception {
         assertEquals("in2mm", 25.4, UnitConv.in2mm(1), 0.00001);
         assertEquals("mm2in", 1.0, UnitConv.mm2in(25.4), 0.00001);
@@ -44,5 +45,4 @@ public class UnitConvTestCase extends Te
         assertEquals("mm2px/72dpi", 841.8897764234434, UnitConv.mm2px(297.0, 72), 0);
         assertEquals("mm2px/300dpi", 3507.8740684310146, UnitConv.mm2px(297.0, 300), 0);
     }
-
-}
\ No newline at end of file
+}

Modified: xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/util/io/ASCII85InputStreamTestCase.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/util/io/ASCII85InputStreamTestCase.java?rev=1365650&r1=1365649&r2=1365650&view=diff
==============================================================================
--- xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/util/io/ASCII85InputStreamTestCase.java (original)
+++ xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/util/io/ASCII85InputStreamTestCase.java Wed Jul 25 15:59:30 2012
@@ -23,13 +23,16 @@ import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.io.InputStream;
 
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
 import org.apache.commons.io.IOUtils;
 import org.apache.commons.io.output.ByteArrayOutputStream;
 
 import org.apache.xmlgraphics.util.HexUtil;
 
-import junit.framework.TestCase;
-
 /**
  * Test case for ASCII85InputStream.
  * <p>
@@ -37,17 +40,10 @@ import junit.framework.TestCase;
  * ASCII85OutputStream. If something fails here make sure
  * ASCII85OutputStreamTestCase runs!
  */
-public class ASCII85InputStreamTestCase extends TestCase {
+public class ASCII85InputStreamTestCase {
 
     private static final boolean DEBUG = false;
 
-    /**
-     * @see junit.framework.TestCase#TestCase(String)
-     */
-    public ASCII85InputStreamTestCase(String name) {
-        super(name);
-    }
-
     private byte[] decode(String text) throws Exception {
         byte[] ascii85 = text.getBytes("US-ASCII");
         InputStream in = new ByteArrayInputStream(ascii85);
@@ -97,8 +93,8 @@ public class ASCII85InputStreamTestCase 
      * Tests the output of ASCII85.
      * @throws Exception if an error occurs
      */
+    @Test
     public void testDecode() throws Exception {
-        byte[] buf;
         innerTestDecode("1. Bodypart".getBytes("US-ASCII"));
         if (DEBUG) {
             System.out.println("===========================================");
@@ -160,6 +156,7 @@ public class ASCII85InputStreamTestCase 
      * Tests the full 8-bit ASCII range.
      * @throws Exception if an error occurs
      */
+    @Test
     public void testFullASCIIRange() throws Exception {
         innerTestDecode(getFullASCIIRange());
     }

Modified: xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/util/io/ASCII85OutputStreamTestCase.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/util/io/ASCII85OutputStreamTestCase.java?rev=1365650&r1=1365649&r2=1365650&view=diff
==============================================================================
--- xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/util/io/ASCII85OutputStreamTestCase.java (original)
+++ xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/util/io/ASCII85OutputStreamTestCase.java Wed Jul 25 15:59:30 2012
@@ -21,14 +21,16 @@ package org.apache.xmlgraphics.util.io;
 
 import java.io.OutputStream;
 
-import org.apache.commons.io.output.ByteArrayOutputStream;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
 
-import junit.framework.TestCase;
+import org.apache.commons.io.output.ByteArrayOutputStream;
 
 /**
  * Test case for ASCII85OutputStream
  */
-public class ASCII85OutputStreamTestCase extends TestCase {
+public class ASCII85OutputStreamTestCase {
 
     /** Test data */
     public static final byte[] DATA = new byte[100];
@@ -36,17 +38,10 @@ public class ASCII85OutputStreamTestCase
     static {
         //Fill in some data
         for (int i = 0; i < 100; i++) {
-            DATA[i] = (byte)i;
+            DATA[i] = (byte) i;
         }
     }
 
-    /**
-     * @see junit.framework.TestCase#TestCase(String)
-     */
-    public ASCII85OutputStreamTestCase(String name) {
-        super(name);
-    }
-
     private String encode(int count) throws Exception {
         return encode(DATA, count);
     }
@@ -63,6 +58,7 @@ public class ASCII85OutputStreamTestCase
      * Tests the output of ASCII85.
      * @throws Exception if an error occurs
      */
+    @Test
     public void testOutput() throws Exception {
         String sz = encode(new byte[] {0, 0, 0, 0, 0, 0, 0, 0}, 8);
         assertEquals("zz~>", sz);

Added: xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/util/io/Base64TestCase.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/util/io/Base64TestCase.java?rev=1365650&view=auto
==============================================================================
--- xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/util/io/Base64TestCase.java (added)
+++ xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/util/io/Base64TestCase.java Wed Jul 25 15:59:30 2012
@@ -0,0 +1,249 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.xmlgraphics.util.io;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.PipedInputStream;
+import java.io.PipedOutputStream;
+import java.net.URL;
+
+import org.junit.Test;
+
+import static org.junit.Assert.fail;
+
+/**
+ * This test validates that the Base64 encoder/decoders work properly.
+ *
+ * @version $Id$
+ */
+public class Base64TestCase {
+
+    private void innerBase64Test(String action, URL in, URL ref) throws Exception {
+        InputStream inIS = in.openStream();
+
+        if (action.equals("ROUND")) {
+            ref = in;
+        } else if (!action.equals("ENCODE") && !action.equals("DECODE")) {
+            fail("Bad action string");
+        }
+
+        InputStream refIS = ref.openStream();
+
+        if (action.equals("ENCODE") || action.equals("ROUND")) {
+            // We need to encode the incomming data
+            PipedOutputStream pos = new PipedOutputStream();
+            OutputStream os = new Base64EncodeStream(pos);
+
+            // Copy the input to the Base64 Encoder (in a seperate thread).
+            Thread t = new StreamCopier(inIS, os);
+
+            // Read that from the piped output stream.
+            inIS = new PipedInputStream(pos);
+            t.start();
+        }
+
+        if (action.equals("DECODE") || action.equals("ROUND")) {
+            inIS = new Base64DecodeStream(inIS);
+        }
+
+
+        int mismatch = compareStreams(inIS, refIS, action.equals("ENCODE"));
+
+        if (mismatch != -1) {
+            fail("Wrong result");
+        }
+    }
+
+    private void innerBase64Test(String action, String in, String ref) throws Exception {
+        final String baseURL = "file:test/resources/org/apache/xmlgraphics/util/io/";
+        innerBase64Test(action, new URL(baseURL + in), new URL(baseURL + ref));
+    }
+
+    private void innerBase64Test(String in) throws Exception {
+        innerBase64Test("ROUND", in, in);
+    }
+
+    private void testBase64Group(String name) throws Exception {
+        innerBase64Test("ENCODE", name, name + ".64");
+        innerBase64Test("DECODE", name + ".64", name);
+        innerBase64Test(name);
+    }
+
+    /**
+     * This method will only throw exceptions if some aspect
+     * of the test's internal operation fails.
+     */
+    @Test
+    public void testBase64() throws Exception {
+        System.out.println(new File(".").getCanonicalPath());
+        testBase64Group("zeroByte");
+        testBase64Group("oneByte");
+        testBase64Group("twoByte");
+        testBase64Group("threeByte");
+        testBase64Group("fourByte");
+        testBase64Group("tenByte");
+        testBase64Group("small");
+        testBase64Group("medium");
+        innerBase64Test("DECODE", "medium.pc.64", "medium");
+        innerBase64Test("large");
+}
+
+    /**
+     * Returns true if the contents of <tt>is1</tt> match the
+     * contents of <tt>is2</tt>
+     */
+    public static int compareStreams(InputStream is1, InputStream is2,
+                              boolean skipws) {
+        byte[] data1 = new byte[100];
+        byte[] data2 = new byte[100];
+        int off1 = 0;
+        int off2 = 0;
+        int idx = 0;
+
+        try {
+            while (true) {
+                int len1 = is1.read(data1, off1, data1.length - off1);
+                int len2 = is2.read(data2, off2, data2.length - off2);
+
+                if (off1 != 0) {
+                    if (len1 == -1) {
+                        len1 = off1;
+                    } else {
+                        len1 += off1;
+                    }
+                }
+
+                if (off2 != 0) {
+                    if (len2 == -1) {
+                        len2 = off2;
+                    } else {
+                        len2 += off2;
+                    }
+                }
+
+                if (len1 == -1) {
+                    if (len2 == -1) {
+                        break; // Both done...
+                    }
+                    // Only is1 is done...
+                    if (!skipws) {
+                        return idx;
+                    }
+                    // check if the rest of is2 is whitespace...
+                    for (int i2 = 0; i2 < len2; i2++) {
+                        if ((data2[i2] != '\n') && (data2[i2] != '\r') && (data2[i2] != ' ')) {
+                            return idx + i2;
+                        }
+                    }
+                    off1 = off2 = 0;
+                    continue;
+                }
+
+                if (len2 == -1) {
+                    // Only is2 is done...
+                    if (!skipws) {
+                        return idx;
+                    }
+
+                    // Check if rest of is1 is whitespace...
+                    for (int i1 = 0; i1 < len1; i1++) {
+                        if ((data1[i1] != '\n') && (data1[i1] != '\r') && (data1[i1] != ' ')) {
+                            return idx + i1;
+                        }
+                    }
+                    off1 = off2 = 0;
+                    continue;
+                }
+
+                int i1 = 0;
+                int i2 = 0;
+                while ((i1 < len1) && (i2 < len2)) {
+                    if (skipws) {
+                        if ((data1[i1] == '\n') || (data1[i1] == '\r') || (data1[i1] == ' ')) {
+                            i1++;
+                            continue;
+                        }
+                        if ((data2[i2] == '\n') || (data2[i2] == '\r') || (data2[i2] == ' ')) {
+                            i2++;
+                            continue;
+                        }
+                    }
+                    if (data1[i1] != data2[i2]) {
+                        return idx + i2;
+                    }
+
+                    i1++;
+                    i2++;
+                }
+
+                if (i1 != len1) {
+                    System.arraycopy(data1, i1, data1, 0, len1 - i1);
+                }
+                if (i2 != len2) {
+                    System.arraycopy(data2, i2, data2, 0, len2 - i2);
+                }
+                off1 = len1 - i1;
+                off2 = len2 - i2;
+                idx += i2;
+            }
+        } catch (IOException ioe) {
+            ioe.printStackTrace();
+            return idx;
+        }
+
+        return -1;
+    }
+
+
+    static class StreamCopier extends Thread {
+        InputStream src;
+        OutputStream dst;
+
+        public StreamCopier(InputStream src,
+                            OutputStream dst) {
+            this.src = src;
+            this.dst = dst;
+        }
+
+        public void run() {
+            try {
+                byte[] data = new byte[1000];
+                while (true) {
+                    int len = src.read(data, 0, data.length);
+                    if (len == -1) {
+                        break;
+                    }
+
+                    dst.write(data, 0, len);
+                }
+            } catch (IOException ioe) {
+                // Nothing
+            }
+            try {
+                dst.close();
+            } catch (IOException ioe) {
+                // Nothing
+            }
+        }
+    }
+}

Propchange: xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/util/io/Base64TestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/util/io/SubInputStreamTestCase.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/util/io/SubInputStreamTestCase.java?rev=1365650&r1=1365649&r2=1365650&view=diff
==============================================================================
--- xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/util/io/SubInputStreamTestCase.java (original)
+++ xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/util/io/SubInputStreamTestCase.java Wed Jul 25 15:59:30 2012
@@ -22,34 +22,29 @@ package org.apache.xmlgraphics.util.io;
 import java.io.ByteArrayInputStream;
 import java.util.Arrays;
 
-import junit.framework.TestCase;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
 
 /**
  * Test case for SubInputStream.
  */
-public class SubInputStreamTestCase extends TestCase {
-
-    /**
-     * Main constructor.
-     * @param name the test case's name
-     * @see junit.framework.TestCase#TestCase(String)
-     */
-    public SubInputStreamTestCase(String name) {
-        super(name);
-    }
+public class SubInputStreamTestCase {
 
     /**
      * Tests SubInputStream.
      * @throws Exception if an error occurs
      */
+    @Test
     public void testMain() throws Exception {
         //Initialize test data
         byte[] data = new byte[256];
         for (int i = 0; i < data.length; i++) {
-            data[i] = (byte)(i & 0xff);
+            data[i] = (byte) (i & 0xff);
         }
 
-        int v, c;
+        int v;
+        int c;
         byte[] buf;
         String s;
 
@@ -65,17 +60,18 @@ public class SubInputStreamTestCase exte
         s = new String(buf, "US-ASCII");
         assertEquals("\u0002\u0003\u0004\u0005", s);
 
-        Arrays.fill(buf, (byte)0);
+        Arrays.fill(buf, (byte) 0);
         c = subin.read(buf, 2, 2);
         assertEquals(2, c);
         s = new String(buf, "US-ASCII");
         assertEquals("\u0000\u0000\u0006\u0007", s);
 
-        Arrays.fill(buf, (byte)0);
+        Arrays.fill(buf, (byte) 0);
         c = subin.read(buf);
         assertEquals(2, c);
         s = new String(buf, "US-ASCII");
         assertEquals("\u0008\u0009\u0000\u0000", s);
+        subin.close();
     }
 
 }

Modified: xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/util/uri/CommonURIResolverTestCase.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/util/uri/CommonURIResolverTestCase.java?rev=1365650&r1=1365649&r2=1365650&view=diff
==============================================================================
--- xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/util/uri/CommonURIResolverTestCase.java (original)
+++ xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/util/uri/CommonURIResolverTestCase.java Wed Jul 25 15:59:30 2012
@@ -21,12 +21,12 @@ package org.apache.xmlgraphics.util.uri;
 
 import javax.xml.transform.URIResolver;
 
-import junit.framework.TestCase;
+import org.junit.Test;
 
 /**
  * Test case for the {@link CommonURIResolver}.
  */
-public class CommonURIResolverTestCase extends TestCase {
+public class CommonURIResolverTestCase {
 
     /**
      * Test the DataURIResolver with correct values.
@@ -34,6 +34,8 @@ public class CommonURIResolverTestCase e
      * @throws Exception
      *             if an error occurs
      */
+
+    @Test
     public void testDataURLHandling() throws Exception {
         URIResolver resolver = CommonURIResolver.getDefaultURIResolver();
         DataURIResolverTestCase.actualURLHAndlingTest(resolver);

Modified: xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/util/uri/DataURIResolverTestCase.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/util/uri/DataURIResolverTestCase.java?rev=1365650&r1=1365649&r2=1365650&view=diff
==============================================================================
--- xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/util/uri/DataURIResolverTestCase.java (original)
+++ xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/util/uri/DataURIResolverTestCase.java Wed Jul 25 15:59:30 2012
@@ -27,19 +27,19 @@ import javax.xml.transform.stream.Stream
 
 import org.junit.Test;
 
-import org.apache.commons.io.IOUtils;
-
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
 
+import org.apache.commons.io.IOUtils;
+
 /**
  * Test case for the RFC 2397 data URL/URI resolver.
  */
 public class DataURIResolverTestCase {
 
-    private static final byte[] TESTDATA = new byte[] { 0, 1, 2, 3, 4, 5 };
+    private static final byte[] TESTDATA = new byte[] {0, 1, 2, 3, 4, 5};
 
     /**
      * Tests DataURLUtil.

Added: xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/xmp/XMPParserTestCase.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/xmp/XMPParserTestCase.java?rev=1365650&view=auto
==============================================================================
--- xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/xmp/XMPParserTestCase.java (added)
+++ xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/xmp/XMPParserTestCase.java Wed Jul 25 15:59:30 2012
@@ -0,0 +1,192 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.xmlgraphics.xmp;
+
+import java.net.URL;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.TimeZone;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+
+import org.apache.xmlgraphics.xmp.schemas.DublinCoreAdapter;
+import org.apache.xmlgraphics.xmp.schemas.DublinCoreSchema;
+import org.apache.xmlgraphics.xmp.schemas.XMPBasicAdapter;
+import org.apache.xmlgraphics.xmp.schemas.XMPBasicSchema;
+import org.apache.xmlgraphics.xmp.schemas.pdf.AdobePDFAdapter;
+import org.apache.xmlgraphics.xmp.schemas.pdf.AdobePDFSchema;
+
+/**
+ * Tests for the XMP parser.
+ */
+public class XMPParserTestCase {
+
+    @Test
+    public void testParseBasics() throws Exception {
+        URL url = getClass().getResource("test-basics.xmp");
+        Metadata meta = XMPParser.parseXMP(url);
+
+        DublinCoreAdapter dcAdapter = DublinCoreSchema.getAdapter(meta);
+        XMPBasicAdapter basicAdapter = XMPBasicSchema.getAdapter(meta);
+        AdobePDFAdapter pdfAdapter = AdobePDFSchema.getAdapter(meta);
+
+        XMPProperty prop;
+        prop = meta.getProperty(XMPConstants.DUBLIN_CORE_NAMESPACE, "creator");
+        XMPArray array;
+        array = prop.getArrayValue();
+        assertEquals(1, array.getSize());
+        assertEquals("John Doe", array.getValue(0).toString());
+        assertEquals("John Doe", dcAdapter.getCreators()[0]);
+
+        prop = meta.getProperty(XMPConstants.DUBLIN_CORE_NAMESPACE, "title");
+        assertEquals("Example document", prop.getValue().toString());
+        assertEquals("Example document", dcAdapter.getTitle());
+        prop = meta.getProperty(XMPConstants.XMP_BASIC_NAMESPACE, "CreateDate");
+        //System.out.println("Creation Date: " + prop.getValue() + " " + prop.getClass().getName());
+        prop = meta.getProperty(XMPConstants.XMP_BASIC_NAMESPACE, "CreatorTool");
+        assertEquals("An XML editor", prop.getValue().toString());
+        assertEquals("An XML editor", basicAdapter.getCreatorTool());
+        prop = meta.getProperty(XMPConstants.ADOBE_PDF_NAMESPACE, "Producer");
+        assertEquals("Apache FOP Version SVN trunk", prop.getValue().toString());
+        assertEquals("Apache FOP Version SVN trunk", pdfAdapter.getProducer());
+        prop = meta.getProperty(XMPConstants.ADOBE_PDF_NAMESPACE, "PDFVersion");
+        assertEquals("1.4", prop.getValue().toString());
+        assertEquals("1.4", pdfAdapter.getPDFVersion());
+    }
+
+    @Test
+    public void testParse1() throws Exception {
+        URL url = getClass().getResource("unknown-schema.xmp");
+        Metadata meta = XMPParser.parseXMP(url);
+
+        DublinCoreAdapter dcAdapter = DublinCoreSchema.getAdapter(meta);
+
+        XMPProperty prop;
+        //Access through the known schema as reference
+        prop = meta.getProperty(XMPConstants.DUBLIN_CORE_NAMESPACE, "title");
+        assertEquals("Unknown Schema", prop.getValue().toString());
+        assertEquals("Unknown Schema", dcAdapter.getTitle());
+
+        //Access through a schema unknown to the XMP framework
+        prop = meta.getProperty("http://unknown.org/something", "dummy");
+        assertEquals("Dummy!", prop.getValue().toString());
+    }
+
+    @Test
+    public void testParseStructures() throws Exception {
+        URL url = getClass().getResource("test-structures.xmp");
+        Metadata meta = XMPParser.parseXMP(url);
+
+        XMPProperty prop;
+
+        String testns = "http://foo.bar/test/";
+        prop = meta.getProperty(testns, "something");
+        assertEquals("blablah", prop.getValue().toString());
+
+        prop = meta.getProperty(testns, "ingredients");
+        XMPArray array = prop.getArrayValue();
+        assertEquals(3, array.getSize());
+        XMPStructure struct = array.getStructure(0);
+        assertEquals(2, struct.getPropertyCount());
+        prop = struct.getValueProperty();
+        assertEquals("Apples", prop.getValue());
+        prop = struct.getProperty(testns, "amount");
+        assertEquals("4", prop.getValue());
+
+        prop = meta.getProperty(testns, "villain");
+        XMPProperty prop1;
+        prop1 = prop.getStructureValue().getProperty(testns, "name");
+        assertEquals("Darth Sidious", prop1.getValue());
+        prop1 = prop.getStructureValue().getProperty(testns, "other-name");
+        assertEquals("Palpatine", prop1.getValue());
+
+        //Test shorthand form
+        prop = meta.getProperty(testns, "project");
+        prop1 = prop.getStructureValue().getProperty(testns, "name");
+        assertEquals("Apache XML Graphics", prop1.getValue());
+        prop1 = prop.getStructureValue().getProperty(testns, "url");
+        assertEquals("http://xmlgraphics.apache.org/", prop1.getValue());
+
+    }
+
+    @Test
+    public void testAttributeValues() throws Exception {
+        URL url = getClass().getResource("test-attribute-values.xmp");
+        Metadata meta = XMPParser.parseXMP(url);
+
+        DublinCoreAdapter dcAdapter = DublinCoreSchema.getAdapter(meta);
+        assertEquals("Ender's Game", dcAdapter.getTitle());
+        assertEquals("Orson Scott Card", dcAdapter.getCreators()[0]);
+    }
+
+    @Test
+    public void testParseDates() throws Exception {
+        URL url = getClass().getResource("test-dates.xmp");
+        Metadata meta = XMPParser.parseXMP(url);
+        XMPProperty prop;
+
+        DublinCoreAdapter dcAdapter = DublinCoreSchema.getAdapter(meta);
+
+        //Simple adapter access
+        Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT+2:00"));
+        cal.set(2006, Calendar.JUNE, 2, 10, 36, 40);
+        cal.set(Calendar.MILLISECOND, 0);
+        assertEquals(cal.getTime(), dcAdapter.getDate());
+        Date[] dates = dcAdapter.getDates();
+        assertEquals(2, dates.length);
+
+        //The second is the most recent and should match the simple value
+        assertEquals(dates[1], dcAdapter.getDate());
+
+        prop = meta.getProperty(XMPConstants.DUBLIN_CORE_NAMESPACE, "date");
+        assertNotNull(prop.getArrayValue());
+        assertEquals(2, prop.getArrayValue().getSize());
+
+        //Now add a new date and check if the adapter's getDate() method returns the new date.
+        cal.set(2008, Calendar.NOVEMBER, 1, 10, 10, 0);
+        dcAdapter.addDate(cal.getTime());
+        assertEquals(3, dcAdapter.getDates().length);
+        prop = meta.getProperty(XMPConstants.DUBLIN_CORE_NAMESPACE, "date");
+        assertNotNull(prop.getArrayValue());
+        assertEquals(3, prop.getArrayValue().getSize());
+        assertEquals(cal.getTime(), dcAdapter.getDate());
+    }
+
+    @Test
+    public void testParseEmptyValues() throws Exception {
+        URL url = getClass().getResource("empty-values.xmp");
+        Metadata meta = XMPParser.parseXMP(url);
+
+        DublinCoreAdapter dc = DublinCoreSchema.getAdapter(meta);
+        String title = dc.getTitle();
+        assertEquals("empty", title);
+
+        title = dc.getTitle("fr"); //Does not exist
+        assertNull(title);
+
+        title = dc.getTitle("de");
+        assertNull(title); //Empty value treated same as not existant
+    }
+
+}

Propchange: xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/xmp/XMPParserTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/xmp/XMPPropertyTestCase.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/xmp/XMPPropertyTestCase.java?rev=1365650&view=auto
==============================================================================
--- xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/xmp/XMPPropertyTestCase.java (added)
+++ xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/xmp/XMPPropertyTestCase.java Wed Jul 25 15:59:30 2012
@@ -0,0 +1,198 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.xmlgraphics.xmp;
+
+import java.io.StringWriter;
+import java.util.Arrays;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.Locale;
+import java.util.Set;
+import java.util.TimeZone;
+
+import javax.xml.transform.stream.StreamResult;
+import javax.xml.transform.stream.StreamSource;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import org.apache.xmlgraphics.util.QName;
+import org.apache.xmlgraphics.xmp.schemas.DublinCoreAdapter;
+import org.apache.xmlgraphics.xmp.schemas.DublinCoreSchema;
+import org.apache.xmlgraphics.xmp.schemas.XMPBasicAdapter;
+import org.apache.xmlgraphics.xmp.schemas.XMPBasicSchema;
+
+/**
+ * Tests property access methods.
+ */
+public class XMPPropertyTestCase {
+
+    @Test
+    public void testPropertyAccess() throws Exception {
+        Metadata xmp = new Metadata();
+        DublinCoreAdapter dc = DublinCoreSchema.getAdapter(xmp);
+        assertNull(dc.getContributors());
+
+        dc.addContributor("Contributor1");
+        assertEquals(1, dc.getContributors().length);
+        assertEquals("Contributor1", dc.getContributors()[0]);
+        dc.removeContributor("Contributor1");
+        assertNull(dc.getContributors());
+
+        dc.addContributor("Contributor1");
+        assertEquals(1, dc.getContributors().length);
+        dc.addContributor("Contributor2");
+        assertEquals(2, dc.getContributors().length);
+        assertFalse(dc.removeContributor("DoesNotExist"));
+        assertTrue(dc.removeContributor("Contributor1"));
+        assertEquals(1, dc.getContributors().length);
+        assertTrue(dc.removeContributor("Contributor2"));
+        assertFalse(dc.removeContributor("Contributor2"));
+        assertNull(dc.getContributors());
+    }
+
+    @Test
+    public void testPropertyRemovalLangAlt() throws Exception {
+        Metadata xmp = new Metadata();
+        DublinCoreAdapter dc = DublinCoreSchema.getAdapter(xmp);
+
+        //dc:title is a "Lang Alt"
+        dc.setTitle("en", "The title");
+        String title = dc.removeTitle("en");
+        assertEquals("The title", title);
+        dc.setTitle("en", "The title");
+        dc.setTitle("de", "Der Titel");
+        title = dc.removeTitle("en");
+        assertEquals("The title", title);
+        title = dc.removeTitle("en");
+        assertNull(title);
+
+        title = dc.removeTitle("de");
+        assertEquals("Der Titel", title);
+        title = dc.removeTitle("de");
+        assertNull(title);
+    }
+
+    @Test
+    public void testReplaceLangAlt() throws Exception {
+        Metadata xmp = new Metadata();
+        DublinCoreAdapter dc = DublinCoreSchema.getAdapter(xmp);
+        dc.setTitle("Default title");
+        StringWriter writer = new StringWriter();
+        XMPSerializer.writeXML(xmp, new StreamResult(writer));
+        String xmpString = writer.toString();
+        xmp = XMPParser.parseXMP(new StreamSource(new java.io.StringReader(xmpString)));
+        dc = DublinCoreSchema.getAdapter(xmp);
+        assertEquals("Default title", dc.getTitle());
+        dc.setTitle("Updated title");
+        XMPProperty prop = xmp.getProperty(new QName(DublinCoreSchema.NAMESPACE, "title"));
+        XMPArray array = prop.getArrayValue();
+        assertNotNull(array);
+        //Check that only one title is present. There used to be a bug that didn't set the
+        //non-qualified value equal to the value qualified with "x-default".
+        assertEquals(1, array.getSize());
+        assertEquals("Updated title", array.getValue(0));
+    }
+
+    @Test
+    public void testPropertyValues() throws Exception {
+        Metadata xmp = new Metadata();
+        DublinCoreAdapter dc = DublinCoreSchema.getAdapter(xmp);
+
+        String format = dc.getFormat();
+        assertNull(format);
+
+        dc.setFormat("application/pdf");
+        format = dc.getFormat();
+        assertEquals("application/pdf", format);
+
+        dc.setFormat("image/jpeg");
+        format = dc.getFormat();
+        assertEquals("image/jpeg", format);
+
+        dc.setFormat(null);
+        format = dc.getFormat();
+        assertNull(format);
+
+        dc.setFormat(""); //Empty string same as null value
+        format = dc.getFormat();
+        assertNull(format);
+
+        dc.setTitle("title");
+        String title = dc.getTitle();
+        assertEquals("title", title);
+
+        dc.setTitle("Titel");
+        title = dc.getTitle();
+        assertEquals("Titel", title);
+
+        dc.setTitle(null);
+        title = dc.getTitle();
+        assertNull(title);
+
+        dc.setTitle("");
+        title = dc.getTitle();
+        assertNull(title);
+    }
+
+    @Test
+    public void testDates() throws Exception {
+        Metadata xmp = new Metadata();
+        XMPBasicAdapter basic = XMPBasicSchema.getAdapter(xmp);
+
+        Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT"), Locale.ENGLISH);
+        cal.set(2008, Calendar.FEBRUARY, 07, 15, 11, 07);
+        cal.set(Calendar.MILLISECOND, 0);
+        Date dt = cal.getTime();
+
+        assertNull(basic.getCreateDate());
+        basic.setCreateDate(dt);
+        Date dt2 = basic.getCreateDate();
+        assertEquals(dt2, dt);
+    }
+
+    @Test
+    public void testQualifiers() throws Exception {
+        Metadata xmp = new Metadata();
+        XMPBasicAdapter basic = XMPBasicSchema.getAdapter(xmp);
+
+        basic.addIdentifier("x123");
+        basic.setIdentifier("id1", "system1");
+        basic.setIdentifier("12345", "system2");
+
+        String[] ids = basic.getIdentifiers();
+        assertEquals(3, ids.length);
+        Set<String> set = new java.util.HashSet<String>(Arrays.asList(ids));
+        assertTrue(set.contains("x123"));
+        assertTrue(set.contains("id1"));
+        assertTrue(set.contains("12345"));
+
+        assertEquals("id1", basic.getIdentifier("system1"));
+        basic.setIdentifier("id2", "system1");
+        assertEquals("id2", basic.getIdentifier("system1"));
+        assertEquals(3, basic.getIdentifiers().length);
+    }
+
+}

Propchange: xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/xmp/XMPPropertyTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: commits-help@xmlgraphics.apache.org


Mime
View raw message