Search in sources :

Example 1 with CheckRecord

use of org.apache.poi.hssf.usermodel.SanityChecker.CheckRecord in project poi by apache.

the class TestSanityChecker method testCheckRecordOrder.

@Test
public void testCheckRecordOrder() {
    final SanityChecker c = new SanityChecker();
    List<Record> records = new ArrayList<Record>();
    records.add(new BOFRecord());
    records.add(INTERFACEHDR);
    records.add(createBoundSheetRec());
    records.add(EOFRecord.instance);
    CheckRecord[] check = { new CheckRecord(BOFRecord.class, '1'), new CheckRecord(InterfaceHdrRecord.class, '0'), new CheckRecord(BoundSheetRecord.class, 'M'), new CheckRecord(NameRecord.class, '*'), new CheckRecord(EOFRecord.class, '1') };
    // check pass
    c.checkRecordOrder(records, check);
    records.add(2, createBoundSheetRec());
    c.checkRecordOrder(records, check);
    // optional record missing
    records.remove(1);
    c.checkRecordOrder(records, check);
    records.add(3, new NameRecord());
    // optional multiple record occurs more than one time
    records.add(3, new NameRecord());
    c.checkRecordOrder(records, check);
    // check fail
    confirmBadRecordOrder(check, new Record[] { new BOFRecord(), createBoundSheetRec(), INTERFACEHDR, EOFRecord.instance });
    confirmBadRecordOrder(check, new Record[] { new BOFRecord(), INTERFACEHDR, createBoundSheetRec(), INTERFACEHDR, EOFRecord.instance });
    confirmBadRecordOrder(check, new Record[] { new BOFRecord(), createBoundSheetRec(), new NameRecord(), EOFRecord.instance, new NameRecord() });
    confirmBadRecordOrder(check, new Record[] { INTERFACEHDR, createBoundSheetRec(), EOFRecord.instance });
    confirmBadRecordOrder(check, new Record[] { new BOFRecord(), INTERFACEHDR, EOFRecord.instance });
    confirmBadRecordOrder(check, new Record[] { INTERFACEHDR, createBoundSheetRec(), new BOFRecord(), EOFRecord.instance });
    confirmBadRecordOrder(check, new Record[] { new BOFRecord(), createBoundSheetRec(), INTERFACEHDR, EOFRecord.instance });
}
Also used : CheckRecord(org.apache.poi.hssf.usermodel.SanityChecker.CheckRecord) NameRecord(org.apache.poi.hssf.record.NameRecord) EOFRecord(org.apache.poi.hssf.record.EOFRecord) InterfaceHdrRecord(org.apache.poi.hssf.record.InterfaceHdrRecord) ArrayList(java.util.ArrayList) BoundSheetRecord(org.apache.poi.hssf.record.BoundSheetRecord) InterfaceHdrRecord(org.apache.poi.hssf.record.InterfaceHdrRecord) Record(org.apache.poi.hssf.record.Record) CheckRecord(org.apache.poi.hssf.usermodel.SanityChecker.CheckRecord) BOFRecord(org.apache.poi.hssf.record.BOFRecord) EOFRecord(org.apache.poi.hssf.record.EOFRecord) NameRecord(org.apache.poi.hssf.record.NameRecord) BOFRecord(org.apache.poi.hssf.record.BOFRecord) BoundSheetRecord(org.apache.poi.hssf.record.BoundSheetRecord) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)1 BOFRecord (org.apache.poi.hssf.record.BOFRecord)1 BoundSheetRecord (org.apache.poi.hssf.record.BoundSheetRecord)1 EOFRecord (org.apache.poi.hssf.record.EOFRecord)1 InterfaceHdrRecord (org.apache.poi.hssf.record.InterfaceHdrRecord)1 NameRecord (org.apache.poi.hssf.record.NameRecord)1 Record (org.apache.poi.hssf.record.Record)1 CheckRecord (org.apache.poi.hssf.usermodel.SanityChecker.CheckRecord)1 Test (org.junit.Test)1