You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-commits@xmlgraphics.apache.org by ga...@apache.org on 2012/06/23 21:31:39 UTC

svn commit: r1353186 [5/5] - in /xmlgraphics/fop/branches/fop-1_1rc1: ./ src/documentation/content/xdocs/trunk/ src/java/META-INF/services/ src/java/org/apache/fop/complexscripts/fonts/ src/java/org/apache/fop/fo/properties/ src/java/org/apache/fop/fon...

Added: xmlgraphics/fop/branches/fop-1_1rc1/test/java/org/apache/fop/fonts/truetype/TTFFileTestCase.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/fop-1_1rc1/test/java/org/apache/fop/fonts/truetype/TTFFileTestCase.java?rev=1353186&view=auto
==============================================================================
--- xmlgraphics/fop/branches/fop-1_1rc1/test/java/org/apache/fop/fonts/truetype/TTFFileTestCase.java (added)
+++ xmlgraphics/fop/branches/fop-1_1rc1/test/java/org/apache/fop/fonts/truetype/TTFFileTestCase.java Sat Jun 23 19:31:33 2012
@@ -0,0 +1,427 @@
+/*
+ * 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.fop.fonts.truetype;
+
+import java.io.IOException;
+import java.util.Map;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import org.apache.fop.fonts.truetype.TTFFile.PostScriptVersion;
+
+/**
+ * Class for testing org.apache.fop.fonts.truetype.TTFFile
+ */
+public class TTFFileTestCase {
+    // We only want to initialize the FontFileReader once (for performance reasons)
+    /** The truetype font file (DejaVuLGCSerif) */
+    protected final TTFFile dejavuTTFFile;
+    /** The FontFileReader for ttfFile (DejaVuLGCSerif) */
+    protected final FontFileReader dejavuReader;
+    /** The truetype font file (DroidSansMono) */
+    protected final TTFFile droidmonoTTFFile;
+    /** The FontFileReader for ttfFile (DroidSansMono) */
+    protected final FontFileReader droidmonoReader;
+
+
+    /**
+     * Constructor initialises FileFontReader to
+     * @throws IOException exception
+     */
+    public TTFFileTestCase() throws IOException {
+        dejavuTTFFile = new TTFFile();
+        dejavuReader = new FontFileReader("test/resources/fonts/ttf/DejaVuLGCSerif.ttf");
+        dejavuTTFFile.readFont(dejavuReader);
+        droidmonoTTFFile = new TTFFile();
+        droidmonoReader = new FontFileReader("test/resources/fonts/ttf/DroidSansMono.ttf");
+        droidmonoTTFFile.readFont(droidmonoReader);
+    }
+
+    /**
+     * Test convertTTFUnit2PDFUnit() - The units per em retrieved reading the HEAD table from
+     * the font file. (DroidSansMono has the same units per em as DejaVu so no point testing it)
+     */
+    @Test
+    public void testConvertTTFUnit2PDFUnit() {
+        // DejaVu has 2048 units per em (PDF works in millipts, thus the 1000)
+        // test rational number
+        assertEquals(1000, dejavuTTFFile.convertTTFUnit2PDFUnit(2048));
+        // test smallest case, this should = 0.488 (round down to 0)
+        assertEquals(0, dejavuTTFFile.convertTTFUnit2PDFUnit(1));
+        // this should round up, but since it's millipts...
+        assertEquals(0, dejavuTTFFile.convertTTFUnit2PDFUnit(2));
+        // ensure behaviour is the same for negative numbers
+        assertEquals(0, dejavuTTFFile.convertTTFUnit2PDFUnit(-0));
+        assertEquals(-1000, dejavuTTFFile.convertTTFUnit2PDFUnit(-2048));
+        assertEquals(0, dejavuTTFFile.convertTTFUnit2PDFUnit(-1));
+        assertEquals(0, dejavuTTFFile.convertTTFUnit2PDFUnit(-2));
+    }
+
+    /**
+     * Test checkTTC()
+     * @throws IOException exception
+     */
+    @Test
+    public void testCheckTTC() throws IOException {
+        // DejaVu is not a TTC, thus this returns true
+        assertTrue(dejavuTTFFile.checkTTC(""));
+        assertTrue(droidmonoTTFFile.checkTTC(""));
+        /*
+         * Cannot reasonably test the rest of this method without an actual truetype collection
+         * because all methods in FontFileReader are "final" and thus mocking isn't possible.
+         */
+    }
+
+    /**
+     * Test getAnsiKerning() - Tests values retrieved from the kern table in the font file.
+     */
+    @Test
+    public void testGetAnsiKerning() {
+        Map<Integer, Map<Integer, Integer>> ansiKerning = dejavuTTFFile.getKerning();
+        if (ansiKerning.isEmpty()) {
+            fail();
+        }
+        Integer k1 = ansiKerning.get(Integer.valueOf('A')).get(
+                Integer.valueOf('T'));
+        assertEquals(dejavuTTFFile.convertTTFUnit2PDFUnit(-112), k1.intValue());
+        Integer k2 = ansiKerning.get(Integer.valueOf('Y')).get(Integer.valueOf('u'));
+        assertEquals(dejavuTTFFile.convertTTFUnit2PDFUnit(-178), k2.intValue());
+
+        // DroidSansMono doens't have kerning (it's mono-spaced)
+        ansiKerning = droidmonoTTFFile.getAnsiKerning();
+        if (!ansiKerning.isEmpty()) {
+            fail("DroidSansMono shouldn't have any kerning data.");
+        }
+    }
+
+    /**
+     * Test getCapHeight - there are several paths to test:
+     * 1) The PCLT table (if present)
+     * 2) The yMax (3rd) value, for the bounding box, for 'H' in the glyf table.
+     * if not the above:
+     * 3) The caps height in the OS/2 table
+     * Tests values retrieved from analysing the font file.
+     */
+    @Test
+    public void testGetCapHeight() {
+        // DejaVu doesn't have the PCLT table and so these have to be guessed
+        // The height is approximated to be the height of the "H" which for
+        // Deja = 1493 TTFunits
+        assertEquals(dejavuTTFFile.convertTTFUnit2PDFUnit(1493), dejavuTTFFile.getCapHeight());
+        // DroidSansMono doesn't have a PCLT table either
+        // height of "H" = 1462
+        assertEquals(droidmonoTTFFile.convertTTFUnit2PDFUnit(1462),
+                droidmonoTTFFile.getCapHeight());
+    }
+
+    /**
+     * Test getCharSetName() - check that it returns "WinAnsiEncoding".
+     */
+    @Test
+    public void testGetCharSetName() {
+        assertTrue("WinAnsiEncoding".equals(dejavuTTFFile.getCharSetName()));
+        assertTrue("WinAnsiEncoding".equals(droidmonoTTFFile.getCharSetName()));
+    }
+
+    /**
+     * Test getCharWidth() - Test values retrieved from the metrics in the glyf table in
+     * the font file.
+     */
+    @Test
+    public void testGetCharWidth() {
+        // Arbitrarily test a few values:
+        // The width of "H" (Unicode index 0x0048) is 1786
+        assertEquals(dejavuTTFFile.convertTTFUnit2PDFUnit(1786), dejavuTTFFile.getCharWidth(0x48));
+        // The width of "i" (unicode index 0x0069) is 655 TTFunits
+        assertEquals(dejavuTTFFile.convertTTFUnit2PDFUnit(655), dejavuTTFFile.getCharWidth(0x69));
+        // final check, "!" (unicode index 0x0021) is 823 TTFunits
+        assertEquals(dejavuTTFFile.convertTTFUnit2PDFUnit(823), dejavuTTFFile.getCharWidth(0x21));
+
+        // All the glyphs should be the same width in DroidSansMono (mono-spaced)
+        int charWidth = droidmonoTTFFile.convertTTFUnit2PDFUnit(1229);
+        for (int i = 0; i < 255; i++) {
+            assertEquals(charWidth, droidmonoTTFFile.getCharWidth(i));
+        }
+    }
+
+    /**
+     * TODO: add implementation to this test
+     */
+    public void testGetCMaps() {
+    }
+
+    /**
+     * Test getFamilyNames() - Test value retrieved from the name table in the font file.
+     */
+    @Test
+    public void testGetFamilyNames() {
+        assertEquals(1, dejavuTTFFile.getFamilyNames().size());
+        for (String name : dejavuTTFFile.getFamilyNames()) {
+            assertEquals("DejaVu LGC Serif", name);
+        }
+        assertEquals(1, droidmonoTTFFile.getFamilyNames().size());
+        for (String name : droidmonoTTFFile.getFamilyNames()) {
+            assertEquals("Droid Sans Mono", name);
+        }
+    }
+
+    /**
+     * Test getFirstChar() - TODO: implement a more intelligent test here.
+     */
+    @Test
+    public void testGetFirstChar() {
+        // Not really sure how to test this intelligently
+        assertEquals(0, dejavuTTFFile.getFirstChar());
+        assertEquals(0, droidmonoTTFFile.getFirstChar());
+    }
+
+    /**
+     * Test getFlags() - Test values retrieved from the POST table in the font file.
+     */
+    @Test
+    public void testGetFlags() {
+        /* DejaVu flags are:
+         * italic angle = 0
+         * fixed pitch = 0
+         * has serifs = true (default value; this font doesn't have a PCLT table)
+         */
+        int flags = dejavuTTFFile.getFlags();
+        assertEquals(0, flags  & 64);       // Italics angle = 0
+        assertEquals(32, flags & 32);       // Adobe standard charset
+        assertEquals(0, flags & 2);         // fixed pitch = 0
+        assertEquals(1, flags & 1);         // has serifs = 1 (true)
+        /*
+         * Droid flags are:
+         * italic angle = 0
+         * fixed pitch = 1
+         * has serifs = true (default value; this font doesn't have a PCLT table)
+         */
+        flags = droidmonoTTFFile.getFlags();
+        assertEquals(0, flags & 64);
+        assertEquals(32, flags & 32);
+        assertEquals(2, flags & 2);
+        assertEquals(1, flags & 1);
+    }
+
+    /**
+     * Test getFontBBox() - Test values retrieved from values in the HEAD table in the font file.
+     */
+    @Test
+    public void testGetFontBBox() {
+        int[] bBox = dejavuTTFFile.getFontBBox();
+        /*
+         * The head table has the following values(DejaVu):
+         * xmin = -1576, ymin = -710, xmax = 3439, ymax = 2544
+         */
+        assertEquals(dejavuTTFFile.convertTTFUnit2PDFUnit(-1576), bBox[0]);
+        assertEquals(dejavuTTFFile.convertTTFUnit2PDFUnit(-710), bBox[1]);
+        assertEquals(dejavuTTFFile.convertTTFUnit2PDFUnit(3439), bBox[2]);
+        assertEquals(dejavuTTFFile.convertTTFUnit2PDFUnit(2544), bBox[3]);
+        /*
+         * The head table has the following values (DroidSansMono):
+         * xmin = -312, ymin= -555, xmax = 1315, ymax = 2163
+         */
+        bBox = droidmonoTTFFile.getFontBBox();
+        assertEquals(droidmonoTTFFile.convertTTFUnit2PDFUnit(-312), bBox[0]);
+        assertEquals(droidmonoTTFFile.convertTTFUnit2PDFUnit(-555), bBox[1]);
+        assertEquals(droidmonoTTFFile.convertTTFUnit2PDFUnit(1315), bBox[2]);
+        assertEquals(droidmonoTTFFile.convertTTFUnit2PDFUnit(2163), bBox[3]);
+    }
+
+    /**
+     * Test getFullName() - Test value retrieved from the name table in the font file.
+     */
+    @Test
+    public void testGetFullName() {
+        assertEquals("DejaVu LGC Serif", dejavuTTFFile.getFullName());
+        assertEquals("Droid Sans Mono", droidmonoTTFFile.getFullName());
+    }
+
+    /**
+     * Test getGlyphName - Test value retrieved from the POST table in the font file.
+     */
+    @Test
+    public void testGetGlyphName() {
+        assertEquals("H", dejavuTTFFile.getGlyphName(43));
+        assertEquals("H", droidmonoTTFFile.getGlyphName(43));
+    }
+
+    /**
+     * Test getItalicAngle() - Test value retrieved from the POST table in the font file.
+     */
+    @Test
+    public void testGetItalicAngle() {
+        assertEquals("0", dejavuTTFFile.getItalicAngle());
+        assertEquals("0", droidmonoTTFFile.getItalicAngle());
+    }
+
+    /**
+     * Test getKerning() - Test values retrieved from the kern table in the font file.
+     */
+    @Test
+    public void testGetKerning() {
+        Map<Integer, Map<Integer, Integer>> kerning = dejavuTTFFile.getKerning();
+        if (kerning.isEmpty()) {
+            fail();
+        }
+        Integer k1 = kerning.get(Integer.valueOf('A')).get(Integer.valueOf('T'));
+        assertEquals(dejavuTTFFile.convertTTFUnit2PDFUnit(-112), k1.intValue());
+        Integer k2 = kerning.get(Integer.valueOf('K')).get(Integer.valueOf('u'));
+        assertEquals(dejavuTTFFile.convertTTFUnit2PDFUnit(-45), k2.intValue());
+
+        // DroidSansMono has no kerning data (mono-spaced)
+        kerning = droidmonoTTFFile.getKerning();
+        if (!kerning.isEmpty()) {
+            fail("DroidSansMono shouldn't have any kerning data");
+        }
+    }
+
+    /**
+     * Test lastChar() - TODO: implement a more intelligent test
+     */
+    @Test
+    public void testLastChar() {
+        assertEquals(0xff, dejavuTTFFile.getLastChar());
+        assertEquals(0xff, droidmonoTTFFile.getLastChar());
+    }
+
+    /**
+     * Test getLowerCaseAscent() - There are several paths to test:
+     * 1) The values in the HHEA table (see code)
+     * 2) Fall back to values from the OS/2 table
+     * Test values retrieved from the font file.
+     */
+    @Test
+    public void testGetLowerCaseAscent() {
+        assertEquals(dejavuTTFFile.convertTTFUnit2PDFUnit(1556),
+                dejavuTTFFile.getLowerCaseAscent());
+        // Curiously the same value
+        assertEquals(droidmonoTTFFile.convertTTFUnit2PDFUnit(1556),
+                droidmonoTTFFile.getLowerCaseAscent());
+    }
+
+    /**
+     * Test getPostScriptName() - Test values retrieved from the post table in the font file.
+     */
+    @Test
+    public void testGetPostScriptName() {
+        assertEquals(PostScriptVersion.V2, dejavuTTFFile.getPostScriptVersion());
+        assertEquals(PostScriptVersion.V2, droidmonoTTFFile.getPostScriptVersion());
+    }
+
+    /**
+     * Test getStemV() - Undefined.
+     */
+    @Test
+    public void testGetStemV() {
+        // Undefined
+        assertEquals("0", dejavuTTFFile.getStemV());
+        assertEquals("0", droidmonoTTFFile.getStemV());
+    }
+
+    /**
+     * Test getSubFamilyName() - Test values retrieved from the name table in the font file.
+     */
+    @Test
+    public void testGetSubFamilyName() {
+        assertEquals("Book", dejavuTTFFile.getSubFamilyName());
+        assertEquals("Regular", droidmonoTTFFile.getSubFamilyName());
+    }
+
+    /**
+     * Test getTTCnames() - TODO: add implementation with TTC font.
+     */
+    public void testGetTTCnames() {
+        // Can't test with with DejaVu since it's not a TrueType Collection
+    }
+
+    /**
+     * Test getWeightClass() - Test value retrieved from the OS/2 table in the font file.
+     */
+    @Test
+    public void testGetWeightClass() {
+        // Retrieved from OS/2 table
+        assertEquals(400, dejavuTTFFile.getWeightClass());
+        assertEquals(400, droidmonoTTFFile.getWeightClass());
+    }
+
+    /**
+     * Test getWidths() - Test values retrieved from the hmtx table in the font file.
+     */
+    @Test
+    public void testGetWidths() {
+        int[] widths = dejavuTTFFile.getWidths();
+        // using the width of 'A' index = 36
+        assertEquals(dejavuTTFFile.convertTTFUnit2PDFUnit(1479), widths[36]);
+        // using the width of '|' index = 95
+        assertEquals(dejavuTTFFile.convertTTFUnit2PDFUnit(690), widths[95]);
+        widths = droidmonoTTFFile.getWidths();
+        // DroidSansMono should have all widths the same size (mono-spaced)
+        int width = droidmonoTTFFile.convertTTFUnit2PDFUnit(1229);
+        for (int i = 0; i < 255; i++) {
+            assertEquals(width, widths[i]);
+        }
+    }
+
+    /**
+     * Test getXHeight() - There are several paths to test:
+     * 1) The PCLT table (if available)
+     * 2) The yMax for the bounding box for 'x' in the glyf table.
+     * Fall back:
+     * 3) The xheight in the OS/2 table.
+     */
+    @Test
+    public void testGetXHeight() {
+        // Since there's no PCLT table, the height of 'x' is used for both DejaVu and DroidSansMono
+        assertEquals(dejavuTTFFile.convertTTFUnit2PDFUnit(1064), dejavuTTFFile.getXHeight());
+        assertEquals(droidmonoTTFFile.convertTTFUnit2PDFUnit(1098), droidmonoTTFFile.getXHeight());
+    }
+
+    /**
+     * Test isCFF() - TODO: add test for a CFF font.
+     */
+    @Test
+    public void testIsCFF() {
+        // Neither DejaVu nor DroidSansMono are a compact format font
+        assertEquals(false, dejavuTTFFile.isCFF());
+        assertEquals(false, droidmonoTTFFile.isCFF());
+    }
+
+    /**
+     * Test isEmbeddable() - Test value retrieved from the OS/2 table in the font file.
+     */
+    @Test
+    public void testIsEmbeddable() {
+        // Dejavu and DroidSansMono are both embeddable
+        assertEquals(true, dejavuTTFFile.isEmbeddable());
+        assertEquals(true, droidmonoTTFFile.isEmbeddable());
+    }
+
+    /**
+     * Test readFont() - Add implementation if necessary.
+     */
+    public void testReadFont() {
+        // I'm pretty sure we've tested this with all the other tests
+    }
+}

