You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by le...@apache.org on 2022/04/13 06:28:18 UTC

svn commit: r1899798 - /pdfbox/trunk/fontbox/src/test/java/org/apache/fontbox/cff/CFFCharsetTest.java

Author: lehmi
Date: Wed Apr 13 06:28:18 2022
New Revision: 1899798

URL: http://svn.apache.org/viewvc?rev=1899798&view=rev
Log:
PDFBOX-5143: add more tests

Modified:
    pdfbox/trunk/fontbox/src/test/java/org/apache/fontbox/cff/CFFCharsetTest.java

Modified: pdfbox/trunk/fontbox/src/test/java/org/apache/fontbox/cff/CFFCharsetTest.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/fontbox/src/test/java/org/apache/fontbox/cff/CFFCharsetTest.java?rev=1899798&r1=1899797&r2=1899798&view=diff
==============================================================================
--- pdfbox/trunk/fontbox/src/test/java/org/apache/fontbox/cff/CFFCharsetTest.java (original)
+++ pdfbox/trunk/fontbox/src/test/java/org/apache/fontbox/cff/CFFCharsetTest.java Wed Apr 13 06:28:18 2022
@@ -16,11 +16,90 @@
 package org.apache.fontbox.cff;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
 
 import org.junit.jupiter.api.Test;
 
 class CFFCharsetTest
 {
+
+    @Test
+    void testEmbeddedCharset()
+    {
+        // true -> CFFCharsetCID
+        EmbeddedCharset embeddedCharsetCID = new EmbeddedCharset(true);
+        assertTrue(embeddedCharsetCID.isCIDFont());
+        embeddedCharsetCID.addCID(10, 20);
+        // test existing mapping
+        assertEquals(10, embeddedCharsetCID.getGIDForCID(20));
+        assertEquals(20, embeddedCharsetCID.getCIDForGID(10));
+        // test not existing mapping
+        assertEquals(0, embeddedCharsetCID.getGIDForCID(99));
+        assertEquals(0, embeddedCharsetCID.getCIDForGID(99));
+        // test not allowed method calls
+        assertThrows(IllegalStateException.class, () -> embeddedCharsetCID.getSIDForGID(0));
+        assertThrows(IllegalStateException.class, () -> embeddedCharsetCID.getGIDForSID(0));
+        assertThrows(IllegalStateException.class, () -> embeddedCharsetCID.addSID(0, 0, "test"));
+        assertThrows(IllegalStateException.class, () -> embeddedCharsetCID.getSID("test"));
+        assertThrows(IllegalStateException.class, () -> embeddedCharsetCID.getNameForGID(0));
+        // false -> CFFCharsetType1
+        EmbeddedCharset embeddedCharsetType1 = new EmbeddedCharset(false);
+        assertFalse(embeddedCharsetType1.isCIDFont());
+        embeddedCharsetType1.addSID(10, 20, "test");
+        // test existing mapping
+        assertEquals(20, embeddedCharsetType1.getSID("test"));
+        assertEquals(10, embeddedCharsetType1.getGIDForSID(20));
+        assertEquals(20, embeddedCharsetType1.getSIDForGID(10));
+        // test not existing mapping
+        assertEquals(0, embeddedCharsetType1.getGIDForSID(99));
+        assertEquals(0, embeddedCharsetType1.getSIDForGID(99));
+        // test not allowed method calls
+        assertThrows(IllegalStateException.class, () -> embeddedCharsetType1.getCIDForGID(0));
+        assertThrows(IllegalStateException.class, () -> embeddedCharsetType1.getGIDForCID(0));
+        assertThrows(IllegalStateException.class, () -> embeddedCharsetType1.addCID(0, 0));
+    }
+
+    @Test
+    void testCFFCharsetCID()
+    {
+        CFFCharsetCID cffCharsetCID = new CFFCharsetCID();
+        assertTrue(cffCharsetCID.isCIDFont());
+        cffCharsetCID.addCID(10, 20);
+        // test existing mapping
+        assertEquals(10, cffCharsetCID.getGIDForCID(20));
+        assertEquals(20, cffCharsetCID.getCIDForGID(10));
+        // test not existing mapping
+        assertEquals(0, cffCharsetCID.getGIDForCID(99));
+        assertEquals(0, cffCharsetCID.getCIDForGID(99));
+        // test not allowed method calls
+        assertThrows(IllegalStateException.class, () -> cffCharsetCID.getSIDForGID(0));
+        assertThrows(IllegalStateException.class, () -> cffCharsetCID.getGIDForSID(0));
+        assertThrows(IllegalStateException.class, () -> cffCharsetCID.addSID(0, 0, "test"));
+        assertThrows(IllegalStateException.class, () -> cffCharsetCID.getSID("test"));
+        assertThrows(IllegalStateException.class, () -> cffCharsetCID.getNameForGID(0));
+    }
+
+    @Test
+    void testCFFCharsetType1()
+    {
+        CFFCharsetType1 cffCharsetType1 = new CFFCharsetType1();
+        assertFalse(cffCharsetType1.isCIDFont());
+        cffCharsetType1.addSID(10, 20, "test");
+        // test existing mapping
+        assertEquals(20, cffCharsetType1.getSID("test"));
+        assertEquals(10, cffCharsetType1.getGIDForSID(20));
+        assertEquals(20, cffCharsetType1.getSIDForGID(10));
+        // test not existing mapping
+        assertEquals(0, cffCharsetType1.getGIDForSID(99));
+        assertEquals(0, cffCharsetType1.getSIDForGID(99));
+        // test not allowed method calls
+        assertThrows(IllegalStateException.class, () -> cffCharsetType1.getCIDForGID(0));
+        assertThrows(IllegalStateException.class, () -> cffCharsetType1.getGIDForCID(0));
+        assertThrows(IllegalStateException.class, () -> cffCharsetType1.addCID(0, 0));
+    }
+
     @Test
     void testCFFExpertCharset()
     {