use of org.apache.poi.hssf.record.Record in project poi by apache.
the class TestEventRecordFactory method testCreateRecord.
/**
* tests that the create record function returns a properly
* constructed record in the simple case.
*/
public void testCreateRecord() {
BOFRecord bof = new BOFRecord();
bof.setBuild((short) 0);
bof.setBuildYear((short) 1999);
bof.setRequiredVersion(123);
bof.setType(BOFRecord.TYPE_WORKBOOK);
bof.setVersion((short) 0x06);
bof.setHistoryBitMask(BOFRecord.HISTORY_MASK);
byte[] bytes = bof.serialize();
Record[] records = RecordFactory.createRecord(TestcaseRecordInputStream.create(bytes));
assertTrue("record.length must be 1, was =" + records.length, records.length == 1);
assertTrue("record is the same", compareRec(bof, records[0]));
}
use of org.apache.poi.hssf.record.Record in project poi by apache.
the class TestHSSFEventFactory method testWithMissingRecords.
public void testWithMissingRecords() throws Exception {
HSSFRequest req = new HSSFRequest();
MockHSSFListener mockListen = new MockHSSFListener();
req.addListenerForAllRecords(mockListen);
POIFSFileSystem fs = new POIFSFileSystem(openSample("SimpleWithSkip.xls"));
HSSFEventFactory factory = new HSSFEventFactory();
factory.processWorkbookEvents(req, fs);
Record[] recs = mockListen.getRecords();
// Check we got the records
assertTrue(recs.length > 100);
// Check that the last few records are as we expect
// (Makes sure we don't accidently skip the end ones)
int numRec = recs.length;
assertEquals(WindowTwoRecord.class, recs[numRec - 3].getClass());
assertEquals(SelectionRecord.class, recs[numRec - 2].getClass());
assertEquals(EOFRecord.class, recs[numRec - 1].getClass());
}
use of org.apache.poi.hssf.record.Record in project poi by apache.
the class TestHSSFEventFactory method testWithPasswordProtectedWorkbooks.
public void testWithPasswordProtectedWorkbooks() throws Exception {
HSSFRequest req = new HSSFRequest();
MockHSSFListener mockListen = new MockHSSFListener();
req.addListenerForAllRecords(mockListen);
// Without a password, can't be read
Biff8EncryptionKey.setCurrentUserPassword(null);
POIFSFileSystem fs = new POIFSFileSystem(openSample("xor-encryption-abc.xls"));
HSSFEventFactory factory = new HSSFEventFactory();
try {
factory.processWorkbookEvents(req, fs);
fail("Shouldn't be able to process protected workbook without the password");
} catch (EncryptedDocumentException e) {
}
// With the password, is properly processed
Biff8EncryptionKey.setCurrentUserPassword("abc");
req = new HSSFRequest();
mockListen = new MockHSSFListener();
req.addListenerForAllRecords(mockListen);
factory.processWorkbookEvents(req, fs);
// Check we got the sheet and the contents
Record[] recs = mockListen.getRecords();
assertTrue(recs.length > 50);
// Has one sheet, with values 1,2,3 in column A rows 1-3
boolean hasSheet = false, hasA1 = false, hasA2 = false, hasA3 = false;
for (Record r : recs) {
if (r instanceof BoundSheetRecord) {
BoundSheetRecord bsr = (BoundSheetRecord) r;
assertEquals("Sheet1", bsr.getSheetname());
hasSheet = true;
}
if (r instanceof NumberRecord) {
NumberRecord nr = (NumberRecord) r;
if (nr.getColumn() == 0 && nr.getRow() == 0) {
assertEquals(1, (int) nr.getValue());
hasA1 = true;
}
if (nr.getColumn() == 0 && nr.getRow() == 1) {
assertEquals(2, (int) nr.getValue());
hasA2 = true;
}
if (nr.getColumn() == 0 && nr.getRow() == 2) {
assertEquals(3, (int) nr.getValue());
hasA3 = true;
}
}
}
assertTrue("Sheet record not found", hasSheet);
assertTrue("Numeric record for A1 not found", hasA1);
assertTrue("Numeric record for A2 not found", hasA2);
assertTrue("Numeric record for A3 not found", hasA3);
}
use of org.apache.poi.hssf.record.Record in project poi by apache.
the class TestMissingRecordAwareHSSFListener method testEndOfRow_bug45672.
/**
* Make sure that the presence of shared formulas does not cause extra
* end-of-row records.
*/
public void testEndOfRow_bug45672() {
readRecords("ex45672.xls");
Record[] rr = r;
int eorCount = 0;
int sfrCount = 0;
for (Record record : rr) {
if (record instanceof SharedFormulaRecord) {
sfrCount++;
}
if (record instanceof LastCellOfRowDummyRecord) {
eorCount++;
}
}
if (eorCount == 2) {
throw new AssertionFailedError("Identified bug 45672");
}
assertEquals(1, eorCount);
assertEquals(1, sfrCount);
}
use of org.apache.poi.hssf.record.Record in project poi by apache.
the class TestMissingRecordAwareHSSFListener method testStringRecordHandling.
public void testStringRecordHandling() {
readRecords("53588.xls");
Record[] rr = r;
int missingCount = 0;
int lastCount = 0;
for (Record record : rr) {
if (record instanceof MissingCellDummyRecord) {
missingCount++;
}
if (record instanceof LastCellOfRowDummyRecord) {
lastCount++;
}
}
assertEquals(1, missingCount);
assertEquals(1, lastCount);
}
Aggregations