Modified: xmlgraphics/fop/branches/fop-1_1rc1/test/java/org/apache/fop/fonts/truetype/TTFFontLoaderTestCase.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/fop-1_1rc1/test/java/org/apache/fop/fonts/truetype/TTFFontLoaderTestCase.java?rev=1353186&r1=1353185&r2=1353186&view=diff
==============================================================================
--- xmlgraphics/fop/branches/fop-1_1rc1/test/java/org/apache/fop/fonts/truetype/TTFFontLoaderTestCase.java (original)
+++ xmlgraphics/fop/branches/fop-1_1rc1/test/java/org/apache/fop/fonts/truetype/TTFFontLoaderTestCase.java Sat Jun 23 19:31:33 2012
@@ -19,18 +19,19 @@
 
 package org.apache.fop.fonts.truetype;
 
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
 import java.io.File;
 import java.io.IOException;
 
 import org.junit.Test;
 
+import org.apache.fop.fonts.EmbeddingMode;
 import org.apache.fop.fonts.EncodingMode;
 import org.apache.fop.fonts.FontManager;
 import org.apache.fop.fonts.FontResolver;
 
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
 /**
  * Test case for {@link TTFFontLoader}.
  */
@@ -47,12 +48,12 @@ public class TTFFontLoaderTestCase {
         boolean useKerning = true;
 
         TTFFontLoader fontLoader = new TTFFontLoader(absoluteFilePath, fontName, embedded,
-                EncodingMode.AUTO, useKerning, useComplexScriptFeatures, resolver);
+                EmbeddingMode.AUTO, EncodingMode.AUTO, useKerning, useComplexScriptFeatures, resolver);
         assertTrue(fontLoader.getFont().hasKerningInfo());
         useKerning = false;
 
