use of org.apache.poi.hssf.model.RecordStream in project poi by apache.
the class TestCFRecordsAggregate method testCFRecordsAggregate.
public void testCFRecordsAggregate() {
HSSFWorkbook workbook = new HSSFWorkbook();
HSSFSheet sheet = workbook.createSheet();
List<Record> recs = new ArrayList<Record>();
CFHeaderBase header = new CFHeaderRecord();
CFRuleBase rule1 = CFRuleRecord.create(sheet, "7");
CFRuleBase rule2 = CFRuleRecord.create(sheet, ComparisonOperator.BETWEEN, "2", "5");
CFRuleBase rule3 = CFRuleRecord.create(sheet, ComparisonOperator.GE, "100", null);
header.setNumberOfConditionalFormats(3);
CellRangeAddress[] cellRanges = { new CellRangeAddress(0, 1, 0, 0), new CellRangeAddress(0, 1, 2, 2) };
header.setCellRanges(cellRanges);
recs.add(header);
recs.add(rule1);
recs.add(rule2);
recs.add(rule3);
CFRecordsAggregate record = CFRecordsAggregate.createCFAggregate(new RecordStream(recs, 0));
// Serialize
byte[] serializedRecord = new byte[record.getRecordSize()];
record.serialize(0, serializedRecord);
InputStream in = new ByteArrayInputStream(serializedRecord);
//Parse
recs = RecordFactory.createRecords(in);
// Verify
assertNotNull(recs);
assertEquals(4, recs.size());
header = (CFHeaderRecord) recs.get(0);
rule1 = (CFRuleRecord) recs.get(1);
assertNotNull(rule1);
rule2 = (CFRuleRecord) recs.get(2);
assertNotNull(rule2);
rule3 = (CFRuleRecord) recs.get(3);
assertNotNull(rule3);
cellRanges = header.getCellRanges();
assertEquals(2, cellRanges.length);
assertEquals(3, header.getNumberOfConditionalFormats());
assertFalse(header.getNeedRecalculation());
record = CFRecordsAggregate.createCFAggregate(new RecordStream(recs, 0));
record = record.cloneCFAggregate();
assertNotNull(record.getHeader());
assertEquals(3, record.getNumberOfRules());
header = record.getHeader();
rule1 = record.getRule(0);
assertNotNull(rule1);
rule2 = record.getRule(1);
assertNotNull(rule2);
rule3 = record.getRule(2);
assertNotNull(rule3);
cellRanges = header.getCellRanges();
assertEquals(2, cellRanges.length);
assertEquals(3, header.getNumberOfConditionalFormats());
assertFalse(header.getNeedRecalculation());
}
use of org.apache.poi.hssf.model.RecordStream 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.model.RecordStream in project poi by apache.
the class TestMergeCellsRecord method testMCTable_bug46009.
public void testMCTable_bug46009() {
MergedCellsTable mct = new MergedCellsTable();
List<Record> recList = new ArrayList<Record>();
CellRangeAddress[] cras = new CellRangeAddress[] { new CellRangeAddress(0, 0, 0, 3) };
recList.add(new MergeCellsRecord(cras, 0, 1));
RecordStream rs = new RecordStream(recList, 0);
mct.read(rs);
try {
mct.visitContainedRecords(dummyRecordVisitor);
} catch (ArrayStoreException e) {
throw new AssertionFailedError("Identified bug 46009");
}
}
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 TestValueRecordsAggregate method constructValueRecord.
private void constructValueRecord(List<Record> records) {
RowBlocksReader rbr = new RowBlocksReader(new RecordStream(records, 0));
SharedValueManager sfrh = rbr.getSharedFormulaManager();
RecordStream rs = rbr.getPlainRecordStream();
while (rs.hasNext()) {
Record rec = rs.getNext();
valueRecord.construct((CellValueRecordInterface) rec, rs, sfrh);
}
}
Aggregations