diff options
author | Dominik Stadler <centic@apache.org> | 2013-10-25 21:57:48 +0000 |
---|---|---|
committer | Dominik Stadler <centic@apache.org> | 2013-10-25 21:57:48 +0000 |
commit | c856b750aeae992878cda8f3693faf17fd2fab14 (patch) | |
tree | 473d46e0ec9c36ec3ccfe0c87f1bf13361558ece /src/testcases/org/apache | |
parent | ea257d494a00b552c2f9d5a104b0b089a14558c4 (diff) | |
download | poi-c856b750aeae992878cda8f3693faf17fd2fab14.tar.gz poi-c856b750aeae992878cda8f3693faf17fd2fab14.zip |
Add a number of tests for the dev-tools. The tests iterate over all .xls
files that are found under test-data, any newly added file or
code-change which breaks one of the dev-tools will cause the tests to
fail in the future. Known broken files can be excluded.
Also fixes two points where some files could cause BiffViewer to fail.
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1535885 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/testcases/org/apache')
7 files changed, 332 insertions, 0 deletions
diff --git a/src/testcases/org/apache/poi/hssf/dev/BaseXLSIteratingTest.java b/src/testcases/org/apache/poi/hssf/dev/BaseXLSIteratingTest.java new file mode 100644 index 0000000000..d0b8708903 --- /dev/null +++ b/src/testcases/org/apache/poi/hssf/dev/BaseXLSIteratingTest.java @@ -0,0 +1,86 @@ +package org.apache.poi.hssf.dev; + +import static org.junit.Assert.assertTrue; + +import java.io.File; +import java.io.FilenameFilter; +import java.io.IOException; +import java.io.OutputStream; +import java.util.ArrayList; +import java.util.List; + +import org.junit.Test; + +/** + * 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. + */ +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>(); + + @Test + public void testMain() throws Exception { + int count = runWithDir("test-data/spreadsheet"); + count += runWithDir("test-data/hpsf"); + + System.out.println("Had " + count + " files"); + } + + private int runWithDir(String dir) { + List<String> failed = new ArrayList<String>(); + + String[] files = new File(dir).list(new FilenameFilter() { + public boolean accept(File arg0, String arg1) { + return arg1.toLowerCase().endsWith(".xls"); + } + }); + + 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) { + for(String file : files) { + try { + runOneFile(dir, file, failed); + } catch (Exception e) { + System.out.println("Failed: " + file); + if(SILENT_EXCLUDED.contains(file)) { + continue; + } + + e.printStackTrace(); + if(!EXCLUDED.contains(file)) { + failed.add(file); + } + } + } + } + + abstract void runOneFile(String dir, String file, List<String> failed) throws Exception; + + /** + * Implementation of an OutputStream which does nothing, used + * to redirect stdout to avoid spamming the console with output + */ + private static class NullOutputStream extends OutputStream { + @Override + public void write(byte[] b, int off, int len) { + } + + @Override + public void write(int b) { + } + + @Override + public void write(byte[] b) throws IOException { + } + } +} diff --git a/src/testcases/org/apache/poi/hssf/dev/TestBiffDrawingToXml.java b/src/testcases/org/apache/poi/hssf/dev/TestBiffDrawingToXml.java new file mode 100644 index 0000000000..90c7ec2188 --- /dev/null +++ b/src/testcases/org/apache/poi/hssf/dev/TestBiffDrawingToXml.java @@ -0,0 +1,45 @@ +package org.apache.poi.hssf.dev; + +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; + +public class TestBiffDrawingToXml 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("password.xls"); +// EXCLUDED.add("XRefCalc.xls"); +// EXCLUDED.add("43493.xls"); +// EXCLUDED.add("51832.xls"); + }; + + @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(String dir, String file, List<String> failed) + 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)); + try { + BiffDrawingToXml.writeToFile(NULL_OUTPUT_STREAM, wb, false, new String[] {}); + } finally { + wb.close(); + } + } finally { + System.setOut(save); + } + } +} diff --git a/src/testcases/org/apache/poi/hssf/dev/TestBiffViewer.java b/src/testcases/org/apache/poi/hssf/dev/TestBiffViewer.java new file mode 100644 index 0000000000..19a915cfa2 --- /dev/null +++ b/src/testcases/org/apache/poi/hssf/dev/TestBiffViewer.java @@ -0,0 +1,45 @@ +package org.apache.poi.hssf.dev; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.PrintStream; +import java.util.List; + +import org.apache.poi.poifs.filesystem.POIFSFileSystem; + +public class TestBiffViewer 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("password.xls"); + EXCLUDED.add("NoGutsRecords.xls"); + EXCLUDED.add("BOOK_in_capitals.xls"); + EXCLUDED.add("XRefCalc.xls"); + EXCLUDED.add("50833.xls"); // probably a problem in BiffViewer + EXCLUDED.add("43493.xls"); + EXCLUDED.add("51832.xls"); + EXCLUDED.add("OddStyleRecord.xls"); + + SILENT_EXCLUDED.add("46904.xls"); + }; + + @Override + void runOneFile(String dir, String file, List<String> failed) throws IOException { + FileInputStream inStream = new FileInputStream(new File(dir, file)); + try { + POIFSFileSystem fs = new POIFSFileSystem(inStream); + InputStream is = fs.createDocumentInputStream("Workbook"); + 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); + } finally { + is.close(); + } + } finally { + inStream.close(); + } + } +} diff --git a/src/testcases/org/apache/poi/hssf/dev/TestEFBiffViewer.java b/src/testcases/org/apache/poi/hssf/dev/TestEFBiffViewer.java new file mode 100644 index 0000000000..23807074cd --- /dev/null +++ b/src/testcases/org/apache/poi/hssf/dev/TestEFBiffViewer.java @@ -0,0 +1,30 @@ +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 { + // TODO: is it ok to fail these? + // Look at the output of the test for the detailed stacktrace of the failures... + EXCLUDED.add("password.xls"); + EXCLUDED.add("XRefCalc.xls"); + EXCLUDED.add("43493.xls"); + EXCLUDED.add("51832.xls"); + }; + + @Override + void runOneFile(String dir, String file, List<String> failed) 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() }); + } finally { + System.setOut(save); + } + } +} diff --git a/src/testcases/org/apache/poi/hssf/dev/TestFormulaViewer.java b/src/testcases/org/apache/poi/hssf/dev/TestFormulaViewer.java new file mode 100644 index 0000000000..ec35a4d5d6 --- /dev/null +++ b/src/testcases/org/apache/poi/hssf/dev/TestFormulaViewer.java @@ -0,0 +1,42 @@ +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; + +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"); + }; + + @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(String dir, String file, List<String> failed) 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.setList(true); + viewer.run(); + } finally { + System.setOut(save); + } + } +} diff --git a/src/testcases/org/apache/poi/hssf/dev/TestReSave.java b/src/testcases/org/apache/poi/hssf/dev/TestReSave.java new file mode 100644 index 0000000000..4cdf01591e --- /dev/null +++ b/src/testcases/org/apache/poi/hssf/dev/TestReSave.java @@ -0,0 +1,50 @@ +package org.apache.poi.hssf.dev; + +import java.io.File; +import java.io.PrintStream; +import java.util.List; + +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("password.xls"); + EXCLUDED.add("43493.xls"); + EXCLUDED.add("51832.xls"); + EXCLUDED.add("49219.xls"); + EXCLUDED.add("49931.xls"); + + SILENT_EXCLUDED.add("46904.xls"); + }; + + @Override + void runOneFile(String dir, String file, List<String> failed) throws Exception { + // avoid running on files leftover from previous failed runs + if(file.endsWith("-saved.xls")) { + return; + } + + 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)); + + try { + ReSave.main(new String[] { new File(dir, file).getAbsolutePath() }); + 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() }); + } finally { + // clean up the re-re-saved file + new File(dir, file.replace(".xls", "-saved.xls").replace(".xls", "-saved.xls")).delete(); + } + } finally { + // clean up the re-saved file + new File(dir, file.replace(".xls", "-saved.xls")).delete(); + } + + } finally { + System.setOut(save); + } + } +} diff --git a/src/testcases/org/apache/poi/hssf/dev/TestRecordLister.java b/src/testcases/org/apache/poi/hssf/dev/TestRecordLister.java new file mode 100644 index 0000000000..2afe6399b0 --- /dev/null +++ b/src/testcases/org/apache/poi/hssf/dev/TestRecordLister.java @@ -0,0 +1,34 @@ +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("WORKBOOK_in_capitals.xls"); + EXCLUDED.add("NoGutsRecords.xls"); + EXCLUDED.add("BOOK_in_capitals.xls"); + EXCLUDED.add("OddStyleRecord.xls"); + + SILENT_EXCLUDED.add("46904.xls"); + }; + + @Override + void runOneFile(String dir, String file, List<String> failed) 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.run(); + } finally { + System.setOut(save); + } + } +} |