-        fontLoader = new TTFFontLoader(absoluteFilePath, fontName, embedded, EncodingMode.AUTO,
-                useKerning, useComplexScriptFeatures, resolver);
+        fontLoader = new TTFFontLoader(absoluteFilePath, fontName, embedded, EmbeddingMode.AUTO,
+                EncodingMode.AUTO, useKerning, useComplexScriptFeatures, resolver);
         assertFalse(fontLoader.getFont().hasKerningInfo());
     }
 }

Added: xmlgraphics/fop/branches/fop-1_1rc1/test/java/org/apache/fop/fonts/truetype/TTFSubSetFileTestCase.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/fop-1_1rc1/test/java/org/apache/fop/fonts/truetype/TTFSubSetFileTestCase.java?rev=1353186&view=auto
==============================================================================
--- xmlgraphics/fop/branches/fop-1_1rc1/test/java/org/apache/fop/fonts/truetype/TTFSubSetFileTestCase.java (added)
+++ xmlgraphics/fop/branches/fop-1_1rc1/test/java/org/apache/fop/fonts/truetype/TTFSubSetFileTestCase.java Sat Jun 23 19:31:33 2012
@@ -0,0 +1,76 @@
+/*
+ * 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.fop.fonts.truetype;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * This class tests TTFSubSetFile
+ * TODO: Test with more than just a single font
+ */
+public class TTFSubSetFileTestCase extends TTFFileTestCase {
+    private TTFSubSetFile ttfSubset;
+    private byte[] subset;
+    /**
+     * Constructor
+     * @throws IOException exception
+     */
+    public TTFSubSetFileTestCase() throws IOException {
+        super();
+    }
+
+    /**
+     * setUp()
+     * @exception IOException file read error
+     */
+    @Before
+    public void setUp() throws IOException {
+        ttfSubset = new TTFSubSetFile();
+        Map<Integer, Integer> glyphs = new HashMap<Integer, Integer>();
+        for (int i = 0; i < 255; i++) {
+            glyphs.put(i, i);
+        }
+        ttfSubset.readFont(dejavuReader, "DejaVu", glyphs);
+        subset = ttfSubset.getFontSubset();
+    }
+    /**
+     * Test readFont(FontFileReader, String, Map) - Reads the font and tests the output by injecting
+     * it into a TTFFile object to check the validity of the file as a font. This currently doesn't
+     * create a cmap table, and so the font doesn't contain ALL of the mandatory tables.
+     * @throws IOException exception
+     */
+    @Test
+    public void testReadFont3Args() throws IOException {
+
+        ByteArrayInputStream byteArray = new ByteArrayInputStream(subset);
+        dejavuTTFFile.readFont(new FontFileReader(byteArray));
+        // Test a couple arbitrary values
+        assertEquals(dejavuTTFFile.convertTTFUnit2PDFUnit(-1576), dejavuTTFFile.getFontBBox()[0]);
+        assertEquals(dejavuTTFFile.getFullName(), "DejaVu LGC Serif");
+    }
+}

