moved all test data to a top-level directory, refactored all junit usages of .testdata.path to one place

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@806959 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Yegor Kozlov 2009-08-23 12:34:24 +00:00
parent e8b5f36704
commit 2712b14d2f
563 changed files with 703 additions and 1102 deletions

View File

@ -76,6 +76,7 @@ under the License.
<property name="main.lib" location="lib"/> <property name="main.lib" location="lib"/>
<property name="ooxml.lib" location="ooxml-lib"/> <property name="ooxml.lib" location="ooxml-lib"/>
<property name="main.reports.test" location="build/test-results"/> <property name="main.reports.test" location="build/test-results"/>
<property name="poi.test.dir" location="test-data"/>
<property name="main.commons-logging.jar" location="${main.lib}/commons-logging-1.1.jar"/> <property name="main.commons-logging.jar" location="${main.lib}/commons-logging-1.1.jar"/>
<property name="main.commons-logging.url" value="${repository.m2}/maven2/commons-logging/commons-logging/1.1/commons-logging-1.1.jar"/> <property name="main.commons-logging.url" value="${repository.m2}/maven2/commons-logging/commons-logging/1.1/commons-logging-1.1.jar"/>
@ -566,12 +567,7 @@ under the License.
<classpath refid="test.classpath"/> <classpath refid="test.classpath"/>
<sysproperty key="user.language" value="en"/> <sysproperty key="user.language" value="en"/>
<sysproperty key="user.country" value="US"/> <sysproperty key="user.country" value="US"/>
<sysproperty key="HSSF.testdata.path" file="${main.src.test}/org/apache/poi/hssf/data"/> <sysproperty key="POI.testdata.path" file="${poi.test.dir}"/>
<sysproperty key="HSLF.testdata.path" file="${main.src.test}/org/apache/poi/hslf/data"/>
<sysproperty key="HWPF.testdata.path" file="${main.src.test}/org/apache/poi/hwpf/data"/>
<sysproperty key="HPSF.testdata.path" file="${main.src.test}/org/apache/poi/hpsf/data"/>
<sysproperty key="POIFS.testdata.path" file="${main.src.test}/org/apache/poi/poifs/data"/>
<sysproperty key="DDF.testdata.path" file="${main.src.test}/org/apache/poi/ddf/data"/>
<sysproperty key="java.awt.headless" value="true"/> <sysproperty key="java.awt.headless" value="true"/>
<formatter type="plain"/> <formatter type="plain"/>
<formatter type="xml"/> <formatter type="xml"/>
@ -602,10 +598,7 @@ under the License.
</classpath> </classpath>
<sysproperty key="user.language" value="en"/> <sysproperty key="user.language" value="en"/>
<sysproperty key="user.country" value="US"/> <sysproperty key="user.country" value="US"/>
<sysproperty key="HSSF.testdata.path" file="${main.src.test}/org/apache/poi/hssf/data"/> <sysproperty key="POI.testdata.path" file="${poi.test.dir}"/>
<sysproperty key="HPSF.testdata.path" file="${main.src.test}/org/apache/poi/hpsf/data"/>
<sysproperty key="HWPF.testdata.path" file="${scratchpad.src.test}/org/apache/poi/hwpf/data"/>
<sysproperty key="POIFS.testdata.path" file="${main.src.test}/org/apache/poi/poifs/data"/>
<sysproperty key="java.awt.headless" value="true"/> <sysproperty key="java.awt.headless" value="true"/>
<formatter type="plain" usefile="no"/> <formatter type="plain" usefile="no"/>
<batchtest todir="${main.reports.test}"> <batchtest todir="${main.reports.test}">
@ -631,15 +624,7 @@ under the License.
</classpath> </classpath>
<sysproperty key="user.language" value="en"/> <sysproperty key="user.language" value="en"/>
<sysproperty key="user.country" value="US"/> <sysproperty key="user.country" value="US"/>
<sysproperty key="HSSF.testdata.path" file="${main.src.test}/org/apache/poi/hssf/data"/> <sysproperty key="POI.testdata.path" file="${poi.test.dir}"/>
<sysproperty key="HPSF.testdata.path" file="${main.src.test}/org/apache/poi/hpsf/data"/>
<sysproperty key="HSLF.testdata.path" file="${scratchpad.src.test}/org/apache/poi/hslf/data"/>
<sysproperty key="HWPF.testdata.path" file="${scratchpad.src.test}/org/apache/poi/hwpf/data"/>
<sysproperty key="HSMF.testdata.path" file="${scratchpad.src.test}/org/apache/poi/hsmf/data"/>
<sysproperty key="HDGF.testdata.path" file="${scratchpad.src.test}/org/apache/poi/hdgf/data"/>
<sysproperty key="HPBF.testdata.path" file="${scratchpad.src.test}/org/apache/poi/hpbf/data"/>
<sysproperty key="POIFS.testdata.path" file="${main.src.test}/org/apache/poi/poifs/data"/>
<sysproperty key="OOXML.testdata.path" file="${ooxml.src.test}/org/apache/poi/ooxml/data"/>
<sysproperty key="java.awt.headless" value="true"/> <sysproperty key="java.awt.headless" value="true"/>
<formatter type="plain" usefile="no"/> <formatter type="plain" usefile="no"/>
<formatter type="xml"/> <formatter type="xml"/>
@ -675,15 +660,7 @@ under the License.
</classpath> </classpath>
<sysproperty key="user.language" value="en"/> <sysproperty key="user.language" value="en"/>
<sysproperty key="user.country" value="US"/> <sysproperty key="user.country" value="US"/>
<sysproperty key="HSSF.testdata.path" file="${main.src.test}/org/apache/poi/hssf/data"/> <sysproperty key="POI.testdata.path" file="${poi.test.dir}"/>
<sysproperty key="HPSF.testdata.path" file="${scratchpad.src.test}/org/apache/poi/hpsf/data"/>
<sysproperty key="HDF.testdata.path" file="${scratchpad.src.test}/org/apache/poi/hdf/data"/>
<sysproperty key="HWPF.testdata.path" file="${scratchpad.src.test}/org/apache/poi/hwpf/data"/>
<sysproperty key="HSLF.testdata.path" file="${scratchpad.src.test}/org/apache/poi/hslf/data"/>
<sysproperty key="HSMF.testdata.path" file="${scratchpad.src.test}/org/apache/poi/hsmf/data"/>
<sysproperty key="HDGF.testdata.path" file="${scratchpad.src.test}/org/apache/poi/hdgf/data"/>
<sysproperty key="HPBF.testdata.path" file="${scratchpad.src.test}/org/apache/poi/hpbf/data"/>
<sysproperty key="POIFS.testdata.path" file="${main.src.test}/org/apache/poi/poifs/data"/>
<sysproperty key="java.awt.headless" value="true"/> <sysproperty key="java.awt.headless" value="true"/>
<formatter type="plain"/> <formatter type="plain"/>
<formatter type="xml"/> <formatter type="xml"/>
@ -714,14 +691,7 @@ under the License.
</classpath> </classpath>
<sysproperty key="user.language" value="en"/> <sysproperty key="user.language" value="en"/>
<sysproperty key="user.country" value="US"/> <sysproperty key="user.country" value="US"/>
<sysproperty key="HSSF.testdata.path" file="${main.src.test}/org/apache/poi/hssf/data"/> <sysproperty key="POI.testdata.path" file="${poi.test.dir}"/>
<sysproperty key="HPSF.testdata.path" file="${scratchpad.src.test}/org/apache/poi/hpsf/data"/>
<sysproperty key="HWPF.testdata.path" file="${scratchpad.src.test}/org/apache/poi/hwpf/data"/>
<sysproperty key="HSLF.testdata.path" file="${scratchpad.src.test}/org/apache/poi/hslf/data"/>
<sysproperty key="HSMF.testdata.path" file="${scratchpad.src.test}/org/apache/poi/hsmf/data"/>
<sysproperty key="HDGF.testdata.path" file="${scratchpad.src.test}/org/apache/poi/hdgf/data"/>
<sysproperty key="HPBF.testdata.path" file="${scratchpad.src.test}/org/apache/poi/hpbf/data"/>
<sysproperty key="POIFS.testdata.path" file="${main.src.test}/org/apache/poi/poifs/data"/>
<sysproperty key="java.awt.headless" value="true"/> <sysproperty key="java.awt.headless" value="true"/>
<sysproperty key="java.awt.headless" value="true"/> <sysproperty key="java.awt.headless" value="true"/>
<formatter type="plain" usefile="no"/> <formatter type="plain" usefile="no"/>
@ -748,8 +718,6 @@ under the License.
</classpath> </classpath>
<sysproperty key="user.language" value="en"/> <sysproperty key="user.language" value="en"/>
<sysproperty key="user.country" value="US"/> <sysproperty key="user.country" value="US"/>
<sysproperty key="HSSF.testdata.path" file="${contrib.src.test}/org/apache/poi/hssf/data"/>
<sysproperty key="HPSF.testdata.path" file="${contrib.src.test}/org/apache/poi/hpsf/data"/>
<sysproperty key="java.awt.headless" value="true"/> <sysproperty key="java.awt.headless" value="true"/>
<formatter type="plain"/> <formatter type="plain"/>
<formatter type="xml"/> <formatter type="xml"/>
@ -780,14 +748,7 @@ under the License.
<classpath refid="test.ooxml.classpath" /> <classpath refid="test.ooxml.classpath" />
<sysproperty key="user.language" value="en"/> <sysproperty key="user.language" value="en"/>
<sysproperty key="user.country" value="US"/> <sysproperty key="user.country" value="US"/>
<sysproperty key="POIFS.testdata.path" file="${main.src.test}/org/apache/poi/poifs/data"/> <sysproperty key="POI.testdata.path" file="${poi.test.dir}"/>
<sysproperty key="HSSF.testdata.path" file="${main.src.test}/org/apache/poi/hssf/data"/>
<sysproperty key="HWPF.testdata.path" file="${scratchpad.src.test}/org/apache/poi/hwpf/data"/>
<sysproperty key="HSLF.testdata.path" file="${scratchpad.src.test}/org/apache/poi/hslf/data"/>
<sysproperty key="HDGF.testdata.path" file="${scratchpad.src.test}/org/apache/poi/hdgf/data"/>
<sysproperty key="OOXML.testdata.path" file="${ooxml.src.test}/org/apache/poi/ooxml/data"/>
<sysproperty key="openxml4j.compliance.input" file="${ooxml.src.test}/org/apache/poi/openxml4j/opc/compliance/data"/>
<sysproperty key="openxml4j.testdata.input" file="${ooxml.src.test}/org/apache/poi/openxml4j/opc/data"/>
<sysproperty key="java.awt.headless" value="true"/> <sysproperty key="java.awt.headless" value="true"/>
<formatter type="plain"/> <formatter type="plain"/>
<formatter type="xml"/> <formatter type="xml"/>
@ -811,12 +772,7 @@ under the License.
<classpath refid="test.ooxml.classpath" /> <classpath refid="test.ooxml.classpath" />
<sysproperty key="user.language" value="en"/> <sysproperty key="user.language" value="en"/>
<sysproperty key="user.country" value="US"/> <sysproperty key="user.country" value="US"/>
<sysproperty key="HSSF.testdata.path" file="${main.src.test}/org/apache/poi/hssf/data"/> <sysproperty key="POI.testdata.path" file="${poi.test.dir}"/>
<sysproperty key="HPSF.testdata.path" file="${main.src.test}/org/apache/poi/hpsf/data"/>
<sysproperty key="HSLF.testdata.path" file="${scratchpad.src.test}/org/apache/poi/hslf/data"/>
<sysproperty key="HWPF.testdata.path" file="${scratchpad.src.test}/org/apache/poi/hwpf/data"/>
<sysproperty key="HSMF.testdata.path" file="${scratchpad.src.test}/org/apache/poi/hsmf/data"/>
<sysproperty key="HDGF.testdata.path" file="${scratchpad.src.test}/org/apache/poi/hdgf/data"/>
<sysproperty key="java.awt.headless" value="true"/> <sysproperty key="java.awt.headless" value="true"/>
<formatter type="plain" usefile="no"/> <formatter type="plain" usefile="no"/>
<formatter type="xml"/> <formatter type="xml"/>

View File

@ -33,6 +33,7 @@
<changes> <changes>
<release version="3.5-beta7" date="2009-??-??"> <release version="3.5-beta7" date="2009-??-??">
<action dev="POI-DEVELOPERS" type="fix">moved all test data to a top-level directory</action>
<action dev="POI-DEVELOPERS" type="add">47721 - Added implementation for INDIRECT()</action> <action dev="POI-DEVELOPERS" type="add">47721 - Added implementation for INDIRECT()</action>
<action dev="POI-DEVELOPERS" type="add">45583 - Avoid exception when reading ClipboardData packet in OLE property sets</action> <action dev="POI-DEVELOPERS" type="add">45583 - Avoid exception when reading ClipboardData packet in OLE property sets</action>
<action dev="POI-DEVELOPERS" type="add">47652 - Added support for reading encrypted workbooks</action> <action dev="POI-DEVELOPERS" type="add">47652 - Added support for reading encrypted workbooks</action>

View File

@ -36,34 +36,24 @@ import junit.framework.TestCase;
*/ */
public class TestEmbeded extends 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 { public void testExcel() throws Exception {
File f = new File(dirname, "ExcelWithAttachments.xlsm"); POIXMLDocument doc = new XSSFWorkbook(
assertTrue(f.exists()); POIDataSamples.getSpreadSheetInstance().openResourceAsStream("ExcelWithAttachments.xlsm")
);
POIXMLDocument doc = new XSSFWorkbook(OPCPackage.open(f.toString()));
test(doc, 4); test(doc, 4);
} }
public void testWord() throws Exception { public void testWord() throws Exception {
File f = new File(dirname, "WordWithAttachments.docx"); POIXMLDocument doc = new XWPFDocument(
assertTrue(f.exists()); POIDataSamples.getDocumentInstance().openResourceAsStream("WordWithAttachments.docx")
);
POIXMLDocument doc = new XWPFDocument(OPCPackage.open(f.toString()));
test(doc, 5); test(doc, 5);
} }
public void testPowerPoint() throws Exception { public void testPowerPoint() throws Exception {
File f = new File(dirname, "PPTWithAttachments.pptm"); POIXMLDocument doc = new XSLFSlideShow(OPCPackage.open(
assertTrue(f.exists()); POIDataSamples.getSlideShowInstance().openResourceAsStream("PPTWithAttachments.pptm"))
);
POIXMLDocument doc = new XSLFSlideShow(OPCPackage.open(f.toString()));
test(doc, 4); test(doc, 4);
} }

View File

