]> source.dussan.org Git - poi.git/commitdiff
Refactor BaseXLSIteratingTest into a Parameterized test to better show which files...
authorDominik Stadler <centic@apache.org>
Tue, 25 Aug 2015 08:30:49 +0000 (08:30 +0000)
committerDominik Stadler <centic@apache.org>
Tue, 25 Aug 2015 08:30:49 +0000 (08:30 +0000)
Simplify exclusion handling
Exclude testEXCEL_3.xls and testEXCEL_4.xls in two tests, not sure why this worked before?!

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1697601 13f79535-47bb-0310-9956-ffa450edef68

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 0adb2cf984ad766b08d86218910eaa29c72947c7..ca15d74ddc953c5ec980784cb2f1345cb04a07d2 100644 (file)
@@ -17,7 +17,6 @@
 package org.apache.poi.hssf.dev;
 
 import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
 
 import java.io.File;
 import java.io.FileInputStream;
@@ -29,79 +28,79 @@ import java.util.List;
 
 import org.apache.poi.POIDataSamples;
 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+import org.junit.Assume;
 import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameter;
+import org.junit.runners.Parameterized.Parameters;
 
 /**
  * Base class for integration-style tests which iterate over all test-files
  * and execute the same action to find out if any change breaks these applications.
+ * 
+ * This test uses {@link Parameterized} to run the test for each file separatedely.
  */
+@RunWith(Parameterized.class)
 public abstract class BaseXLSIteratingTest {
     protected static final OutputStream NULL_OUTPUT_STREAM = new NullOutputStream();
 
        protected static final List<String> EXCLUDED = new ArrayList<String>();
-       protected static final List<String> SILENT_EXCLUDED = new ArrayList<String>();
 
+    @Parameters(name="{index}: {0} using {1}")
+    public static Iterable<Object[]> files() {
+        String dataDirName = System.getProperty(POIDataSamples.TEST_PROPERTY);
+        if(dataDirName == null) {
+            dataDirName = "test-data";
+        }
+
+        List<Object[]> files = new ArrayList<Object[]>();
+        findFile(files, dataDirName + "/spreadsheet");
+        findFile(files, dataDirName + "/hpsf");
+        
+        return files;
+    }
+       
+    private static void findFile(List<Object[]> list, String dir) {
+        String[] files = new File(dir).list(new FilenameFilter() {
+            @Override
+            public boolean accept(File arg0, String arg1) {
+                return arg1.toLowerCase().endsWith(".xls");
+            }
+        });
+        
+        assertNotNull("Did not find any xls files in directory " + dir, files);
+        
+        for(String file : files) {
+            list.add(new Object[] { new File(dir, file) });
+        }
+    }
+    
+    @Parameter
+    public File file;
+    
        @Test
        public void testMain() throws Exception {
-           String dataDirName = System.getProperty(POIDataSamples.TEST_PROPERTY);
-           if(dataDirName == null) {
-               dataDirName = "test-data";
-           }
-
-           int count = runWithDir(dataDirName + "/spreadsheet");
-               count += runWithDir(dataDirName + "/hpsf");
-               
-               System.out.println("Had " + count + " files");
-       }
-
-       private int runWithDir(String dir) throws IOException {
-               List<String> failed = new ArrayList<String>();
-
-               String[] files = new File(dir).list(new FilenameFilter() {
-                       @Override
-            public boolean accept(File arg0, String arg1) {
-                               return arg1.toLowerCase().endsWith(".xls");
-                       }
-               });
-               
-               assertNotNull("Did not find any xls files in directory " + dir, files);
-               
-               runWithArrayOfFiles(files, dir, failed);
-
-               assertTrue("Expected to have no failed except the ones excluded, but had: " + failed, 
-                               failed.isEmpty());
-               
-               return files.length;
-       }
-
-       private void runWithArrayOfFiles(String[] files, String dir, List<String> failed) throws IOException {
-               for(String file : files) {
+               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);
                        try {
-                               runOneFile(dir, file, failed);
-                       } catch (Exception e) {
-                               if(SILENT_EXCLUDED.contains(file)) {
-                                       continue;
-                               }
-
-                               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 can use SILENT_EXCLUDED instead
-                               FileInputStream stream = new FileInputStream(new File(dir, file));
-                               try {
-                                       assertNotNull(new HSSFWorkbook(stream));
-                               } finally {
-                                       stream.close();
-                               }
-                               
-                               if(!EXCLUDED.contains(file)) {
-                                       failed.add(file);
-                               }
+                               assertNotNull(new HSSFWorkbook(stream));
+                       } finally {
+                               stream.close();
                        }
                }
        }
 
