Author: tilman
Date: Mon Aug 31 12:12:12 2026
New Revision: 1937684

Log:
PDFBOX-5660: improve test coverage

Modified:
   
pdfbox/branches/2.0/fontbox/src/test/java/org/apache/fontbox/ttf/TrueTypeFontCollectionTest.java

Modified: 
pdfbox/branches/2.0/fontbox/src/test/java/org/apache/fontbox/ttf/TrueTypeFontCollectionTest.java
==============================================================================
--- 
pdfbox/branches/2.0/fontbox/src/test/java/org/apache/fontbox/ttf/TrueTypeFontCollectionTest.java
    Mon Aug 31 11:23:58 2026        (r1937683)
+++ 
pdfbox/branches/2.0/fontbox/src/test/java/org/apache/fontbox/ttf/TrueTypeFontCollectionTest.java
    Mon Aug 31 12:12:12 2026        (r1937684)
@@ -19,13 +19,37 @@ package org.apache.fontbox.ttf;
 import static org.junit.Assert.fail;
 
 import java.io.ByteArrayInputStream;
+import java.io.File;
 import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assume.assumeTrue;
 
 import org.junit.Test;
 
 public class TrueTypeFontCollectionTest
 {
     @Test
+    public void testMissingTtcHeader()
+    {
+        try
+        {
+            new TrueTypeCollection(new ByteArrayInputStream(new byte[4]));
+        }
+        catch (IOException ex)
+        {
+            // this is the expected behaviour
+            assertEquals("Missing TTC header", ex.getMessage());
+        }
+        catch (Throwable throwable)
+        {
+            fail("Missing ttc header not detected!");
+        }
+    }
+
+    @Test
     public void testNumberOfFonts()
     {
         byte[] payload = { 0x74, 0x74, 0x63, 0x66, 0x00, 0x00, 0x00, 0x00, 
0x7F, (byte) 0xFF,
@@ -34,13 +58,76 @@ public class TrueTypeFontCollectionTest
         {
             new TrueTypeCollection(new ByteArrayInputStream(payload));
         }
-        catch (IOException exception)
+        catch (IOException ex)
         {
             // this is the expected behaviour
+            assertEquals("Invalid number of fonts 2147483647", 
ex.getMessage());
         }
         catch (Throwable throwable)
         {
             fail("Invalid number of fonts not detected!");
         }
     }
+
+    @Test
+    public void testMingLiu() throws IOException
+    {
+        File file = new File("c:/windows/fonts/mingliu.ttc");
+        assumeTrue(file.exists());
+        checkTrueTypeCollection(file, "[MingLiU, PMingLiU, 
Ming-Lt-HKSCS-UNI-H]");
+    }
+
+    @Test
+    public void testMsMincho() throws IOException
+    {
+        File file = new File("c:/windows/fonts/msmincho.ttc");
+        assumeTrue(file.exists());
+        checkTrueTypeCollection(file, "[MS-Mincho, MS-PMincho]");
+    }
+
+    @Test
+    public void testSimSun() throws IOException
+    {
+        File file = new File("c:/windows/fonts/simsun.ttc");
+        assumeTrue(file.exists());
+        checkTrueTypeCollection(file, "[SimSun, NSimSun]");
+    }
+
+    @Test
+    public void testLucidaGrande() throws IOException
+    {
+        File file = new File("/System/Library/Fonts/LucidaGrande.ttc");
+        assumeTrue(file.exists());
+        checkTrueTypeCollection(file, "[LucidaGrande, LucidaGrande-Bold, 
.LucidaGrandeUI, .LucidaGrandeUI-Bold]");
+    }
+
+    @Test
+    public void testAvenir() throws IOException
+    {
+        File file = new File("/System/Library/Fonts/Avenir.ttc");
+        assumeTrue(file.exists());
+        checkTrueTypeCollection(file, 
+                "[Avenir-Book, Avenir-BookOblique, Avenir-Black, 
Avenir-BlackOblique, "
+                        + "Avenir-Heavy, Avenir-HeavyOblique, Avenir-Light, 
Avenir-LightOblique, "
+                        + "Avenir-Medium, Avenir-MediumOblique, 
Avenir-Oblique, Avenir-Roman]");
+    }
+
+    private void checkTrueTypeCollection(File file, String expected) throws 
IOException
+    {
+        final TrueTypeCollection ttc = new TrueTypeCollection(file);
+        final List<String> list = new ArrayList();
+        ttc.processAllFonts(new TrueTypeCollection.TrueTypeFontProcessor()
+        {
+            @Override
+            public void process(TrueTypeFont ttf) throws IOException
+            {
+                list.add(ttf.getName());
+                TrueTypeFont ttfByName = ttc.getFontByName(ttf.getName());
+                assertEquals(ttf.getName(), ttfByName.getName());
+                ttfByName.close();
+            }
+        });
+        assertEquals(expected, list.toString());
+        ttc.close();
+    }
 }

Reply via email to