diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/PAPBinTable.java b/src/scratchpad/src/org/apache/poi/hwpf/model/PAPBinTable.java index ea7d52a0b..07ccad1c9 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/PAPBinTable.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/PAPBinTable.java @@ -249,7 +249,9 @@ public class PAPBinTable { PAPX papx = oldPapxSortedByEndPos.get( papxIndex ); - assert papx.getEnd() > startInclusive; + assert papxIndex + 1 == oldPapxSortedByEndPos.size() + || papx.getEnd() > startInclusive; + if ( papx.getEnd() - 1 > charIndex ) { lastPapxIndex = papxIndex; diff --git a/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestPAPBinTable.java b/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestPAPBinTable.java index e34d563ac..95ed6f7ad 100644 --- a/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestPAPBinTable.java +++ b/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestPAPBinTable.java @@ -18,77 +18,67 @@ package org.apache.poi.hwpf.model; import java.io.ByteArrayOutputStream; -import java.util.ArrayList; +import java.util.List; import junit.framework.TestCase; import org.apache.poi.hwpf.HWPFDocFixture; +import org.apache.poi.hwpf.HWPFTestDataSamples; import org.apache.poi.hwpf.model.io.HWPFFileSystem; -public final class TestPAPBinTable - extends TestCase +public final class TestPAPBinTable extends TestCase { - private PAPBinTable _pAPBinTable = null; - private HWPFDocFixture _hWPFDocFixture; - private TextPieceTable fakeTPT = new TextPieceTable(); - - public void testReadWrite() - throws Exception - { - FileInformationBlock fib = _hWPFDocFixture._fib; - byte[] mainStream = _hWPFDocFixture._mainStream; - byte[] tableStream = _hWPFDocFixture._tableStream; - - _pAPBinTable = new PAPBinTable(mainStream, tableStream, null, fib.getFcPlcfbtePapx(), fib.getLcbPlcfbtePapx(), null, fakeTPT, false); - - HWPFFileSystem fileSys = new HWPFFileSystem(); - - _pAPBinTable.writeTo(fileSys, 0); - ByteArrayOutputStream tableOut = fileSys.getStream("1Table"); - ByteArrayOutputStream mainOut = fileSys.getStream("WordDocument"); - - byte[] newTableStream = tableOut.toByteArray(); - byte[] newMainStream = mainOut.toByteArray(); - - PAPBinTable newBinTable = new PAPBinTable(newMainStream, newTableStream, null,0, newTableStream.length, null, fakeTPT, false); - - ArrayList oldTextRuns = _pAPBinTable.getParagraphs(); - ArrayList newTextRuns = newBinTable.getParagraphs(); - - assertEquals(oldTextRuns.size(), newTextRuns.size()); - - int size = oldTextRuns.size(); - for (int x = 0; x < size; x++) + public void testObIs() { - PropertyNode oldNode = (PropertyNode)oldTextRuns.get(x); - PropertyNode newNode = (PropertyNode)newTextRuns.get(x); - - assertTrue(oldNode.equals(newNode)); + // shall not fail with assertions on + HWPFTestDataSamples.openSampleFile( "ob_is.doc" ); } + public void testReadWrite() throws Exception + { + /** @todo verify the constructors */ + HWPFDocFixture _hWPFDocFixture = new HWPFDocFixture( this, + HWPFDocFixture.DEFAULT_TEST_FILE ); + _hWPFDocFixture.setUp(); + TextPieceTable fakeTPT = new TextPieceTable(); + FileInformationBlock fib = _hWPFDocFixture._fib; + byte[] mainStream = _hWPFDocFixture._mainStream; + byte[] tableStream = _hWPFDocFixture._tableStream; - } + PAPBinTable _pAPBinTable = new PAPBinTable( mainStream, tableStream, + null, fib.getFcPlcfbtePapx(), fib.getLcbPlcfbtePapx(), null, + fakeTPT, false ); - protected void setUp() - throws Exception - { - super.setUp(); - /**@todo verify the constructors*/ - _hWPFDocFixture = new HWPFDocFixture(this, HWPFDocFixture.DEFAULT_TEST_FILE); + HWPFFileSystem fileSys = new HWPFFileSystem(); - _hWPFDocFixture.setUp(); - } + _pAPBinTable.writeTo( fileSys, 0 ); + ByteArrayOutputStream tableOut = fileSys.getStream( "1Table" ); + ByteArrayOutputStream mainOut = fileSys.getStream( "WordDocument" ); - protected void tearDown() - throws Exception - { - _hWPFDocFixture.tearDown(); + byte[] newTableStream = tableOut.toByteArray(); + byte[] newMainStream = mainOut.toByteArray(); - _hWPFDocFixture = null; - super.tearDown(); - } + PAPBinTable newBinTable = new PAPBinTable( newMainStream, + newTableStream, null, 0, newTableStream.length, null, fakeTPT, + false ); + List oldTextRuns = _pAPBinTable.getParagraphs(); + List newTextRuns = newBinTable.getParagraphs(); + + assertEquals( oldTextRuns.size(), newTextRuns.size() ); + + int size = oldTextRuns.size(); + for ( int x = 0; x < size; x++ ) + { + PAPX oldNode = oldTextRuns.get( x ); + PAPX newNode = newTextRuns.get( x ); + + assertTrue( oldNode.equals( newNode ) ); + } + + _hWPFDocFixture.tearDown(); + } }