use of org.apache.poi.hssf.model.RecordStream in project poi by apache.
the class TestRowRecordsAggregate method testUnknownContinue_bug46280.
/**
* This problem was noted as the overt symptom of bug 46280. The logic for skipping {@link
* UnknownRecord}s in the constructor {@link RowRecordsAggregate} did not allow for the
* possibility of tailing {@link ContinueRecord}s.<br/>
* The functionality change being tested here is actually not critical to the overall fix
* for bug 46280, since the fix involved making sure the that offending <i>PivotTable</i>
* records do not get into {@link RowRecordsAggregate}.<br/>
* This fix in {@link RowRecordsAggregate} was implemented anyway since any {@link
* UnknownRecord} has the potential of being 'continued'.
*/
@Test
public void testUnknownContinue_bug46280() {
Record[] inRecs = { new RowRecord(0), new NumberRecord(), new UnknownRecord(0x5555, "dummydata".getBytes(LocaleUtil.CHARSET_1252)), new ContinueRecord("moredummydata".getBytes(LocaleUtil.CHARSET_1252)) };
RecordStream rs = new RecordStream(Arrays.asList(inRecs), 0);
RowRecordsAggregate rra;
try {
rra = new RowRecordsAggregate(rs, SharedValueManager.createEmpty());
} catch (RuntimeException e) {
if (e.getMessage().startsWith("Unexpected record type")) {
fail("Identified bug 46280a");
}
throw e;
}
RecordCollector rv = new RecordCollector();
rra.visitContainedRecords(rv);
Record[] outRecs = rv.getRecords();
assertEquals(5, outRecs.length);
}
use of org.apache.poi.hssf.model.RecordStream in project poi by apache.
the class TestPageSettingsBlock method testDuplicateHeaderFooterInside_bug48026.
public void testDuplicateHeaderFooterInside_bug48026() {
Record[] recs = { BOFRecord.createSheetBOF(), new IndexRecord(), //PageSettingsBlock
new HeaderRecord("&LDecember"), new FooterRecord("&LJanuary"), new DimensionsRecord(), new WindowTwoRecord(), //CustomViewSettingsRecordAggregate
new UserSViewBegin(HexRead.readFromString("53 CE BD CC DE 38 44 45 97 C1 5C 89 F9 37 32 1B 01 00 00 00 64 00 00 00 40 00 00 00 03 00 00 00 7D 00 00 20 00 00 34 00 00 00 18 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 FF FF FF FF")), new SelectionRecord(0, 0), // the other is matched with a CustomViewSettingsRecordAggregate having UserSViewBegin with the same GUID
new HeaderFooterRecord(HexRead.readFromString("9C 08 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 34 33 00 00 00 00 00 00 00 00")), new HeaderFooterRecord(HexRead.readFromString("9C 08 00 00 00 00 00 00 00 00 00 00 53 CE BD CC DE 38 44 45 97 C1 5C 89 F9 37 32 1B 34 33 00 00 00 00 00 00 00 00")), new UserSViewEnd(HexRead.readFromString("01 00")), EOFRecord.instance };
RecordStream rs = new RecordStream(Arrays.asList(recs), 0);
InternalSheet sheet;
try {
sheet = InternalSheet.createSheet(rs);
} catch (RuntimeException e) {
if (e.getMessage().equals("Duplicate PageSettingsBlock record (sid=0x89c)")) {
throw new AssertionFailedError("Identified bug 48026");
}
throw e;
}
RecordCollector rv = new RecordCollector();
sheet.visitContainedRecords(rv, 0);
Record[] outRecs = rv.getRecords();
assertEquals(recs.length + 1, outRecs.length);
//expected order of records:
Record[] expectedRecs = { //BOFRecord
recs[0], //IndexRecord
recs[1], //HeaderRecord
recs[2], //FooterRecord
recs[3], // DimensionsRecord
recs[4], // WindowTwoRecord
recs[5], // UserSViewBegin
recs[6], // SelectionRecord
recs[7], //HeaderRecord
recs[2], //FooterRecord
recs[3], // HeaderFooterRecord
recs[8], // UserSViewEnd
recs[10], //EOFRecord
recs[11] };
for (int i = 0; i < expectedRecs.length; i++) {
assertEquals("Record mismatch at index " + i, expectedRecs[i].getClass(), outRecs[i].getClass());
}
HeaderFooterRecord hd1 = (HeaderFooterRecord) expectedRecs[10];
//GUID is zero
assertArrayEquals(new byte[16], hd1.getGuid());
assertTrue(hd1.isCurrentSheet());
UserSViewBegin svb = (UserSViewBegin) expectedRecs[6];
HeaderFooterRecord hd2 = (HeaderFooterRecord) recs[9];
assertFalse(hd2.isCurrentSheet());
//GUIDs of HeaderFooterRecord and UserSViewBegin must be the same
assertArrayEquals(svb.getGuid(), hd2.getGuid());
}
use of org.apache.poi.hssf.model.RecordStream in project poi by apache.
the class TestPageSettingsBlock method testMissingHeaderFooter.
/**
* Excel tolerates missing header / footer records, but adds them (empty) in when re-saving.
* This is not critical functionality but it has been decided to keep POI consistent with
* Excel in this regard.
*/
public void testMissingHeaderFooter() {
// initialise PSB with some records, but not the header / footer
Record[] recs = { new HCenterRecord(), new VCenterRecord() };
RecordStream rs = new RecordStream(Arrays.asList(recs), 0);
PageSettingsBlock psb = new PageSettingsBlock(rs);
// serialize the PSB to see what records come out
RecordCollector rc = new RecordCollector();
psb.visitContainedRecords(rc);
Record[] outRecs = rc.getRecords();
if (outRecs.length == 2) {
throw new AssertionFailedError("PageSettingsBlock didn't add missing header/footer records");
}
assertEquals(4, outRecs.length);
assertEquals(HeaderRecord.class, outRecs[0].getClass());
assertEquals(FooterRecord.class, outRecs[1].getClass());
assertEquals(HCenterRecord.class, outRecs[2].getClass());
assertEquals(VCenterRecord.class, outRecs[3].getClass());
// make sure the added header / footer records are empty
HeaderRecord hr = (HeaderRecord) outRecs[0];
assertEquals("", hr.getText());
FooterRecord fr = (FooterRecord) outRecs[1];
assertEquals("", fr.getText());
}
use of org.apache.poi.hssf.model.RecordStream in project poi by apache.
the class TestPageSettingsBlock method testLateHeaderFooter_bug46953.
/**
* Bug 46953 occurred because POI didn't handle late PSB records properly.
*/
public void testLateHeaderFooter_bug46953() {
int rowIx = 5;
int colIx = 6;
NumberRecord nr = new NumberRecord();
nr.setRow(rowIx);
nr.setColumn((short) colIx);
nr.setValue(3.0);
Record[] recs = { BOFRecord.createSheetBOF(), new HeaderRecord("&LSales Figures"), new FooterRecord("&LJanuary"), new DimensionsRecord(), new WindowTwoRecord(), new HeaderFooterRecord(HexRead.readFromString("9C 08 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 C4 60 00 00 00 00 00 00 00 00")), EOFRecord.instance };
RecordStream rs = new RecordStream(Arrays.asList(recs), 0);
InternalSheet sheet = InternalSheet.createSheet(rs);
RecordCollector rv = new RecordCollector();
sheet.visitContainedRecords(rv, 0);
Record[] outRecs = rv.getRecords();
if (outRecs[4] == EOFRecord.instance) {
throw new AssertionFailedError("Identified bug 46953 - EOF incorrectly appended to PSB");
}
// +1 for index record
assertEquals(recs.length + 1, outRecs.length);
assertEquals(BOFRecord.class, outRecs[0].getClass());
assertEquals(IndexRecord.class, outRecs[1].getClass());
assertEquals(HeaderRecord.class, outRecs[2].getClass());
assertEquals(FooterRecord.class, outRecs[3].getClass());
assertEquals(HeaderFooterRecord.class, outRecs[4].getClass());
assertEquals(DimensionsRecord.class, outRecs[5].getClass());
assertEquals(WindowTwoRecord.class, outRecs[6].getClass());
assertEquals(EOFRecord.instance, outRecs[7]);
}
use of org.apache.poi.hssf.model.RecordStream in project poi by apache.
the class TestPageSettingsBlock method testDuplicateHeaderFooter_bug48026.
public void testDuplicateHeaderFooter_bug48026() {
Record[] recs = { BOFRecord.createSheetBOF(), new IndexRecord(), //PageSettingsBlock
new HeaderRecord("&LDecember"), new FooterRecord("&LJanuary"), new DimensionsRecord(), new WindowTwoRecord(), //CustomViewSettingsRecordAggregate
new UserSViewBegin(HexRead.readFromString("53 CE BD CC DE 38 44 45 97 C1 5C 89 F9 37 32 1B 01 00 00 00 64 00 00 00 40 00 00 00 03 00 00 00 7D 00 00 20 00 00 34 00 00 00 18 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 FF FF FF FF")), new SelectionRecord(0, 0), new UserSViewEnd(HexRead.readFromString("01 00")), // the other is matched with a CustomViewSettingsRecordAggregate having UserSViewBegin with the same GUID
new HeaderFooterRecord(HexRead.readFromString("9C 08 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 34 33 00 00 00 00 00 00 00 00")), new HeaderFooterRecord(HexRead.readFromString("9C 08 00 00 00 00 00 00 00 00 00 00 53 CE BD CC DE 38 44 45 97 C1 5C 89 F9 37 32 1B 34 33 00 00 00 00 00 00 00 00")), EOFRecord.instance };
RecordStream rs = new RecordStream(Arrays.asList(recs), 0);
InternalSheet sheet;
try {
sheet = InternalSheet.createSheet(rs);
} catch (RuntimeException e) {
if (e.getMessage().equals("Duplicate PageSettingsBlock record (sid=0x89c)")) {
throw new AssertionFailedError("Identified bug 48026");
}
throw e;
}
RecordCollector rv = new RecordCollector();
sheet.visitContainedRecords(rv, 0);
Record[] outRecs = rv.getRecords();
assertEquals(recs.length, outRecs.length);
//expected order of records:
Record[] expectedRecs = { //BOFRecord
recs[0], //IndexRecord
recs[1], //HeaderRecord
recs[2], //FooterRecord
recs[3], //HeaderFooterRecord
recs[9], // DimensionsRecord
recs[4], // WindowTwoRecord
recs[5], // UserSViewBegin
recs[6], // SelectionRecord
recs[7], // HeaderFooterRecord
recs[10], // UserSViewEnd
recs[8], //EOFRecord
recs[11] };
for (int i = 0; i < expectedRecs.length; i++) {
assertEquals("Record mismatch at index " + i, expectedRecs[i].getClass(), outRecs[i].getClass());
}
HeaderFooterRecord hd1 = (HeaderFooterRecord) expectedRecs[4];
//GUID is zero
assertArrayEquals(new byte[16], hd1.getGuid());
assertTrue(hd1.isCurrentSheet());
UserSViewBegin svb = (UserSViewBegin) expectedRecs[7];
HeaderFooterRecord hd2 = (HeaderFooterRecord) expectedRecs[9];
assertFalse(hd2.isCurrentSheet());
//GUIDs of HeaderFooterRecord and UserSViewBegin must be the same
assertArrayEquals(svb.getGuid(), hd2.getGuid());
}
Aggregations