1 2 17 18 package org.apache.poi.hssf.usermodel; 19 20 import junit.framework.TestCase; 21 import junit.framework.AssertionFailedError; 22 23 import java.util.List ; 24 import java.util.ArrayList ; 25 26 import org.apache.poi.hssf.record.*; 27 28 33 public class TestSanityChecker 34 extends TestCase 35 { 36 public TestSanityChecker( String s ) 37 { 38 super( s ); 39 } 40 41 public void testCheckRecordOrder() 42 throws Exception 43 { 44 final SanityChecker c = new SanityChecker(); 45 List records = new ArrayList (); 46 records.add(new BOFRecord()); 47 records.add(new InterfaceHdrRecord()); 48 records.add(new BoundSheetRecord()); 49 records.add(new EOFRecord()); 50 final SanityChecker.CheckRecord[] check = { 51 new SanityChecker.CheckRecord(BOFRecord.class, '1'), 52 new SanityChecker.CheckRecord(InterfaceHdrRecord.class, '0'), 53 new SanityChecker.CheckRecord(BoundSheetRecord.class, 'M'), 54 new SanityChecker.CheckRecord(NameRecord.class, '*'), 55 new SanityChecker.CheckRecord(EOFRecord.class, '1'), 56 }; 57 c.checkRecordOrder(records, check); 59 records.add(2, new BoundSheetRecord()); 60 c.checkRecordOrder(records, check); 61 records.remove(1); c.checkRecordOrder(records, check); 63 records.add(3, new NameRecord()); 64 records.add(3, new NameRecord()); c.checkRecordOrder(records, check); 66 67 expectFail( new Runnable () { 69 public void run() 70 { 71 List records = new ArrayList (); 73 records.add(new BOFRecord()); 74 records.add(new BoundSheetRecord()); 75 records.add(new InterfaceHdrRecord()); 76 records.add(new EOFRecord()); 77 c.checkRecordOrder(records, check); 78 } 79 }); 80 81 expectFail( new Runnable () { 82 public void run() 83 { 84 List records = new ArrayList (); 86 records.add(new BOFRecord()); 87 records.add(new InterfaceHdrRecord()); 88 records.add(new BoundSheetRecord()); 89 records.add(new InterfaceHdrRecord()); 90 records.add(new EOFRecord()); 91 c.checkRecordOrder(records, check); 92 } 93 }); 94 95 expectFail( new Runnable () { 96 public void run() 97 { 98 List records = new ArrayList (); 100 records.add(new BOFRecord()); 101 records.add(new BoundSheetRecord()); 102 records.add(new NameRecord()); 103 records.add(new EOFRecord()); 104 records.add(new NameRecord()); 105 c.checkRecordOrder(records, check); 106 } 107 }); 108 109 expectFail( new Runnable () { 110 public void run() 111 { 112 List records = new ArrayList (); 114 records.add(new InterfaceHdrRecord()); 115 records.add(new BoundSheetRecord()); 116 records.add(new EOFRecord()); 117 c.checkRecordOrder(records, check); 118 } 119 }); 120 121 expectFail( new Runnable () { 122 public void run() 123 { 124 List records = new ArrayList (); 126 records.add(new BOFRecord()); 127 records.add(new InterfaceHdrRecord()); 128 records.add(new EOFRecord()); 129 c.checkRecordOrder(records, check); 130 } 131 }); 132 133 expectFail( new Runnable () { 134 public void run() 135 { 136 List records = new ArrayList (); 138 records.add(new InterfaceHdrRecord()); 139 records.add(new BoundSheetRecord()); 140 records.add(new BOFRecord()); 141 records.add(new EOFRecord()); 142 c.checkRecordOrder(records, check); 143 } 144 }); 145 146 expectFail( new Runnable () { 147 public void run() 148 { 149 List records = new ArrayList (); 151 records.add(new BOFRecord()); 152 records.add(new BoundSheetRecord()); 153 records.add(new InterfaceHdrRecord()); 154 records.add(new EOFRecord()); 155 c.checkRecordOrder(records, check); 156 } 157 }); 158 159 } 160 161 private void expectFail( Runnable runnable ) 162 { 163 boolean fail = false; 164 try 165 { 166 runnable.run(); 167 fail = true; 168 } 169 catch (AssertionFailedError pass) 170 { 171 } 172 assertTrue(!fail); 173 } 174 175 } 176 177 | Popular Tags |