use of org.apache.poi.hssf.record.Record in project poi by apache.
the class TestValueRecordsAggregate method confirmMulBlank.
private void confirmMulBlank(int expectedTotalBlankCells, int expectedNumberOfMulBlankRecords, int expectedNumberOfSingleBlankRecords) {
// assumed row ranges set-up by caller:
final int firstRow = 1;
final int lastRow = 2;
final class BlankStats {
public int countBlankCells;
public int countMulBlankRecords;
public int countSingleBlankRecords;
}
final BlankStats bs = new BlankStats();
RecordVisitor rv = new RecordVisitor() {
@Override
public void visitRecord(Record r) {
if (r instanceof MulBlankRecord) {
MulBlankRecord mbr = (MulBlankRecord) r;
bs.countMulBlankRecords++;
bs.countBlankCells += mbr.getNumColumns();
} else if (r instanceof BlankRecord) {
bs.countSingleBlankRecords++;
bs.countBlankCells++;
}
}
};
for (int rowIx = firstRow; rowIx <= lastRow; rowIx++) {
if (valueRecord.rowHasCells(rowIx)) {
valueRecord.visitCellsForRow(rowIx, rv);
}
}
assertEquals(expectedTotalBlankCells, bs.countBlankCells);
assertEquals(expectedNumberOfMulBlankRecords, bs.countMulBlankRecords);
assertEquals(expectedNumberOfSingleBlankRecords, bs.countSingleBlankRecords);
}
use of org.apache.poi.hssf.record.Record in project poi by apache.
the class TestRowRecordsAggregate method verifySharedValues.
private static int verifySharedValues(Record[] recs, Class<? extends SharedValueRecordBase> shfClass) {
int result = 0;
for (int i = 0; i < recs.length; i++) {
Record rec = recs[i];
if (rec.getClass() == shfClass) {
result++;
Record prevRec = recs[i - 1];
if (!(prevRec instanceof FormulaRecord)) {
fail("Bad record order at index " + i + ": Formula record expected but got (" + prevRec.getClass().getName() + ")");
}
verifySharedFormula((FormulaRecord) prevRec, rec);
}
}
return result;
}
use of org.apache.poi.hssf.record.Record 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.record.Record in project poi by apache.
the class TestSharedValueManager method testPartiallyOverlappingRanges.
/**
* This bug happened when there were two or more shared formula ranges that overlapped. POI
* would sometimes associate formulas in the overlapping region with the wrong shared formula
*/
public void testPartiallyOverlappingRanges() {
Record[] records;
int attempt = 1;
do {
HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook(SAMPLE_FILE_NAME);
HSSFSheet sheet = wb.getSheetAt(0);
RecordInspector.getRecords(sheet, 0);
assertEquals("1+1", sheet.getRow(2).getCell(0).getCellFormula());
if ("1+1".equals(sheet.getRow(3).getCell(0).getCellFormula())) {
throw new AssertionFailedError("Identified bug - wrong shared formula record chosen" + " (attempt " + attempt + ")");
}
assertEquals("2+2", sheet.getRow(3).getCell(0).getCellFormula());
records = RecordInspector.getRecords(sheet, 0);
} while (attempt++ < MAX_ATTEMPTS);
int count = 0;
for (Record record : records) {
if (record instanceof SharedFormulaRecord) {
count++;
}
}
assertEquals(2, count);
}
use of org.apache.poi.hssf.record.Record in project poi by apache.
the class TestBugs method bug51675.
@Test
public void bug51675() throws Exception {
final List<Short> list = new ArrayList<Short>();
HSSFWorkbook wb = openSample("51675.xls");
HSSFSheet sh = wb.getSheetAt(0);
InternalSheet ish = HSSFTestHelper.getSheetForTest(sh);
PageSettingsBlock psb = (PageSettingsBlock) ish.getRecords().get(13);
psb.visitContainedRecords(new RecordAggregate.RecordVisitor() {
@Override
public void visitRecord(Record r) {
list.add(r.getSid());
}
});
assertEquals(UnknownRecord.BITMAP_00E9, list.get(list.size() - 1).intValue());
assertEquals(UnknownRecord.HEADER_FOOTER_089C, list.get(list.size() - 2).intValue());
wb.close();
}
Aggregations