]> source.dussan.org Git - poi.git/commitdiff
a few performance fixes to speed-up the tests
authorAndreas Beeker <kiwiwings@apache.org>
Thu, 30 Jun 2016 22:59:46 +0000 (22:59 +0000)
committerAndreas Beeker <kiwiwings@apache.org>
Thu, 30 Jun 2016 22:59:46 +0000 (22:59 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1750867 13f79535-47bb-0310-9956-ffa450edef68

12 files changed:
src/java/org/apache/poi/hssf/dev/BiffViewer.java
src/java/org/apache/poi/hssf/dev/FormulaViewer.java
src/java/org/apache/poi/hssf/dev/ReSave.java
src/java/org/apache/poi/util/HexDump.java
src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackage.java
src/testcases/org/apache/poi/hssf/dev/BaseXLSIteratingTest.java
src/testcases/org/apache/poi/hssf/dev/TestBiffDrawingToXml.java
src/testcases/org/apache/poi/hssf/dev/TestBiffViewer.java
src/testcases/org/apache/poi/hssf/dev/TestEFBiffViewer.java
src/testcases/org/apache/poi/hssf/dev/TestFormulaViewer.java
src/testcases/org/apache/poi/hssf/dev/TestReSave.java
src/testcases/org/apache/poi/hssf/dev/TestRecordLister.java

index 35842c319becd64e51f910ed5a3b896a91a0f206..7a57c5be2cbf7454b503cd157de23cdcab4d35c8 100644 (file)
@@ -204,8 +204,8 @@ import org.apache.poi.util.StringUtil;
  * @see        #main
  */
 public final class BiffViewer {
-    static final String NEW_LINE_CHARS = System.getProperty("line.separator");
-    private static POILogger logger = POILogFactory.getLogger(BiffViewer.class);
+    private static final char[] NEW_LINE_CHARS = System.getProperty("line.separator").toCharArray();
+    private static final POILogger logger = POILogFactory.getLogger(BiffViewer.class);
 
     private BiffViewer() {
         // no instances of this class
@@ -804,39 +804,55 @@ public final class BiffViewer {
        }
 
        private static void hexDumpLine(Writer w, byte[] data, int lineStartAddress, int lineDataOffset, int startDelta, int endDelta) {
-               if (startDelta >= endDelta) {
+           final char[] buf = new char[8+2*COLUMN_SEPARATOR.length+DUMP_LINE_LEN*3-1+DUMP_LINE_LEN+NEW_LINE_CHARS.length];
+
+           if (startDelta >= endDelta) {
                        throw new IllegalArgumentException("Bad start/end delta");
                }
+           int idx=0;
                try {
-                       writeHex(w, lineStartAddress, 8);
-                       w.write(COLUMN_SEPARATOR);
+                       writeHex(buf, idx, lineStartAddress, 8);
+                       idx = arraycopy(COLUMN_SEPARATOR, buf, idx+8);
                        // raw hex data
                        for (int i=0; i< DUMP_LINE_LEN; i++) {
                                if (i>0) {
-                                       w.write(" ");
+                                   buf[idx++] = ' ';
                                }
                                if (i >= startDelta && i < endDelta) {
-                                       writeHex(w, data[lineDataOffset+i], 2);
+                                       writeHex(buf, idx, data[lineDataOffset+i], 2);
                                } else {
-                                       w.write("  ");
+                                   buf[idx] = ' ';
+                                   buf[idx+1] = ' ';
                                }
+                               idx += 2;
                        }
-                       w.write(COLUMN_SEPARATOR);
+                       idx = arraycopy(COLUMN_SEPARATOR, buf, idx);
 
                        // interpreted ascii
                        for (int i=0; i< DUMP_LINE_LEN; i++) {
+                           char ch = ' ';
                                if (i >= startDelta && i < endDelta) {
-                                       w.write(getPrintableChar(data[lineDataOffset+i]));
-                               } else {
-                                       w.write(" ");
+                                   ch = getPrintableChar(data[lineDataOffset+i]);
                                }
+                               buf[idx++] = ch;
                        }
-                       w.write(NEW_LINE_CHARS);
+
+                       idx = arraycopy(NEW_LINE_CHARS, buf, idx);
+                       
+                       w.write(buf, 0, idx);
                } catch (IOException e) {
                        throw new RuntimeException(e);
                }
        }
 
+       private static int arraycopy(char[] in, char[] out, int pos) {
+           int idx = pos;
+           for (char c : in) {
+               out[idx++] = c;
+           }
+           return idx;
+       }
+       
        private static char getPrintableChar(byte b) {
                char ib = (char) (b & 0x00FF);
                if (ib < 32 || ib > 126) {
@@ -845,14 +861,12 @@ public final class BiffViewer {
                return ib;
        }
 
-       private static void writeHex(Writer w, int value, int nDigits) throws IOException {
-               char[] buf = new char[nDigits];
+       private static void writeHex(char buf[], int startInBuf, int value, int nDigits) throws IOException {
                int acc = value;
                for(int i=nDigits-1; i>=0; i--) {
                        int digit = acc & 0x0F;
-                       buf[i] = (char) (digit < 10 ? ('0' + digit) : ('A' + digit - 10));
-                       acc >>= 4;
+                       buf[startInBuf+i] = (char) (digit < 10 ? ('0' + digit) : ('A' + digit - 10));
+                       acc >>>= 4;
                }
-               w.write(buf);
        }
 }
index 8fce8d2e9e9cdca5d93411182ea2f74dc1ebf0c2..3c012dd47d401e1e32f899db96d4ca0ae66096eb 100644 (file)
@@ -98,7 +98,7 @@ public class FormulaViewer
             StringBuffer buf = new StringBuffer();
             
             if (token instanceof ExpPtg) return;
-            buf.append(((OperationPtg) token).toFormulaString());
+            buf.append(token.toFormulaString());
             buf.append(sep);
             switch (token.getPtgClass()) {
                 case Ptg.CLASS_REF :
index 9c136ab6ba12036a12750ed400b81ebcb2be1f18..7f1988897386e4329546b944084b58c545911bd5 100644 (file)
 
 package org.apache.poi.hssf.dev;
 
+import java.io.ByteArrayOutputStream;
 import java.io.FileInputStream;
 import java.io.FileOutputStream;
+import java.io.OutputStream;
 
 import org.apache.poi.hssf.usermodel.HSSFSheet;
 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
@@ -29,13 +31,19 @@ import org.apache.poi.hssf.usermodel.HSSFWorkbook;
  *
  *  Usage: ReSave [-dg] input.xls
  *    -dg    initialize drawings, causes to re-build escher aggregates in all sheets
+ *    -bos   only write to memory instead of a file
  */
 public class ReSave {
     public static void main(String[] args) throws Exception {
         boolean initDrawing = false;
+        boolean saveToMemory = false;
+        ByteArrayOutputStream bos = new ByteArrayOutputStream();
         for(String filename : args) {
-            if(filename.equals("-dg")) initDrawing = true;
-            else {
+            if(filename.equals("-dg")) {
+                initDrawing = true;
+            } else if(filename.equals("-bos")) {
+                saveToMemory = true;
+            } else {
                 System.out.print("reading " + filename + "...");
                 FileInputStream is = new FileInputStream(filename);
                 HSSFWorkbook wb = new HSSFWorkbook(is);
@@ -48,18 +56,26 @@ public class ReSave {
                             /*HSSFPatriarch dg =*/ sheet.getDrawingPatriarch();
                         }
                     }
-    
-                    String outputFile = filename.replace(".xls", "-saved.xls");
-                    System.out.print("saving to " + outputFile + "...");
-                    FileOutputStream out = new FileOutputStream(outputFile);
+
+                    OutputStream os;
+                    if (saveToMemory) {
+                        bos.reset();
+                        os = bos;
+                    } else {
+                        String outputFile = filename.replace(".xls", "-saved.xls");
+                        System.out.print("saving to " + outputFile + "...");
+                        os = new FileOutputStream(outputFile);
+                    }
+                    
                     try {
-                        wb.write(out);
+                        wb.write(os);
                     } finally {
-                        out.close();
+                        os.close();
                     }
                     System.out.println("done");
                 } finally {
                     wb.close();
+                    is.close();
                 }
             }
         }
index 2e3a45f526ddc7893ee506e761002e340231e06b..25fb3c27580959a4adf7d79d903ec34647333727 100644 (file)
@@ -27,7 +27,6 @@ import java.io.OutputStream;
 import java.io.OutputStreamWriter;
 import java.io.PrintStream;
 import java.nio.charset.Charset;
-import java.util.Locale;
 
 import org.apache.commons.codec.CharEncoding;
 
@@ -149,10 +148,10 @@ public class HexDump {
                 chars_read = 16;
             }
             
-            buffer.append(xpad(display_offset, 8, ""));
+            writeHex(buffer, display_offset, 8, "");
             for (int k = 0; k < 16; k++) {
                 if (k < chars_read) {
-                    buffer.append(xpad(data[ k + j ], 2, " "));
+                    writeHex(buffer, data[ k + j ], 2, " ");
                 } else {
                     buffer.append("   ");
                 }
@@ -243,12 +242,12 @@ public class HexDump {
         }
         final int digits = (int) Math.round(Math.log(value.length) / Math.log(10) + 0.5);
         StringBuilder retVal = new StringBuilder();
-        retVal.append(xpad(0, digits, ""));
+        writeHex(retVal, 0, digits, "");
         retVal.append(": ");
         for(int x=0, i=-1; x < value.length; x++) {
             if (++i == bytesPerLine) {
                 retVal.append('\n');
-                retVal.append(xpad(x, digits, ""));
+                writeHex(retVal, x, digits, "");
                 retVal.append(": ");
                 i = 0;
             } else if (x>0) {
@@ -266,7 +265,9 @@ public class HexDump {
      * @return          The result right padded with 0
      */
     public static String toHex(short value) {
-        return xpad(value & 0xFFFF, 4, "");
+        StringBuilder sb = new StringBuilder(4);
+        writeHex(sb, value & 0xFFFF, 4, "");
+        return sb.toString();
     }
 
     /**
@@ -276,7 +277,9 @@ public class HexDump {
      * @return          The result right padded with 0
      */
     public static String toHex(byte value) {
-        return xpad(value & 0xFF, 2, "");
+        StringBuilder sb = new StringBuilder(2);
+        writeHex(sb, value & 0xFF, 2, "");
+        return sb.toString();
     }
 
     /**
@@ -286,7 +289,9 @@ public class HexDump {
      * @return          The result right padded with 0
      */
     public static String toHex(int value) {
-        return xpad(value & 0xFFFFFFFFL, 8, "");
+        StringBuilder sb = new StringBuilder(8);
+        writeHex(sb, value & 0xFFFFFFFFL, 8, "");
+        return sb.toString();
     }
 
     /**
@@ -296,7 +301,9 @@ public class HexDump {
      * @return          The result right padded with 0
      */
     public static String toHex(long value) {
-        return xpad(value, 16, "");
+        StringBuilder sb = new StringBuilder(16);
+        writeHex(sb, value, 16, "");
+        return sb.toString();
     }
 
     /**
@@ -352,46 +359,51 @@ public class HexDump {
      * @return string of 16 (zero padded) uppercase hex chars and prefixed with '0x'
      */
     public static String longToHex(long value) {
-        return xpad(value, 16, "0x");
+        StringBuilder sb = new StringBuilder(18);
+        writeHex(sb, value, 16, "0x");
+        return sb.toString();
     }
     
     /**
      * @return string of 8 (zero padded) uppercase hex chars and prefixed with '0x'
      */
     public static String intToHex(int value) {
-        return xpad(value & 0xFFFFFFFFL, 8, "0x");
+        StringBuilder sb = new StringBuilder(10);
+        writeHex(sb, value & 0xFFFFFFFFL, 8, "0x");
+        return sb.toString();
     }
     
     /**
      * @return string of 4 (zero padded) uppercase hex chars and prefixed with '0x'
      */
     public static String shortToHex(int value) {
-        return xpad(value & 0xFFFFL, 4, "0x");
+        StringBuilder sb = new StringBuilder(6);
+        writeHex(sb, value & 0xFFFFL, 4, "0x");
+        return sb.toString();
     }
     
     /**
      * @return string of 2 (zero padded) uppercase hex chars and prefixed with '0x'
      */
     public static String byteToHex(int value) {
-        return xpad(value & 0xFFL, 2, "0x");
-    }
-
-    private static String xpad(long value, int pad, String prefix) {
-        String sv = Long.toHexString(value).toUpperCase(Locale.ROOT);
-        int len = sv.length();
-        if ((pad == 0 || len == pad) && "".equals(prefix)) return sv;
-        StringBuilder sb = new StringBuilder(prefix);
-        if (len < pad) {
-            sb.append("0000000000000000", 0, pad-len);
-            sb.append(sv);
-        } else if (len > pad) {
-            sb.append(sv, len-pad, len);
-        } else {
-            sb.append(sv);
-        }
+        StringBuilder sb = new StringBuilder(4);
+        writeHex(sb, value & 0xFFL, 2, "0x");
         return sb.toString();
     }
     
+    private static void writeHex(StringBuilder sb, long value, int nDigits, String prefix) {
+        sb.append(prefix);
+        char[] buf = new char[nDigits];
+        long acc = value;
+        for(int i=nDigits-1; i>=0; i--) {
+            int digit = (int)(acc & 0x0F);
+            buf[i] = (char) (digit < 10 ? ('0' + digit) : ('A' + digit - 10));
+            acc >>>= 4;
+        }
+        sb.append(buf);
+    }    
+    
+    
     public static void main(String[] args) throws Exception {
         File file = new File(args[0]);
         InputStream in = new BufferedInputStream(new FileInputStream(file));
index 54107ff341ccaae4d6ad6925bad93ea18dff5cc4..d84ecab81bb83b765ffa2a73fa594d5d2ca9181e 100644 (file)
@@ -786,7 +786,7 @@ public final class TestPackage {
         ZipFile zipFile = ZipHelper.openZipFile(OpenXML4JTestDataSamples.getSampleFile("sample.xlsx"));
                assertNotNull(zipFile);
 
-               ByteArrayOutputStream bos = new ByteArrayOutputStream();
+               ByteArrayOutputStream bos = new ByteArrayOutputStream(2500000);
                ZipOutputStream append = new ZipOutputStream(bos);
                // first, copy contents from existing war
         Enumeration<? extends ZipEntry> entries = zipFile.entries();
@@ -807,7 +807,8 @@ public final class TestPackage {
                     append.write(bos2.toByteArray(), 0, (int)size);
                     byte spam[] = new byte[0x7FFF];
                     for (int i=0; i<spam.length; i++) spam[i] = ' ';
-                    while (size < 0x7FFF0000) {
+                    // 0x7FFF0000 is the maximum for 32-bit zips, but less still works
+                    while (size < 0x7FFF00) {
                         append.write(spam);
                         size += spam.length;
                     }
index bdb26aa85ef91cc1ce9c86162efd0092ce98f114..5f471d5b66684bf3a6499ae83eacab459a81b2a2 100644 (file)
@@ -24,14 +24,17 @@ import java.io.FilenameFilter;
 import java.io.IOException;
 import java.io.OutputStream;
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Locale;
+import java.util.Map;
 
 import org.apache.poi.POIDataSamples;
 import org.apache.poi.hssf.record.crypto.Biff8EncryptionKey;
 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
-import org.junit.Assume;
+import org.junit.Rule;
 import org.junit.Test;
+import org.junit.rules.ExpectedException;
 import org.junit.runner.RunWith;
 import org.junit.runners.Parameterized;
 import org.junit.runners.Parameterized.Parameter;
@@ -47,7 +50,11 @@ import org.junit.runners.Parameterized.Parameters;
 public abstract class BaseXLSIteratingTest {
     protected static final OutputStream NULL_OUTPUT_STREAM = new NullOutputStream();
 
-       protected static final List<String> EXCLUDED = new ArrayList<String>();
+    @Rule
+    public ExpectedException thrown = ExpectedException.none();
+    
+       protected static final Map<String,Class<? extends Throwable>> EXCLUDED =
+        new HashMap<String,Class<? extends Throwable>>();
 
     @Parameters(name="{index}: {0}")
     public static Iterable<Object[]> files() {
@@ -85,16 +92,15 @@ public abstract class BaseXLSIteratingTest {
        public void testMain() throws Exception {
            // we had intermittent problems when this was set differently somehow, let's try to set it here so it always is set correctly for these tests
            Biff8EncryptionKey.setCurrentUserPassword(null);
+
+           String fileName = file.getName();
+           if (EXCLUDED.containsKey(fileName)) {
+               thrown.expect(EXCLUDED.get(fileName));
+           }
            
                try {
                        runOneFile(file);
                } catch (Exception e) {
-                   Assume.assumeFalse("File " + file + " is excluded currently",
-                           EXCLUDED.contains(file.getName()));
-
-                       System.out.println("Failed: " + file);
-                       e.printStackTrace();
-                       
                        // try to read it in HSSFWorkbook to quickly fail if we cannot read the file there at all and thus probably should use EXCLUDED instead
                        FileInputStream stream = new FileInputStream(file);
                        HSSFWorkbook wb = null;
@@ -107,6 +113,8 @@ public abstract class BaseXLSIteratingTest {
                            }
                                stream.close();
                        }
+                       
+                       throw e;
                }
        }
 
index 039a1535002ddeab5967f4d2f53f09e911adfc02..7b1d49b9eec45207339130eb75050e7498d67866 100644 (file)
@@ -21,22 +21,29 @@ import java.io.FileInputStream;
 import java.io.InputStream;
 import java.io.PrintStream;
 
+import org.apache.poi.EncryptedDocumentException;
+import org.apache.poi.hssf.OldExcelFormatException;
+import org.apache.poi.hssf.record.RecordInputStream;
+import org.junit.BeforeClass;
+
 public class TestBiffDrawingToXml extends BaseXLSIteratingTest {
-       static {
-        EXCLUDED.add("35897-type4.xls"); // unsupported crypto api header 
-        EXCLUDED.add("43493.xls");  // HSSFWorkbook cannot open it as well
-        EXCLUDED.add("46904.xls");
-        EXCLUDED.add("44958_1.xls");
-        EXCLUDED.add("51832.xls");
-        EXCLUDED.add("59074.xls");
-               EXCLUDED.add("password.xls"); 
-        EXCLUDED.add("testEXCEL_2.xls");  // Biff 2 / Excel 2, pre-OLE2
-        EXCLUDED.add("testEXCEL_3.xls");  // Biff 3 / Excel 3, pre-OLE2
-        EXCLUDED.add("testEXCEL_4.xls");  // Biff 4 / Excel 4, pre-OLE2
-        EXCLUDED.add("testEXCEL_5.xls");  // Biff 5 / Excel 5
-        EXCLUDED.add("testEXCEL_95.xls"); // Biff 5 / Excel 95
-               EXCLUDED.add("xor-encryption-abc.xls"); 
-       }
+    @BeforeClass
+    public static void setup() {
+        EXCLUDED.clear();
+        EXCLUDED.put("35897-type4.xls", EncryptedDocumentException.class); // unsupported crypto api header 
+        EXCLUDED.put("51832.xls", EncryptedDocumentException.class);
+        EXCLUDED.put("xor-encryption-abc.xls", EncryptedDocumentException.class); 
+        EXCLUDED.put("password.xls", EncryptedDocumentException.class); 
+        EXCLUDED.put("46904.xls", OldExcelFormatException.class);
+        EXCLUDED.put("59074.xls", OldExcelFormatException.class);
+        EXCLUDED.put("testEXCEL_2.xls", OldExcelFormatException.class);  // Biff 2 / Excel 2, pre-OLE2
+        EXCLUDED.put("testEXCEL_3.xls", OldExcelFormatException.class);  // Biff 3 / Excel 3, pre-OLE2
+        EXCLUDED.put("testEXCEL_4.xls", OldExcelFormatException.class);  // Biff 4 / Excel 4, pre-OLE2
+        EXCLUDED.put("testEXCEL_5.xls", OldExcelFormatException.class);  // Biff 5 / Excel 5
+        EXCLUDED.put("testEXCEL_95.xls", OldExcelFormatException.class); // Biff 5 / Excel 95
+        EXCLUDED.put("43493.xls", RecordInputStream.LeftoverDataException.class);  // HSSFWorkbook cannot open it as well
+        EXCLUDED.put("44958_1.xls", RecordInputStream.LeftoverDataException.class);
+    }
        
        @Override
        void runOneFile(File pFile) throws Exception {
index f2e42f1402739993d7e519e340bd392bfc721830..04070b4c6cd564c8d11bdce990e48bcdea3ff3f2 100644 (file)
@@ -22,28 +22,32 @@ import java.io.InputStream;
 import java.io.OutputStreamWriter;
 import java.io.PrintWriter;
 
+import org.apache.poi.EncryptedDocumentException;
+import org.apache.poi.hssf.OldExcelFormatException;
+import org.apache.poi.hssf.record.RecordInputStream;
 import org.apache.poi.poifs.filesystem.NPOIFSFileSystem;
 import org.apache.poi.util.LocaleUtil;
+import org.junit.BeforeClass;
 
 public class TestBiffViewer extends BaseXLSIteratingTest {
-    static {
-        // these are likely ok to fail
-        EXCLUDED.add("XRefCalc.xls");  // "Buffer overrun"
-        EXCLUDED.add("50833.xls");             // "Name is too long" when setting username
-        EXCLUDED.add("OddStyleRecord.xls");            
-        EXCLUDED.add("NoGutsRecords.xls"); 
-        EXCLUDED.add("51832.xls");     // password 
-        EXCLUDED.add("43493.xls");     // HSSFWorkbook cannot open it as well
-        EXCLUDED.add("password.xls"); 
-        EXCLUDED.add("46904.xls");
-        EXCLUDED.add("59074.xls"); // Biff 5 / Excel 95
-        EXCLUDED.add("35897-type4.xls"); // unsupported crypto api header 
-        EXCLUDED.add("xor-encryption-abc.xls"); // unsupported XOR-encryption
-        EXCLUDED.add("testEXCEL_2.xls");  // Biff 2 / Excel 2, pre-OLE2
-        EXCLUDED.add("testEXCEL_3.xls");  // Biff 3 / Excel 3, pre-OLE2
-        EXCLUDED.add("testEXCEL_4.xls");  // Biff 4 / Excel 4, pre-OLE2
-        EXCLUDED.add("testEXCEL_5.xls");  // Biff 5 / Excel 5
-        EXCLUDED.add("testEXCEL_95.xls"); // Biff 5 / Excel 95
+    @BeforeClass
+    public static void setup() {
+        EXCLUDED.clear();
+        EXCLUDED.put("35897-type4.xls", EncryptedDocumentException.class); // unsupported crypto api header 
+        EXCLUDED.put("51832.xls", EncryptedDocumentException.class);
+        EXCLUDED.put("xor-encryption-abc.xls", EncryptedDocumentException.class); 
+        EXCLUDED.put("password.xls", EncryptedDocumentException.class); 
+        EXCLUDED.put("46904.xls", OldExcelFormatException.class);
+        EXCLUDED.put("59074.xls", OldExcelFormatException.class);
+        EXCLUDED.put("testEXCEL_2.xls", OldExcelFormatException.class);  // Biff 2 / Excel 2, pre-OLE2
+        EXCLUDED.put("testEXCEL_3.xls", OldExcelFormatException.class);  // Biff 3 / Excel 3, pre-OLE2
+        EXCLUDED.put("testEXCEL_4.xls", OldExcelFormatException.class);  // Biff 4 / Excel 4, pre-OLE2
+        EXCLUDED.put("testEXCEL_5.xls", OldExcelFormatException.class);  // Biff 5 / Excel 5
+        EXCLUDED.put("testEXCEL_95.xls", OldExcelFormatException.class); // Biff 5 / Excel 95
+        EXCLUDED.put("43493.xls", RecordInputStream.LeftoverDataException.class);  // HSSFWorkbook cannot open it as well
+        // EXCLUDED.put("44958_1.xls", RecordInputStream.LeftoverDataException.class);
+        EXCLUDED.put("50833.xls", IllegalArgumentException.class);       // "Name is too long" when setting username
+        EXCLUDED.put("XRefCalc.xls", RuntimeException.class);            // "Buffer overrun"
     }
 
     @Override
index c6ec27e3487580738fa1c115c2798386bbfe1b9f..6204803788f12300da5d527db33e827f93bcf9bc 100644 (file)
@@ -20,26 +20,31 @@ import java.io.File;
 import java.io.IOException;
 import java.io.PrintStream;
 
+import org.apache.poi.EncryptedDocumentException;
+import org.apache.poi.hssf.OldExcelFormatException;
+import org.apache.poi.hssf.record.RecordInputStream;
 import org.apache.poi.util.LocaleUtil;
+import org.junit.BeforeClass;
 
 public class TestEFBiffViewer extends BaseXLSIteratingTest {
-       static {
-               // these are likely ok to fail
-               EXCLUDED.add("XRefCalc.xls"); 
-               EXCLUDED.add("password.xls"); 
-               EXCLUDED.add("51832.xls");              // password
-               EXCLUDED.add("xor-encryption-abc.xls");    // password, ty again later!
-               EXCLUDED.add("43493.xls");      // HSSFWorkbook cannot open it as well
-               EXCLUDED.add("44958_1.xls");   // known bad file
-               EXCLUDED.add("46904.xls");     // Exception, too old
-               EXCLUDED.add("47251_1.xls");   // Broken test file
-        EXCLUDED.add("testEXCEL_3.xls");  // Biff 3 / Excel 3, pre-OLE2
-               EXCLUDED.add("testEXCEL_4.xls");   // old unsupported format
-               EXCLUDED.add("testEXCEL_5.xls");   // old unsupported format
-               EXCLUDED.add("testEXCEL_95.xls");   // old unsupported format
-               EXCLUDED.add("35897-type4.xls");   // unsupported encryption
-               EXCLUDED.add("59074.xls");      // Biff 5 / Excel 95
-       }
+    @BeforeClass
+    public static void setup() {
+        EXCLUDED.clear();
+        EXCLUDED.put("35897-type4.xls", EncryptedDocumentException.class); // unsupported crypto api header 
+        EXCLUDED.put("51832.xls", EncryptedDocumentException.class);
+        EXCLUDED.put("xor-encryption-abc.xls", EncryptedDocumentException.class); 
+        EXCLUDED.put("password.xls", EncryptedDocumentException.class); 
+        EXCLUDED.put("46904.xls", OldExcelFormatException.class);
+        EXCLUDED.put("59074.xls", OldExcelFormatException.class);
+        EXCLUDED.put("testEXCEL_2.xls", OldExcelFormatException.class);  // Biff 2 / Excel 2, pre-OLE2
+        EXCLUDED.put("testEXCEL_3.xls", OldExcelFormatException.class);  // Biff 3 / Excel 3, pre-OLE2
+        EXCLUDED.put("testEXCEL_4.xls", OldExcelFormatException.class);  // Biff 4 / Excel 4, pre-OLE2
+        EXCLUDED.put("testEXCEL_5.xls", OldExcelFormatException.class);  // Biff 5 / Excel 5
+        EXCLUDED.put("testEXCEL_95.xls", OldExcelFormatException.class); // Biff 5 / Excel 95
+        EXCLUDED.put("43493.xls", RecordInputStream.LeftoverDataException.class);  // HSSFWorkbook cannot open it as well
+        EXCLUDED.put("44958_1.xls", RecordInputStream.LeftoverDataException.class);
+        EXCLUDED.put("XRefCalc.xls", RuntimeException.class);            // "Buffer overrun"
+    }
        
        @Override
        void runOneFile(File fileIn) throws IOException {
index 1b2ef67e2c6b06b19f581629c72b24674dfcd483..6a87ac03c95870466dd23334d9efa2eb4b8d9362 100644 (file)
 ==================================================================== */
 package org.apache.poi.hssf.dev;
 
+import static org.junit.Assume.assumeTrue;
+
 import java.io.File;
 import java.io.PrintStream;
 
+import org.apache.poi.EncryptedDocumentException;
+import org.apache.poi.hssf.OldExcelFormatException;
+import org.apache.poi.hssf.record.RecordInputStream;
 import org.apache.poi.util.LocaleUtil;
-import org.junit.Ignore;
-import org.junit.Test;
+import org.junit.BeforeClass;
 
 public class TestFormulaViewer extends BaseXLSIteratingTest {
-       static {
-               // TODO: is it ok to fail these? 
-               // Look at the output of the test for the detailed stacktrace of the failures...
-//             EXCLUDED.add("WORKBOOK_in_capitals.xls");       
-//             EXCLUDED.add("NoGutsRecords.xls"); 
-//             EXCLUDED.add("BOOK_in_capitals.xls"); 
-//             EXCLUDED.add("46904.xls"); 
-//             EXCLUDED.add("OddStyleRecord.xls");             
-       }
+    @BeforeClass
+    public static void setup() {
+        EXCLUDED.clear();
+        EXCLUDED.put("35897-type4.xls", EncryptedDocumentException.class); // unsupported crypto api header 
+        EXCLUDED.put("51832.xls", EncryptedDocumentException.class);
+        EXCLUDED.put("xor-encryption-abc.xls", EncryptedDocumentException.class); 
+        EXCLUDED.put("password.xls", EncryptedDocumentException.class); 
+        EXCLUDED.put("46904.xls", OldExcelFormatException.class);
+        EXCLUDED.put("59074.xls", OldExcelFormatException.class);
+        EXCLUDED.put("testEXCEL_2.xls", OldExcelFormatException.class);  // Biff 2 / Excel 2, pre-OLE2
+        EXCLUDED.put("testEXCEL_3.xls", OldExcelFormatException.class);  // Biff 3 / Excel 3, pre-OLE2
+        EXCLUDED.put("testEXCEL_4.xls", OldExcelFormatException.class);  // Biff 4 / Excel 4, pre-OLE2
+        EXCLUDED.put("testEXCEL_5.xls", OldExcelFormatException.class);  // Biff 5 / Excel 5
+        EXCLUDED.put("testEXCEL_95.xls", OldExcelFormatException.class); // Biff 5 / Excel 95
+        EXCLUDED.put("43493.xls", RecordInputStream.LeftoverDataException.class);  // HSSFWorkbook cannot open it as well
+        EXCLUDED.put("44958_1.xls", RecordInputStream.LeftoverDataException.class);
+    }
        
-       @Override
-       @Ignore("Not yet done, nearly all files fail with various errors, remove this method when done to use the one from the abstract base class!...")
-       @Test
-       public void testMain() throws Exception {
-       }
-
     @Override
        void runOneFile(File fileIn) throws Exception {
                PrintStream save = System.out;
@@ -51,6 +57,14 @@ public class TestFormulaViewer extends BaseXLSIteratingTest {
             viewer.setFile(fileIn.getAbsolutePath());
             viewer.setList(true);
             viewer.run();
+               } catch (RuntimeException re) {
+                   String m = re.getMessage();
+                   if (m.startsWith("toFormulaString") || m.startsWith("3D references")) {
+                       // TODO: fix those cases, but ignore them for now ...
+                       assumeTrue(true);
+                   } else {
+                       throw re;
+                   }
                } finally {
                        System.setOut(save);
                }
index d858f881ebca72e225338134135d1749a7468037..413815b70a407caadd198b48452e67d9b3d451ec 100644 (file)
@@ -23,19 +23,33 @@ import java.io.PrintStream;
 import java.util.ArrayList;
 import java.util.List;
 
+import org.apache.poi.EncryptedDocumentException;
 import org.apache.poi.POIDataSamples;
+import org.apache.poi.hssf.OldExcelFormatException;
+import org.apache.poi.hssf.record.RecordInputStream;
 import org.apache.poi.util.LocaleUtil;
+import org.junit.BeforeClass;
 
 public class TestReSave extends BaseXLSIteratingTest {
-       static {
-               // these are likely ok to fail
-               EXCLUDED.add("password.xls"); 
-               EXCLUDED.add("43493.xls");      // HSSFWorkbook cannot open it as well
-               EXCLUDED.add("46904.xls"); 
-               EXCLUDED.add("51832.xls");      // password 
-        EXCLUDED.add("44958_1.xls");   // known bad file
-       }
-       
+    @BeforeClass
+    public static void setup() {
+        EXCLUDED.clear();
+        EXCLUDED.put("35897-type4.xls", EncryptedDocumentException.class); // unsupported crypto api header 
+        EXCLUDED.put("51832.xls", EncryptedDocumentException.class);
+        EXCLUDED.put("xor-encryption-abc.xls", EncryptedDocumentException.class); 
+        EXCLUDED.put("password.xls", EncryptedDocumentException.class); 
+        EXCLUDED.put("46904.xls", OldExcelFormatException.class);
+        EXCLUDED.put("59074.xls", OldExcelFormatException.class);
+        EXCLUDED.put("testEXCEL_2.xls", OldExcelFormatException.class);  // Biff 2 / Excel 2, pre-OLE2
+        EXCLUDED.put("testEXCEL_3.xls", OldExcelFormatException.class);  // Biff 3 / Excel 3, pre-OLE2
+        EXCLUDED.put("testEXCEL_4.xls", OldExcelFormatException.class);  // Biff 4 / Excel 4, pre-OLE2
+        EXCLUDED.put("testEXCEL_5.xls", OldExcelFormatException.class);  // Biff 5 / Excel 5
+        EXCLUDED.put("testEXCEL_95.xls", OldExcelFormatException.class); // Biff 5 / Excel 95
+        EXCLUDED.put("43493.xls", RecordInputStream.LeftoverDataException.class);  // HSSFWorkbook cannot open it as well
+        EXCLUDED.put("44958_1.xls", RecordInputStream.LeftoverDataException.class);
+        EXCLUDED.put("XRefCalc.xls", RuntimeException.class);            // "Buffer overrun"
+    }
+
        @Override
        void runOneFile(File fileIn) throws Exception {
                // avoid running on files leftover from previous failed runs
@@ -55,13 +69,8 @@ public class TestReSave extends BaseXLSIteratingTest {
                                // also try BiffViewer on the saved file
                 new TestBiffViewer().runOneFile(reSavedFile);
 
-                       try {
-                               // had one case where the re-saved could not be re-saved!
-                               ReSave.main(new String[] { reSavedFile.getAbsolutePath() });
-                       } finally {
-                               // clean up the re-re-saved file
-                           new File(fileIn.getParentFile(), reSavedFile.getName().replace(".xls", "-saved.xls")).delete();
-                       }
+                       // had one case where the re-saved could not be re-saved!
+                       ReSave.main(new String[] { "-bos", reSavedFile.getAbsolutePath() });
                        } finally {
                                // clean up the re-saved file
                                reSavedFile.delete();
index ebc26c3e5750171351f4fb58739bcfae08b85693..5009fa5220abef74ac683a7f502a90018ed7ca4e 100644 (file)
@@ -20,18 +20,22 @@ import java.io.File;
 import java.io.IOException;
 import java.io.PrintStream;
 
+import org.apache.poi.hssf.OldExcelFormatException;
 import org.apache.poi.util.LocaleUtil;
+import org.junit.BeforeClass;
 
 public class TestRecordLister extends BaseXLSIteratingTest {
-       static {
-               // these are likely ok to fail
-               EXCLUDED.add("46904.xls"); 
-        EXCLUDED.add("testEXCEL_3.xls");  // Biff 3 / Excel 3, pre-OLE2
-        EXCLUDED.add("testEXCEL_4.xls");   // old unsupported format
-        EXCLUDED.add("testEXCEL_5.xls");  // Biff 5 / Excel 5
-        EXCLUDED.add("testEXCEL_95.xls"); // Biff 5 / Excel 95
-               EXCLUDED.add("59074.xls");      // Biff 5 / Excel 95
-       }
+    @BeforeClass
+    public static void setup() {
+        EXCLUDED.clear();
+        EXCLUDED.put("46904.xls", OldExcelFormatException.class);
+        EXCLUDED.put("59074.xls", OldExcelFormatException.class);
+        EXCLUDED.put("testEXCEL_2.xls", OldExcelFormatException.class);  // Biff 2 / Excel 2, pre-OLE2
+        EXCLUDED.put("testEXCEL_3.xls", OldExcelFormatException.class);  // Biff 3 / Excel 3, pre-OLE2
+        EXCLUDED.put("testEXCEL_4.xls", OldExcelFormatException.class);  // Biff 4 / Excel 4, pre-OLE2
+        EXCLUDED.put("testEXCEL_5.xls", OldExcelFormatException.class);  // Biff 5 / Excel 5
+        EXCLUDED.put("testEXCEL_95.xls", OldExcelFormatException.class); // Biff 5 / Excel 95
+    }
        
        @Override
        void runOneFile(File fileIn) throws IOException {