Fix inconsistent indents
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1675690 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
bcf825883a
commit
3eb0a69666
@ -36,99 +36,99 @@ import org.apache.poi.hssf.record.SelectionRecord;
|
|||||||
import org.apache.poi.hssf.record.WindowTwoRecord;
|
import org.apache.poi.hssf.record.WindowTwoRecord;
|
||||||
import org.apache.poi.hssf.record.crypto.Biff8EncryptionKey;
|
import org.apache.poi.hssf.record.crypto.Biff8EncryptionKey;
|
||||||
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
|
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Testing for {@link HSSFEventFactory}
|
||||||
*/
|
*/
|
||||||
public final class TestHSSFEventFactory extends TestCase {
|
public final class TestHSSFEventFactory extends TestCase {
|
||||||
|
private static final InputStream openSample(String sampleFileName) {
|
||||||
private static final InputStream openSample(String sampleFileName) {
|
return HSSFTestDataSamples.openSampleFileStream(sampleFileName);
|
||||||
return HSSFTestDataSamples.openSampleFileStream(sampleFileName);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public void testWithMissingRecords() throws Exception {
|
public void testWithMissingRecords() throws Exception {
|
||||||
|
|
||||||
HSSFRequest req = new HSSFRequest();
|
HSSFRequest req = new HSSFRequest();
|
||||||
MockHSSFListener mockListen = new MockHSSFListener();
|
MockHSSFListener mockListen = new MockHSSFListener();
|
||||||
req.addListenerForAllRecords(mockListen);
|
req.addListenerForAllRecords(mockListen);
|
||||||
|
|
||||||
POIFSFileSystem fs = new POIFSFileSystem(openSample("SimpleWithSkip.xls"));
|
|
||||||
HSSFEventFactory factory = new HSSFEventFactory();
|
|
||||||
factory.processWorkbookEvents(req, fs);
|
|
||||||
|
|
||||||
Record[] recs = mockListen.getRecords();
|
POIFSFileSystem fs = new POIFSFileSystem(openSample("SimpleWithSkip.xls"));
|
||||||
// Check we got the records
|
HSSFEventFactory factory = new HSSFEventFactory();
|
||||||
assertTrue( recs.length > 100 );
|
factory.processWorkbookEvents(req, fs);
|
||||||
|
|
||||||
// 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());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testWithCrazyContinueRecords() throws Exception {
|
Record[] recs = mockListen.getRecords();
|
||||||
// Some files have crazy ordering of their continue records
|
// Check we got the records
|
||||||
// Check that we don't break on them (bug #42844)
|
assertTrue( recs.length > 100 );
|
||||||
|
|
||||||
HSSFRequest req = new HSSFRequest();
|
|
||||||
MockHSSFListener mockListen = new MockHSSFListener();
|
|
||||||
req.addListenerForAllRecords(mockListen);
|
|
||||||
|
|
||||||
POIFSFileSystem fs = new POIFSFileSystem(openSample("ContinueRecordProblem.xls"));
|
|
||||||
HSSFEventFactory factory = new HSSFEventFactory();
|
|
||||||
factory.processWorkbookEvents(req, fs);
|
|
||||||
|
|
||||||
Record[] recs = mockListen.getRecords();
|
// Check that the last few records are as we expect
|
||||||
// Check we got the records
|
// (Makes sure we don't accidently skip the end ones)
|
||||||
assertTrue( recs.length > 100 );
|
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());
|
||||||
|
}
|
||||||
|
|
||||||
// And none of them are continue ones
|
public void testWithCrazyContinueRecords() throws Exception {
|
||||||
for(int i=0; i<recs.length; i++) {
|
// Some files have crazy ordering of their continue records
|
||||||
assertFalse( recs[i] instanceof ContinueRecord );
|
// Check that we don't break on them (bug #42844)
|
||||||
}
|
|
||||||
|
|
||||||
// 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(DVALRecord.class, recs[numRec-4].getClass());
|
|
||||||
assertEquals(DVRecord.class, recs[numRec-3].getClass());
|
|
||||||
assertEquals(FeatHdrRecord.class, recs[numRec-2].getClass());
|
|
||||||
assertEquals(EOFRecord.class, recs[numRec-1].getClass());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
HSSFRequest req = new HSSFRequest();
|
||||||
* Unknown records can be continued.
|
MockHSSFListener mockListen = new MockHSSFListener();
|
||||||
* Check that HSSFEventFactory doesn't break on them.
|
req.addListenerForAllRecords(mockListen);
|
||||||
* (the test file was provided in a reopen of bug #42844)
|
|
||||||
*/
|
|
||||||
public void testUnknownContinueRecords() throws Exception {
|
|
||||||
|
|
||||||
HSSFRequest req = new HSSFRequest();
|
POIFSFileSystem fs = new POIFSFileSystem(openSample("ContinueRecordProblem.xls"));
|
||||||
MockHSSFListener mockListen = new MockHSSFListener();
|
HSSFEventFactory factory = new HSSFEventFactory();
|
||||||
req.addListenerForAllRecords(mockListen);
|
factory.processWorkbookEvents(req, fs);
|
||||||
|
|
||||||
POIFSFileSystem fs = new POIFSFileSystem(openSample("42844.xls"));
|
Record[] recs = mockListen.getRecords();
|
||||||
HSSFEventFactory factory = new HSSFEventFactory();
|
// Check we got the records
|
||||||
factory.processWorkbookEvents(req, fs);
|
assertTrue( recs.length > 100 );
|
||||||
}
|
|
||||||
|
|
||||||
private static class MockHSSFListener implements HSSFListener {
|
// And none of them are continue ones
|
||||||
private final List<Record> records = new ArrayList<Record>();
|
for(int i=0; i<recs.length; i++) {
|
||||||
|
assertFalse( recs[i] instanceof ContinueRecord );
|
||||||
|
}
|
||||||
|
|
||||||
public MockHSSFListener() {}
|
// Check that the last few records are as we expect
|
||||||
public Record[] getRecords() {
|
// (Makes sure we don't accidently skip the end ones)
|
||||||
Record[] result = new Record[records.size()];
|
int numRec = recs.length;
|
||||||
records.toArray(result);
|
assertEquals(DVALRecord.class, recs[numRec-4].getClass());
|
||||||
return result;
|
assertEquals(DVRecord.class, recs[numRec-3].getClass());
|
||||||
}
|
assertEquals(FeatHdrRecord.class, recs[numRec-2].getClass());
|
||||||
|
assertEquals(EOFRecord.class, recs[numRec-1].getClass());
|
||||||
|
}
|
||||||
|
|
||||||
public void processRecord(Record record) {
|
/**
|
||||||
records.add(record);
|
* Unknown records can be continued.
|
||||||
}
|
* Check that HSSFEventFactory doesn't break on them.
|
||||||
}
|
* (the test file was provided in a reopen of bug #42844)
|
||||||
|
*/
|
||||||
|
public void testUnknownContinueRecords() throws Exception {
|
||||||
|
|
||||||
public void testWithDifferentWorkbookName() throws Exception {
|
HSSFRequest req = new HSSFRequest();
|
||||||
|
MockHSSFListener mockListen = new MockHSSFListener();
|
||||||
|
req.addListenerForAllRecords(mockListen);
|
||||||
|
|
||||||
|
POIFSFileSystem fs = new POIFSFileSystem(openSample("42844.xls"));
|
||||||
|
HSSFEventFactory factory = new HSSFEventFactory();
|
||||||
|
factory.processWorkbookEvents(req, fs);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class MockHSSFListener implements HSSFListener {
|
||||||
|
private final List<Record> records = new ArrayList<Record>();
|
||||||
|
|
||||||
|
public MockHSSFListener() {}
|
||||||
|
public Record[] getRecords() {
|
||||||
|
Record[] result = new Record[records.size()];
|
||||||
|
records.toArray(result);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void processRecord(Record record) {
|
||||||
|
records.add(record);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testWithDifferentWorkbookName() throws Exception {
|
||||||
HSSFRequest req = new HSSFRequest();
|
HSSFRequest req = new HSSFRequest();
|
||||||
MockHSSFListener mockListen = new MockHSSFListener();
|
MockHSSFListener mockListen = new MockHSSFListener();
|
||||||
req.addListenerForAllRecords(mockListen);
|
req.addListenerForAllRecords(mockListen);
|
||||||
@ -140,14 +140,14 @@ public final class TestHSSFEventFactory extends TestCase {
|
|||||||
fs = new POIFSFileSystem(openSample("WORKBOOK_in_capitals.xls"));
|
fs = new POIFSFileSystem(openSample("WORKBOOK_in_capitals.xls"));
|
||||||
factory = new HSSFEventFactory();
|
factory = new HSSFEventFactory();
|
||||||
factory.processWorkbookEvents(req, fs);
|
factory.processWorkbookEvents(req, fs);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testWithPasswordProtectedWorkbooks() throws Exception {
|
public void testWithPasswordProtectedWorkbooks() throws Exception {
|
||||||
HSSFRequest req = new HSSFRequest();
|
HSSFRequest req = new HSSFRequest();
|
||||||
MockHSSFListener mockListen = new MockHSSFListener();
|
MockHSSFListener mockListen = new MockHSSFListener();
|
||||||
req.addListenerForAllRecords(mockListen);
|
req.addListenerForAllRecords(mockListen);
|
||||||
|
|
||||||
// Without a password, can't be read
|
// Without a password, can't be read
|
||||||
Biff8EncryptionKey.setCurrentUserPassword(null);
|
Biff8EncryptionKey.setCurrentUserPassword(null);
|
||||||
POIFSFileSystem fs = new POIFSFileSystem(openSample("xor-encryption-abc.xls"));
|
POIFSFileSystem fs = new POIFSFileSystem(openSample("xor-encryption-abc.xls"));
|
||||||
|
|
||||||
@ -156,20 +156,20 @@ public final class TestHSSFEventFactory extends TestCase {
|
|||||||
factory.processWorkbookEvents(req, fs);
|
factory.processWorkbookEvents(req, fs);
|
||||||
fail("Shouldn't be able to process protected workbook without the password");
|
fail("Shouldn't be able to process protected workbook without the password");
|
||||||
} catch (EncryptedDocumentException e) {}
|
} catch (EncryptedDocumentException e) {}
|
||||||
|
|
||||||
|
|
||||||
// With the password, is properly processed
|
// With the password, is properly processed
|
||||||
Biff8EncryptionKey.setCurrentUserPassword("abc");
|
Biff8EncryptionKey.setCurrentUserPassword("abc");
|
||||||
|
|
||||||
req = new HSSFRequest();
|
req = new HSSFRequest();
|
||||||
mockListen = new MockHSSFListener();
|
mockListen = new MockHSSFListener();
|
||||||
req.addListenerForAllRecords(mockListen);
|
req.addListenerForAllRecords(mockListen);
|
||||||
factory.processWorkbookEvents(req, fs);
|
factory.processWorkbookEvents(req, fs);
|
||||||
|
|
||||||
// Check we got the sheet and the contents
|
// Check we got the sheet and the contents
|
||||||
Record[] recs = mockListen.getRecords();
|
Record[] recs = mockListen.getRecords();
|
||||||
assertTrue( recs.length > 50 );
|
assertTrue( recs.length > 50 );
|
||||||
|
|
||||||
// Has one sheet, with values 1,2,3 in column A rows 1-3
|
// Has one sheet, with values 1,2,3 in column A rows 1-3
|
||||||
boolean hasSheet=false, hasA1=false, hasA2=false, hasA3=false;
|
boolean hasSheet=false, hasA1=false, hasA2=false, hasA3=false;
|
||||||
for (Record r : recs) {
|
for (Record r : recs) {
|
||||||
@ -194,10 +194,10 @@ public final class TestHSSFEventFactory extends TestCase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
assertTrue("Sheet record not found", hasSheet);
|
assertTrue("Sheet record not found", hasSheet);
|
||||||
assertTrue("Numeric record for A1 not found", hasA1);
|
assertTrue("Numeric record for A1 not found", hasA1);
|
||||||
assertTrue("Numeric record for A2 not found", hasA2);
|
assertTrue("Numeric record for A2 not found", hasA2);
|
||||||
assertTrue("Numeric record for A3 not found", hasA3);
|
assertTrue("Numeric record for A3 not found", hasA3);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user