use of org.apache.poi.hssf.usermodel.RecordInspector.RecordCollector 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());
}
use of org.apache.poi.hssf.usermodel.RecordInspector.RecordCollector in project poi by apache.
the class TestPageSettingsBlock method testLateMargins_bug47199.
/**
* Bug 47199 was due to the margin records being located well after the initial PSB records.
* The example file supplied (attachment 23710) had three non-PSB record types
* between the PRINTSETUP record and first MARGIN record:
* <ul>
* <li>PRINTSETUP(0x00A1)</li>
* <li>DEFAULTCOLWIDTH(0x0055)</li>
* <li>COLINFO(0x007D)</li>
* <li>DIMENSIONS(0x0200)</li>
* <li>BottomMargin(0x0029)</li>
* </ul>
*/
public void testLateMargins_bug47199() {
Record[] recs = { BOFRecord.createSheetBOF(), new HeaderRecord("&LSales Figures"), new FooterRecord("&LJanuary"), new DimensionsRecord(), createBottomMargin(0.787F), new WindowTwoRecord(), EOFRecord.instance };
RecordStream rs = new RecordStream(Arrays.asList(recs), 0);
InternalSheet sheet;
try {
sheet = InternalSheet.createSheet(rs);
} catch (RuntimeException e) {
if (e.getMessage().equals("two Page Settings Blocks found in the same sheet")) {
throw new AssertionFailedError("Identified bug 47199a - failed to process late margings records");
}
throw e;
}
RecordCollector rv = new RecordCollector();
sheet.visitContainedRecords(rv, 0);
Record[] outRecs = rv.getRecords();
// +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(DimensionsRecord.class, outRecs[5].getClass());
assertEquals(WindowTwoRecord.class, outRecs[6].getClass());
assertEquals(EOFRecord.instance, outRecs[7]);
}
use of org.apache.poi.hssf.usermodel.RecordInspector.RecordCollector in project poi by apache.
the class TestHSSFSheet method protectSheetRecordOrder_bug47363a.
/**
* {@link PasswordRecord} belongs with the rest of the Worksheet Protection Block
* (which should be before {@link DimensionsRecord}).
*/
@Test
public void protectSheetRecordOrder_bug47363a() throws IOException {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet s = wb.createSheet();
s.protectSheet("secret");
RecordCollector rc = new RecordCollector();
s.getSheet().visitContainedRecords(rc, 0);
Record[] recs = rc.getRecords();
int nRecs = recs.length;
if (recs[nRecs - 2] instanceof PasswordRecord && recs[nRecs - 5] instanceof DimensionsRecord) {
fail("Identified bug 47363a - PASSWORD after DIMENSION");
}
// Check that protection block is together, and before DIMENSION
confirmRecordClass(recs, nRecs - 4, DimensionsRecord.class);
confirmRecordClass(recs, nRecs - 9, ProtectRecord.class);
confirmRecordClass(recs, nRecs - 8, ObjectProtectRecord.class);
confirmRecordClass(recs, nRecs - 7, ScenarioProtectRecord.class);
confirmRecordClass(recs, nRecs - 6, PasswordRecord.class);
wb.close();
}
use of org.apache.poi.hssf.usermodel.RecordInspector.RecordCollector in project poi by apache.
the class TestHSSFSheet method dvProtectionOrder_bug47363b.
/**
* There should be no problem with adding data validations after sheet protection
*/
@Test
public void dvProtectionOrder_bug47363b() throws IOException {
HSSFWorkbook workbook = new HSSFWorkbook();
HSSFSheet sheet = workbook.createSheet("Sheet1");
sheet.protectSheet("secret");
DataValidationHelper dataValidationHelper = sheet.getDataValidationHelper();
DataValidationConstraint dvc = dataValidationHelper.createIntegerConstraint(DataValidationConstraint.OperatorType.BETWEEN, "10", "100");
CellRangeAddressList numericCellAddressList = new CellRangeAddressList(0, 0, 1, 1);
DataValidation dv = dataValidationHelper.createValidation(dvc, numericCellAddressList);
try {
sheet.addValidationData(dv);
} catch (IllegalStateException e) {
String expMsg = "Unexpected (org.apache.poi.hssf.record.PasswordRecord) while looking for DV Table insert pos";
if (expMsg.equals(e.getMessage())) {
fail("Identified bug 47363b");
}
workbook.close();
throw e;
}
RecordCollector rc;
rc = new RecordCollector();
sheet.getSheet().visitContainedRecords(rc, 0);
int nRecsWithProtection = rc.getRecords().length;
sheet.protectSheet(null);
rc = new RecordCollector();
sheet.getSheet().visitContainedRecords(rc, 0);
int nRecsWithoutProtection = rc.getRecords().length;
assertEquals(4, nRecsWithProtection - nRecsWithoutProtection);
workbook.close();
}
use of org.apache.poi.hssf.usermodel.RecordInspector.RecordCollector 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);
}
Aggregations