-       abstract void runOneFile(String dir, String file, List<String> failed) throws Exception;
+       abstract void runOneFile(File file) throws Exception;
 
        /**
         * Implementation of an OutputStream which does nothing, used
index e141608959e61032af26b46b64a9f129d6a11fa4..2a14b906ca2d0ac6325a697648217c52a76a99ee 100644 (file)
@@ -20,7 +20,6 @@ import java.io.File;
 import java.io.FileInputStream;
 import java.io.InputStream;
 import java.io.PrintStream;
-import java.util.List;
 
 import org.junit.Ignore;
 import org.junit.Test;
@@ -42,13 +41,13 @@ public class TestBiffDrawingToXml extends BaseXLSIteratingTest {
        }
        
        @Override
-       void runOneFile(String dir, String file, List<String> failed)
+       void runOneFile(File file)
                        throws Exception {
                PrintStream save = System.out;
                try {
                        //System.setOut(new PrintStream(TestBiffViewer.NULL_OUTPUT_STREAM));
                        // use a NullOutputStream to not write the bytes anywhere for best runtime 
-                   InputStream wb = new FileInputStream(new File(dir, file));
+                   InputStream wb = new FileInputStream(file);
                    try {
                        BiffDrawingToXml.writeToFile(NULL_OUTPUT_STREAM, wb, false, new String[] {});
                    } finally {
index 5d27990dab0fac2f7e5cbce408fa3442eef90c39..a1d190ab582f0f966bd616db42d2a23b780591ee 100644 (file)
@@ -20,34 +20,30 @@ import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.PrintStream;
-import java.util.List;
 
 public class TestBiffViewer extends BaseXLSIteratingTest {
        static {
-               // Look at the output of the test for the detailed stacktrace of the failures...
-               //EXCLUDED.add("");
-               
                // these are likely ok to fail
-               SILENT_EXCLUDED.add("XRefCalc.xls");    // "Buffer overrun"
-               SILENT_EXCLUDED.add("50833.xls");               // "Name is too long" when setting username
-               SILENT_EXCLUDED.add("OddStyleRecord.xls");              
-               SILENT_EXCLUDED.add("NoGutsRecords.xls"); 
-               SILENT_EXCLUDED.add("51832.xls");       // password 
-               SILENT_EXCLUDED.add("43493.xls");       // HSSFWorkbook cannot open it as well
-               SILENT_EXCLUDED.add("password.xls"); 
-               SILENT_EXCLUDED.add("46904.xls");
-        SILENT_EXCLUDED.add("35897-type4.xls"); // unsupported crypto api header 
-               SILENT_EXCLUDED.add("xor-encryption-abc.xls"); // unsupported XOR-encryption
-        SILENT_EXCLUDED.add("testEXCEL_2.xls");  // Biff 2 / Excel 2, pre-OLE2
-        SILENT_EXCLUDED.add("testEXCEL_3.xls");  // Biff 3 / Excel 3, pre-OLE2
-        SILENT_EXCLUDED.add("testEXCEL_4.xls");  // Biff 4 / Excel 4, pre-OLE2
-        SILENT_EXCLUDED.add("testEXCEL_5.xls");  // Biff 5 / Excel 5
-        SILENT_EXCLUDED.add("testEXCEL_95.xls"); // Biff 5 / Excel 95
+               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("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
        }
 
        @Override
-       void runOneFile(String dir, String file, List<String> failed) throws IOException {
-               InputStream is = BiffViewer.getPOIFSInputStream(new File(dir, file));
+       void runOneFile(File file) throws IOException {
+               InputStream is = BiffViewer.getPOIFSInputStream(file);
                try {
                        // use a NullOutputStream to not write the bytes anywhere for best runtime 
                        BiffViewer.runBiffViewer(new PrintStream(NULL_OUTPUT_STREAM), is, true, true, true, false);
index c3730bc043629815820a56c7e7b77a943a7f3d04..32eaa924f48340a407a6786547e6d395ee5d1bfb 100644 (file)
@@ -19,36 +19,33 @@ package org.apache.poi.hssf.dev;
 import java.io.File;
 import java.io.IOException;
 import java.io.PrintStream;
-import java.util.List;
 
 public class TestEFBiffViewer extends BaseXLSIteratingTest {
        static {
-               // Look at the output of the test for the detailed stacktrace of the failures...
-               //EXCLUDED.add("");
-
                // these are likely ok to fail
-               SILENT_EXCLUDED.add("XRefCalc.xls"); 
-               SILENT_EXCLUDED.add("password.xls"); 
-               SILENT_EXCLUDED.add("51832.xls");               // password
-               SILENT_EXCLUDED.add("xor-encryption-abc.xls");    // password, ty again later!
-               SILENT_EXCLUDED.add("43493.xls");       // HSSFWorkbook cannot open it as well
-               SILENT_EXCLUDED.add("44958_1.xls");   // known bad file
-               SILENT_EXCLUDED.add("46904.xls");     // Exception, too old
-               SILENT_EXCLUDED.add("47251_1.xls");   // Broken test file
-               SILENT_EXCLUDED.add("testEXCEL_4.xls");   // old unsupported format
-               SILENT_EXCLUDED.add("testEXCEL_5.xls");   // old unsupported format
-               SILENT_EXCLUDED.add("testEXCEL_95.xls");   // old unsupported format
-               SILENT_EXCLUDED.add("35897-type4.xls");   // unsupported encryption
+               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
        }
        
        @Override
-       void runOneFile(String dir, String file, List<String> failed) throws IOException {
+       void runOneFile(File file) throws IOException {
                PrintStream save = System.out;
                try {
                        // redirect standard out during the test to avoid spamming the console with output
                        System.setOut(new PrintStream(NULL_OUTPUT_STREAM));
 
-                       EFBiffViewer.main(new String[] { new File(dir, file).getAbsolutePath() });
+                       EFBiffViewer.main(new String[] { file.getAbsolutePath() });
                } finally {
                        System.setOut(save);
                }
index 8683b78dcf182841fc8ee8d6e8552f661680098c..b6014376c518ce5cc3b2d4853f0f87f9abce9a36 100644 (file)
@@ -18,7 +18,6 @@ package org.apache.poi.hssf.dev;
 
 import java.io.File;
 import java.io.PrintStream;
-import java.util.List;
 
 import org.junit.Ignore;
 import org.junit.Test;
@@ -41,14 +40,14 @@ public class TestFormulaViewer extends BaseXLSIteratingTest {
        }
 
        @Override
-       void runOneFile(String dir, String file, List<String> failed) throws Exception {
+       void runOneFile(File file) throws Exception {
                PrintStream save = System.out;
                try {
                        // redirect standard out during the test to avoid spamming the console with output
                        System.setOut(new PrintStream(NULL_OUTPUT_STREAM));
 
             FormulaViewer viewer = new FormulaViewer();
-            viewer.setFile(new File(dir, file).getAbsolutePath());
+            viewer.setFile(file.getAbsolutePath());
             viewer.setList(true);
             viewer.run();
                } finally {
index d42af8858f823fe09bd3c338fd76fdf79f9db3df..e26bffea3a8c9fa8c4f90cdf8cec614e154e9a8b 100644 (file)
@@ -24,26 +24,21 @@ import java.util.ArrayList;
 import java.util.List;
 
 import org.apache.poi.POIDataSamples;
-import org.junit.Test;
 
 public class TestReSave 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("49931.xls");
-
                // these are likely ok to fail
-               SILENT_EXCLUDED.add("password.xls"); 
-               SILENT_EXCLUDED.add("43493.xls");       // HSSFWorkbook cannot open it as well
-               SILENT_EXCLUDED.add("46904.xls"); 
-               SILENT_EXCLUDED.add("51832.xls");       // password 
-        SILENT_EXCLUDED.add("44958_1.xls");   // known bad file
+               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
        }
        
        @Override
-       void runOneFile(String dir, String file, List<String> failed) throws Exception {
+       void runOneFile(File file) throws Exception {
                // avoid running on files leftover from previous failed runs
-               if(file.endsWith("-saved.xls")) {
+               if(file.getName().endsWith("-saved.xls")) {
                        return;
                }
 
@@ -52,22 +47,23 @@ public class TestReSave extends BaseXLSIteratingTest {
                        // redirect standard out during the test to avoid spamming the console with output
                        System.setOut(new PrintStream(NULL_OUTPUT_STREAM));
 
+                       File reSavedFile = new File(file.getParentFile(), file.getName().replace(".xls", "-saved.xls"));
                        try {
-                               ReSave.main(new String[] { new File(dir, file).getAbsolutePath() });
+                               ReSave.main(new String[] { file.getAbsolutePath() });
                                
                                // also try BiffViewer on the saved file
-                               new TestBiffViewer().runOneFile(dir, file.replace(".xls", "-saved.xls"), failed);
+                new TestBiffViewer().runOneFile(reSavedFile);
 
                        try {
                                // had one case where the re-saved could not be re-saved!
-                               ReSave.main(new String[] { new File(dir, file.replace(".xls", "-saved.xls")).getAbsolutePath() });
+                               ReSave.main(new String[] { reSavedFile.getAbsolutePath() });
                        } finally {
                                // clean up the re-re-saved file
-                               new File(dir, file.replace(".xls", "-saved.xls").replace(".xls", "-saved.xls")).delete();
+                           new File(file.getParentFile(), reSavedFile.getName().replace(".xls", "-saved.xls")).delete();
                        }
                        } finally {
                                // clean up the re-saved file
-                               new File(dir, file.replace(".xls", "-saved.xls")).delete();
+                               reSavedFile.delete();
                        }
 
                } finally {
@@ -75,7 +71,8 @@ public class TestReSave extends BaseXLSIteratingTest {
                }
        }
 
-       @Test
+       //Only used for local testing
+       //@Test
        public void testOneFile() throws Exception {
         String dataDirName = System.getProperty(POIDataSamples.TEST_PROPERTY);
         if(dataDirName == null) {
@@ -83,7 +80,7 @@ public class TestReSave extends BaseXLSIteratingTest {
         }
 
                List<String> failed = new ArrayList<String>();
-               runOneFile(dataDirName + "/spreadsheet", "49219.xls", failed);
+               runOneFile(new File(dataDirName + "/spreadsheet", "49931.xls"));
 
                assertTrue("Expected to have no failed except the ones excluded, but had: " + failed, 
                                failed.isEmpty());
index c74816fd1e3b68408cad635b3927a805c4e3b0b0..6c40b8b5ce031f8e3ef5c91685308fdedea34ae4 100644 (file)
@@ -19,27 +19,24 @@ package org.apache.poi.hssf.dev;
 import java.io.File;
 import java.io.IOException;
 import java.io.PrintStream;
-import java.util.List;
 
 public class TestRecordLister 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("");
-
                // these are likely ok to fail
-               SILENT_EXCLUDED.add("46904.xls"); 
+               EXCLUDED.add("46904.xls"); 
+        EXCLUDED.add("testEXCEL_3.xls");  // Biff 3 / Excel 3, pre-OLE2
+        EXCLUDED.add("testEXCEL_4.xls");   // old unsupported format
        }
        
        @Override
-       void runOneFile(String dir, String file, List<String> failed) throws IOException {
+       void runOneFile(File file) throws IOException {
                PrintStream save = System.out;
                try {
                        // redirect standard out during the test to avoid spamming the console with output
                        System.setOut(new PrintStream(NULL_OUTPUT_STREAM));
 
                        RecordLister viewer = new RecordLister();
-            viewer.setFile(new File(dir, file).getAbsolutePath());
+            viewer.setFile(file.getAbsolutePath());
             viewer.run();
                } finally {
                        System.setOut(save);