aboutsummaryrefslogtreecommitdiffstats
path: root/src/testcases/org/apache/poi/hssf/eventmodel
diff options
context:
space:
mode:
authorAvik Sengupta <avik@apache.org>2003-03-07 15:49:04 +0000
committerAvik Sengupta <avik@apache.org>2003-03-07 15:49:04 +0000
commitc7ff97b7dd6b57f5436a1ccf4c16c250282a2696 (patch)
tree335d64e3953b0874f9de9f6db9eea404a9fe481e /src/testcases/org/apache/poi/hssf/eventmodel
parent43c981a497a760dd9e1118a9c317a66a8e48f190 (diff)
downloadpoi-c7ff97b7dd6b57f5436a1ccf4c16c250282a2696.tar.gz
poi-c7ff97b7dd6b57f5436a1ccf4c16c250282a2696.zip
Fixed bug 17373 - incorrect handling of continue records after unknown records corrupting a template. Patch submitted by Csaba Nagy -- thanks
git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@353024 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/testcases/org/apache/poi/hssf/eventmodel')
-rw-r--r--src/testcases/org/apache/poi/hssf/eventmodel/TestEventRecordFactory.java59
1 files changed, 59 insertions, 0 deletions
diff --git a/src/testcases/org/apache/poi/hssf/eventmodel/TestEventRecordFactory.java b/src/testcases/org/apache/poi/hssf/eventmodel/TestEventRecordFactory.java
index 992fd9cc46..9c3ba32256 100644
--- a/src/testcases/org/apache/poi/hssf/eventmodel/TestEventRecordFactory.java
+++ b/src/testcases/org/apache/poi/hssf/eventmodel/TestEventRecordFactory.java
@@ -3,10 +3,13 @@ package org.apache.poi.hssf.eventmodel;
import java.io.ByteArrayInputStream;
import java.io.EOFException;
import java.util.Iterator;
+import java.util.Arrays;
import org.apache.poi.hssf.record.BOFRecord;
import org.apache.poi.hssf.record.EOFRecord;
import org.apache.poi.hssf.record.Record;
+import org.apache.poi.hssf.record.UnknownRecord;
+import org.apache.poi.hssf.record.ContinueRecord;
import junit.framework.TestCase;
@@ -14,6 +17,7 @@ import junit.framework.TestCase;
* enclosing_type describe the purpose here
*
* @author Andrew C. Oliver acoliver@apache.org
+ * @author Csaba Nagy (ncsaba at yahoo dot com)
*/
public class TestEventRecordFactory extends TestCase
{
@@ -173,4 +177,59 @@ public class TestEventRecordFactory extends TestCase
// fail("not implemented");
}
+
+ /**
+ * TEST NAME: Test Creating ContinueRecords After Unknown Records From An InputStream <P>
+ * OBJECTIVE: Test that the RecordFactory given an InputStream
+ * constructs the expected records.<P>
+ * SUCCESS: Record factory creates the expected records.<P>
+ * FAILURE: The wrong records are created or contain the wrong values <P>
+ *
+ */
+ public void testContinuedUnknownRecord()
+ {
+ final byte[] data = new byte[]
+ {
+ 0, -1, 0, 0, // an unknown record with 0 length
+ 0x3C , 0, 3, 0, 1, 2, 3, // a continuation record with 3 bytes of data
+ 0x3C , 0, 1, 0, 4 // one more continuation record with 1 byte of data
+ };
+
+ final int[] recCnt = { 0 };
+ final int[] offset = { 0 };
+ factory.registerListener(
+ new ERFListener() {
+ private String[] expectedRecordTypes = {
+ UnknownRecord.class.getName(),
+ ContinueRecord.class.getName(),
+ ContinueRecord.class.getName()
+ };
+ public boolean processRecord(Record rec)
+ {
+ // System.out.println(rec.toString());
+ assertEquals(
+ "Record type",
+ expectedRecordTypes[recCnt[0]],
+ rec.getClass().getName()
+ );
+ compareData(rec, "Record " + recCnt[0] + ": ");
+ recCnt[0]++;
+ return true;
+ }
+ private void compareData(Record record, String message) {
+ byte[] recData = record.serialize();
+ for (int i = 0; i < recData.length; i++) {
+ assertEquals(message + " data byte " + i, data[offset[0]++], recData[i]);
+ }
+ }
+ },
+ new short[] {-256, 0x3C}
+ );
+
+ factory.processRecords(new ByteArrayInputStream(data));
+ assertEquals("nr. of processed records", 3, recCnt[0]);
+ assertEquals("nr. of processed bytes", data.length, offset[0]);
+ }
+
+
}