poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From talli...@apache.org
Subject svn commit: r1787264 - in /poi/trunk/src/integrationtest/org/apache/poi: TestAllFiles.java stress/XSSFBFileHandler.java stress/XSSFFileHandler.java
Date Thu, 16 Mar 2017 22:32:25 GMT
Author: tallison
Date: Thu Mar 16 22:32:24 2017
New Revision: 1787264

URL: http://svn.apache.org/viewvc?rev=1787264&view=rev
Log:
60826 -- update stress tests to handle xlsb

Added:
    poi/trunk/src/integrationtest/org/apache/poi/stress/XSSFBFileHandler.java
      - copied, changed from r1787212, poi/trunk/src/integrationtest/org/apache/poi/stress/XSSFFileHandler.java
Modified:
    poi/trunk/src/integrationtest/org/apache/poi/TestAllFiles.java
    poi/trunk/src/integrationtest/org/apache/poi/stress/XSSFFileHandler.java

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=1787264&r1=1787263&r2=1787264&view=diff
==============================================================================
--- poi/trunk/src/integrationtest/org/apache/poi/TestAllFiles.java (original)
+++ poi/trunk/src/integrationtest/org/apache/poi/TestAllFiles.java Thu Mar 16 22:32:24 2017
@@ -17,7 +17,40 @@
 package org.apache.poi;
 
 
-import org.apache.poi.stress.*;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+
+import java.io.BufferedInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.poi.stress.AbstractFileHandler;
+import org.apache.poi.stress.FileHandler;
+import org.apache.poi.stress.HDGFFileHandler;
+import org.apache.poi.stress.HMEFFileHandler;
+import org.apache.poi.stress.HPBFFileHandler;
+import org.apache.poi.stress.HPSFFileHandler;
+import org.apache.poi.stress.HSLFFileHandler;
+import org.apache.poi.stress.HSMFFileHandler;
+import org.apache.poi.stress.HSSFFileHandler;
+import org.apache.poi.stress.HWPFFileHandler;
+import org.apache.poi.stress.OPCFileHandler;
+import org.apache.poi.stress.POIFSFileHandler;
+import org.apache.poi.stress.XDGFFileHandler;
+import org.apache.poi.stress.XSLFFileHandler;
+import org.apache.poi.stress.XSSFBFileHandler;
+import org.apache.poi.stress.XSSFFileHandler;
+import org.apache.poi.stress.XWPFFileHandler;
 import org.apache.tools.ant.DirectoryScanner;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -25,15 +58,6 @@ import org.junit.runners.Parameterized;
 import org.junit.runners.Parameterized.Parameter;
 import org.junit.runners.Parameterized.Parameters;
 
