Enhance integration tests to call some of the common examples/devtools to also trigger these with all sample files, currently XLSX2CSV, BiffViewer, FromHowTo
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1737308 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
26af28bbdb
commit
88e9ff08db
@ -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>
|
||||
|
@ -28,6 +28,7 @@ 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.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;
|
||||
@ -107,6 +108,11 @@ public class XLSX2CSV {
|
||||
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;
|
||||
|
@ -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 {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -133,4 +133,9 @@ public abstract class AbstractFileHandler implements FileHandler {
|
||||
stream.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleAdditional(File file) throws Exception {
|
||||
// by default we do nothing here
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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 SpreadsheetHandler {
|
||||
// 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 {
|
||||
|
@ -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;
|
||||
@ -112,6 +114,66 @@ public class XSSFFileHandler extends SpreadsheetHandler {
|
||||
}
|
||||
}
|
||||
|
||||
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 SpreadsheetHandler {
|
||||
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"));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user