diff options
author | Nick Burch <nick@apache.org> | 2008-06-28 18:21:21 +0000 |
---|---|---|
committer | Nick Burch <nick@apache.org> | 2008-06-28 18:21:21 +0000 |
commit | 9147f07e308e6aabec08548336e9a02598bc5cf9 (patch) | |
tree | 54721c95a1c707cf09826cfb3f37416247fba4d5 /src/testcases/org/apache/poi/hssf/eventusermodel | |
parent | 910c010d47d4afafe3a5bb0602b38c8c1cc70a7c (diff) | |
download | poi-9147f07e308e6aabec08548336e9a02598bc5cf9.tar.gz poi-9147f07e308e6aabec08548336e9a02598bc5cf9.zip |
Avoid spurious missing lines with the MissingRecordAware event code, and odd files that contain RowRecords in the middle of the cell Records.
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@672562 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/testcases/org/apache/poi/hssf/eventusermodel')
-rw-r--r-- | src/testcases/org/apache/poi/hssf/eventusermodel/TestMissingRecordAwareHSSFListener.java | 77 |
1 files changed, 70 insertions, 7 deletions
diff --git a/src/testcases/org/apache/poi/hssf/eventusermodel/TestMissingRecordAwareHSSFListener.java b/src/testcases/org/apache/poi/hssf/eventusermodel/TestMissingRecordAwareHSSFListener.java index 16a406cba1..bbad7b7f48 100644 --- a/src/testcases/org/apache/poi/hssf/eventusermodel/TestMissingRecordAwareHSSFListener.java +++ b/src/testcases/org/apache/poi/hssf/eventusermodel/TestMissingRecordAwareHSSFListener.java @@ -16,8 +16,6 @@ ==================================================================== */ package org.apache.poi.hssf.eventusermodel; -import java.io.File; -import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; @@ -29,6 +27,7 @@ import org.apache.poi.hssf.HSSFTestDataSamples; import org.apache.poi.hssf.eventusermodel.dummyrecord.LastCellOfRowDummyRecord; import org.apache.poi.hssf.eventusermodel.dummyrecord.MissingCellDummyRecord; import org.apache.poi.hssf.eventusermodel.dummyrecord.MissingRowDummyRecord; +import org.apache.poi.hssf.record.BOFRecord; import org.apache.poi.hssf.record.LabelSSTRecord; import org.apache.poi.hssf.record.Record; import org.apache.poi.hssf.record.RowRecord; @@ -40,8 +39,7 @@ public final class TestMissingRecordAwareHSSFListener extends TestCase { private Record[] r; - public void setUp() { - + public void openNormal() { HSSFRequest req = new HSSFRequest(); MockHSSFListener mockListen = new MockHSSFListener(); MissingRecordAwareHSSFListener listener = new MissingRecordAwareHSSFListener(mockListen); @@ -55,10 +53,31 @@ public final class TestMissingRecordAwareHSSFListener extends TestCase { } catch (IOException e) { throw new RuntimeException(e); } + r = mockListen.getRecords(); + assertTrue(r.length > 100); + } + public void openAlt() { + HSSFRequest req = new HSSFRequest(); + MockHSSFListener mockListen = new MockHSSFListener(); + MissingRecordAwareHSSFListener listener = new MissingRecordAwareHSSFListener(mockListen); + req.addListenerForAllRecords(listener); + + HSSFEventFactory factory = new HSSFEventFactory(); + try { + InputStream is = HSSFTestDataSamples.openSampleFileStream("MRExtraLines.xls"); + POIFSFileSystem fs = new POIFSFileSystem(is); + factory.processWorkbookEvents(req, fs); + } catch (IOException e) { + throw new RuntimeException(e); + } + + r = mockListen.getRecords(); + assertTrue(r.length > 100); } public void testMissingRowRecords() throws Exception { + openNormal(); // We have rows 0, 1, 2, 20 and 21 int row0 = -1; @@ -108,6 +127,7 @@ public final class TestMissingRecordAwareHSSFListener extends TestCase { } public void testEndOfRowRecords() throws Exception { + openNormal(); // Find the cell at 0,0 int cell00 = -1; @@ -194,7 +214,7 @@ public final class TestMissingRecordAwareHSSFListener extends TestCase { assertTrue(r[cell00+57] instanceof LastCellOfRowDummyRecord); // Check the numbers of the last seen columns - LastCellOfRowDummyRecord[] lrs = new LastCellOfRowDummyRecord[23]; + LastCellOfRowDummyRecord[] lrs = new LastCellOfRowDummyRecord[24]; int lrscount = 0; for(int i=0; i<r.length; i++) { if(r[i] instanceof LastCellOfRowDummyRecord) { @@ -229,6 +249,7 @@ public final class TestMissingRecordAwareHSSFListener extends TestCase { public void testMissingCellRecords() throws Exception { + openNormal(); // Find the cell at 0,0 int cell00 = -1; @@ -326,10 +347,41 @@ public final class TestMissingRecordAwareHSSFListener extends TestCase { assertEquals(22, mc.getRow()); assertEquals(10, mc.getColumn()); } + + // Make sure we don't put in any extra new lines + // that aren't already there + public void testNoExtraNewLines() throws Exception { + // Load a different file + openAlt(); + for(int i=0; i<r.length; i++) { + System.err.println(r[i]); + } + + + // This file has has something in lines 1-33 + List lcor = new ArrayList(); + for(int i=0; i<r.length; i++) { + if(r[i] instanceof LastCellOfRowDummyRecord) + lcor.add( (LastCellOfRowDummyRecord)r[i] ); + } + + // Check we got the 33 rows + assertEquals(33, lcor.size()); + LastCellOfRowDummyRecord[] rowEnds = (LastCellOfRowDummyRecord[]) + lcor.toArray(new LastCellOfRowDummyRecord[lcor.size()]); + assertEquals(33, rowEnds.length); + + // And check they have the right stuff in them, + // no repeats + for(int i=0; i<rowEnds.length; i++) { + assertEquals(i, rowEnds[i].getRow()); + } + } private static final class MockHSSFListener implements HSSFListener { public MockHSSFListener() {} private final List _records = new ArrayList(); + private boolean logToStdOut = false; public void processRecord(Record record) { _records.add(record); @@ -346,9 +398,20 @@ public final class TestMissingRecordAwareHSSFListener extends TestCase { LastCellOfRowDummyRecord lc = (LastCellOfRowDummyRecord)record; log("Got end-of row, row was " + lc.getRow() + ", last column was " + lc.getLastColumnNumber()); } + + if(record instanceof BOFRecord) { + BOFRecord r = (BOFRecord)record; + if(r.getType() == BOFRecord.TYPE_WORKSHEET) { + log("On new sheet"); + } + } + if(record instanceof RowRecord) { + RowRecord rr = (RowRecord)record; + log("Starting row #" + rr.getRowNumber()); + } } - private static void log(String msg) { - if(false) { // successful tests should be quiet + private void log(String msg) { + if(logToStdOut) { System.out.println(msg); } } |