Added: xmlgraphics/fop/branches/fop-1_1rc1/test/java/org/apache/fop/fonts/truetype/TTFTableNameTestCase.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/fop-1_1rc1/test/java/org/apache/fop/fonts/truetype/TTFTableNameTestCase.java?rev=1353186&view=auto
==============================================================================
--- xmlgraphics/fop/branches/fop-1_1rc1/test/java/org/apache/fop/fonts/truetype/TTFTableNameTestCase.java (added)
+++ xmlgraphics/fop/branches/fop-1_1rc1/test/java/org/apache/fop/fonts/truetype/TTFTableNameTestCase.java Sat Jun 23 19:31:33 2012
@@ -0,0 +1,153 @@
+/*
+ * 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.fop.fonts.truetype;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * This class tests the enum org.apache.fop.fonts.truetype.TTFTableName
+ *
+ */
+public class TTFTableNameTestCase {
+    /**
+     * Test getName() - tests that the getName() method returns the expected String as expected in
+     * the Directory Table.
+     * @exception IllegalAccessException error
+     */
+    @Test
+    public void testGetName() throws IllegalAccessException {
+        assertEquals("tableDirectory", TTFTableName.TABLE_DIRECTORY.getName());
+        assertEquals("EBDT", TTFTableName.EBDT.getName());
+        assertEquals("EBLC", TTFTableName.EBLC.getName());
+        assertEquals("EBSC", TTFTableName.EBSC.getName());
+        assertEquals("FFTM", TTFTableName.FFTM.getName());
+        assertEquals("GDEF", TTFTableName.GDEF.getName());
+        assertEquals("GPOS", TTFTableName.GPOS.getName());
+        assertEquals("GSUB", TTFTableName.GSUB.getName());
+        assertEquals("LTSH", TTFTableName.LTSH.getName());
+        assertEquals("OS/2", TTFTableName.OS2.getName());
+        assertEquals("PCLT", TTFTableName.PCLT.getName());
+        assertEquals("VDMX", TTFTableName.VDMX.getName());
+        assertEquals("cmap", TTFTableName.CMAP.getName());
+        assertEquals("cvt ", TTFTableName.CVT.getName());
+        assertEquals("fpgm", TTFTableName.FPGM.getName());
+        assertEquals("gasp", TTFTableName.GASP.getName());
+        assertEquals("glyf", TTFTableName.GLYF.getName());
+        assertEquals("hdmx", TTFTableName.HDMX.getName());
+        assertEquals("head", TTFTableName.HEAD.getName());
+        assertEquals("hhea", TTFTableName.HHEA.getName());
+        assertEquals("hmtx", TTFTableName.HMTX.getName());
+        assertEquals("kern", TTFTableName.KERN.getName());
+        assertEquals("loca", TTFTableName.LOCA.getName());
+        assertEquals("maxp", TTFTableName.MAXP.getName());
+        assertEquals("name", TTFTableName.NAME.getName());
+        assertEquals("post", TTFTableName.POST.getName());
+        assertEquals("prep", TTFTableName.PREP.getName());
+        assertEquals("vhea", TTFTableName.VHEA.getName());
+        assertEquals("vmtx", TTFTableName.VMTX.getName());
+        // make sure it works with other table names
+        TTFTableName test = TTFTableName.getValue("test");
+        assertEquals("test", test.getName());
+    }
+
+    /**
+     * Test getValue(String) - tests that the getValue(String) method returns the expected
+     * TTFTableNames value when it is given a String (name of a table).
+     * @exception IllegalAccessException error
+     */
+    @Test
+    public void testGetValue() throws IllegalAccessException {
+        assertEquals(TTFTableName.EBDT, TTFTableName.getValue("EBDT"));
+        assertEquals(TTFTableName.EBLC, TTFTableName.getValue("EBLC"));
+        assertEquals(TTFTableName.EBSC, TTFTableName.getValue("EBSC"));
+        assertEquals(TTFTableName.FFTM, TTFTableName.getValue("FFTM"));
+        assertEquals(TTFTableName.LTSH, TTFTableName.getValue("LTSH"));
+        assertEquals(TTFTableName.OS2, TTFTableName.getValue("OS/2"));
+        assertEquals(TTFTableName.PCLT, TTFTableName.getValue("PCLT"));
+        assertEquals(TTFTableName.VDMX, TTFTableName.getValue("VDMX"));
+        assertEquals(TTFTableName.CMAP, TTFTableName.getValue("cmap"));
+        assertEquals(TTFTableName.CVT, TTFTableName.getValue("cvt "));
+        assertEquals(TTFTableName.FPGM, TTFTableName.getValue("fpgm"));
+        assertEquals(TTFTableName.GASP, TTFTableName.getValue("gasp"));
+        assertEquals(TTFTableName.GLYF, TTFTableName.getValue("glyf"));
+        assertEquals(TTFTableName.HDMX, TTFTableName.getValue("hdmx"));
+        assertEquals(TTFTableName.HEAD, TTFTableName.getValue("head"));
+        assertEquals(TTFTableName.HHEA, TTFTableName.getValue("hhea"));
+        assertEquals(TTFTableName.HMTX, TTFTableName.getValue("hmtx"));
+        assertEquals(TTFTableName.KERN, TTFTableName.getValue("kern"));
+        assertEquals(TTFTableName.LOCA, TTFTableName.getValue("loca"));
+        assertEquals(TTFTableName.MAXP, TTFTableName.getValue("maxp"));
+        assertEquals(TTFTableName.NAME, TTFTableName.getValue("name"));
+        assertEquals(TTFTableName.POST, TTFTableName.getValue("post"));
+        assertEquals(TTFTableName.PREP, TTFTableName.getValue("prep"));
+        assertEquals(TTFTableName.VHEA, TTFTableName.getValue("vhea"));
+        assertEquals(TTFTableName.VMTX, TTFTableName.getValue("vmtx"));
+        // Test that we can store a random table name and it will not fail or throw an error.
+        TTFTableName test = TTFTableName.getValue("random");
+        assertTrue(test instanceof TTFTableName);
+    }
+
+    /**
+     * This class overrides hashCode() - we need to ensure it works properly by instantiating two
+     * objects and comparing their hash-codes.
+     * @exception IllegalAccessException error
+     */
+    @Test
+    public void testHashCode() throws IllegalAccessException {
+        TTFTableName a = TTFTableName.getValue("testObject");
+        TTFTableName b = TTFTableName.getValue("testObject");
+        assertTrue(a.hashCode() == b.hashCode());
+        TTFTableName c = TTFTableName.getValue("fail");
+        assertFalse(a.hashCode() == c.hashCode());
+    }
+
+    /**
+     * This class overrides equals(object) - we need to test:
+     * 1) Reflexivity
+     * 2) Symmetry
+     * 3) Transitivity
+     * 4) Consistency
+     * 5) check it fails if you put in a null value
+     * @throws IllegalAccessException error
+     */
+    @Test
+    public void testEquals() throws IllegalAccessException {
+        // Reflexivity
+        TTFTableName a = TTFTableName.getValue("test");
+        assertTrue(a.equals(a));
+        // Symmetry
+        TTFTableName b = TTFTableName.getValue("test");
+        assertTrue(a.equals(b));
+        assertTrue(b.equals(a));
+        // Transitivity (tested with symmetry)
+        // Consistency (test that a == b is true and that a == c fails)
+        TTFTableName c = TTFTableName.getValue("fail");
+        for (int i = 0; i < 100; i++) {
+            assertTrue(a.equals(b));
+            assertFalse(a.equals(c));
+        }
+        // check with null value
+        assertFalse(a.equals(null));
+    }
+}

Added: xmlgraphics/fop/branches/fop-1_1rc1/test/java/org/apache/fop/render/RawPNGTestUtil.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/fop-1_1rc1/test/java/org/apache/fop/render/RawPNGTestUtil.java?rev=1353186&view=auto
==============================================================================
--- xmlgraphics/fop/branches/fop-1_1rc1/test/java/org/apache/fop/render/RawPNGTestUtil.java (added)
+++ xmlgraphics/fop/branches/fop-1_1rc1/test/java/org/apache/fop/render/RawPNGTestUtil.java Sat Jun 23 19:31:33 2012
@@ -0,0 +1,92 @@
+/*
+ * 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.fop.render;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.util.zip.Deflater;
+import java.util.zip.DeflaterOutputStream;
+
+import org.apache.xmlgraphics.image.loader.ImageSize;
+
+public final class RawPNGTestUtil {
+
+    private static int NUM_ROWS = 32;
+    private static int NUM_COLUMNS = 32;
+    private static int DPI = 72;
+
+    private RawPNGTestUtil() {
+
+    }
+
+    /**
+     * Builds a PNG IDAT section for a square of a given color and alpha; the filter is fixed.
+     * @param gray the gray color; set to -1 if using RGB
+     * @param red the red color; ignored if gray > -1
+     * @param green the green color; ignored if gray > -1
+     * @param blue the blue color; ignored if gray > -1
+     * @param alpha the alpha color; set to -1 if not present
+     * @return the PNG IDAT byte array
+     * @throws IOException
+     */
+    public static byte[] buildGRGBAData(int gray, int red, int green, int blue, int alpha) throws IOException {
+        // build an image, 32x32, Gray or RGB, with or without alpha, and with filter
+        int filter = 0;
+        int numRows = NUM_ROWS;
+        int numColumns = NUM_COLUMNS;
+        int numComponents = (gray > -1 ? 1 : 3) + (alpha > -1 ? 1 : 0);
+        int numBytesPerRow = numColumns * numComponents + 1; // 1 for filter
+        int numBytes = numRows * numBytesPerRow;
+        byte[] data = new byte[numBytes];
+        for (int r = 0; r < numRows; r++) {
+            data[r * numBytesPerRow] = (byte) filter;
+            for (int c = 0; c < numColumns; c++) {
+                if (numComponents == 1) {
+                    data[r * numBytesPerRow + numComponents * c + 1] = (byte) gray;
+                } else if (numComponents == 2) {
+                    data[r * numBytesPerRow + numComponents * c + 1] = (byte) gray;
+                    data[r * numBytesPerRow + numComponents * c + 2] = (byte) alpha;
+                } else if (numComponents == 3) {
+                    data[r * numBytesPerRow + numComponents * c + 1] = (byte) red;
+                    data[r * numBytesPerRow + numComponents * c + 2] = (byte) green;
+                    data[r * numBytesPerRow + numComponents * c + 3] = (byte) blue;
+                } else if (numComponents == 4) {
+                    data[r * numBytesPerRow + numComponents * c + 1] = (byte) red;
+                    data[r * numBytesPerRow + numComponents * c + 2] = (byte) green;
+                    data[r * numBytesPerRow + numComponents * c + 3] = (byte) blue;
+                    data[r * numBytesPerRow + numComponents * c + 4] = (byte) alpha;
+                }
+            }
+        }
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        DeflaterOutputStream dos = new DeflaterOutputStream(baos, new Deflater());
+        dos.write(data);
+        dos.close();
+        return baos.toByteArray();
+    }
+
+    /**
+     * 
+     * @return a default ImageSize
+     */
+    public static ImageSize getImageSize() {
+        return new ImageSize(NUM_ROWS, NUM_COLUMNS, DPI);
+    }
+}

