FileDocCategorySizeDatePackage
TestFontCollection.javaAPI DocApache Poi 3.0.13440Mon Jan 01 18:56:12 GMT 2007org.apache.poi.hslf.record

TestFontCollection

public class TestFontCollection extends TestCase
Tests FontCollection and FontEntityAtom records
author
Yegor Kozlov

Fields Summary
private byte[]
data
Constructors Summary
Methods Summary
public voidtestAddFont()

        FontCollection fonts = new FontCollection(data, 0, data.length);
        int idx = fonts.addFont("Times New Roman");
        assertEquals(idx, 0);
        idx = fonts.addFont("Helvetica");
        assertEquals(idx, 1);
        idx = fonts.addFont("Arial");
        assertEquals(idx, 2);
        idx = fonts.addFont("Arial"); //the font being added twice
        assertEquals(idx, 2);

        // Font collection should contain 3 fonts
        Record[] child = fonts.getChildRecords();
        assertEquals(child.length, 3);
        
        // Check we get the right font name for the indicies
        assertEquals("Times New Roman", fonts.getFontWithId(0));
        assertEquals("Helvetica", fonts.getFontWithId(1));
        assertEquals("Arial", fonts.getFontWithId(2));
        assertNull(fonts.getFontWithId(3));
    
public voidtestFonts()


         
        FontCollection fonts = new FontCollection(data, 0, data.length);
        Record[] child = fonts.getChildRecords();
        assertEquals(child.length, 1);

        FontEntityAtom fnt = (FontEntityAtom)child[0];
        assertEquals(fnt.getFontName(), "Times New Roman");
    
public voidtestWrite()

        FontCollection fonts = new FontCollection(data, 0, data.length);
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        fonts.writeOut(out);
        byte[] recdata = out.toByteArray();
        assertTrue(Arrays.equals(recdata, data));