From 628f5026bf2f4f8e9e868dbaaa0484d9384e2544 Mon Sep 17 00:00:00 2001 From: Nick Burch Date: Tue, 2 Aug 2005 17:16:46 +0000 Subject: [PATCH] Tests for Font support from Yegor, from Bug #35972 git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@353760 13f79535-47bb-0310-9956-ffa450edef68 --- .../poi/hslf/record/TestFontCollection.java | 75 +++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 src/scratchpad/testcases/org/apache/poi/hslf/record/TestFontCollection.java diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestFontCollection.java b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestFontCollection.java new file mode 100644 index 0000000000..eb759a5689 --- /dev/null +++ b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestFontCollection.java @@ -0,0 +1,75 @@ + +/* ==================================================================== + Copyright 2002-2004 Apache Software Foundation + + 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. +==================================================================== */ + +package org.apache.poi.hslf.record; + +import junit.framework.TestCase; + +import java.io.ByteArrayOutputStream; +import java.util.Arrays; + +/** + * Tests FontCollection and FontEntityAtom records + * + * @author Yegor Kozlov + */ +public class TestFontCollection extends TestCase { + // From a real file + private byte[] data = new byte[] { + 0x0F, 0x00, 0xD5-256, 0x07, 0x4C, 0x00, 0x00, 0x00, + 0x00, 0x00, 0xB7-256, 0x0F, 0x44, 0x00, 0x00, 0x00, + 0x54, 0x00, 0x69, 0x00, 0x6D, 0x00, 0x65, 0x00, 0x73, 0x00, + 0x20, 0x00, 0x4E, 0x00, 0x65, 0x00, 0x77, 0x00, 0x20, 0x00, + 0x52, 0x00, 0x6F, 0x00, 0x6D, 0x00, 0x61, 0x00, 0x6E, 0x00, + 0x00, 0x00, 0x74, 0x34, 0xB8-256, 0x00, 0x7C, 0xDA-256, 0x12, 0x00, + 0x64, 0xDA-256, 0x12, 0x00, 0x76, 0xC7-256, 0x0B, 0x30, 0x08, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7C, 0xDA-256, 0x12, 0x00, + 0x28, 0xDD-256, 0x0D, 0x30, 0x00, 0x00, 0x04, 0x00 }; + + public void testFonts() throws Exception { + 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 void testAddFont() throws Exception { + 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); + } + + public void testWrite() throws Exception { + FontCollection fonts = new FontCollection(data, 0, data.length); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + fonts.writeOut(out); + byte[] recdata = out.toByteArray(); + assertTrue(Arrays.equals(recdata, data)); + } +} -- 2.39.5