Added: xmlgraphics/fop/branches/fop-1_1rc1/test/java/org/apache/fop/render/pdf/ImageRawPNGAdapterTestCase.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/fop-1_1rc1/test/java/org/apache/fop/render/pdf/ImageRawPNGAdapterTestCase.java?rev=1353186&view=auto
==============================================================================
--- xmlgraphics/fop/branches/fop-1_1rc1/test/java/org/apache/fop/render/pdf/ImageRawPNGAdapterTestCase.java (added)
+++ xmlgraphics/fop/branches/fop-1_1rc1/test/java/org/apache/fop/render/pdf/ImageRawPNGAdapterTestCase.java Sat Jun 23 19:31:33 2012
@@ -0,0 +1,142 @@
+/*
+ * 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.fop.render.pdf;
+
+import java.awt.image.ComponentColorModel;
+import java.awt.image.IndexColorModel;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.util.zip.Deflater;
+import java.util.zip.DeflaterOutputStream;
+
+import org.junit.Test;
+
+import org.apache.xmlgraphics.image.loader.ImageSize;
+import org.apache.xmlgraphics.image.loader.impl.ImageRawPNG;
+
+import org.apache.fop.pdf.FlateFilter;
+import org.apache.fop.pdf.PDFAMode;
+import org.apache.fop.pdf.PDFDocument;
+import org.apache.fop.pdf.PDFProfile;
+import org.apache.fop.render.RawPNGTestUtil;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public class ImageRawPNGAdapterTestCase {
+
+    @Test
+    public void testSetupWithIndexColorModel() {
+        IndexColorModel cm = mock(IndexColorModel.class);
+        ImageRawPNG irpng = mock(ImageRawPNG.class);
+        PDFDocument doc = mock(PDFDocument.class);
+        PDFProfile profile = mock(PDFProfile.class);
+        ImageRawPNGAdapter irpnga = new ImageRawPNGAdapter(irpng, "mock");
+        ImageSize is = RawPNGTestUtil.getImageSize();
+
+        when(irpng.getColorModel()).thenReturn(cm);
+        // when(cm.hasAlpha()).thenReturn(false);
+        when(doc.getProfile()).thenReturn(profile);
+        when(profile.getPDFAMode()).thenReturn(PDFAMode.PDFA_1A);
+        when(irpng.getSize()).thenReturn(is);
+        irpnga.setup(doc);
+        FlateFilter filter = (FlateFilter) irpnga.getPDFFilter();
+        assertEquals(1, filter.getColors());
+    }
+
+    @Test
+    public void testSetupWithComponentColorModel() throws IOException {
+        ComponentColorModel cm = mock(ComponentColorModel.class);
+        ImageRawPNG irpng = mock(ImageRawPNG.class);
+        PDFDocument doc = mock(PDFDocument.class);
+        PDFProfile profile = mock(PDFProfile.class);
+        ImageRawPNGAdapter irpnga = new ImageRawPNGAdapter(irpng, "mock");
+        ImageSize is = RawPNGTestUtil.getImageSize();
+
+        when(irpng.getColorModel()).thenReturn(cm);
+        when(cm.getNumComponents()).thenReturn(3);
+        // when(cm.hasAlpha()).thenReturn(false);
+        when(doc.getProfile()).thenReturn(profile);
+        when(profile.getPDFAMode()).thenReturn(PDFAMode.PDFA_1A);
+        when(irpng.getSize()).thenReturn(is);
+        irpnga.setup(doc);
+        FlateFilter filter = (FlateFilter) irpnga.getPDFFilter();
+        assertEquals(3, filter.getColors());
+    }
+
+    @Test
+    public void testOutputContentsWithRGBPNG() throws IOException {
+        testOutputContentsWithGRGBAPNG(-1, 128, 128, 128, -1);
+    }
+
+    @Test
+    public void testOutputContentsWithRGBAPNG() throws IOException {
+        testOutputContentsWithGRGBAPNG(-1, 128, 128, 128, 128);
+    }
+
+    @Test
+    public void testOutputContentsWithGPNG() throws IOException {
+        testOutputContentsWithGRGBAPNG(128, -1, -1, -1, -1);
+    }
+
+    @Test
+    public void testOutputContentsWithGAPNG() throws IOException {
+        testOutputContentsWithGRGBAPNG(128, -1, -1, -1, 128);
+    }
+
+    private void testOutputContentsWithGRGBAPNG(int gray, int red, int green, int blue, int alpha)
+            throws IOException {
+        int numColorComponents = gray > -1 ? 1 : 3;
+        int numComponents = numColorComponents + (alpha > -1 ? 1 : 0);
+        ComponentColorModel cm = mock(ComponentColorModel.class);
+        ImageRawPNG irpng = mock(ImageRawPNG.class);
+        PDFDocument doc = mock(PDFDocument.class);
+        PDFProfile profile = mock(PDFProfile.class);
+        ImageRawPNGAdapter irpnga = new ImageRawPNGAdapter(irpng, "mock");
+        ImageSize is = RawPNGTestUtil.getImageSize();
+
+        when(irpng.getColorModel()).thenReturn(cm);
+        when(cm.getNumComponents()).thenReturn(numComponents);
+        // when(cm.hasAlpha()).thenReturn(false);
+        when(doc.getProfile()).thenReturn(profile);
+        when(profile.getPDFAMode()).thenReturn(PDFAMode.PDFA_1A);
+        when(irpng.getSize()).thenReturn(is);
+        irpnga.setup(doc);
+        FlateFilter filter = (FlateFilter) irpnga.getPDFFilter();
+        assertEquals(numColorComponents, filter.getColors());
+
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        byte[] data = RawPNGTestUtil.buildGRGBAData(gray, red, green, blue, alpha);
+        ByteArrayInputStream bais = new ByteArrayInputStream(data);
+        when(irpng.createInputStream()).thenReturn(bais);
+        irpnga.outputContents(baos);
+        if (alpha > -1) {
+            byte[] expected = RawPNGTestUtil.buildGRGBAData(gray, red, green, blue, -1);
+            assertArrayEquals(expected, baos.toByteArray());
+        } else {
+            assertArrayEquals(data, baos.toByteArray());
+        }
+    }
+
+}

Added: xmlgraphics/fop/branches/fop-1_1rc1/test/java/org/apache/fop/render/ps/ImageEncoderPNGTestCase.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/fop-1_1rc1/test/java/org/apache/fop/render/ps/ImageEncoderPNGTestCase.java?rev=1353186&view=auto
==============================================================================
--- xmlgraphics/fop/branches/fop-1_1rc1/test/java/org/apache/fop/render/ps/ImageEncoderPNGTestCase.java (added)
+++ xmlgraphics/fop/branches/fop-1_1rc1/test/java/org/apache/fop/render/ps/ImageEncoderPNGTestCase.java Sat Jun 23 19:31:33 2012
@@ -0,0 +1,133 @@
+/*
+ * 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.fop.render.ps;
+
+import java.awt.image.ComponentColorModel;
+import java.awt.image.IndexColorModel;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+
+import org.junit.Test;
+
+import org.apache.xmlgraphics.image.loader.ImageSize;
+import org.apache.xmlgraphics.image.loader.impl.ImageRawPNG;
+
+import org.apache.fop.render.RawPNGTestUtil;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public class ImageEncoderPNGTestCase {
+
+    @Test
+    public void testWriteToWithRGBPNG() throws IOException {
+        testWriteToWithGRGBAPNG(-1, 128, 128, 128, -1);
+    }
+
+    @Test
+    public void testWriteToWithGPNG() throws IOException {
+        testWriteToWithGRGBAPNG(128, -1, -1, -1, -1);
+    }
+
+    @Test
+    public void testWriteToWithRGBAPNG() throws IOException {
+        testWriteToWithGRGBAPNG(-1, 128, 128, 128, 128);
+    }
+
+    @Test
+    public void testWriteToWithGAPNG() throws IOException {
+        testWriteToWithGRGBAPNG(128, -1, -1, -1, 128);
+    }
+
+    private void testWriteToWithGRGBAPNG(int gray, int red, int green, int blue, int alpha)
+            throws IOException {
+        int numComponents = (gray > -1 ? 1 : 3) + (alpha > -1 ? 1 : 0);
+        ImageSize is = RawPNGTestUtil.getImageSize();
+        ComponentColorModel cm = mock(ComponentColorModel.class);
+        when(cm.getNumComponents()).thenReturn(numComponents);
+        ImageRawPNG irpng = mock(ImageRawPNG.class);
+        when(irpng.getColorModel()).thenReturn(cm);
+        when(irpng.getSize()).thenReturn(is);
+        ImageEncoderPNG iepng = new ImageEncoderPNG(irpng);
+
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        byte[] data = RawPNGTestUtil.buildGRGBAData(gray, red, green, blue, alpha);
+        ByteArrayInputStream bais = new ByteArrayInputStream(data);
+        when(irpng.createInputStream()).thenReturn(bais);
+        iepng.writeTo(baos);
+        if (alpha > -1) {
+            byte[] expected = RawPNGTestUtil.buildGRGBAData(gray, red, green, blue, -1);
+            assertArrayEquals(expected, baos.toByteArray());
+        } else {
+            assertArrayEquals(data, baos.toByteArray());
+        }
+    }
+
+    @Test
+    public void testWriteToWithPalettePNG() throws IOException {
+        ImageSize is = RawPNGTestUtil.getImageSize();
+        IndexColorModel cm = mock(IndexColorModel.class);
+        ImageRawPNG irpng = mock(ImageRawPNG.class);
+        when(irpng.getColorModel()).thenReturn(cm);
+        when(irpng.getSize()).thenReturn(is);
+        ImageEncoderPNG iepng = new ImageEncoderPNG(irpng);
+
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        byte[] data = RawPNGTestUtil.buildGRGBAData(128, -1, -1, -1, -1);
+        ByteArrayInputStream bais = new ByteArrayInputStream(data);
+        when(irpng.createInputStream()).thenReturn(bais);
+        iepng.writeTo(baos);
+        assertArrayEquals(data, baos.toByteArray());
+    }
+
+    @Test
+    public void testGetImplicitFilterWithIndexColorModel() {
+        ImageSize is = RawPNGTestUtil.getImageSize();
+        IndexColorModel cm = mock(IndexColorModel.class);
+        ImageRawPNG irpng = mock(ImageRawPNG.class);
+        when(irpng.getColorModel()).thenReturn(cm);
+        when(irpng.getBitDepth()).thenReturn(8);
+        when(irpng.getSize()).thenReturn(is);
+        ImageEncoderPNG iepng = new ImageEncoderPNG(irpng);
+
+        String expectedFilter = "<< /Predictor 15 /Columns 32 /Colors 1 /BitsPerComponent 8 >> /FlateDecode";
+        assertEquals(expectedFilter, iepng.getImplicitFilter());
+    }
+
+    @Test
+    public void testGetImplicitFilterWithComponentColorModel() {
+        ImageSize is = RawPNGTestUtil.getImageSize();
+        ComponentColorModel cm = mock(ComponentColorModel.class);
+        when(cm.getNumComponents()).thenReturn(3);
+        ImageRawPNG irpng = mock(ImageRawPNG.class);
+        when(irpng.getColorModel()).thenReturn(cm);
+        when(irpng.getBitDepth()).thenReturn(8);
+        when(irpng.getSize()).thenReturn(is);
+        ImageEncoderPNG iepng = new ImageEncoderPNG(irpng);
+
+        String expectedFilter = "<< /Predictor 15 /Columns 32 /Colors 3 /BitsPerComponent 8 >> /FlateDecode";
+        assertEquals(expectedFilter, iepng.getImplicitFilter());
+    }
+
+}

Copied: xmlgraphics/fop/branches/fop-1_1rc1/test/java/org/apache/fop/render/ps/RenderPSTestSuite.java (from r1345841, xmlgraphics/fop/branches/fop-1_1rc1/test/java/org/apache/fop/fonts/EncodingModeTestCase.java)
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/fop-1_1rc1/test/java/org/apache/fop/render/ps/RenderPSTestSuite.java?p2=xmlgraphics/fop/branches/fop-1_1rc1/test/java/org/apache/fop/render/ps/RenderPSTestSuite.java&p1=xmlgraphics/fop/branches/fop-1_1rc1/test/java/org/apache/fop/fonts/EncodingModeTestCase.java&r1=1345841&r2=1353186&rev=1353186&view=diff
==============================================================================
--- xmlgraphics/fop/branches/fop-1_1rc1/test/java/org/apache/fop/fonts/EncodingModeTestCase.java (original)
+++ xmlgraphics/fop/branches/fop-1_1rc1/test/java/org/apache/fop/render/ps/RenderPSTestSuite.java Sat Jun 23 19:31:33 2012
@@ -17,25 +17,27 @@
 
 /* $Id$ */
 
