Search in sources :

Example 1 with UnknownRecord

use of org.apache.poi.hssf.record.UnknownRecord 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);
}
Also used : RecordStream(org.apache.poi.hssf.model.RecordStream) RecordCollector(org.apache.poi.hssf.usermodel.RecordInspector.RecordCollector) RowRecord(org.apache.poi.hssf.record.RowRecord) UnknownRecord(org.apache.poi.hssf.record.UnknownRecord) ContinueRecord(org.apache.poi.hssf.record.ContinueRecord) Record(org.apache.poi.hssf.record.Record) NumberRecord(org.apache.poi.hssf.record.NumberRecord) UnknownRecord(org.apache.poi.hssf.record.UnknownRecord) ArrayRecord(org.apache.poi.hssf.record.ArrayRecord) ContinueRecord(org.apache.poi.hssf.record.ContinueRecord) TableRecord(org.apache.poi.hssf.record.TableRecord) RowRecord(org.apache.poi.hssf.record.RowRecord) SharedFormulaRecord(org.apache.poi.hssf.record.SharedFormulaRecord) FormulaRecord(org.apache.poi.hssf.record.FormulaRecord) NumberRecord(org.apache.poi.hssf.record.NumberRecord) Test(org.junit.Test)

Example 2 with UnknownRecord

use of org.apache.poi.hssf.record.UnknownRecord in project poi by apache.

the class TestRowBlocksReader method testAbnormalPivotTableRecords_bug46280.

@Test
public void testAbnormalPivotTableRecords_bug46280() {
    int SXVIEW_SID = ViewDefinitionRecord.sid;
    Record[] inRecs = { new RowRecord(0), new NumberRecord(), // normally MSODRAWING(0x00EC) would come here before SXVIEW
    new UnknownRecord(SXVIEW_SID, "dummydata (SXVIEW: View Definition)".getBytes(LocaleUtil.CHARSET_1252)), new WindowTwoRecord() };
    RecordStream rs = new RecordStream(Arrays.asList(inRecs), 0);
    RowBlocksReader rbr = new RowBlocksReader(rs);
    if (rs.peekNextClass() == WindowTwoRecord.class) {
        // Should have stopped at the SXVIEW record
        fail("Identified bug 46280b");
    }
    RecordStream rbStream = rbr.getPlainRecordStream();
    assertEquals(inRecs[0], rbStream.getNext());
    assertEquals(inRecs[1], rbStream.getNext());
    assertFalse(rbStream.hasNext());
    assertTrue(rs.hasNext());
    assertEquals(inRecs[2], rs.getNext());
    assertEquals(inRecs[3], rs.getNext());
}
Also used : RowRecord(org.apache.poi.hssf.record.RowRecord) UnknownRecord(org.apache.poi.hssf.record.UnknownRecord) Record(org.apache.poi.hssf.record.Record) NumberRecord(org.apache.poi.hssf.record.NumberRecord) UnknownRecord(org.apache.poi.hssf.record.UnknownRecord) ViewDefinitionRecord(org.apache.poi.hssf.record.pivottable.ViewDefinitionRecord) RowRecord(org.apache.poi.hssf.record.RowRecord) WindowTwoRecord(org.apache.poi.hssf.record.WindowTwoRecord) WindowTwoRecord(org.apache.poi.hssf.record.WindowTwoRecord) NumberRecord(org.apache.poi.hssf.record.NumberRecord) Test(org.junit.Test)

Example 3 with UnknownRecord

use of org.apache.poi.hssf.record.UnknownRecord in project poi by apache.

the class HSSFWorkbook method insertChartRecord.

/** Test only. Do not use */
public void insertChartRecord() {
    int loc = workbook.findFirstRecordLocBySid(SSTRecord.sid);
    byte[] data = { (byte) 0x0F, (byte) 0x00, (byte) 0x00, (byte) 0xF0, (byte) 0x52, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x06, (byte) 0xF0, (byte) 0x18, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01, (byte) 0x08, (byte) 0x00, (byte) 0x00, (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x03, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x33, (byte) 0x00, (byte) 0x0B, (byte) 0xF0, (byte) 0x12, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0xBF, (byte) 0x00, (byte) 0x08, (byte) 0x00, (byte) 0x08, (byte) 0x00, (byte) 0x81, (byte) 0x01, (byte) 0x09, (byte) 0x00, (byte) 0x00, (byte) 0x08, (byte) 0xC0, (byte) 0x01, (byte) 0x40, (byte) 0x00, (byte) 0x00, (byte) 0x08, (byte) 0x40, (byte) 0x00, (byte) 0x1E, (byte) 0xF1, (byte) 0x10, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x0D, (byte) 0x00, (byte) 0x00, (byte) 0x08, (byte) 0x0C, (byte) 0x00, (byte) 0x00, (byte) 0x08, (byte) 0x17, (byte) 0x00, (byte) 0x00, (byte) 0x08, (byte) 0xF7, (byte) 0x00, (byte) 0x00, (byte) 0x10 };
    UnknownRecord r = new UnknownRecord((short) 0x00EB, data);
    workbook.getRecords().add(loc, r);
}
Also used : UnknownRecord(org.apache.poi.hssf.record.UnknownRecord)

Aggregations

UnknownRecord (org.apache.poi.hssf.record.UnknownRecord)3 NumberRecord (org.apache.poi.hssf.record.NumberRecord)2 Record (org.apache.poi.hssf.record.Record)2 RowRecord (org.apache.poi.hssf.record.RowRecord)2 Test (org.junit.Test)2 RecordStream (org.apache.poi.hssf.model.RecordStream)1 ArrayRecord (org.apache.poi.hssf.record.ArrayRecord)1 ContinueRecord (org.apache.poi.hssf.record.ContinueRecord)1 FormulaRecord (org.apache.poi.hssf.record.FormulaRecord)1 SharedFormulaRecord (org.apache.poi.hssf.record.SharedFormulaRecord)1 TableRecord (org.apache.poi.hssf.record.TableRecord)1 WindowTwoRecord (org.apache.poi.hssf.record.WindowTwoRecord)1 ViewDefinitionRecord (org.apache.poi.hssf.record.pivottable.ViewDefinitionRecord)1 RecordCollector (org.apache.poi.hssf.usermodel.RecordInspector.RecordCollector)1