summaryrefslogtreecommitdiffstats
path: root/src/testcases/org/apache
diff options
context:
space:
mode:
Diffstat (limited to 'src/testcases/org/apache')
-rw-r--r--src/testcases/org/apache/poi/hssf/record/TestSeriesTextRecord.java101
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java3
2 files changed, 74 insertions, 30 deletions
diff --git a/src/testcases/org/apache/poi/hssf/record/TestSeriesTextRecord.java b/src/testcases/org/apache/poi/hssf/record/TestSeriesTextRecord.java
index a016e60e91..8b05dc4336 100644
--- a/src/testcases/org/apache/poi/hssf/record/TestSeriesTextRecord.java
+++ b/src/testcases/org/apache/poi/hssf/record/TestSeriesTextRecord.java
@@ -17,46 +17,89 @@
package org.apache.poi.hssf.record;
-
+import junit.framework.AssertionFailedError;
import junit.framework.TestCase;
-/**
- * Tests the serialization and deserialization of the SeriesTextRecord
- * class works correctly. Test data taken directly from a real
- * Excel file.
- *
+import org.apache.poi.util.HexRead;
+/**
+ * Tests the serialization and deserialization of the SeriesTextRecord class
+ * works correctly. Test data taken directly from a real Excel file.
+ *
+ *
* @author Andrew C. Oliver (acoliver at apache.org)
*/
public final class TestSeriesTextRecord extends TestCase {
- byte[] data = new byte[] {
- (byte)0x00,(byte)0x00,(byte)0x0C,(byte)0x01,(byte)0x56,(byte)0x00,(byte)0x61,(byte)0x00,(byte)0x6C,(byte)0x00,(byte)0x75,(byte)0x00,(byte)0x65,(byte)0x00,(byte)0x20,(byte)0x00,(byte)0x4E,(byte)0x00,(byte)0x75,(byte)0x00,(byte)0x6D,(byte)0x00,(byte)0x62,(byte)0x00,(byte)0x65,(byte)0x00,(byte)0x72,(byte)0x00
- };
+ private static final byte[] SIMPLE_DATA = HexRead
+ .readFromString("00 00 0C 00 56 61 6C 75 65 20 4E 75 6D 62 65 72");
+
+ public void testLoad() {
+ SeriesTextRecord record = new SeriesTextRecord(TestcaseRecordInputStream.create(0x100d, SIMPLE_DATA));
+
+ assertEquals((short) 0, record.getId());
+ assertEquals("Value Number", record.getText());
- public void testLoad() {
- SeriesTextRecord record = new SeriesTextRecord(TestcaseRecordInputStream.create(0x100d, data));
+ assertEquals(SIMPLE_DATA.length + 4, record.getRecordSize());
+ }
- assertEquals( (short)0, record.getId());
- assertEquals( (byte)0x0C, record.getTextLength());
- assertEquals( (byte)0x01, record.getUndocumented());
- assertEquals( "Value Number", record.getText());
+ public void testStore() {
+ SeriesTextRecord record = new SeriesTextRecord();
- assertEquals( 32, record.getRecordSize() );
- }
+ record.setId(0);
+ record.setText("Value Number");
- public void testStore()
- {
- SeriesTextRecord record = new SeriesTextRecord();
+ byte[] recordBytes = record.serialize();
+ TestcaseRecordInputStream.confirmRecordEncoding(SeriesTextRecord.sid, SIMPLE_DATA,
+ recordBytes);
+ }
- record.setId( (short)0 );
- record.setTextLength( (byte)0x0C );
- record.setUndocumented( (byte)0x01 );
- record.setText( "Value Number" );
+ public void testReserializeLongTitle() {
+ // Hex dump from bug 45784 attachment 22560 streamOffset=0x0CD1
+ byte[] data = HexRead.readFromString(
+ "00 00, "
+ + "82 "
+ + "01 "
+ + "50 00 6C 00 61 00 73 00 6D 00 61 00 20 00 4C 00 "
+ + "65 00 76 00 65 00 6C 00 73 00 20 00 6F 00 66 00 "
+ + "20 00 4C 00 2D 00 30 00 30 00 30 00 31 00 31 00 "
+ + "31 00 32 00 32 00 32 00 2D 00 33 00 33 00 33 00 "
+ + "58 00 34 00 34 00 34 00 20 00 69 00 6E 00 20 00 "
+ + "53 00 44 00 20 00 72 00 61 00 74 00 0A 00 50 00 "
+ + "4F 00 20 00 33 00 2E 00 30 00 20 00 6D 00 67 00 "
+ + "2F 00 6B 00 67 00 20 00 28 00 35 00 2E 00 30 00 "
+ + "20 00 6D 00 4C 00 2F 00 6B 00 67 00 29 00 20 00 "
+ + "69 00 6E 00 20 00 4D 00 65 00 74 00 68 00 6F 00 "
+ + "63 00 65 00 6C 00 0A 00 49 00 56 00 20 00 30 00 "
+ + "2E 00 35 00 20 00 6D 00 67 00 2F 00 6B 00 67 00 "
+ + "20 00 28 00 31 00 2E 00 30 00 20 00 6D 00 4C 00 "
+ + "2F 00 6B 00 67 00 29 00 20 00 69 00 6E 00 20 00 "
+ + "36 00 30 00 25 00 20 00 50 00 45 00 47 00 20 00 "
+ + "32 00 30 00 30 00 0A 00 46 00 20 00 3D 00 61 00 "
+ + "62 00 63 00");
+ RecordInputStream in = TestcaseRecordInputStream.create(SeriesTextRecord.sid, data);
+ SeriesTextRecord str;
+ try {
+ str = new SeriesTextRecord(in);
+ } catch (RecordFormatException e) {
+ if (e.getCause() instanceof IllegalArgumentException) {
+ // 'would be' error msg changed at svn r703620
+ // "Illegal length - asked for -126 but only 130 left!"
+ // "Bad requested string length (-126)"
+ throw new AssertionFailedError("Identified bug 45784a");
+ }
+ throw e;
+ }
- byte [] recordBytes = record.serialize();
- assertEquals(recordBytes.length - 4, data.length);
- for (int i = 0; i < data.length; i++)
- assertEquals("At offset " + i, data[i], recordBytes[i+4]);
- }
+ if (str.getRecordSize() < 0) {
+ throw new AssertionFailedError("Identified bug 45784b");
+ }
+ byte[] ser;
+ try {
+ ser = str.serialize();
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ TestcaseRecordInputStream.confirmRecordEncoding(SeriesTextRecord.sid, data, ser);
+ }
}
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java b/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java
index 4c8604b698..4ca87428af 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java
@@ -1481,9 +1481,10 @@ public final class TestBugs extends TestCase {
* Charts with long titles
*/
public void test45784() {
- // This used to break
+ // This used to break
HSSFWorkbook wb = openSample("45784.xls");
assertEquals(1, wb.getNumberOfSheets());
+ wb = HSSFTestDataSamples.writeOutAndReadBack(wb);
}
/**