-import java.io.BufferedInputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.InputStream;
-import java.util.*;
-
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-
 /**
  *  This is an integration test which performs various actions on all stored test-files and
tries
  *  to reveal problems which are introduced, but not covered (yet) by unit tests. 
@@ -60,7 +84,8 @@ import static org.junit.Assert.assertNot
  */
 @RunWith(Parameterized.class)
 public class TestAllFiles {
-    private static final File ROOT_DIR = new File("test-data");
+
+    private static final File ROOT_DIR = new File("C:/users/tallison/idea projects/poi-trunk/test-data");
 
     static final String[] SCAN_EXCLUDES = new String[] { "**/.svn/**", "lost+found" };
     
@@ -72,7 +97,7 @@ public class TestAllFiles {
         HANDLERS.put(".xlsx", new XSSFFileHandler());
         HANDLERS.put(".xlsm", new XSSFFileHandler());
         HANDLERS.put(".xltx", new XSSFFileHandler());
-        HANDLERS.put(".xlsb", new XSSFFileHandler());
+        HANDLERS.put(".xlsb", new XSSFBFileHandler());
 
         // Word
         HANDLERS.put(".doc", new HWPFFileHandler());
@@ -250,7 +275,6 @@ public class TestAllFiles {
         "openxml4j/invalid.xlsx",
         "spreadsheet/54764-2.xlsx",   // see TestXSSFBugs.bug54764()
         "spreadsheet/54764.xlsx",     // see TestXSSFBugs.bug54764()
-        "spreadsheet/Simple.xlsb",
         "poifs/unknown_properties.msg", // POIFS properties corrupted
         "poifs/only-zero-byte-streams.ole2", // No actual contents
         "spreadsheet/poc-xmlbomb.xlsx",  // contains xml-entity-expansion

Copied: poi/trunk/src/integrationtest/org/apache/poi/stress/XSSFBFileHandler.java (from r1787212,
poi/trunk/src/integrationtest/org/apache/poi/stress/XSSFFileHandler.java)
URL: http://svn.apache.org/viewvc/poi/trunk/src/integrationtest/org/apache/poi/stress/XSSFBFileHandler.java?p2=poi/trunk/src/integrationtest/org/apache/poi/stress/XSSFBFileHandler.java&p1=poi/trunk/src/integrationtest/org/apache/poi/stress/XSSFFileHandler.java&r1=1787212&r2=1787264&rev=1787264&view=diff
==============================================================================
--- poi/trunk/src/integrationtest/org/apache/poi/stress/XSSFFileHandler.java (original)
+++ poi/trunk/src/integrationtest/org/apache/poi/stress/XSSFBFileHandler.java Thu Mar 16 22:32:24
2017
@@ -16,258 +16,81 @@
 ==================================================================== */
 package org.apache.poi.stress;
 
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
 
-import java.io.*;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Locale;
-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.NotOfficeXmlFileException;
-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.openxml4j.opc.PackageAccess;
 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.XLSBUnsupportedException;
+import org.apache.poi.xssf.extractor.XSSFBEventBasedExcelExtractor;
 import org.apache.poi.xssf.usermodel.XSSFWorkbook;
-import org.junit.Test;
-import org.xml.sax.SAXException;
 
-public class XSSFFileHandler extends SpreadsheetHandler {
+public class XSSFBFileHandler extends AbstractFileHandler {
+
+    static {
+        //this is a "Beta" xlsb version and is not openable with Excel 2016
+        //TODO: see if we can support this easily enough
+        AbstractFileHandler.EXPECTED_EXTRACTOR_FAILURES.add(
+                "spreadsheet/Simple.xlsb"
+        );
+    }
+
+
     @Override
     public void handleFile(InputStream stream) throws Exception {
-        // ignore password protected files
-        if (POIXMLDocumentHandler.isEncrypted(stream)) return;
-
         ByteArrayOutputStream out = new ByteArrayOutputStream();
         IOUtils.copy(stream, out);
 
         final byte[] bytes = out.toByteArray();
-        final XSSFWorkbook wb;
-        wb = new XSSFWorkbook(new ByteArrayInputStream(bytes));
-
-        // use the combined handler for HSSF/XSSF
-        handleWorkbook(wb);
-        
-        // TODO: some documents fail currently...
-        //XSSFFormulaEvaluator evaluator = new XSSFFormulaEvaluator(wb);
-        //evaluator.evaluateAll();
-
-        // also verify general POIFS-stuff
-        new POIXMLDocumentHandler().handlePOIXMLDocument(wb);
-        
-        // and finally ensure that exporting to XML works
-        exportToXML(wb);
-
-        checkXSSFReader(OPCPackage.open(new ByteArrayInputStream(bytes)));
-        
-        wb.close();
-    }
-
-
-    private void checkXSSFReader(OPCPackage p) throws IOException, OpenXML4JException {
-        XSSFReader reader = new XSSFReader(p);
-        
-        // these can be null...
-        InputStream sharedStringsData = reader.getSharedStringsData();
-        if(sharedStringsData != null) {
-            sharedStringsData.close();
+        OPCPackage opcPackage = OPCPackage.open(new ByteArrayInputStream(bytes));
+        try {
+            testOne(opcPackage);
+        } finally {
+            opcPackage.close();
         }
-        reader.getSharedStringsTable();
 
-        InputStream stylesData = reader.getStylesData();
-        if(stylesData != null) {
-            stylesData.close();
-        }
-        reader.getStylesTable();
-        
-        InputStream themesData = reader.getThemesData();
-        if(themesData != null) {
-            themesData.close();
-        }
+        testNotHandledByWorkbookException(OPCPackage.open(new ByteArrayInputStream(bytes)));
 
-        assertNotNull(reader.getWorkbookData());
-        
-        Iterator<InputStream> sheetsData = reader.getSheetsData();
-        while(sheetsData.hasNext()) {
-            InputStream str = sheetsData.next();
-            str.close();
-        }
     }
-    
-    private void exportToXML(XSSFWorkbook wb) throws SAXException,
-            ParserConfigurationException, TransformerException {
-        for (XSSFMap map : wb.getCustomXMLMappings()) {
-            XSSFExportToXml exporter = new XSSFExportToXml(map);
 
-            ByteArrayOutputStream os = new ByteArrayOutputStream();
-            exporter.exportToXML(os, true);
-        }
-    }
+    private void testNotHandledByWorkbookException(OPCPackage pkg) throws IOException {
 
-    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");
-        
-        // corrupt/invalid
-        EXPECTED_ADDITIONAL_FAILURES.add("openxml4j/invalid.xlsx");
+        try {
+            XSSFWorkbook workbook = new XSSFWorkbook(pkg);
+        } catch (XLSBUnsupportedException e) {
+            //this is what we'd expect
+            //swallow
+        }
     }
 
-    @SuppressWarnings("resource")
     @Override
-    public void handleAdditional(File file) throws Exception {
-        // redirect stdout as the examples often write lots of text
-        PrintStream oldOut = System.out;
+    public void handleExtracting(File file) throws Exception {
+        OPCPackage pkg = OPCPackage.open(file, PackageAccess.READ);
         try {
-            System.setOut(new NullPrintStream());
-            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;
-            }
+            testOne(pkg);
         } finally {
-            System.setOut(oldOut);
+            pkg.close();
         }
-    }
 
-    // a test-case to test this locally without executing the full TestAllFiles
-    @Test
-    public void test() throws Exception {
-        InputStream stream = new BufferedInputStream(new FileInputStream("test-data/spreadsheet/ref-56737.xlsx"));
+        pkg = OPCPackage.open(file, PackageAccess.READ);
         try {
-            handleFile(stream);
+            testNotHandledByWorkbookException(pkg);
         } finally {
-            stream.close();
+            pkg.close();
         }
     }
 
-    // a test-case to test this locally without executing the full TestAllFiles
-    @Test
-    public void testExtractor() throws Exception {
-        handleExtracting(new File("test-data/spreadsheet/ref-56737.xlsx"));
-    }
-
-    @Test
-    public void testAdditional() throws Exception {
-        handleAdditional(new File("test-data/spreadsheet/poc-xmlbomb.xlsx"));
-    }
-    
-    // need to override all methods to omit calls to UTF-handling methods 
-    static class NullPrintStream extends PrintStream {
-        @SuppressWarnings("resource")
-        NullPrintStream() {
-            super(new OutputStream() {
-                @Override
-                public void write(int b) {}
-                @Override
-                public void write(byte[] b) {}
-                @Override
-                public void write(byte[] b, int off, int len) {}
-            });
+    private void testOne(OPCPackage pkg) throws Exception {
+        XSSFBEventBasedExcelExtractor ex = new XSSFBEventBasedExcelExtractor(pkg);
+        String txt = ex.getText();
+        if (txt.length() < 1) {
+            throw new RuntimeException("Should have gotten some text.");
         }
-        @Override
-        public void write(int b) {}
-        @Override
-        public void write(byte[] buf, int off, int len) {}
-        @Override
-        public void print(boolean b) {}
-        @Override
-        public void print(char c) {}
-        @Override
-        public void print(int i) {}
-        @Override
-        public void print(long l) {}
-        @Override
-        public void print(float f) {}
-        @Override
-        public void print(double d) {}
-        @Override
-        public void print(char[] s) {}
-        @Override
-        public void print(String s) {}
-        @Override
-        public void print(Object obj) {}
-        @Override
-        public void println() {}
-        @Override
-        public void println(boolean x) {}
-        @Override
-        public void println(char x) {}
-        @Override
-        public void println(int x) {}
-        @Override
-        public void println(long x) {}
-        @Override
-        public void println(float x) {}
-        @Override
-        public void println(double x) {}
-        @Override
-        public void println(char[] x) {}
-        @Override
-        public void println(String x) {}
-        @Override
-        public void println(Object x) {}
-        @Override
-        public PrintStream printf(String format, Object... args) { return this; }
-        @Override
-        public PrintStream printf(Locale l, String format, Object... args) { return this;
}
-        @Override
-        public PrintStream format(String format, Object... args) { return this; }
-        @Override
-        public PrintStream format(Locale l, String format, Object... args) { return this;
}
-        @Override
-        public PrintStream append(CharSequence csq) { return this; }
-        @Override
-        public PrintStream append(CharSequence csq, int start, int end) { return this; }
-        @Override
-        public PrintStream append(char c) { return this; }
-        @Override
-        public void write(byte[] b) {}
+
     }
+
 }

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=1787264&r1=1787263&r2=1787264&view=diff
==============================================================================
--- poi/trunk/src/integrationtest/org/apache/poi/stress/XSSFFileHandler.java (original)
+++ poi/trunk/src/integrationtest/org/apache/poi/stress/XSSFFileHandler.java Thu Mar 16 22:32:24
2017
@@ -19,18 +19,24 @@ package org.apache.poi.stress;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 
-import java.io.*;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.TransformerException;
+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.OutputStream;
+import java.io.PrintStream;
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.Locale;
 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.NotOfficeXmlFileException;
 import org.apache.poi.openxml4j.exceptions.OLE2NotOfficeXmlFileException;
 import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
 import org.apache.poi.openxml4j.opc.OPCPackage;
@@ -131,8 +137,6 @@ public class XSSFFileHandler extends Spr
         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");
         



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


Mime
View raw message