From 7e2f39de176e8fa312eddef4c30783ce13be2c10 Mon Sep 17 00:00:00 2001 From: Nick Burch Date: Sun, 31 Jul 2005 18:06:48 +0000 Subject: [PATCH] Test code for the new Text Styling record class git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@353756 13f79535-47bb-0310-9956-ffa450edef68 --- .../hslf/record/TestStyleTextPropAtom.java | 114 ++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 src/scratchpad/testcases/org/apache/poi/hslf/record/TestStyleTextPropAtom.java diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestStyleTextPropAtom.java b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestStyleTextPropAtom.java new file mode 100644 index 0000000000..91679b9684 --- /dev/null +++ b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestStyleTextPropAtom.java @@ -0,0 +1,114 @@ + +/* ==================================================================== + 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 org.apache.poi.hslf.record.StyleTextPropAtom.*; + +import junit.framework.TestCase; +import java.io.ByteArrayOutputStream; + +/** + * Tests that StyleTextPropAtom works properly + * + * @author Nick Burch (nick at torchbox dot com) + */ +public class TestStyleTextPropAtom extends TestCase { + // From a real file + private byte[] data_a = new byte[] { 0, 0, 0xA1-256, 0x0F, 0x2A, 0, 0, 0, + 0x36, 00, 00, 00, 00, 00, 00, 00, + 00, 00, 0x15, 00, 00, 00, 00, 00, + 00, 00, 0x11, 00, 00, 00, 00, 00, + 0x04, 00, 00, 00, 00, 0x05, 0x10, 00, + 00, 00, 00, 00, 0x04, 00, 0xFF-256, 0x33, 00, 0xFE-256 + }; + + private byte[] data_b = new byte[] { 0, 0, 0xA1-256, 0x0F, 0x2E, 0, 0, 0, + 0x53, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0x1E, 0, 0, 0, 01, 0, + 0, 0, 01, 0, 0x1C, 0, 0, 0, + 02, 0, 04, 0, 02, 0, 0, 0, + 0, 05, 0x19, 0, 0, 0, 0, 0, + 04, 0, 0xFF-256, 0x33, 0, 0xFE-256 + }; + + public void testRecordType() throws Exception { + StyleTextPropAtom stpa = new StyleTextPropAtom(data_a,0,data_a.length); + StyleTextPropAtom stpb = new StyleTextPropAtom(data_b,0,data_b.length); + assertEquals(4001l, stpa.getRecordType()); + assertEquals(4001l, stpb.getRecordType()); + } + + public void testCharacterGroups() throws Exception { + StyleTextPropAtom stpa = new StyleTextPropAtom(data_a,0,data_a.length); + StyleTextPropAtom stpb = new StyleTextPropAtom(data_b,0,data_b.length); + + assertEquals(3, stpa.getCharacterStyles().length); + assertEquals(3, stpb.getCharacterStyles().length); + } + + public void testCharacterLengths() throws Exception { + StyleTextPropAtom stpa = new StyleTextPropAtom(data_a,0,data_a.length); + StyleTextPropAtom stpb = new StyleTextPropAtom(data_b,0,data_b.length); + + // 54 chars, 21 + 17 (+ 16) + assertEquals(54, stpa.getParagraphStyleCharactersCoveredLength() ); + CharacterStyle[] csa = stpa.getCharacterStyles(); + assertEquals(21, csa[0].getCharactersCoveredLength() ); + assertEquals(17, csa[1].getCharactersCoveredLength() ); + assertEquals(0, csa[2].getCharactersCoveredLength() ); + + // 83 chars, 30 + 28 (+ 25) + assertEquals(83, stpb.getParagraphStyleCharactersCoveredLength() ); + CharacterStyle[] csb = stpb.getCharacterStyles(); + assertEquals(30, csb[0].getCharactersCoveredLength() ); + assertEquals(28, csb[1].getCharactersCoveredLength() ); + assertEquals(0, csb[2].getCharactersCoveredLength() ); + } + + public void testCharacterProps() throws Exception { + StyleTextPropAtom stpa = new StyleTextPropAtom(data_a,0,data_a.length); + StyleTextPropAtom stpb = new StyleTextPropAtom(data_b,0,data_b.length); + + // Set A has no styles + CharacterStyle[] csa = stpa.getCharacterStyles(); + for(int i=0; i