poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cen...@apache.org
Subject svn commit: r1737308 - in /poi/trunk: ./ src/examples/src/org/apache/poi/xssf/eventusermodel/ src/integrationtest/org/apache/poi/ src/integrationtest/org/apache/poi/stress/
Date Fri, 01 Apr 2016 06:25:50 GMT
Author: centic
Date: Fri Apr  1 06:25:49 2016
New Revision: 1737308

URL: http://svn.apache.org/viewvc?rev=1737308&view=rev
Log:
Enhance integration tests to call some of the common examples/devtools  to also trigger these
with all sample files, currently XLSX2CSV, BiffViewer, FromHowTo

Modified:
    poi/trunk/build.xml
    poi/trunk/src/examples/src/org/apache/poi/xssf/eventusermodel/XLSX2CSV.java
    poi/trunk/src/integrationtest/org/apache/poi/TestAllFiles.java
    poi/trunk/src/integrationtest/org/apache/poi/stress/AbstractFileHandler.java
    poi/trunk/src/integrationtest/org/apache/poi/stress/FileHandler.java
    poi/trunk/src/integrationtest/org/apache/poi/stress/HSSFFileHandler.java
    poi/trunk/src/integrationtest/org/apache/poi/stress/XSSFFileHandler.java

Modified: poi/trunk/build.xml
URL: http://svn.apache.org/viewvc/poi/trunk/build.xml?rev=1737308&r1=1737307&r2=1737308&view=diff
==============================================================================
--- poi/trunk/build.xml (original)
+++ poi/trunk/build.xml Fri Apr  1 06:25:49 2016
@@ -334,6 +334,7 @@ under the License.
         <pathelement location="${main.output.test.dir}"/>
         <pathelement location="${ooxml.output.dir}"/>
         <pathelement location="${integration.output.test.dir}"/>
+        <pathelement location="${examples.output.dir}"/>
     </path>
 
     <path id="ooxml-lite.classpath">
@@ -998,6 +999,7 @@ under the License.
                 <path refid="ooxml.classpath"/>
                 <pathelement location="${ooxml.output.dir}"/>
                 <pathelement location="${main.output.test.dir}"/>
+                <pathelement location="${examples.output.dir}"/>
                 <pathelement location="${main.ant.jar}"/>
             </classpath>
         </javac>

Modified: poi/trunk/src/examples/src/org/apache/poi/xssf/eventusermodel/XLSX2CSV.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/examples/src/org/apache/poi/xssf/eventusermodel/XLSX2CSV.java?rev=1737308&r1=1737307&r2=1737308&view=diff
==============================================================================
--- poi/trunk/src/examples/src/org/apache/poi/xssf/eventusermodel/XLSX2CSV.java (original)
+++ poi/trunk/src/examples/src/org/apache/poi/xssf/eventusermodel/XLSX2CSV.java Fri Apr  1
06:25:49 2016
@@ -28,6 +28,7 @@ import org.apache.poi.openxml4j.exceptio
 import org.apache.poi.openxml4j.opc.OPCPackage;
 import org.apache.poi.openxml4j.opc.PackageAccess;
 import org.apache.poi.ss.usermodel.DataFormatter;
+import org.apache.poi.ss.util.CellAddress;
 import org.apache.poi.ss.util.CellReference;
 import org.apache.poi.util.SAXHelper;
 import org.apache.poi.xssf.eventusermodel.XSSFSheetXMLHandler.SheetContentsHandler;
@@ -106,7 +107,12 @@ public class XLSX2CSV {
             } else {
                 output.append(',');
             }
-            
+
+            // gracefully handle missing CellRef here in a similar way as XSSFCell does
+            if(cellReference == null) {
+                cellReference = new CellAddress(currentRow, currentCol).formatAsString();
+            }
+
             // Did we miss any cells?
             int thisCol = (new CellReference(cellReference)).getCol();
             int missedCols = thisCol - currentCol - 1;

