diff --git a/build.xml b/build.xml index 1bc0579ab2..49a9d901e0 100644 --- a/build.xml +++ b/build.xml @@ -76,6 +76,7 @@ under the License. + @@ -566,12 +567,7 @@ under the License. - - - - - - + @@ -602,10 +598,7 @@ under the License. - - - - + @@ -631,16 +624,8 @@ under the License. - - - - - - - - - - + + @@ -675,15 +660,7 @@ under the License. - - - - - - - - - + @@ -714,14 +691,7 @@ under the License. - - - - - - - - + @@ -748,8 +718,6 @@ under the License. - - @@ -780,14 +748,7 @@ under the License. - - - - - - - - + @@ -811,12 +772,7 @@ under the License. - - - - - - + diff --git a/src/documentation/content/xdocs/status.xml b/src/documentation/content/xdocs/status.xml index 491b65e1da..adbbc79915 100644 --- a/src/documentation/content/xdocs/status.xml +++ b/src/documentation/content/xdocs/status.xml @@ -33,6 +33,7 @@ + moved all test data to a top-level directory 47721 - Added implementation for INDIRECT() 45583 - Avoid exception when reading ClipboardData packet in OLE property sets 47652 - Added support for reading encrypted workbooks diff --git a/src/ooxml/testcases/org/apache/poi/TestEmbeded.java b/src/ooxml/testcases/org/apache/poi/TestEmbeded.java index ddd394cf2d..dd63f2799f 100644 --- a/src/ooxml/testcases/org/apache/poi/TestEmbeded.java +++ b/src/ooxml/testcases/org/apache/poi/TestEmbeded.java @@ -36,34 +36,24 @@ import junit.framework.TestCase; */ public class TestEmbeded extends TestCase { - public String dirname; - - public void setUp() { - dirname = System.getProperty("OOXML.testdata.path"); - assertNotNull(dirname); - } - public void testExcel() throws Exception { - File f = new File(dirname, "ExcelWithAttachments.xlsm"); - assertTrue(f.exists()); - - POIXMLDocument doc = new XSSFWorkbook(OPCPackage.open(f.toString())); + POIXMLDocument doc = new XSSFWorkbook( + POIDataSamples.getSpreadSheetInstance().openResourceAsStream("ExcelWithAttachments.xlsm") + ); test(doc, 4); } public void testWord() throws Exception { - File f = new File(dirname, "WordWithAttachments.docx"); - assertTrue(f.exists()); - - POIXMLDocument doc = new XWPFDocument(OPCPackage.open(f.toString())); + POIXMLDocument doc = new XWPFDocument( + POIDataSamples.getDocumentInstance().openResourceAsStream("WordWithAttachments.docx") + ); test(doc, 5); } public void testPowerPoint() throws Exception { - File f = new File(dirname, "PPTWithAttachments.pptm"); - assertTrue(f.exists()); - - POIXMLDocument doc = new XSLFSlideShow(OPCPackage.open(f.toString())); + POIXMLDocument doc = new XSLFSlideShow(OPCPackage.open( + POIDataSamples.getSlideShowInstance().openResourceAsStream("PPTWithAttachments.pptm")) + ); test(doc, 4); } diff --git a/src/ooxml/testcases/org/apache/poi/TestPOIXMLDocument.java b/src/ooxml/testcases/org/apache/poi/TestPOIXMLDocument.java index 8843f60933..e495df7676 100755 --- a/src/ooxml/testcases/org/apache/poi/TestPOIXMLDocument.java +++ b/src/ooxml/testcases/org/apache/poi/TestPOIXMLDocument.java @@ -30,11 +30,13 @@ import org.apache.poi.openxml4j.opc.OPCPackage; import org.apache.poi.openxml4j.opc.PackagePart; import org.apache.poi.openxml4j.opc.PackageRelationship; import org.apache.poi.util.TempFile; +import org.apache.poi.util.PackageHelper; /** * Test recursive read and write of OPC packages */ public final class TestPOIXMLDocument extends TestCase { + private static class OPCParser extends POIXMLDocument { public OPCParser(OPCPackage pkg) { @@ -81,9 +83,8 @@ public final class TestPOIXMLDocument extends TestCase { } } - public void assertReadWrite(String path) throws Exception { + public void assertReadWrite(OPCPackage pkg1) throws Exception { - OPCPackage pkg1 = OPCPackage.open(path); OPCParser doc = new OPCParser(pkg1); doc.parse(new TestFactory()); @@ -124,17 +125,20 @@ public final class TestPOIXMLDocument extends TestCase { } public void testPPTX() throws Exception { - File file = new File(System.getProperty("OOXML.testdata.path"), "PPTWithAttachments.pptm"); - assertReadWrite(file.getAbsolutePath()); + assertReadWrite( + PackageHelper.open(POIDataSamples.getSlideShowInstance().openResourceAsStream("PPTWithAttachments.pptm")) + ); } public void testXLSX() throws Exception { - File file = new File(System.getProperty("OOXML.testdata.path"), "ExcelWithAttachments.xlsm"); - assertReadWrite(file.getAbsolutePath()); + assertReadWrite( + PackageHelper.open(POIDataSamples.getSpreadSheetInstance().openResourceAsStream("ExcelWithAttachments.xlsm")) + ); } public void testDOCX() throws Exception { - File file = new File(System.getProperty("OOXML.testdata.path"), "WordWithAttachments.docx"); - assertReadWrite(file.getAbsolutePath()); + assertReadWrite( + PackageHelper.open(POIDataSamples.getDocumentInstance().openResourceAsStream("WordWithAttachments.docx")) + ); } } diff --git a/src/ooxml/testcases/org/apache/poi/TestXMLPropertiesTextExtractor.java b/src/ooxml/testcases/org/apache/poi/TestXMLPropertiesTextExtractor.java index 2c0c5b5513..303946a113 100644 --- a/src/ooxml/testcases/org/apache/poi/TestXMLPropertiesTextExtractor.java +++ b/src/ooxml/testcases/org/apache/poi/TestXMLPropertiesTextExtractor.java @@ -21,21 +21,16 @@ import java.io.File; import org.apache.poi.xssf.extractor.XSSFExcelExtractor; import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.apache.poi.openxml4j.opc.OPCPackage; +import org.apache.poi.util.PackageHelper; import junit.framework.TestCase; public final class TestXMLPropertiesTextExtractor extends TestCase { - private String dirname; - - protected void setUp() { - dirname = System.getProperty("OOXML.testdata.path"); - assertTrue( (new File(dirname)).exists() ); - } + private static final POIDataSamples _ssSamples = POIDataSamples.getSpreadSheetInstance(); public void testGetFromMainExtractor() throws Exception { - OPCPackage pkg = OPCPackage.open( - (new File(dirname, "ExcelWithAttachments.xlsm")).toString() - ); + OPCPackage pkg = PackageHelper.open(_ssSamples.openResourceAsStream("ExcelWithAttachments.xlsm")); + XSSFWorkbook wb = new XSSFWorkbook(pkg); XSSFExcelExtractor ext = new XSSFExcelExtractor(wb); @@ -54,8 +49,8 @@ public final class TestXMLPropertiesTextExtractor extends TestCase { } public void testCore() throws Exception { - OPCPackage pkg = OPCPackage.open( - (new File(dirname, "ExcelWithAttachments.xlsm")).toString() + OPCPackage pkg = PackageHelper.open( + _ssSamples.openResourceAsStream("ExcelWithAttachments.xlsm") ); XSSFWorkbook wb = new XSSFWorkbook(pkg); @@ -72,7 +67,7 @@ public final class TestXMLPropertiesTextExtractor extends TestCase { public void testExtended() throws Exception { OPCPackage pkg = OPCPackage.open( - (new File(dirname, "ExcelWithAttachments.xlsm")).toString() + _ssSamples.openResourceAsStream("ExcelWithAttachments.xlsm") ); XSSFWorkbook wb = new XSSFWorkbook(pkg); diff --git a/src/ooxml/testcases/org/apache/poi/extractor/TestExtractorFactory.java b/src/ooxml/testcases/org/apache/poi/extractor/TestExtractorFactory.java index 76daeed760..421b979e3a 100644 --- a/src/ooxml/testcases/org/apache/poi/extractor/TestExtractorFactory.java +++ b/src/ooxml/testcases/org/apache/poi/extractor/TestExtractorFactory.java @@ -22,10 +22,13 @@ import java.io.IOException; import org.apache.poi.POIOLE2TextExtractor; import org.apache.poi.POITextExtractor; +import org.apache.poi.POIDataSamples; import org.apache.poi.hdgf.extractor.VisioTextExtractor; import org.apache.poi.hslf.extractor.PowerPointExtractor; import org.apache.poi.hssf.extractor.ExcelExtractor; +import org.apache.poi.hssf.HSSFTestDataSamples; import org.apache.poi.hwpf.extractor.WordExtractor; +import org.apache.poi.hwpf.HWPFTestDataSamples; import org.apache.poi.poifs.filesystem.POIFSFileSystem; import org.apache.poi.xslf.extractor.XSLFPowerPointExtractor; import org.apache.poi.xssf.extractor.XSSFExcelExtractor; @@ -40,21 +43,18 @@ import org.apache.poi.openxml4j.opc.OPCPackage; * Test that the extractor factory plays nicely */ public class TestExtractorFactory extends TestCase { - private String excel_dir; - private String word_dir; - private String powerpoint_dir; - private String visio_dir; - private String poifs_dir; - + private File txt; private File xls; private File xlsx; - private File xltx; + private File xltx; + private File xlsEmb; private File doc; private File docx; - private File dotx; + private File dotx; + private File docEmb; private File ppt; private File pptx; @@ -64,31 +64,25 @@ public class TestExtractorFactory extends TestCase { protected void setUp() throws Exception { super.setUp(); - excel_dir = System.getProperty("HSSF.testdata.path"); - word_dir = System.getProperty("HWPF.testdata.path"); - powerpoint_dir = System.getProperty("HSLF.testdata.path"); - visio_dir = System.getProperty("HDGF.testdata.path"); - poifs_dir = System.getProperty("POIFS.testdata.path"); - assertNotNull(excel_dir); - assertNotNull(word_dir); - assertNotNull(powerpoint_dir); - assertNotNull(visio_dir); - assertNotNull(poifs_dir); - - txt = new File(powerpoint_dir, "SampleShow.txt"); - - xls = new File(excel_dir, "SampleSS.xls"); - xlsx = new File(excel_dir, "SampleSS.xlsx"); - xltx = new File(excel_dir, "test.xltx"); + POIDataSamples ssTests = POIDataSamples.getSpreadSheetInstance(); + xls = ssTests.getFile("SampleSS.xls"); + xlsx = ssTests.getFile("SampleSS.xlsx"); + xltx = ssTests.getFile("test.xltx"); + xlsEmb = ssTests.getFile("excel_with_embeded.xls"); - doc = new File(word_dir, "SampleDoc.doc"); - docx = new File(word_dir, "SampleDoc.docx"); - dotx = new File(word_dir, "test.dotx"); + POIDataSamples wpTests = POIDataSamples.getDocumentInstance(); + doc = wpTests.getFile("SampleDoc.doc"); + docx = wpTests.getFile("SampleDoc.docx"); + dotx = wpTests.getFile("test.dotx"); + docEmb = wpTests.getFile("word_with_embeded.doc"); - ppt = new File(powerpoint_dir, "SampleShow.ppt"); - pptx = new File(powerpoint_dir, "SampleShow.pptx"); - - vsd = new File(visio_dir, "Test_Visio-Some_Random_Text.vsd"); + POIDataSamples slTests = POIDataSamples.getSlideShowInstance(); + ppt = slTests.getFile("SampleShow.ppt"); + pptx = slTests.getFile("SampleShow.pptx"); + txt = slTests.getFile("SampleShow.txt"); + + POIDataSamples dgTests = POIDataSamples.getDiagramInstance(); + vsd = dgTests.getFile("Test_Visio-Some_Random_Text.vsd"); } public void testFile() throws Exception { @@ -339,8 +333,7 @@ public class TestExtractorFactory extends TestCase { public void testEmbeded() throws Exception { POIOLE2TextExtractor ext; POITextExtractor[] embeds; - File f; - + // No embedings ext = (POIOLE2TextExtractor) ExtractorFactory.createExtractor(xls); @@ -348,9 +341,8 @@ public class TestExtractorFactory extends TestCase { assertEquals(0, embeds.length); // Excel - f = new File(poifs_dir, "excel_with_embeded.xls"); ext = (POIOLE2TextExtractor) - ExtractorFactory.createExtractor(f); + ExtractorFactory.createExtractor(xlsEmb); embeds = ExtractorFactory.getEmbededDocsTextExtractors(ext); assertEquals(6, embeds.length); @@ -367,9 +359,8 @@ public class TestExtractorFactory extends TestCase { assertEquals(2, numWord); // Word - f = new File(poifs_dir, "word_with_embeded.doc"); ext = (POIOLE2TextExtractor) - ExtractorFactory.createExtractor(f); + ExtractorFactory.createExtractor(docEmb); embeds = ExtractorFactory.getEmbededDocsTextExtractors(ext); numWord = 0; numXls = 0; numPpt = 0; diff --git a/src/ooxml/testcases/org/apache/poi/openxml4j/OpenXML4JTestDataSamples.java b/src/ooxml/testcases/org/apache/poi/openxml4j/OpenXML4JTestDataSamples.java index 62291d37bd..edf0179066 100755 --- a/src/ooxml/testcases/org/apache/poi/openxml4j/OpenXML4JTestDataSamples.java +++ b/src/ooxml/testcases/org/apache/poi/openxml4j/OpenXML4JTestDataSamples.java @@ -17,6 +17,9 @@ package org.apache.poi.openxml4j; +import org.apache.poi.POIDataSamples; +import org.apache.poi.util.TempFile; + import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; @@ -28,121 +31,31 @@ import java.io.InputStream; * @author jmicich */ public final class OpenXML4JTestDataSamples { - - private static final String IN_DIR_PROP_NAME = "openxml4j.testdata.input"; - private static final String COMP_IN_DIR_PROP_NAME = "openxml4j.compliance.input"; - - private static File _sampleInputDir; - private static File _sampleOutputDir; - private static File _complianceSampleInputDir; + private static final POIDataSamples _samples = POIDataSamples.getOpenXML4JInstance(); private OpenXML4JTestDataSamples() { // no instances of this class } - + public static InputStream openSampleStream(String sampleFileName) { - File f = getSampleFile(sampleFileName); - try { - return new FileInputStream(f); - } catch (FileNotFoundException e) { - throw new RuntimeException(e); - } + return _samples.openResourceAsStream(sampleFileName); } public static String getSampleFileName(String sampleFileName) { - // TODO - investigate allowing read/write access for package opened on stream return getSampleFile(sampleFileName).getAbsolutePath(); } public static File getSampleFile(String sampleFileName) { - File dir = getSampleInputDir(); - File f = new File(dir, sampleFileName); - if (!f.exists()) { - throw new RuntimeException("Specified sample file '" - + f.getAbsolutePath() + "' does not exist"); - } - if (f.isDirectory()) { - throw new RuntimeException("Specified sample file '" - + f.getAbsolutePath() + "' is a directory"); - } - return f; + return _samples.getFile(sampleFileName); } public static File getOutputFile(String outputFileName) { - File dir = getSampleOutputDir(); - return new File(dir, outputFileName); + String suffix = outputFileName.substring(outputFileName.lastIndexOf('.')); + return TempFile.createTempFile(outputFileName, suffix); } public static InputStream openComplianceSampleStream(String sampleFileName) { - File f = getComplianceSampleFile(sampleFileName); - try { - return new FileInputStream(f); - } catch (FileNotFoundException e) { - throw new RuntimeException(e); - } - } - private static File getComplianceSampleFile(String sampleFileName) { - File dir = getComplianceSampleInputDir(); - File f = new File(dir, sampleFileName); - if (!f.exists()) { - throw new RuntimeException("Specified sample file '" - + f.getAbsolutePath() + "' does not exist"); - } - if (f.isDirectory()) { - throw new RuntimeException("Specified sample file '" - + f.getAbsolutePath() + "' is a directory"); - } - return f; - } - public static String getComplianceSampleFileName(String sampleFileName) { - return getComplianceSampleFile(sampleFileName).getAbsolutePath(); - } - private static File getComplianceSampleInputDir() { - if (_complianceSampleInputDir == null) { - _complianceSampleInputDir = getAndCheckDirByProperty(COMP_IN_DIR_PROP_NAME); - } - return _complianceSampleInputDir; - } - - - private static File getSampleInputDir() { - if (_sampleInputDir == null) { - _sampleInputDir = getAndCheckDirByProperty(IN_DIR_PROP_NAME); - } - return _sampleInputDir; - } - - private static File getAndCheckDirByProperty(String propName) { - String dirName = System.getProperty(propName); - File dir = new File(dirName); - if (!dir.exists()) { - throw new RuntimeException("Specified '" + propName + "' directory: '" - + dirName + "' does not exist"); - } - if (!dir.isDirectory()) { - throw new RuntimeException("Specified '" + propName + "' directory: '" - + dirName + "' is a not a proper directory"); - } - return dir; - } - - private static File getSampleOutputDir() { - if (_sampleOutputDir == null) { - File dir = new File(System.getProperty("java.io.tmpdir"), "poifiles"); - if (dir.exists()) { - if (!dir.isDirectory()) { - throw new RuntimeException("Specified output directory: '" - + dir.getAbsolutePath() + "' is a not a proper directory"); - } - } else { - if (!dir.mkdirs()) { - throw new RuntimeException("Failed to create directory: '" - + dir.getAbsolutePath() + "'"); - } - } - _sampleOutputDir = dir; - } - return _sampleOutputDir; + return _samples.openResourceAsStream(sampleFileName); } } diff --git a/src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/TestOPCComplianceCoreProperties.java b/src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/TestOPCComplianceCoreProperties.java index 7d26fddd7a..b3a4a6320f 100755 --- a/src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/TestOPCComplianceCoreProperties.java +++ b/src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/TestOPCComplianceCoreProperties.java @@ -33,6 +33,7 @@ import org.apache.poi.openxml4j.opc.OPCPackage; import org.apache.poi.openxml4j.opc.PackageRelationshipTypes; import org.apache.poi.openxml4j.opc.PackagingURIHelper; import org.apache.poi.openxml4j.opc.TargetMode; +import org.apache.poi.POIDataSamples; /** * Test core properties Open Packaging Convention compliance. @@ -144,11 +145,11 @@ public final class TestOPCComplianceCoreProperties extends TestCase { * Test M4.1 rule. */ public void testOnlyOneCorePropertiesPart_AddPart() { - String sampleFileName = OpenXML4JTestDataSamples.getComplianceSampleFileName("OPCCompliance_CoreProperties_OnlyOneCorePropertiesPart.docx"); + String sampleFileName = "OPCCompliance_CoreProperties_OnlyOneCorePropertiesPart.docx"; OPCPackage pkg = null; try { - pkg = OPCPackage.open(sampleFileName); - } catch (InvalidFormatException e) { + pkg = OPCPackage.open(POIDataSamples.getOpenXML4JInstance().getFile(sampleFileName).getPath()); + } catch (Exception e) { throw new RuntimeException(e); } diff --git a/src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/TestOPCCompliancePackageModel.java b/src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/TestOPCCompliancePackageModel.java index b07c8c51bc..e3c54f367e 100755 --- a/src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/TestOPCCompliancePackageModel.java +++ b/src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/TestOPCCompliancePackageModel.java @@ -18,6 +18,7 @@ package org.apache.poi.openxml4j.opc.compliance; import java.io.File; +import java.io.IOException; import junit.framework.TestCase; @@ -29,6 +30,7 @@ import org.apache.poi.openxml4j.opc.PackagePartName; import org.apache.poi.openxml4j.opc.PackageRelationshipTypes; import org.apache.poi.openxml4j.opc.PackagingURIHelper; import org.apache.poi.openxml4j.opc.TargetMode; +import org.apache.poi.POIDataSamples; /** * Test Open Packaging Convention package model compliance. @@ -70,11 +72,10 @@ public class TestOPCCompliancePackageModel extends TestCase { * part name derived from another part name by appending segments to it. * [M1.11] */ - public void testPartNameDerivationReadingFailure() { - String filepath = System.getProperty("openxml4j.compliance.input") - + File.separator + "OPCCompliance_DerivedPartNameFAIL.docx"; + public void testPartNameDerivationReadingFailure() throws IOException { + String filename = "OPCCompliance_DerivedPartNameFAIL.docx"; try { - OPCPackage.open(filepath); + OPCPackage.open(POIDataSamples.getOpenXML4JInstance().openResourceAsStream(filename)); } catch (InvalidFormatException e) { return; } diff --git a/src/ooxml/testcases/org/apache/poi/openxml4j/opc/internal/data/sample.docx b/src/ooxml/testcases/org/apache/poi/openxml4j/opc/internal/data/sample.docx deleted file mode 100755 index dc87bc817a..0000000000 Binary files a/src/ooxml/testcases/org/apache/poi/openxml4j/opc/internal/data/sample.docx and /dev/null differ diff --git a/src/ooxml/testcases/org/apache/poi/xslf/TestXSLFSlideShow.java b/src/ooxml/testcases/org/apache/poi/xslf/TestXSLFSlideShow.java index e1e821323c..03d50ca608 100644 --- a/src/ooxml/testcases/org/apache/poi/xslf/TestXSLFSlideShow.java +++ b/src/ooxml/testcases/org/apache/poi/xslf/TestXSLFSlideShow.java @@ -16,31 +16,23 @@ ==================================================================== */ package org.apache.poi.xslf; -import java.io.File; - import junit.framework.TestCase; -import org.apache.poi.POIXMLDocument; +import org.apache.poi.POIDataSamples; import org.apache.poi.openxml4j.opc.OPCPackage; import org.apache.poi.openxml4j.opc.PackagePart; import org.openxmlformats.schemas.presentationml.x2006.main.CTSlideIdListEntry; import org.openxmlformats.schemas.presentationml.x2006.main.CTSlideMasterIdListEntry; public class TestXSLFSlideShow extends TestCase { - private String sampleFile; + private static final POIDataSamples slTests = POIDataSamples.getSlideShowInstance(); + private OPCPackage pack; - protected void setUp() throws Exception { - super.setUp(); - - sampleFile = new File( - System.getProperty("HSLF.testdata.path") + - File.separator + "sample.pptx" - ).toString(); + protected void setUp() throws Exception { + pack = OPCPackage.open(slTests.openResourceAsStream("sample.pptx")); } public void testContainsMainContentType() throws Exception { - OPCPackage pack = POIXMLDocument.openPackage(sampleFile); - boolean found = false; for(PackagePart part : pack.getParts()) { if(part.getContentType().equals(XSLFSlideShow.MAIN_CONTENT_TYPE)) { @@ -52,15 +44,11 @@ public class TestXSLFSlideShow extends TestCase { } public void testOpen() throws Exception { - POIXMLDocument.openPackage(sampleFile); - + XSLFSlideShow xml; // With the finalised uri, should be fine - xml = new XSLFSlideShow( - POIXMLDocument.openPackage(sampleFile) - ); - + xml = new XSLFSlideShow(pack); // Check the core assertNotNull(xml.getPresentation()); @@ -74,7 +62,7 @@ public class TestXSLFSlideShow extends TestCase { } public void testSlideBasics() throws Exception { - XSLFSlideShow xml = new XSLFSlideShow(sampleFile); + XSLFSlideShow xml = new XSLFSlideShow(pack); // Should have 1 master assertEquals(1, xml.getSlideMasterReferences().sizeOfSldMasterIdArray()); @@ -108,7 +96,7 @@ public class TestXSLFSlideShow extends TestCase { } public void testMetadataBasics() throws Exception { - XSLFSlideShow xml = new XSLFSlideShow(sampleFile); + XSLFSlideShow xml = new XSLFSlideShow(pack); assertNotNull(xml.getProperties().getCoreProperties()); assertNotNull(xml.getProperties().getExtendedProperties()); diff --git a/src/ooxml/testcases/org/apache/poi/xslf/extractor/TestXSLFPowerPointExtractor.java b/src/ooxml/testcases/org/apache/poi/xslf/extractor/TestXSLFPowerPointExtractor.java index ac31356374..334e556465 100644 --- a/src/ooxml/testcases/org/apache/poi/xslf/extractor/TestXSLFPowerPointExtractor.java +++ b/src/ooxml/testcases/org/apache/poi/xslf/extractor/TestXSLFPowerPointExtractor.java @@ -16,9 +16,8 @@ ==================================================================== */ package org.apache.poi.xslf.extractor; -import java.io.File; - -import org.apache.poi.POIXMLDocument; +import org.apache.poi.POIDataSamples; +import org.apache.poi.openxml4j.opc.OPCPackage; import org.apache.poi.xslf.XSLFSlideShow; import junit.framework.TestCase; @@ -31,18 +30,12 @@ public class TestXSLFPowerPointExtractor extends TestCase { * A simple file */ private XSLFSlideShow xmlA; - private File fileA; + private OPCPackage pkg; protected void setUp() throws Exception { - super.setUp(); - - fileA = new File( - System.getProperty("HSLF.testdata.path") + - File.separator + "sample.pptx" - ); - assertTrue(fileA.exists()); - - xmlA = new XSLFSlideShow(fileA.toString()); + POIDataSamples slTests = POIDataSamples.getSlideShowInstance(); + pkg = OPCPackage.open(slTests.openResourceAsStream("sample.pptx")); + xmlA = new XSLFSlideShow(pkg); } /** @@ -50,8 +43,7 @@ public class TestXSLFPowerPointExtractor extends TestCase { */ public void testGetSimpleText() throws Exception { new XSLFPowerPointExtractor(xmlA); - new XSLFPowerPointExtractor( - POIXMLDocument.openPackage(fileA.toString())); + new XSLFPowerPointExtractor(pkg); XSLFPowerPointExtractor extractor = new XSLFPowerPointExtractor(xmlA); @@ -110,13 +102,8 @@ public class TestXSLFPowerPointExtractor extends TestCase { } public void testGetComments() throws Exception { - File file = new File( - System.getProperty("HSLF.testdata.path") + - File.separator + "45545_Comment.pptx" - ); - assertTrue(file.exists()); - - xmlA = new XSLFSlideShow(file.toString()); + POIDataSamples slTests = POIDataSamples.getSlideShowInstance(); + xmlA = new XSLFSlideShow(OPCPackage.open(slTests.openResourceAsStream("45545_Comment.pptx"))); XSLFPowerPointExtractor extractor = new XSLFPowerPointExtractor(xmlA); diff --git a/src/ooxml/testcases/org/apache/poi/xssf/XSSFITestDataProvider.java b/src/ooxml/testcases/org/apache/poi/xssf/XSSFITestDataProvider.java index 4d04a10151..58dde48bfa 100755 --- a/src/ooxml/testcases/org/apache/poi/xssf/XSSFITestDataProvider.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/XSSFITestDataProvider.java @@ -22,6 +22,7 @@ import org.apache.poi.ss.SpreadsheetVersion; import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.apache.poi.hssf.HSSFTestDataSamples; +import org.apache.poi.POIDataSamples; /** * @author Yegor Kozlov @@ -45,7 +46,7 @@ public final class XSSFITestDataProvider implements ITestDataProvider { } public byte[] getTestDataFileContent(String fileName) { - return HSSFTestDataSamples.getTestDataFileContent(fileName); + return POIDataSamples.getSpreadSheetInstance().readFile(fileName); } public SpreadsheetVersion getSpreadsheetVersion(){ diff --git a/src/ooxml/testcases/org/apache/poi/xssf/XSSFTestDataSamples.java b/src/ooxml/testcases/org/apache/poi/xssf/XSSFTestDataSamples.java index 94df0da632..166c3b35e5 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/XSSFTestDataSamples.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/XSSFTestDataSamples.java @@ -38,15 +38,8 @@ import org.apache.poi.util.TempFile; * @author Josh Micich */ public class XSSFTestDataSamples { - - public static InputStream openSampleFileStream(String sampleFileName) { - return HSSFTestDataSamples.openSampleFileStream(sampleFileName); - } - public static byte[] getTestDataFileContent(String fileName) { - return HSSFTestDataSamples.getTestDataFileContent(fileName); - } - public static final XSSFWorkbook openSampleWorkbook(String sampleName) { + public static XSSFWorkbook openSampleWorkbook(String sampleName) { InputStream is = HSSFTestDataSamples.openSampleFileStream(sampleName); try { return new XSSFWorkbook(is); @@ -57,24 +50,17 @@ public class XSSFTestDataSamples { public static R writeOutAndReadBack(R wb) { Workbook result; try { + ByteArrayOutputStream baos = new ByteArrayOutputStream(8192); + wb.write(baos); + InputStream is = new ByteArrayInputStream(baos.toByteArray()); if (wb instanceof HSSFWorkbook) { - ByteArrayOutputStream baos = new ByteArrayOutputStream(8192); - wb.write(baos); - InputStream is = new ByteArrayInputStream(baos.toByteArray()); result = new HSSFWorkbook(is); } else if (wb instanceof XSSFWorkbook) { - File tmp = TempFile.createTempFile("poi-ooxml-", ".xlsx"); - FileOutputStream out = new FileOutputStream(tmp); - wb.write(out); - out.close(); - OPCPackage pkg = OPCPackage.open(tmp.getAbsolutePath()); - result = new XSSFWorkbook(pkg); + result = new XSSFWorkbook(is); } else { - throw new RuntimeException("Unexpected workbook type (" + throw new RuntimeException("Unexpected workbook type (" + wb.getClass().getName() + ")"); } - } catch (InvalidFormatException e) { - throw new RuntimeException(e); } catch (IOException e) { throw new RuntimeException(e); } diff --git a/src/ooxml/testcases/org/apache/poi/xssf/data/sample.xlsx b/src/ooxml/testcases/org/apache/poi/xssf/data/sample.xlsx deleted file mode 100644 index a275cf417e..0000000000 Binary files a/src/ooxml/testcases/org/apache/poi/xssf/data/sample.xlsx and /dev/null differ diff --git a/src/ooxml/testcases/org/apache/poi/xssf/eventusermodel/TestXSSFReader.java b/src/ooxml/testcases/org/apache/poi/xssf/eventusermodel/TestXSSFReader.java index 0ace7c3f63..0592fbcc76 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/eventusermodel/TestXSSFReader.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/eventusermodel/TestXSSFReader.java @@ -26,14 +26,16 @@ import org.apache.poi.openxml4j.opc.OPCPackage; import org.apache.poi.util.IOUtils; import org.apache.poi.xssf.XSSFTestDataSamples; import org.apache.poi.xssf.usermodel.XSSFRichTextString; +import org.apache.poi.POIDataSamples; /** * Tests for {@link XSSFReader} */ public final class TestXSSFReader extends TestCase { + private static POIDataSamples _ssTests = POIDataSamples.getSpreadSheetInstance(); - public void testGetBits() throws Exception { - OPCPackage pkg = OPCPackage.open(XSSFTestDataSamples.openSampleFileStream("SampleSS.xlsx")); + public void testGetBits() throws Exception { + OPCPackage pkg = OPCPackage.open(_ssTests.openResourceAsStream("SampleSS.xlsx")); XSSFReader r = new XSSFReader(pkg); @@ -46,7 +48,7 @@ public final class TestXSSFReader extends TestCase { } public void testStyles() throws Exception { - OPCPackage pkg = OPCPackage.open(XSSFTestDataSamples.openSampleFileStream("SampleSS.xlsx")); + OPCPackage pkg = OPCPackage.open(_ssTests.openResourceAsStream("SampleSS.xlsx")); XSSFReader r = new XSSFReader(pkg); @@ -55,7 +57,7 @@ public final class TestXSSFReader extends TestCase { } public void testStrings() throws Exception { - OPCPackage pkg = OPCPackage.open(XSSFTestDataSamples.openSampleFileStream("SampleSS.xlsx")); + OPCPackage pkg = OPCPackage.open(_ssTests.openResourceAsStream("SampleSS.xlsx")); XSSFReader r = new XSSFReader(pkg); @@ -64,7 +66,7 @@ public final class TestXSSFReader extends TestCase { } public void testSheets() throws Exception { - OPCPackage pkg = OPCPackage.open(XSSFTestDataSamples.openSampleFileStream("SampleSS.xlsx")); + OPCPackage pkg = OPCPackage.open(_ssTests.openResourceAsStream("SampleSS.xlsx")); XSSFReader r = new XSSFReader(pkg); byte[] data = new byte[4096]; @@ -96,7 +98,7 @@ public final class TestXSSFReader extends TestCase { * (as they are defined in the workbook.xml) */ public void testOrderOfSheets() throws Exception { - OPCPackage pkg = OPCPackage.open(XSSFTestDataSamples.openSampleFileStream("reordered_sheets.xlsx")); + OPCPackage pkg = OPCPackage.open(_ssTests.openResourceAsStream("reordered_sheets.xlsx")); XSSFReader r = new XSSFReader(pkg); diff --git a/src/ooxml/testcases/org/apache/poi/xssf/io/TestLoadSaveXSSF.java b/src/ooxml/testcases/org/apache/poi/xssf/io/TestLoadSaveXSSF.java index 0f739f750e..f635eea850 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/io/TestLoadSaveXSSF.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/io/TestLoadSaveXSSF.java @@ -28,23 +28,15 @@ import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.apache.poi.xssf.usermodel.XSSFPictureData; +import org.apache.poi.xssf.XSSFITestDataProvider; +import org.apache.poi.POIDataSamples; public class TestLoadSaveXSSF extends TestCase { - - String filename; - - protected void setUp() { - - System.setProperty("org.apache.poi.util.POILogger", org.apache.poi.util.CommonsLogger.class.getName()); - filename = System.getProperty("XSSF.testdata.path"); - if (filename == null) { - filename = "src/ooxml/testcases/org/apache/poi/xssf/data"; - } - } + private static final POIDataSamples _ssSampels = POIDataSamples.getSpreadSheetInstance(); public void testLoadSample() throws Exception { - XSSFWorkbook workbook = new XSSFWorkbook(new File(filename, "sample.xlsx").getAbsolutePath()); + XSSFWorkbook workbook = new XSSFWorkbook(_ssSampels.openResourceAsStream("sample.xlsx")); assertEquals(3, workbook.getNumberOfSheets()); assertEquals("Sheet1", workbook.getSheetName(0)); Sheet sheet = workbook.getSheetAt(0); @@ -58,7 +50,7 @@ public class TestLoadSaveXSSF extends TestCase { // TODO filename string hard coded in XSSFWorkbook constructor in order to make ant test-ooxml target be successful. public void testLoadStyles() throws Exception { - XSSFWorkbook workbook = new XSSFWorkbook(new File(filename, "styles.xlsx").getAbsolutePath()); + XSSFWorkbook workbook = new XSSFWorkbook(_ssSampels.openResourceAsStream("styles.xlsx")); Sheet sheet = workbook.getSheetAt(0); Row row = sheet.getRow(0); Cell cell = row.getCell((short) 0); @@ -68,7 +60,7 @@ public class TestLoadSaveXSSF extends TestCase { // TODO filename string hard coded in XSSFWorkbook constructor in order to make ant test-ooxml target be successful. public void testLoadPictures() throws Exception { - XSSFWorkbook workbook = new XSSFWorkbook(new File(filename, "picture.xlsx").getAbsolutePath()); + XSSFWorkbook workbook = new XSSFWorkbook(_ssSampels.openResourceAsStream("picture.xlsx")); List pictures = workbook.getAllPictures(); assertEquals(1, pictures.size()); } diff --git a/src/ooxml/testcases/org/apache/poi/xwpf/XWPFTestDataSamples.java b/src/ooxml/testcases/org/apache/poi/xwpf/XWPFTestDataSamples.java index 3255d62f10..945ffebe6d 100755 --- a/src/ooxml/testcases/org/apache/poi/xwpf/XWPFTestDataSamples.java +++ b/src/ooxml/testcases/org/apache/poi/xwpf/XWPFTestDataSamples.java @@ -28,7 +28,7 @@ import java.io.*; public class XWPFTestDataSamples { public static XWPFDocument openSampleDocument(String sampleName) { - InputStream is = HWPFTestDataSamples.openSampleFileStream(sampleName); + InputStream is = POIDataSamples.getDocumentInstance().openResourceAsStream(sampleName); try { return new XWPFDocument(is); } catch (IOException e) { @@ -46,9 +46,4 @@ public class XWPFTestDataSamples { throw new RuntimeException(e); } } - - public static POIDataSamples getInstance(){ - return HWPFTestDataSamples.getInstance(); - } - } diff --git a/src/scratchpad/testcases/org/apache/poi/TestPOIDocumentScratchpad.java b/src/scratchpad/testcases/org/apache/poi/TestPOIDocumentScratchpad.java index 8c9224fd9d..7e7d0b249a 100644 --- a/src/scratchpad/testcases/org/apache/poi/TestPOIDocumentScratchpad.java +++ b/src/scratchpad/testcases/org/apache/poi/TestPOIDocumentScratchpad.java @@ -25,7 +25,7 @@ import junit.framework.TestCase; import java.io.*; import org.apache.poi.hslf.HSLFSlideShow; -import org.apache.poi.hwpf.HWPFDocument; +import org.apache.poi.hwpf.HWPFTestDataSamples; import org.apache.poi.poifs.filesystem.*; /** @@ -41,29 +41,15 @@ public final class TestPOIDocumentScratchpad extends TestCase { // The POI Documents to work on private POIDocument doc; private POIDocument doc2; - // POIFS primed on the test (powerpoint and word) data - private POIFSFileSystem pfs; - private POIFSFileSystem pfs2; /** * Set things up, using a PowerPoint document and * a Word Document for our testing */ public void setUp() throws Exception { - String dirnameHSLF = System.getProperty("HSLF.testdata.path"); - String filenameHSLF = dirnameHSLF + "/basic_test_ppt_file.ppt"; - String dirnameHSSF = System.getProperty("HSSF.testdata.path"); - String filenameHSSF = dirnameHSLF + "/DateFormats.ppt"; - String dirnameHWPF = System.getProperty("HWPF.testdata.path"); - String filenameHWPF = dirnameHWPF + "/test2.doc"; + doc = new HSLFSlideShow(POIDataSamples.getSlideShowInstance().openResourceAsStream("basic_test_ppt_file.ppt")); - FileInputStream fisHSLF = new FileInputStream(filenameHSLF); - pfs = new POIFSFileSystem(fisHSLF); - doc = new HSLFSlideShow(pfs); - - FileInputStream fisHWPF = new FileInputStream(filenameHWPF); - pfs2 = new POIFSFileSystem(fisHWPF); - doc2 = new HWPFDocument(pfs2); + doc2 = HWPFTestDataSamples.openSampleFile("test2.doc"); } public void testReadProperties() { diff --git a/src/scratchpad/testcases/org/apache/poi/hdf/model/TestHDFDocument.java b/src/scratchpad/testcases/org/apache/poi/hdf/model/TestHDFDocument.java index 4f4b4707b8..42f79caf40 100644 --- a/src/scratchpad/testcases/org/apache/poi/hdf/model/TestHDFDocument.java +++ b/src/scratchpad/testcases/org/apache/poi/hdf/model/TestHDFDocument.java @@ -23,6 +23,7 @@ import java.io.IOException; import java.io.InputStream; import junit.framework.TestCase; +import org.apache.poi.POIDataSamples; /** * Class to test {@link HDFDocument} functionality @@ -30,19 +31,12 @@ import junit.framework.TestCase; * @author Bob Otterberg */ public final class TestHDFDocument extends TestCase { + private static final POIDataSamples _samples = POIDataSamples.getDocumentInstance(); + public void testStopJUnitComplainintAboutNoTests() { // TODO - fix these junits } - private static InputStream openSample(String sampleFileName) { - String fullPathName = System.getProperty("HDF.testdata.path") + "/" + sampleFileName; - try { - return new FileInputStream(System.getProperty("HDF.testdata.path")); - } catch (FileNotFoundException e) { - throw new RuntimeException("Sample HDF file '" + fullPathName + "' was not found."); - } - } - /** * OBJECTIVE: Test that HDF can read an empty document (empty.doc).

* SUCCESS: HDF reads the document. Matches values in their particular positions.

@@ -50,7 +44,7 @@ public final class TestHDFDocument extends TestCase { * in the document in their known positions.

*/ public void fixme_testEmpty() throws IOException { - InputStream stream = openSample("empty.doc"); + InputStream stream = _samples.openResourceAsStream("empty.doc"); new HDFDocument(stream); } @@ -61,7 +55,7 @@ public final class TestHDFDocument extends TestCase { * in the document in their known positions.

*/ public void fixme_testSimple() throws IOException { - InputStream stream = openSample("simple.doc"); + InputStream stream = _samples.openResourceAsStream("simple.doc"); new HDFDocument(stream); } @@ -73,7 +67,7 @@ public final class TestHDFDocument extends TestCase { * */ public void fixme_testSimpleList() throws IOException { - InputStream stream = openSample("simple-list.doc"); + InputStream stream = _samples.openResourceAsStream("simple-list.doc"); new HDFDocument(stream); } @@ -84,7 +78,7 @@ public final class TestHDFDocument extends TestCase { * in the document in their known positions.

*/ public void fixme_testSimpleTable() throws IOException { - InputStream stream = openSample("simple-table.doc"); + InputStream stream = _samples.openResourceAsStream("simple-table.doc"); new HDFDocument(stream); } } diff --git a/src/scratchpad/testcases/org/apache/poi/hdgf/TestHDGFCore.java b/src/scratchpad/testcases/org/apache/poi/hdgf/TestHDGFCore.java index e98c8110a0..d6616b9147 100644 --- a/src/scratchpad/testcases/org/apache/poi/hdgf/TestHDGFCore.java +++ b/src/scratchpad/testcases/org/apache/poi/hdgf/TestHDGFCore.java @@ -22,18 +22,17 @@ import java.io.FileInputStream; import org.apache.poi.hdgf.streams.PointerContainingStream; import org.apache.poi.hdgf.streams.TrailerStream; import org.apache.poi.poifs.filesystem.POIFSFileSystem; +import org.apache.poi.POIDataSamples; import junit.framework.TestCase; public final class TestHDGFCore extends TestCase { + private static POIDataSamples _dgTests = POIDataSamples.getDiagramInstance(); + private POIFSFileSystem fs; - private String dirname; - private String filename; protected void setUp() throws Exception { - dirname = System.getProperty("HDGF.testdata.path"); - filename = dirname + "/Test_Visio-Some_Random_Text.vsd"; - fs = new POIFSFileSystem(new FileInputStream(filename)); + fs = new POIFSFileSystem(_dgTests.openResourceAsStream("Test_Visio-Some_Random_Text.vsd")); } public void testCreate() throws Exception { @@ -68,8 +67,7 @@ public final class TestHDGFCore extends TestCase { * appears to have a negative chunk length */ public void DISABLEDtestNegativeChunkLength() throws Exception { - filename = dirname + "/NegativeChunkLength.vsd"; - fs = new POIFSFileSystem(new FileInputStream(filename)); + fs = new POIFSFileSystem(_dgTests.openResourceAsStream("NegativeChunkLength.vsd")); HDGFDiagram hdgf = new HDGFDiagram(fs); assertNotNull(hdgf); diff --git a/src/scratchpad/testcases/org/apache/poi/hdgf/extractor/TestVisioExtractor.java b/src/scratchpad/testcases/org/apache/poi/hdgf/extractor/TestVisioExtractor.java index 16bd9a961e..30b8db4fbd 100644 --- a/src/scratchpad/testcases/org/apache/poi/hdgf/extractor/TestVisioExtractor.java +++ b/src/scratchpad/testcases/org/apache/poi/hdgf/extractor/TestVisioExtractor.java @@ -19,20 +19,20 @@ package org.apache.poi.hdgf.extractor; import java.io.ByteArrayOutputStream; import java.io.File; -import java.io.FileInputStream; import java.io.PrintStream; import junit.framework.TestCase; import org.apache.poi.hdgf.HDGFDiagram; import org.apache.poi.poifs.filesystem.POIFSFileSystem; +import org.apache.poi.POIDataSamples; public final class TestVisioExtractor extends TestCase { - private String dirname; + private static POIDataSamples _dgTests = POIDataSamples.getDiagramInstance(); + private String defFilename; protected void setUp() { - dirname = System.getProperty("HDGF.testdata.path"); - defFilename = dirname + "/Test_Visio-Some_Random_Text.vsd"; + defFilename = "Test_Visio-Some_Random_Text.vsd"; } /** @@ -41,14 +41,14 @@ public final class TestVisioExtractor extends TestCase { public void testCreation() throws Exception { VisioTextExtractor extractor; - extractor = new VisioTextExtractor(new FileInputStream(defFilename)); + extractor = new VisioTextExtractor(_dgTests.openResourceAsStream(defFilename)); assertNotNull(extractor); assertNotNull(extractor.getAllText()); assertEquals(3, extractor.getAllText().length); extractor = new VisioTextExtractor( new POIFSFileSystem( - new FileInputStream(defFilename) + _dgTests.openResourceAsStream(defFilename) ) ); assertNotNull(extractor); @@ -58,7 +58,7 @@ public final class TestVisioExtractor extends TestCase { extractor = new VisioTextExtractor( new HDGFDiagram( new POIFSFileSystem( - new FileInputStream(defFilename) + _dgTests.openResourceAsStream(defFilename) ) ) ); @@ -69,7 +69,7 @@ public final class TestVisioExtractor extends TestCase { public void testExtraction() throws Exception { VisioTextExtractor extractor = - new VisioTextExtractor(new FileInputStream(defFilename)); + new VisioTextExtractor(_dgTests.openResourceAsStream(defFilename)); // Check the array fetch String[] text = extractor.getAllText(); @@ -86,20 +86,11 @@ public final class TestVisioExtractor extends TestCase { } public void testProblemFiles() throws Exception { - File a = new File(dirname, "44594.vsd"); - VisioTextExtractor.main(new String[] {a.toString()}); - - File b = new File(dirname, "44594-2.vsd"); - VisioTextExtractor.main(new String[] {b.toString()}); - - File c = new File(dirname, "ShortChunk1.vsd"); - VisioTextExtractor.main(new String[] {c.toString()}); - - File d = new File(dirname, "ShortChunk2.vsd"); - VisioTextExtractor.main(new String[] {d.toString()}); - - File e = new File(dirname, "ShortChunk3.vsd"); - VisioTextExtractor.main(new String[] {e.toString()}); + String[] files = {"44594.vsd", "44594-2.vsd", "ShortChunk1.vsd", "ShortChunk2.vsd", "ShortChunk3.vsd"}; + for(String file : files){ + VisioTextExtractor ex = new VisioTextExtractor(_dgTests.openResourceAsStream(file)); + ex.getText(); + } } public void testMain() throws Exception { @@ -108,7 +99,8 @@ public final class TestVisioExtractor extends TestCase { PrintStream capture = new PrintStream(baos); System.setOut(capture); - VisioTextExtractor.main(new String[] {defFilename}); + String path = _dgTests.getFile(defFilename).getPath(); + VisioTextExtractor.main(new String[] {path}); // Put things back System.setOut(oldOut); diff --git a/src/scratchpad/testcases/org/apache/poi/hdgf/streams/TestStreamBugs.java b/src/scratchpad/testcases/org/apache/poi/hdgf/streams/TestStreamBugs.java index 66c3907082..5ba377afdf 100644 --- a/src/scratchpad/testcases/org/apache/poi/hdgf/streams/TestStreamBugs.java +++ b/src/scratchpad/testcases/org/apache/poi/hdgf/streams/TestStreamBugs.java @@ -18,6 +18,7 @@ package org.apache.poi.hdgf.streams; import java.io.FileInputStream; +import java.io.InputStream; import org.apache.poi.hdgf.HDGFDiagram; import org.apache.poi.hdgf.chunks.ChunkFactory; @@ -25,6 +26,7 @@ import org.apache.poi.hdgf.pointers.Pointer; import org.apache.poi.hdgf.pointers.PointerFactory; import org.apache.poi.poifs.filesystem.DocumentEntry; import org.apache.poi.poifs.filesystem.POIFSFileSystem; +import org.apache.poi.POIDataSamples; /** * Tests for bugs with streams @@ -36,13 +38,11 @@ public final class TestStreamBugs extends StreamTest { private POIFSFileSystem filesystem; protected void setUp() throws Exception { - String dirname = System.getProperty("HDGF.testdata.path"); - String filename = dirname + "/44594.vsd"; ptrFactory = new PointerFactory(11); chunkFactory = new ChunkFactory(11); - FileInputStream fin = new FileInputStream(filename); - filesystem = new POIFSFileSystem(fin); + InputStream is = POIDataSamples.getDiagramInstance().openResourceAsStream("44594.vsd"); + filesystem = new POIFSFileSystem(is); DocumentEntry docProps = (DocumentEntry)filesystem.getRoot().getEntry("VisioDocument"); diff --git a/src/scratchpad/testcases/org/apache/poi/hdgf/streams/TestStreamComplex.java b/src/scratchpad/testcases/org/apache/poi/hdgf/streams/TestStreamComplex.java index a06c03aa24..6aa2b2e31c 100644 --- a/src/scratchpad/testcases/org/apache/poi/hdgf/streams/TestStreamComplex.java +++ b/src/scratchpad/testcases/org/apache/poi/hdgf/streams/TestStreamComplex.java @@ -18,6 +18,7 @@ package org.apache.poi.hdgf.streams; import java.io.FileInputStream; +import java.io.InputStream; import org.apache.poi.hdgf.chunks.Chunk; import org.apache.poi.hdgf.chunks.ChunkFactory; @@ -25,6 +26,7 @@ import org.apache.poi.hdgf.pointers.Pointer; import org.apache.poi.hdgf.pointers.PointerFactory; import org.apache.poi.poifs.filesystem.DocumentEntry; import org.apache.poi.poifs.filesystem.POIFSFileSystem; +import org.apache.poi.POIDataSamples; public final class TestStreamComplex extends StreamTest { private byte[] contents; @@ -34,13 +36,11 @@ public final class TestStreamComplex extends StreamTest { private PointerFactory ptrFactory; protected void setUp() throws Exception { - String dirname = System.getProperty("HDGF.testdata.path"); - String filename = dirname + "/Test_Visio-Some_Random_Text.vsd"; ptrFactory = new PointerFactory(11); chunkFactory = new ChunkFactory(11); - FileInputStream fin = new FileInputStream(filename); - POIFSFileSystem filesystem = new POIFSFileSystem(fin); + InputStream is = POIDataSamples.getDiagramInstance().openResourceAsStream("Test_Visio-Some_Random_Text.vsd"); + POIFSFileSystem filesystem = new POIFSFileSystem(is); DocumentEntry docProps = (DocumentEntry)filesystem.getRoot().getEntry("VisioDocument"); diff --git a/src/scratchpad/testcases/org/apache/poi/hpbf/TestHPBFDocument.java b/src/scratchpad/testcases/org/apache/poi/hpbf/TestHPBFDocument.java index 96e1591e02..4ea2793774 100644 --- a/src/scratchpad/testcases/org/apache/poi/hpbf/TestHPBFDocument.java +++ b/src/scratchpad/testcases/org/apache/poi/hpbf/TestHPBFDocument.java @@ -21,27 +21,22 @@ import java.io.File; import java.io.FileInputStream; import junit.framework.TestCase; +import org.apache.poi.POIDataSamples; public final class TestHPBFDocument extends TestCase { - private String dir; - - protected void setUp() { - dir = System.getProperty("HPBF.testdata.path"); - } + private static final POIDataSamples _samples = POIDataSamples.getPublisherInstance(); public void testOpen() throws Exception { - File f = new File(dir, "Sample.pub"); HPBFDocument doc = new HPBFDocument( - new FileInputStream(f) + _samples.openResourceAsStream("Sample.pub") ); assertNotNull(doc); } public void testBits() throws Exception { - File f = new File(dir, "Sample.pub"); HPBFDocument doc = new HPBFDocument( - new FileInputStream(f) + _samples.openResourceAsStream("Sample.pub") ); assertNotNull(doc.getMainContents()); diff --git a/src/scratchpad/testcases/org/apache/poi/hpbf/extractor/TextPublisherTextExtractor.java b/src/scratchpad/testcases/org/apache/poi/hpbf/extractor/TextPublisherTextExtractor.java index 7aceb66d43..fd3c97fe72 100644 --- a/src/scratchpad/testcases/org/apache/poi/hpbf/extractor/TextPublisherTextExtractor.java +++ b/src/scratchpad/testcases/org/apache/poi/hpbf/extractor/TextPublisherTextExtractor.java @@ -21,37 +21,31 @@ import java.io.File; import java.io.FileInputStream; import org.apache.poi.hpbf.HPBFDocument; +import org.apache.poi.POIDataSamples; import junit.framework.TestCase; public final class TextPublisherTextExtractor extends TestCase { - private String dir; - - protected void setUp() { - dir = System.getProperty("HPBF.testdata.path"); - } + private static final POIDataSamples _samples = POIDataSamples.getPublisherInstance(); public void testBasics() throws Exception { - File f = new File(dir, "Sample.pub"); HPBFDocument doc = new HPBFDocument( - new FileInputStream(f) + _samples.openResourceAsStream("Sample.pub") ); PublisherTextExtractor ext = new PublisherTextExtractor(doc); ext.getText(); - f = new File(dir, "Simple.pub"); ext = new PublisherTextExtractor( - new FileInputStream(f) + _samples.openResourceAsStream("Simple.pub") ); ext.getText(); } public void testContents() throws Exception { - File f = new File(dir, "Sample.pub"); HPBFDocument doc = new HPBFDocument( - new FileInputStream(f) + _samples.openResourceAsStream("Sample.pub") ); PublisherTextExtractor ext = @@ -87,9 +81,8 @@ public final class TextPublisherTextExtractor extends TestCase { ); // Now a simpler one - f = new File(dir, "Simple.pub"); ext = new PublisherTextExtractor( - new FileInputStream(f) + _samples.openResourceAsStream("Simple.pub") ); text = ext.getText(); assertEquals( @@ -113,21 +106,18 @@ public final class TextPublisherTextExtractor extends TestCase { File f; HPBFDocument doc; - f = new File(dir, "Sample.pub"); doc = new HPBFDocument( - new FileInputStream(f) + _samples.openResourceAsStream("Sample.pub") ); String s2007 = (new PublisherTextExtractor(doc)).getText(); - f = new File(dir, "Sample2000.pub"); doc = new HPBFDocument( - new FileInputStream(f) + _samples.openResourceAsStream("Sample2000.pub") ); String s2000 = (new PublisherTextExtractor(doc)).getText(); - f = new File(dir, "Sample98.pub"); doc = new HPBFDocument( - new FileInputStream(f) + _samples.openResourceAsStream("Sample98.pub") ); String s98 = (new PublisherTextExtractor(doc)).getText(); @@ -141,9 +131,8 @@ public final class TextPublisherTextExtractor extends TestCase { * as we can hope it to. */ public void testWithHyperlinks() throws Exception { - File f = new File(dir, "LinkAt10.pub"); HPBFDocument doc = new HPBFDocument( - new FileInputStream(f) + _samples.openResourceAsStream("LinkAt10.pub") ); PublisherTextExtractor ext = @@ -159,8 +148,9 @@ public final class TextPublisherTextExtractor extends TestCase { // Now a much more complex document - f = new File(dir, "Sample.pub"); - ext = new PublisherTextExtractor(new FileInputStream(f)); + ext = new PublisherTextExtractor( + _samples.openResourceAsStream("Sample.pub") + ); ext.setHyperlinksByDefault(true); String text = ext.getText(); diff --git a/src/scratchpad/testcases/org/apache/poi/hpbf/model/TestEscherParts.java b/src/scratchpad/testcases/org/apache/poi/hpbf/model/TestEscherParts.java index 702c5fd8f3..0df03e16eb 100644 --- a/src/scratchpad/testcases/org/apache/poi/hpbf/model/TestEscherParts.java +++ b/src/scratchpad/testcases/org/apache/poi/hpbf/model/TestEscherParts.java @@ -21,20 +21,16 @@ import java.io.File; import java.io.FileInputStream; import org.apache.poi.hpbf.HPBFDocument; +import org.apache.poi.POIDataSamples; import junit.framework.TestCase; public final class TestEscherParts extends TestCase { - private String dir; - - protected void setUp() { - dir = System.getProperty("HPBF.testdata.path"); - } + private static final POIDataSamples _samples = POIDataSamples.getPublisherInstance(); public void testBasics() throws Exception { - File f = new File(dir, "Sample.pub"); HPBFDocument doc = new HPBFDocument( - new FileInputStream(f) + _samples.openResourceAsStream("Sample.pub") ); EscherStm es = doc.getEscherStm(); @@ -50,9 +46,8 @@ public final class TestEscherParts extends TestCase { } public void testComplex() throws Exception { - File f = new File(dir, "SampleBrochure.pub"); HPBFDocument doc = new HPBFDocument( - new FileInputStream(f) + _samples.openResourceAsStream("SampleBrochure.pub") ); EscherStm es = doc.getEscherStm(); @@ -68,9 +63,8 @@ public final class TestEscherParts extends TestCase { // Now do another complex file - f = new File(dir, "SampleNewsletter.pub"); doc = new HPBFDocument( - new FileInputStream(f) + _samples.openResourceAsStream("SampleNewsletter.pub") ); es = doc.getEscherStm(); diff --git a/src/scratchpad/testcases/org/apache/poi/hpbf/model/TestQuillContents.java b/src/scratchpad/testcases/org/apache/poi/hpbf/model/TestQuillContents.java index 6a80c86286..b88e45b028 100644 --- a/src/scratchpad/testcases/org/apache/poi/hpbf/model/TestQuillContents.java +++ b/src/scratchpad/testcases/org/apache/poi/hpbf/model/TestQuillContents.java @@ -17,29 +17,22 @@ package org.apache.poi.hpbf.model; -import java.io.File; -import java.io.FileInputStream; - import org.apache.poi.hpbf.HPBFDocument; import org.apache.poi.hpbf.model.qcbits.QCTextBit; import org.apache.poi.hpbf.model.qcbits.QCPLCBit.Type12; import org.apache.poi.hpbf.model.qcbits.QCPLCBit.Type0; import org.apache.poi.hpbf.model.qcbits.QCPLCBit.Type4; import org.apache.poi.hpbf.model.qcbits.QCPLCBit.Type8; +import org.apache.poi.POIDataSamples; import junit.framework.TestCase; public final class TestQuillContents extends TestCase { - private String dir; - - protected void setUp() { - dir = System.getProperty("HPBF.testdata.path"); - } + private static final POIDataSamples _samples = POIDataSamples.getPublisherInstance(); public void testBasics() throws Exception { - File f = new File(dir, "Sample.pub"); HPBFDocument doc = new HPBFDocument( - new FileInputStream(f) + _samples.openResourceAsStream("Sample.pub") ); QuillContents qc = doc.getQuillContents(); @@ -69,9 +62,8 @@ public final class TestQuillContents extends TestCase { } public void testText() throws Exception { - File f = new File(dir, "Sample.pub"); HPBFDocument doc = new HPBFDocument( - new FileInputStream(f) + _samples.openResourceAsStream("Sample.pub") ); QuillContents qc = doc.getQuillContents(); @@ -84,9 +76,8 @@ public final class TestQuillContents extends TestCase { } public void testPLC() throws Exception { - File f = new File(dir, "Simple.pub"); HPBFDocument doc = new HPBFDocument( - new FileInputStream(f) + _samples.openResourceAsStream("Simple.pub") ); QuillContents qc = doc.getQuillContents(); @@ -145,9 +136,8 @@ public final class TestQuillContents extends TestCase { } public void testComplexPLC() throws Exception { - File f = new File(dir, "Sample.pub"); HPBFDocument doc = new HPBFDocument( - new FileInputStream(f) + _samples.openResourceAsStream("Sample.pub") ); QuillContents qc = doc.getQuillContents(); @@ -247,9 +237,8 @@ public final class TestQuillContents extends TestCase { } public void testNoHyperlinks() throws Exception { - File f = new File(dir, "SampleNewsletter.pub"); HPBFDocument doc = new HPBFDocument( - new FileInputStream(f) + _samples.openResourceAsStream("SampleNewsletter.pub") ); QuillContents qc = doc.getQuillContents(); @@ -264,15 +253,13 @@ public final class TestQuillContents extends TestCase { } public void testSimpleHyperlink() throws Exception { - File f; HPBFDocument doc; QuillContents qc; Type12 hlBit; // Link at 10 - f = new File(dir, "LinkAt10.pub"); doc = new HPBFDocument( - new FileInputStream(f) + _samples.openResourceAsStream("LinkAt10.pub") ); qc = doc.getQuillContents(); @@ -285,9 +272,8 @@ public final class TestQuillContents extends TestCase { assertEquals("http://poi.apache.org/", hlBit.getHyperlink(0)); // Longer link at 10 - f = new File(dir, "LinkAt10Longer.pub"); doc = new HPBFDocument( - new FileInputStream(f) + _samples.openResourceAsStream("LinkAt10Longer.pub") ); qc = doc.getQuillContents(); @@ -300,9 +286,8 @@ public final class TestQuillContents extends TestCase { assertEquals("http://poi.apache.org/hpbf/", hlBit.getHyperlink(0)); // Link at 20 - f = new File(dir, "LinkAt20.pub"); doc = new HPBFDocument( - new FileInputStream(f) + _samples.openResourceAsStream("LinkAt20.pub") ); qc = doc.getQuillContents(); @@ -316,15 +301,13 @@ public final class TestQuillContents extends TestCase { } public void testManyHyperlinks() throws Exception { - File f; HPBFDocument doc; QuillContents qc; Type12 hlBit; // Link at 10 - f = new File(dir, "LinkAt10.pub"); doc = new HPBFDocument( - new FileInputStream(f) + _samples.openResourceAsStream("LinkAt10.pub") ); qc = doc.getQuillContents(); @@ -339,16 +322,14 @@ public final class TestQuillContents extends TestCase { } public void testHyperlinkDifferentVersions() throws Exception { - File f; HPBFDocument doc; QuillContents qc; Type12 hlBitA; Type12 hlBitB; // Latest version - f = new File(dir, "Sample.pub"); doc = new HPBFDocument( - new FileInputStream(f) + _samples.openResourceAsStream("Sample.pub") ); qc = doc.getQuillContents(); @@ -375,9 +356,8 @@ public final class TestQuillContents extends TestCase { assertEquals("mailto:dev@poi.apache.org?subject=HPBF", hlBitB.getHyperlink(2)); // 2000 version - f = new File(dir, "Sample2000.pub"); doc = new HPBFDocument( - new FileInputStream(f) + _samples.openResourceAsStream("Sample2000.pub") ); qc = doc.getQuillContents(); @@ -404,9 +384,8 @@ public final class TestQuillContents extends TestCase { assertEquals("mailto:dev@poi.apache.org?subject=HPBF", hlBitB.getHyperlink(2)); // 98 version - f = new File(dir, "Sample98.pub"); doc = new HPBFDocument( - new FileInputStream(f) + _samples.openResourceAsStream("Sample98.pub") ); qc = doc.getQuillContents(); diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/TestEncryptedFile.java b/src/scratchpad/testcases/org/apache/poi/hslf/TestEncryptedFile.java index 892cb81387..da07810b86 100644 --- a/src/scratchpad/testcases/org/apache/poi/hslf/TestEncryptedFile.java +++ b/src/scratchpad/testcases/org/apache/poi/hslf/TestEncryptedFile.java @@ -21,6 +21,7 @@ package org.apache.poi.hslf; import junit.framework.TestCase; import org.apache.poi.hslf.exceptions.EncryptedPowerPointFileException; +import org.apache.poi.POIDataSamples; /** * Tests that HSLFSlideShow does the right thing with an encrypted file @@ -28,48 +29,31 @@ import org.apache.poi.hslf.exceptions.EncryptedPowerPointFileException; * @author Nick Burch (nick at torchbox dot com) */ public final class TestEncryptedFile extends TestCase { - // A non encrypted file - private String ss_ne; - // An encrypted file, with encrypted properties - private String ss_e; - // An encrypted file, without encrypted properties - private String ss_np_e; - // An encrypted file, with a 56 bit key - private String ss_56_e; - - - public TestEncryptedFile() { - String dirname = System.getProperty("HSLF.testdata.path"); - - ss_ne = dirname + "/basic_test_ppt_file.ppt"; - ss_e = dirname + "/Password_Protected-hello.ppt"; - ss_np_e = dirname + "/Password_Protected-np-hello.ppt"; - ss_56_e = dirname + "/Password_Protected-56-hello.ppt"; - } + private static POIDataSamples slTests = POIDataSamples.getSlideShowInstance(); public void testLoadNonEncrypted() throws Exception { - HSLFSlideShow hss = new HSLFSlideShow(ss_ne); + HSLFSlideShow hss = new HSLFSlideShow(slTests.openResourceAsStream("basic_test_ppt_file.ppt")); assertNotNull(hss); } public void testLoadEncrypted() throws Exception { try { - new HSLFSlideShow(ss_e); + new HSLFSlideShow(slTests.openResourceAsStream("Password_Protected-hello.ppt")); fail(); } catch(EncryptedPowerPointFileException e) { // Good } try { - new HSLFSlideShow(ss_np_e); + new HSLFSlideShow(slTests.openResourceAsStream("Password_Protected-np-hello.ppt")); fail(); } catch(EncryptedPowerPointFileException e) { // Good } try { - new HSLFSlideShow(ss_56_e); + new HSLFSlideShow(slTests.openResourceAsStream("Password_Protected-56-hello.ppt")); fail(); } catch(EncryptedPowerPointFileException e) { // Good diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/TestReWrite.java b/src/scratchpad/testcases/org/apache/poi/hslf/TestReWrite.java index b1468f2c55..ff918ad03d 100644 --- a/src/scratchpad/testcases/org/apache/poi/hslf/TestReWrite.java +++ b/src/scratchpad/testcases/org/apache/poi/hslf/TestReWrite.java @@ -19,10 +19,14 @@ package org.apache.poi.hslf; import junit.framework.TestCase; -import java.io.*; import org.apache.poi.hslf.usermodel.SlideShow; import org.apache.poi.poifs.filesystem.*; +import org.apache.poi.POIDataSamples; + +import java.io.ByteArrayOutputStream; +import java.io.ByteArrayInputStream; +import java.io.FileNotFoundException; /** * Tests that HSLFSlideShow writes the powerpoint bit of data back out @@ -41,21 +45,16 @@ public final class TestReWrite extends TestCase { private POIFSFileSystem pfsC; public void setUp() throws Exception { - String dirname = System.getProperty("HSLF.testdata.path"); - String filenameA = dirname + "/basic_test_ppt_file.ppt"; - FileInputStream fisA = new FileInputStream(filenameA); - pfsA = new POIFSFileSystem(fisA); + POIDataSamples slTests = POIDataSamples.getSlideShowInstance(); + + pfsA = new POIFSFileSystem(slTests.openResourceAsStream("basic_test_ppt_file.ppt")); hssA = new HSLFSlideShow(pfsA); - String filenameB = dirname + "/ParagraphStylesShorterThanCharStyles.ppt"; - FileInputStream fisB = new FileInputStream(filenameB); - pfsB = new POIFSFileSystem(fisB); + pfsB = new POIFSFileSystem(slTests.openResourceAsStream("ParagraphStylesShorterThanCharStyles.ppt")); hssB = new HSLFSlideShow(pfsB); - String filenameC = dirname + "/WithMacros.ppt"; - FileInputStream fisC = new FileInputStream(filenameC); - pfsC = new POIFSFileSystem(fisC); + pfsC = new POIFSFileSystem(slTests.openResourceAsStream("WithMacros.ppt")); hssC = new HSLFSlideShow(pfsC); } diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/TestReWriteSanity.java b/src/scratchpad/testcases/org/apache/poi/hslf/TestReWriteSanity.java index 7467021544..4590e551ce 100644 --- a/src/scratchpad/testcases/org/apache/poi/hslf/TestReWriteSanity.java +++ b/src/scratchpad/testcases/org/apache/poi/hslf/TestReWriteSanity.java @@ -23,6 +23,7 @@ import java.io.*; import java.util.*; import org.apache.poi.hslf.record.*; import org.apache.poi.poifs.filesystem.*; +import org.apache.poi.POIDataSamples; /** * Tests that HSLFSlideShow writes the powerpoint bit of data back out @@ -37,10 +38,8 @@ public final class TestReWriteSanity extends TestCase { private POIFSFileSystem pfs; public TestReWriteSanity() throws Exception { - String dirname = System.getProperty("HSLF.testdata.path"); - String filename = dirname + "/basic_test_ppt_file.ppt"; - FileInputStream fis = new FileInputStream(filename); - pfs = new POIFSFileSystem(fis); + POIDataSamples slTests = POIDataSamples.getSlideShowInstance(); + pfs = new POIFSFileSystem(slTests.openResourceAsStream("basic_test_ppt_file.ppt")); ss = new HSLFSlideShow(pfs); } diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/TestRecordCounts.java b/src/scratchpad/testcases/org/apache/poi/hslf/TestRecordCounts.java index 16e0c2785c..5d509b6203 100644 --- a/src/scratchpad/testcases/org/apache/poi/hslf/TestRecordCounts.java +++ b/src/scratchpad/testcases/org/apache/poi/hslf/TestRecordCounts.java @@ -20,6 +20,7 @@ package org.apache.poi.hslf; import junit.framework.TestCase; import org.apache.poi.hslf.record.*; +import org.apache.poi.POIDataSamples; /** * Tests that HSLFSlideShow returns the right numbers of key records when @@ -32,9 +33,8 @@ public final class TestRecordCounts extends TestCase { private HSLFSlideShow ss; public TestRecordCounts() throws Exception { - String dirname = System.getProperty("HSLF.testdata.path"); - String filename = dirname + "/basic_test_ppt_file.ppt"; - ss = new HSLFSlideShow(filename); + POIDataSamples slTests = POIDataSamples.getSlideShowInstance(); + ss = new HSLFSlideShow(slTests.openResourceAsStream("basic_test_ppt_file.ppt")); } public void testSheetsCount() { diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/extractor/TestCruddyExtractor.java b/src/scratchpad/testcases/org/apache/poi/hslf/extractor/TestCruddyExtractor.java index fdcc45e0b9..8b236b31ee 100644 --- a/src/scratchpad/testcases/org/apache/poi/hslf/extractor/TestCruddyExtractor.java +++ b/src/scratchpad/testcases/org/apache/poi/hslf/extractor/TestCruddyExtractor.java @@ -21,6 +21,8 @@ package org.apache.poi.hslf.extractor; import junit.framework.TestCase; import java.util.Vector; +import org.apache.poi.POIDataSamples; + /** * Tests that the QuickButCruddyTextExtractor works correctly * @@ -56,9 +58,8 @@ public final class TestCruddyExtractor extends TestCase { }; public TestCruddyExtractor() throws Exception { - String dirname = System.getProperty("HSLF.testdata.path"); - String filename = dirname + "/basic_test_ppt_file.ppt"; - te = new QuickButCruddyTextExtractor(filename); + POIDataSamples slTests = POIDataSamples.getSlideShowInstance(); + te = new QuickButCruddyTextExtractor(slTests.openResourceAsStream("basic_test_ppt_file.ppt")); } public void testReadAsVector() { diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/extractor/TestExtractor.java b/src/scratchpad/testcases/org/apache/poi/hslf/extractor/TestExtractor.java index 769638bf02..66316be7df 100644 --- a/src/scratchpad/testcases/org/apache/poi/hslf/extractor/TestExtractor.java +++ b/src/scratchpad/testcases/org/apache/poi/hslf/extractor/TestExtractor.java @@ -28,6 +28,7 @@ import org.apache.poi.poifs.filesystem.DirectoryNode; import org.apache.poi.poifs.filesystem.POIFSFileSystem; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.hwpf.HWPFDocument; +import org.apache.poi.POIDataSamples; import junit.framework.TestCase; @@ -41,19 +42,15 @@ public final class TestExtractor extends TestCase { private PowerPointExtractor ppe; /** Extractor primed on the 1 page but text-box'd test data */ private PowerPointExtractor ppe2; - /** Where to go looking for our test files */ - private String dirname; /** Where our embeded files live */ - private String pdirname; + //private String pdirname; + private static POIDataSamples slTests = POIDataSamples.getSlideShowInstance(); + //private String pdirname; protected void setUp() throws Exception { - dirname = System.getProperty("HSLF.testdata.path"); - String filename = dirname + "/basic_test_ppt_file.ppt"; - ppe = new PowerPointExtractor(filename); - String filename2 = dirname + "/with_textbox.ppt"; - ppe2 = new PowerPointExtractor(filename2); - - pdirname = System.getProperty("POIFS.testdata.path"); + + ppe = new PowerPointExtractor(slTests.openResourceAsStream("basic_test_ppt_file.ppt")); + ppe2 = new PowerPointExtractor(slTests.openResourceAsStream("with_textbox.ppt")); } public void testReadSheetText() { @@ -114,8 +111,7 @@ public final class TestExtractor extends TestCase { * @throws Exception */ public void testMissingCoreRecords() throws Exception { - String filename = dirname + "/missing_core_records.ppt"; - ppe = new PowerPointExtractor(filename); + ppe = new PowerPointExtractor(slTests.openResourceAsStream("missing_core_records.ppt")); String text = ppe.getText(true, false); String nText = ppe.getNotes(); @@ -141,72 +137,67 @@ public final class TestExtractor extends TestCase { } public void testExtractFromEmbeded() throws Exception { - String filename3 = pdirname + "/excel_with_embeded.xls"; - POIFSFileSystem fs = new POIFSFileSystem( - new FileInputStream(filename3) - ); - HSLFSlideShow ss; - - DirectoryNode dirA = (DirectoryNode) - fs.getRoot().getEntry("MBD0000A3B6"); - DirectoryNode dirB = (DirectoryNode) - fs.getRoot().getEntry("MBD0000A3B3"); - - assertNotNull(dirA.getEntry("PowerPoint Document")); - assertNotNull(dirB.getEntry("PowerPoint Document")); - - // Check the first file - ss = new HSLFSlideShow(dirA, fs); - ppe = new PowerPointExtractor(ss); - assertEquals("Sample PowerPoint file\nThis is the 1st file\nNot much too it\n", - ppe.getText(true, false) - ); + POIFSFileSystem fs = new POIFSFileSystem( + POIDataSamples.getSpreadSheetInstance().openResourceAsStream("excel_with_embeded.xls") + ); + HSLFSlideShow ss; - // And the second - ss = new HSLFSlideShow(dirB, fs); - ppe = new PowerPointExtractor(ss); - assertEquals("Sample PowerPoint file\nThis is the 2nd file\nNot much too it either\n", - ppe.getText(true, false) - ); - } + DirectoryNode dirA = (DirectoryNode) + fs.getRoot().getEntry("MBD0000A3B6"); + DirectoryNode dirB = (DirectoryNode) + fs.getRoot().getEntry("MBD0000A3B3"); - /** - * A powerpoint file with embeded powerpoint files - */ - public void testExtractFromOwnEmbeded() throws Exception { - String path = pdirname + "/ppt_with_embeded.ppt"; - ppe = new PowerPointExtractor(path); - List shapes = ppe.getOLEShapes(); - assertEquals("Expected 6 ole shapes in " + path, 6, shapes.size()); - int num_ppt = 0, num_doc = 0, num_xls = 0; - for(OLEShape ole : shapes) { - String name = ole.getInstanceName(); - InputStream data = ole.getObjectData().getData(); - if ("Worksheet".equals(name)) { - HSSFWorkbook wb = new HSSFWorkbook(data); - num_xls++; - } else if ("Document".equals(name)) { - HWPFDocument doc = new HWPFDocument(data); - num_doc++; - } else if ("Presentation".equals(name)) { - num_ppt++; - SlideShow ppt = new SlideShow(data); - } - } - assertEquals("Expected 2 embedded Word Documents", 2, num_doc); - assertEquals("Expected 2 embedded Excel Spreadsheets", 2, num_xls); - assertEquals("Expected 2 embedded PowerPoint Presentations", 2, num_ppt); - } + assertNotNull(dirA.getEntry("PowerPoint Document")); + assertNotNull(dirB.getEntry("PowerPoint Document")); + + // Check the first file + ss = new HSLFSlideShow(dirA, fs); + ppe = new PowerPointExtractor(ss); + assertEquals("Sample PowerPoint file\nThis is the 1st file\nNot much too it\n", + ppe.getText(true, false) + ); + + // And the second + ss = new HSLFSlideShow(dirB, fs); + ppe = new PowerPointExtractor(ss); + assertEquals("Sample PowerPoint file\nThis is the 2nd file\nNot much too it either\n", + ppe.getText(true, false) + ); + } + + /** + * A powerpoint file with embeded powerpoint files + */ + public void testExtractFromOwnEmbeded() throws Exception { + String path = "ppt_with_embeded.ppt"; + ppe = new PowerPointExtractor(POIDataSamples.getSlideShowInstance().openResourceAsStream(path)); + List shapes = ppe.getOLEShapes(); + assertEquals("Expected 6 ole shapes in " + path, 6, shapes.size()); + int num_ppt = 0, num_doc = 0, num_xls = 0; + for(OLEShape ole : shapes) { + String name = ole.getInstanceName(); + InputStream data = ole.getObjectData().getData(); + if ("Worksheet".equals(name)) { + HSSFWorkbook wb = new HSSFWorkbook(data); + num_xls++; + } else if ("Document".equals(name)) { + HWPFDocument doc = new HWPFDocument(data); + num_doc++; + } else if ("Presentation".equals(name)) { + num_ppt++; + SlideShow ppt = new SlideShow(data); + } + } + assertEquals("Expected 2 embedded Word Documents", 2, num_doc); + assertEquals("Expected 2 embedded Excel Spreadsheets", 2, num_xls); + assertEquals("Expected 2 embedded PowerPoint Presentations", 2, num_ppt); + } /** * From bug #45543 */ public void testWithComments() throws Exception { - String filename; - - // New file - filename = dirname + "/WithComments.ppt"; - ppe = new PowerPointExtractor(filename); + ppe = new PowerPointExtractor(slTests.openResourceAsStream("WithComments.ppt")); String text = ppe.getText(); assertFalse("Comments not in by default", contains(text, "This is a test comment")); @@ -218,8 +209,7 @@ public final class TestExtractor extends TestCase { // And another file - filename = dirname + "/45543.ppt"; - ppe = new PowerPointExtractor(filename); + ppe = new PowerPointExtractor(slTests.openResourceAsStream("45543.ppt")); text = ppe.getText(); assertFalse("Comments not in by default", contains(text, "testdoc")); @@ -234,11 +224,10 @@ public final class TestExtractor extends TestCase { * From bug #45537 */ public void testHeaderFooter() throws Exception { - String filename, text; - + String text; + // With a header on the notes - filename = dirname + "/45537_Header.ppt"; - HSLFSlideShow hslf = new HSLFSlideShow(new FileInputStream(filename)); + HSLFSlideShow hslf = new HSLFSlideShow(slTests.openResourceAsStream("45537_Header.ppt")); SlideShow ss = new SlideShow(hslf); assertNotNull(ss.getNotesHeadersFooters()); assertEquals("testdoc test phrase", ss.getNotesHeadersFooters().getHeaderText()); @@ -256,13 +245,12 @@ public final class TestExtractor extends TestCase { // And with a footer, also on notes - filename = dirname + "/45537_Footer.ppt"; - hslf = new HSLFSlideShow(new FileInputStream(filename)); + hslf = new HSLFSlideShow(slTests.openResourceAsStream("45537_Footer.ppt")); ss = new SlideShow(hslf); assertNotNull(ss.getNotesHeadersFooters()); assertEquals("testdoc test phrase", ss.getNotesHeadersFooters().getFooterText()); - ppe = new PowerPointExtractor(filename); + ppe = new PowerPointExtractor(slTests.openResourceAsStream("45537_Footer.ppt")); text = ppe.getText(); assertFalse("Unable to find expected word in text\n" + text, contains(text, "testdoc")); diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestBackground.java b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestBackground.java index e1ac1914f6..69e7a6b37f 100644 --- a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestBackground.java +++ b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestBackground.java @@ -24,6 +24,7 @@ import java.awt.*; import org.apache.poi.hslf.usermodel.SlideShow; import org.apache.poi.hslf.HSLFSlideShow; +import org.apache.poi.POIDataSamples; /** * Test Fill object. @@ -31,6 +32,7 @@ import org.apache.poi.hslf.HSLFSlideShow; * @author Yegor Kozlov */ public final class TestBackground extends TestCase { + private static POIDataSamples _slTests = POIDataSamples.getSlideShowInstance(); /** * Default background for slide, shape and slide master. @@ -52,7 +54,7 @@ public final class TestBackground extends TestCase { * Read fill information from an reference ppt file */ public void testReadBackground() throws Exception { - SlideShow ppt = new SlideShow(new HSLFSlideShow(System.getProperty("HSLF.testdata.path") + "/backgrounds.ppt")); + SlideShow ppt = new SlideShow(_slTests.openResourceAsStream("backgrounds.ppt")); Fill fill; Shape shape; @@ -93,7 +95,7 @@ public final class TestBackground extends TestCase { slide = ppt.createSlide(); slide.setFollowMasterBackground(false); fill = slide.getBackground().getFill(); - idx = ppt.addPicture(new File(System.getProperty("HSLF.testdata.path") + "/tomcat.png"), Picture.PNG); + idx = ppt.addPicture(_slTests.readFile("tomcat.png"), Picture.PNG); fill.setFillType(Fill.FILL_PICTURE); fill.setPictureData(idx); @@ -107,7 +109,7 @@ public final class TestBackground extends TestCase { slide = ppt.createSlide(); slide.setFollowMasterBackground(false); fill = slide.getBackground().getFill(); - idx = ppt.addPicture(new File(System.getProperty("HSLF.testdata.path") + "/tomcat.png"), Picture.PNG); + idx = ppt.addPicture(_slTests.readFile("tomcat.png"), Picture.PNG); fill.setFillType(Fill.FILL_PATTERN); fill.setPictureData(idx); fill.setBackgroundColor(Color.green); @@ -123,7 +125,7 @@ public final class TestBackground extends TestCase { slide = ppt.createSlide(); slide.setFollowMasterBackground(false); fill = slide.getBackground().getFill(); - idx = ppt.addPicture(new File(System.getProperty("HSLF.testdata.path") + "/tomcat.png"), Picture.PNG); + idx = ppt.addPicture(_slTests.readFile("tomcat.png"), Picture.PNG); fill.setFillType(Fill.FILL_TEXTURE); fill.setPictureData(idx); @@ -131,7 +133,7 @@ public final class TestBackground extends TestCase { shape.setAnchor(new java.awt.Rectangle(100, 100, 200, 200)); fill = shape.getFill(); fill.setFillType(Fill.FILL_PICTURE); - idx = ppt.addPicture(new File(System.getProperty("HSLF.testdata.path") + "/clock.jpg"), Picture.JPEG); + idx = ppt.addPicture(_slTests.readFile("clock.jpg"), Picture.JPEG); fill.setPictureData(idx); slide.addShape(shape); diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestHeadersFooters.java b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestHeadersFooters.java index cf94e04539..1e86b8c3af 100644 --- a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestHeadersFooters.java +++ b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestHeadersFooters.java @@ -19,6 +19,7 @@ package org.apache.poi.hslf.model; import java.io.*; import org.apache.poi.hslf.usermodel.SlideShow; +import org.apache.poi.POIDataSamples; import junit.framework.TestCase; @@ -28,14 +29,11 @@ import junit.framework.TestCase; public final class TestHeadersFooters extends TestCase { - public static final String cwd = System.getProperty("HSLF.testdata.path"); + private static POIDataSamples _slTests = POIDataSamples.getSlideShowInstance(); public void testRead() throws Exception { - File file = new File(cwd, "headers_footers.ppt"); - FileInputStream is = new FileInputStream(file); - SlideShow ppt = new SlideShow(is); - is.close(); + SlideShow ppt = new SlideShow(_slTests.openResourceAsStream("headers_footers.ppt")); HeadersFooters slideHdd = ppt.getSlideHeadersFooters(); assertTrue(slideHdd.isFooterVisible()); @@ -79,10 +77,7 @@ public final class TestHeadersFooters extends TestCase */ public void testReadNoHeadersFooters() throws Exception { - File file = new File(cwd, "basic_test_ppt_file.ppt"); - FileInputStream is = new FileInputStream(file); - SlideShow ppt = new SlideShow(is); - is.close(); + SlideShow ppt = new SlideShow(_slTests.openResourceAsStream("basic_test_ppt_file.ppt")); HeadersFooters slideHdd = ppt.getSlideHeadersFooters(); assertFalse(slideHdd.isFooterVisible()); @@ -119,10 +114,7 @@ public final class TestHeadersFooters extends TestCase */ public void testRead2007() throws Exception { - File file = new File(cwd, "headers_footers_2007.ppt"); - FileInputStream is = new FileInputStream(file); - SlideShow ppt = new SlideShow(is); - is.close(); + SlideShow ppt = new SlideShow(_slTests.openResourceAsStream("headers_footers_2007.ppt")); HeadersFooters slideHdd = ppt.getSlideHeadersFooters(); assertTrue(slideHdd.isFooterVisible()); diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestHyperlink.java b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestHyperlink.java index 48de8804e9..6f9f9eb8b4 100644 --- a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestHyperlink.java +++ b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestHyperlink.java @@ -19,10 +19,8 @@ package org.apache.poi.hslf.model; import junit.framework.TestCase; -import java.io.FileInputStream; -import java.io.File; - import org.apache.poi.hslf.usermodel.SlideShow; +import org.apache.poi.POIDataSamples; /** * Test Hyperlink. @@ -30,12 +28,10 @@ import org.apache.poi.hslf.usermodel.SlideShow; * @author Yegor Kozlov */ public final class TestHyperlink extends TestCase { - protected String cwd = System.getProperty("HSLF.testdata.path"); + private static POIDataSamples _slTests = POIDataSamples.getSlideShowInstance(); public void testTextRunHyperlinks() throws Exception { - FileInputStream is = new FileInputStream(new File(cwd, "WithLinks.ppt")); - SlideShow ppt = new SlideShow(is); - is.close(); + SlideShow ppt = new SlideShow(_slTests.openResourceAsStream("WithLinks.ppt")); TextRun[] run; Slide slide; diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestMovieShape.java b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestMovieShape.java index 8d2f704561..9460642bb4 100755 --- a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestMovieShape.java +++ b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestMovieShape.java @@ -20,11 +20,11 @@ package org.apache.poi.hslf.model; import java.awt.geom.Rectangle2D; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; -import java.io.File; import junit.framework.TestCase; import org.apache.poi.hslf.usermodel.SlideShow; +import org.apache.poi.POIDataSamples; /** * Test MovieShape object. @@ -33,16 +33,16 @@ import org.apache.poi.hslf.usermodel.SlideShow; */ public final class TestMovieShape extends TestCase { - protected String cwd = System.getProperty("HSLF.testdata.path"); + private static POIDataSamples _slTests = POIDataSamples.getSlideShowInstance(); public void testCreate() throws Exception { SlideShow ppt = new SlideShow(); Slide slide = ppt.createSlide(); - String path = cwd + "/test-movie.mpg"; + String path = "/test-movie.mpg"; int movieIdx = ppt.addMovie(path, MovieShape.MOVIE_MPEG); - int thumbnailIdx = ppt.addPicture(new File(cwd, "tomcat.png"), Picture.PNG); + int thumbnailIdx = ppt.addPicture(_slTests.readFile("tomcat.png"), Picture.PNG); MovieShape shape = new MovieShape(movieIdx, thumbnailIdx); shape.setAnchor(new Rectangle2D.Float(300,225,120,90)); diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestOleEmbedding.java b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestOleEmbedding.java index e8fae8a37e..28445210fb 100644 --- a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestOleEmbedding.java +++ b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestOleEmbedding.java @@ -17,9 +17,6 @@ package org.apache.poi.hslf.model; -import java.io.File; -import java.io.FileInputStream; - import junit.framework.TestCase; import org.apache.poi.hslf.HSLFSlideShow; @@ -29,17 +26,17 @@ import org.apache.poi.hslf.usermodel.SlideShow; import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.hwpf.HWPFDocument; +import org.apache.poi.POIDataSamples; public final class TestOleEmbedding extends TestCase { + private static POIDataSamples _slTests = POIDataSamples.getSlideShowInstance(); /** * Tests support for OLE objects. * * @throws Exception if an error occurs. */ public void testOleEmbedding2003() throws Exception { - String dirname = System.getProperty("HSLF.testdata.path"); - File file = new File(dirname, "ole2-embedding-2003.ppt"); - HSLFSlideShow slideShow = new HSLFSlideShow(new FileInputStream(file)); + HSLFSlideShow slideShow = new HSLFSlideShow(_slTests.openResourceAsStream("ole2-embedding-2003.ppt")); // Placeholder EMFs for clients that don't support the OLE components. PictureData[] pictures = slideShow.getPictures(); assertEquals("Should be two pictures", 2, pictures.length); @@ -54,11 +51,7 @@ public final class TestOleEmbedding extends TestCase { } public void testOLEShape() throws Exception { - String dirname = System.getProperty("HSLF.testdata.path"); - File file = new File(dirname, "ole2-embedding-2003.ppt"); - FileInputStream is = new FileInputStream(file); - SlideShow ppt = new SlideShow(is); - is.close(); + SlideShow ppt = new SlideShow(_slTests.openResourceAsStream("ole2-embedding-2003.ppt")); Slide slide = ppt.getSlides()[0]; Shape[] sh = slide.getShapes(); diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestPPGraphics2D.java b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestPPGraphics2D.java index 521230077e..b89383c302 100644 --- a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestPPGraphics2D.java +++ b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestPPGraphics2D.java @@ -20,6 +20,7 @@ package org.apache.poi.hslf.model; import junit.framework.TestCase; import org.apache.poi.hslf.usermodel.SlideShow; import org.apache.poi.hslf.HSLFSlideShow; +import org.apache.poi.POIDataSamples; import java.awt.*; import java.awt.Rectangle; @@ -32,12 +33,11 @@ import java.io.ByteArrayInputStream; * @author Yegor Kozlov */ public final class TestPPGraphics2D extends TestCase { + private static POIDataSamples _slTests = POIDataSamples.getSlideShowInstance(); private SlideShow ppt; protected void setUp() throws Exception { - String dirname = System.getProperty("HSLF.testdata.path"); - String filename = dirname + "/empty.ppt"; - ppt = new SlideShow(new HSLFSlideShow(filename)); + ppt = new SlideShow(_slTests.openResourceAsStream("empty.ppt")); } public void testGraphics() throws Exception { diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestPicture.java b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestPicture.java index 3be128921b..871893210a 100755 --- a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestPicture.java +++ b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestPicture.java @@ -20,13 +20,13 @@ package org.apache.poi.hslf.model; import java.awt.Graphics2D; import java.awt.Rectangle; import java.awt.image.BufferedImage; -import java.io.File; import junit.framework.TestCase; import org.apache.poi.ddf.EscherBSERecord; import org.apache.poi.hslf.usermodel.PictureData; import org.apache.poi.hslf.usermodel.SlideShow; +import org.apache.poi.POIDataSamples; /** * Test Picture shape. @@ -34,6 +34,7 @@ import org.apache.poi.hslf.usermodel.SlideShow; * @author Yegor Kozlov */ public final class TestPicture extends TestCase { + private static POIDataSamples _slTests = POIDataSamples.getSlideShowInstance(); /** * Test that the reference count of a blip is incremented every time the picture is inserted. @@ -41,14 +42,13 @@ public final class TestPicture extends TestCase { * */ public void testMultiplePictures() throws Exception { - String cwd = System.getProperty("HSLF.testdata.path"); SlideShow ppt = new SlideShow(); Slide s = ppt.createSlide(); Slide s2 = ppt.createSlide(); Slide s3 = ppt.createSlide(); - int idx = ppt.addPicture(new File(cwd, "clock.jpg"), Picture.JPEG); + int idx = ppt.addPicture(_slTests.readFile("clock.jpg"), Picture.JPEG); Picture pict = new Picture(idx); Picture pict2 = new Picture(idx); Picture pict3 = new Picture(idx); diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestSetBoldItalic.java b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestSetBoldItalic.java index 572dbd035c..23b798fd6f 100644 --- a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestSetBoldItalic.java +++ b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestSetBoldItalic.java @@ -36,10 +36,6 @@ public final class TestSetBoldItalic extends TestCase { * and set some of the style attributes */ public void testTextBoxWrite() throws Exception { - //String dirname = System.getProperty("HSLF.testdata.path"); - //String filename = dirname + "/with_textbox.ppt"; - //new SlideShow(new HSLFSlideShow(filename)); - SlideShow ppt = new SlideShow(); Slide sl = ppt.createSlide(); RichTextRun rt; diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestShapes.java b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestShapes.java index 292b7fd63d..0d016e39d3 100644 --- a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestShapes.java +++ b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestShapes.java @@ -22,12 +22,12 @@ import org.apache.poi.hslf.usermodel.SlideShow; import org.apache.poi.hslf.usermodel.RichTextRun; import org.apache.poi.hslf.HSLFSlideShow; import org.apache.poi.ddf.*; +import org.apache.poi.POIDataSamples; import java.awt.*; import java.awt.Rectangle; import java.io.ByteArrayOutputStream; import java.io.ByteArrayInputStream; -import java.io.File; import java.io.IOException; import java.util.ArrayList; @@ -37,16 +37,15 @@ import java.util.ArrayList; * @author Yegor Kozlov */ public final class TestShapes extends TestCase { + private static POIDataSamples _slTests = POIDataSamples.getSlideShowInstance(); + private SlideShow ppt; private SlideShow pptB; protected void setUp() throws Exception { - String dirname = System.getProperty("HSLF.testdata.path"); - String filename = dirname + "/empty.ppt"; - ppt = new SlideShow(new HSLFSlideShow(filename)); + ppt = new SlideShow(_slTests.openResourceAsStream("empty.ppt")); - String filenameB = dirname + "/empty_textbox.ppt"; - pptB = new SlideShow(new HSLFSlideShow(filenameB)); + pptB = new SlideShow(_slTests.openResourceAsStream("empty_textbox.ppt")); } public void testGraphics() throws Exception { @@ -94,9 +93,7 @@ public final class TestShapes extends TestCase { * @throws Exception */ public void testTextBoxRead() throws Exception { - String dirname = System.getProperty("HSLF.testdata.path"); - String filename = dirname + "/with_textbox.ppt"; - ppt = new SlideShow(new HSLFSlideShow(filename)); + ppt = new SlideShow(_slTests.openResourceAsStream("with_textbox.ppt")); Slide sl = ppt.getSlides()[0]; Shape[] sh = sl.getShapes(); for (int i = 0; i < sh.length; i++) { @@ -198,17 +195,16 @@ public final class TestShapes extends TestCase { * it must be the same as returned by Slide.getTextRuns(). */ public void testTextBoxSet() throws Exception { - textBoxSet("/with_textbox.ppt"); - textBoxSet("/basic_test_ppt_file.ppt"); - textBoxSet("/next_test_ppt_file.ppt"); - textBoxSet("/Single_Coloured_Page.ppt"); - textBoxSet("/Single_Coloured_Page_With_Fonts_and_Alignments.ppt"); - textBoxSet("/incorrect_slide_order.ppt"); + textBoxSet("with_textbox.ppt"); + textBoxSet("basic_test_ppt_file.ppt"); + textBoxSet("next_test_ppt_file.ppt"); + textBoxSet("Single_Coloured_Page.ppt"); + textBoxSet("Single_Coloured_Page_With_Fonts_and_Alignments.ppt"); + textBoxSet("incorrect_slide_order.ppt"); } private void textBoxSet(String filename) throws Exception { - String dirname = System.getProperty("HSLF.testdata.path"); - SlideShow ppt = new SlideShow(new HSLFSlideShow(dirname + filename)); + SlideShow ppt = new SlideShow(_slTests.openResourceAsStream(filename)); Slide[] sl = ppt.getSlides(); for (int k = 0; k < sl.length; k++) { ArrayList lst1 = new ArrayList(); @@ -234,7 +230,6 @@ public final class TestShapes extends TestCase { * Test adding shapes to ShapeGroup */ public void testShapeGroup() throws Exception { - String cwd = System.getProperty("HSLF.testdata.path"); SlideShow ppt = new SlideShow(); Slide slide = ppt.createSlide(); @@ -245,8 +240,7 @@ public final class TestShapes extends TestCase { group.setAnchor(new Rectangle(0, 0, (int)pgsize.getWidth(), (int)pgsize.getHeight())); slide.addShape(group); - File img = new File(cwd, "clock.jpg"); - int idx = ppt.addPicture(img, Picture.JPEG); + int idx = ppt.addPicture(_slTests.readFile("clock.jpg"), Picture.JPEG); Picture pict = new Picture(idx, group); pict.setAnchor(new Rectangle(0, 0, 200, 200)); group.addShape(pict); @@ -287,8 +281,8 @@ public final class TestShapes extends TestCase { * Test functionality of Sheet.removeShape(Shape shape) */ public void testRemoveShapes() throws IOException { - String file = System.getProperty("HSLF.testdata.path")+ "/with_textbox.ppt"; - SlideShow ppt = new SlideShow(new HSLFSlideShow(file)); + String file = "with_textbox.ppt"; + SlideShow ppt = new SlideShow(_slTests.openResourceAsStream(file)); Slide sl = ppt.getSlides()[0]; Shape[] sh = sl.getShapes(); assertEquals("expected four shaped in " + file, 4, sh.length); diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestSheet.java b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestSheet.java index 667478b043..4bed9ee186 100644 --- a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestSheet.java +++ b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestSheet.java @@ -20,14 +20,11 @@ package org.apache.poi.hslf.model; import junit.framework.AssertionFailedError; import junit.framework.TestCase; -import java.io.FileInputStream; -import java.io.File; - -import org.apache.poi.hslf.HSLFSlideShow; import org.apache.poi.hslf.exceptions.EncryptedPowerPointFileException; import org.apache.poi.hslf.record.ColorSchemeAtom; import org.apache.poi.hslf.record.PPDrawing; import org.apache.poi.hslf.usermodel.SlideShow; +import org.apache.poi.POIDataSamples; /** * Test common functionality of the Sheet object. @@ -36,23 +33,16 @@ import org.apache.poi.hslf.usermodel.SlideShow; * @author Yegor Kozlov */ public final class TestSheet extends TestCase { + private static POIDataSamples _slTests = POIDataSamples.getSlideShowInstance(); /** * For each ppt in the test directory check that all sheets are properly initialized */ public void testSheet() throws Exception { - File home = new File(System.getProperty("HSLF.testdata.path")); - File[] files = home.listFiles(); - for (int i = 0; i < files.length; i++) { - if(!files[i].getName().endsWith(".ppt")) continue; - if(files[i].getName().endsWith("PPT95.ppt")) continue; - + String[] tests = {"SampleShow.ppt", "backgrounds.ppt", "text_shapes.ppt", "pictures.ppt"}; + for (String file : tests) { try { - FileInputStream is = new FileInputStream(files[i]); - HSLFSlideShow hslf = new HSLFSlideShow(is); - is.close(); - - SlideShow ppt = new SlideShow(hslf); + SlideShow ppt = new SlideShow(_slTests.openResourceAsStream(file)); doSlideShow(ppt); } catch (EncryptedPowerPointFileException e){ ; //skip encrypted ppt diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestSlideChangeNotes.java b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestSlideChangeNotes.java index e39ca5a4d1..71c95f87b7 100644 --- a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestSlideChangeNotes.java +++ b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestSlideChangeNotes.java @@ -23,6 +23,7 @@ import junit.framework.TestCase; import org.apache.poi.hslf.HSLFSlideShow; import org.apache.poi.hslf.record.SlideAtom; import org.apache.poi.hslf.usermodel.SlideShow; +import org.apache.poi.POIDataSamples; /** * Tests that changing a slide's idea of what notes sheet is its works right @@ -34,9 +35,8 @@ public final class TestSlideChangeNotes extends TestCase { private SlideShow ss; public TestSlideChangeNotes() throws Exception { - String dirname = System.getProperty("HSLF.testdata.path"); - String filename = dirname + "/basic_test_ppt_file.ppt"; - HSLFSlideShow hss = new HSLFSlideShow(filename); + POIDataSamples _slTests = POIDataSamples.getSlideShowInstance(); + HSLFSlideShow hss = new HSLFSlideShow(_slTests.openResourceAsStream("basic_test_ppt_file.ppt")); ss = new SlideShow(hss); } diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestSlideMaster.java b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestSlideMaster.java index 20bdaa8a57..45c3c0c2bc 100644 --- a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestSlideMaster.java +++ b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestSlideMaster.java @@ -28,6 +28,7 @@ import org.apache.poi.hslf.record.Environment; import org.apache.poi.hslf.record.TextHeaderAtom; import org.apache.poi.hslf.usermodel.RichTextRun; import org.apache.poi.hslf.usermodel.SlideShow; +import org.apache.poi.POIDataSamples; /** * Tests for SlideMaster @@ -35,18 +36,14 @@ import org.apache.poi.hslf.usermodel.SlideShow; * @author Yegor Kozlov */ public final class TestSlideMaster extends TestCase{ - String home; - - public void setUp() { - home = System.getProperty("HSLF.testdata.path"); - } + private static POIDataSamples _slTests = POIDataSamples.getSlideShowInstance(); /** * The reference ppt has two masters. * Check we can read their attributes. */ public void testSlideMaster() throws Exception { - SlideShow ppt = new SlideShow(new HSLFSlideShow(home + "/slide_master.ppt")); + SlideShow ppt = new SlideShow(_slTests.openResourceAsStream("slide_master.ppt")); Environment env = ppt.getDocumentRecord().getEnvironment(); @@ -86,7 +83,7 @@ public final class TestSlideMaster extends TestCase{ * Test we can read default text attributes for a title master sheet */ public void testTitleMasterTextAttributes() throws Exception { - SlideShow ppt = new SlideShow(new HSLFSlideShow(home + "/slide_master.ppt")); + SlideShow ppt = new SlideShow(_slTests.openResourceAsStream("slide_master.ppt")); TitleMaster[] master = ppt.getTitleMasters(); assertEquals(1, master.length); @@ -107,7 +104,7 @@ public final class TestSlideMaster extends TestCase{ * Slide 3 has title layout and follows the TitleMaster. Verify that. */ public void testTitleMaster() throws Exception { - SlideShow ppt = new SlideShow(new HSLFSlideShow(home + "/slide_master.ppt")); + SlideShow ppt = new SlideShow(_slTests.openResourceAsStream("slide_master.ppt")); Slide slide = ppt.getSlides()[2]; MasterSheet masterSheet = slide.getMasterSheet(); assertTrue(masterSheet instanceof TitleMaster); @@ -136,7 +133,7 @@ public final class TestSlideMaster extends TestCase{ * If a style attribute is not set ensure it is read from the master */ public void testMasterAttributes() throws Exception { - SlideShow ppt = new SlideShow(new HSLFSlideShow(home + "/slide_master.ppt")); + SlideShow ppt = new SlideShow(_slTests.openResourceAsStream("slide_master.ppt")); Slide[] slide = ppt.getSlides(); assertEquals(3, slide.length); TextRun[] trun; @@ -185,7 +182,7 @@ public final class TestSlideMaster extends TestCase{ * Check we can dynamically assign a slide master to a slide. */ public void testChangeSlideMaster() throws Exception { - SlideShow ppt = new SlideShow(new HSLFSlideShow(home + "/slide_master.ppt")); + SlideShow ppt = new SlideShow(_slTests.openResourceAsStream("slide_master.ppt")); SlideMaster[] master = ppt.getSlidesMasters(); Slide[] slide = ppt.getSlides(); int sheetNo; @@ -219,7 +216,7 @@ public final class TestSlideMaster extends TestCase{ * (typical for the "bullted body" placeholder) */ public void testIndentation() throws Exception { - SlideShow ppt = new SlideShow(new HSLFSlideShow(home + "/slide_master.ppt")); + SlideShow ppt = new SlideShow(_slTests.openResourceAsStream("slide_master.ppt")); Slide slide = ppt.getSlides()[0]; TextRun[] trun; diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestSlides.java b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestSlides.java index f60cfed57d..11889f4409 100644 --- a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestSlides.java +++ b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestSlides.java @@ -20,6 +20,7 @@ package org.apache.poi.hslf.model; import junit.framework.TestCase; import org.apache.poi.hslf.HSLFSlideShow; import org.apache.poi.hslf.usermodel.SlideShow; +import org.apache.poi.POIDataSamples; import java.io.ByteArrayOutputStream; import java.io.ByteArrayInputStream; @@ -137,8 +138,8 @@ public final class TestSlides extends TestCase { * Add slides to ppt which already has two slides */ public void testAddSlides2to3() throws Exception { - String dirname = System.getProperty("HSLF.testdata.path"); - SlideShow ppt = new SlideShow(new HSLFSlideShow(dirname + "/basic_test_ppt_file.ppt")); + POIDataSamples slTests = POIDataSamples.getSlideShowInstance(); + SlideShow ppt = new SlideShow(slTests.openResourceAsStream("basic_test_ppt_file.ppt")); assertTrue(ppt.getSlides().length == 2); diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestTextRun.java b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestTextRun.java index 770a44803e..be399fefa6 100644 --- a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestTextRun.java +++ b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestTextRun.java @@ -22,13 +22,13 @@ import java.io.IOException; import junit.framework.TestCase; -import org.apache.poi.hslf.HSLFSlideShow; import org.apache.poi.hslf.model.textproperties.TextPropCollection; import org.apache.poi.hslf.record.TextBytesAtom; import org.apache.poi.hslf.record.TextCharsAtom; import org.apache.poi.hslf.record.TextHeaderAtom; import org.apache.poi.hslf.usermodel.RichTextRun; import org.apache.poi.hslf.usermodel.SlideShow; +import org.apache.poi.POIDataSamples; /** * Tests for TextRuns @@ -36,32 +36,19 @@ import org.apache.poi.hslf.usermodel.SlideShow; * @author Nick Burch (nick at torchbox dot com) */ public final class TestTextRun extends TestCase { + private static POIDataSamples _slTests = POIDataSamples.getSlideShowInstance(); + // SlideShow primed on the test data private SlideShow ss; private SlideShow ssRich; - // TODO - use this or similar through rest of hslf tests - private static SlideShow openSampleSlideShow(String name) { - String dirname = System.getProperty("HSLF.testdata.path"); + protected void setUp() throws IOException { // Basic (non rich) test file - String filename = dirname + "/" + name; - HSLFSlideShow x; - try { - x = new HSLFSlideShow(filename); - } catch (IOException e) { - throw new RuntimeException(e); - } - return new SlideShow(x); - } - - protected void setUp() { - - // Basic (non rich) test file - ss = openSampleSlideShow("basic_test_ppt_file.ppt"); + ss = new SlideShow(_slTests.openResourceAsStream("basic_test_ppt_file.ppt")); // Rich test file - ssRich = openSampleSlideShow("Single_Coloured_Page.ppt"); + ssRich = new SlideShow(_slTests.openResourceAsStream("Single_Coloured_Page.ppt")); } /** @@ -429,10 +416,10 @@ public final class TestTextRun extends TestCase { * of the wrong list of potential paragraph properties defined in StyleTextPropAtom. * */ - public void testBug41015() { + public void testBug41015() throws IOException { RichTextRun[] rt; - SlideShow ppt = openSampleSlideShow("bug-41015.ppt"); + SlideShow ppt = new SlideShow(_slTests.openResourceAsStream("bug-41015.ppt")); Slide sl = ppt.getSlides()[0]; TextRun[] txt = sl.getTextRuns(); assertEquals(2, txt.length); diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestTextRunReWrite.java b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestTextRunReWrite.java index 2a2a10bb45..db55a2c052 100644 --- a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestTextRunReWrite.java +++ b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestTextRunReWrite.java @@ -25,6 +25,7 @@ import org.apache.poi.hslf.HSLFSlideShow; import org.apache.poi.hslf.usermodel.RichTextRun; import org.apache.poi.hslf.usermodel.SlideShow; import org.apache.poi.poifs.filesystem.*; +import org.apache.poi.POIDataSamples; /** * Tests that if we load something up, get a TextRun, set the text @@ -45,10 +46,9 @@ public final class TestTextRunReWrite extends TestCase { * Load up a test PPT file with rich data */ public void setUp() throws Exception { - String dirname = System.getProperty("HSLF.testdata.path"); - String filename = dirname + "/Single_Coloured_Page_With_Fonts_and_Alignments.ppt"; - FileInputStream fis = new FileInputStream(filename); - pfs = new POIFSFileSystem(fis); + POIDataSamples slTests = POIDataSamples.getSlideShowInstance(); + String filename = "Single_Coloured_Page_With_Fonts_and_Alignments.ppt"; + pfs = new POIFSFileSystem(slTests.openResourceAsStream(filename)); hss = new HSLFSlideShow(pfs); ss = new SlideShow(hss); } diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestTextShape.java b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestTextShape.java index 07ed6d2da6..7285f5120a 100755 --- a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestTextShape.java +++ b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestTextShape.java @@ -25,6 +25,7 @@ import java.util.HashMap; import org.apache.poi.hslf.usermodel.SlideShow; import org.apache.poi.hslf.record.TextHeaderAtom; +import org.apache.poi.POIDataSamples; /** * Verify behavior of TextShape and its sub-classes @@ -32,7 +33,7 @@ import org.apache.poi.hslf.record.TextHeaderAtom; * @author Yegor Kozlov */ public final class TestTextShape extends TestCase { - protected String cwd = System.getProperty("HSLF.testdata.path"); + private static POIDataSamples _slTests = POIDataSamples.getSlideShowInstance(); public void testCreateAutoShape(){ TextShape shape = new AutoShape(ShapeTypes.Trapezoid); @@ -70,9 +71,7 @@ public final class TestTextShape extends TestCase { * - text in auto-shapes */ public void testRead() throws IOException { - FileInputStream is = new FileInputStream(new File(cwd, "text_shapes.ppt")); - SlideShow ppt = new SlideShow(is); - is.close(); + SlideShow ppt = new SlideShow(_slTests.openResourceAsStream("text_shapes.ppt")); ArrayList lst1 = new ArrayList(); Slide slide = ppt.getSlides()[0]; @@ -157,9 +156,7 @@ public final class TestTextShape extends TestCase { } public void testMargins() throws IOException { - FileInputStream is = new FileInputStream(new File(cwd, "text-margins.ppt")); - SlideShow ppt = new SlideShow(is); - is.close(); + SlideShow ppt = new SlideShow(_slTests.openResourceAsStream("text-margins.ppt")); Slide slide = ppt.getSlides()[0]; diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestCurrentUserAtom.java b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestCurrentUserAtom.java index 8df159a32d..ed1f19a030 100644 --- a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestCurrentUserAtom.java +++ b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestCurrentUserAtom.java @@ -20,12 +20,12 @@ package org.apache.poi.hslf.record; import junit.framework.TestCase; import java.io.ByteArrayOutputStream; -import java.io.FileInputStream; import java.io.InputStream; import org.apache.poi.hslf.exceptions.EncryptedPowerPointFileException; import org.apache.poi.poifs.filesystem.DocumentEntry; import org.apache.poi.poifs.filesystem.POIFSFileSystem; +import org.apache.poi.POIDataSamples; /** * Tests that CurrentUserAtom works properly. @@ -33,6 +33,7 @@ import org.apache.poi.poifs.filesystem.POIFSFileSystem; * @author Nick Burch (nick at torchbox dot com) */ public final class TestCurrentUserAtom extends TestCase { + private static POIDataSamples _slTests = POIDataSamples.getSlideShowInstance(); /** Not encrypted */ private String normalFile; /** Encrypted */ @@ -41,14 +42,13 @@ public final class TestCurrentUserAtom extends TestCase { protected void setUp() throws Exception { super.setUp(); - String dirname = System.getProperty("HSLF.testdata.path"); - normalFile = dirname + "/basic_test_ppt_file.ppt"; - encFile = dirname + "/Password_Protected-hello.ppt"; + normalFile = "basic_test_ppt_file.ppt"; + encFile = "Password_Protected-hello.ppt"; } public void testReadNormal() throws Exception { POIFSFileSystem fs = new POIFSFileSystem( - new FileInputStream(normalFile) + _slTests.openResourceAsStream(normalFile) ); CurrentUserAtom cu = new CurrentUserAtom(fs); @@ -68,7 +68,7 @@ public final class TestCurrentUserAtom extends TestCase { public void testReadEnc() throws Exception { POIFSFileSystem fs = new POIFSFileSystem( - new FileInputStream(encFile) + _slTests.openResourceAsStream(encFile) ); try { @@ -82,7 +82,7 @@ public final class TestCurrentUserAtom extends TestCase { public void testWriteNormal() throws Exception { // Get raw contents from a known file POIFSFileSystem fs = new POIFSFileSystem( - new FileInputStream(normalFile) + _slTests.openResourceAsStream(normalFile) ); DocumentEntry docProps = (DocumentEntry)fs.getRoot().getEntry("Current User"); byte[] contents = new byte[docProps.getSize()]; diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestDocument.java b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestDocument.java index e61273bb50..114a41da8d 100644 --- a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestDocument.java +++ b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestDocument.java @@ -18,10 +18,10 @@ package org.apache.poi.hslf.record; import junit.framework.TestCase; -import java.io.*; import org.apache.poi.hslf.HSLFSlideShow; import org.apache.poi.poifs.filesystem.*; +import org.apache.poi.POIDataSamples; /** * Tests that Document works properly (Also tests Environment while we're at it) @@ -35,10 +35,8 @@ public final class TestDocument extends TestCase { private POIFSFileSystem pfs; public TestDocument() throws Exception { - String dirname = System.getProperty("HSLF.testdata.path"); - String filename = dirname + "/basic_test_ppt_file.ppt"; - FileInputStream fis = new FileInputStream(filename); - pfs = new POIFSFileSystem(fis); + POIDataSamples slTests = POIDataSamples.getSlideShowInstance(); + pfs = new POIFSFileSystem(slTests.openResourceAsStream("basic_test_ppt_file.ppt")); ss = new HSLFSlideShow(pfs); } diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestExHyperlink.java b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestExHyperlink.java index 18ae888ecd..fff9d7286e 100644 --- a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestExHyperlink.java +++ b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestExHyperlink.java @@ -19,7 +19,6 @@ package org.apache.poi.hslf.record; import java.io.ByteArrayOutputStream; -import java.io.File; import java.util.ArrayList; import java.util.List; @@ -28,6 +27,7 @@ import junit.framework.TestCase; import org.apache.poi.hslf.HSLFSlideShow; import org.apache.poi.hslf.usermodel.SlideShow; +import org.apache.poi.POIDataSamples; /** * Tests that ExHyperlink works properly. @@ -98,8 +98,8 @@ public final class TestExHyperlink extends TestCase { } public void testRealFile() throws Exception { - String dirname = System.getProperty("HSLF.testdata.path"); - HSLFSlideShow hss = new HSLFSlideShow(dirname + File.separator + "WithLinks.ppt"); + POIDataSamples slTests = POIDataSamples.getSlideShowInstance(); + HSLFSlideShow hss = new HSLFSlideShow(slTests.openResourceAsStream("WithLinks.ppt")); SlideShow ss = new SlideShow(hss); // Get the document diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestExObjList.java b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestExObjList.java index b2bf2d7065..d3739ec3b8 100644 --- a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestExObjList.java +++ b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestExObjList.java @@ -18,12 +18,11 @@ package org.apache.poi.hslf.record; -import java.io.File; - import junit.framework.TestCase; import org.apache.poi.hslf.HSLFSlideShow; import org.apache.poi.hslf.usermodel.SlideShow; +import org.apache.poi.POIDataSamples; /** * Tests that ExObjList works properly. @@ -32,8 +31,8 @@ import org.apache.poi.hslf.usermodel.SlideShow; */ public class TestExObjList extends TestCase { public void testRealFile() throws Exception { - String dirname = System.getProperty("HSLF.testdata.path"); - HSLFSlideShow hss = new HSLFSlideShow(dirname + File.separator + "WithLinks.ppt"); + POIDataSamples slTests = POIDataSamples.getSlideShowInstance(); + HSLFSlideShow hss = new HSLFSlideShow(slTests.openResourceAsStream("WithLinks.ppt")); SlideShow ss = new SlideShow(hss); // Get the document diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestRecordContainer.java b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestRecordContainer.java index 74684e7e73..8481cbc70f 100644 --- a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestRecordContainer.java +++ b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestRecordContainer.java @@ -21,6 +21,7 @@ package org.apache.poi.hslf.record; import junit.framework.TestCase; import org.apache.poi.hslf.HSLFSlideShow; +import org.apache.poi.POIDataSamples; /** * Tests that the helper methods on RecordContainer work properly @@ -147,9 +148,8 @@ public final class TestRecordContainer extends TestCase { super.setUp(); // Find a real RecordContainer record - String dirname = System.getProperty("HSLF.testdata.path"); - String filename = dirname + "/basic_test_ppt_file.ppt"; - HSLFSlideShow hss = new HSLFSlideShow(filename); + POIDataSamples slTests = POIDataSamples.getSlideShowInstance(); + HSLFSlideShow hss = new HSLFSlideShow(slTests.openResourceAsStream("basic_test_ppt_file.ppt")); Record[] r = hss.getRecords(); for(int i=0; i 128); // Check right contents - byte[] emf = HWPFTestDataSamples.getTestDataFileContent("vector_image.emf"); + byte[] emf = POIDataSamples.getDocumentInstance().readFile("vector_image.emf"); byte[] pemf = pic.getContent(); assertEquals(emf.length, pemf.length); for(int i=0; itrue if standard system propery is not set, * but the data is available on the test runtime classpath */ private boolean _sampleDataIsAvaliableOnClassPath; - private String _testDataDir; + private String _moduleDir; /** * - * @param dir the name of the system property that defines path to the test files - * @param classPathTestFile the name of the test file to check if resources are available from the classpath + * @param moduleDir the name of the directory containing the test files */ - public POIDataSamples(String dir, String classPathTestFile){ - _testDataDir = dir; - initialise(classPathTestFile); + private POIDataSamples(String moduleDir){ + _moduleDir = moduleDir; + initialise(); } + public static POIDataSamples getSpreadSheetInstance(){ + if(_instSpreadsheet == null) _instSpreadsheet = new POIDataSamples("spreadsheet"); + return _instSpreadsheet; + } + + public static POIDataSamples getDocumentInstance(){ + if(_instDocument == null) _instDocument = new POIDataSamples("document"); + return _instDocument; + } + + public static POIDataSamples getSlideShowInstance(){ + if(_instSlideshow == null) _instSlideshow = new POIDataSamples("slideshow"); + return _instSlideshow; + } + + public static POIDataSamples getDiagramInstance(){ + if(_instOpenxml4j == null) _instOpenxml4j = new POIDataSamples("diagram"); + return _instOpenxml4j; + } + + public static POIDataSamples getOpenXML4JInstance(){ + if(_instDiagram == null) _instDiagram = new POIDataSamples("openxml4j"); + return _instDiagram; + } + + public static POIDataSamples getPOIFSInstance(){ + if(_instPOIFS == null) _instPOIFS = new POIDataSamples("poifs"); + return _instPOIFS; + } + + public static POIDataSamples getDDFInstance(){ + if(_instDDF == null) _instDDF = new POIDataSamples("ddf"); + return _instDDF; + } + + public static POIDataSamples getHPSFInstance(){ + if(_instHPSF == null) _instHPSF = new POIDataSamples("hpsf"); + return _instHPSF; + } + + public static POIDataSamples getPublisherInstance(){ + if(_instHPBF == null) _instHPBF = new POIDataSamples("publisher"); + return _instHPBF; + } + + public static POIDataSamples getHSMFInstance(){ + if(_instHSMF == null) _instHSMF = new POIDataSamples("hsmf"); + return _instHSMF; + } /** * Opens a sample file from the test data directory * @@ -60,24 +123,11 @@ public abstract class POIDataSamples { } if (_resolvedDataDir == null) { throw new RuntimeException("Must set system property '" - + _testDataDir + + TEST_PROPERTY + "' properly before running tests"); } - File f = new File(_resolvedDataDir, sampleFileName); - if (!f.exists()) { - throw new RuntimeException("Sample file '" + sampleFileName - + "' not found in data dir '" + _resolvedDataDir.getAbsolutePath() + "'"); - } - try { - if(!sampleFileName.equals(f.getCanonicalFile().getName())){ - throw new RuntimeException("File name is case-sensitive: requested '" + sampleFileName - + "' but actual file is '" + f.getCanonicalFile().getName() + "'"); - } - } catch (IOException e){ - throw new RuntimeException(e); - } - + File f = getFile(sampleFileName); try { return new FileInputStream(f); } catch (FileNotFoundException e) { @@ -87,13 +137,32 @@ public abstract class POIDataSamples { /** * - * @param classPathTest test file to check if the resources are avaiable from the classpath + * @param sampleFileName the name of the test file + * @return + * @throws RuntimeException if the file was not found */ - private void initialise(String classPathTest) { - String dataDirName = System.getProperty(_testDataDir); + public File getFile(String sampleFileName) { + File f = new File(_resolvedDataDir, sampleFileName); + if (!f.exists()) { + throw new RuntimeException("Sample file '" + sampleFileName + + "' not found in data dir '" + _resolvedDataDir.getAbsolutePath() + "'"); + } + try { + if(sampleFileName.length() > 0 && !sampleFileName.equals(f.getCanonicalFile().getName())){ + throw new RuntimeException("File name is case-sensitive: requested '" + sampleFileName + + "' but actual file is '" + f.getCanonicalFile().getName() + "'"); + } + } catch (IOException e){ + throw new RuntimeException(e); + } + return f; + } + + private void initialise() { + String dataDirName = System.getProperty(TEST_PROPERTY); if (dataDirName == null) { // check to see if we can just get the resources from the classpath - InputStream is = openClasspathResource(classPathTest); + InputStream is = openClasspathResource(""); if (is != null) { try { is.close(); // be nice @@ -104,14 +173,12 @@ public abstract class POIDataSamples { return; } - throw new RuntimeException("Must set system property '" - + _testDataDir + "' before running tests"); + throw new RuntimeException("Must set system property '" + + TEST_PROPERTY + "' before running tests"); } - File dataDir = new File(dataDirName); + File dataDir = new File(dataDirName, _moduleDir); if (!dataDir.exists()) { - throw new RuntimeException("Data dir '" + dataDirName - + "' specified by system property '" + _testDataDir - + "' does not exist"); + throw new RuntimeException("Data dir '" + _moduleDir + " does not exist"); } // convert to canonical file, to make any subsequent error messages // clearer. @@ -129,7 +196,7 @@ public abstract class POIDataSamples { * @return null if the sample file is not deployed on the classpath. */ private InputStream openClasspathResource(String sampleFileName) { - return getClass().getResourceAsStream("data/" + sampleFileName); + return getClass().getResourceAsStream("/" + _moduleDir + "/" + sampleFileName); } private static final class NonSeekableInputStream extends InputStream { diff --git a/src/testcases/org/apache/poi/ddf/TestEscherBlipRecord.java b/src/testcases/org/apache/poi/ddf/TestEscherBlipRecord.java index 9e2921fe88..6dffb8df22 100755 --- a/src/testcases/org/apache/poi/ddf/TestEscherBlipRecord.java +++ b/src/testcases/org/apache/poi/ddf/TestEscherBlipRecord.java @@ -23,6 +23,7 @@ import java.io.IOException; import java.util.Arrays; import junit.framework.TestCase; +import org.apache.poi.POIDataSamples; /** * Test read/serialize of escher blip records @@ -30,12 +31,12 @@ import junit.framework.TestCase; * @author Yegor Kozlov */ public final class TestEscherBlipRecord extends TestCase { - protected String cwd = System.getProperty("DDF.testdata.path"); + private static final POIDataSamples _samples = POIDataSamples.getDDFInstance(); //test reading/serializing of a PNG blip public void testReadPNG() { //provided in bug-44886 - byte[] data = read(new File(cwd, "Container.dat")); + byte[] data = _samples.readFile("Container.dat"); EscherContainerRecord record = new EscherContainerRecord(); record.fillFields(data, 0, new DefaultEscherRecordFactory()); @@ -80,7 +81,7 @@ public final class TestEscherBlipRecord extends TestCase { //test reading/serializing of a PICT metafile public void testReadPICT() { //provided in bug-44886 - byte[] data = read(new File(cwd, "Container.dat")); + byte[] data = _samples.readFile("Container.dat"); EscherContainerRecord record = new EscherContainerRecord(); record.fillFields(data, 0, new DefaultEscherRecordFactory()); @@ -131,7 +132,7 @@ public final class TestEscherBlipRecord extends TestCase { //integral test: check that the read-write-read round trip is consistent public void testContainer() { - byte[] data = read(new File(cwd, "Container.dat")); + byte[] data = _samples.readFile("Container.dat"); EscherContainerRecord record = new EscherContainerRecord(); record.fillFields(data, 0, new DefaultEscherRecordFactory()); @@ -156,7 +157,7 @@ public final class TestEscherBlipRecord extends TestCase { * The test data was created from pl031405.xls attached to Bugzilla #47143 */ public void test47143() { - byte[] data = read(new File(cwd, "47143.dat")); + byte[] data = _samples.readFile("47143.dat"); EscherBSERecord bse = new EscherBSERecord(); bse.fillFields(data, 0, new DefaultEscherRecordFactory()); bse.toString(); //assert that toString() works diff --git a/src/testcases/org/apache/poi/ddf/TestEscherContainerRecord.java b/src/testcases/org/apache/poi/ddf/TestEscherContainerRecord.java index 4d83cad446..3db6a3784d 100644 --- a/src/testcases/org/apache/poi/ddf/TestEscherContainerRecord.java +++ b/src/testcases/org/apache/poi/ddf/TestEscherContainerRecord.java @@ -25,16 +25,13 @@ import junit.framework.TestCase; import org.apache.poi.util.HexRead; import org.apache.poi.util.HexDump; import org.apache.poi.util.IOUtils; +import org.apache.poi.POIDataSamples; /** * Tests for {@link EscherContainerRecord} */ public final class TestEscherContainerRecord extends TestCase { - private String ESCHER_DATA_PATH; - - protected void setUp() { - ESCHER_DATA_PATH = System.getProperty("DDF.testdata.path"); - } + private static final POIDataSamples _samples = POIDataSamples.getDDFInstance(); public void testFillFields() { EscherRecordFactory f = new DefaultEscherRecordFactory(); @@ -151,11 +148,7 @@ public final class TestEscherContainerRecord extends TestCase { * but hopefully we now read the correct size. */ public void testBug44857() throws Exception { - File f = new File(ESCHER_DATA_PATH, "Container.dat"); - assertTrue(f.exists()); - - FileInputStream finp = new FileInputStream(f); - byte[] data = IOUtils.toByteArray(finp); + byte[] data = _samples.readFile("Container.dat"); // This used to fail with an OutOfMemory EscherContainerRecord record = new EscherContainerRecord(); diff --git a/src/testcases/org/apache/poi/hpsf/basic/AllDataFilesTester.java b/src/testcases/org/apache/poi/hpsf/basic/AllDataFilesTester.java index ba7c650b37..0e1c212326 100644 --- a/src/testcases/org/apache/poi/hpsf/basic/AllDataFilesTester.java +++ b/src/testcases/org/apache/poi/hpsf/basic/AllDataFilesTester.java @@ -17,6 +17,8 @@ package org.apache.poi.hpsf.basic; +import org.apache.poi.POIDataSamples; + import java.io.File; import java.io.FileFilter; import java.util.logging.Logger; @@ -30,6 +32,7 @@ import java.util.logging.Logger; * href="mailto:klute@rainer-klute.de"><klute@rainer-klute.de> */ public class AllDataFilesTester { + private static final POIDataSamples _samples = POIDataSamples.getHPSFInstance(); /** *

Interface specifying how to run a test on a single file.

@@ -56,8 +59,8 @@ public class AllDataFilesTester { */ public void runTests(final TestTask task) throws Throwable { - final String dataDirName = System.getProperty("HPSF.testdata.path"); - final File dataDir = new File(dataDirName); + POIDataSamples _samples = POIDataSamples.getHPSFInstance(); + final File dataDir = _samples.getFile(""); final File[] docs = dataDir.listFiles(new FileFilter() { public boolean accept(final File file) diff --git a/src/testcases/org/apache/poi/hpsf/basic/TestBasic.java b/src/testcases/org/apache/poi/hpsf/basic/TestBasic.java index 0eeef4bbdf..b773bd6fd7 100644 --- a/src/testcases/org/apache/poi/hpsf/basic/TestBasic.java +++ b/src/testcases/org/apache/poi/hpsf/basic/TestBasic.java @@ -37,6 +37,7 @@ import org.apache.poi.hpsf.PropertySetFactory; import org.apache.poi.hpsf.Section; import org.apache.poi.hpsf.SummaryInformation; import org.apache.poi.hpsf.wellknown.SectionIDMap; +import org.apache.poi.POIDataSamples; /** *

Tests the basic HPSF functionality.

@@ -80,11 +81,10 @@ public final class TestBasic extends TestCase { * @exception FileNotFoundException if the file to be read does not exist. * @exception IOException if any other I/O exception occurs. */ - public void setUp() throws FileNotFoundException, IOException + public void setUp() throws IOException { - final File dataDir = - new File(System.getProperty("HPSF.testdata.path")); - final File data = new File(dataDir, POI_FS); + POIDataSamples samples = POIDataSamples.getHPSFInstance(); + final File data = samples.getFile(POI_FS); poiFiles = Util.readPOIFiles(data); } diff --git a/src/testcases/org/apache/poi/hpsf/basic/TestEmptyProperties.java b/src/testcases/org/apache/poi/hpsf/basic/TestEmptyProperties.java index 806b49745a..47c4adc340 100644 --- a/src/testcases/org/apache/poi/hpsf/basic/TestEmptyProperties.java +++ b/src/testcases/org/apache/poi/hpsf/basic/TestEmptyProperties.java @@ -35,6 +35,7 @@ import org.apache.poi.hpsf.PropertySet; import org.apache.poi.hpsf.PropertySetFactory; import org.apache.poi.hpsf.SummaryInformation; import org.apache.poi.hpsf.Variant; +import org.apache.poi.POIDataSamples; /** *

Test case for OLE2 files with empty properties. An empty property's type @@ -69,9 +70,8 @@ public final class TestEmptyProperties extends TestCase { */ public void setUp() throws FileNotFoundException, IOException { - final File dataDir = - new File(System.getProperty("HPSF.testdata.path")); - final File data = new File(dataDir, POI_FS); + POIDataSamples samples = POIDataSamples.getHPSFInstance(); + final File data = samples.getFile(POI_FS); poiFiles = Util.readPOIFiles(data); } diff --git a/src/testcases/org/apache/poi/hpsf/basic/TestReadAllFiles.java b/src/testcases/org/apache/poi/hpsf/basic/TestReadAllFiles.java index 9916dbc995..8f7bbd5b05 100644 --- a/src/testcases/org/apache/poi/hpsf/basic/TestReadAllFiles.java +++ b/src/testcases/org/apache/poi/hpsf/basic/TestReadAllFiles.java @@ -25,6 +25,7 @@ import java.io.InputStream; import junit.framework.TestCase; import org.apache.poi.hpsf.PropertySetFactory; +import org.apache.poi.POIDataSamples; /** *

Tests some HPSF functionality by reading all property sets from all files @@ -41,8 +42,8 @@ public class TestReadAllFiles extends TestCase { */ public void testReadAllFiles() { - final File dataDir = - new File(System.getProperty("HPSF.testdata.path")); + POIDataSamples _samples = POIDataSamples.getHPSFInstance(); + final File dataDir = _samples.getFile(""); final File[] fileList = dataDir.listFiles(new FileFilter() { public boolean accept(final File f) diff --git a/src/testcases/org/apache/poi/hpsf/basic/TestUnicode.java b/src/testcases/org/apache/poi/hpsf/basic/TestUnicode.java index f9cf2b0dcd..581ff14381 100644 --- a/src/testcases/org/apache/poi/hpsf/basic/TestUnicode.java +++ b/src/testcases/org/apache/poi/hpsf/basic/TestUnicode.java @@ -32,6 +32,7 @@ import org.apache.poi.hpsf.PropertySet; import org.apache.poi.hpsf.PropertySetFactory; import org.apache.poi.hpsf.Section; import org.apache.poi.hpsf.SummaryInformation; +import org.apache.poi.POIDataSamples; /** *

Tests whether Unicode string can be read from a @@ -57,9 +58,8 @@ public class TestUnicode extends TestCase { * @exception IOException if any other I/O exception occurs */ protected void setUp() { - final File dataDir = - new File(System.getProperty("HPSF.testdata.path")); - data = new File(dataDir, POI_FS); + POIDataSamples samples = POIDataSamples.getHPSFInstance(); + data = samples.getFile(POI_FS); } diff --git a/src/testcases/org/apache/poi/hpsf/basic/TestWrite.java b/src/testcases/org/apache/poi/hpsf/basic/TestWrite.java index dbb528f6e2..f824ffb7bc 100644 --- a/src/testcases/org/apache/poi/hpsf/basic/TestWrite.java +++ b/src/testcases/org/apache/poi/hpsf/basic/TestWrite.java @@ -63,6 +63,7 @@ import org.apache.poi.poifs.eventfilesystem.POIFSReaderListener; import org.apache.poi.poifs.filesystem.POIFSFileSystem; import org.apache.poi.util.LittleEndian; import org.apache.poi.util.TempFile; +import org.apache.poi.POIDataSamples; /** *

Tests HPSF's writing functionality.

@@ -71,6 +72,7 @@ import org.apache.poi.util.TempFile; */ public class TestWrite extends TestCase { + private static final POIDataSamples _samples = POIDataSamples.getHPSFInstance(); static final String POI_FS = "TestHPSFWritingFunctionality.doc"; @@ -110,10 +112,7 @@ public class TestWrite extends TestCase */ public void testNoFormatID() throws IOException { - final String dataDirName = System.getProperty("HPSF.testdata.path"); - final File dataDir = new File(dataDirName); - final File filename = new File(dataDir, POI_FS); - filename.deleteOnExit(); + final File filename = TempFile.createTempFile(POI_FS, ".doc"); /* Create a mutable property set with a section that does not have the * formatID set: */ @@ -159,8 +158,7 @@ public class TestWrite extends TestCase public void testWriteEmptyPropertySet() throws IOException, UnsupportedVariantTypeException { - final File dataDir = - new File(System.getProperty("HPSF.testdata.path")); + final File dataDir = _samples.getFile(""); final File filename = new File(dataDir, POI_FS); filename.deleteOnExit(); @@ -202,8 +200,7 @@ public class TestWrite extends TestCase { final String AUTHOR = "Rainer Klute"; final String TITLE = "Test Document"; - final File dataDir = - new File(System.getProperty("HPSF.testdata.path")); + final File dataDir = _samples.getFile(""); final File filename = new File(dataDir, POI_FS); filename.deleteOnExit(); final OutputStream out = new FileOutputStream(filename); @@ -274,8 +271,7 @@ public class TestWrite extends TestCase final String SECTION1 = "Section 1"; final String SECTION2 = "Section 2"; - final File dataDir = - new File(System.getProperty("HPSF.testdata.path")); + final File dataDir = _samples.getFile(""); final File filename = new File(dataDir, POI_FS); filename.deleteOnExit(); final OutputStream out = new FileOutputStream(filename); @@ -673,8 +669,7 @@ public class TestWrite extends TestCase */ public void testRecreate() { - final File dataDir = - new File(System.getProperty("HPSF.testdata.path")); + final File dataDir = _samples.getFile(""); final File[] fileList = dataDir.listFiles(new FileFilter() { public boolean accept(final File f) diff --git a/src/testcases/org/apache/poi/hpsf/basic/TestWriteWellKnown.java b/src/testcases/org/apache/poi/hpsf/basic/TestWriteWellKnown.java index d570b029b3..ca3b0864ba 100644 --- a/src/testcases/org/apache/poi/hpsf/basic/TestWriteWellKnown.java +++ b/src/testcases/org/apache/poi/hpsf/basic/TestWriteWellKnown.java @@ -53,6 +53,7 @@ import org.apache.poi.poifs.filesystem.DirectoryEntry; import org.apache.poi.poifs.filesystem.DocumentEntry; import org.apache.poi.poifs.filesystem.DocumentInputStream; import org.apache.poi.poifs.filesystem.POIFSFileSystem; +import org.apache.poi.POIDataSamples; /** *

Tests HPSF's high-level writing functionality for the well-known property @@ -78,8 +79,8 @@ public class TestWriteWellKnown extends TestCase { /** *

This test method checks whether DocumentSummary information streams - * can be read. This is done by opening all "Test*" files in the directrory - * pointed to by the "HPSF.testdata.path" system property, trying to extract + * can be read. This is done by opening all "Test*" files in the 'poifs' directrory + * pointed to by the "POI.testdata.path" system property, trying to extract * the document summary information stream in the root directory and calling * its get... methods.

* @throws IOException @@ -93,8 +94,8 @@ public class TestWriteWellKnown extends TestCase { NoPropertySetStreamException, MarkUnsupportedException, UnexpectedPropertySetTypeException { - final String dataDirName = System.getProperty("HPSF.testdata.path"); - final File dataDir = new File(dataDirName); + POIDataSamples _samples = POIDataSamples.getHPSFInstance(); + final File dataDir = _samples.getFile(""); final File[] docs = dataDir.listFiles(new FileFilter() { public boolean accept(final File file) @@ -205,8 +206,8 @@ public class TestWriteWellKnown extends TestCase { NoPropertySetStreamException, MarkUnsupportedException, UnexpectedPropertySetTypeException, WritingNotSupportedException { - final String dataDirName = System.getProperty("HPSF.testdata.path"); - final File dataDir = new File(dataDirName); + POIDataSamples _samples = POIDataSamples.getHPSFInstance(); + final File dataDir = _samples.getFile(""); final File doc1 = new File(dataDir, POI_FS); /* Read a test document doc1 into a POI filesystem. */ @@ -625,8 +626,8 @@ public class TestWriteWellKnown extends TestCase { } }; - final String dataDirName = System.getProperty("HPSF.testdata.path"); - final File dataDir = new File(dataDirName); + POIDataSamples _samples = POIDataSamples.getHPSFInstance(); + final File dataDir = _samples.getFile(""); final File[] docs = dataDir.listFiles(new FileFilter() { public boolean accept(final File file) diff --git a/src/testcases/org/apache/poi/hpsf/extractor/TestHPSFPropertiesExtractor.java b/src/testcases/org/apache/poi/hpsf/extractor/TestHPSFPropertiesExtractor.java index 3120f3cc0d..6d1478fba0 100644 --- a/src/testcases/org/apache/poi/hpsf/extractor/TestHPSFPropertiesExtractor.java +++ b/src/testcases/org/apache/poi/hpsf/extractor/TestHPSFPropertiesExtractor.java @@ -27,18 +27,15 @@ import org.apache.poi.hssf.extractor.ExcelExtractor; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.hssf.HSSFTestDataSamples; import org.apache.poi.poifs.filesystem.POIFSFileSystem; +import org.apache.poi.POIDataSamples; public final class TestHPSFPropertiesExtractor extends TestCase { - private String dir; - - protected void setUp() { - dir = System.getProperty("HPSF.testdata.path"); - assertNotNull("HPSF.testdata.path not set", dir); - } + private static final POIDataSamples _samples = POIDataSamples.getHPSFInstance(); public void testNormalProperties() throws Exception { - POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream( - new File(dir, "TestMickey.doc"))); + POIFSFileSystem fs = new POIFSFileSystem( + _samples.openResourceAsStream("TestMickey.doc") + ); HPSFPropertiesExtractor ext = new HPSFPropertiesExtractor(fs); ext.getText(); @@ -60,8 +57,9 @@ public final class TestHPSFPropertiesExtractor extends TestCase { } public void testNormalUnicodeProperties() throws Exception { - POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(new File(dir, - "TestUnicode.xls"))); + POIFSFileSystem fs = new POIFSFileSystem( + _samples.openResourceAsStream("TestUnicode.xls") + ); HPSFPropertiesExtractor ext = new HPSFPropertiesExtractor(fs); ext.getText(); @@ -83,8 +81,9 @@ public final class TestHPSFPropertiesExtractor extends TestCase { } public void testCustomProperties() throws Exception { - POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream( - new File(dir, "TestMickey.doc"))); + POIFSFileSystem fs = new POIFSFileSystem( + _samples.openResourceAsStream("TestMickey.doc") + ); HPSFPropertiesExtractor ext = new HPSFPropertiesExtractor(fs); // Custom properties are part of the document info stream @@ -101,7 +100,9 @@ public final class TestHPSFPropertiesExtractor extends TestCase { POIFSFileSystem fs; HSSFWorkbook wb; try { - fs = new POIFSFileSystem(new FileInputStream(new File(dir, "TestUnicode.xls"))); + fs = new POIFSFileSystem( + _samples.openResourceAsStream("TestUnicode.xls") + ); wb = new HSSFWorkbook(fs); } catch (IOException e) { throw new RuntimeException(e); diff --git a/src/testcases/org/apache/poi/hslf/data/basic_test_ppt_file.ppt b/src/testcases/org/apache/poi/hslf/data/basic_test_ppt_file.ppt deleted file mode 100644 index af16393f44..0000000000 Binary files a/src/testcases/org/apache/poi/hslf/data/basic_test_ppt_file.ppt and /dev/null differ diff --git a/src/testcases/org/apache/poi/hssf/HSSFITestDataProvider.java b/src/testcases/org/apache/poi/hssf/HSSFITestDataProvider.java index 6f6a782410..6be47dea05 100755 --- a/src/testcases/org/apache/poi/hssf/HSSFITestDataProvider.java +++ b/src/testcases/org/apache/poi/hssf/HSSFITestDataProvider.java @@ -21,6 +21,7 @@ import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.ss.ITestDataProvider; import org.apache.poi.ss.SpreadsheetVersion; import org.apache.poi.ss.usermodel.Workbook; +import org.apache.poi.POIDataSamples; /** * @author Yegor Kozlov @@ -44,7 +45,7 @@ public final class HSSFITestDataProvider implements ITestDataProvider { } public byte[] getTestDataFileContent(String fileName) { - return HSSFTestDataSamples.getTestDataFileContent(fileName); + return POIDataSamples.getSpreadSheetInstance().readFile(fileName); } public SpreadsheetVersion getSpreadsheetVersion(){ diff --git a/src/testcases/org/apache/poi/hssf/HSSFTestDataSamples.java b/src/testcases/org/apache/poi/hssf/HSSFTestDataSamples.java index cbe4e61cd9..2e4553ff71 100644 --- a/src/testcases/org/apache/poi/hssf/HSSFTestDataSamples.java +++ b/src/testcases/org/apache/poi/hssf/HSSFTestDataSamples.java @@ -30,17 +30,9 @@ import org.apache.poi.hssf.usermodel.HSSFWorkbook; * * @author Josh Micich */ -public final class HSSFTestDataSamples extends POIDataSamples { +public final class HSSFTestDataSamples { - private static final HSSFTestDataSamples _inst = new HSSFTestDataSamples("HSSF.testdata.path", "SampleSS.xls"); - - private HSSFTestDataSamples(String dir, String classPathTestFile){ - super(dir, classPathTestFile); - } - - public static POIDataSamples getInstance(){ - return _inst; - } + private static final POIDataSamples _inst = POIDataSamples.getSpreadSheetInstance(); public static InputStream openSampleFileStream(String sampleFileName) { return _inst.openResourceAsStream(sampleFileName); diff --git a/src/testcases/org/apache/poi/hssf/extractor/TestExcelExtractor.java b/src/testcases/org/apache/poi/hssf/extractor/TestExcelExtractor.java index 5d2518acec..0e9634e626 100644 --- a/src/testcases/org/apache/poi/hssf/extractor/TestExcelExtractor.java +++ b/src/testcases/org/apache/poi/hssf/extractor/TestExcelExtractor.java @@ -28,6 +28,8 @@ import org.apache.poi.hssf.record.crypto.Biff8EncryptionKey; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.poifs.filesystem.DirectoryNode; import org.apache.poi.poifs.filesystem.POIFSFileSystem; +import org.apache.poi.POIDataSamples; + /** * */ @@ -214,11 +216,8 @@ public final class TestExcelExtractor extends TestCase { * Embded in a non-excel file */ public void testWithEmbeded() throws Exception { - // TODO - encapsulate sys prop 'POIFS.testdata.path' similar to HSSFTestDataSamples - String pdirname = System.getProperty("POIFS.testdata.path"); - String filename = pdirname + "/word_with_embeded.doc"; POIFSFileSystem fs = new POIFSFileSystem( - new FileInputStream(filename) + POIDataSamples.getDocumentInstance().openResourceAsStream("word_with_embeded.doc") ); DirectoryNode objPool = (DirectoryNode) fs.getRoot().getEntry("ObjectPool"); @@ -244,12 +243,10 @@ public final class TestExcelExtractor extends TestCase { * Excel embeded in excel */ public void testWithEmbededInOwn() throws Exception { - // TODO - encapsulate sys prop 'POIFS.testdata.path' similar to HSSFTestDataSamples - String pdirname = System.getProperty("POIFS.testdata.path"); - String filename = pdirname + "/excel_with_embeded.xls"; + POIDataSamples ssSamples = POIDataSamples.getSpreadSheetInstance(); POIFSFileSystem fs = new POIFSFileSystem( - new FileInputStream(filename) - ); + ssSamples.openResourceAsStream("excel_with_embeded.xls") + ); DirectoryNode dirA = (DirectoryNode) fs.getRoot().getEntry("MBD0000A3B5"); DirectoryNode dirB = (DirectoryNode) fs.getRoot().getEntry("MBD0000A3B4"); diff --git a/src/testcases/org/apache/poi/hwpf/data/test2.doc b/src/testcases/org/apache/poi/hwpf/data/test2.doc deleted file mode 100755 index 06921df395..0000000000 Binary files a/src/testcases/org/apache/poi/hwpf/data/test2.doc and /dev/null differ diff --git a/src/testcases/org/apache/poi/poifs/data/source-files/sample1.doc b/src/testcases/org/apache/poi/poifs/data/source-files/sample1.doc deleted file mode 100644 index 0e935aa528..0000000000 Binary files a/src/testcases/org/apache/poi/poifs/data/source-files/sample1.doc and /dev/null differ diff --git a/src/testcases/org/apache/poi/poifs/data/source-files/sample1.ppt b/src/testcases/org/apache/poi/poifs/data/source-files/sample1.ppt deleted file mode 100644 index 7d72e02362..0000000000 Binary files a/src/testcases/org/apache/poi/poifs/data/source-files/sample1.ppt and /dev/null differ diff --git a/src/testcases/org/apache/poi/poifs/data/source-files/sample1.xls b/src/testcases/org/apache/poi/poifs/data/source-files/sample1.xls deleted file mode 100644 index c00643cc5a..0000000000 Binary files a/src/testcases/org/apache/poi/poifs/data/source-files/sample1.xls and /dev/null differ diff --git a/src/testcases/org/apache/poi/poifs/data/source-files/sample2.doc b/src/testcases/org/apache/poi/poifs/data/source-files/sample2.doc deleted file mode 100644 index df5022a041..0000000000 Binary files a/src/testcases/org/apache/poi/poifs/data/source-files/sample2.doc and /dev/null differ diff --git a/src/testcases/org/apache/poi/poifs/data/source-files/sample2.ppt b/src/testcases/org/apache/poi/poifs/data/source-files/sample2.ppt deleted file mode 100644 index 40227fdca5..0000000000 Binary files a/src/testcases/org/apache/poi/poifs/data/source-files/sample2.ppt and /dev/null differ diff --git a/src/testcases/org/apache/poi/poifs/data/source-files/sample2.xls b/src/testcases/org/apache/poi/poifs/data/source-files/sample2.xls deleted file mode 100644 index 66a1b1124d..0000000000 Binary files a/src/testcases/org/apache/poi/poifs/data/source-files/sample2.xls and /dev/null differ diff --git a/src/testcases/org/apache/poi/poifs/filesystem/TestPOIFSFileSystem.java b/src/testcases/org/apache/poi/poifs/filesystem/TestPOIFSFileSystem.java index 4a948ba8c6..095dd58317 100755 --- a/src/testcases/org/apache/poi/poifs/filesystem/TestPOIFSFileSystem.java +++ b/src/testcases/org/apache/poi/poifs/filesystem/TestPOIFSFileSystem.java @@ -26,6 +26,7 @@ import java.io.InputStream; import junit.framework.TestCase; import org.apache.poi.hssf.HSSFTestDataSamples; +import org.apache.poi.POIDataSamples; /** * Tests for POIFSFileSystem @@ -134,15 +135,13 @@ public final class TestPOIFSFileSystem extends TestCase { String[] files = new String[] { "ShortLastBlock.qwp", "ShortLastBlock.wps" }; - String pdirname = System.getProperty("POIFS.testdata.path"); - for(int i=0; i