@ -30,11 +30,13 @@ import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.openxml4j.opc.PackagePart; import org.apache.poi.openxml4j.opc.PackagePart;
import org.apache.poi.openxml4j.opc.PackageRelationship; import org.apache.poi.openxml4j.opc.PackageRelationship;
import org.apache.poi.util.TempFile; import org.apache.poi.util.TempFile;
import org.apache.poi.util.PackageHelper;
/** /**
* Test recursive read and write of OPC packages * Test recursive read and write of OPC packages
*/ */
public final class TestPOIXMLDocument extends TestCase { public final class TestPOIXMLDocument extends TestCase {
private static class OPCParser extends POIXMLDocument { private static class OPCParser extends POIXMLDocument {
public OPCParser(OPCPackage pkg) { 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); OPCParser doc = new OPCParser(pkg1);
doc.parse(new TestFactory()); doc.parse(new TestFactory());
@ -124,17 +125,20 @@ public final class TestPOIXMLDocument extends TestCase {
} }
public void testPPTX() throws Exception { public void testPPTX() throws Exception {
File file = new File(System.getProperty("OOXML.testdata.path"), "PPTWithAttachments.pptm"); assertReadWrite(
assertReadWrite(file.getAbsolutePath()); PackageHelper.open(POIDataSamples.getSlideShowInstance().openResourceAsStream("PPTWithAttachments.pptm"))
);
} }
public void testXLSX() throws Exception { public void testXLSX() throws Exception {
File file = new File(System.getProperty("OOXML.testdata.path"), "ExcelWithAttachments.xlsm"); assertReadWrite(
assertReadWrite(file.getAbsolutePath()); PackageHelper.open(POIDataSamples.getSpreadSheetInstance().openResourceAsStream("ExcelWithAttachments.xlsm"))
);
} }
public void testDOCX() throws Exception { public void testDOCX() throws Exception {
File file = new File(System.getProperty("OOXML.testdata.path"), "WordWithAttachments.docx"); assertReadWrite(
assertReadWrite(file.getAbsolutePath()); PackageHelper.open(POIDataSamples.getDocumentInstance().openResourceAsStream("WordWithAttachments.docx"))
);
} }
} }

View File

@ -21,21 +21,16 @@ import java.io.File;
import org.apache.poi.xssf.extractor.XSSFExcelExtractor; import org.apache.poi.xssf.extractor.XSSFExcelExtractor;
import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.poi.openxml4j.opc.OPCPackage; import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.util.PackageHelper;
import junit.framework.TestCase; import junit.framework.TestCase;
public final class TestXMLPropertiesTextExtractor extends TestCase { public final class TestXMLPropertiesTextExtractor extends TestCase {
private String dirname; private static final POIDataSamples _ssSamples = POIDataSamples.getSpreadSheetInstance();
protected void setUp() {
dirname = System.getProperty("OOXML.testdata.path");
assertTrue( (new File(dirname)).exists() );
}
public void testGetFromMainExtractor() throws Exception { public void testGetFromMainExtractor() throws Exception {
OPCPackage pkg = OPCPackage.open( OPCPackage pkg = PackageHelper.open(_ssSamples.openResourceAsStream("ExcelWithAttachments.xlsm"));
(new File(dirname, "ExcelWithAttachments.xlsm")).toString()
);
XSSFWorkbook wb = new XSSFWorkbook(pkg); XSSFWorkbook wb = new XSSFWorkbook(pkg);
XSSFExcelExtractor ext = new XSSFExcelExtractor(wb); XSSFExcelExtractor ext = new XSSFExcelExtractor(wb);
@ -54,8 +49,8 @@ public final class TestXMLPropertiesTextExtractor extends TestCase {
} }
public void testCore() throws Exception { public void testCore() throws Exception {
OPCPackage pkg = OPCPackage.open( OPCPackage pkg = PackageHelper.open(
(new File(dirname, "ExcelWithAttachments.xlsm")).toString() _ssSamples.openResourceAsStream("ExcelWithAttachments.xlsm")
); );
XSSFWorkbook wb = new XSSFWorkbook(pkg); XSSFWorkbook wb = new XSSFWorkbook(pkg);
@ -72,7 +67,7 @@ public final class TestXMLPropertiesTextExtractor extends TestCase {
public void testExtended() throws Exception { public void testExtended() throws Exception {
OPCPackage pkg = OPCPackage.open( OPCPackage pkg = OPCPackage.open(
(new File(dirname, "ExcelWithAttachments.xlsm")).toString() _ssSamples.openResourceAsStream("ExcelWithAttachments.xlsm")
); );
XSSFWorkbook wb = new XSSFWorkbook(pkg); XSSFWorkbook wb = new XSSFWorkbook(pkg);

View File

@ -22,10 +22,13 @@ import java.io.IOException;
import org.apache.poi.POIOLE2TextExtractor; import org.apache.poi.POIOLE2TextExtractor;
import org.apache.poi.POITextExtractor; import org.apache.poi.POITextExtractor;
import org.apache.poi.POIDataSamples;
import org.apache.poi.hdgf.extractor.VisioTextExtractor; import org.apache.poi.hdgf.extractor.VisioTextExtractor;
import org.apache.poi.hslf.extractor.PowerPointExtractor; import org.apache.poi.hslf.extractor.PowerPointExtractor;
import org.apache.poi.hssf.extractor.ExcelExtractor; 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.extractor.WordExtractor;
import org.apache.poi.hwpf.HWPFTestDataSamples;
import org.apache.poi.poifs.filesystem.POIFSFileSystem; import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.xslf.extractor.XSLFPowerPointExtractor; import org.apache.poi.xslf.extractor.XSLFPowerPointExtractor;
import org.apache.poi.xssf.extractor.XSSFExcelExtractor; 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 * Test that the extractor factory plays nicely
*/ */
public class TestExtractorFactory extends TestCase { 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 txt;
private File xls; private File xls;
private File xlsx; private File xlsx;
private File xltx; private File xltx;
private File xlsEmb;
private File doc; private File doc;
private File docx; private File docx;
private File dotx; private File dotx;
private File docEmb;
private File ppt; private File ppt;
private File pptx; private File pptx;
@ -64,31 +64,25 @@ public class TestExtractorFactory extends TestCase {
protected void setUp() throws Exception { protected void setUp() throws Exception {
super.setUp(); super.setUp();
excel_dir = System.getProperty("HSSF.testdata.path"); POIDataSamples ssTests = POIDataSamples.getSpreadSheetInstance();
word_dir = System.getProperty("HWPF.testdata.path"); xls = ssTests.getFile("SampleSS.xls");
powerpoint_dir = System.getProperty("HSLF.testdata.path"); xlsx = ssTests.getFile("SampleSS.xlsx");
visio_dir = System.getProperty("HDGF.testdata.path"); xltx = ssTests.getFile("test.xltx");
poifs_dir = System.getProperty("POIFS.testdata.path"); xlsEmb = ssTests.getFile("excel_with_embeded.xls");
assertNotNull(excel_dir);
assertNotNull(word_dir);
assertNotNull(powerpoint_dir);
assertNotNull(visio_dir);
assertNotNull(poifs_dir);
txt = new File(powerpoint_dir, "SampleShow.txt"); 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");
xls = new File(excel_dir, "SampleSS.xls"); POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
xlsx = new File(excel_dir, "SampleSS.xlsx"); ppt = slTests.getFile("SampleShow.ppt");
xltx = new File(excel_dir, "test.xltx"); pptx = slTests.getFile("SampleShow.pptx");
txt = slTests.getFile("SampleShow.txt");
doc = new File(word_dir, "SampleDoc.doc"); POIDataSamples dgTests = POIDataSamples.getDiagramInstance();
docx = new File(word_dir, "SampleDoc.docx"); vsd = dgTests.getFile("Test_Visio-Some_Random_Text.vsd");
dotx = new File(word_dir, "test.dotx");
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");
} }
public void testFile() throws Exception { public void testFile() throws Exception {
@ -339,7 +333,6 @@ public class TestExtractorFactory extends TestCase {
public void testEmbeded() throws Exception { public void testEmbeded() throws Exception {
POIOLE2TextExtractor ext; POIOLE2TextExtractor ext;
POITextExtractor[] embeds; POITextExtractor[] embeds;
File f;
// No embedings // No embedings
ext = (POIOLE2TextExtractor) ext = (POIOLE2TextExtractor)
@ -348,9 +341,8 @@ public class TestExtractorFactory extends TestCase {
assertEquals(0, embeds.length); assertEquals(0, embeds.length);
// Excel // Excel
f = new File(poifs_dir, "excel_with_embeded.xls");
ext = (POIOLE2TextExtractor) ext = (POIOLE2TextExtractor)
ExtractorFactory.createExtractor(f); ExtractorFactory.createExtractor(xlsEmb);
embeds = ExtractorFactory.getEmbededDocsTextExtractors(ext); embeds = ExtractorFactory.getEmbededDocsTextExtractors(ext);
assertEquals(6, embeds.length); assertEquals(6, embeds.length);
@ -367,9 +359,8 @@ public class TestExtractorFactory extends TestCase {
assertEquals(2, numWord); assertEquals(2, numWord);
// Word // Word
f = new File(poifs_dir, "word_with_embeded.doc");
ext = (POIOLE2TextExtractor) ext = (POIOLE2TextExtractor)
ExtractorFactory.createExtractor(f); ExtractorFactory.createExtractor(docEmb);
embeds = ExtractorFactory.getEmbededDocsTextExtractors(ext); embeds = ExtractorFactory.getEmbededDocsTextExtractors(ext);
numWord = 0; numXls = 0; numPpt = 0; numWord = 0; numXls = 0; numPpt = 0;

View File

@ -17,6 +17,9 @@
package org.apache.poi.openxml4j; package org.apache.poi.openxml4j;
import org.apache.poi.POIDataSamples;
import org.apache.poi.util.TempFile;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
@ -28,121 +31,31 @@ import java.io.InputStream;
* @author jmicich * @author jmicich
*/ */
public final class OpenXML4JTestDataSamples { public final class OpenXML4JTestDataSamples {
private static final POIDataSamples _samples = POIDataSamples.getOpenXML4JInstance();
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 OpenXML4JTestDataSamples() { private OpenXML4JTestDataSamples() {
// no instances of this class // no instances of this class
} }
public static InputStream openSampleStream(String sampleFileName) { public static InputStream openSampleStream(String sampleFileName) {
File f = getSampleFile(sampleFileName); return _samples.openResourceAsStream(sampleFileName);
try {
return new FileInputStream(f);
} catch (FileNotFoundException e) {
throw new RuntimeException(e);
}
} }
public static String getSampleFileName(String sampleFileName) { public static String getSampleFileName(String sampleFileName) {
// TODO - investigate allowing read/write access for package opened on stream
return getSampleFile(sampleFileName).getAbsolutePath(); return getSampleFile(sampleFileName).getAbsolutePath();
} }
public static File getSampleFile(String sampleFileName) { public static File getSampleFile(String sampleFileName) {
File dir = getSampleInputDir(); return _samples.getFile(sampleFileName);
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 File getOutputFile(String outputFileName) { public static File getOutputFile(String outputFileName) {
File dir = getSampleOutputDir(); String suffix = outputFileName.substring(outputFileName.lastIndexOf('.'));
return new File(dir, outputFileName); return TempFile.createTempFile(outputFileName, suffix);
} }
public static InputStream openComplianceSampleStream(String sampleFileName) { public static InputStream openComplianceSampleStream(String sampleFileName) {
File f = getComplianceSampleFile(sampleFileName); return _samples.openResourceAsStream(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;
} }
} }

View File

@ -33,6 +33,7 @@ import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.openxml4j.opc.PackageRelationshipTypes; import org.apache.poi.openxml4j.opc.PackageRelationshipTypes;
import org.apache.poi.openxml4j.opc.PackagingURIHelper; import org.apache.poi.openxml4j.opc.PackagingURIHelper;
import org.apache.poi.openxml4j.opc.TargetMode; import org.apache.poi.openxml4j.opc.TargetMode;
import org.apache.poi.POIDataSamples;
/** /**
* Test core properties Open Packaging Convention compliance. * Test core properties Open Packaging Convention compliance.
@ -144,11 +145,11 @@ public final class TestOPCComplianceCoreProperties extends TestCase {
* Test M4.1 rule. * Test M4.1 rule.
*/ */
public void testOnlyOneCorePropertiesPart_AddPart() { public void testOnlyOneCorePropertiesPart_AddPart() {
String sampleFileName = OpenXML4JTestDataSamples.getComplianceSampleFileName("OPCCompliance_CoreProperties_OnlyOneCorePropertiesPart.docx"); String sampleFileName = "OPCCompliance_CoreProperties_OnlyOneCorePropertiesPart.docx";
OPCPackage pkg = null; OPCPackage pkg = null;
try { try {
pkg = OPCPackage.open(sampleFileName); pkg = OPCPackage.open(POIDataSamples.getOpenXML4JInstance().getFile(sampleFileName).getPath());
} catch (InvalidFormatException e) { } catch (Exception e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }

View File

@ -18,6 +18,7 @@
package org.apache.poi.openxml4j.opc.compliance; package org.apache.poi.openxml4j.opc.compliance;
import java.io.File; import java.io.File;
import java.io.IOException;
import junit.framework.TestCase; 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.PackageRelationshipTypes;
import org.apache.poi.openxml4j.opc.PackagingURIHelper; import org.apache.poi.openxml4j.opc.PackagingURIHelper;
import org.apache.poi.openxml4j.opc.TargetMode; import org.apache.poi.openxml4j.opc.TargetMode;
import org.apache.poi.POIDataSamples;
/** /**
* Test Open Packaging Convention package model compliance. * 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. * part name derived from another part name by appending segments to it.
* [M1.11] * [M1.11]
*/ */
public void testPartNameDerivationReadingFailure() { public void testPartNameDerivationReadingFailure() throws IOException {
String filepath = System.getProperty("openxml4j.compliance.input") String filename = "OPCCompliance_DerivedPartNameFAIL.docx";
+ File.separator + "OPCCompliance_DerivedPartNameFAIL.docx";
try { try {
OPCPackage.open(filepath); OPCPackage.open(POIDataSamples.getOpenXML4JInstance().openResourceAsStream(filename));
} catch (InvalidFormatException e) { } catch (InvalidFormatException e) {
return; return;
} }

View File

@ -16,31 +16,23 @@
==================================================================== */ ==================================================================== */
package org.apache.poi.xslf; package org.apache.poi.xslf;
import java.io.File;
import junit.framework.TestCase; 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.OPCPackage;
import org.apache.poi.openxml4j.opc.PackagePart; import org.apache.poi.openxml4j.opc.PackagePart;
import org.openxmlformats.schemas.presentationml.x2006.main.CTSlideIdListEntry; import org.openxmlformats.schemas.presentationml.x2006.main.CTSlideIdListEntry;
import org.openxmlformats.schemas.presentationml.x2006.main.CTSlideMasterIdListEntry; import org.openxmlformats.schemas.presentationml.x2006.main.CTSlideMasterIdListEntry;
public class TestXSLFSlideShow extends TestCase { public class TestXSLFSlideShow extends TestCase {
private String sampleFile; private static final POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
private OPCPackage pack;
protected void setUp() throws Exception { protected void setUp() throws Exception {
super.setUp(); pack = OPCPackage.open(slTests.openResourceAsStream("sample.pptx"));
sampleFile = new File(
System.getProperty("HSLF.testdata.path") +
File.separator + "sample.pptx"
).toString();
} }
public void testContainsMainContentType() throws Exception { public void testContainsMainContentType() throws Exception {
OPCPackage pack = POIXMLDocument.openPackage(sampleFile);
boolean found = false; boolean found = false;
for(PackagePart part : pack.getParts()) { for(PackagePart part : pack.getParts()) {
if(part.getContentType().equals(XSLFSlideShow.MAIN_CONTENT_TYPE)) { if(part.getContentType().equals(XSLFSlideShow.MAIN_CONTENT_TYPE)) {
@ -52,15 +44,11 @@ public class TestXSLFSlideShow extends TestCase {
} }
public void testOpen() throws Exception { public void testOpen() throws Exception {
POIXMLDocument.openPackage(sampleFile);
XSLFSlideShow xml; XSLFSlideShow xml;
// With the finalised uri, should be fine // With the finalised uri, should be fine
xml = new XSLFSlideShow( xml = new XSLFSlideShow(pack);
POIXMLDocument.openPackage(sampleFile)
);
// Check the core // Check the core
assertNotNull(xml.getPresentation()); assertNotNull(xml.getPresentation());
@ -74,7 +62,7 @@ public class TestXSLFSlideShow extends TestCase {
} }
public void testSlideBasics() throws Exception { public void testSlideBasics() throws Exception {
XSLFSlideShow xml = new XSLFSlideShow(sampleFile); XSLFSlideShow xml = new XSLFSlideShow(pack);
// Should have 1 master // Should have 1 master
assertEquals(1, xml.getSlideMasterReferences().sizeOfSldMasterIdArray()); assertEquals(1, xml.getSlideMasterReferences().sizeOfSldMasterIdArray());
@ -108,7 +96,7 @@ public class TestXSLFSlideShow extends TestCase {
} }
public void testMetadataBasics() throws Exception { public void testMetadataBasics() throws Exception {
XSLFSlideShow xml = new XSLFSlideShow(sampleFile); XSLFSlideShow xml = new XSLFSlideShow(pack);
assertNotNull(xml.getProperties().getCoreProperties()); assertNotNull(xml.getProperties().getCoreProperties());
assertNotNull(xml.getProperties().getExtendedProperties()); assertNotNull(xml.getProperties().getExtendedProperties());

View File

@ -16,9 +16,8 @@
==================================================================== */ ==================================================================== */
package org.apache.poi.xslf.extractor; package org.apache.poi.xslf.extractor;
import java.io.File; import org.apache.poi.POIDataSamples;
import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.POIXMLDocument;
import org.apache.poi.xslf.XSLFSlideShow; import org.apache.poi.xslf.XSLFSlideShow;
import junit.framework.TestCase; import junit.framework.TestCase;
@ -31,18 +30,12 @@ public class TestXSLFPowerPointExtractor extends TestCase {
* A simple file * A simple file
*/ */
private XSLFSlideShow xmlA; private XSLFSlideShow xmlA;
private File fileA; private OPCPackage pkg;
protected void setUp() throws Exception { protected void setUp() throws Exception {
super.setUp(); POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
pkg = OPCPackage.open(slTests.openResourceAsStream("sample.pptx"));
fileA = new File( xmlA = new XSLFSlideShow(pkg);
System.getProperty("HSLF.testdata.path") +
File.separator + "sample.pptx"
);
assertTrue(fileA.exists());
xmlA = new XSLFSlideShow(fileA.toString());
} }
/** /**
@ -50,8 +43,7 @@ public class TestXSLFPowerPointExtractor extends TestCase {
*/ */
public void testGetSimpleText() throws Exception { public void testGetSimpleText() throws Exception {
new XSLFPowerPointExtractor(xmlA); new XSLFPowerPointExtractor(xmlA);
new XSLFPowerPointExtractor( new XSLFPowerPointExtractor(pkg);
POIXMLDocument.openPackage(fileA.toString()));
XSLFPowerPointExtractor extractor = XSLFPowerPointExtractor extractor =
new XSLFPowerPointExtractor(xmlA); new XSLFPowerPointExtractor(xmlA);
@ -110,13 +102,8 @@ public class TestXSLFPowerPointExtractor extends TestCase {
} }
public void testGetComments() throws Exception { public void testGetComments() throws Exception {
File file = new File( POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
System.getProperty("HSLF.testdata.path") + xmlA = new XSLFSlideShow(OPCPackage.open(slTests.openResourceAsStream("45545_Comment.pptx")));
File.separator + "45545_Comment.pptx"
);
assertTrue(file.exists());
xmlA = new XSLFSlideShow(file.toString());
XSLFPowerPointExtractor extractor = XSLFPowerPointExtractor extractor =
new XSLFPowerPointExtractor(xmlA); new XSLFPowerPointExtractor(xmlA);

View File

@ -22,6 +22,7 @@ import org.apache.poi.ss.SpreadsheetVersion;
import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.poi.hssf.HSSFTestDataSamples; import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.POIDataSamples;
/** /**
* @author Yegor Kozlov * @author Yegor Kozlov
@ -45,7 +46,7 @@ public final class XSSFITestDataProvider implements ITestDataProvider {
} }
public byte[] getTestDataFileContent(String fileName) { public byte[] getTestDataFileContent(String fileName) {
return HSSFTestDataSamples.getTestDataFileContent(fileName); return POIDataSamples.getSpreadSheetInstance().readFile(fileName);
} }
public SpreadsheetVersion getSpreadsheetVersion(){ public SpreadsheetVersion getSpreadsheetVersion(){

View File

@ -39,14 +39,7 @@ import org.apache.poi.util.TempFile;
*/ */
public class XSSFTestDataSamples { public class XSSFTestDataSamples {
public static InputStream openSampleFileStream(String sampleFileName) { public static XSSFWorkbook openSampleWorkbook(String sampleName) {
return HSSFTestDataSamples.openSampleFileStream(sampleFileName);
}
public static byte[] getTestDataFileContent(String fileName) {
return HSSFTestDataSamples.getTestDataFileContent(fileName);
}
public static final XSSFWorkbook openSampleWorkbook(String sampleName) {
InputStream is = HSSFTestDataSamples.openSampleFileStream(sampleName); InputStream is = HSSFTestDataSamples.openSampleFileStream(sampleName);
try { try {
return new XSSFWorkbook(is); return new XSSFWorkbook(is);
@ -57,24 +50,17 @@ public class XSSFTestDataSamples {
public static <R extends Workbook> R writeOutAndReadBack(R wb) { public static <R extends Workbook> R writeOutAndReadBack(R wb) {
Workbook result; Workbook result;
try { try {
if (wb instanceof HSSFWorkbook) {
ByteArrayOutputStream baos = new ByteArrayOutputStream(8192); ByteArrayOutputStream baos = new ByteArrayOutputStream(8192);
wb.write(baos); wb.write(baos);
InputStream is = new ByteArrayInputStream(baos.toByteArray()); InputStream is = new ByteArrayInputStream(baos.toByteArray());
if (wb instanceof HSSFWorkbook) {
result = new HSSFWorkbook(is); result = new HSSFWorkbook(is);
} else if (wb instanceof XSSFWorkbook) { } else if (wb instanceof XSSFWorkbook) {
File tmp = TempFile.createTempFile("poi-ooxml-", ".xlsx"); result = new XSSFWorkbook(is);
FileOutputStream out = new FileOutputStream(tmp);
wb.write(out);
out.close();
OPCPackage pkg = OPCPackage.open(tmp.getAbsolutePath());
result = new XSSFWorkbook(pkg);
} else { } else {
throw new RuntimeException("Unexpected workbook type (" throw new RuntimeException("Unexpected workbook type ("
+ wb.getClass().getName() + ")"); + wb.getClass().getName() + ")");
} }
} catch (InvalidFormatException e) {
throw new RuntimeException(e);
} catch (IOException e) { } catch (IOException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }

View File

@ -26,14 +26,16 @@ import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.util.IOUtils; import org.apache.poi.util.IOUtils;
import org.apache.poi.xssf.XSSFTestDataSamples; import org.apache.poi.xssf.XSSFTestDataSamples;
import org.apache.poi.xssf.usermodel.XSSFRichTextString; import org.apache.poi.xssf.usermodel.XSSFRichTextString;
import org.apache.poi.POIDataSamples;
/** /**
* Tests for {@link XSSFReader} * Tests for {@link XSSFReader}
*/ */
public final class TestXSSFReader extends TestCase { public final class TestXSSFReader extends TestCase {
private static POIDataSamples _ssTests = POIDataSamples.getSpreadSheetInstance();
public void testGetBits() throws Exception { public void testGetBits() throws Exception {
OPCPackage pkg = OPCPackage.open(XSSFTestDataSamples.openSampleFileStream("SampleSS.xlsx")); OPCPackage pkg = OPCPackage.open(_ssTests.openResourceAsStream("SampleSS.xlsx"));
XSSFReader r = new XSSFReader(pkg); XSSFReader r = new XSSFReader(pkg);
@ -46,7 +48,7 @@ public final class TestXSSFReader extends TestCase {
} }
public void testStyles() throws Exception { 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); XSSFReader r = new XSSFReader(pkg);
@ -55,7 +57,7 @@ public final class TestXSSFReader extends TestCase {
} }
public void testStrings() throws Exception { 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); XSSFReader r = new XSSFReader(pkg);
@ -64,7 +66,7 @@ public final class TestXSSFReader extends TestCase {
} }
public void testSheets() throws Exception { 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); XSSFReader r = new XSSFReader(pkg);
byte[] data = new byte[4096]; byte[] data = new byte[4096];
@ -96,7 +98,7 @@ public final class TestXSSFReader extends TestCase {
* (as they are defined in the workbook.xml) * (as they are defined in the workbook.xml)
*/ */
public void testOrderOfSheets() throws Exception { 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); XSSFReader r = new XSSFReader(pkg);

View File

@ -28,23 +28,15 @@ import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.poi.xssf.usermodel.XSSFPictureData; import org.apache.poi.xssf.usermodel.XSSFPictureData;
import org.apache.poi.xssf.XSSFITestDataProvider;
import org.apache.poi.POIDataSamples;
public class TestLoadSaveXSSF extends TestCase { public class TestLoadSaveXSSF extends TestCase {
private static final POIDataSamples _ssSampels = POIDataSamples.getSpreadSheetInstance();
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";
}
}
public void testLoadSample() throws Exception { 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(3, workbook.getNumberOfSheets());
assertEquals("Sheet1", workbook.getSheetName(0)); assertEquals("Sheet1", workbook.getSheetName(0));
Sheet sheet = workbook.getSheetAt(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. // TODO filename string hard coded in XSSFWorkbook constructor in order to make ant test-ooxml target be successful.
public void testLoadStyles() throws Exception { 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); Sheet sheet = workbook.getSheetAt(0);
Row row = sheet.getRow(0); Row row = sheet.getRow(0);
Cell cell = row.getCell((short) 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. // TODO filename string hard coded in XSSFWorkbook constructor in order to make ant test-ooxml target be successful.
public void testLoadPictures() throws Exception { public void testLoadPictures() throws Exception {
XSSFWorkbook workbook = new XSSFWorkbook(new File(filename, "picture.xlsx").getAbsolutePath()); XSSFWorkbook workbook = new XSSFWorkbook(_ssSampels.openResourceAsStream("picture.xlsx"));
List<XSSFPictureData> pictures = workbook.getAllPictures(); List<XSSFPictureData> pictures = workbook.getAllPictures();
assertEquals(1, pictures.size()); assertEquals(1, pictures.size());
} }

View File

@ -28,7 +28,7 @@ import java.io.*;
public class XWPFTestDataSamples { public class XWPFTestDataSamples {
public static XWPFDocument openSampleDocument(String sampleName) { public static XWPFDocument openSampleDocument(String sampleName) {
InputStream is = HWPFTestDataSamples.openSampleFileStream(sampleName); InputStream is = POIDataSamples.getDocumentInstance().openResourceAsStream(sampleName);
try { try {
return new XWPFDocument(is); return new XWPFDocument(is);
} catch (IOException e) { } catch (IOException e) {
@ -46,9 +46,4 @@ public class XWPFTestDataSamples {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
} }
public static POIDataSamples getInstance(){
return HWPFTestDataSamples.getInstance();
}
} }

View File

@ -25,7 +25,7 @@ import junit.framework.TestCase;
import java.io.*; import java.io.*;
import org.apache.poi.hslf.HSLFSlideShow; import org.apache.poi.hslf.HSLFSlideShow;
import org.apache.poi.hwpf.HWPFDocument; import org.apache.poi.hwpf.HWPFTestDataSamples;
import org.apache.poi.poifs.filesystem.*; import org.apache.poi.poifs.filesystem.*;
/** /**
@ -41,29 +41,15 @@ public final class TestPOIDocumentScratchpad extends TestCase {
// The POI Documents to work on // The POI Documents to work on
private POIDocument doc; private POIDocument doc;
private POIDocument doc2; 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 * Set things up, using a PowerPoint document and
* a Word Document for our testing * a Word Document for our testing
*/ */
public void setUp() throws Exception { public void setUp() throws Exception {
String dirnameHSLF = System.getProperty("HSLF.testdata.path"); doc = new HSLFSlideShow(POIDataSamples.getSlideShowInstance().openResourceAsStream("basic_test_ppt_file.ppt"));
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";
FileInputStream fisHSLF = new FileInputStream(filenameHSLF); doc2 = HWPFTestDataSamples.openSampleFile("test2.doc");
pfs = new POIFSFileSystem(fisHSLF);
doc = new HSLFSlideShow(pfs);
FileInputStream fisHWPF = new FileInputStream(filenameHWPF);
pfs2 = new POIFSFileSystem(fisHWPF);
doc2 = new HWPFDocument(pfs2);
} }
public void testReadProperties() { public void testReadProperties() {

View File

@ -23,6 +23,7 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import junit.framework.TestCase; import junit.framework.TestCase;
import org.apache.poi.POIDataSamples;
/** /**
* Class to test {@link HDFDocument} functionality * Class to test {@link HDFDocument} functionality
@ -30,19 +31,12 @@ import junit.framework.TestCase;
* @author Bob Otterberg * @author Bob Otterberg
*/ */
public final class TestHDFDocument extends TestCase { public final class TestHDFDocument extends TestCase {
private static final POIDataSamples _samples = POIDataSamples.getDocumentInstance();
public void testStopJUnitComplainintAboutNoTests() { public void testStopJUnitComplainintAboutNoTests() {
// TODO - fix these junits // 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).<P> * OBJECTIVE: Test that HDF can read an empty document (empty.doc).<P>
* SUCCESS: HDF reads the document. Matches values in their particular positions.<P> * SUCCESS: HDF reads the document. Matches values in their particular positions.<P>
@ -50,7 +44,7 @@ public final class TestHDFDocument extends TestCase {
* in the document in their known positions.<P> * in the document in their known positions.<P>
*/ */
public void fixme_testEmpty() throws IOException { public void fixme_testEmpty() throws IOException {
InputStream stream = openSample("empty.doc"); InputStream stream = _samples.openResourceAsStream("empty.doc");
new HDFDocument(stream); new HDFDocument(stream);
} }
@ -61,7 +55,7 @@ public final class TestHDFDocument extends TestCase {
* in the document in their known positions.<P> * in the document in their known positions.<P>
*/ */
public void fixme_testSimple() throws IOException { public void fixme_testSimple() throws IOException {
InputStream stream = openSample("simple.doc"); InputStream stream = _samples.openResourceAsStream("simple.doc");
new HDFDocument(stream); new HDFDocument(stream);
} }
@ -73,7 +67,7 @@ public final class TestHDFDocument extends TestCase {
* *
*/ */
public void fixme_testSimpleList() throws IOException { public void fixme_testSimpleList() throws IOException {
InputStream stream = openSample("simple-list.doc"); InputStream stream = _samples.openResourceAsStream("simple-list.doc");
new HDFDocument(stream); new HDFDocument(stream);
} }
@ -84,7 +78,7 @@ public final class TestHDFDocument extends TestCase {
* in the document in their known positions.<P> * in the document in their known positions.<P>
*/ */
public void fixme_testSimpleTable() throws IOException { public void fixme_testSimpleTable() throws IOException {
InputStream stream = openSample("simple-table.doc"); InputStream stream = _samples.openResourceAsStream("simple-table.doc");
new HDFDocument(stream); new HDFDocument(stream);
} }
} }

View File

@ -22,18 +22,17 @@ import java.io.FileInputStream;
import org.apache.poi.hdgf.streams.PointerContainingStream; import org.apache.poi.hdgf.streams.PointerContainingStream;
import org.apache.poi.hdgf.streams.TrailerStream; import org.apache.poi.hdgf.streams.TrailerStream;
import org.apache.poi.poifs.filesystem.POIFSFileSystem; import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.POIDataSamples;
import junit.framework.TestCase; import junit.framework.TestCase;
public final class TestHDGFCore extends TestCase { public final class TestHDGFCore extends TestCase {
private static POIDataSamples _dgTests = POIDataSamples.getDiagramInstance();
private POIFSFileSystem fs; private POIFSFileSystem fs;
private String dirname;
private String filename;
protected void setUp() throws Exception { protected void setUp() throws Exception {
dirname = System.getProperty("HDGF.testdata.path"); fs = new POIFSFileSystem(_dgTests.openResourceAsStream("Test_Visio-Some_Random_Text.vsd"));
filename = dirname + "/Test_Visio-Some_Random_Text.vsd";
fs = new POIFSFileSystem(new FileInputStream(filename));
} }
public void testCreate() throws Exception { public void testCreate() throws Exception {
@ -68,8 +67,7 @@ public final class TestHDGFCore extends TestCase {
* appears to have a negative chunk length * appears to have a negative chunk length
*/ */
public void DISABLEDtestNegativeChunkLength() throws Exception { public void DISABLEDtestNegativeChunkLength() throws Exception {
filename = dirname + "/NegativeChunkLength.vsd"; fs = new POIFSFileSystem(_dgTests.openResourceAsStream("NegativeChunkLength.vsd"));
fs = new POIFSFileSystem(new FileInputStream(filename));
HDGFDiagram hdgf = new HDGFDiagram(fs); HDGFDiagram hdgf = new HDGFDiagram(fs);
assertNotNull(hdgf); assertNotNull(hdgf);

View File

@ -19,20 +19,20 @@ package org.apache.poi.hdgf.extractor;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.File; import java.io.File;
import java.io.FileInputStream;
import java.io.PrintStream; import java.io.PrintStream;
import junit.framework.TestCase; import junit.framework.TestCase;
import org.apache.poi.hdgf.HDGFDiagram; import org.apache.poi.hdgf.HDGFDiagram;
import org.apache.poi.poifs.filesystem.POIFSFileSystem; import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.POIDataSamples;
public final class TestVisioExtractor extends TestCase { public final class TestVisioExtractor extends TestCase {
private String dirname; private static POIDataSamples _dgTests = POIDataSamples.getDiagramInstance();
private String defFilename; private String defFilename;
protected void setUp() { protected void setUp() {
dirname = System.getProperty("HDGF.testdata.path"); defFilename = "Test_Visio-Some_Random_Text.vsd";
defFilename = dirname + "/Test_Visio-Some_Random_Text.vsd";
} }
/** /**
@ -41,14 +41,14 @@ public final class TestVisioExtractor extends TestCase {
public void testCreation() throws Exception { public void testCreation() throws Exception {
VisioTextExtractor extractor; VisioTextExtractor extractor;
extractor = new VisioTextExtractor(new FileInputStream(defFilename)); extractor = new VisioTextExtractor(_dgTests.openResourceAsStream(defFilename));
assertNotNull(extractor); assertNotNull(extractor);
assertNotNull(extractor.getAllText()); assertNotNull(extractor.getAllText());
assertEquals(3, extractor.getAllText().length); assertEquals(3, extractor.getAllText().length);
extractor = new VisioTextExtractor( extractor = new VisioTextExtractor(
new POIFSFileSystem( new POIFSFileSystem(
new FileInputStream(defFilename) _dgTests.openResourceAsStream(defFilename)
) )
); );
assertNotNull(extractor); assertNotNull(extractor);
@ -58,7 +58,7 @@ public final class TestVisioExtractor extends TestCase {
extractor = new VisioTextExtractor( extractor = new VisioTextExtractor(
new HDGFDiagram( new HDGFDiagram(
new POIFSFileSystem( new POIFSFileSystem(
new FileInputStream(defFilename) _dgTests.openResourceAsStream(defFilename)
) )
) )
); );
@ -69,7 +69,7 @@ public final class TestVisioExtractor extends TestCase {
public void testExtraction() throws Exception { public void testExtraction() throws Exception {
VisioTextExtractor extractor = VisioTextExtractor extractor =
new VisioTextExtractor(new FileInputStream(defFilename)); new VisioTextExtractor(_dgTests.openResourceAsStream(defFilename));
// Check the array fetch // Check the array fetch
String[] text = extractor.getAllText(); String[] text = extractor.getAllText();
@ -86,20 +86,11 @@ public final class TestVisioExtractor extends TestCase {
} }
public void testProblemFiles() throws Exception { public void testProblemFiles() throws Exception {
File a = new File(dirname, "44594.vsd"); String[] files = {"44594.vsd", "44594-2.vsd", "ShortChunk1.vsd", "ShortChunk2.vsd", "ShortChunk3.vsd"};
VisioTextExtractor.main(new String[] {a.toString()}); for(String file : files){
VisioTextExtractor ex = new VisioTextExtractor(_dgTests.openResourceAsStream(file));
File b = new File(dirname, "44594-2.vsd"); ex.getText();
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()});
} }
public void testMain() throws Exception { public void testMain() throws Exception {
@ -108,7 +99,8 @@ public final class TestVisioExtractor extends TestCase {
PrintStream capture = new PrintStream(baos); PrintStream capture = new PrintStream(baos);
System.setOut(capture); System.setOut(capture);
VisioTextExtractor.main(new String[] {defFilename}); String path = _dgTests.getFile(defFilename).getPath();
VisioTextExtractor.main(new String[] {path});
// Put things back // Put things back
System.setOut(oldOut); System.setOut(oldOut);

View File

@ -18,6 +18,7 @@
package org.apache.poi.hdgf.streams; package org.apache.poi.hdgf.streams;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.InputStream;
import org.apache.poi.hdgf.HDGFDiagram; import org.apache.poi.hdgf.HDGFDiagram;
import org.apache.poi.hdgf.chunks.ChunkFactory; 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.hdgf.pointers.PointerFactory;
import org.apache.poi.poifs.filesystem.DocumentEntry; import org.apache.poi.poifs.filesystem.DocumentEntry;
import org.apache.poi.poifs.filesystem.POIFSFileSystem; import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.POIDataSamples;
/** /**
* Tests for bugs with streams * Tests for bugs with streams
@ -36,13 +38,11 @@ public final class TestStreamBugs extends StreamTest {
private POIFSFileSystem filesystem; private POIFSFileSystem filesystem;
protected void setUp() throws Exception { protected void setUp() throws Exception {
String dirname = System.getProperty("HDGF.testdata.path");
String filename = dirname + "/44594.vsd";
ptrFactory = new PointerFactory(11); ptrFactory = new PointerFactory(11);
chunkFactory = new ChunkFactory(11); chunkFactory = new ChunkFactory(11);
FileInputStream fin = new FileInputStream(filename); InputStream is = POIDataSamples.getDiagramInstance().openResourceAsStream("44594.vsd");
filesystem = new POIFSFileSystem(fin); filesystem = new POIFSFileSystem(is);
DocumentEntry docProps = DocumentEntry docProps =
(DocumentEntry)filesystem.getRoot().getEntry("VisioDocument"); (DocumentEntry)filesystem.getRoot().getEntry("VisioDocument");

View File

@ -18,6 +18,7 @@
package org.apache.poi.hdgf.streams; package org.apache.poi.hdgf.streams;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.InputStream;
import org.apache.poi.hdgf.chunks.Chunk; import org.apache.poi.hdgf.chunks.Chunk;
import org.apache.poi.hdgf.chunks.ChunkFactory; 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.hdgf.pointers.PointerFactory;
import org.apache.poi.poifs.filesystem.DocumentEntry; import org.apache.poi.poifs.filesystem.DocumentEntry;
import org.apache.poi.poifs.filesystem.POIFSFileSystem; import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.POIDataSamples;
public final class TestStreamComplex extends StreamTest { public final class TestStreamComplex extends StreamTest {
private byte[] contents; private byte[] contents;
@ -34,13 +36,11 @@ public final class TestStreamComplex extends StreamTest {
private PointerFactory ptrFactory; private PointerFactory ptrFactory;
protected void setUp() throws Exception { 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); ptrFactory = new PointerFactory(11);
chunkFactory = new ChunkFactory(11); chunkFactory = new ChunkFactory(11);
FileInputStream fin = new FileInputStream(filename); InputStream is = POIDataSamples.getDiagramInstance().openResourceAsStream("Test_Visio-Some_Random_Text.vsd");
POIFSFileSystem filesystem = new POIFSFileSystem(fin); POIFSFileSystem filesystem = new POIFSFileSystem(is);
DocumentEntry docProps = DocumentEntry docProps =
(DocumentEntry)filesystem.getRoot().getEntry("VisioDocument"); (DocumentEntry)filesystem.getRoot().getEntry("VisioDocument");

View File

@ -21,27 +21,22 @@ import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import junit.framework.TestCase; import junit.framework.TestCase;
import org.apache.poi.POIDataSamples;
public final class TestHPBFDocument extends TestCase { public final class TestHPBFDocument extends TestCase {
private String dir; private static final POIDataSamples _samples = POIDataSamples.getPublisherInstance();
protected void setUp() {
dir = System.getProperty("HPBF.testdata.path");
}
public void testOpen() throws Exception { public void testOpen() throws Exception {
File f = new File(dir, "Sample.pub");
HPBFDocument doc = new HPBFDocument( HPBFDocument doc = new HPBFDocument(
new FileInputStream(f) _samples.openResourceAsStream("Sample.pub")
); );
assertNotNull(doc); assertNotNull(doc);
} }
public void testBits() throws Exception { public void testBits() throws Exception {
File f = new File(dir, "Sample.pub");
HPBFDocument doc = new HPBFDocument( HPBFDocument doc = new HPBFDocument(
new FileInputStream(f) _samples.openResourceAsStream("Sample.pub")
); );
assertNotNull(doc.getMainContents()); assertNotNull(doc.getMainContents());

View File

@ -21,37 +21,31 @@ import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import org.apache.poi.hpbf.HPBFDocument; import org.apache.poi.hpbf.HPBFDocument;
import org.apache.poi.POIDataSamples;
import junit.framework.TestCase; import junit.framework.TestCase;
public final class TextPublisherTextExtractor extends TestCase { public final class TextPublisherTextExtractor extends TestCase {
private String dir; private static final POIDataSamples _samples = POIDataSamples.getPublisherInstance();
protected void setUp() {
dir = System.getProperty("HPBF.testdata.path");
}
public void testBasics() throws Exception { public void testBasics() throws Exception {
File f = new File(dir, "Sample.pub");
HPBFDocument doc = new HPBFDocument( HPBFDocument doc = new HPBFDocument(
new FileInputStream(f) _samples.openResourceAsStream("Sample.pub")
); );
PublisherTextExtractor ext = PublisherTextExtractor ext =
new PublisherTextExtractor(doc); new PublisherTextExtractor(doc);
ext.getText(); ext.getText();
f = new File(dir, "Simple.pub");
ext = new PublisherTextExtractor( ext = new PublisherTextExtractor(
new FileInputStream(f) _samples.openResourceAsStream("Simple.pub")
); );
ext.getText(); ext.getText();
} }
public void testContents() throws Exception { public void testContents() throws Exception {
File f = new File(dir, "Sample.pub");
HPBFDocument doc = new HPBFDocument( HPBFDocument doc = new HPBFDocument(
new FileInputStream(f) _samples.openResourceAsStream("Sample.pub")
); );
PublisherTextExtractor ext = PublisherTextExtractor ext =
@ -87,9 +81,8 @@ public final class TextPublisherTextExtractor extends TestCase {
); );
// Now a simpler one // Now a simpler one
f = new File(dir, "Simple.pub");
ext = new PublisherTextExtractor( ext = new PublisherTextExtractor(
new FileInputStream(f) _samples.openResourceAsStream("Simple.pub")
); );
text = ext.getText(); text = ext.getText();
assertEquals( assertEquals(
@ -113,21 +106,18 @@ public final class TextPublisherTextExtractor extends TestCase {
File f; File f;
HPBFDocument doc; HPBFDocument doc;
f = new File(dir, "Sample.pub");
doc = new HPBFDocument( doc = new HPBFDocument(
new FileInputStream(f) _samples.openResourceAsStream("Sample.pub")
); );
String s2007 = (new PublisherTextExtractor(doc)).getText(); String s2007 = (new PublisherTextExtractor(doc)).getText();
f = new File(dir, "Sample2000.pub");
doc = new HPBFDocument( doc = new HPBFDocument(
new FileInputStream(f) _samples.openResourceAsStream("Sample2000.pub")
); );
String s2000 = (new PublisherTextExtractor(doc)).getText(); String s2000 = (new PublisherTextExtractor(doc)).getText();
f = new File(dir, "Sample98.pub");
doc = new HPBFDocument( doc = new HPBFDocument(
new FileInputStream(f) _samples.openResourceAsStream("Sample98.pub")
); );
String s98 = (new PublisherTextExtractor(doc)).getText(); String s98 = (new PublisherTextExtractor(doc)).getText();
@ -141,9 +131,8 @@ public final class TextPublisherTextExtractor extends TestCase {
* as we can hope it to. * as we can hope it to.
*/ */
public void testWithHyperlinks() throws Exception { public void testWithHyperlinks() throws Exception {
File f = new File(dir, "LinkAt10.pub");
HPBFDocument doc = new HPBFDocument( HPBFDocument doc = new HPBFDocument(
new FileInputStream(f) _samples.openResourceAsStream("LinkAt10.pub")
); );
PublisherTextExtractor ext = PublisherTextExtractor ext =
@ -159,8 +148,9 @@ public final class TextPublisherTextExtractor extends TestCase {
// Now a much more complex document // Now a much more complex document
f = new File(dir, "Sample.pub"); ext = new PublisherTextExtractor(
ext = new PublisherTextExtractor(new FileInputStream(f)); _samples.openResourceAsStream("Sample.pub")
);
ext.setHyperlinksByDefault(true); ext.setHyperlinksByDefault(true);
String text = ext.getText(); String text = ext.getText();

View File

@ -21,20 +21,16 @@ import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import org.apache.poi.hpbf.HPBFDocument; import org.apache.poi.hpbf.HPBFDocument;
import org.apache.poi.POIDataSamples;
import junit.framework.TestCase; import junit.framework.TestCase;
public final class TestEscherParts extends TestCase { public final class TestEscherParts extends TestCase {
private String dir; private static final POIDataSamples _samples = POIDataSamples.getPublisherInstance();
protected void setUp() {
dir = System.getProperty("HPBF.testdata.path");
}
public void testBasics() throws Exception { public void testBasics() throws Exception {
File f = new File(dir, "Sample.pub");
HPBFDocument doc = new HPBFDocument( HPBFDocument doc = new HPBFDocument(
new FileInputStream(f) _samples.openResourceAsStream("Sample.pub")
); );
EscherStm es = doc.getEscherStm(); EscherStm es = doc.getEscherStm();
@ -50,9 +46,8 @@ public final class TestEscherParts extends TestCase {
} }
public void testComplex() throws Exception { public void testComplex() throws Exception {
File f = new File(dir, "SampleBrochure.pub");
HPBFDocument doc = new HPBFDocument( HPBFDocument doc = new HPBFDocument(
new FileInputStream(f) _samples.openResourceAsStream("SampleBrochure.pub")
); );
EscherStm es = doc.getEscherStm(); EscherStm es = doc.getEscherStm();
@ -68,9 +63,8 @@ public final class TestEscherParts extends TestCase {
// Now do another complex file // Now do another complex file
f = new File(dir, "SampleNewsletter.pub");
doc = new HPBFDocument( doc = new HPBFDocument(
new FileInputStream(f) _samples.openResourceAsStream("SampleNewsletter.pub")
); );
es = doc.getEscherStm(); es = doc.getEscherStm();

View File

@ -17,29 +17,22 @@
package org.apache.poi.hpbf.model; 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.HPBFDocument;
import org.apache.poi.hpbf.model.qcbits.QCTextBit; 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.Type12;
import org.apache.poi.hpbf.model.qcbits.QCPLCBit.Type0; 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.Type4;
import org.apache.poi.hpbf.model.qcbits.QCPLCBit.Type8; import org.apache.poi.hpbf.model.qcbits.QCPLCBit.Type8;
import org.apache.poi.POIDataSamples;
import junit.framework.TestCase; import junit.framework.TestCase;
public final class TestQuillContents extends TestCase { public final class TestQuillContents extends TestCase {
private String dir; private static final POIDataSamples _samples = POIDataSamples.getPublisherInstance();
protected void setUp() {
dir = System.getProperty("HPBF.testdata.path");
}
public void testBasics() throws Exception { public void testBasics() throws Exception {
File f = new File(dir, "Sample.pub");
HPBFDocument doc = new HPBFDocument( HPBFDocument doc = new HPBFDocument(
new FileInputStream(f) _samples.openResourceAsStream("Sample.pub")
); );
QuillContents qc = doc.getQuillContents(); QuillContents qc = doc.getQuillContents();
@ -69,9 +62,8 @@ public final class TestQuillContents extends TestCase {
} }
public void testText() throws Exception { public void testText() throws Exception {
File f = new File(dir, "Sample.pub");
HPBFDocument doc = new HPBFDocument( HPBFDocument doc = new HPBFDocument(
new FileInputStream(f) _samples.openResourceAsStream("Sample.pub")
); );
QuillContents qc = doc.getQuillContents(); QuillContents qc = doc.getQuillContents();
@ -84,9 +76,8 @@ public final class TestQuillContents extends TestCase {
} }
public void testPLC() throws Exception { public void testPLC() throws Exception {
File f = new File(dir, "Simple.pub");
HPBFDocument doc = new HPBFDocument( HPBFDocument doc = new HPBFDocument(
new FileInputStream(f) _samples.openResourceAsStream("Simple.pub")
); );
QuillContents qc = doc.getQuillContents(); QuillContents qc = doc.getQuillContents();
@ -145,9 +136,8 @@ public final class TestQuillContents extends TestCase {
} }
public void testComplexPLC() throws Exception { public void testComplexPLC() throws Exception {
File f = new File(dir, "Sample.pub");
HPBFDocument doc = new HPBFDocument( HPBFDocument doc = new HPBFDocument(
new FileInputStream(f) _samples.openResourceAsStream("Sample.pub")
); );
QuillContents qc = doc.getQuillContents(); QuillContents qc = doc.getQuillContents();
@ -247,9 +237,8 @@ public final class TestQuillContents extends TestCase {
} }
public void testNoHyperlinks() throws Exception { public void testNoHyperlinks() throws Exception {
File f = new File(dir, "SampleNewsletter.pub");
HPBFDocument doc = new HPBFDocument( HPBFDocument doc = new HPBFDocument(
new FileInputStream(f) _samples.openResourceAsStream("SampleNewsletter.pub")
); );
QuillContents qc = doc.getQuillContents(); QuillContents qc = doc.getQuillContents();
@ -264,15 +253,13 @@ public final class TestQuillContents extends TestCase {
} }
public void testSimpleHyperlink() throws Exception { public void testSimpleHyperlink() throws Exception {
File f;
HPBFDocument doc; HPBFDocument doc;
QuillContents qc; QuillContents qc;
Type12 hlBit; Type12 hlBit;
// Link at 10 // Link at 10
f = new File(dir, "LinkAt10.pub");
doc = new HPBFDocument( doc = new HPBFDocument(
new FileInputStream(f) _samples.openResourceAsStream("LinkAt10.pub")
); );
qc = doc.getQuillContents(); qc = doc.getQuillContents();
@ -285,9 +272,8 @@ public final class TestQuillContents extends TestCase {
assertEquals("http://poi.apache.org/", hlBit.getHyperlink(0)); assertEquals("http://poi.apache.org/", hlBit.getHyperlink(0));
// Longer link at 10 // Longer link at 10
f = new File(dir, "LinkAt10Longer.pub");
doc = new HPBFDocument( doc = new HPBFDocument(
new FileInputStream(f) _samples.openResourceAsStream("LinkAt10Longer.pub")
); );
qc = doc.getQuillContents(); qc = doc.getQuillContents();
@ -300,9 +286,8 @@ public final class TestQuillContents extends TestCase {
assertEquals("http://poi.apache.org/hpbf/", hlBit.getHyperlink(0)); assertEquals("http://poi.apache.org/hpbf/", hlBit.getHyperlink(0));
// Link at 20 // Link at 20
f = new File(dir, "LinkAt20.pub");
doc = new HPBFDocument( doc = new HPBFDocument(
new FileInputStream(f) _samples.openResourceAsStream("LinkAt20.pub")
); );
qc = doc.getQuillContents(); qc = doc.getQuillContents();
@ -316,15 +301,13 @@ public final class TestQuillContents extends TestCase {
} }
public void testManyHyperlinks() throws Exception { public void testManyHyperlinks() throws Exception {
File f;
HPBFDocument doc; HPBFDocument doc;
QuillContents qc; QuillContents qc;
Type12 hlBit; Type12 hlBit;
// Link at 10 // Link at 10
f = new File(dir, "LinkAt10.pub");
doc = new HPBFDocument( doc = new HPBFDocument(
new FileInputStream(f) _samples.openResourceAsStream("LinkAt10.pub")
); );
qc = doc.getQuillContents(); qc = doc.getQuillContents();
@ -339,16 +322,14 @@ public final class TestQuillContents extends TestCase {
} }
public void testHyperlinkDifferentVersions() throws Exception { public void testHyperlinkDifferentVersions() throws Exception {
File f;
HPBFDocument doc; HPBFDocument doc;
QuillContents qc; QuillContents qc;
Type12 hlBitA; Type12 hlBitA;
Type12 hlBitB; Type12 hlBitB;
// Latest version // Latest version
f = new File(dir, "Sample.pub");
doc = new HPBFDocument( doc = new HPBFDocument(
new FileInputStream(f) _samples.openResourceAsStream("Sample.pub")
); );
qc = doc.getQuillContents(); qc = doc.getQuillContents();
@ -375,9 +356,8 @@ public final class TestQuillContents extends TestCase {
assertEquals("mailto:dev@poi.apache.org?subject=HPBF", hlBitB.getHyperlink(2)); assertEquals("mailto:dev@poi.apache.org?subject=HPBF", hlBitB.getHyperlink(2));
// 2000 version // 2000 version
f = new File(dir, "Sample2000.pub");
doc = new HPBFDocument( doc = new HPBFDocument(
new FileInputStream(f) _samples.openResourceAsStream("Sample2000.pub")
); );
qc = doc.getQuillContents(); qc = doc.getQuillContents();
@ -404,9 +384,8 @@ public final class TestQuillContents extends TestCase {
assertEquals("mailto:dev@poi.apache.org?subject=HPBF", hlBitB.getHyperlink(2)); assertEquals("mailto:dev@poi.apache.org?subject=HPBF", hlBitB.getHyperlink(2));
// 98 version // 98 version
f = new File(dir, "Sample98.pub");
doc = new HPBFDocument( doc = new HPBFDocument(
new FileInputStream(f) _samples.openResourceAsStream("Sample98.pub")
); );
qc = doc.getQuillContents(); qc = doc.getQuillContents();

View File

@ -21,6 +21,7 @@ package org.apache.poi.hslf;
import junit.framework.TestCase; import junit.framework.TestCase;
import org.apache.poi.hslf.exceptions.EncryptedPowerPointFileException; import org.apache.poi.hslf.exceptions.EncryptedPowerPointFileException;
import org.apache.poi.POIDataSamples;
/** /**
* Tests that HSLFSlideShow does the right thing with an encrypted file * 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) * @author Nick Burch (nick at torchbox dot com)
*/ */
public final class TestEncryptedFile extends TestCase { public final class TestEncryptedFile extends TestCase {
// A non encrypted file private static POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
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";
}
public void testLoadNonEncrypted() throws Exception { public void testLoadNonEncrypted() throws Exception {
HSLFSlideShow hss = new HSLFSlideShow(ss_ne); HSLFSlideShow hss = new HSLFSlideShow(slTests.openResourceAsStream("basic_test_ppt_file.ppt"));
assertNotNull(hss); assertNotNull(hss);
} }
public void testLoadEncrypted() throws Exception { public void testLoadEncrypted() throws Exception {
try { try {
new HSLFSlideShow(ss_e); new HSLFSlideShow(slTests.openResourceAsStream("Password_Protected-hello.ppt"));
fail(); fail();
} catch(EncryptedPowerPointFileException e) { } catch(EncryptedPowerPointFileException e) {
// Good // Good
} }
try { try {
new HSLFSlideShow(ss_np_e); new HSLFSlideShow(slTests.openResourceAsStream("Password_Protected-np-hello.ppt"));
fail(); fail();
} catch(EncryptedPowerPointFileException e) { } catch(EncryptedPowerPointFileException e) {
// Good // Good
} }
try { try {
new HSLFSlideShow(ss_56_e); new HSLFSlideShow(slTests.openResourceAsStream("Password_Protected-56-hello.ppt"));
fail(); fail();
} catch(EncryptedPowerPointFileException e) { } catch(EncryptedPowerPointFileException e) {
// Good // Good

View File

@ -19,10 +19,14 @@ package org.apache.poi.hslf;
import junit.framework.TestCase; import junit.framework.TestCase;
import java.io.*;
import org.apache.poi.hslf.usermodel.SlideShow; import org.apache.poi.hslf.usermodel.SlideShow;
import org.apache.poi.poifs.filesystem.*; 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 * Tests that HSLFSlideShow writes the powerpoint bit of data back out
@ -41,21 +45,16 @@ public final class TestReWrite extends TestCase {
private POIFSFileSystem pfsC; private POIFSFileSystem pfsC;
public void setUp() throws Exception { public void setUp() throws Exception {
String dirname = System.getProperty("HSLF.testdata.path");
String filenameA = dirname + "/basic_test_ppt_file.ppt"; POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
FileInputStream fisA = new FileInputStream(filenameA);
pfsA = new POIFSFileSystem(fisA); pfsA = new POIFSFileSystem(slTests.openResourceAsStream("basic_test_ppt_file.ppt"));
hssA = new HSLFSlideShow(pfsA); hssA = new HSLFSlideShow(pfsA);
String filenameB = dirname + "/ParagraphStylesShorterThanCharStyles.ppt"; pfsB = new POIFSFileSystem(slTests.openResourceAsStream("ParagraphStylesShorterThanCharStyles.ppt"));
FileInputStream fisB = new FileInputStream(filenameB);
pfsB = new POIFSFileSystem(fisB);
hssB = new HSLFSlideShow(pfsB); hssB = new HSLFSlideShow(pfsB);
String filenameC = dirname + "/WithMacros.ppt"; pfsC = new POIFSFileSystem(slTests.openResourceAsStream("WithMacros.ppt"));
FileInputStream fisC = new FileInputStream(filenameC);
pfsC = new POIFSFileSystem(fisC);
hssC = new HSLFSlideShow(pfsC); hssC = new HSLFSlideShow(pfsC);
} }

View File

@ -23,6 +23,7 @@ import java.io.*;
import java.util.*; import java.util.*;
import org.apache.poi.hslf.record.*; import org.apache.poi.hslf.record.*;
import org.apache.poi.poifs.filesystem.*; import org.apache.poi.poifs.filesystem.*;
import org.apache.poi.POIDataSamples;
/** /**
* Tests that HSLFSlideShow writes the powerpoint bit of data back out * Tests that HSLFSlideShow writes the powerpoint bit of data back out
@ -37,10 +38,8 @@ public final class TestReWriteSanity extends TestCase {
private POIFSFileSystem pfs; private POIFSFileSystem pfs;
public TestReWriteSanity() throws Exception { public TestReWriteSanity() throws Exception {
String dirname = System.getProperty("HSLF.testdata.path"); POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
String filename = dirname + "/basic_test_ppt_file.ppt"; pfs = new POIFSFileSystem(slTests.openResourceAsStream("basic_test_ppt_file.ppt"));
FileInputStream fis = new FileInputStream(filename);
pfs = new POIFSFileSystem(fis);
ss = new HSLFSlideShow(pfs); ss = new HSLFSlideShow(pfs);
} }

View File

@ -20,6 +20,7 @@ package org.apache.poi.hslf;
import junit.framework.TestCase; import junit.framework.TestCase;
import org.apache.poi.hslf.record.*; import org.apache.poi.hslf.record.*;
import org.apache.poi.POIDataSamples;
/** /**
* Tests that HSLFSlideShow returns the right numbers of key records when * Tests that HSLFSlideShow returns the right numbers of key records when
@ -32,9 +33,8 @@ public final class TestRecordCounts extends TestCase {
private HSLFSlideShow ss; private HSLFSlideShow ss;
public TestRecordCounts() throws Exception { public TestRecordCounts() throws Exception {
String dirname = System.getProperty("HSLF.testdata.path"); POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
String filename = dirname + "/basic_test_ppt_file.ppt"; ss = new HSLFSlideShow(slTests.openResourceAsStream("basic_test_ppt_file.ppt"));
ss = new HSLFSlideShow(filename);
} }
public void testSheetsCount() { public void testSheetsCount() {

View File

@ -21,6 +21,8 @@ package org.apache.poi.hslf.extractor;
import junit.framework.TestCase; import junit.framework.TestCase;
import java.util.Vector; import java.util.Vector;
import org.apache.poi.POIDataSamples;
/** /**
* Tests that the QuickButCruddyTextExtractor works correctly * Tests that the QuickButCruddyTextExtractor works correctly
* *
@ -56,9 +58,8 @@ public final class TestCruddyExtractor extends TestCase {
}; };
public TestCruddyExtractor() throws Exception { public TestCruddyExtractor() throws Exception {
String dirname = System.getProperty("HSLF.testdata.path"); POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
String filename = dirname + "/basic_test_ppt_file.ppt"; te = new QuickButCruddyTextExtractor(slTests.openResourceAsStream("basic_test_ppt_file.ppt"));
te = new QuickButCruddyTextExtractor(filename);
} }
public void testReadAsVector() { public void testReadAsVector() {

View File

@ -28,6 +28,7 @@ import org.apache.poi.poifs.filesystem.DirectoryNode;
import org.apache.poi.poifs.filesystem.POIFSFileSystem; import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hwpf.HWPFDocument; import org.apache.poi.hwpf.HWPFDocument;
import org.apache.poi.POIDataSamples;
import junit.framework.TestCase; import junit.framework.TestCase;
@ -41,19 +42,15 @@ public final class TestExtractor extends TestCase {
private PowerPointExtractor ppe; private PowerPointExtractor ppe;
/** Extractor primed on the 1 page but text-box'd test data */ /** Extractor primed on the 1 page but text-box'd test data */
private PowerPointExtractor ppe2; private PowerPointExtractor ppe2;
/** Where to go looking for our test files */
private String dirname;
/** Where our embeded files live */ /** 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 { 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() { public void testReadSheetText() {
@ -114,8 +111,7 @@ public final class TestExtractor extends TestCase {
* @throws Exception * @throws Exception
*/ */
public void testMissingCoreRecords() throws Exception { public void testMissingCoreRecords() throws Exception {
String filename = dirname + "/missing_core_records.ppt"; ppe = new PowerPointExtractor(slTests.openResourceAsStream("missing_core_records.ppt"));
ppe = new PowerPointExtractor(filename);
String text = ppe.getText(true, false); String text = ppe.getText(true, false);
String nText = ppe.getNotes(); String nText = ppe.getNotes();
@ -141,9 +137,8 @@ public final class TestExtractor extends TestCase {
} }
public void testExtractFromEmbeded() throws Exception { public void testExtractFromEmbeded() throws Exception {
String filename3 = pdirname + "/excel_with_embeded.xls";
POIFSFileSystem fs = new POIFSFileSystem( POIFSFileSystem fs = new POIFSFileSystem(
new FileInputStream(filename3) POIDataSamples.getSpreadSheetInstance().openResourceAsStream("excel_with_embeded.xls")
); );
HSLFSlideShow ss; HSLFSlideShow ss;
@ -174,8 +169,8 @@ public final class TestExtractor extends TestCase {
* A powerpoint file with embeded powerpoint files * A powerpoint file with embeded powerpoint files
*/ */
public void testExtractFromOwnEmbeded() throws Exception { public void testExtractFromOwnEmbeded() throws Exception {
String path = pdirname + "/ppt_with_embeded.ppt"; String path = "ppt_with_embeded.ppt";
ppe = new PowerPointExtractor(path); ppe = new PowerPointExtractor(POIDataSamples.getSlideShowInstance().openResourceAsStream(path));
List<OLEShape> shapes = ppe.getOLEShapes(); List<OLEShape> shapes = ppe.getOLEShapes();
assertEquals("Expected 6 ole shapes in " + path, 6, shapes.size()); assertEquals("Expected 6 ole shapes in " + path, 6, shapes.size());
int num_ppt = 0, num_doc = 0, num_xls = 0; int num_ppt = 0, num_doc = 0, num_xls = 0;
@ -202,11 +197,7 @@ public final class TestExtractor extends TestCase {
* From bug #45543 * From bug #45543
*/ */
public void testWithComments() throws Exception { public void testWithComments() throws Exception {
String filename; ppe = new PowerPointExtractor(slTests.openResourceAsStream("WithComments.ppt"));
// New file
filename = dirname + "/WithComments.ppt";
ppe = new PowerPointExtractor(filename);
String text = ppe.getText(); String text = ppe.getText();
assertFalse("Comments not in by default", contains(text, "This is a test comment")); 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 // And another file
filename = dirname + "/45543.ppt"; ppe = new PowerPointExtractor(slTests.openResourceAsStream("45543.ppt"));
ppe = new PowerPointExtractor(filename);
text = ppe.getText(); text = ppe.getText();
assertFalse("Comments not in by default", contains(text, "testdoc")); assertFalse("Comments not in by default", contains(text, "testdoc"));
@ -234,11 +224,10 @@ public final class TestExtractor extends TestCase {
* From bug #45537 * From bug #45537
*/ */
public void testHeaderFooter() throws Exception { public void testHeaderFooter() throws Exception {
String filename, text; String text;
// With a header on the notes // With a header on the notes
filename = dirname + "/45537_Header.ppt"; HSLFSlideShow hslf = new HSLFSlideShow(slTests.openResourceAsStream("45537_Header.ppt"));
HSLFSlideShow hslf = new HSLFSlideShow(new FileInputStream(filename));
SlideShow ss = new SlideShow(hslf); SlideShow ss = new SlideShow(hslf);
assertNotNull(ss.getNotesHeadersFooters()); assertNotNull(ss.getNotesHeadersFooters());
assertEquals("testdoc test phrase", ss.getNotesHeadersFooters().getHeaderText()); assertEquals("testdoc test phrase", ss.getNotesHeadersFooters().getHeaderText());
@ -256,13 +245,12 @@ public final class TestExtractor extends TestCase {
// And with a footer, also on notes // And with a footer, also on notes
filename = dirname + "/45537_Footer.ppt"; hslf = new HSLFSlideShow(slTests.openResourceAsStream("45537_Footer.ppt"));
hslf = new HSLFSlideShow(new FileInputStream(filename));
ss = new SlideShow(hslf); ss = new SlideShow(hslf);
assertNotNull(ss.getNotesHeadersFooters()); assertNotNull(ss.getNotesHeadersFooters());
assertEquals("testdoc test phrase", ss.getNotesHeadersFooters().getFooterText()); assertEquals("testdoc test phrase", ss.getNotesHeadersFooters().getFooterText());
ppe = new PowerPointExtractor(filename); ppe = new PowerPointExtractor(slTests.openResourceAsStream("45537_Footer.ppt"));
text = ppe.getText(); text = ppe.getText();
assertFalse("Unable to find expected word in text\n" + text, contains(text, "testdoc")); assertFalse("Unable to find expected word in text\n" + text, contains(text, "testdoc"));

View File

@ -24,6 +24,7 @@ import java.awt.*;
import org.apache.poi.hslf.usermodel.SlideShow; import org.apache.poi.hslf.usermodel.SlideShow;
import org.apache.poi.hslf.HSLFSlideShow; import org.apache.poi.hslf.HSLFSlideShow;
import org.apache.poi.POIDataSamples;
/** /**
* Test <code>Fill</code> object. * Test <code>Fill</code> object.
@ -31,6 +32,7 @@ import org.apache.poi.hslf.HSLFSlideShow;
* @author Yegor Kozlov * @author Yegor Kozlov
*/ */
public final class TestBackground extends TestCase { public final class TestBackground extends TestCase {
private static POIDataSamples _slTests = POIDataSamples.getSlideShowInstance();
/** /**
* Default background for slide, shape and slide master. * 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 * Read fill information from an reference ppt file
*/ */
public void testReadBackground() throws Exception { 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; Fill fill;
Shape shape; Shape shape;
@ -93,7 +95,7 @@ public final class TestBackground extends TestCase {
slide = ppt.createSlide(); slide = ppt.createSlide();
slide.setFollowMasterBackground(false); slide.setFollowMasterBackground(false);
fill = slide.getBackground().getFill(); 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.setFillType(Fill.FILL_PICTURE);
fill.setPictureData(idx); fill.setPictureData(idx);
@ -107,7 +109,7 @@ public final class TestBackground extends TestCase {
slide = ppt.createSlide(); slide = ppt.createSlide();
slide.setFollowMasterBackground(false); slide.setFollowMasterBackground(false);
fill = slide.getBackground().getFill(); 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.setFillType(Fill.FILL_PATTERN);
fill.setPictureData(idx); fill.setPictureData(idx);
fill.setBackgroundColor(Color.green); fill.setBackgroundColor(Color.green);
@ -123,7 +125,7 @@ public final class TestBackground extends TestCase {
slide = ppt.createSlide(); slide = ppt.createSlide();
slide.setFollowMasterBackground(false); slide.setFollowMasterBackground(false);
fill = slide.getBackground().getFill(); 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.setFillType(Fill.FILL_TEXTURE);
fill.setPictureData(idx); fill.setPictureData(idx);
@ -131,7 +133,7 @@ public final class TestBackground extends TestCase {
shape.setAnchor(new java.awt.Rectangle(100, 100, 200, 200)); shape.setAnchor(new java.awt.Rectangle(100, 100, 200, 200));
fill = shape.getFill(); fill = shape.getFill();
fill.setFillType(Fill.FILL_PICTURE); 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); fill.setPictureData(idx);
slide.addShape(shape); slide.addShape(shape);

View File

@ -19,6 +19,7 @@ package org.apache.poi.hslf.model;
import java.io.*; import java.io.*;
import org.apache.poi.hslf.usermodel.SlideShow; import org.apache.poi.hslf.usermodel.SlideShow;
import org.apache.poi.POIDataSamples;
import junit.framework.TestCase; import junit.framework.TestCase;
@ -28,14 +29,11 @@ import junit.framework.TestCase;
public final class TestHeadersFooters extends 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 public void testRead() throws Exception
{ {
File file = new File(cwd, "headers_footers.ppt"); SlideShow ppt = new SlideShow(_slTests.openResourceAsStream("headers_footers.ppt"));
FileInputStream is = new FileInputStream(file);
SlideShow ppt = new SlideShow(is);
is.close();
HeadersFooters slideHdd = ppt.getSlideHeadersFooters(); HeadersFooters slideHdd = ppt.getSlideHeadersFooters();
assertTrue(slideHdd.isFooterVisible()); assertTrue(slideHdd.isFooterVisible());
@ -79,10 +77,7 @@ public final class TestHeadersFooters extends TestCase
*/ */
public void testReadNoHeadersFooters() throws Exception public void testReadNoHeadersFooters() throws Exception
{ {
File file = new File(cwd, "basic_test_ppt_file.ppt"); SlideShow ppt = new SlideShow(_slTests.openResourceAsStream("basic_test_ppt_file.ppt"));
FileInputStream is = new FileInputStream(file);
SlideShow ppt = new SlideShow(is);
is.close();
HeadersFooters slideHdd = ppt.getSlideHeadersFooters(); HeadersFooters slideHdd = ppt.getSlideHeadersFooters();
assertFalse(slideHdd.isFooterVisible()); assertFalse(slideHdd.isFooterVisible());
@ -119,10 +114,7 @@ public final class TestHeadersFooters extends TestCase
*/ */
public void testRead2007() throws Exception public void testRead2007() throws Exception
{ {
File file = new File(cwd, "headers_footers_2007.ppt"); SlideShow ppt = new SlideShow(_slTests.openResourceAsStream("headers_footers_2007.ppt"));
FileInputStream is = new FileInputStream(file);
SlideShow ppt = new SlideShow(is);
is.close();
HeadersFooters slideHdd = ppt.getSlideHeadersFooters(); HeadersFooters slideHdd = ppt.getSlideHeadersFooters();
assertTrue(slideHdd.isFooterVisible()); assertTrue(slideHdd.isFooterVisible());

View File

@ -19,10 +19,8 @@ package org.apache.poi.hslf.model;
import junit.framework.TestCase; import junit.framework.TestCase;
import java.io.FileInputStream;
import java.io.File;
import org.apache.poi.hslf.usermodel.SlideShow; import org.apache.poi.hslf.usermodel.SlideShow;
import org.apache.poi.POIDataSamples;
/** /**
* Test Hyperlink. * Test Hyperlink.
@ -30,12 +28,10 @@ import org.apache.poi.hslf.usermodel.SlideShow;
* @author Yegor Kozlov * @author Yegor Kozlov
*/ */
public final class TestHyperlink extends TestCase { 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 { public void testTextRunHyperlinks() throws Exception {
FileInputStream is = new FileInputStream(new File(cwd, "WithLinks.ppt")); SlideShow ppt = new SlideShow(_slTests.openResourceAsStream("WithLinks.ppt"));
SlideShow ppt = new SlideShow(is);
is.close();
TextRun[] run; TextRun[] run;
Slide slide; Slide slide;

View File

@ -20,11 +20,11 @@ package org.apache.poi.hslf.model;
import java.awt.geom.Rectangle2D; import java.awt.geom.Rectangle2D;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.File;
import junit.framework.TestCase; import junit.framework.TestCase;
import org.apache.poi.hslf.usermodel.SlideShow; import org.apache.poi.hslf.usermodel.SlideShow;
import org.apache.poi.POIDataSamples;
/** /**
* Test <code>MovieShape</code> object. * Test <code>MovieShape</code> object.
@ -33,16 +33,16 @@ import org.apache.poi.hslf.usermodel.SlideShow;
*/ */
public final class TestMovieShape extends TestCase { 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 { public void testCreate() throws Exception {
SlideShow ppt = new SlideShow(); SlideShow ppt = new SlideShow();
Slide slide = ppt.createSlide(); Slide slide = ppt.createSlide();
String path = cwd + "/test-movie.mpg"; String path = "/test-movie.mpg";
int movieIdx = ppt.addMovie(path, MovieShape.MOVIE_MPEG); 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); MovieShape shape = new MovieShape(movieIdx, thumbnailIdx);
shape.setAnchor(new Rectangle2D.Float(300,225,120,90)); shape.setAnchor(new Rectangle2D.Float(300,225,120,90));

View File

@ -17,9 +17,6 @@
package org.apache.poi.hslf.model; package org.apache.poi.hslf.model;
import java.io.File;
import java.io.FileInputStream;
import junit.framework.TestCase; import junit.framework.TestCase;
import org.apache.poi.hslf.HSLFSlideShow; 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.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hwpf.HWPFDocument; import org.apache.poi.hwpf.HWPFDocument;
import org.apache.poi.POIDataSamples;
public final class TestOleEmbedding extends TestCase { public final class TestOleEmbedding extends TestCase {
private static POIDataSamples _slTests = POIDataSamples.getSlideShowInstance();
/** /**
* Tests support for OLE objects. * Tests support for OLE objects.
* *
* @throws Exception if an error occurs. * @throws Exception if an error occurs.
*/ */
public void testOleEmbedding2003() throws Exception { public void testOleEmbedding2003() throws Exception {
String dirname = System.getProperty("HSLF.testdata.path"); HSLFSlideShow slideShow = new HSLFSlideShow(_slTests.openResourceAsStream("ole2-embedding-2003.ppt"));
File file = new File(dirname, "ole2-embedding-2003.ppt");
HSLFSlideShow slideShow = new HSLFSlideShow(new FileInputStream(file));
// Placeholder EMFs for clients that don't support the OLE components. // Placeholder EMFs for clients that don't support the OLE components.
PictureData[] pictures = slideShow.getPictures(); PictureData[] pictures = slideShow.getPictures();
assertEquals("Should be two pictures", 2, pictures.length); assertEquals("Should be two pictures", 2, pictures.length);
@ -54,11 +51,7 @@ public final class TestOleEmbedding extends TestCase {
} }
public void testOLEShape() throws Exception { public void testOLEShape() throws Exception {
String dirname = System.getProperty("HSLF.testdata.path"); SlideShow ppt = new SlideShow(_slTests.openResourceAsStream("ole2-embedding-2003.ppt"));
File file = new File(dirname, "ole2-embedding-2003.ppt");
FileInputStream is = new FileInputStream(file);
SlideShow ppt = new SlideShow(is);
is.close();
Slide slide = ppt.getSlides()[0]; Slide slide = ppt.getSlides()[0];
Shape[] sh = slide.getShapes(); Shape[] sh = slide.getShapes();

View File

@ -20,6 +20,7 @@ package org.apache.poi.hslf.model;
import junit.framework.TestCase; import junit.framework.TestCase;
import org.apache.poi.hslf.usermodel.SlideShow; import org.apache.poi.hslf.usermodel.SlideShow;
import org.apache.poi.hslf.HSLFSlideShow; import org.apache.poi.hslf.HSLFSlideShow;
import org.apache.poi.POIDataSamples;
import java.awt.*; import java.awt.*;
import java.awt.Rectangle; import java.awt.Rectangle;
@ -32,12 +33,11 @@ import java.io.ByteArrayInputStream;
* @author Yegor Kozlov * @author Yegor Kozlov
*/ */
public final class TestPPGraphics2D extends TestCase { public final class TestPPGraphics2D extends TestCase {
private static POIDataSamples _slTests = POIDataSamples.getSlideShowInstance();
private SlideShow ppt; private SlideShow ppt;
protected void setUp() throws Exception { protected void setUp() throws Exception {
String dirname = System.getProperty("HSLF.testdata.path"); ppt = new SlideShow(_slTests.openResourceAsStream("empty.ppt"));
String filename = dirname + "/empty.ppt";
ppt = new SlideShow(new HSLFSlideShow(filename));
} }
public void testGraphics() throws Exception { public void testGraphics() throws Exception {

View File

@ -20,13 +20,13 @@ package org.apache.poi.hslf.model;
import java.awt.Graphics2D; import java.awt.Graphics2D;
import java.awt.Rectangle; import java.awt.Rectangle;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.io.File;
import junit.framework.TestCase; import junit.framework.TestCase;
import org.apache.poi.ddf.EscherBSERecord; import org.apache.poi.ddf.EscherBSERecord;
import org.apache.poi.hslf.usermodel.PictureData; import org.apache.poi.hslf.usermodel.PictureData;
import org.apache.poi.hslf.usermodel.SlideShow; import org.apache.poi.hslf.usermodel.SlideShow;
import org.apache.poi.POIDataSamples;
/** /**
* Test Picture shape. * Test Picture shape.
@ -34,6 +34,7 @@ import org.apache.poi.hslf.usermodel.SlideShow;
* @author Yegor Kozlov * @author Yegor Kozlov
*/ */
public final class TestPicture extends TestCase { 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. * 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 { public void testMultiplePictures() throws Exception {
String cwd = System.getProperty("HSLF.testdata.path");
SlideShow ppt = new SlideShow(); SlideShow ppt = new SlideShow();
Slide s = ppt.createSlide(); Slide s = ppt.createSlide();
Slide s2 = ppt.createSlide(); Slide s2 = ppt.createSlide();
Slide s3 = 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 pict = new Picture(idx);
Picture pict2 = new Picture(idx); Picture pict2 = new Picture(idx);
Picture pict3 = new Picture(idx); Picture pict3 = new Picture(idx);

View File

@ -36,10 +36,6 @@ public final class TestSetBoldItalic extends TestCase {
* and set some of the style attributes * and set some of the style attributes
*/ */
public void testTextBoxWrite() throws Exception { 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(); SlideShow ppt = new SlideShow();
Slide sl = ppt.createSlide(); Slide sl = ppt.createSlide();
RichTextRun rt; RichTextRun rt;

View File

@ -22,12 +22,12 @@ import org.apache.poi.hslf.usermodel.SlideShow;
import org.apache.poi.hslf.usermodel.RichTextRun; import org.apache.poi.hslf.usermodel.RichTextRun;
import org.apache.poi.hslf.HSLFSlideShow; import org.apache.poi.hslf.HSLFSlideShow;
import org.apache.poi.ddf.*; import org.apache.poi.ddf.*;
import org.apache.poi.POIDataSamples;
import java.awt.*; import java.awt.*;
import java.awt.Rectangle; import java.awt.Rectangle;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
@ -37,16 +37,15 @@ import java.util.ArrayList;
* @author Yegor Kozlov * @author Yegor Kozlov
*/ */
public final class TestShapes extends TestCase { public final class TestShapes extends TestCase {
private static POIDataSamples _slTests = POIDataSamples.getSlideShowInstance();
private SlideShow ppt; private SlideShow ppt;
private SlideShow pptB; private SlideShow pptB;
protected void setUp() throws Exception { protected void setUp() throws Exception {
String dirname = System.getProperty("HSLF.testdata.path"); ppt = new SlideShow(_slTests.openResourceAsStream("empty.ppt"));
String filename = dirname + "/empty.ppt";
ppt = new SlideShow(new HSLFSlideShow(filename));
String filenameB = dirname + "/empty_textbox.ppt"; pptB = new SlideShow(_slTests.openResourceAsStream("empty_textbox.ppt"));
pptB = new SlideShow(new HSLFSlideShow(filenameB));
} }
public void testGraphics() throws Exception { public void testGraphics() throws Exception {
@ -94,9 +93,7 @@ public final class TestShapes extends TestCase {
* @throws Exception * @throws Exception
*/ */
public void testTextBoxRead() throws Exception { public void testTextBoxRead() throws Exception {
String dirname = System.getProperty("HSLF.testdata.path"); ppt = new SlideShow(_slTests.openResourceAsStream("with_textbox.ppt"));
String filename = dirname + "/with_textbox.ppt";
ppt = new SlideShow(new HSLFSlideShow(filename));
Slide sl = ppt.getSlides()[0]; Slide sl = ppt.getSlides()[0];
Shape[] sh = sl.getShapes(); Shape[] sh = sl.getShapes();
for (int i = 0; i < sh.length; i++) { 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(). * it must be the same as returned by Slide.getTextRuns().
*/ */
public void testTextBoxSet() throws Exception { public void testTextBoxSet() throws Exception {
textBoxSet("/with_textbox.ppt"); textBoxSet("with_textbox.ppt");
textBoxSet("/basic_test_ppt_file.ppt"); textBoxSet("basic_test_ppt_file.ppt");
textBoxSet("/next_test_ppt_file.ppt"); textBoxSet("next_test_ppt_file.ppt");
textBoxSet("/Single_Coloured_Page.ppt"); textBoxSet("Single_Coloured_Page.ppt");
textBoxSet("/Single_Coloured_Page_With_Fonts_and_Alignments.ppt"); textBoxSet("Single_Coloured_Page_With_Fonts_and_Alignments.ppt");
textBoxSet("/incorrect_slide_order.ppt"); textBoxSet("incorrect_slide_order.ppt");
} }
private void textBoxSet(String filename) throws Exception { private void textBoxSet(String filename) throws Exception {
String dirname = System.getProperty("HSLF.testdata.path"); SlideShow ppt = new SlideShow(_slTests.openResourceAsStream(filename));
SlideShow ppt = new SlideShow(new HSLFSlideShow(dirname + filename));
Slide[] sl = ppt.getSlides(); Slide[] sl = ppt.getSlides();
for (int k = 0; k < sl.length; k++) { for (int k = 0; k < sl.length; k++) {
ArrayList lst1 = new ArrayList(); ArrayList lst1 = new ArrayList();
@ -234,7 +230,6 @@ public final class TestShapes extends TestCase {
* Test adding shapes to <code>ShapeGroup</code> * Test adding shapes to <code>ShapeGroup</code>
*/ */
public void testShapeGroup() throws Exception { public void testShapeGroup() throws Exception {
String cwd = System.getProperty("HSLF.testdata.path");
SlideShow ppt = new SlideShow(); SlideShow ppt = new SlideShow();
Slide slide = ppt.createSlide(); 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())); group.setAnchor(new Rectangle(0, 0, (int)pgsize.getWidth(), (int)pgsize.getHeight()));
slide.addShape(group); slide.addShape(group);
File img = new File(cwd, "clock.jpg"); int idx = ppt.addPicture(_slTests.readFile("clock.jpg"), Picture.JPEG);
int idx = ppt.addPicture(img, Picture.JPEG);
Picture pict = new Picture(idx, group); Picture pict = new Picture(idx, group);
pict.setAnchor(new Rectangle(0, 0, 200, 200)); pict.setAnchor(new Rectangle(0, 0, 200, 200));
group.addShape(pict); group.addShape(pict);
@ -287,8 +281,8 @@ public final class TestShapes extends TestCase {
* Test functionality of Sheet.removeShape(Shape shape) * Test functionality of Sheet.removeShape(Shape shape)
*/ */
public void testRemoveShapes() throws IOException { public void testRemoveShapes() throws IOException {
String file = System.getProperty("HSLF.testdata.path")+ "/with_textbox.ppt"; String file = "with_textbox.ppt";
SlideShow ppt = new SlideShow(new HSLFSlideShow(file)); SlideShow ppt = new SlideShow(_slTests.openResourceAsStream(file));
Slide sl = ppt.getSlides()[0]; Slide sl = ppt.getSlides()[0];
Shape[] sh = sl.getShapes(); Shape[] sh = sl.getShapes();
assertEquals("expected four shaped in " + file, 4, sh.length); assertEquals("expected four shaped in " + file, 4, sh.length);

View File

@ -20,14 +20,11 @@ package org.apache.poi.hslf.model;
import junit.framework.AssertionFailedError; import junit.framework.AssertionFailedError;
import junit.framework.TestCase; 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.exceptions.EncryptedPowerPointFileException;
import org.apache.poi.hslf.record.ColorSchemeAtom; import org.apache.poi.hslf.record.ColorSchemeAtom;
import org.apache.poi.hslf.record.PPDrawing; import org.apache.poi.hslf.record.PPDrawing;
import org.apache.poi.hslf.usermodel.SlideShow; import org.apache.poi.hslf.usermodel.SlideShow;
import org.apache.poi.POIDataSamples;
/** /**
* Test common functionality of the <code>Sheet</code> object. * Test common functionality of the <code>Sheet</code> object.
@ -36,23 +33,16 @@ import org.apache.poi.hslf.usermodel.SlideShow;
* @author Yegor Kozlov * @author Yegor Kozlov
*/ */
public final class TestSheet extends TestCase { 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 * For each ppt in the test directory check that all sheets are properly initialized
*/ */
public void testSheet() throws Exception { public void testSheet() throws Exception {
File home = new File(System.getProperty("HSLF.testdata.path")); String[] tests = {"SampleShow.ppt", "backgrounds.ppt", "text_shapes.ppt", "pictures.ppt"};
File[] files = home.listFiles(); for (String file : tests) {
for (int i = 0; i < files.length; i++) {
if(!files[i].getName().endsWith(".ppt")) continue;
if(files[i].getName().endsWith("PPT95.ppt")) continue;
try { try {
FileInputStream is = new FileInputStream(files[i]); SlideShow ppt = new SlideShow(_slTests.openResourceAsStream(file));
HSLFSlideShow hslf = new HSLFSlideShow(is);
is.close();
SlideShow ppt = new SlideShow(hslf);
doSlideShow(ppt); doSlideShow(ppt);
} catch (EncryptedPowerPointFileException e){ } catch (EncryptedPowerPointFileException e){
; //skip encrypted ppt ; //skip encrypted ppt

View File

@ -23,6 +23,7 @@ import junit.framework.TestCase;
import org.apache.poi.hslf.HSLFSlideShow; import org.apache.poi.hslf.HSLFSlideShow;
import org.apache.poi.hslf.record.SlideAtom; import org.apache.poi.hslf.record.SlideAtom;
import org.apache.poi.hslf.usermodel.SlideShow; 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 * 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; private SlideShow ss;
public TestSlideChangeNotes() throws Exception { public TestSlideChangeNotes() throws Exception {
String dirname = System.getProperty("HSLF.testdata.path"); POIDataSamples _slTests = POIDataSamples.getSlideShowInstance();
String filename = dirname + "/basic_test_ppt_file.ppt"; HSLFSlideShow hss = new HSLFSlideShow(_slTests.openResourceAsStream("basic_test_ppt_file.ppt"));
HSLFSlideShow hss = new HSLFSlideShow(filename);
ss = new SlideShow(hss); ss = new SlideShow(hss);
} }

View File

@ -28,6 +28,7 @@ import org.apache.poi.hslf.record.Environment;
import org.apache.poi.hslf.record.TextHeaderAtom; import org.apache.poi.hslf.record.TextHeaderAtom;
import org.apache.poi.hslf.usermodel.RichTextRun; import org.apache.poi.hslf.usermodel.RichTextRun;
import org.apache.poi.hslf.usermodel.SlideShow; import org.apache.poi.hslf.usermodel.SlideShow;
import org.apache.poi.POIDataSamples;
/** /**
* Tests for SlideMaster * Tests for SlideMaster
@ -35,18 +36,14 @@ import org.apache.poi.hslf.usermodel.SlideShow;
* @author Yegor Kozlov * @author Yegor Kozlov
*/ */
public final class TestSlideMaster extends TestCase{ public final class TestSlideMaster extends TestCase{
String home; private static POIDataSamples _slTests = POIDataSamples.getSlideShowInstance();
public void setUp() {
home = System.getProperty("HSLF.testdata.path");
}
/** /**
* The reference ppt has two masters. * The reference ppt has two masters.
* Check we can read their attributes. * Check we can read their attributes.
*/ */
public void testSlideMaster() throws Exception { 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(); 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 * Test we can read default text attributes for a title master sheet
*/ */
public void testTitleMasterTextAttributes() throws Exception { 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(); TitleMaster[] master = ppt.getTitleMasters();
assertEquals(1, master.length); 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. * Slide 3 has title layout and follows the TitleMaster. Verify that.
*/ */
public void testTitleMaster() throws Exception { 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]; Slide slide = ppt.getSlides()[2];
MasterSheet masterSheet = slide.getMasterSheet(); MasterSheet masterSheet = slide.getMasterSheet();
assertTrue(masterSheet instanceof TitleMaster); 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 * If a style attribute is not set ensure it is read from the master
*/ */
public void testMasterAttributes() throws Exception { 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(); Slide[] slide = ppt.getSlides();
assertEquals(3, slide.length); assertEquals(3, slide.length);
TextRun[] trun; TextRun[] trun;
@ -185,7 +182,7 @@ public final class TestSlideMaster extends TestCase{
* Check we can dynamically assign a slide master to a slide. * Check we can dynamically assign a slide master to a slide.
*/ */
public void testChangeSlideMaster() throws Exception { 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(); SlideMaster[] master = ppt.getSlidesMasters();
Slide[] slide = ppt.getSlides(); Slide[] slide = ppt.getSlides();
int sheetNo; int sheetNo;
@ -219,7 +216,7 @@ public final class TestSlideMaster extends TestCase{
* (typical for the "bullted body" placeholder) * (typical for the "bullted body" placeholder)
*/ */
public void testIndentation() throws Exception { 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]; Slide slide = ppt.getSlides()[0];
TextRun[] trun; TextRun[] trun;

View File

@ -20,6 +20,7 @@ package org.apache.poi.hslf.model;
import junit.framework.TestCase; import junit.framework.TestCase;
import org.apache.poi.hslf.HSLFSlideShow; import org.apache.poi.hslf.HSLFSlideShow;
import org.apache.poi.hslf.usermodel.SlideShow; import org.apache.poi.hslf.usermodel.SlideShow;
import org.apache.poi.POIDataSamples;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
@ -137,8 +138,8 @@ public final class TestSlides extends TestCase {
* Add slides to ppt which already has two slides * Add slides to ppt which already has two slides
*/ */
public void testAddSlides2to3() throws Exception { public void testAddSlides2to3() throws Exception {
String dirname = System.getProperty("HSLF.testdata.path"); POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
SlideShow ppt = new SlideShow(new HSLFSlideShow(dirname + "/basic_test_ppt_file.ppt")); SlideShow ppt = new SlideShow(slTests.openResourceAsStream("basic_test_ppt_file.ppt"));
assertTrue(ppt.getSlides().length == 2); assertTrue(ppt.getSlides().length == 2);

View File

@ -22,13 +22,13 @@ import java.io.IOException;
import junit.framework.TestCase; import junit.framework.TestCase;
import org.apache.poi.hslf.HSLFSlideShow;
import org.apache.poi.hslf.model.textproperties.TextPropCollection; import org.apache.poi.hslf.model.textproperties.TextPropCollection;
import org.apache.poi.hslf.record.TextBytesAtom; import org.apache.poi.hslf.record.TextBytesAtom;
import org.apache.poi.hslf.record.TextCharsAtom; import org.apache.poi.hslf.record.TextCharsAtom;
import org.apache.poi.hslf.record.TextHeaderAtom; import org.apache.poi.hslf.record.TextHeaderAtom;
import org.apache.poi.hslf.usermodel.RichTextRun; import org.apache.poi.hslf.usermodel.RichTextRun;
import org.apache.poi.hslf.usermodel.SlideShow; import org.apache.poi.hslf.usermodel.SlideShow;
import org.apache.poi.POIDataSamples;
/** /**
* Tests for TextRuns * Tests for TextRuns
@ -36,32 +36,19 @@ import org.apache.poi.hslf.usermodel.SlideShow;
* @author Nick Burch (nick at torchbox dot com) * @author Nick Burch (nick at torchbox dot com)
*/ */
public final class TestTextRun extends TestCase { public final class TestTextRun extends TestCase {
private static POIDataSamples _slTests = POIDataSamples.getSlideShowInstance();
// SlideShow primed on the test data // SlideShow primed on the test data
private SlideShow ss; private SlideShow ss;
private SlideShow ssRich; private SlideShow ssRich;
// TODO - use this or similar through rest of hslf tests protected void setUp() throws IOException {
private static SlideShow openSampleSlideShow(String name) {
String dirname = System.getProperty("HSLF.testdata.path");
// Basic (non rich) test file // Basic (non rich) test file
String filename = dirname + "/" + name; ss = new SlideShow(_slTests.openResourceAsStream("basic_test_ppt_file.ppt"));
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");
// Rich test file // 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. * of the wrong list of potential paragraph properties defined in StyleTextPropAtom.
* *
*/ */
public void testBug41015() { public void testBug41015() throws IOException {
RichTextRun[] rt; RichTextRun[] rt;
SlideShow ppt = openSampleSlideShow("bug-41015.ppt"); SlideShow ppt = new SlideShow(_slTests.openResourceAsStream("bug-41015.ppt"));
Slide sl = ppt.getSlides()[0]; Slide sl = ppt.getSlides()[0];
TextRun[] txt = sl.getTextRuns(); TextRun[] txt = sl.getTextRuns();
assertEquals(2, txt.length); assertEquals(2, txt.length);

View File

@ -25,6 +25,7 @@ import org.apache.poi.hslf.HSLFSlideShow;
import org.apache.poi.hslf.usermodel.RichTextRun; import org.apache.poi.hslf.usermodel.RichTextRun;
import org.apache.poi.hslf.usermodel.SlideShow; import org.apache.poi.hslf.usermodel.SlideShow;
import org.apache.poi.poifs.filesystem.*; import org.apache.poi.poifs.filesystem.*;
import org.apache.poi.POIDataSamples;
/** /**
* Tests that if we load something up, get a TextRun, set the text * 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 * Load up a test PPT file with rich data
*/ */
public void setUp() throws Exception { public void setUp() throws Exception {
String dirname = System.getProperty("HSLF.testdata.path"); POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
String filename = dirname + "/Single_Coloured_Page_With_Fonts_and_Alignments.ppt"; String filename = "Single_Coloured_Page_With_Fonts_and_Alignments.ppt";
FileInputStream fis = new FileInputStream(filename); pfs = new POIFSFileSystem(slTests.openResourceAsStream(filename));
pfs = new POIFSFileSystem(fis);
hss = new HSLFSlideShow(pfs); hss = new HSLFSlideShow(pfs);
ss = new SlideShow(hss); ss = new SlideShow(hss);
} }

View File

@ -25,6 +25,7 @@ import java.util.HashMap;
import org.apache.poi.hslf.usermodel.SlideShow; import org.apache.poi.hslf.usermodel.SlideShow;
import org.apache.poi.hslf.record.TextHeaderAtom; import org.apache.poi.hslf.record.TextHeaderAtom;
import org.apache.poi.POIDataSamples;
/** /**
* Verify behavior of <code>TextShape</code> and its sub-classes * Verify behavior of <code>TextShape</code> and its sub-classes
@ -32,7 +33,7 @@ import org.apache.poi.hslf.record.TextHeaderAtom;
* @author Yegor Kozlov * @author Yegor Kozlov
*/ */
public final class TestTextShape extends TestCase { public final class TestTextShape extends TestCase {
protected String cwd = System.getProperty("HSLF.testdata.path"); private static POIDataSamples _slTests = POIDataSamples.getSlideShowInstance();
public void testCreateAutoShape(){ public void testCreateAutoShape(){
TextShape shape = new AutoShape(ShapeTypes.Trapezoid); TextShape shape = new AutoShape(ShapeTypes.Trapezoid);
@ -70,9 +71,7 @@ public final class TestTextShape extends TestCase {
* - text in auto-shapes * - text in auto-shapes
*/ */
public void testRead() throws IOException { public void testRead() throws IOException {
FileInputStream is = new FileInputStream(new File(cwd, "text_shapes.ppt")); SlideShow ppt = new SlideShow(_slTests.openResourceAsStream("text_shapes.ppt"));
SlideShow ppt = new SlideShow(is);
is.close();
ArrayList lst1 = new ArrayList(); ArrayList lst1 = new ArrayList();
Slide slide = ppt.getSlides()[0]; Slide slide = ppt.getSlides()[0];
@ -157,9 +156,7 @@ public final class TestTextShape extends TestCase {
} }
public void testMargins() throws IOException { public void testMargins() throws IOException {
FileInputStream is = new FileInputStream(new File(cwd, "text-margins.ppt")); SlideShow ppt = new SlideShow(_slTests.openResourceAsStream("text-margins.ppt"));
SlideShow ppt = new SlideShow(is);
is.close();
Slide slide = ppt.getSlides()[0]; Slide slide = ppt.getSlides()[0];

View File

@ -20,12 +20,12 @@ package org.apache.poi.hslf.record;
import junit.framework.TestCase; import junit.framework.TestCase;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.InputStream; import java.io.InputStream;
import org.apache.poi.hslf.exceptions.EncryptedPowerPointFileException; import org.apache.poi.hslf.exceptions.EncryptedPowerPointFileException;
import org.apache.poi.poifs.filesystem.DocumentEntry; import org.apache.poi.poifs.filesystem.DocumentEntry;
import org.apache.poi.poifs.filesystem.POIFSFileSystem; import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.POIDataSamples;
/** /**
* Tests that CurrentUserAtom works properly. * Tests that CurrentUserAtom works properly.
@ -33,6 +33,7 @@ import org.apache.poi.poifs.filesystem.POIFSFileSystem;
* @author Nick Burch (nick at torchbox dot com) * @author Nick Burch (nick at torchbox dot com)
*/ */
public final class TestCurrentUserAtom extends TestCase { public final class TestCurrentUserAtom extends TestCase {
private static POIDataSamples _slTests = POIDataSamples.getSlideShowInstance();
/** Not encrypted */ /** Not encrypted */
private String normalFile; private String normalFile;
/** Encrypted */ /** Encrypted */
@ -41,14 +42,13 @@ public final class TestCurrentUserAtom extends TestCase {
protected void setUp() throws Exception { protected void setUp() throws Exception {
super.setUp(); super.setUp();
String dirname = System.getProperty("HSLF.testdata.path"); normalFile = "basic_test_ppt_file.ppt";
normalFile = dirname + "/basic_test_ppt_file.ppt"; encFile = "Password_Protected-hello.ppt";
encFile = dirname + "/Password_Protected-hello.ppt";
} }
public void testReadNormal() throws Exception { public void testReadNormal() throws Exception {
POIFSFileSystem fs = new POIFSFileSystem( POIFSFileSystem fs = new POIFSFileSystem(
new FileInputStream(normalFile) _slTests.openResourceAsStream(normalFile)
); );
CurrentUserAtom cu = new CurrentUserAtom(fs); CurrentUserAtom cu = new CurrentUserAtom(fs);
@ -68,7 +68,7 @@ public final class TestCurrentUserAtom extends TestCase {
public void testReadEnc() throws Exception { public void testReadEnc() throws Exception {
POIFSFileSystem fs = new POIFSFileSystem( POIFSFileSystem fs = new POIFSFileSystem(
new FileInputStream(encFile) _slTests.openResourceAsStream(encFile)
); );
try { try {
@ -82,7 +82,7 @@ public final class TestCurrentUserAtom extends TestCase {
public void testWriteNormal() throws Exception { public void testWriteNormal() throws Exception {
// Get raw contents from a known file // Get raw contents from a known file
POIFSFileSystem fs = new POIFSFileSystem( POIFSFileSystem fs = new POIFSFileSystem(
new FileInputStream(normalFile) _slTests.openResourceAsStream(normalFile)
); );
DocumentEntry docProps = (DocumentEntry)fs.getRoot().getEntry("Current User"); DocumentEntry docProps = (DocumentEntry)fs.getRoot().getEntry("Current User");
byte[] contents = new byte[docProps.getSize()]; byte[] contents = new byte[docProps.getSize()];

View File

@ -18,10 +18,10 @@
package org.apache.poi.hslf.record; package org.apache.poi.hslf.record;
import junit.framework.TestCase; import junit.framework.TestCase;
import java.io.*;
import org.apache.poi.hslf.HSLFSlideShow; import org.apache.poi.hslf.HSLFSlideShow;
import org.apache.poi.poifs.filesystem.*; import org.apache.poi.poifs.filesystem.*;
import org.apache.poi.POIDataSamples;
/** /**
* Tests that Document works properly (Also tests Environment while we're at it) * 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; private POIFSFileSystem pfs;
public TestDocument() throws Exception { public TestDocument() throws Exception {
String dirname = System.getProperty("HSLF.testdata.path"); POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
String filename = dirname + "/basic_test_ppt_file.ppt"; pfs = new POIFSFileSystem(slTests.openResourceAsStream("basic_test_ppt_file.ppt"));
FileInputStream fis = new FileInputStream(filename);
pfs = new POIFSFileSystem(fis);
ss = new HSLFSlideShow(pfs); ss = new HSLFSlideShow(pfs);
} }

View File

@ -19,7 +19,6 @@ package org.apache.poi.hslf.record;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -28,6 +27,7 @@ import junit.framework.TestCase;
import org.apache.poi.hslf.HSLFSlideShow; import org.apache.poi.hslf.HSLFSlideShow;
import org.apache.poi.hslf.usermodel.SlideShow; import org.apache.poi.hslf.usermodel.SlideShow;
import org.apache.poi.POIDataSamples;
/** /**
* Tests that ExHyperlink works properly. * Tests that ExHyperlink works properly.
@ -98,8 +98,8 @@ public final class TestExHyperlink extends TestCase {
} }
public void testRealFile() throws Exception { public void testRealFile() throws Exception {
String dirname = System.getProperty("HSLF.testdata.path"); POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
HSLFSlideShow hss = new HSLFSlideShow(dirname + File.separator + "WithLinks.ppt"); HSLFSlideShow hss = new HSLFSlideShow(slTests.openResourceAsStream("WithLinks.ppt"));
SlideShow ss = new SlideShow(hss); SlideShow ss = new SlideShow(hss);
// Get the document // Get the document

View File

@ -18,12 +18,11 @@
package org.apache.poi.hslf.record; package org.apache.poi.hslf.record;
import java.io.File;
import junit.framework.TestCase; import junit.framework.TestCase;
import org.apache.poi.hslf.HSLFSlideShow; import org.apache.poi.hslf.HSLFSlideShow;
import org.apache.poi.hslf.usermodel.SlideShow; import org.apache.poi.hslf.usermodel.SlideShow;
import org.apache.poi.POIDataSamples;
/** /**
* Tests that ExObjList works properly. * Tests that ExObjList works properly.
@ -32,8 +31,8 @@ import org.apache.poi.hslf.usermodel.SlideShow;
*/ */
public class TestExObjList extends TestCase { public class TestExObjList extends TestCase {
public void testRealFile() throws Exception { public void testRealFile() throws Exception {
String dirname = System.getProperty("HSLF.testdata.path"); POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
HSLFSlideShow hss = new HSLFSlideShow(dirname + File.separator + "WithLinks.ppt"); HSLFSlideShow hss = new HSLFSlideShow(slTests.openResourceAsStream("WithLinks.ppt"));
SlideShow ss = new SlideShow(hss); SlideShow ss = new SlideShow(hss);
// Get the document // Get the document

View File

@ -21,6 +21,7 @@ package org.apache.poi.hslf.record;
import junit.framework.TestCase; import junit.framework.TestCase;
import org.apache.poi.hslf.HSLFSlideShow; import org.apache.poi.hslf.HSLFSlideShow;
import org.apache.poi.POIDataSamples;
/** /**
* Tests that the helper methods on RecordContainer work properly * Tests that the helper methods on RecordContainer work properly
@ -147,9 +148,8 @@ public final class TestRecordContainer extends TestCase {
super.setUp(); super.setUp();
// Find a real RecordContainer record // Find a real RecordContainer record
String dirname = System.getProperty("HSLF.testdata.path"); POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
String filename = dirname + "/basic_test_ppt_file.ppt"; HSLFSlideShow hss = new HSLFSlideShow(slTests.openResourceAsStream("basic_test_ppt_file.ppt"));
HSLFSlideShow hss = new HSLFSlideShow(filename);
Record[] r = hss.getRecords(); Record[] r = hss.getRecords();
for(int i=0; i<r.length; i++) { for(int i=0; i<r.length; i++) {

View File

@ -17,14 +17,13 @@
package org.apache.poi.hslf.record; package org.apache.poi.hslf.record;
import java.io.File;
import java.io.FileInputStream;
import java.util.Arrays; import java.util.Arrays;
import junit.framework.AssertionFailedError; import junit.framework.AssertionFailedError;
import junit.framework.TestCase; import junit.framework.TestCase;
import org.apache.poi.hslf.usermodel.SlideShow; import org.apache.poi.hslf.usermodel.SlideShow;
import org.apache.poi.POIDataSamples;
/** /**
* Tests Sound-related records: SoundCollection(2020), Sound(2022) and * Tests Sound-related records: SoundCollection(2020), Sound(2022) and
@ -34,10 +33,9 @@ import org.apache.poi.hslf.usermodel.SlideShow;
*/ */
public final class TestSound extends TestCase { public final class TestSound extends TestCase {
public void testRealFile() throws Exception { public void testRealFile() throws Exception {
String cwd = System.getProperty("HSLF.testdata.path"); POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
FileInputStream is = new FileInputStream(new File(cwd, "sound.ppt"));
SlideShow ppt = new SlideShow(is); SlideShow ppt = new SlideShow(slTests.openResourceAsStream("sound.ppt"));
is.close();
// Get the document // Get the document
Document doc = ppt.getDocumentRecord(); Document doc = ppt.getDocumentRecord();
@ -71,13 +69,7 @@ public final class TestSound extends TestCase {
assertEquals(".WAV", sound.getSoundType()); assertEquals(".WAV", sound.getSoundType());
assertNotNull(sound.getSoundData()); assertNotNull(sound.getSoundData());
File f = new File(cwd, "ringin.wav"); byte[] ref_data = slTests.readFile("ringin.wav");
int length = (int) f.length();
byte[] ref_data = new byte[length];
is = new FileInputStream(f);
is.read(ref_data);
is.close();
assertTrue(Arrays.equals(ref_data, sound.getSoundData())); assertTrue(Arrays.equals(ref_data, sound.getSoundData()));
} }
} }

View File

@ -30,6 +30,7 @@ import org.apache.poi.hslf.record.RecordTypes;
import org.apache.poi.hslf.record.UserEditAtom; import org.apache.poi.hslf.record.UserEditAtom;
import org.apache.poi.hslf.record.Document; import org.apache.poi.hslf.record.Document;
import org.apache.poi.hslf.model.*; import org.apache.poi.hslf.model.*;
import org.apache.poi.POIDataSamples;
/** /**
* Tests that SlideShow adds additional sheets properly * Tests that SlideShow adds additional sheets properly
@ -56,14 +57,12 @@ public final class TestAddingSlides extends TestCase {
hss_empty = HSLFSlideShow.create(); hss_empty = HSLFSlideShow.create();
ss_empty = new SlideShow(hss_empty); ss_empty = new SlideShow(hss_empty);
String dirname = System.getProperty("HSLF.testdata.path"); POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
String filename = dirname + "/Single_Coloured_Page.ppt"; hss_one = new HSLFSlideShow(slTests.openResourceAsStream("Single_Coloured_Page.ppt"));
hss_one = new HSLFSlideShow(filename);
ss_one = new SlideShow(hss_one); ss_one = new SlideShow(hss_one);
filename = dirname + "/basic_test_ppt_file.ppt"; hss_two = new HSLFSlideShow(slTests.openResourceAsStream("basic_test_ppt_file.ppt"));
hss_two = new HSLFSlideShow(filename);
ss_two = new SlideShow(hss_two); ss_two = new SlideShow(hss_two);
} }
@ -274,8 +273,8 @@ public final class TestAddingSlides extends TestCase {
public void test47261() throws Exception { public void test47261() throws Exception {
File src = new File(System.getProperty("HSLF.testdata.path"), "47261.ppt"); POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
SlideShow ppt = new SlideShow(new FileInputStream(src)); SlideShow ppt = new SlideShow(slTests.openResourceAsStream("47261.ppt"));
Slide[] slides = ppt.getSlides(); Slide[] slides = ppt.getSlides();
Document doc = ppt.getDocumentRecord(); Document doc = ppt.getDocumentRecord();
assertNotNull(doc.getSlideSlideListWithText()); assertNotNull(doc.getSlideSlideListWithText());

View File

@ -17,8 +17,6 @@
package org.apache.poi.hslf.usermodel; package org.apache.poi.hslf.usermodel;
import java.io.File;
import java.io.FileInputStream;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
@ -44,6 +42,7 @@ import org.apache.poi.hslf.model.TextBox;
import org.apache.poi.hslf.model.TextRun; import org.apache.poi.hslf.model.TextRun;
import org.apache.poi.hslf.model.TextShape; import org.apache.poi.hslf.model.TextShape;
import org.apache.poi.hslf.model.TitleMaster; import org.apache.poi.hslf.model.TitleMaster;
import org.apache.poi.POIDataSamples;
/** /**
* Testcases for bugs entered in bugzilla * Testcases for bugs entered in bugzilla
@ -52,15 +51,13 @@ import org.apache.poi.hslf.model.TitleMaster;
* @author Yegor Kozlov * @author Yegor Kozlov
*/ */
public final class TestBugs extends TestCase { public final class TestBugs extends TestCase {
protected String cwd = System.getProperty("HSLF.testdata.path"); private static POIDataSamples _slTests = POIDataSamples.getSlideShowInstance();
/** /**
* Bug 41384: Array index wrong in record creation * Bug 41384: Array index wrong in record creation
*/ */
public void test41384() throws Exception { public void test41384() throws Exception {
FileInputStream is = new FileInputStream(new File(cwd, "41384.ppt")); HSLFSlideShow hslf = new HSLFSlideShow(_slTests.openResourceAsStream("41384.ppt"));
HSLFSlideShow hslf = new HSLFSlideShow(is);
is.close();
SlideShow ppt = new SlideShow(hslf); SlideShow ppt = new SlideShow(hslf);
assertTrue("No Exceptions while reading file", true); assertTrue("No Exceptions while reading file", true);
@ -78,9 +75,7 @@ public final class TestBugs extends TestCase {
* when the RichTextRun comes from a Notes model object * when the RichTextRun comes from a Notes model object
*/ */
public void test42474_1() throws Exception { public void test42474_1() throws Exception {
FileInputStream is = new FileInputStream(new File(cwd, "42474-1.ppt")); HSLFSlideShow hslf = new HSLFSlideShow(_slTests.openResourceAsStream("42474-1.ppt"));
HSLFSlideShow hslf = new HSLFSlideShow(is);
is.close();
SlideShow ppt = new SlideShow(hslf); SlideShow ppt = new SlideShow(hslf);
assertTrue("No Exceptions while reading file", true); assertTrue("No Exceptions while reading file", true);
@ -108,9 +103,7 @@ public final class TestBugs extends TestCase {
* Second fix from Bug 42474: Incorrect matching of notes to slides * Second fix from Bug 42474: Incorrect matching of notes to slides
*/ */
public void test42474_2() throws Exception { public void test42474_2() throws Exception {
FileInputStream is = new FileInputStream(new File(cwd, "42474-2.ppt")); HSLFSlideShow hslf = new HSLFSlideShow(_slTests.openResourceAsStream("42474-2.ppt"));
HSLFSlideShow hslf = new HSLFSlideShow(is);
is.close();
SlideShow ppt = new SlideShow(hslf); SlideShow ppt = new SlideShow(hslf);
@ -140,9 +133,7 @@ public final class TestBugs extends TestCase {
* Bug 42485: All TextBoxes inside ShapeGroups have null TextRuns * Bug 42485: All TextBoxes inside ShapeGroups have null TextRuns
*/ */
public void test42485 () throws Exception { public void test42485 () throws Exception {
FileInputStream is = new FileInputStream(new File(cwd, "42485.ppt")); HSLFSlideShow hslf = new HSLFSlideShow(_slTests.openResourceAsStream("42485.ppt"));
HSLFSlideShow hslf = new HSLFSlideShow(is);
is.close();
SlideShow ppt = new SlideShow(hslf); SlideShow ppt = new SlideShow(hslf);
Shape[] shape = ppt.getSlides()[0].getShapes(); Shape[] shape = ppt.getSlides()[0].getShapes();
@ -164,9 +155,7 @@ public final class TestBugs extends TestCase {
* Bug 42484: NullPointerException from ShapeGroup.getAnchor() * Bug 42484: NullPointerException from ShapeGroup.getAnchor()
*/ */
public void test42484 () throws Exception { public void test42484 () throws Exception {
FileInputStream is = new FileInputStream(new File(cwd, "42485.ppt")); //test file is the same as for bug 42485 HSLFSlideShow hslf = new HSLFSlideShow(_slTests.openResourceAsStream("42485.ppt"));
HSLFSlideShow hslf = new HSLFSlideShow(is);
is.close();
SlideShow ppt = new SlideShow(hslf); SlideShow ppt = new SlideShow(hslf);
Shape[] shape = ppt.getSlides()[0].getShapes(); Shape[] shape = ppt.getSlides()[0].getShapes();
@ -187,9 +176,7 @@ public final class TestBugs extends TestCase {
* Bug 41381: Exception from Slide.getMasterSheet() on a seemingly valid PPT file * Bug 41381: Exception from Slide.getMasterSheet() on a seemingly valid PPT file
*/ */
public void test41381() throws Exception { public void test41381() throws Exception {
FileInputStream is = new FileInputStream(new File(cwd, "alterman_security.ppt")); HSLFSlideShow hslf = new HSLFSlideShow(_slTests.openResourceAsStream("alterman_security.ppt"));
HSLFSlideShow hslf = new HSLFSlideShow(is);
is.close();
SlideShow ppt = new SlideShow(hslf); SlideShow ppt = new SlideShow(hslf);
assertTrue("No Exceptions while reading file", true); assertTrue("No Exceptions while reading file", true);
@ -208,9 +195,7 @@ public final class TestBugs extends TestCase {
* Bug 42486: Failure parsing a seemingly valid PPT * Bug 42486: Failure parsing a seemingly valid PPT
*/ */
public void test42486 () throws Exception { public void test42486 () throws Exception {
FileInputStream is = new FileInputStream(new File(cwd, "42486.ppt")); HSLFSlideShow hslf = new HSLFSlideShow(_slTests.openResourceAsStream("42486.ppt"));
HSLFSlideShow hslf = new HSLFSlideShow(is);
is.close();
SlideShow ppt = new SlideShow(hslf); SlideShow ppt = new SlideShow(hslf);
Slide[] slide = ppt.getSlides(); Slide[] slide = ppt.getSlides();
@ -225,9 +210,7 @@ public final class TestBugs extends TestCase {
* Bug 42524: NPE in Shape.getShapeType() * Bug 42524: NPE in Shape.getShapeType()
*/ */
public void test42524 () throws Exception { public void test42524 () throws Exception {
FileInputStream is = new FileInputStream(new File(cwd, "42486.ppt")); //test file is the same as for Bug 42486 HSLFSlideShow hslf = new HSLFSlideShow(_slTests.openResourceAsStream("42486.ppt"));
HSLFSlideShow hslf = new HSLFSlideShow(is);
is.close();
SlideShow ppt = new SlideShow(hslf); SlideShow ppt = new SlideShow(hslf);
//walk down the tree and see if there were no errors while reading //walk down the tree and see if there were no errors while reading
@ -254,9 +237,7 @@ public final class TestBugs extends TestCase {
* Bug 42520: NPE in Picture.getPictureData() * Bug 42520: NPE in Picture.getPictureData()
*/ */
public void test42520 () throws Exception { public void test42520 () throws Exception {
FileInputStream is = new FileInputStream(new File(cwd, "42520.ppt")); //test file is the same as for Bug 42486 HSLFSlideShow hslf = new HSLFSlideShow(_slTests.openResourceAsStream("42520.ppt"));
HSLFSlideShow hslf = new HSLFSlideShow(is);
is.close();
SlideShow ppt = new SlideShow(hslf); SlideShow ppt = new SlideShow(hslf);
@ -292,9 +273,7 @@ public final class TestBugs extends TestCase {
* ( also fixed followup: getTextRuns() returns no text ) * ( also fixed followup: getTextRuns() returns no text )
*/ */
public void test38256 () throws Exception { public void test38256 () throws Exception {
FileInputStream is = new FileInputStream(new File(cwd, "38256.ppt")); SlideShow ppt = new SlideShow(_slTests.openResourceAsStream("38256.ppt"));
SlideShow ppt = new SlideShow(is);
is.close();
assertTrue("No Exceptions while reading file", true); assertTrue("No Exceptions while reading file", true);
@ -321,9 +300,7 @@ public final class TestBugs extends TestCase {
* ( also fixed followup: getTextRuns() returns no text ) * ( also fixed followup: getTextRuns() returns no text )
*/ */
public void test43781 () throws Exception { public void test43781 () throws Exception {
FileInputStream is = new FileInputStream(new File(cwd, "43781.ppt")); SlideShow ppt = new SlideShow(_slTests.openResourceAsStream("43781.ppt"));
SlideShow ppt = new SlideShow(is);
is.close();
assertTrue("No Exceptions while reading file", true); assertTrue("No Exceptions while reading file", true);
@ -354,9 +331,7 @@ public final class TestBugs extends TestCase {
* Bug 44296: HSLF Not Extracting Slide Background Image * Bug 44296: HSLF Not Extracting Slide Background Image
*/ */
public void test44296 () throws Exception { public void test44296 () throws Exception {
FileInputStream is = new FileInputStream(new File(cwd, "44296.ppt")); SlideShow ppt = new SlideShow(_slTests.openResourceAsStream("44296.ppt"));
SlideShow ppt = new SlideShow(is);
is.close();
Slide slide = ppt.getSlides()[0]; Slide slide = ppt.getSlides()[0];
@ -373,25 +348,21 @@ public final class TestBugs extends TestCase {
* Bug 44770: java.lang.RuntimeException: Couldn't instantiate the class for type with id 1036 on class class org.apache.poi.hslf.record.PPDrawing * Bug 44770: java.lang.RuntimeException: Couldn't instantiate the class for type with id 1036 on class class org.apache.poi.hslf.record.PPDrawing
*/ */
public void test44770() throws Exception { public void test44770() throws Exception {
FileInputStream is = new FileInputStream(new File(cwd, "44770.ppt"));
try { try {
new SlideShow(is); new SlideShow(_slTests.openResourceAsStream("44770.ppt"));
} catch (RuntimeException e) { } catch (RuntimeException e) {
if (e.getMessage().equals("Couldn't instantiate the class for type with id 1036 on class class org.apache.poi.hslf.record.PPDrawing")) { if (e.getMessage().equals("Couldn't instantiate the class for type with id 1036 on class class org.apache.poi.hslf.record.PPDrawing")) {
throw new AssertionFailedError("Identified bug 44770"); throw new AssertionFailedError("Identified bug 44770");
} }
throw e; throw e;
} }
is.close();
} }
/** /**
* Bug 41071: Will not extract text from Powerpoint TextBoxes * Bug 41071: Will not extract text from Powerpoint TextBoxes
*/ */
public void test41071() throws Exception { public void test41071() throws Exception {
FileInputStream is = new FileInputStream(new File(cwd, "41071.ppt")); SlideShow ppt = new SlideShow(_slTests.openResourceAsStream("41071.ppt"));
SlideShow ppt = new SlideShow(is);
is.close();
Slide slide = ppt.getSlides()[0]; Slide slide = ppt.getSlides()[0];
Shape[] sh = slide.getShapes(); Shape[] sh = slide.getShapes();
@ -411,13 +382,11 @@ public final class TestBugs extends TestCase {
*/ */
public void test41711() throws Exception { public void test41711() throws Exception {
// New file is fine // New file is fine
FileInputStream is = new FileInputStream(new File(cwd, "SampleShow.ppt")); new SlideShow(_slTests.openResourceAsStream("SampleShow.ppt"));
SlideShow ppt = new SlideShow(is);
// PowerPoint 95 gives an old format exception // PowerPoint 95 gives an old format exception
is = new FileInputStream(new File(cwd, "PPT95.ppt"));
try { try {
new SlideShow(is); new SlideShow(_slTests.openResourceAsStream("PPT95.ppt"));
fail("OldPowerPointFormatException should've been thrown"); fail("OldPowerPointFormatException should've been thrown");
} catch(OldPowerPointFormatException e) { } catch(OldPowerPointFormatException e) {
// Good // Good

View File

@ -21,6 +21,7 @@ package org.apache.poi.hslf.usermodel;
import junit.framework.TestCase; import junit.framework.TestCase;
import org.apache.poi.hslf.*; import org.apache.poi.hslf.*;
import org.apache.poi.hslf.model.*; import org.apache.poi.hslf.model.*;
import org.apache.poi.POIDataSamples;
/** /**
* Tests that SlideShow returns the right number of Sheets and MetaSheets * Tests that SlideShow returns the right number of Sheets and MetaSheets
@ -32,9 +33,8 @@ public final class TestCounts extends TestCase {
private SlideShow ss; private SlideShow ss;
public TestCounts() throws Exception { public TestCounts() throws Exception {
String dirname = System.getProperty("HSLF.testdata.path"); POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
String filename = dirname + "/basic_test_ppt_file.ppt"; HSLFSlideShow hss = new HSLFSlideShow(slTests.openResourceAsStream("basic_test_ppt_file.ppt"));
HSLFSlideShow hss = new HSLFSlideShow(filename);
ss = new SlideShow(hss); ss = new SlideShow(hss);
} }

View File

@ -21,6 +21,7 @@ package org.apache.poi.hslf.usermodel;
import junit.framework.TestCase; import junit.framework.TestCase;
import org.apache.poi.hslf.*; import org.apache.poi.hslf.*;
import org.apache.poi.hslf.record.*; import org.apache.poi.hslf.record.*;
import org.apache.poi.POIDataSamples;
/** /**
* Tests that SlideShow finds the right records as its most recent ones * Tests that SlideShow finds the right records as its most recent ones
@ -34,9 +35,8 @@ public final class TestMostRecentRecords extends TestCase {
private SlideShow ss; private SlideShow ss;
public TestMostRecentRecords() throws Exception { public TestMostRecentRecords() throws Exception {
String dirname = System.getProperty("HSLF.testdata.path"); POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
String filename = dirname + "/basic_test_ppt_file.ppt"; hss = new HSLFSlideShow(slTests.openResourceAsStream("basic_test_ppt_file.ppt"));
hss = new HSLFSlideShow(filename);
ss = new SlideShow(hss); ss = new SlideShow(hss);
} }

View File

@ -21,6 +21,7 @@ package org.apache.poi.hslf.usermodel;
import junit.framework.TestCase; import junit.framework.TestCase;
import org.apache.poi.hslf.*; import org.apache.poi.hslf.*;
import org.apache.poi.hslf.model.*; import org.apache.poi.hslf.model.*;
import org.apache.poi.POIDataSamples;
/** /**
* Tests that SlideShow returns MetaSheets which have the right text in them * Tests that SlideShow returns MetaSheets which have the right text in them
@ -32,9 +33,8 @@ public final class TestNotesText extends TestCase {
private SlideShow ss; private SlideShow ss;
public TestNotesText() throws Exception { public TestNotesText() throws Exception {
String dirname = System.getProperty("HSLF.testdata.path"); POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
String filename = dirname + "/basic_test_ppt_file.ppt"; HSLFSlideShow hss = new HSLFSlideShow(slTests.openResourceAsStream("basic_test_ppt_file.ppt"));
HSLFSlideShow hss = new HSLFSlideShow(filename);
ss = new SlideShow(hss); ss = new SlideShow(hss);
} }

View File

@ -20,6 +20,7 @@ package org.apache.poi.hslf.usermodel;
import org.apache.poi.hslf.*; import org.apache.poi.hslf.*;
import org.apache.poi.hslf.blip.*; import org.apache.poi.hslf.blip.*;
import org.apache.poi.hslf.model.*; import org.apache.poi.hslf.model.*;
import org.apache.poi.POIDataSamples;
import junit.framework.TestCase; import junit.framework.TestCase;
import java.io.*; import java.io.*;
@ -31,12 +32,9 @@ import java.util.Arrays;
* @author Yegor Kozlov * @author Yegor Kozlov
*/ */
public final class TestPictures extends TestCase{ public final class TestPictures extends TestCase{
private static POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
protected File cwd; //protected File cwd;
public void setUp() {
cwd = new File(System.getProperty("HSLF.testdata.path"));
}
/** /**
* Test read/write Macintosh PICT * Test read/write Macintosh PICT
@ -45,8 +43,8 @@ public final class TestPictures extends TestCase{
SlideShow ppt = new SlideShow(); SlideShow ppt = new SlideShow();
Slide slide = ppt.createSlide(); Slide slide = ppt.createSlide();
File img = new File(cwd, "cow.pict"); byte[] src_bytes = slTests.readFile("cow.pict");
int idx = ppt.addPicture(img, Picture.PICT); int idx = ppt.addPicture(src_bytes, Picture.PICT);
Picture pict = new Picture(idx); Picture pict = new Picture(idx);
assertEquals(idx, pict.getPictureIndex()); assertEquals(idx, pict.getPictureIndex());
slide.addShape(pict); slide.addShape(pict);
@ -73,7 +71,6 @@ public final class TestPictures extends TestCase{
assertEquals(Picture.PICT, pictures[0].getType()); assertEquals(Picture.PICT, pictures[0].getType());
assertTrue(pictures[0] instanceof PICT); assertTrue(pictures[0] instanceof PICT);
//compare the content of the initial file with what is stored in the PictureData //compare the content of the initial file with what is stored in the PictureData
byte[] src_bytes = read(img);
byte[] ppt_bytes = pictures[0].getData(); byte[] ppt_bytes = pictures[0].getData();
assertEquals(src_bytes.length, ppt_bytes.length); assertEquals(src_bytes.length, ppt_bytes.length);
//in PICT the first 512 bytes are MAC specific and may not be preserved, ignore them //in PICT the first 512 bytes are MAC specific and may not be preserved, ignore them
@ -91,8 +88,8 @@ public final class TestPictures extends TestCase{
SlideShow ppt = new SlideShow(); SlideShow ppt = new SlideShow();
Slide slide = ppt.createSlide(); Slide slide = ppt.createSlide();
File img = new File(cwd, "santa.wmf"); byte[] src_bytes = slTests.readFile("santa.wmf");
int idx = ppt.addPicture(img, Picture.WMF); int idx = ppt.addPicture(src_bytes, Picture.WMF);
Picture pict = new Picture(idx); Picture pict = new Picture(idx);
assertEquals(idx, pict.getPictureIndex()); assertEquals(idx, pict.getPictureIndex());
slide.addShape(pict); slide.addShape(pict);
@ -119,7 +116,6 @@ public final class TestPictures extends TestCase{
assertEquals(Picture.WMF, pictures[0].getType()); assertEquals(Picture.WMF, pictures[0].getType());
assertTrue(pictures[0] instanceof WMF); assertTrue(pictures[0] instanceof WMF);
//compare the content of the initial file with what is stored in the PictureData //compare the content of the initial file with what is stored in the PictureData
byte[] src_bytes = read(img);
byte[] ppt_bytes = pictures[0].getData(); byte[] ppt_bytes = pictures[0].getData();
assertEquals(src_bytes.length, ppt_bytes.length); assertEquals(src_bytes.length, ppt_bytes.length);
//in WMF the first 22 bytes - is a metafile header //in WMF the first 22 bytes - is a metafile header
@ -137,8 +133,9 @@ public final class TestPictures extends TestCase{
SlideShow ppt = new SlideShow(); SlideShow ppt = new SlideShow();
Slide slide = ppt.createSlide(); Slide slide = ppt.createSlide();
File img = new File(cwd, "wrench.emf"); byte[] src_bytes = slTests.readFile("wrench.emf");
int idx = ppt.addPicture(img, Picture.EMF); int idx = ppt.addPicture(src_bytes, Picture.EMF);
Picture pict = new Picture(idx); Picture pict = new Picture(idx);
assertEquals(idx, pict.getPictureIndex()); assertEquals(idx, pict.getPictureIndex());
slide.addShape(pict); slide.addShape(pict);
@ -165,7 +162,6 @@ public final class TestPictures extends TestCase{
assertEquals(Picture.EMF, pictures[0].getType()); assertEquals(Picture.EMF, pictures[0].getType());
assertTrue(pictures[0] instanceof EMF); assertTrue(pictures[0] instanceof EMF);
//compare the content of the initial file with what is stored in the PictureData //compare the content of the initial file with what is stored in the PictureData
byte[] src_bytes = read(img);
byte[] ppt_bytes = pictures[0].getData(); byte[] ppt_bytes = pictures[0].getData();
assertTrue(Arrays.equals(src_bytes, ppt_bytes)); assertTrue(Arrays.equals(src_bytes, ppt_bytes));
} }
@ -177,8 +173,8 @@ public final class TestPictures extends TestCase{
SlideShow ppt = new SlideShow(); SlideShow ppt = new SlideShow();
Slide slide = ppt.createSlide(); Slide slide = ppt.createSlide();
File img = new File(cwd, "tomcat.png"); byte[] src_bytes = slTests.readFile("tomcat.png");
int idx = ppt.addPicture(img, Picture.PNG); int idx = ppt.addPicture(src_bytes, Picture.PNG);
Picture pict = new Picture(idx); Picture pict = new Picture(idx);
assertEquals(idx, pict.getPictureIndex()); assertEquals(idx, pict.getPictureIndex());
slide.addShape(pict); slide.addShape(pict);
@ -205,7 +201,6 @@ public final class TestPictures extends TestCase{
assertEquals(Picture.PNG, pictures[0].getType()); assertEquals(Picture.PNG, pictures[0].getType());
assertTrue(pictures[0] instanceof PNG); assertTrue(pictures[0] instanceof PNG);
//compare the content of the initial file with what is stored in the PictureData //compare the content of the initial file with what is stored in the PictureData
byte[] src_bytes = read(img);
byte[] ppt_bytes = pictures[0].getData(); byte[] ppt_bytes = pictures[0].getData();
assertTrue(Arrays.equals(src_bytes, ppt_bytes)); assertTrue(Arrays.equals(src_bytes, ppt_bytes));
} }
@ -217,8 +212,9 @@ public final class TestPictures extends TestCase{
SlideShow ppt = new SlideShow(); SlideShow ppt = new SlideShow();
Slide slide = ppt.createSlide(); Slide slide = ppt.createSlide();
File img = new File(cwd, "clock.jpg"); byte[] src_bytes = slTests.readFile("clock.jpg");
int idx = ppt.addPicture(img, Picture.JPEG); int idx = ppt.addPicture(src_bytes, Picture.JPEG);
Picture pict = new Picture(idx); Picture pict = new Picture(idx);
assertEquals(idx, pict.getPictureIndex()); assertEquals(idx, pict.getPictureIndex());
slide.addShape(pict); slide.addShape(pict);
@ -245,7 +241,6 @@ public final class TestPictures extends TestCase{
assertEquals(Picture.JPEG, pictures[0].getType()); assertEquals(Picture.JPEG, pictures[0].getType());
assertTrue(pictures[0] instanceof JPEG); assertTrue(pictures[0] instanceof JPEG);
//compare the content of the initial file with what is stored in the PictureData //compare the content of the initial file with what is stored in the PictureData
byte[] src_bytes = read(img);
byte[] ppt_bytes = pictures[0].getData(); byte[] ppt_bytes = pictures[0].getData();
assertTrue(Arrays.equals(src_bytes, ppt_bytes)); assertTrue(Arrays.equals(src_bytes, ppt_bytes));
} }
@ -257,13 +252,8 @@ public final class TestPictures extends TestCase{
SlideShow ppt = new SlideShow(); SlideShow ppt = new SlideShow();
Slide slide = ppt.createSlide(); Slide slide = ppt.createSlide();
File img = new File(cwd, "sci_cec.dib"); byte[] src_bytes = slTests.readFile("sci_cec.dib");
int idx = ppt.addPicture(src_bytes, Picture.DIB);
// Check we can read the test DIB image
assertTrue(img.exists());
// Add the image
int idx = ppt.addPicture(img, Picture.DIB);
Picture pict = new Picture(idx); Picture pict = new Picture(idx);
assertEquals(idx, pict.getPictureIndex()); assertEquals(idx, pict.getPictureIndex());
slide.addShape(pict); slide.addShape(pict);
@ -290,22 +280,10 @@ public final class TestPictures extends TestCase{
assertEquals(Picture.DIB, pictures[0].getType()); assertEquals(Picture.DIB, pictures[0].getType());
assertTrue(pictures[0] instanceof DIB); assertTrue(pictures[0] instanceof DIB);
//compare the content of the initial file with what is stored in the PictureData //compare the content of the initial file with what is stored in the PictureData
byte[] src_bytes = read(img);
byte[] ppt_bytes = pictures[0].getData(); byte[] ppt_bytes = pictures[0].getData();
assertTrue(Arrays.equals(src_bytes, ppt_bytes)); assertTrue(Arrays.equals(src_bytes, ppt_bytes));
} }
/**
* Read file into a byte array
*/
protected byte[] read(File f) throws IOException {
byte[] bytes = new byte[(int)f.length()];
FileInputStream is = new FileInputStream(f);
is.read(bytes);
is.close();
return bytes;
}
/** /**
* Read pictures in different formats from a reference slide show * Read pictures in different formats from a reference slide show
*/ */
@ -315,7 +293,7 @@ public final class TestPictures extends TestCase{
Picture pict; Picture pict;
PictureData pdata; PictureData pdata;
SlideShow ppt = new SlideShow(new HSLFSlideShow(new File(cwd, "pictures.ppt").getPath())); SlideShow ppt = new SlideShow(slTests.openResourceAsStream("pictures.ppt"));
Slide[] slides = ppt.getSlides(); Slide[] slides = ppt.getSlides();
PictureData[] pictures = ppt.getPictureData(); PictureData[] pictures = ppt.getPictureData();
assertEquals(5, pictures.length); assertEquals(5, pictures.length);
@ -325,7 +303,7 @@ public final class TestPictures extends TestCase{
assertTrue(pdata instanceof JPEG); assertTrue(pdata instanceof JPEG);
assertEquals(Picture.JPEG, pdata.getType()); assertEquals(Picture.JPEG, pdata.getType());
src_bytes = pdata.getData(); src_bytes = pdata.getData();
ppt_bytes = read(new File(cwd, "clock.jpg")); ppt_bytes = slTests.readFile("clock.jpg");
assertTrue(Arrays.equals(src_bytes, ppt_bytes)); assertTrue(Arrays.equals(src_bytes, ppt_bytes));
pict = (Picture)slides[1].getShapes()[0]; //the second slide contains PNG pict = (Picture)slides[1].getShapes()[0]; //the second slide contains PNG
@ -333,7 +311,7 @@ public final class TestPictures extends TestCase{
assertTrue(pdata instanceof PNG); assertTrue(pdata instanceof PNG);
assertEquals(Picture.PNG, pdata.getType()); assertEquals(Picture.PNG, pdata.getType());
src_bytes = pdata.getData(); src_bytes = pdata.getData();
ppt_bytes = read(new File(cwd, "tomcat.png")); ppt_bytes = slTests.readFile("tomcat.png");
assertTrue(Arrays.equals(src_bytes, ppt_bytes)); assertTrue(Arrays.equals(src_bytes, ppt_bytes));
pict = (Picture)slides[2].getShapes()[0]; //the third slide contains WMF pict = (Picture)slides[2].getShapes()[0]; //the third slide contains WMF
@ -341,7 +319,7 @@ public final class TestPictures extends TestCase{
assertTrue(pdata instanceof WMF); assertTrue(pdata instanceof WMF);
assertEquals(Picture.WMF, pdata.getType()); assertEquals(Picture.WMF, pdata.getType());
src_bytes = pdata.getData(); src_bytes = pdata.getData();
ppt_bytes = read(new File(cwd, "santa.wmf")); ppt_bytes = slTests.readFile("santa.wmf");
assertEquals(src_bytes.length, ppt_bytes.length); assertEquals(src_bytes.length, ppt_bytes.length);
//ignore the first 22 bytes - it is a WMF metafile header //ignore the first 22 bytes - it is a WMF metafile header
b1 = new byte[src_bytes.length-22]; b1 = new byte[src_bytes.length-22];
@ -355,7 +333,7 @@ public final class TestPictures extends TestCase{
assertTrue(pdata instanceof PICT); assertTrue(pdata instanceof PICT);
assertEquals(Picture.PICT, pdata.getType()); assertEquals(Picture.PICT, pdata.getType());
src_bytes = pdata.getData(); src_bytes = pdata.getData();
ppt_bytes = read(new File(cwd, "cow.pict")); ppt_bytes = slTests.readFile("cow.pict");
assertEquals(src_bytes.length, ppt_bytes.length); assertEquals(src_bytes.length, ppt_bytes.length);
//ignore the first 512 bytes - it is a MAC specific crap //ignore the first 512 bytes - it is a MAC specific crap
b1 = new byte[src_bytes.length-512]; b1 = new byte[src_bytes.length-512];
@ -369,7 +347,7 @@ public final class TestPictures extends TestCase{
assertTrue(pdata instanceof EMF); assertTrue(pdata instanceof EMF);
assertEquals(Picture.EMF, pdata.getType()); assertEquals(Picture.EMF, pdata.getType());
src_bytes = pdata.getData(); src_bytes = pdata.getData();
ppt_bytes = read(new File(cwd, "wrench.emf")); ppt_bytes = slTests.readFile("wrench.emf");
assertTrue(Arrays.equals(src_bytes, ppt_bytes)); assertTrue(Arrays.equals(src_bytes, ppt_bytes));
} }
@ -379,7 +357,7 @@ public final class TestPictures extends TestCase{
* crazy pictures of type 0, we do our best. * crazy pictures of type 0, we do our best.
*/ */
public void testZeroPictureType() throws Exception { public void testZeroPictureType() throws Exception {
HSLFSlideShow hslf = new HSLFSlideShow(new File(cwd, "PictureTypeZero.ppt").getPath()); HSLFSlideShow hslf = new HSLFSlideShow(slTests.openResourceAsStream("PictureTypeZero.ppt"));
// Should still have 2 real pictures // Should still have 2 real pictures
assertEquals(2, hslf.getPictures().length); assertEquals(2, hslf.getPictures().length);
@ -409,7 +387,7 @@ public final class TestPictures extends TestCase{
} }
public void testZeroPictureLength() throws Exception { public void testZeroPictureLength() throws Exception {
HSLFSlideShow hslf = new HSLFSlideShow(new File(cwd, "PictureLengthZero.ppt").getPath()); HSLFSlideShow hslf = new HSLFSlideShow(slTests.openResourceAsStream("PictureLengthZero.ppt"));
// Should still have 2 real pictures // Should still have 2 real pictures
assertEquals(2, hslf.getPictures().length); assertEquals(2, hslf.getPictures().length);
@ -453,7 +431,7 @@ public final class TestPictures extends TestCase{
} }
public void testGetPictureName() throws Exception { public void testGetPictureName() throws Exception {
SlideShow ppt = new SlideShow(new HSLFSlideShow(new File(cwd, "ppt_with_png.ppt").getPath())); SlideShow ppt = new SlideShow(slTests.openResourceAsStream("ppt_with_png.ppt"));
Slide slide = ppt.getSlides()[0]; Slide slide = ppt.getSlides()[0];
Picture p = (Picture)slide.getShapes()[0]; //the first slide contains JPEG Picture p = (Picture)slide.getShapes()[0]; //the first slide contains JPEG
@ -464,7 +442,7 @@ public final class TestPictures extends TestCase{
SlideShow ppt = new SlideShow(); SlideShow ppt = new SlideShow();
Slide slide = ppt.createSlide(); Slide slide = ppt.createSlide();
File img = new File(cwd, "tomcat.png"); byte[] img = slTests.readFile("tomcat.png");
int idx = ppt.addPicture(img, Picture.PNG); int idx = ppt.addPicture(img, Picture.PNG);
Picture pict = new Picture(idx); Picture pict = new Picture(idx);
pict.setPictureName("tomcat.png"); pict.setPictureName("tomcat.png");

View File

@ -24,6 +24,7 @@ import java.io.ByteArrayOutputStream;
import junit.framework.TestCase; import junit.framework.TestCase;
import org.apache.poi.hslf.*; import org.apache.poi.hslf.*;
import org.apache.poi.hslf.model.*; import org.apache.poi.hslf.model.*;
import org.apache.poi.POIDataSamples;
/** /**
* Tests that SlideShow can re-order slides properly * Tests that SlideShow can re-order slides properly
@ -47,18 +48,15 @@ public final class TestReOrderingSlides extends TestCase {
* Create/open the slideshows * Create/open the slideshows
*/ */
public void setUp() throws Exception { public void setUp() throws Exception {
String dirname = System.getProperty("HSLF.testdata.path"); POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
String filename = dirname + "/Single_Coloured_Page.ppt"; hss_one = new HSLFSlideShow(slTests.openResourceAsStream("Single_Coloured_Page.ppt"));
hss_one = new HSLFSlideShow(filename);
ss_one = new SlideShow(hss_one); ss_one = new SlideShow(hss_one);
filename = dirname + "/basic_test_ppt_file.ppt"; hss_two = new HSLFSlideShow(slTests.openResourceAsStream("basic_test_ppt_file.ppt"));
hss_two = new HSLFSlideShow(filename);
ss_two = new SlideShow(hss_two); ss_two = new SlideShow(hss_two);
filename = dirname + "/incorrect_slide_order.ppt"; hss_three = new HSLFSlideShow(slTests.openResourceAsStream("incorrect_slide_order.ppt"));
hss_three = new HSLFSlideShow(filename);
ss_three = new SlideShow(hss_three); ss_three = new SlideShow(hss_three);
} }

View File

@ -23,6 +23,7 @@ import org.apache.poi.hslf.*;
import org.apache.poi.hslf.record.ParentAwareRecord; import org.apache.poi.hslf.record.ParentAwareRecord;
import org.apache.poi.hslf.record.Record; import org.apache.poi.hslf.record.Record;
import org.apache.poi.hslf.record.RecordContainer; import org.apache.poi.hslf.record.RecordContainer;
import org.apache.poi.POIDataSamples;
/** /**
* Tests that the record setup done by SlideShow * Tests that the record setup done by SlideShow
@ -37,9 +38,8 @@ public final class TestRecordSetup extends TestCase {
private HSLFSlideShow hss; private HSLFSlideShow hss;
public TestRecordSetup() throws Exception { public TestRecordSetup() throws Exception {
String dirname = System.getProperty("HSLF.testdata.path"); POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
String filename = dirname + "/basic_test_ppt_file.ppt"; hss = new HSLFSlideShow(slTests.openResourceAsStream("basic_test_ppt_file.ppt"));
hss = new HSLFSlideShow(filename);
ss = new SlideShow(hss); ss = new SlideShow(hss);
} }

View File

@ -19,7 +19,6 @@ package org.apache.poi.hslf.usermodel;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import junit.framework.TestCase; import junit.framework.TestCase;
@ -30,6 +29,7 @@ import org.apache.poi.hslf.model.TextBox;
import org.apache.poi.hslf.model.TextRun; import org.apache.poi.hslf.model.TextRun;
import org.apache.poi.hslf.record.Record; import org.apache.poi.hslf.record.Record;
import org.apache.poi.hslf.record.SlideListWithText; import org.apache.poi.hslf.record.SlideListWithText;
import org.apache.poi.POIDataSamples;
/** /**
* Test that the friendly getters and setters on RichTextRun * Test that the friendly getters and setters on RichTextRun
@ -38,6 +38,8 @@ import org.apache.poi.hslf.record.SlideListWithText;
* @author Nick Burch (nick at torchbox dot com) * @author Nick Burch (nick at torchbox dot com)
*/ */
public final class TestRichTextRun extends TestCase { public final class TestRichTextRun extends TestCase {
private static POIDataSamples _slTests = POIDataSamples.getSlideShowInstance();
// SlideShow primed on the test data // SlideShow primed on the test data
private SlideShow ss; private SlideShow ss;
private SlideShow ssRichA; private SlideShow ssRichA;
@ -50,27 +52,23 @@ public final class TestRichTextRun extends TestCase {
private static String filenameC; private static String filenameC;
protected void setUp() throws Exception { protected void setUp() throws Exception {
String dirname = System.getProperty("HSLF.testdata.path");
// Basic (non rich) test file // Basic (non rich) test file
String filename = dirname + "/basic_test_ppt_file.ppt"; hss = new HSLFSlideShow(_slTests.openResourceAsStream("basic_test_ppt_file.ppt"));
hss = new HSLFSlideShow(filename);
ss = new SlideShow(hss); ss = new SlideShow(hss);
// Rich test file A // Rich test file A
filename = dirname + "/Single_Coloured_Page.ppt"; hssRichA = new HSLFSlideShow(_slTests.openResourceAsStream("Single_Coloured_Page.ppt"));
hssRichA = new HSLFSlideShow(filename);
ssRichA = new SlideShow(hssRichA); ssRichA = new SlideShow(hssRichA);
// Rich test file B // Rich test file B
filename = dirname + "/Single_Coloured_Page_With_Fonts_and_Alignments.ppt"; hssRichB = new HSLFSlideShow(_slTests.openResourceAsStream("Single_Coloured_Page_With_Fonts_and_Alignments.ppt"));
hssRichB = new HSLFSlideShow(filename);
ssRichB = new SlideShow(hssRichB); ssRichB = new SlideShow(hssRichB);
// Rich test file C - has paragraph styles that run out before // Rich test file C - has paragraph styles that run out before
// the character ones do // the character ones do
filenameC = dirname + "/ParagraphStylesShorterThanCharStyles.ppt"; filenameC = "ParagraphStylesShorterThanCharStyles.ppt";
hssRichC = new HSLFSlideShow(filenameC); hssRichC = new HSLFSlideShow(_slTests.openResourceAsStream(filenameC));
ssRichC = new SlideShow(hssRichC); ssRichC = new SlideShow(hssRichC);
} }
@ -375,7 +373,7 @@ public final class TestRichTextRun extends TestCase {
*/ */
private void assertMatchesSLTWC(SlideShow s) throws Exception { private void assertMatchesSLTWC(SlideShow s) throws Exception {
// Grab a new copy of slideshow C // Grab a new copy of slideshow C
SlideShow refC = new SlideShow(new HSLFSlideShow(filenameC)); SlideShow refC = new SlideShow(_slTests.openResourceAsStream(filenameC));
// Write out the 2nd SLWT in the active document // Write out the 2nd SLWT in the active document
SlideListWithText refSLWT = refC.getDocumentRecord().getSlideListWithTexts()[1]; SlideListWithText refSLWT = refC.getDocumentRecord().getSlideListWithTexts()[1];
@ -449,7 +447,7 @@ if(false) {
} }
public void testIndentationLevel() throws Exception { public void testIndentationLevel() throws Exception {
SlideShow ppt = new SlideShow(new HSLFSlideShow(new File(System.getProperty("HSLF.testdata.path"), "ParagraphStylesShorterThanCharStyles.ppt").getPath())); SlideShow ppt = new SlideShow(_slTests.openResourceAsStream("ParagraphStylesShorterThanCharStyles.ppt"));
Slide[] sl = ppt.getSlides(); Slide[] sl = ppt.getSlides();
for (int i = 0; i < sl.length; i++) { for (int i = 0; i < sl.length; i++) {
TextRun[] txt = sl[i].getTextRuns(); TextRun[] txt = sl[i].getTextRuns();
@ -465,9 +463,7 @@ if(false) {
} }
public void testReadParagraphStyles() throws Exception { public void testReadParagraphStyles() throws Exception {
FileInputStream is = new FileInputStream(new File(System.getProperty("HSLF.testdata.path"), "bullets.ppt")); SlideShow ppt = new SlideShow(_slTests.openResourceAsStream("bullets.ppt"));
SlideShow ppt = new SlideShow(is);
is.close();
assertTrue("No Exceptions while reading file", true); assertTrue("No Exceptions while reading file", true);
RichTextRun rt; RichTextRun rt;
@ -560,9 +556,7 @@ if(false) {
} }
public void testAddText() throws Exception { public void testAddText() throws Exception {
FileInputStream is = new FileInputStream(new File(System.getProperty("HSLF.testdata.path"), "bullets.ppt")); SlideShow ppt = new SlideShow(_slTests.openResourceAsStream("bullets.ppt"));
SlideShow ppt = new SlideShow(is);
is.close();
assertTrue("No Exceptions while reading file", true); assertTrue("No Exceptions while reading file", true);
RichTextRun rt; RichTextRun rt;

View File

@ -21,6 +21,7 @@ package org.apache.poi.hslf.usermodel;
import junit.framework.TestCase; import junit.framework.TestCase;
import org.apache.poi.hslf.*; import org.apache.poi.hslf.*;
import org.apache.poi.hslf.model.*; import org.apache.poi.hslf.model.*;
import org.apache.poi.POIDataSamples;
/** /**
* Tests that SlideShow returns Sheets which have the right text in them * Tests that SlideShow returns Sheets which have the right text in them
@ -32,9 +33,8 @@ public final class TestSheetText extends TestCase {
private SlideShow ss; private SlideShow ss;
public TestSheetText() throws Exception { public TestSheetText() throws Exception {
String dirname = System.getProperty("HSLF.testdata.path"); POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
String filename = dirname + "/basic_test_ppt_file.ppt"; HSLFSlideShow hss = new HSLFSlideShow(slTests.openResourceAsStream("basic_test_ppt_file.ppt"));
HSLFSlideShow hss = new HSLFSlideShow(filename);
ss = new SlideShow(hss); ss = new SlideShow(hss);
} }
@ -63,9 +63,8 @@ public final class TestSheetText extends TestCase {
* (Make sure we don't screw up / throw an exception etc) * (Make sure we don't screw up / throw an exception etc)
*/ */
public void testWithShortTextPropData() throws Exception { public void testWithShortTextPropData() throws Exception {
String dirname = System.getProperty("HSLF.testdata.path"); POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
String filename = dirname + "/iisd_report.ppt"; HSLFSlideShow hss = new HSLFSlideShow(slTests.openResourceAsStream("iisd_report.ppt"));
HSLFSlideShow hss = new HSLFSlideShow(filename);
SlideShow sss = new SlideShow(hss); SlideShow sss = new SlideShow(hss);
// Should come out with 10 slides, no notes // Should come out with 10 slides, no notes

View File

@ -20,6 +20,7 @@ package org.apache.poi.hslf.usermodel;
import junit.framework.TestCase; import junit.framework.TestCase;
import org.apache.poi.hslf.*; import org.apache.poi.hslf.*;
import org.apache.poi.hslf.model.*; import org.apache.poi.hslf.model.*;
import org.apache.poi.POIDataSamples;
/** /**
* Tests that SlideShow returns Sheets in the right order * Tests that SlideShow returns Sheets in the right order
@ -27,20 +28,18 @@ import org.apache.poi.hslf.model.*;
* @author Nick Burch (nick at torchbox dot com) * @author Nick Burch (nick at torchbox dot com)
*/ */
public final class TestSlideOrdering extends TestCase { public final class TestSlideOrdering extends TestCase {
private static POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
// Simple slideshow, record order matches slide order // Simple slideshow, record order matches slide order
private SlideShow ssA; private SlideShow ssA;
// Complex slideshow, record order doesn't match slide order // Complex slideshow, record order doesn't match slide order
private SlideShow ssB; private SlideShow ssB;
public TestSlideOrdering() throws Exception { public TestSlideOrdering() throws Exception {
String dirname = System.getProperty("HSLF.testdata.path"); HSLFSlideShow hssA = new HSLFSlideShow(slTests.openResourceAsStream("basic_test_ppt_file.ppt"));
String filenameA = dirname + "/basic_test_ppt_file.ppt";
HSLFSlideShow hssA = new HSLFSlideShow(filenameA);
ssA = new SlideShow(hssA); ssA = new SlideShow(hssA);
String filenameB = dirname + "/incorrect_slide_order.ppt"; HSLFSlideShow hssB = new HSLFSlideShow(slTests.openResourceAsStream("incorrect_slide_order.ppt"));
HSLFSlideShow hssB = new HSLFSlideShow(filenameB);
ssB = new SlideShow(hssB); ssB = new SlideShow(hssB);
} }
@ -85,7 +84,9 @@ public final class TestSlideOrdering extends TestCase {
* array of reference slide titles * array of reference slide titles
*/ */
protected void assertSlideOrdering(String filename, String[] titles) throws Exception { protected void assertSlideOrdering(String filename, String[] titles) throws Exception {
SlideShow ppt = new SlideShow(new HSLFSlideShow(filename)); POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
SlideShow ppt = new SlideShow(slTests.openResourceAsStream(filename));
Slide[] slide = ppt.getSlides(); Slide[] slide = ppt.getSlides();
assertEquals(titles.length, slide.length); assertEquals(titles.length, slide.length);
@ -96,25 +97,23 @@ public final class TestSlideOrdering extends TestCase {
} }
public void testTitles() throws Exception { public void testTitles() throws Exception {
String dirname = System.getProperty("HSLF.testdata.path"); assertSlideOrdering("basic_test_ppt_file.ppt", new String[] {
assertSlideOrdering(dirname + "/basic_test_ppt_file.ppt", new String[] {
"This is a test title", "This is the title on page 2" }); "This is a test title", "This is the title on page 2" });
assertSlideOrdering(dirname + "/incorrect_slide_order.ppt", new String[] { "Slide 1", assertSlideOrdering("incorrect_slide_order.ppt", new String[] { "Slide 1",
"Slide 2", "Slide 3" }); "Slide 2", "Slide 3" });
assertSlideOrdering(dirname + "/next_test_ppt_file.ppt", new String[] { assertSlideOrdering("next_test_ppt_file.ppt", new String[] {
"This is a test title", "This is the title on page 2" }); "This is a test title", "This is the title on page 2" });
assertSlideOrdering(dirname + "/Single_Coloured_Page.ppt", assertSlideOrdering("Single_Coloured_Page.ppt",
new String[] { "This is a title, it" + (char) 0x2019 + "s in black" }); new String[] { "This is a title, it" + (char) 0x2019 + "s in black" });
assertSlideOrdering(dirname + "/Single_Coloured_Page_With_Fonts_and_Alignments.ppt", assertSlideOrdering("Single_Coloured_Page_With_Fonts_and_Alignments.ppt",
new String[] { "This is a title, it" + (char) 0x2019 + "s in black" }); new String[] { "This is a title, it" + (char) 0x2019 + "s in black" });
assertSlideOrdering( assertSlideOrdering(
dirname + "/ParagraphStylesShorterThanCharStyles.ppt", "ParagraphStylesShorterThanCharStyles.ppt",
new String[] { new String[] {
"ROMANCE: AN ANALYSIS", "ROMANCE: AN ANALYSIS",
"AGENDA", "AGENDA",

View File

@ -17,11 +17,10 @@
package org.apache.poi.hslf.usermodel; package org.apache.poi.hslf.usermodel;
import java.io.File;
import java.io.FileInputStream;
import java.util.Arrays; import java.util.Arrays;
import junit.framework.TestCase; import junit.framework.TestCase;
import org.apache.poi.POIDataSamples;
/** /**
* Test reading sound data from a ppt * Test reading sound data from a ppt
@ -29,28 +28,16 @@ import junit.framework.TestCase;
* @author Yegor Kozlov * @author Yegor Kozlov
*/ */
public final class TestSoundData extends TestCase{ public final class TestSoundData extends TestCase{
private static POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
protected File cwd;
public void setUp() {
cwd = new File(System.getProperty("HSLF.testdata.path"));
}
/** /**
* Read a reference sound file from disk and compare it from the data extracted from the slide show * Read a reference sound file from disk and compare it from the data extracted from the slide show
*/ */
public void testSounds() throws Exception { public void testSounds() throws Exception {
//read the reference sound file //read the reference sound file
File f = new File(cwd, "ringin.wav"); byte[] ref_data = slTests.readFile("ringin.wav");
int length = (int)f.length();
byte[] ref_data = new byte[length];
FileInputStream is = new FileInputStream(f);
is.read(ref_data);
is.close();
is = new FileInputStream(new File(cwd, "sound.ppt")); SlideShow ppt = new SlideShow(slTests.openResourceAsStream("sound.ppt"));
SlideShow ppt = new SlideShow(is);
is.close();
SoundData[] sound = ppt.getSoundData(); SoundData[] sound = ppt.getSoundData();
assertEquals("Expected 1 sound", 1, sound.length); assertEquals("Expected 1 sound", 1, sound.length);

View File

@ -21,6 +21,7 @@ import java.io.IOException;
import org.apache.poi.hsmf.MAPIMessage; import org.apache.poi.hsmf.MAPIMessage;
import org.apache.poi.hsmf.exceptions.ChunkNotFoundException; import org.apache.poi.hsmf.exceptions.ChunkNotFoundException;
import org.apache.poi.POIDataSamples;
import junit.framework.TestCase; import junit.framework.TestCase;
@ -38,8 +39,8 @@ public final class TestBlankFileRead extends TestCase {
* Initialize this test, load up the blank.msg mapi message. * Initialize this test, load up the blank.msg mapi message.
*/ */
public TestBlankFileRead() throws IOException { public TestBlankFileRead() throws IOException {
String dirname = System.getProperty("HSMF.testdata.path"); POIDataSamples samples = POIDataSamples.getHSMFInstance();
this.mapiMessage = new MAPIMessage(dirname + "/blank.msg"); this.mapiMessage = new MAPIMessage(samples.openResourceAsStream("blank.msg"));
} }
/** /**

View File

@ -27,6 +27,7 @@ import junit.framework.TestCase;
import org.apache.poi.hsmf.MAPIMessage; import org.apache.poi.hsmf.MAPIMessage;
import org.apache.poi.hsmf.exceptions.ChunkNotFoundException; import org.apache.poi.hsmf.exceptions.ChunkNotFoundException;
import org.apache.poi.POIDataSamples;
/** /**
* Tests to verify that we can read attachments from msg file * Tests to verify that we can read attachments from msg file
@ -42,8 +43,8 @@ public class TestFileWithAttachmentsRead extends TestCase {
* @throws Exception * @throws Exception
*/ */
public TestFileWithAttachmentsRead() throws IOException { public TestFileWithAttachmentsRead() throws IOException {
String dirname = System.getProperty("HSMF.testdata.path"); POIDataSamples samples = POIDataSamples.getHSMFInstance();
this.mapiMessage = new MAPIMessage(dirname + "/attachment_test_msg.msg"); this.mapiMessage = new MAPIMessage(samples.openResourceAsStream("attachment_test_msg.msg"));
} }
/** /**

View File

@ -21,6 +21,7 @@ import java.io.IOException;
import org.apache.poi.hsmf.MAPIMessage; import org.apache.poi.hsmf.MAPIMessage;
import org.apache.poi.hsmf.exceptions.ChunkNotFoundException; import org.apache.poi.hsmf.exceptions.ChunkNotFoundException;
import org.apache.poi.POIDataSamples;
import junit.framework.TestCase; import junit.framework.TestCase;
@ -35,8 +36,8 @@ private MAPIMessage mapiMessage;
* @throws Exception * @throws Exception
*/ */
public TestOutlook30FileRead() throws IOException { public TestOutlook30FileRead() throws IOException {
String dirname = System.getProperty("HSMF.testdata.path"); POIDataSamples samples = POIDataSamples.getHSMFInstance();
this.mapiMessage = new MAPIMessage(dirname + "/outlook_30_msg.msg"); this.mapiMessage = new MAPIMessage(samples.openResourceAsStream("outlook_30_msg.msg"));
} }
/** /**

View File

@ -21,6 +21,7 @@ import java.io.IOException;
import org.apache.poi.hsmf.MAPIMessage; import org.apache.poi.hsmf.MAPIMessage;
import org.apache.poi.hsmf.exceptions.ChunkNotFoundException; import org.apache.poi.hsmf.exceptions.ChunkNotFoundException;
import org.apache.poi.POIDataSamples;
import junit.framework.TestCase; import junit.framework.TestCase;
@ -38,8 +39,8 @@ private MAPIMessage mapiMessage;
* @throws Exception * @throws Exception
*/ */
public TestSimpleFileRead() throws IOException { public TestSimpleFileRead() throws IOException {
String dirname = System.getProperty("HSMF.testdata.path"); POIDataSamples samples = POIDataSamples.getHSMFInstance();
this.mapiMessage = new MAPIMessage(dirname + "/simple_test_msg.msg"); this.mapiMessage = new MAPIMessage(samples.openResourceAsStream("simple_test_msg.msg"));
} }
/** /**

View File

@ -20,6 +20,7 @@ package org.apache.poi.hwpf;
import org.apache.poi.hwpf.model.FileInformationBlock; import org.apache.poi.hwpf.model.FileInformationBlock;
import org.apache.poi.poifs.filesystem.DocumentEntry; import org.apache.poi.poifs.filesystem.DocumentEntry;
import org.apache.poi.poifs.filesystem.POIFSFileSystem; import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.POIDataSamples;
public final class HWPFDocFixture public final class HWPFDocFixture
@ -38,7 +39,7 @@ public final class HWPFDocFixture
try try
{ {
POIFSFileSystem filesystem = new POIFSFileSystem( POIFSFileSystem filesystem = new POIFSFileSystem(
HWPFTestDataSamples.openSampleFileStream("test.doc")); POIDataSamples.getDocumentInstance().openResourceAsStream("test.doc"));
DocumentEntry documentProps = DocumentEntry documentProps =
(DocumentEntry) filesystem.getRoot().getEntry("WordDocument"); (DocumentEntry) filesystem.getRoot().getEntry("WordDocument");

View File

@ -20,29 +20,12 @@ import org.apache.poi.POIDataSamples;
import java.io.*; import java.io.*;
public class HWPFTestDataSamples extends POIDataSamples { public class HWPFTestDataSamples {
private static final HWPFTestDataSamples _inst = new HWPFTestDataSamples("HWPF.testdata.path", "SampleDoc.doc");
private HWPFTestDataSamples(String dir, String classPathTestFile){
super(dir, classPathTestFile);
}
public static POIDataSamples getInstance(){
return _inst;
}
public static InputStream openSampleFileStream(String sampleFileName) {
return _inst.openResourceAsStream(sampleFileName);
}
public static byte[] getTestDataFileContent(String fileName) {
return _inst.readFile(fileName);
}
public static HWPFDocument openSampleFile(String sampleFileName) { public static HWPFDocument openSampleFile(String sampleFileName) {
try { try {
return new HWPFDocument(_inst.openResourceAsStream(sampleFileName)); InputStream is = POIDataSamples.getDocumentInstance().openResourceAsStream(sampleFileName);
return new HWPFDocument(is);
} catch (IOException e) { } catch (IOException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }

View File

@ -23,6 +23,7 @@ import junit.framework.TestCase;
import org.apache.poi.hwpf.model.PicturesTable; import org.apache.poi.hwpf.model.PicturesTable;
import org.apache.poi.hwpf.usermodel.Picture; import org.apache.poi.hwpf.usermodel.Picture;
import org.apache.poi.POIDataSamples;
/** /**
* Test picture support in HWPF * Test picture support in HWPF
@ -154,6 +155,6 @@ public final class TestHWPFPictures extends TestCase {
} }
private static byte[] readFile(String file) { private static byte[] readFile(String file) {
return HWPFTestDataSamples.getTestDataFileContent(file); return POIDataSamples.getDocumentInstance().readFile(file);
} }
} }

View File

@ -23,6 +23,7 @@ import org.apache.poi.hwpf.HWPFDocument;
import org.apache.poi.hwpf.HWPFTestDataSamples; import org.apache.poi.hwpf.HWPFTestDataSamples;
import org.apache.poi.poifs.filesystem.DirectoryNode; import org.apache.poi.poifs.filesystem.DirectoryNode;
import org.apache.poi.poifs.filesystem.POIFSFileSystem; import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.POIDataSamples;
import java.io.FileInputStream; import java.io.FileInputStream;
@ -65,17 +66,16 @@ public final class TestWordExtractor extends TestCase {
private String filename6; private String filename6;
protected void setUp() throws Exception { protected void setUp() throws Exception {
String pdirname = System.getProperty("POIFS.testdata.path");
String filename = "test2.doc"; String filename = "test2.doc";
String filename2 = "test.doc"; String filename2 = "test.doc";
filename3 = pdirname + "/excel_with_embeded.xls"; filename3 = "excel_with_embeded.xls";
filename4 = "ThreeColHeadFoot.doc"; filename4 = "ThreeColHeadFoot.doc";
filename5 = "HeaderFooterUnicode.doc"; filename5 = "HeaderFooterUnicode.doc";
filename6 = "footnote.doc"; filename6 = "footnote.doc";
POIDataSamples docTests = POIDataSamples.getDocumentInstance();
extractor = new WordExtractor(HWPFTestDataSamples.openSampleFileStream(filename)); extractor = new WordExtractor(docTests.openResourceAsStream(filename));
extractor2 = new WordExtractor(HWPFTestDataSamples.openSampleFileStream(filename2)); extractor2 = new WordExtractor(docTests.openResourceAsStream(filename2));
// Build splat'd out text version // Build splat'd out text version
for(int i=0; i<p_text1.length; i++) { for(int i=0; i<p_text1.length; i++) {
@ -123,7 +123,7 @@ public final class TestWordExtractor extends TestCase {
* @throws Exception * @throws Exception
*/ */
public void testExtractFromEmbeded() throws Exception { public void testExtractFromEmbeded() throws Exception {
POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(filename3)); POIFSFileSystem fs = new POIFSFileSystem(POIDataSamples.getSpreadSheetInstance().openResourceAsStream(filename3));
HWPFDocument doc; HWPFDocument doc;
WordExtractor extractor3; WordExtractor extractor3;

View File

@ -20,6 +20,7 @@ package org.apache.poi.hwpf.extractor;
import junit.framework.TestCase; import junit.framework.TestCase;
import org.apache.poi.hwpf.HWPFTestDataSamples; import org.apache.poi.hwpf.HWPFTestDataSamples;
import org.apache.poi.POIDataSamples;
/** /**
* Tests for bugs with the WordExtractor * Tests for bugs with the WordExtractor
@ -30,7 +31,7 @@ public final class TestWordExtractorBugs extends TestCase {
public void testProblemMetadata() throws Exception { public void testProblemMetadata() throws Exception {
WordExtractor extractor = WordExtractor extractor =
new WordExtractor(HWPFTestDataSamples.openSampleFileStream("ProblemExtracting.doc")); new WordExtractor(POIDataSamples.getDocumentInstance().openResourceAsStream("ProblemExtracting.doc"));
// Check it gives text without error // Check it gives text without error
extractor.getText(); extractor.getText();

View File

@ -24,6 +24,7 @@ import junit.framework.TestCase;
import org.apache.poi.hwpf.HWPFDocument; import org.apache.poi.hwpf.HWPFDocument;
import org.apache.poi.hwpf.HWPFTestDataSamples; import org.apache.poi.hwpf.HWPFTestDataSamples;
import org.apache.poi.util.LittleEndian; import org.apache.poi.util.LittleEndian;
import org.apache.poi.POIDataSamples;
/** /**
* Test the picture handling * Test the picture handling
@ -98,7 +99,7 @@ public final class TestPictures extends TestCase {
assertTrue(pic.getSize() > 128); assertTrue(pic.getSize() > 128);
// Check right contents // Check right contents
byte[] emf = HWPFTestDataSamples.getTestDataFileContent("vector_image.emf"); byte[] emf = POIDataSamples.getDocumentInstance().readFile("vector_image.emf");
byte[] pemf = pic.getContent(); byte[] pemf = pic.getContent();
assertEquals(emf.length, pemf.length); assertEquals(emf.length, pemf.length);
for(int i=0; i<emf.length; i++) { for(int i=0; i<emf.length; i++) {

View File

@ -20,26 +20,89 @@ import java.io.*;
/** /**
* Centralises logic for finding/opening sample files * Centralises logic for finding/opening sample files
*
*/ */
public abstract class POIDataSamples { public final class POIDataSamples {
/**
* Name of the system property that defined path to the test data.
*/
public static final String TEST_PROPERTY = "POI.testdata.path";
private static POIDataSamples _instSlideshow;
private static POIDataSamples _instSpreadsheet;
private static POIDataSamples _instDocument;
private static POIDataSamples _instDiagram;
private static POIDataSamples _instOpenxml4j;
private static POIDataSamples _instPOIFS;
private static POIDataSamples _instDDF;
private static POIDataSamples _instHPSF;
private static POIDataSamples _instHPBF;
private static POIDataSamples _instHSMF;
private File _resolvedDataDir; private File _resolvedDataDir;
/** <code>true</code> if standard system propery is not set, /** <code>true</code> if standard system propery is not set,
* but the data is available on the test runtime classpath */ * but the data is available on the test runtime classpath */
private boolean _sampleDataIsAvaliableOnClassPath; 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 moduleDir the name of the directory containing the test files
* @param classPathTestFile the name of the test file to check if resources are available from the classpath
*/ */
public POIDataSamples(String dir, String classPathTestFile){ private POIDataSamples(String moduleDir){
_testDataDir = dir; _moduleDir = moduleDir;
initialise(classPathTestFile); 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 * Opens a sample file from the test data directory
* *
@ -60,24 +123,11 @@ public abstract class POIDataSamples {
} }
if (_resolvedDataDir == null) { if (_resolvedDataDir == null) {
throw new RuntimeException("Must set system property '" throw new RuntimeException("Must set system property '"
+ _testDataDir + TEST_PROPERTY
+ "' properly before running tests"); + "' properly before running tests");
} }
File f = new File(_resolvedDataDir, sampleFileName); File f = getFile(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);
}
try { try {
return new FileInputStream(f); return new FileInputStream(f);
} catch (FileNotFoundException e) { } 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) { public File getFile(String sampleFileName) {
String dataDirName = System.getProperty(_testDataDir); 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) { if (dataDirName == null) {
// check to see if we can just get the resources from the classpath // check to see if we can just get the resources from the classpath
InputStream is = openClasspathResource(classPathTest); InputStream is = openClasspathResource("");
if (is != null) { if (is != null) {
try { try {
is.close(); // be nice is.close(); // be nice
@ -104,14 +173,12 @@ public abstract class POIDataSamples {
return; return;
} }
throw new RuntimeException("Must set system property '" throw new RuntimeException("Must set system property '" +
+ _testDataDir + "' before running tests"); TEST_PROPERTY + "' before running tests");
} }
File dataDir = new File(dataDirName); File dataDir = new File(dataDirName, _moduleDir);
if (!dataDir.exists()) { if (!dataDir.exists()) {
throw new RuntimeException("Data dir '" + dataDirName throw new RuntimeException("Data dir '" + _moduleDir + " does not exist");
+ "' specified by system property '" + _testDataDir
+ "' does not exist");
} }
// convert to canonical file, to make any subsequent error messages // convert to canonical file, to make any subsequent error messages
// clearer. // clearer.
@ -129,7 +196,7 @@ public abstract class POIDataSamples {
* @return <code>null</code> if the sample file is not deployed on the classpath. * @return <code>null</code> if the sample file is not deployed on the classpath.
*/ */
private InputStream openClasspathResource(String sampleFileName) { private InputStream openClasspathResource(String sampleFileName) {
return getClass().getResourceAsStream("data/" + sampleFileName); return getClass().getResourceAsStream("/" + _moduleDir + "/" + sampleFileName);
} }
private static final class NonSeekableInputStream extends InputStream { private static final class NonSeekableInputStream extends InputStream {

View File

@ -23,6 +23,7 @@ import java.io.IOException;
import java.util.Arrays; import java.util.Arrays;
import junit.framework.TestCase; import junit.framework.TestCase;
import org.apache.poi.POIDataSamples;
/** /**
* Test read/serialize of escher blip records * Test read/serialize of escher blip records
@ -30,12 +31,12 @@ import junit.framework.TestCase;
* @author Yegor Kozlov * @author Yegor Kozlov
*/ */
public final class TestEscherBlipRecord extends TestCase { 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 //test reading/serializing of a PNG blip
public void testReadPNG() { public void testReadPNG() {
//provided in bug-44886 //provided in bug-44886
byte[] data = read(new File(cwd, "Container.dat")); byte[] data = _samples.readFile("Container.dat");
EscherContainerRecord record = new EscherContainerRecord(); EscherContainerRecord record = new EscherContainerRecord();
record.fillFields(data, 0, new DefaultEscherRecordFactory()); record.fillFields(data, 0, new DefaultEscherRecordFactory());
@ -80,7 +81,7 @@ public final class TestEscherBlipRecord extends TestCase {
//test reading/serializing of a PICT metafile //test reading/serializing of a PICT metafile
public void testReadPICT() { public void testReadPICT() {
//provided in bug-44886 //provided in bug-44886
byte[] data = read(new File(cwd, "Container.dat")); byte[] data = _samples.readFile("Container.dat");
EscherContainerRecord record = new EscherContainerRecord(); EscherContainerRecord record = new EscherContainerRecord();
record.fillFields(data, 0, new DefaultEscherRecordFactory()); 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 //integral test: check that the read-write-read round trip is consistent
public void testContainer() { public void testContainer() {
byte[] data = read(new File(cwd, "Container.dat")); byte[] data = _samples.readFile("Container.dat");
EscherContainerRecord record = new EscherContainerRecord(); EscherContainerRecord record = new EscherContainerRecord();
record.fillFields(data, 0, new DefaultEscherRecordFactory()); 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 * The test data was created from pl031405.xls attached to Bugzilla #47143
*/ */
public void test47143() { public void test47143() {
byte[] data = read(new File(cwd, "47143.dat")); byte[] data = _samples.readFile("47143.dat");
EscherBSERecord bse = new EscherBSERecord(); EscherBSERecord bse = new EscherBSERecord();
bse.fillFields(data, 0, new DefaultEscherRecordFactory()); bse.fillFields(data, 0, new DefaultEscherRecordFactory());
bse.toString(); //assert that toString() works bse.toString(); //assert that toString() works

View File

@ -25,16 +25,13 @@ import junit.framework.TestCase;
import org.apache.poi.util.HexRead; import org.apache.poi.util.HexRead;
import org.apache.poi.util.HexDump; import org.apache.poi.util.HexDump;
import org.apache.poi.util.IOUtils; import org.apache.poi.util.IOUtils;
import org.apache.poi.POIDataSamples;
/** /**
* Tests for {@link EscherContainerRecord} * Tests for {@link EscherContainerRecord}
*/ */
public final class TestEscherContainerRecord extends TestCase { public final class TestEscherContainerRecord extends TestCase {
private String ESCHER_DATA_PATH; private static final POIDataSamples _samples = POIDataSamples.getDDFInstance();
protected void setUp() {
ESCHER_DATA_PATH = System.getProperty("DDF.testdata.path");
}
public void testFillFields() { public void testFillFields() {
EscherRecordFactory f = new DefaultEscherRecordFactory(); EscherRecordFactory f = new DefaultEscherRecordFactory();
@ -151,11 +148,7 @@ public final class TestEscherContainerRecord extends TestCase {
* but hopefully we now read the correct size. * but hopefully we now read the correct size.
*/ */
public void testBug44857() throws Exception { public void testBug44857() throws Exception {
File f = new File(ESCHER_DATA_PATH, "Container.dat"); byte[] data = _samples.readFile("Container.dat");
assertTrue(f.exists());
FileInputStream finp = new FileInputStream(f);
byte[] data = IOUtils.toByteArray(finp);
// This used to fail with an OutOfMemory // This used to fail with an OutOfMemory
EscherContainerRecord record = new EscherContainerRecord(); EscherContainerRecord record = new EscherContainerRecord();

View File

@ -17,6 +17,8 @@
package org.apache.poi.hpsf.basic; package org.apache.poi.hpsf.basic;
import org.apache.poi.POIDataSamples;
import java.io.File; import java.io.File;
import java.io.FileFilter; import java.io.FileFilter;
import java.util.logging.Logger; import java.util.logging.Logger;
@ -30,6 +32,7 @@ import java.util.logging.Logger;
* href="mailto:klute@rainer-klute.de">&lt;klute@rainer-klute.de&gt;</a> * href="mailto:klute@rainer-klute.de">&lt;klute@rainer-klute.de&gt;</a>
*/ */
public class AllDataFilesTester { public class AllDataFilesTester {
private static final POIDataSamples _samples = POIDataSamples.getHPSFInstance();
/** /**
* <p>Interface specifying how to run a test on a single file.</p> * <p>Interface specifying how to run a test on a single file.</p>
@ -56,8 +59,8 @@ public class AllDataFilesTester {
*/ */
public void runTests(final TestTask task) throws Throwable public void runTests(final TestTask task) throws Throwable
{ {
final String dataDirName = System.getProperty("HPSF.testdata.path"); POIDataSamples _samples = POIDataSamples.getHPSFInstance();
final File dataDir = new File(dataDirName); final File dataDir = _samples.getFile("");
final File[] docs = dataDir.listFiles(new FileFilter() final File[] docs = dataDir.listFiles(new FileFilter()
{ {
public boolean accept(final File file) public boolean accept(final File file)

View File

@ -37,6 +37,7 @@ import org.apache.poi.hpsf.PropertySetFactory;
import org.apache.poi.hpsf.Section; import org.apache.poi.hpsf.Section;
import org.apache.poi.hpsf.SummaryInformation; import org.apache.poi.hpsf.SummaryInformation;
import org.apache.poi.hpsf.wellknown.SectionIDMap; import org.apache.poi.hpsf.wellknown.SectionIDMap;
import org.apache.poi.POIDataSamples;
/** /**
* <p>Tests the basic HPSF functionality.</p> * <p>Tests the basic HPSF functionality.</p>
@ -80,11 +81,10 @@ public final class TestBasic extends TestCase {
* @exception FileNotFoundException if the file to be read does not exist. * @exception FileNotFoundException if the file to be read does not exist.
* @exception IOException if any other I/O exception occurs. * @exception IOException if any other I/O exception occurs.
*/ */
public void setUp() throws FileNotFoundException, IOException public void setUp() throws IOException
{ {
final File dataDir = POIDataSamples samples = POIDataSamples.getHPSFInstance();
new File(System.getProperty("HPSF.testdata.path")); final File data = samples.getFile(POI_FS);
final File data = new File(dataDir, POI_FS);
poiFiles = Util.readPOIFiles(data); poiFiles = Util.readPOIFiles(data);
} }

View File

@ -35,6 +35,7 @@ import org.apache.poi.hpsf.PropertySet;
import org.apache.poi.hpsf.PropertySetFactory; import org.apache.poi.hpsf.PropertySetFactory;
import org.apache.poi.hpsf.SummaryInformation; import org.apache.poi.hpsf.SummaryInformation;
import org.apache.poi.hpsf.Variant; import org.apache.poi.hpsf.Variant;
import org.apache.poi.POIDataSamples;
/** /**
* <p>Test case for OLE2 files with empty properties. An empty property's type * <p>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 public void setUp() throws FileNotFoundException, IOException
{ {
final File dataDir = POIDataSamples samples = POIDataSamples.getHPSFInstance();
new File(System.getProperty("HPSF.testdata.path")); final File data = samples.getFile(POI_FS);
final File data = new File(dataDir, POI_FS);
poiFiles = Util.readPOIFiles(data); poiFiles = Util.readPOIFiles(data);
} }

View File

@ -25,6 +25,7 @@ import java.io.InputStream;
import junit.framework.TestCase; import junit.framework.TestCase;
import org.apache.poi.hpsf.PropertySetFactory; import org.apache.poi.hpsf.PropertySetFactory;
import org.apache.poi.POIDataSamples;
/** /**
* <p>Tests some HPSF functionality by reading all property sets from all files * <p>Tests some HPSF functionality by reading all property sets from all files
@ -41,8 +42,8 @@ public class TestReadAllFiles extends TestCase {
*/ */
public void testReadAllFiles() public void testReadAllFiles()
{ {
final File dataDir = POIDataSamples _samples = POIDataSamples.getHPSFInstance();
new File(System.getProperty("HPSF.testdata.path")); final File dataDir = _samples.getFile("");
final File[] fileList = dataDir.listFiles(new FileFilter() final File[] fileList = dataDir.listFiles(new FileFilter()
{ {
public boolean accept(final File f) public boolean accept(final File f)

View File

@ -32,6 +32,7 @@ import org.apache.poi.hpsf.PropertySet;
import org.apache.poi.hpsf.PropertySetFactory; import org.apache.poi.hpsf.PropertySetFactory;
import org.apache.poi.hpsf.Section; import org.apache.poi.hpsf.Section;
import org.apache.poi.hpsf.SummaryInformation; import org.apache.poi.hpsf.SummaryInformation;
import org.apache.poi.POIDataSamples;
/** /**
* <p>Tests whether Unicode string can be read from a * <p>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 * @exception IOException if any other I/O exception occurs
*/ */
protected void setUp() { protected void setUp() {
final File dataDir = POIDataSamples samples = POIDataSamples.getHPSFInstance();
new File(System.getProperty("HPSF.testdata.path")); data = samples.getFile(POI_FS);
data = new File(dataDir, POI_FS);
} }

View File

@ -63,6 +63,7 @@ import org.apache.poi.poifs.eventfilesystem.POIFSReaderListener;
import org.apache.poi.poifs.filesystem.POIFSFileSystem; import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.util.LittleEndian; import org.apache.poi.util.LittleEndian;
import org.apache.poi.util.TempFile; import org.apache.poi.util.TempFile;
import org.apache.poi.POIDataSamples;
/** /**
* <p>Tests HPSF's writing functionality.</p> * <p>Tests HPSF's writing functionality.</p>
@ -71,6 +72,7 @@ import org.apache.poi.util.TempFile;
*/ */
public class TestWrite extends TestCase public class TestWrite extends TestCase
{ {
private static final POIDataSamples _samples = POIDataSamples.getHPSFInstance();
static final String POI_FS = "TestHPSFWritingFunctionality.doc"; static final String POI_FS = "TestHPSFWritingFunctionality.doc";
@ -110,10 +112,7 @@ public class TestWrite extends TestCase
*/ */
public void testNoFormatID() throws IOException public void testNoFormatID() throws IOException
{ {
final String dataDirName = System.getProperty("HPSF.testdata.path"); final File filename = TempFile.createTempFile(POI_FS, ".doc");
final File dataDir = new File(dataDirName);
final File filename = new File(dataDir, POI_FS);
filename.deleteOnExit();
/* Create a mutable property set with a section that does not have the /* Create a mutable property set with a section that does not have the
* formatID set: */ * formatID set: */
@ -159,8 +158,7 @@ public class TestWrite extends TestCase
public void testWriteEmptyPropertySet() public void testWriteEmptyPropertySet()
throws IOException, UnsupportedVariantTypeException throws IOException, UnsupportedVariantTypeException
{ {
final File dataDir = final File dataDir = _samples.getFile("");
new File(System.getProperty("HPSF.testdata.path"));
final File filename = new File(dataDir, POI_FS); final File filename = new File(dataDir, POI_FS);
filename.deleteOnExit(); filename.deleteOnExit();
@ -202,8 +200,7 @@ public class TestWrite extends TestCase
{ {
final String AUTHOR = "Rainer Klute"; final String AUTHOR = "Rainer Klute";
final String TITLE = "Test Document"; final String TITLE = "Test Document";
final File dataDir = final File dataDir = _samples.getFile("");
new File(System.getProperty("HPSF.testdata.path"));
final File filename = new File(dataDir, POI_FS); final File filename = new File(dataDir, POI_FS);
filename.deleteOnExit(); filename.deleteOnExit();
final OutputStream out = new FileOutputStream(filename); final OutputStream out = new FileOutputStream(filename);
@ -274,8 +271,7 @@ public class TestWrite extends TestCase
final String SECTION1 = "Section 1"; final String SECTION1 = "Section 1";
final String SECTION2 = "Section 2"; final String SECTION2 = "Section 2";
final File dataDir = final File dataDir = _samples.getFile("");
new File(System.getProperty("HPSF.testdata.path"));
final File filename = new File(dataDir, POI_FS); final File filename = new File(dataDir, POI_FS);
filename.deleteOnExit(); filename.deleteOnExit();
final OutputStream out = new FileOutputStream(filename); final OutputStream out = new FileOutputStream(filename);
@ -673,8 +669,7 @@ public class TestWrite extends TestCase
*/ */
public void testRecreate() public void testRecreate()
{ {
final File dataDir = final File dataDir = _samples.getFile("");
new File(System.getProperty("HPSF.testdata.path"));
final File[] fileList = dataDir.listFiles(new FileFilter() final File[] fileList = dataDir.listFiles(new FileFilter()
{ {
public boolean accept(final File f) public boolean accept(final File f)

View File

@ -53,6 +53,7 @@ import org.apache.poi.poifs.filesystem.DirectoryEntry;
import org.apache.poi.poifs.filesystem.DocumentEntry; import org.apache.poi.poifs.filesystem.DocumentEntry;
import org.apache.poi.poifs.filesystem.DocumentInputStream; import org.apache.poi.poifs.filesystem.DocumentInputStream;
import org.apache.poi.poifs.filesystem.POIFSFileSystem; import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.POIDataSamples;
/** /**
* <p>Tests HPSF's high-level writing functionality for the well-known property * <p>Tests HPSF's high-level writing functionality for the well-known property
@ -78,8 +79,8 @@ public class TestWriteWellKnown extends TestCase {
/** /**
* <p>This test method checks whether DocumentSummary information streams * <p>This test method checks whether DocumentSummary information streams
* can be read. This is done by opening all "Test*" files in the directrory * can be read. This is done by opening all "Test*" files in the 'poifs' directrory
* pointed to by the "HPSF.testdata.path" system property, trying to extract * pointed to by the "POI.testdata.path" system property, trying to extract
* the document summary information stream in the root directory and calling * the document summary information stream in the root directory and calling
* its get... methods.</p> * its get... methods.</p>
* @throws IOException * @throws IOException
@ -93,8 +94,8 @@ public class TestWriteWellKnown extends TestCase {
NoPropertySetStreamException, MarkUnsupportedException, NoPropertySetStreamException, MarkUnsupportedException,
UnexpectedPropertySetTypeException UnexpectedPropertySetTypeException
{ {
final String dataDirName = System.getProperty("HPSF.testdata.path"); POIDataSamples _samples = POIDataSamples.getHPSFInstance();
final File dataDir = new File(dataDirName); final File dataDir = _samples.getFile("");
final File[] docs = dataDir.listFiles(new FileFilter() final File[] docs = dataDir.listFiles(new FileFilter()
{ {
public boolean accept(final File file) public boolean accept(final File file)
@ -205,8 +206,8 @@ public class TestWriteWellKnown extends TestCase {
NoPropertySetStreamException, MarkUnsupportedException, NoPropertySetStreamException, MarkUnsupportedException,
UnexpectedPropertySetTypeException, WritingNotSupportedException UnexpectedPropertySetTypeException, WritingNotSupportedException
{ {
final String dataDirName = System.getProperty("HPSF.testdata.path"); POIDataSamples _samples = POIDataSamples.getHPSFInstance();
final File dataDir = new File(dataDirName); final File dataDir = _samples.getFile("");
final File doc1 = new File(dataDir, POI_FS); final File doc1 = new File(dataDir, POI_FS);
/* Read a test document <em>doc1</em> into a POI filesystem. */ /* Read a test document <em>doc1</em> into a POI filesystem. */
@ -625,8 +626,8 @@ public class TestWriteWellKnown extends TestCase {
} }
}; };
final String dataDirName = System.getProperty("HPSF.testdata.path"); POIDataSamples _samples = POIDataSamples.getHPSFInstance();
final File dataDir = new File(dataDirName); final File dataDir = _samples.getFile("");
final File[] docs = dataDir.listFiles(new FileFilter() final File[] docs = dataDir.listFiles(new FileFilter()
{ {
public boolean accept(final File file) public boolean accept(final File file)

View File

@ -27,18 +27,15 @@ import org.apache.poi.hssf.extractor.ExcelExtractor;
import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.HSSFTestDataSamples; import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.poifs.filesystem.POIFSFileSystem; import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.POIDataSamples;
public final class TestHPSFPropertiesExtractor extends TestCase { public final class TestHPSFPropertiesExtractor extends TestCase {
private String dir; private static final POIDataSamples _samples = POIDataSamples.getHPSFInstance();
protected void setUp() {
dir = System.getProperty("HPSF.testdata.path");
assertNotNull("HPSF.testdata.path not set", dir);
}
public void testNormalProperties() throws Exception { public void testNormalProperties() throws Exception {
POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream( POIFSFileSystem fs = new POIFSFileSystem(
new File(dir, "TestMickey.doc"))); _samples.openResourceAsStream("TestMickey.doc")
);
HPSFPropertiesExtractor ext = new HPSFPropertiesExtractor(fs); HPSFPropertiesExtractor ext = new HPSFPropertiesExtractor(fs);
ext.getText(); ext.getText();
@ -60,8 +57,9 @@ public final class TestHPSFPropertiesExtractor extends TestCase {
} }
public void testNormalUnicodeProperties() throws Exception { public void testNormalUnicodeProperties() throws Exception {
POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(new File(dir, POIFSFileSystem fs = new POIFSFileSystem(
"TestUnicode.xls"))); _samples.openResourceAsStream("TestUnicode.xls")
);
HPSFPropertiesExtractor ext = new HPSFPropertiesExtractor(fs); HPSFPropertiesExtractor ext = new HPSFPropertiesExtractor(fs);
ext.getText(); ext.getText();
@ -83,8 +81,9 @@ public final class TestHPSFPropertiesExtractor extends TestCase {
} }
public void testCustomProperties() throws Exception { public void testCustomProperties() throws Exception {
POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream( POIFSFileSystem fs = new POIFSFileSystem(
new File(dir, "TestMickey.doc"))); _samples.openResourceAsStream("TestMickey.doc")
);
HPSFPropertiesExtractor ext = new HPSFPropertiesExtractor(fs); HPSFPropertiesExtractor ext = new HPSFPropertiesExtractor(fs);
// Custom properties are part of the document info stream // Custom properties are part of the document info stream
@ -101,7 +100,9 @@ public final class TestHPSFPropertiesExtractor extends TestCase {
POIFSFileSystem fs; POIFSFileSystem fs;
HSSFWorkbook wb; HSSFWorkbook wb;
try { try {
fs = new POIFSFileSystem(new FileInputStream(new File(dir, "TestUnicode.xls"))); fs = new POIFSFileSystem(
_samples.openResourceAsStream("TestUnicode.xls")
);
wb = new HSSFWorkbook(fs); wb = new HSSFWorkbook(fs);
} catch (IOException e) { } catch (IOException e) {
throw new RuntimeException(e); throw new RuntimeException(e);

View File

@ -21,6 +21,7 @@ import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.ITestDataProvider; import org.apache.poi.ss.ITestDataProvider;
import org.apache.poi.ss.SpreadsheetVersion; import org.apache.poi.ss.SpreadsheetVersion;
import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.POIDataSamples;
/** /**
* @author Yegor Kozlov * @author Yegor Kozlov
@ -44,7 +45,7 @@ public final class HSSFITestDataProvider implements ITestDataProvider {
} }
public byte[] getTestDataFileContent(String fileName) { public byte[] getTestDataFileContent(String fileName) {
return HSSFTestDataSamples.getTestDataFileContent(fileName); return POIDataSamples.getSpreadSheetInstance().readFile(fileName);
} }
public SpreadsheetVersion getSpreadsheetVersion(){ public SpreadsheetVersion getSpreadsheetVersion(){

View File

@ -30,17 +30,9 @@ import org.apache.poi.hssf.usermodel.HSSFWorkbook;
* *
* @author Josh Micich * @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 static final POIDataSamples _inst = POIDataSamples.getSpreadSheetInstance();
private HSSFTestDataSamples(String dir, String classPathTestFile){
super(dir, classPathTestFile);
}
public static POIDataSamples getInstance(){
return _inst;
}
public static InputStream openSampleFileStream(String sampleFileName) { public static InputStream openSampleFileStream(String sampleFileName) {
return _inst.openResourceAsStream(sampleFileName); return _inst.openResourceAsStream(sampleFileName);

View File

@ -28,6 +28,8 @@ import org.apache.poi.hssf.record.crypto.Biff8EncryptionKey;
import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.poifs.filesystem.DirectoryNode; import org.apache.poi.poifs.filesystem.DirectoryNode;
import org.apache.poi.poifs.filesystem.POIFSFileSystem; 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 * Embded in a non-excel file
*/ */
public void testWithEmbeded() throws Exception { 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( POIFSFileSystem fs = new POIFSFileSystem(
new FileInputStream(filename) POIDataSamples.getDocumentInstance().openResourceAsStream("word_with_embeded.doc")
); );
DirectoryNode objPool = (DirectoryNode) fs.getRoot().getEntry("ObjectPool"); DirectoryNode objPool = (DirectoryNode) fs.getRoot().getEntry("ObjectPool");
@ -244,11 +243,9 @@ public final class TestExcelExtractor extends TestCase {
* Excel embeded in excel * Excel embeded in excel
*/ */
public void testWithEmbededInOwn() throws Exception { public void testWithEmbededInOwn() throws Exception {
// TODO - encapsulate sys prop 'POIFS.testdata.path' similar to HSSFTestDataSamples POIDataSamples ssSamples = POIDataSamples.getSpreadSheetInstance();
String pdirname = System.getProperty("POIFS.testdata.path");
String filename = pdirname + "/excel_with_embeded.xls";
POIFSFileSystem fs = new POIFSFileSystem( POIFSFileSystem fs = new POIFSFileSystem(
new FileInputStream(filename) ssSamples.openResourceAsStream("excel_with_embeded.xls")
); );
DirectoryNode dirA = (DirectoryNode) fs.getRoot().getEntry("MBD0000A3B5"); DirectoryNode dirA = (DirectoryNode) fs.getRoot().getEntry("MBD0000A3B5");

Some files were not shown because too many files have changed in this diff Show More