From: Said Ryan Ackley Date: Sat, 28 Jun 2003 15:58:27 +0000 (+0000) Subject: tests X-Git-Tag: PERF_BEFORE_MERGE~290 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=68cc1da72f3bbd01a20daad125a8b1a5b0e2486c;p=poi.git tests git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@353176 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/scratchpad/testcases/org/apache/poi/hwpf/HWPFDocFixture.java b/src/scratchpad/testcases/org/apache/poi/hwpf/HWPFDocFixture.java new file mode 100644 index 0000000000..abee2dbb58 --- /dev/null +++ b/src/scratchpad/testcases/org/apache/poi/hwpf/HWPFDocFixture.java @@ -0,0 +1,59 @@ +package org.apache.poi.hwpf; + +import java.io.FileInputStream; + +import org.apache.poi.poifs.filesystem.POIFSFileSystem; +import org.apache.poi.poifs.filesystem.DocumentEntry; + +import org.apache.poi.hwpf.model.hdftypes.*; + + +public class HWPFDocFixture +{ + public byte[] _tableStream; + public byte[] _mainStream; + public FileInformationBlock _fib; + + public HWPFDocFixture(Object obj) + { + + } + + public void setUp() + { + try + { + POIFSFileSystem filesystem = new POIFSFileSystem(new FileInputStream( + "C:\\test.doc")); + + DocumentEntry documentProps = + (DocumentEntry) filesystem.getRoot().getEntry("WordDocument"); + _mainStream = new byte[documentProps.getSize()]; + filesystem.createDocumentInputStream("WordDocument").read(_mainStream); + + // use the fib to determine the name of the table stream. + _fib = new FileInformationBlock(_mainStream); + + String name = "0Table"; + if (_fib.isFWhichTblStm()) + { + name = "1Table"; + } + + // read in the table stream. + DocumentEntry tableProps = + (DocumentEntry) filesystem.getRoot().getEntry(name); + _tableStream = new byte[tableProps.getSize()]; + filesystem.createDocumentInputStream(name).read(_tableStream); + } + catch (Throwable t) + { + t.printStackTrace(); + } + } + + public void tearDown() + { + } + +} diff --git a/src/scratchpad/testcases/org/apache/poi/hwpf/model/hdftypes/TestCHPBinTable.java b/src/scratchpad/testcases/org/apache/poi/hwpf/model/hdftypes/TestCHPBinTable.java new file mode 100644 index 0000000000..cc3c9a3457 --- /dev/null +++ b/src/scratchpad/testcases/org/apache/poi/hwpf/model/hdftypes/TestCHPBinTable.java @@ -0,0 +1,77 @@ +package org.apache.poi.hwpf.model.hdftypes; + +import java.io.ByteArrayOutputStream; +import java.util.ArrayList; + +import junit.framework.*; + +import org.apache.poi.hwpf.*; +import org.apache.poi.hwpf.model.io.*; + +public class TestCHPBinTable + extends TestCase +{ + private CHPBinTable _cHPBinTable = null; + private HWPFDocFixture _hWPFDocFixture; + + public TestCHPBinTable(String name) + { + super(name); + } + + public void testReadWrite() + throws Exception + { + FileInformationBlock fib = _hWPFDocFixture._fib; + byte[] mainStream = _hWPFDocFixture._mainStream; + byte[] tableStream = _hWPFDocFixture._tableStream; + int fcMin = fib.getFcMin(); + + _cHPBinTable = new CHPBinTable(mainStream, tableStream, fib.getFcPlcfbteChpx(), fib.getLcbPlcfbteChpx(), fcMin); + + HWPFFileSystem fileSys = new HWPFFileSystem(); + + _cHPBinTable.writeTo(fileSys, 0); + ByteArrayOutputStream tableOut = fileSys.getStream("1Table"); + ByteArrayOutputStream mainOut = fileSys.getStream("WordDocument"); + + byte[] newTableStream = tableOut.toByteArray(); + byte[] newMainStream = mainOut.toByteArray(); + + CHPBinTable newBinTable = new CHPBinTable(newMainStream, newTableStream, 0, newTableStream.length, 0); + + ArrayList oldTextRuns = _cHPBinTable._textRuns; + ArrayList newTextRuns = newBinTable._textRuns; + + assertEquals(oldTextRuns.size(), newTextRuns.size()); + + int size = oldTextRuns.size(); + for (int x = 0; x < size; x++) + { + PropertyNode oldNode = (PropertyNode)oldTextRuns.get(x); + PropertyNode newNode = (PropertyNode)newTextRuns.get(x); + + assertTrue(oldNode.equals(newNode)); + } + + } + protected void setUp() + throws Exception + { + super.setUp(); + _hWPFDocFixture = new HWPFDocFixture(this); + + _hWPFDocFixture.setUp(); + } + + protected void tearDown() + throws Exception + { + _cHPBinTable = null; + _hWPFDocFixture.tearDown(); + + _hWPFDocFixture = null; + super.tearDown(); + } + +} diff --git a/src/scratchpad/testcases/org/apache/poi/hwpf/model/hdftypes/TestPlexOfCps.java b/src/scratchpad/testcases/org/apache/poi/hwpf/model/hdftypes/TestPlexOfCps.java new file mode 100644 index 0000000000..0aa8270a11 --- /dev/null +++ b/src/scratchpad/testcases/org/apache/poi/hwpf/model/hdftypes/TestPlexOfCps.java @@ -0,0 +1,68 @@ +package org.apache.poi.hwpf.model.hdftypes; + +import junit.framework.*; +import org.apache.poi.hwpf.*; + +import org.apache.poi.util.LittleEndian; + +public class TestPlexOfCps + extends TestCase +{ + private PlexOfCps _plexOfCps = null; + private HWPFDocFixture _hWPFDocFixture; + + public TestPlexOfCps(String name) + { + super(name); + } + public void testWriteRead() + throws Exception + { + _plexOfCps = new PlexOfCps(4); + + int last = 0; + for (int x = 0; x < 110; x++) + { + byte[] intHolder = new byte[4]; + int span = (int)(110.0f * Math.random()); + LittleEndian.putInt(intHolder, span); + _plexOfCps.addProperty(new PropertyNode(last, last + span, intHolder)); + last += span; + } + + byte[] output = _plexOfCps.toByteArray(); + _plexOfCps = new PlexOfCps(output, 0, output.length, 4); + int len = _plexOfCps.length(); + assertEquals(len, 110); + + last = 0; + for (int x = 0; x < len; x++) + { + PropertyNode node = _plexOfCps.getProperty(x); + assertEquals(node.getStart(), last); + last = node.getEnd(); + int span = LittleEndian.getInt(node.getBuf()); + assertEquals(node.getEnd()-node.getStart(), span); + } + } + protected void setUp() + throws Exception + { + super.setUp(); + /**@todo verify the constructors*/ + _hWPFDocFixture = new HWPFDocFixture(this); + + _hWPFDocFixture.setUp(); + } + + protected void tearDown() + throws Exception + { + _plexOfCps = null; + _hWPFDocFixture.tearDown(); + + _hWPFDocFixture = null; + super.tearDown(); + } + +}