use of org.apache.poi.hssf.record.RecordBase in project poi by apache.
the class TestReadWriteChart method testBOFandEOFRecords.
/**
* In the presence of a chart we need to make sure BOF/EOF records still exist.
*/
@Test
public void testBOFandEOFRecords() throws Exception {
HSSFWorkbook workbook = HSSFTestDataSamples.openSampleWorkbook("SimpleChart.xls");
HSSFSheet sheet = workbook.getSheetAt(0);
HSSFRow firstRow = sheet.getRow(0);
HSSFCell firstCell = firstRow.getCell(0);
//System.out.println("first assertion for date");
Calendar calExp = LocaleUtil.getLocaleCalendar(2000, 0, 1, 10, 51, 2);
Date dateAct = HSSFDateUtil.getJavaDate(firstCell.getNumericCellValue(), false);
assertEquals(calExp.getTime(), dateAct);
HSSFRow row = sheet.createRow(15);
HSSFCell cell = row.createCell(1);
cell.setCellValue(22);
InternalSheet newSheet = workbook.getSheetAt(0).getSheet();
List<RecordBase> records = newSheet.getRecords();
assertTrue(records.get(0) instanceof BOFRecord);
assertTrue(records.get(records.size() - 1) instanceof EOFRecord);
workbook.close();
}
use of org.apache.poi.hssf.record.RecordBase in project poi by apache.
the class TestSheet method testShiftFormulasAddCondFormat_bug46547.
/**
* Prior to the fix for bug 46547, shifting formulas would have the side-effect
* of creating a {@link ConditionalFormattingTable}. There was no impairment to
* functionality since empty record aggregates are equivalent to missing record
* aggregates. However, since this unnecessary creation helped expose bug 46547b,
* and since there is a slight performance hit the fix was made to avoid it.
*/
@Test
public void testShiftFormulasAddCondFormat_bug46547() {
// Create a sheet with data validity (similar to bugzilla attachment id=23131).
InternalSheet sheet = InternalSheet.createSheet();
List<RecordBase> sheetRecs = sheet.getRecords();
assertEquals(23, sheetRecs.size());
FormulaShifter shifter = FormulaShifter.createForRowShift(0, "", 0, 0, 1, SpreadsheetVersion.EXCEL97);
sheet.updateFormulasAfterCellShift(shifter, 0);
if (sheetRecs.size() == 24 && sheetRecs.get(22) instanceof ConditionalFormattingTable) {
throw new AssertionFailedError("Identified bug 46547a");
}
assertEquals(23, sheetRecs.size());
}
use of org.apache.poi.hssf.record.RecordBase in project poi by apache.
the class TestEscherRecordFactory method testDgContainerMustBeRootOfHSSFSheetEscherRecords.
public void testDgContainerMustBeRootOfHSSFSheetEscherRecords() throws IOException {
HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("47251.xls");
HSSFSheet sh = wb.getSheetAt(0);
InternalSheet ish = HSSFTestHelper.getSheetForTest(sh);
List<RecordBase> records = ish.getRecords();
// records to be aggregated
List<RecordBase> dgRecords = records.subList(19, 23);
byte[] dgBytes = toByteArray(dgRecords);
sh.getDrawingPatriarch();
EscherAggregate agg = (EscherAggregate) ish.findFirstRecordBySid(EscherAggregate.sid);
assertEquals(true, agg.getEscherRecords().get(0) instanceof EscherContainerRecord);
assertEquals(EscherContainerRecord.DG_CONTAINER, agg.getEscherRecords().get(0).getRecordId());
assertEquals((short) 0x0, agg.getEscherRecords().get(0).getOptions());
agg = (EscherAggregate) ish.findFirstRecordBySid(EscherAggregate.sid);
byte[] dgBytesAfterSave = agg.serialize();
assertEquals("different size of drawing data before and after save", dgBytes.length, dgBytesAfterSave.length);
assertTrue("drawing data before and after save is different", Arrays.equals(dgBytes, dgBytesAfterSave));
}
use of org.apache.poi.hssf.record.RecordBase in project poi by apache.
the class TestSheet method testGutsRecord_bug45640.
/**
* Checks for bug introduced around r682282-r683880 that caused a second GUTS records
* which in turn got the dimensions record out of alignment
*/
@Test
public void testGutsRecord_bug45640() {
InternalSheet sheet = InternalSheet.createSheet();
sheet.addRow(new RowRecord(0));
sheet.addRow(new RowRecord(1));
sheet.groupRowRange(0, 1, true);
sheet.toString();
List<RecordBase> recs = sheet.getRecords();
int count = 0;
for (int i = 0; i < recs.size(); i++) {
if (recs.get(i) instanceof GutsRecord) {
count++;
}
}
if (count == 2) {
throw new AssertionFailedError("Identified bug 45640");
}
assertEquals(1, count);
}
Aggregations