-package org.apache.fop.fonts;
+package org.apache.fop.render.ps;
 
-import static org.junit.Assert.assertEquals;
-
-import org.junit.Test;
-
-public class EncodingModeTestCase {
-
-    @Test
-    public void testGetName() {
-        assertEquals("auto", EncodingMode.AUTO.getName());
-        assertEquals("single-byte", EncodingMode.SINGLE_BYTE.getName());
-        assertEquals("cid", EncodingMode.CID.getName());
-    }
-
-    @Test
-    public void testGetValue() {
-        assertEquals(EncodingMode.AUTO, EncodingMode.getEncodingMode("auto"));
-        assertEquals(EncodingMode.SINGLE_BYTE, EncodingMode.getEncodingMode("single-byte"));
-        assertEquals(EncodingMode.CID, EncodingMode.getEncodingMode("cid"));
-    }
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+import org.junit.runners.Suite.SuiteClasses;
+
+import org.apache.fop.render.ps.fonts.PSTTFGeneratorTestCase;
+import org.apache.fop.render.ps.fonts.PSTTFGlyphOutputStreamTestCase;
+import org.apache.fop.render.ps.fonts.PSTTFOutputStreamTestCase;
+import org.apache.fop.render.ps.fonts.PSTTFTableOutputStreamTestCase;
+
+
+/**
+ * A test Suite for org.apache.fop.render.ps.*
+ */
+@RunWith(Suite.class)
+@SuiteClasses({
+        PSTTFGeneratorTestCase.class,
+        PSTTFOutputStreamTestCase.class,
+        PSTTFGlyphOutputStreamTestCase.class,
+        PSTTFTableOutputStreamTestCase.class
+})
+public final class RenderPSTestSuite {
 }

Added: xmlgraphics/fop/branches/fop-1_1rc1/test/java/org/apache/fop/render/ps/fonts/PSTTFGeneratorTestCase.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/fop-1_1rc1/test/java/org/apache/fop/render/ps/fonts/PSTTFGeneratorTestCase.java?rev=1353186&view=auto
==============================================================================
--- xmlgraphics/fop/branches/fop-1_1rc1/test/java/org/apache/fop/render/ps/fonts/PSTTFGeneratorTestCase.java (added)
+++ xmlgraphics/fop/branches/fop-1_1rc1/test/java/org/apache/fop/render/ps/fonts/PSTTFGeneratorTestCase.java Sat Jun 23 19:31:33 2012
@@ -0,0 +1,120 @@
+/*
+ * 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.fop.render.ps.fonts;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import org.apache.xmlgraphics.ps.PSGenerator;
+
+/**
+ * The test class for org.apache.fop.render.ps.fonts.PSGenerator
+ */
+public class PSTTFGeneratorTestCase {
+    private PSTTFGenerator ttfGen;
+    private ByteArrayOutputStream out = new ByteArrayOutputStream();
+    private PSGenerator gen = new PSGenerator(out);
+    private byte[] byteArray;
+
+    /**
+     * Constructor
+     */
+    public PSTTFGeneratorTestCase() {
+        byteArray = new byte[65536];
+        for (int i = 0; i < 65536; i++) {
+            byteArray[i] = (byte) i;
+        }
+    }
+
+    @Before
+    public void setUp() {
+        ttfGen = new PSTTFGenerator(gen);
+    }
+
+    /**
+     * Tests startString() - starts the string in an appropriate way for a PostScript file.
+     * @exception IOException write error
+     */
+    @Test
+    public void testStartString() throws IOException {
+        ttfGen.startString();
+        assertEquals("<\n", out.toString());
+    }
+
+    /**
+     * Test streamBytes() - tests that strings are written to file in the proper format.
+     * @throws IOException write error.
+     */
+    @Test
+    public void testStreamBytes() throws IOException {
+        ttfGen.streamBytes(byteArray, 0, 16);
+        assertEquals("000102030405060708090A0B0C0D0E0F", out.toString());
+        /*
+         * 65520 is the closes multiple of 80 to 65535 (max string size in PS document) and since
+         * one byte takes up two characters, 65520 / 2 - 16 (16 bytes already written)= 32744.
+         */
+        ttfGen.streamBytes(byteArray, 0, 32744);
+        // Using a regex to ensure that the format is correct
+        assertTrue(out.toString().matches("([0-9A-F]{80}\n){819}"));
+        try {
+            ttfGen.streamBytes(byteArray, 0, PSTTFGenerator.MAX_BUFFER_SIZE + 1);
+            fail("Shouldn't be able to write more than MAX_BUFFER_SIZE to a PS document");
+        } catch (UnsupportedOperationException e) {
+            // PASS
+        }
+    }
+
+    /**
+     * Test reset() - reset should reset the line counter such that when reset() is invoked the
+     * following string streamed to the PS document should be 80 chars long.
+     * @throws IOException file write error.
+     */
+    @Test
+    public void testReset() throws IOException {
+        ttfGen.streamBytes(byteArray, 0, 40);
+        assertTrue(out.toString().matches("([0-9A-F]{80}\n)"));
+        ttfGen.streamBytes(byteArray, 0, 40);
+        assertTrue(out.toString().matches("([0-9A-F]{80}\n){2}"));
+
+    }
+
+    /**
+     * Test endString() - ensures strings are ended in the PostScript document in the correct
+     * format, a "00" needs to be appended to the end of a string.
+     * @throws IOException file write error
+     */
+    @Test
+    public void testEndString() throws IOException {
+        ttfGen.endString();
+        assertEquals("00\n> ", out.toString());
+        out.reset();
+        // we need to check that this doesn't write more than 80 chars per line
+        ttfGen.streamBytes(byteArray, 0, 40);
+        ttfGen.endString();
+        assertTrue(out.toString().matches("([0-9A-F]{80}\n)00\n> "));
+    }
+}

Added: xmlgraphics/fop/branches/fop-1_1rc1/test/java/org/apache/fop/render/ps/fonts/PSTTFGlyphOutputStreamTestCase.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/fop-1_1rc1/test/java/org/apache/fop/render/ps/fonts/PSTTFGlyphOutputStreamTestCase.java?rev=1353186&view=auto
==============================================================================
--- xmlgraphics/fop/branches/fop-1_1rc1/test/java/org/apache/fop/render/ps/fonts/PSTTFGlyphOutputStreamTestCase.java (added)
+++ xmlgraphics/fop/branches/fop-1_1rc1/test/java/org/apache/fop/render/ps/fonts/PSTTFGlyphOutputStreamTestCase.java Sat Jun 23 19:31:33 2012
@@ -0,0 +1,109 @@
+/*
+ * 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.fop.render.ps.fonts;
+
+import java.io.IOException;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.InOrder;
+
+import static org.junit.Assert.fail;
+import static org.mockito.Mockito.inOrder;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+
+/**
+ * Test class for PSTTFGlyphOutputStream
+ */
+public class PSTTFGlyphOutputStreamTestCase {
+    private PSTTFGenerator mockGen;
+    private PSTTFGlyphOutputStream glyphOut;
+
+    @Before
+    public void setUp() {
+        mockGen = mock(PSTTFGenerator.class);
+        glyphOut = new PSTTFGlyphOutputStream(mockGen);
+    }
+
+    /**
+     * Test startGlyphStream() - test that startGlyphStream() invokes reset() and startString() in
+     * PSTTFGenerator.
+     * @exception IOException file write error
+     */
+    @Test
+    public void testStartGlyphStream() throws IOException {
+        glyphOut.startGlyphStream();
+        verify(mockGen).startString();
+    }
+
+    /**
+     * Test streamGlyph(byte[],int,int) - tests several paths:
+     * 1) strings are properly appended
+     * 2) when total strings size > PSTTFGenerator.MAX_BUFFER_SIZE, the strings is closed and a new
+     * strings is started.
+     * 3) if a glyph of size > PSTTFGenerator.MAX_BUFFER_SIZE is attempted, an exception is thrown.
+     * @throws IOException file write error.
+     */
+    @Test
+    public void testStreamGlyph() throws IOException {
+        int byteArraySize = 10;
+        byte[] byteArray = new byte[byteArraySize];
+        int runs = 100;
+        for (int i = 0; i < runs; i++) {
+            glyphOut.streamGlyph(byteArray, 0, byteArraySize);
+        }
+        verify(mockGen, times(runs)).streamBytes(byteArray, 0, byteArraySize);
+
+        /*
+         * We want to run this for MAX_BUFFER_SIZE / byteArraySize so that go over the string
+         * boundary and enforce the ending and starting of a new string. Using mockito to ensure
+         * that this behaviour is performed in order (since this is an integral behavioural aspect)
+         */
+        int stringLimit = PSTTFGenerator.MAX_BUFFER_SIZE / byteArraySize;
+        for (int i = 0; i < stringLimit; i++) {
+            glyphOut.streamGlyph(byteArray, 0, byteArraySize);
+        }
+        InOrder inOrder = inOrder(mockGen);
+        inOrder.verify(mockGen, times(stringLimit)).streamBytes(byteArray, 0, byteArraySize);
+        inOrder.verify(mockGen).endString();
+        inOrder.verify(mockGen).startString();
+        inOrder.verify(mockGen, times(runs)).streamBytes(byteArray, 0, byteArraySize);
+
+        try {
+            glyphOut.streamGlyph(byteArray, 0, PSTTFGenerator.MAX_BUFFER_SIZE + 1);
+            fail("Shouldn't allow a length > PSTTFGenerator.MAX_BUFFER_SIZE");
+        } catch (UnsupportedOperationException e) {
+            // PASS
+        }
+    }
+
+    /**
+     * Test endGlyphStream() - tests that PSTTFGenerator.endString() is invoked when this method
+     * is called.
+     * @throws IOException file write exception
+     */
+    @Test
+    public void testEndGlyphStream() throws IOException {
+        glyphOut.endGlyphStream();
+        verify(mockGen).endString();
+    }
+}

Added: xmlgraphics/fop/branches/fop-1_1rc1/test/java/org/apache/fop/render/ps/fonts/PSTTFOutputStreamTestCase.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/fop-1_1rc1/test/java/org/apache/fop/render/ps/fonts/PSTTFOutputStreamTestCase.java?rev=1353186&view=auto
==============================================================================
--- xmlgraphics/fop/branches/fop-1_1rc1/test/java/org/apache/fop/render/ps/fonts/PSTTFOutputStreamTestCase.java (added)
+++ xmlgraphics/fop/branches/fop-1_1rc1/test/java/org/apache/fop/render/ps/fonts/PSTTFOutputStreamTestCase.java Sat Jun 23 19:31:33 2012
@@ -0,0 +1,90 @@
+/*
+ * 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.fop.render.ps.fonts;
+
+import java.io.IOException;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+
+import org.apache.xmlgraphics.ps.PSGenerator;
+
+import org.apache.fop.fonts.truetype.TTFGlyphOutputStream;
+import org.apache.fop.fonts.truetype.TTFTableOutputStream;
+
+/**
+ * Tests PSTTFOuputStream
+ */
+public class PSTTFOutputStreamTestCase {
+    private PSGenerator gen;
+    private PSTTFOutputStream out;
+
+    /**
+     * Assigns an OutputStream to the PSGenerator.
+     */
+    @Before
+    public void setUp() {
+        gen = mock(PSGenerator.class);
+        out = new PSTTFOutputStream(gen);
+    }
+
+    /**
+     * Test startFontStream() - Just tests that the font is properly initiated in the PostScript
+     * document (in this case with "/sfnts[")
+     * @throws IOException write exception.
+     */
+    @Test
+    public void testStartFontStream() throws IOException {
+        out.startFontStream();
+        verify(gen).write("/sfnts[");
+    }
+
+    /**
+     * Test getTableOutputStream() - we need to test that the inheritance model is properly obeyed.
+     */
+    @Test
+    public void testGetTableOutputStream() {
+        TTFTableOutputStream tableOut = out.getTableOutputStream();
+        assertTrue(tableOut instanceof PSTTFTableOutputStream);
+    }
+
+    /**
+     * Test getGlyphOutputStream() - we need to test that the inheritance model is properly obeyed.
+     */
+    @Test
+    public void testGetGlyphOutputStream() {
+        TTFGlyphOutputStream glyphOut = out.getGlyphOutputStream();
+        assertTrue(glyphOut instanceof PSTTFGlyphOutputStream);
+    }
+
+    /**
+     * Test endFontStream()
+     * @exception IOException write error.
+     */
+    @Test
+    public void testEndFontStream() throws IOException {
+        out.endFontStream();
+        verify(gen).writeln("] def");
+    }
+}

Added: xmlgraphics/fop/branches/fop-1_1rc1/test/java/org/apache/fop/render/ps/fonts/PSTTFTableOutputStreamTestCase.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/fop-1_1rc1/test/java/org/apache/fop/render/ps/fonts/PSTTFTableOutputStreamTestCase.java?rev=1353186&view=auto
==============================================================================
--- xmlgraphics/fop/branches/fop-1_1rc1/test/java/org/apache/fop/render/ps/fonts/PSTTFTableOutputStreamTestCase.java (added)
+++ xmlgraphics/fop/branches/fop-1_1rc1/test/java/org/apache/fop/render/ps/fonts/PSTTFTableOutputStreamTestCase.java Sat Jun 23 19:31:33 2012
@@ -0,0 +1,87 @@
+/*
+ * 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.fop.render.ps.fonts;
+
+import java.io.IOException;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.InOrder;
+
+import static org.mockito.Mockito.inOrder;
+import static org.mockito.Mockito.mock;
+
+/**
+ * Test class for unit testing PSTTFTableOutputStream
+ */
+public class PSTTFTableOutputStreamTestCase {
+    private PSTTFGenerator mockGen;
+    private PSTTFTableOutputStream tableOut;
+
+    @Before
+    public void setUp() {
+        mockGen = mock(PSTTFGenerator.class);
+        tableOut = new PSTTFTableOutputStream(mockGen);
+    }
+
+    /**
+     * Test streamTable() - several paths to test (2. and 3. test corner cases):
+     * 1) that a table of length < PSTTFGenerator.MAX_BUFFER_SIZE invokes the correct methods in
+     * PSTTFGenerator.
+     * 2) that a table of length > PSTTFGenerator.MAX_BUFFER_SIZE and
+     * length == n * PSTTFGenerator.MAX_BUFFER_SIZE is split up and the methods in PSTTFGenerator
+     * are invoked.
+     * 3) that a table of length > PSTTFGenerator.MAX_BUFFER_SIZE but
+     * length != n * PSTTFGenerator.MAX_BUFFER_SIZE is split up and the methods in PSTTFGenerator
+     * are invoked.
+     * @throws IOException file write error.
+     */
+    @Test
+    public void testStreamTable() throws IOException {
+        byte[] byteArray = new byte[PSTTFGenerator.MAX_BUFFER_SIZE * 3];
+        tableOut.streamTable(byteArray, 0, 10);
+        InOrder inOrder = inOrder(mockGen);
+        inOrder.verify(mockGen).startString();
+        inOrder.verify(mockGen).streamBytes(byteArray, 0, 10);
+        inOrder.verify(mockGen).endString();
+
+        setUp(); // reset all all the method calls
+        /* We're going to run this 3 times to ensure the proper method calls are invoked and all
+         * the bytes are streamed */
+        tableOut.streamTable(byteArray, 0, byteArray.length);
+        inOrder = inOrder(mockGen);
+        for (int i = 0; i < 3; i++) {
+            int offset = PSTTFGenerator.MAX_BUFFER_SIZE * i;
+            inOrder.verify(mockGen).startString();
+            inOrder.verify(mockGen).streamBytes(byteArray, offset, PSTTFGenerator.MAX_BUFFER_SIZE);
+            inOrder.verify(mockGen).endString();
+        }
+
+        setUp(); // reset all the method calls
+        tableOut.streamTable(byteArray, 0, PSTTFGenerator.MAX_BUFFER_SIZE + 1);
+        inOrder = inOrder(mockGen);
+        inOrder.verify(mockGen).startString();
+        inOrder.verify(mockGen).streamBytes(byteArray, 0, PSTTFGenerator.MAX_BUFFER_SIZE);
+        inOrder.verify(mockGen).endString();
+        inOrder.verify(mockGen).startString();
+        inOrder.verify(mockGen).streamBytes(byteArray, PSTTFGenerator.MAX_BUFFER_SIZE, 1);
+        inOrder.verify(mockGen).endString();
+    }
+}

Copied: xmlgraphics/fop/branches/fop-1_1rc1/test/java/org/apache/fop/util/HexEncoderTestCase.java (from r1345841, xmlgraphics/fop/branches/fop-1_1rc1/test/java/org/apache/fop/fonts/DejaVuLGCSerifTestCase.java)
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/fop-1_1rc1/test/java/org/apache/fop/util/HexEncoderTestCase.java?p2=xmlgraphics/fop/branches/fop-1_1rc1/test/java/org/apache/fop/util/HexEncoderTestCase.java&p1=xmlgraphics/fop/branches/fop-1_1rc1/test/java/org/apache/fop/fonts/DejaVuLGCSerifTestCase.java&r1=1345841&r2=1353186&rev=1353186&view=diff
==============================================================================
--- xmlgraphics/fop/branches/fop-1_1rc1/test/java/org/apache/fop/fonts/DejaVuLGCSerifTestCase.java (original)
+++ xmlgraphics/fop/branches/fop-1_1rc1/test/java/org/apache/fop/util/HexEncoderTestCase.java Sat Jun 23 19:31:33 2012
@@ -17,40 +17,45 @@
 
 /* $Id$ */
 
-package org.apache.fop.fonts;
+package org.apache.fop.util;
 
-import static org.junit.Assert.assertEquals;
-
-import java.io.File;
-
-import org.junit.Before;
 import org.junit.Test;
 
+import static org.junit.Assert.assertEquals;
+
 /**
- *
+ * Test case for the conversion of characters into hex-encoded strings.
  */
-public class DejaVuLGCSerifTestCase {
-
-    private FontResolver fontResolver = FontManager.createMinimalFontResolver(false);
-    private CustomFont font;
+public class HexEncoderTestCase {
 
     /**
-     * sets up the testcase by loading the DejaVu Font.
-     *
-     * @throws Exception
-     *             if the test fails.
+     * Tests that characters are properly encoded into hex strings.
      */
-    @Before
-    public void setUp() throws Exception {
-        File file = new File("test/resources/fonts/ttf/DejaVuLGCSerif.ttf");
-        font = FontLoader.loadFont(file, "", true, EncodingMode.AUTO, fontResolver);
+    @Test
+    public void testEncodeChar() {
+        char[] digits = new char[] {'0', '0', '0', '0'};
+        for (int c = 0; c <= 0xFFFF; c++) {
+            assertEquals(new String(digits), HexEncoder.encode((char) c));
+            increment(digits);
+        }
     }
 
-    /**
-     * Simple test to see if font name was detected correctly.
-     */
-    @Test
-    public void testFontName() {
-        assertEquals("DejaVuLGCSerif", font.getFontName());
+    private static void increment(char[] digits) {
+        int d = 4;
+        do {
+            d--;
+            digits[d] = successor(digits[d]);
+        } while (digits[d] == '0' && d > 0);
     }
+
+    private static char successor(char d) {
+        if (d == '9') {
+            return 'A';
+        } else if (d == 'F') {
+            return '0';
+        } else {
+            return (char) (d + 1);
+        }
+    }
+
 }

Added: xmlgraphics/fop/branches/fop-1_1rc1/test/resources/fonts/ttf/DroidSansMono.LICENSE
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/fop-1_1rc1/test/resources/fonts/ttf/DroidSansMono.LICENSE?rev=1353186&view=auto
==============================================================================
--- xmlgraphics/fop/branches/fop-1_1rc1/test/resources/fonts/ttf/DroidSansMono.LICENSE (added)
+++ xmlgraphics/fop/branches/fop-1_1rc1/test/resources/fonts/ttf/DroidSansMono.LICENSE Sat Jun 23 19:31:33 2012
@@ -0,0 +1,18 @@
+Copyright (C) 2008 The Android Open Source Project
+
+Licensed 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.
+
+##########
+
+This directory contains the fonts for the platform. They are licensed
+under the Apache 2 license.

Added: xmlgraphics/fop/branches/fop-1_1rc1/test/resources/fonts/ttf/DroidSansMono.ttf
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/fop-1_1rc1/test/resources/fonts/ttf/DroidSansMono.ttf?rev=1353186&view=auto
==============================================================================
Files xmlgraphics/fop/branches/fop-1_1rc1/test/resources/fonts/ttf/DroidSansMono.ttf (added) and xmlgraphics/fop/branches/fop-1_1rc1/test/resources/fonts/ttf/DroidSansMono.ttf Sat Jun 23 19:31:33 2012 differ



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