Modified: poi/trunk/src/integrationtest/org/apache/poi/TestAllFiles.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/integrationtest/org/apache/poi/TestAllFiles.java?rev=1737308&r1=1737307&r2=1737308&view=diff
==============================================================================
--- poi/trunk/src/integrationtest/org/apache/poi/TestAllFiles.java (original)
+++ poi/trunk/src/integrationtest/org/apache/poi/TestAllFiles.java Fri Apr  1 06:25:49 2016
@@ -308,6 +308,7 @@ public class TestAllFiles {
         return files;
     }
 
+    @SuppressWarnings("DefaultAnnotationParam")
     @Parameter(value=0)
     public String file;
 
@@ -356,6 +357,9 @@ public class TestAllFiles {
                 throw new Exception("While handling " + file, e);
             }
         }
+
+        // let some file handlers do additional stuff
+        handler.handleAdditional(inputFile);
     }
 
     static String getExtension(String file) {
@@ -375,5 +379,9 @@ public class TestAllFiles {
         @Override
         public void handleExtracting(File file) throws Exception {
         }
+
+        @Override
+        public void handleAdditional(File file) throws Exception {
+        }
     }
 }

Modified: poi/trunk/src/integrationtest/org/apache/poi/stress/AbstractFileHandler.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/integrationtest/org/apache/poi/stress/AbstractFileHandler.java?rev=1737308&r1=1737307&r2=1737308&view=diff
==============================================================================
--- poi/trunk/src/integrationtest/org/apache/poi/stress/AbstractFileHandler.java (original)
+++ poi/trunk/src/integrationtest/org/apache/poi/stress/AbstractFileHandler.java Fri Apr 
1 06:25:49 2016
@@ -133,4 +133,9 @@ public abstract class AbstractFileHandle
             stream.close();
         }
     }
+
+    @Override
+    public void handleAdditional(File file) throws Exception {
+        // by default we do nothing here
+    }
 }

Modified: poi/trunk/src/integrationtest/org/apache/poi/stress/FileHandler.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/integrationtest/org/apache/poi/stress/FileHandler.java?rev=1737308&r1=1737307&r2=1737308&view=diff
==============================================================================
--- poi/trunk/src/integrationtest/org/apache/poi/stress/FileHandler.java (original)
+++ poi/trunk/src/integrationtest/org/apache/poi/stress/FileHandler.java Fri Apr  1 06:25:49
2016
@@ -41,4 +41,10 @@ public interface FileHandler {
 	 * is returning some text. 
 	 */
 	void handleExtracting(File file) throws Exception;
+
+	/**
+	 * Allows to perform some additional work, e.g. run
+	 * some of the example applications
+	 */
+	void handleAdditional(File file) throws Exception;
 }

Modified: poi/trunk/src/integrationtest/org/apache/poi/stress/HSSFFileHandler.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/integrationtest/org/apache/poi/stress/HSSFFileHandler.java?rev=1737308&r1=1737307&r2=1737308&view=diff
==============================================================================
--- poi/trunk/src/integrationtest/org/apache/poi/stress/HSSFFileHandler.java (original)
+++ poi/trunk/src/integrationtest/org/apache/poi/stress/HSSFFileHandler.java Fri Apr  1 06:25:49
2016
@@ -16,13 +16,19 @@
 ==================================================================== */
 package org.apache.poi.stress;
 
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.InputStream;
-
+import org.apache.poi.EncryptedDocumentException;
+import org.apache.poi.hssf.OldExcelFormatException;
+import org.apache.poi.hssf.dev.BiffViewer;
 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+import org.apache.poi.util.RecordFormatException;
 import org.junit.Test;
 
+import java.io.*;
+import java.util.HashSet;
+import java.util.Set;
+
+import static org.junit.Assert.assertFalse;
+
 public class HSSFFileHandler extends SpreadsheetHandler {
 	private POIFSFileHandler delegate = new POIFSFileHandler();
 	@Override
@@ -40,6 +46,54 @@ public class HSSFFileHandler extends Spr
 		// TODO: still fails on some records... RecordsStresser.handleWorkbook(wb);
 	}
 
+	private static final Set<String> EXPECTED_ADDITIONAL_FAILURES = new HashSet<String>();
+	static {
+		// encrypted
+		EXPECTED_ADDITIONAL_FAILURES.add("spreadsheet/35897-type4.xls");
+		EXPECTED_ADDITIONAL_FAILURES.add("spreadsheet/xor-encryption-abc.xls");
+		EXPECTED_ADDITIONAL_FAILURES.add("spreadsheet/password.xls");
+		// broken files
+		EXPECTED_ADDITIONAL_FAILURES.add("spreadsheet/43493.xls");
+		// TODO: ok to ignore?
+		EXPECTED_ADDITIONAL_FAILURES.add("spreadsheet/50833.xls");
+		EXPECTED_ADDITIONAL_FAILURES.add("spreadsheet/51832.xls");
+		EXPECTED_ADDITIONAL_FAILURES.add("spreadsheet/XRefCalc.xls");
+	}
+
+	@Override
+	public void handleAdditional(File file) throws Exception {
+		// redirect stdout as the examples often write lots of text
+		PrintStream oldOut = System.out;
+		try {
+			System.setOut(new PrintStream(new OutputStream() {
+				@Override
+				public void write(int b) throws IOException {
+				}
+			}));
+
+			BiffViewer.main(new String[]{file.getAbsolutePath()});
+
+			assertFalse("Expected Extraction to fail for file " + file + " and handler " + this +
", but did not fail!",
+					EXPECTED_ADDITIONAL_FAILURES.contains(file.getParentFile().getName() + "/" + file.getName()));
+		} catch (OldExcelFormatException e) {
+			// old excel formats are not supported here
+		} catch (EncryptedDocumentException e) {
+			if(!EXPECTED_ADDITIONAL_FAILURES.contains(file.getParentFile().getName() + "/" + file.getName()))
{
+				throw e;
+			}
+		} catch (RecordFormatException e) {
+			if(!EXPECTED_ADDITIONAL_FAILURES.contains(file.getParentFile().getName() + "/" + file.getName()))
{
+				throw e;
+			}
+		} catch (RuntimeException e) {
+			if(!EXPECTED_ADDITIONAL_FAILURES.contains(file.getParentFile().getName() + "/" + file.getName()))
{
+				throw e;
+			}
+		} finally {
+			System.setOut(oldOut);
+		}
+	}
+
 	// a test-case to test this locally without executing the full TestAllFiles
 	@Test
 	public void test() throws Exception {

Modified: poi/trunk/src/integrationtest/org/apache/poi/stress/XSSFFileHandler.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/integrationtest/org/apache/poi/stress/XSSFFileHandler.java?rev=1737308&r1=1737307&r2=1737308&view=diff
==============================================================================
--- poi/trunk/src/integrationtest/org/apache/poi/stress/XSSFFileHandler.java (original)
+++ poi/trunk/src/integrationtest/org/apache/poi/stress/XSSFFileHandler.java Fri Apr  1 06:25:49
2016
@@ -16,24 +16,26 @@
 ==================================================================== */
 package org.apache.poi.stress;
 
+import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 
-import java.io.BufferedInputStream;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
+import java.io.*;
+import java.util.HashSet;
 import java.util.Iterator;
+import java.util.Set;
 
 import javax.xml.parsers.ParserConfigurationException;
 import javax.xml.transform.TransformerException;
 
+import org.apache.poi.POIXMLException;
+import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
+import org.apache.poi.openxml4j.exceptions.OLE2NotOfficeXmlFileException;
 import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
 import org.apache.poi.openxml4j.opc.OPCPackage;
 import org.apache.poi.util.IOUtils;
+import org.apache.poi.xssf.eventusermodel.XLSX2CSV;
 import org.apache.poi.xssf.eventusermodel.XSSFReader;
+import org.apache.poi.xssf.eventusermodel.examples.FromHowTo;
 import org.apache.poi.xssf.extractor.XSSFExportToXml;
 import org.apache.poi.xssf.usermodel.XSSFMap;
 import org.apache.poi.xssf.usermodel.XSSFWorkbook;
@@ -111,7 +113,67 @@ public class XSSFFileHandler extends Spr
             exporter.exportToXML(os, true);
         }
     }
-    
+
+    private static final Set<String> EXPECTED_ADDITIONAL_FAILURES = new HashSet<String>();
+    static {
+        // expected sheet-id not found
+        EXPECTED_ADDITIONAL_FAILURES.add("spreadsheet/52348.xlsx");
+        EXPECTED_ADDITIONAL_FAILURES.add("spreadsheet/59021.xlsx");
+        // zip-bomb
+        EXPECTED_ADDITIONAL_FAILURES.add("spreadsheet/54764.xlsx");
+        EXPECTED_ADDITIONAL_FAILURES.add("spreadsheet/54764-2.xlsx");
+        EXPECTED_ADDITIONAL_FAILURES.add("spreadsheet/54764.xlsx");
+        EXPECTED_ADDITIONAL_FAILURES.add("spreadsheet/poc-xmlbomb.xlsx");
+        // strict OOXML
+        EXPECTED_ADDITIONAL_FAILURES.add("spreadsheet/57914.xlsx");
+        EXPECTED_ADDITIONAL_FAILURES.add("spreadsheet/SampleSS.strict.xlsx");
+        EXPECTED_ADDITIONAL_FAILURES.add("spreadsheet/SimpleStrict.xlsx");
+        EXPECTED_ADDITIONAL_FAILURES.add("spreadsheet/sample.strict.xlsx");
+        // binary format
+        EXPECTED_ADDITIONAL_FAILURES.add("spreadsheet/Simple.xlsb");
+        // TODO: good to ignore?
+        EXPECTED_ADDITIONAL_FAILURES.add("spreadsheet/sample-beta.xlsx");
+    }
+
+    @Override
+    public void handleAdditional(File file) throws Exception {
+        // redirect stdout as the examples often write lots of text
+        PrintStream oldOut = System.out;
+        try {
+            System.setOut(new PrintStream(new OutputStream() {
+                @Override
+                public void write(int b) throws IOException {
+                }
+            }));
+            FromHowTo.main(new String[]{file.getAbsolutePath()});
+            XLSX2CSV.main(new String[]{file.getAbsolutePath()});
+
+            assertFalse("Expected Extraction to fail for file " + file + " and handler "
+ this + ", but did not fail!",
+                    EXPECTED_ADDITIONAL_FAILURES.contains(file.getParentFile().getName()
+ "/" + file.getName()));
+
+        } catch (OLE2NotOfficeXmlFileException e) {
+            // we have some files that are not actually OOXML and thus cannot be tested here
+        } catch (IllegalArgumentException e) {
+            if(!EXPECTED_ADDITIONAL_FAILURES.contains(file.getParentFile().getName() + "/"
+ file.getName())) {
+                throw e;
+            }
+        } catch (InvalidFormatException e) {
+            if(!EXPECTED_ADDITIONAL_FAILURES.contains(file.getParentFile().getName() + "/"
+ file.getName())) {
+                throw e;
+            }
+        } catch (IOException e) {
+            if(!EXPECTED_ADDITIONAL_FAILURES.contains(file.getParentFile().getName() + "/"
+ file.getName())) {
+                throw e;
+            }
+        } catch (POIXMLException e) {
+            if(!EXPECTED_ADDITIONAL_FAILURES.contains(file.getParentFile().getName() + "/"
+ file.getName())) {
+                throw e;
+            }
+        } finally {
+            System.setOut(oldOut);
+        }
+    }
+
     // a test-case to test this locally without executing the full TestAllFiles
     @Test
     public void test() throws Exception {
@@ -128,4 +190,9 @@ public class XSSFFileHandler extends Spr
     public void testExtractor() throws Exception {
         handleExtracting(new File("test-data/spreadsheet/ref-56737.xlsx"));
     }
-}
\ No newline at end of file
+
+    @Test
+    public void testAdditional() throws Exception {
+        handleAdditional(new File("test-data/spreadsheet/poc-xmlbomb.xlsx"));
+    }
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org


Mime
View raw message