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="ooxml.lib" location="ooxml-lib"/>
<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.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"/>
<sysproperty key="user.language" value="en"/>
<sysproperty key="user.country" value="US"/>
<sysproperty key="HSSF.testdata.path" file="${main.src.test}/org/apache/poi/hssf/data"/>
<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="POI.testdata.path" file="${poi.test.dir}"/>
<sysproperty key="java.awt.headless" value="true"/>
<formatter type="plain"/>
<formatter type="xml"/>
@ -602,10 +598,7 @@ under the License.
</classpath>
<sysproperty key="user.language" value="en"/>
<sysproperty key="user.country" value="US"/>
<sysproperty key="HSSF.testdata.path" file="${main.src.test}/org/apache/poi/hssf/data"/>
<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="POI.testdata.path" file="${poi.test.dir}"/>
<sysproperty key="java.awt.headless" value="true"/>
<formatter type="plain" usefile="no"/>
<batchtest todir="${main.reports.test}">
@ -631,15 +624,7 @@ under the License.
</classpath>
<sysproperty key="user.language" value="en"/>
<sysproperty key="user.country" value="US"/>
<sysproperty key="HSSF.testdata.path" file="${main.src.test}/org/apache/poi/hssf/data"/>
<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="POI.testdata.path" file="${poi.test.dir}"/>
<sysproperty key="java.awt.headless" value="true"/>
<formatter type="plain" usefile="no"/>
<formatter type="xml"/>
@ -675,15 +660,7 @@ under the License.
</classpath>
<sysproperty key="user.language" value="en"/>
<sysproperty key="user.country" value="US"/>
<sysproperty key="HSSF.testdata.path" file="${main.src.test}/org/apache/poi/hssf/data"/>
<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="POI.testdata.path" file="${poi.test.dir}"/>
<sysproperty key="java.awt.headless" value="true"/>
<formatter type="plain"/>
<formatter type="xml"/>
@ -714,14 +691,7 @@ under the License.
</classpath>
<sysproperty key="user.language" value="en"/>
<sysproperty key="user.country" value="US"/>
<sysproperty key="HSSF.testdata.path" file="${main.src.test}/org/apache/poi/hssf/data"/>
<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="POI.testdata.path" file="${poi.test.dir}"/>
<sysproperty key="java.awt.headless" value="true"/>
<sysproperty key="java.awt.headless" value="true"/>
<formatter type="plain" usefile="no"/>
@ -748,8 +718,6 @@ under the License.
</classpath>
<sysproperty key="user.language" value="en"/>
<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"/>
<formatter type="plain"/>
<formatter type="xml"/>
@ -780,14 +748,7 @@ under the License.
<classpath refid="test.ooxml.classpath" />
<sysproperty key="user.language" value="en"/>
<sysproperty key="user.country" value="US"/>
<sysproperty key="POIFS.testdata.path" file="${main.src.test}/org/apache/poi/poifs/data"/>
<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="POI.testdata.path" file="${poi.test.dir}"/>
<sysproperty key="java.awt.headless" value="true"/>
<formatter type="plain"/>
<formatter type="xml"/>
@ -811,12 +772,7 @@ under the License.
<classpath refid="test.ooxml.classpath" />
<sysproperty key="user.language" value="en"/>
<sysproperty key="user.country" value="US"/>
<sysproperty key="HSSF.testdata.path" file="${main.src.test}/org/apache/poi/hssf/data"/>
<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="POI.testdata.path" file="${poi.test.dir}"/>
<sysproperty key="java.awt.headless" value="true"/>
<formatter type="plain" usefile="no"/>
<formatter type="xml"/>

View File

@ -33,6 +33,7 @@
<changes>
<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">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>

View File

@ -36,34 +36,24 @@ import junit.framework.TestCase;
*/
public class TestEmbeded extends TestCase
{
public String dirname;
public void setUp() {
dirname = System.getProperty("OOXML.testdata.path");
assertNotNull(dirname);
}
public void testExcel() throws Exception {
File f = new File(dirname, "ExcelWithAttachments.xlsm");
assertTrue(f.exists());
POIXMLDocument doc = new XSSFWorkbook(OPCPackage.open(f.toString()));
POIXMLDocument doc = new XSSFWorkbook(
POIDataSamples.getSpreadSheetInstance().openResourceAsStream("ExcelWithAttachments.xlsm")
);
test(doc, 4);
}
public void testWord() throws Exception {
File f = new File(dirname, "WordWithAttachments.docx");
assertTrue(f.exists());
POIXMLDocument doc = new XWPFDocument(OPCPackage.open(f.toString()));
POIXMLDocument doc = new XWPFDocument(
POIDataSamples.getDocumentInstance().openResourceAsStream("WordWithAttachments.docx")
);
test(doc, 5);
}
public void testPowerPoint() throws Exception {
File f = new File(dirname, "PPTWithAttachments.pptm");
assertTrue(f.exists());
POIXMLDocument doc = new XSLFSlideShow(OPCPackage.open(f.toString()));
POIXMLDocument doc = new XSLFSlideShow(OPCPackage.open(
POIDataSamples.getSlideShowInstance().openResourceAsStream("PPTWithAttachments.pptm"))
);
test(doc, 4);
}

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

View File

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

View File

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

View File

@ -17,6 +17,9 @@
package org.apache.poi.openxml4j;
import org.apache.poi.POIDataSamples;
import org.apache.poi.util.TempFile;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
@ -28,121 +31,31 @@ import java.io.InputStream;
* @author jmicich
*/
public final class OpenXML4JTestDataSamples {
private static final String IN_DIR_PROP_NAME = "openxml4j.testdata.input";
private static final String COMP_IN_DIR_PROP_NAME = "openxml4j.compliance.input";
private static File _sampleInputDir;
private static File _sampleOutputDir;
private static File _complianceSampleInputDir;
private static final POIDataSamples _samples = POIDataSamples.getOpenXML4JInstance();
private OpenXML4JTestDataSamples() {
// no instances of this class
}
public static InputStream openSampleStream(String sampleFileName) {
File f = getSampleFile(sampleFileName);
try {
return new FileInputStream(f);
} catch (FileNotFoundException e) {
throw new RuntimeException(e);
}
return _samples.openResourceAsStream(sampleFileName);
}
public static String getSampleFileName(String sampleFileName) {
// TODO - investigate allowing read/write access for package opened on stream
return getSampleFile(sampleFileName).getAbsolutePath();
}
public static File getSampleFile(String sampleFileName) {
File dir = getSampleInputDir();
File f = new File(dir, sampleFileName);
if (!f.exists()) {
throw new RuntimeException("Specified sample file '"
+ f.getAbsolutePath() + "' does not exist");
}
if (f.isDirectory()) {
throw new RuntimeException("Specified sample file '"
+ f.getAbsolutePath() + "' is a directory");
}
return f;
return _samples.getFile(sampleFileName);
}
public static File getOutputFile(String outputFileName) {
File dir = getSampleOutputDir();
return new File(dir, outputFileName);
String suffix = outputFileName.substring(outputFileName.lastIndexOf('.'));
return TempFile.createTempFile(outputFileName, suffix);
}
public static InputStream openComplianceSampleStream(String sampleFileName) {
File f = getComplianceSampleFile(sampleFileName);
try {
return new FileInputStream(f);
} catch (FileNotFoundException e) {
throw new RuntimeException(e);
}
}
private static File getComplianceSampleFile(String sampleFileName) {
File dir = getComplianceSampleInputDir();
File f = new File(dir, sampleFileName);
if (!f.exists()) {
throw new RuntimeException("Specified sample file '"
+ f.getAbsolutePath() + "' does not exist");
}
if (f.isDirectory()) {
throw new RuntimeException("Specified sample file '"
+ f.getAbsolutePath() + "' is a directory");
}
return f;
}
public static String getComplianceSampleFileName(String sampleFileName) {
return getComplianceSampleFile(sampleFileName).getAbsolutePath();
}
private static File getComplianceSampleInputDir() {
if (_complianceSampleInputDir == null) {
_complianceSampleInputDir = getAndCheckDirByProperty(COMP_IN_DIR_PROP_NAME);
}
return _complianceSampleInputDir;
}
private static File getSampleInputDir() {
if (_sampleInputDir == null) {
_sampleInputDir = getAndCheckDirByProperty(IN_DIR_PROP_NAME);
}
return _sampleInputDir;
}
private static File getAndCheckDirByProperty(String propName) {
String dirName = System.getProperty(propName);
File dir = new File(dirName);
if (!dir.exists()) {
throw new RuntimeException("Specified '" + propName + "' directory: '"
+ dirName + "' does not exist");
}
if (!dir.isDirectory()) {
throw new RuntimeException("Specified '" + propName + "' directory: '"
+ dirName + "' is a not a proper directory");
}
return dir;
}
private static File getSampleOutputDir() {
if (_sampleOutputDir == null) {
File dir = new File(System.getProperty("java.io.tmpdir"), "poifiles");
if (dir.exists()) {
if (!dir.isDirectory()) {
throw new RuntimeException("Specified output directory: '"
+ dir.getAbsolutePath() + "' is a not a proper directory");
}
} else {
if (!dir.mkdirs()) {
throw new RuntimeException("Failed to create directory: '"
+ dir.getAbsolutePath() + "'");
}
}
_sampleOutputDir = dir;
}
return _sampleOutputDir;
return _samples.openResourceAsStream(sampleFileName);
}
}

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

View File

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

View File

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

View File

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

View File

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

View File

@ -39,14 +39,7 @@ import org.apache.poi.util.TempFile;
*/
public class XSSFTestDataSamples {
public static InputStream openSampleFileStream(String sampleFileName) {
return HSSFTestDataSamples.openSampleFileStream(sampleFileName);
}
public static byte[] getTestDataFileContent(String fileName) {
return HSSFTestDataSamples.getTestDataFileContent(fileName);
}
public static final XSSFWorkbook openSampleWorkbook(String sampleName) {
public static XSSFWorkbook openSampleWorkbook(String sampleName) {
InputStream is = HSSFTestDataSamples.openSampleFileStream(sampleName);
try {
return new XSSFWorkbook(is);
@ -57,24 +50,17 @@ public class XSSFTestDataSamples {
public static <R extends Workbook> R writeOutAndReadBack(R wb) {
Workbook result;
try {
if (wb instanceof HSSFWorkbook) {
ByteArrayOutputStream baos = new ByteArrayOutputStream(8192);
wb.write(baos);
InputStream is = new ByteArrayInputStream(baos.toByteArray());
if (wb instanceof HSSFWorkbook) {
result = new HSSFWorkbook(is);
} else if (wb instanceof XSSFWorkbook) {
File tmp = TempFile.createTempFile("poi-ooxml-", ".xlsx");
FileOutputStream out = new FileOutputStream(tmp);
wb.write(out);
out.close();
OPCPackage pkg = OPCPackage.open(tmp.getAbsolutePath());
result = new XSSFWorkbook(pkg);
result = new XSSFWorkbook(is);
} else {
throw new RuntimeException("Unexpected workbook type ("
+ wb.getClass().getName() + ")");
}
} catch (InvalidFormatException e) {
throw new RuntimeException(e);
} catch (IOException 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.xssf.XSSFTestDataSamples;
import org.apache.poi.xssf.usermodel.XSSFRichTextString;
import org.apache.poi.POIDataSamples;
/**
* Tests for {@link XSSFReader}
*/
public final class TestXSSFReader extends TestCase {
private static POIDataSamples _ssTests = POIDataSamples.getSpreadSheetInstance();
public void testGetBits() throws Exception {
OPCPackage pkg = OPCPackage.open(XSSFTestDataSamples.openSampleFileStream("SampleSS.xlsx"));
OPCPackage pkg = OPCPackage.open(_ssTests.openResourceAsStream("SampleSS.xlsx"));
XSSFReader r = new XSSFReader(pkg);
@ -46,7 +48,7 @@ public final class TestXSSFReader extends TestCase {
}
public void testStyles() throws Exception {
OPCPackage pkg = OPCPackage.open(XSSFTestDataSamples.openSampleFileStream("SampleSS.xlsx"));
OPCPackage pkg = OPCPackage.open(_ssTests.openResourceAsStream("SampleSS.xlsx"));
XSSFReader r = new XSSFReader(pkg);
@ -55,7 +57,7 @@ public final class TestXSSFReader extends TestCase {
}
public void testStrings() throws Exception {
OPCPackage pkg = OPCPackage.open(XSSFTestDataSamples.openSampleFileStream("SampleSS.xlsx"));
OPCPackage pkg = OPCPackage.open(_ssTests.openResourceAsStream("SampleSS.xlsx"));
XSSFReader r = new XSSFReader(pkg);
@ -64,7 +66,7 @@ public final class TestXSSFReader extends TestCase {
}
public void testSheets() throws Exception {
OPCPackage pkg = OPCPackage.open(XSSFTestDataSamples.openSampleFileStream("SampleSS.xlsx"));
OPCPackage pkg = OPCPackage.open(_ssTests.openResourceAsStream("SampleSS.xlsx"));
XSSFReader r = new XSSFReader(pkg);
byte[] data = new byte[4096];
@ -96,7 +98,7 @@ public final class TestXSSFReader extends TestCase {
* (as they are defined in the workbook.xml)
*/
public void testOrderOfSheets() throws Exception {
OPCPackage pkg = OPCPackage.open(XSSFTestDataSamples.openSampleFileStream("reordered_sheets.xlsx"));
OPCPackage pkg = OPCPackage.open(_ssTests.openResourceAsStream("reordered_sheets.xlsx"));
XSSFReader r = new XSSFReader(pkg);

View File

@ -28,23 +28,15 @@ import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.poi.xssf.usermodel.XSSFPictureData;
import org.apache.poi.xssf.XSSFITestDataProvider;
import org.apache.poi.POIDataSamples;
public class TestLoadSaveXSSF extends TestCase {
String filename;
protected void setUp() {
System.setProperty("org.apache.poi.util.POILogger", org.apache.poi.util.CommonsLogger.class.getName());
filename = System.getProperty("XSSF.testdata.path");
if (filename == null) {
filename = "src/ooxml/testcases/org/apache/poi/xssf/data";
}
}
private static final POIDataSamples _ssSampels = POIDataSamples.getSpreadSheetInstance();
public void testLoadSample() throws Exception {
XSSFWorkbook workbook = new XSSFWorkbook(new File(filename, "sample.xlsx").getAbsolutePath());
XSSFWorkbook workbook = new XSSFWorkbook(_ssSampels.openResourceAsStream("sample.xlsx"));
assertEquals(3, workbook.getNumberOfSheets());
assertEquals("Sheet1", workbook.getSheetName(0));
Sheet sheet = workbook.getSheetAt(0);
@ -58,7 +50,7 @@ public class TestLoadSaveXSSF extends TestCase {
// TODO filename string hard coded in XSSFWorkbook constructor in order to make ant test-ooxml target be successful.
public void testLoadStyles() throws Exception {
XSSFWorkbook workbook = new XSSFWorkbook(new File(filename, "styles.xlsx").getAbsolutePath());
XSSFWorkbook workbook = new XSSFWorkbook(_ssSampels.openResourceAsStream("styles.xlsx"));
Sheet sheet = workbook.getSheetAt(0);
Row row = sheet.getRow(0);
Cell cell = row.getCell((short) 0);
@ -68,7 +60,7 @@ public class TestLoadSaveXSSF extends TestCase {
// TODO filename string hard coded in XSSFWorkbook constructor in order to make ant test-ooxml target be successful.
public void testLoadPictures() throws Exception {
XSSFWorkbook workbook = new XSSFWorkbook(new File(filename, "picture.xlsx").getAbsolutePath());
XSSFWorkbook workbook = new XSSFWorkbook(_ssSampels.openResourceAsStream("picture.xlsx"));
List<XSSFPictureData> pictures = workbook.getAllPictures();
assertEquals(1, pictures.size());
}

View File

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

View File

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

View File

@ -23,6 +23,7 @@ import java.io.IOException;
import java.io.InputStream;
import junit.framework.TestCase;
import org.apache.poi.POIDataSamples;
/**
* Class to test {@link HDFDocument} functionality
@ -30,19 +31,12 @@ import junit.framework.TestCase;
* @author Bob Otterberg
*/
public final class TestHDFDocument extends TestCase {
private static final POIDataSamples _samples = POIDataSamples.getDocumentInstance();
public void testStopJUnitComplainintAboutNoTests() {
// TODO - fix these junits
}
private static InputStream openSample(String sampleFileName) {
String fullPathName = System.getProperty("HDF.testdata.path") + "/" + sampleFileName;
try {
return new FileInputStream(System.getProperty("HDF.testdata.path"));
} catch (FileNotFoundException e) {
throw new RuntimeException("Sample HDF file '" + fullPathName + "' was not found.");
}
}
/**
* OBJECTIVE: Test that HDF can read an empty document (empty.doc).<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>
*/
public void fixme_testEmpty() throws IOException {
InputStream stream = openSample("empty.doc");
InputStream stream = _samples.openResourceAsStream("empty.doc");
new HDFDocument(stream);
}
@ -61,7 +55,7 @@ public final class TestHDFDocument extends TestCase {
* in the document in their known positions.<P>
*/
public void fixme_testSimple() throws IOException {
InputStream stream = openSample("simple.doc");
InputStream stream = _samples.openResourceAsStream("simple.doc");
new HDFDocument(stream);
}
@ -73,7 +67,7 @@ public final class TestHDFDocument extends TestCase {
*
*/
public void fixme_testSimpleList() throws IOException {
InputStream stream = openSample("simple-list.doc");
InputStream stream = _samples.openResourceAsStream("simple-list.doc");
new HDFDocument(stream);
}
@ -84,7 +78,7 @@ public final class TestHDFDocument extends TestCase {
* in the document in their known positions.<P>
*/
public void fixme_testSimpleTable() throws IOException {
InputStream stream = openSample("simple-table.doc");
InputStream stream = _samples.openResourceAsStream("simple-table.doc");
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.TrailerStream;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.POIDataSamples;
import junit.framework.TestCase;
public final class TestHDGFCore extends TestCase {
private static POIDataSamples _dgTests = POIDataSamples.getDiagramInstance();
private POIFSFileSystem fs;
private String dirname;
private String filename;
protected void setUp() throws Exception {
dirname = System.getProperty("HDGF.testdata.path");
filename = dirname + "/Test_Visio-Some_Random_Text.vsd";
fs = new POIFSFileSystem(new FileInputStream(filename));
fs = new POIFSFileSystem(_dgTests.openResourceAsStream("Test_Visio-Some_Random_Text.vsd"));
}
public void testCreate() throws Exception {
@ -68,8 +67,7 @@ public final class TestHDGFCore extends TestCase {
* appears to have a negative chunk length
*/
public void DISABLEDtestNegativeChunkLength() throws Exception {
filename = dirname + "/NegativeChunkLength.vsd";
fs = new POIFSFileSystem(new FileInputStream(filename));
fs = new POIFSFileSystem(_dgTests.openResourceAsStream("NegativeChunkLength.vsd"));
HDGFDiagram hdgf = new HDGFDiagram(fs);
assertNotNull(hdgf);

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -21,6 +21,7 @@ package org.apache.poi.hslf;
import junit.framework.TestCase;
import org.apache.poi.hslf.exceptions.EncryptedPowerPointFileException;
import org.apache.poi.POIDataSamples;
/**
* Tests that HSLFSlideShow does the right thing with an encrypted file
@ -28,48 +29,31 @@ import org.apache.poi.hslf.exceptions.EncryptedPowerPointFileException;
* @author Nick Burch (nick at torchbox dot com)
*/
public final class TestEncryptedFile extends TestCase {
// A non encrypted file
private String ss_ne;
// An encrypted file, with encrypted properties
private String ss_e;
// An encrypted file, without encrypted properties
private String ss_np_e;
// An encrypted file, with a 56 bit key
private String ss_56_e;
public TestEncryptedFile() {
String dirname = System.getProperty("HSLF.testdata.path");
ss_ne = dirname + "/basic_test_ppt_file.ppt";
ss_e = dirname + "/Password_Protected-hello.ppt";
ss_np_e = dirname + "/Password_Protected-np-hello.ppt";
ss_56_e = dirname + "/Password_Protected-56-hello.ppt";
}
private static POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
public void testLoadNonEncrypted() throws Exception {
HSLFSlideShow hss = new HSLFSlideShow(ss_ne);
HSLFSlideShow hss = new HSLFSlideShow(slTests.openResourceAsStream("basic_test_ppt_file.ppt"));
assertNotNull(hss);
}
public void testLoadEncrypted() throws Exception {
try {
new HSLFSlideShow(ss_e);
new HSLFSlideShow(slTests.openResourceAsStream("Password_Protected-hello.ppt"));
fail();
} catch(EncryptedPowerPointFileException e) {
// Good
}
try {
new HSLFSlideShow(ss_np_e);
new HSLFSlideShow(slTests.openResourceAsStream("Password_Protected-np-hello.ppt"));
fail();
} catch(EncryptedPowerPointFileException e) {
// Good
}
try {
new HSLFSlideShow(ss_56_e);
new HSLFSlideShow(slTests.openResourceAsStream("Password_Protected-56-hello.ppt"));
fail();
} catch(EncryptedPowerPointFileException e) {
// Good

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -24,6 +24,7 @@ import java.awt.*;
import org.apache.poi.hslf.usermodel.SlideShow;
import org.apache.poi.hslf.HSLFSlideShow;
import org.apache.poi.POIDataSamples;
/**
* Test <code>Fill</code> object.
@ -31,6 +32,7 @@ import org.apache.poi.hslf.HSLFSlideShow;
* @author Yegor Kozlov
*/
public final class TestBackground extends TestCase {
private static POIDataSamples _slTests = POIDataSamples.getSlideShowInstance();
/**
* Default background for slide, shape and slide master.
@ -52,7 +54,7 @@ public final class TestBackground extends TestCase {
* Read fill information from an reference ppt file
*/
public void testReadBackground() throws Exception {
SlideShow ppt = new SlideShow(new HSLFSlideShow(System.getProperty("HSLF.testdata.path") + "/backgrounds.ppt"));
SlideShow ppt = new SlideShow(_slTests.openResourceAsStream("backgrounds.ppt"));
Fill fill;
Shape shape;
@ -93,7 +95,7 @@ public final class TestBackground extends TestCase {
slide = ppt.createSlide();
slide.setFollowMasterBackground(false);
fill = slide.getBackground().getFill();
idx = ppt.addPicture(new File(System.getProperty("HSLF.testdata.path") + "/tomcat.png"), Picture.PNG);
idx = ppt.addPicture(_slTests.readFile("tomcat.png"), Picture.PNG);
fill.setFillType(Fill.FILL_PICTURE);
fill.setPictureData(idx);
@ -107,7 +109,7 @@ public final class TestBackground extends TestCase {
slide = ppt.createSlide();
slide.setFollowMasterBackground(false);
fill = slide.getBackground().getFill();
idx = ppt.addPicture(new File(System.getProperty("HSLF.testdata.path") + "/tomcat.png"), Picture.PNG);
idx = ppt.addPicture(_slTests.readFile("tomcat.png"), Picture.PNG);
fill.setFillType(Fill.FILL_PATTERN);
fill.setPictureData(idx);
fill.setBackgroundColor(Color.green);
@ -123,7 +125,7 @@ public final class TestBackground extends TestCase {
slide = ppt.createSlide();
slide.setFollowMasterBackground(false);
fill = slide.getBackground().getFill();
idx = ppt.addPicture(new File(System.getProperty("HSLF.testdata.path") + "/tomcat.png"), Picture.PNG);
idx = ppt.addPicture(_slTests.readFile("tomcat.png"), Picture.PNG);
fill.setFillType(Fill.FILL_TEXTURE);
fill.setPictureData(idx);
@ -131,7 +133,7 @@ public final class TestBackground extends TestCase {
shape.setAnchor(new java.awt.Rectangle(100, 100, 200, 200));
fill = shape.getFill();
fill.setFillType(Fill.FILL_PICTURE);
idx = ppt.addPicture(new File(System.getProperty("HSLF.testdata.path") + "/clock.jpg"), Picture.JPEG);
idx = ppt.addPicture(_slTests.readFile("clock.jpg"), Picture.JPEG);
fill.setPictureData(idx);
slide.addShape(shape);

View File

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

View File

@ -19,10 +19,8 @@ package org.apache.poi.hslf.model;
import junit.framework.TestCase;
import java.io.FileInputStream;
import java.io.File;
import org.apache.poi.hslf.usermodel.SlideShow;
import org.apache.poi.POIDataSamples;
/**
* Test Hyperlink.
@ -30,12 +28,10 @@ import org.apache.poi.hslf.usermodel.SlideShow;
* @author Yegor Kozlov
*/
public final class TestHyperlink extends TestCase {
protected String cwd = System.getProperty("HSLF.testdata.path");
private static POIDataSamples _slTests = POIDataSamples.getSlideShowInstance();
public void testTextRunHyperlinks() throws Exception {
FileInputStream is = new FileInputStream(new File(cwd, "WithLinks.ppt"));
SlideShow ppt = new SlideShow(is);
is.close();
SlideShow ppt = new SlideShow(_slTests.openResourceAsStream("WithLinks.ppt"));
TextRun[] run;
Slide slide;

View File

@ -20,11 +20,11 @@ package org.apache.poi.hslf.model;
import java.awt.geom.Rectangle2D;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import junit.framework.TestCase;
import org.apache.poi.hslf.usermodel.SlideShow;
import org.apache.poi.POIDataSamples;
/**
* Test <code>MovieShape</code> object.
@ -33,16 +33,16 @@ import org.apache.poi.hslf.usermodel.SlideShow;
*/
public final class TestMovieShape extends TestCase {
protected String cwd = System.getProperty("HSLF.testdata.path");
private static POIDataSamples _slTests = POIDataSamples.getSlideShowInstance();
public void testCreate() throws Exception {
SlideShow ppt = new SlideShow();
Slide slide = ppt.createSlide();
String path = cwd + "/test-movie.mpg";
String path = "/test-movie.mpg";
int movieIdx = ppt.addMovie(path, MovieShape.MOVIE_MPEG);
int thumbnailIdx = ppt.addPicture(new File(cwd, "tomcat.png"), Picture.PNG);
int thumbnailIdx = ppt.addPicture(_slTests.readFile("tomcat.png"), Picture.PNG);
MovieShape shape = new MovieShape(movieIdx, thumbnailIdx);
shape.setAnchor(new Rectangle2D.Float(300,225,120,90));

View File

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

View File

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

View File

@ -20,13 +20,13 @@ package org.apache.poi.hslf.model;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.image.BufferedImage;
import java.io.File;
import junit.framework.TestCase;
import org.apache.poi.ddf.EscherBSERecord;
import org.apache.poi.hslf.usermodel.PictureData;
import org.apache.poi.hslf.usermodel.SlideShow;
import org.apache.poi.POIDataSamples;
/**
* Test Picture shape.
@ -34,6 +34,7 @@ import org.apache.poi.hslf.usermodel.SlideShow;
* @author Yegor Kozlov
*/
public final class TestPicture extends TestCase {
private static POIDataSamples _slTests = POIDataSamples.getSlideShowInstance();
/**
* Test that the reference count of a blip is incremented every time the picture is inserted.
@ -41,14 +42,13 @@ public final class TestPicture extends TestCase {
*
*/
public void testMultiplePictures() throws Exception {
String cwd = System.getProperty("HSLF.testdata.path");
SlideShow ppt = new SlideShow();
Slide s = ppt.createSlide();
Slide s2 = ppt.createSlide();
Slide s3 = ppt.createSlide();
int idx = ppt.addPicture(new File(cwd, "clock.jpg"), Picture.JPEG);
int idx = ppt.addPicture(_slTests.readFile("clock.jpg"), Picture.JPEG);
Picture pict = new Picture(idx);
Picture pict2 = new Picture(idx);
Picture pict3 = new Picture(idx);

View File

@ -36,10 +36,6 @@ public final class TestSetBoldItalic extends TestCase {
* and set some of the style attributes
*/
public void testTextBoxWrite() throws Exception {
//String dirname = System.getProperty("HSLF.testdata.path");
//String filename = dirname + "/with_textbox.ppt";
//new SlideShow(new HSLFSlideShow(filename));
SlideShow ppt = new SlideShow();
Slide sl = ppt.createSlide();
RichTextRun rt;

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

View File

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

View File

@ -23,6 +23,7 @@ import junit.framework.TestCase;
import org.apache.poi.hslf.HSLFSlideShow;
import org.apache.poi.hslf.record.SlideAtom;
import org.apache.poi.hslf.usermodel.SlideShow;
import org.apache.poi.POIDataSamples;
/**
* Tests that changing a slide's idea of what notes sheet is its works right
@ -34,9 +35,8 @@ public final class TestSlideChangeNotes extends TestCase {
private SlideShow ss;
public TestSlideChangeNotes() throws Exception {
String dirname = System.getProperty("HSLF.testdata.path");
String filename = dirname + "/basic_test_ppt_file.ppt";
HSLFSlideShow hss = new HSLFSlideShow(filename);
POIDataSamples _slTests = POIDataSamples.getSlideShowInstance();
HSLFSlideShow hss = new HSLFSlideShow(_slTests.openResourceAsStream("basic_test_ppt_file.ppt"));
ss = new SlideShow(hss);
}

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

View File

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

View File

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

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -17,14 +17,13 @@
package org.apache.poi.hslf.record;
import java.io.File;
import java.io.FileInputStream;
import java.util.Arrays;
import junit.framework.AssertionFailedError;
import junit.framework.TestCase;
import org.apache.poi.hslf.usermodel.SlideShow;
import org.apache.poi.POIDataSamples;
/**
* 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 void testRealFile() throws Exception {
String cwd = System.getProperty("HSLF.testdata.path");
FileInputStream is = new FileInputStream(new File(cwd, "sound.ppt"));
SlideShow ppt = new SlideShow(is);
is.close();
POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
SlideShow ppt = new SlideShow(slTests.openResourceAsStream("sound.ppt"));
// Get the document
Document doc = ppt.getDocumentRecord();
@ -71,13 +69,7 @@ public final class TestSound extends TestCase {
assertEquals(".WAV", sound.getSoundType());
assertNotNull(sound.getSoundData());
File f = new File(cwd, "ringin.wav");
int length = (int) f.length();
byte[] ref_data = new byte[length];
is = new FileInputStream(f);
is.read(ref_data);
is.close();
byte[] ref_data = slTests.readFile("ringin.wav");
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.Document;
import org.apache.poi.hslf.model.*;
import org.apache.poi.POIDataSamples;
/**
* Tests that SlideShow adds additional sheets properly
@ -56,14 +57,12 @@ public final class TestAddingSlides extends TestCase {
hss_empty = HSLFSlideShow.create();
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(filename);
hss_one = new HSLFSlideShow(slTests.openResourceAsStream("Single_Coloured_Page.ppt"));
ss_one = new SlideShow(hss_one);
filename = dirname + "/basic_test_ppt_file.ppt";
hss_two = new HSLFSlideShow(filename);
hss_two = new HSLFSlideShow(slTests.openResourceAsStream("basic_test_ppt_file.ppt"));
ss_two = new SlideShow(hss_two);
}
@ -274,8 +273,8 @@ public final class TestAddingSlides extends TestCase {
public void test47261() throws Exception {
File src = new File(System.getProperty("HSLF.testdata.path"), "47261.ppt");
SlideShow ppt = new SlideShow(new FileInputStream(src));
POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
SlideShow ppt = new SlideShow(slTests.openResourceAsStream("47261.ppt"));
Slide[] slides = ppt.getSlides();
Document doc = ppt.getDocumentRecord();
assertNotNull(doc.getSlideSlideListWithText());

View File

@ -17,8 +17,6 @@
package org.apache.poi.hslf.usermodel;
import java.io.File;
import java.io.FileInputStream;
import java.util.ArrayList;
import java.util.HashMap;
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.TextShape;
import org.apache.poi.hslf.model.TitleMaster;
import org.apache.poi.POIDataSamples;
/**
* Testcases for bugs entered in bugzilla
@ -52,15 +51,13 @@ import org.apache.poi.hslf.model.TitleMaster;
* @author Yegor Kozlov
*/
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
*/
public void test41384() throws Exception {
FileInputStream is = new FileInputStream(new File(cwd, "41384.ppt"));
HSLFSlideShow hslf = new HSLFSlideShow(is);
is.close();
HSLFSlideShow hslf = new HSLFSlideShow(_slTests.openResourceAsStream("41384.ppt"));
SlideShow ppt = new SlideShow(hslf);
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
*/
public void test42474_1() throws Exception {
FileInputStream is = new FileInputStream(new File(cwd, "42474-1.ppt"));
HSLFSlideShow hslf = new HSLFSlideShow(is);
is.close();
HSLFSlideShow hslf = new HSLFSlideShow(_slTests.openResourceAsStream("42474-1.ppt"));
SlideShow ppt = new SlideShow(hslf);
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
*/
public void test42474_2() throws Exception {
FileInputStream is = new FileInputStream(new File(cwd, "42474-2.ppt"));
HSLFSlideShow hslf = new HSLFSlideShow(is);
is.close();
HSLFSlideShow hslf = new HSLFSlideShow(_slTests.openResourceAsStream("42474-2.ppt"));
SlideShow ppt = new SlideShow(hslf);
@ -140,9 +133,7 @@ public final class TestBugs extends TestCase {
* Bug 42485: All TextBoxes inside ShapeGroups have null TextRuns
*/
public void test42485 () throws Exception {
FileInputStream is = new FileInputStream(new File(cwd, "42485.ppt"));
HSLFSlideShow hslf = new HSLFSlideShow(is);
is.close();
HSLFSlideShow hslf = new HSLFSlideShow(_slTests.openResourceAsStream("42485.ppt"));
SlideShow ppt = new SlideShow(hslf);
Shape[] shape = ppt.getSlides()[0].getShapes();
@ -164,9 +155,7 @@ public final class TestBugs extends TestCase {
* Bug 42484: NullPointerException from ShapeGroup.getAnchor()
*/
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(is);
is.close();
HSLFSlideShow hslf = new HSLFSlideShow(_slTests.openResourceAsStream("42485.ppt"));
SlideShow ppt = new SlideShow(hslf);
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
*/
public void test41381() throws Exception {
FileInputStream is = new FileInputStream(new File(cwd, "alterman_security.ppt"));
HSLFSlideShow hslf = new HSLFSlideShow(is);
is.close();
HSLFSlideShow hslf = new HSLFSlideShow(_slTests.openResourceAsStream("alterman_security.ppt"));
SlideShow ppt = new SlideShow(hslf);
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
*/
public void test42486 () throws Exception {
FileInputStream is = new FileInputStream(new File(cwd, "42486.ppt"));
HSLFSlideShow hslf = new HSLFSlideShow(is);
is.close();
HSLFSlideShow hslf = new HSLFSlideShow(_slTests.openResourceAsStream("42486.ppt"));
SlideShow ppt = new SlideShow(hslf);
Slide[] slide = ppt.getSlides();
@ -225,9 +210,7 @@ public final class TestBugs extends TestCase {
* Bug 42524: NPE in Shape.getShapeType()
*/
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(is);
is.close();
HSLFSlideShow hslf = new HSLFSlideShow(_slTests.openResourceAsStream("42486.ppt"));
SlideShow ppt = new SlideShow(hslf);
//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()
*/
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(is);
is.close();
HSLFSlideShow hslf = new HSLFSlideShow(_slTests.openResourceAsStream("42520.ppt"));
SlideShow ppt = new SlideShow(hslf);
@ -292,9 +273,7 @@ public final class TestBugs extends TestCase {
* ( also fixed followup: getTextRuns() returns no text )
*/
public void test38256 () throws Exception {
FileInputStream is = new FileInputStream(new File(cwd, "38256.ppt"));
SlideShow ppt = new SlideShow(is);
is.close();
SlideShow ppt = new SlideShow(_slTests.openResourceAsStream("38256.ppt"));
assertTrue("No Exceptions while reading file", true);
@ -321,9 +300,7 @@ public final class TestBugs extends TestCase {
* ( also fixed followup: getTextRuns() returns no text )
*/
public void test43781 () throws Exception {
FileInputStream is = new FileInputStream(new File(cwd, "43781.ppt"));
SlideShow ppt = new SlideShow(is);
is.close();
SlideShow ppt = new SlideShow(_slTests.openResourceAsStream("43781.ppt"));
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
*/
public void test44296 () throws Exception {
FileInputStream is = new FileInputStream(new File(cwd, "44296.ppt"));
SlideShow ppt = new SlideShow(is);
is.close();
SlideShow ppt = new SlideShow(_slTests.openResourceAsStream("44296.ppt"));
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
*/
public void test44770() throws Exception {
FileInputStream is = new FileInputStream(new File(cwd, "44770.ppt"));
try {
new SlideShow(is);
new SlideShow(_slTests.openResourceAsStream("44770.ppt"));
} 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")) {
throw new AssertionFailedError("Identified bug 44770");
}
throw e;
}
is.close();
}
/**
* Bug 41071: Will not extract text from Powerpoint TextBoxes
*/
public void test41071() throws Exception {
FileInputStream is = new FileInputStream(new File(cwd, "41071.ppt"));
SlideShow ppt = new SlideShow(is);
is.close();
SlideShow ppt = new SlideShow(_slTests.openResourceAsStream("41071.ppt"));
Slide slide = ppt.getSlides()[0];
Shape[] sh = slide.getShapes();
@ -411,13 +382,11 @@ public final class TestBugs extends TestCase {
*/
public void test41711() throws Exception {
// New file is fine
FileInputStream is = new FileInputStream(new File(cwd, "SampleShow.ppt"));
SlideShow ppt = new SlideShow(is);
new SlideShow(_slTests.openResourceAsStream("SampleShow.ppt"));
// PowerPoint 95 gives an old format exception
is = new FileInputStream(new File(cwd, "PPT95.ppt"));
try {
new SlideShow(is);
new SlideShow(_slTests.openResourceAsStream("PPT95.ppt"));
fail("OldPowerPointFormatException should've been thrown");
} catch(OldPowerPointFormatException e) {
// Good

View File

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

View File

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

View File

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

View File

@ -20,6 +20,7 @@ package org.apache.poi.hslf.usermodel;
import org.apache.poi.hslf.*;
import org.apache.poi.hslf.blip.*;
import org.apache.poi.hslf.model.*;
import org.apache.poi.POIDataSamples;
import junit.framework.TestCase;
import java.io.*;
@ -31,12 +32,9 @@ import java.util.Arrays;
* @author Yegor Kozlov
*/
public final class TestPictures extends TestCase{
private static POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
protected File cwd;
public void setUp() {
cwd = new File(System.getProperty("HSLF.testdata.path"));
}
//protected File cwd;
/**
* Test read/write Macintosh PICT
@ -45,8 +43,8 @@ public final class TestPictures extends TestCase{
SlideShow ppt = new SlideShow();
Slide slide = ppt.createSlide();
File img = new File(cwd, "cow.pict");
int idx = ppt.addPicture(img, Picture.PICT);
byte[] src_bytes = slTests.readFile("cow.pict");
int idx = ppt.addPicture(src_bytes, Picture.PICT);
Picture pict = new Picture(idx);
assertEquals(idx, pict.getPictureIndex());
slide.addShape(pict);
@ -73,7 +71,6 @@ public final class TestPictures extends TestCase{
assertEquals(Picture.PICT, pictures[0].getType());
assertTrue(pictures[0] instanceof PICT);
//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();
assertEquals(src_bytes.length, ppt_bytes.length);
//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();
Slide slide = ppt.createSlide();
File img = new File(cwd, "santa.wmf");
int idx = ppt.addPicture(img, Picture.WMF);
byte[] src_bytes = slTests.readFile("santa.wmf");
int idx = ppt.addPicture(src_bytes, Picture.WMF);
Picture pict = new Picture(idx);
assertEquals(idx, pict.getPictureIndex());
slide.addShape(pict);
@ -119,7 +116,6 @@ public final class TestPictures extends TestCase{
assertEquals(Picture.WMF, pictures[0].getType());
assertTrue(pictures[0] instanceof WMF);
//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();
assertEquals(src_bytes.length, ppt_bytes.length);
//in WMF the first 22 bytes - is a metafile header
@ -137,8 +133,9 @@ public final class TestPictures extends TestCase{
SlideShow ppt = new SlideShow();
Slide slide = ppt.createSlide();
File img = new File(cwd, "wrench.emf");
int idx = ppt.addPicture(img, Picture.EMF);
byte[] src_bytes = slTests.readFile("wrench.emf");
int idx = ppt.addPicture(src_bytes, Picture.EMF);
Picture pict = new Picture(idx);
assertEquals(idx, pict.getPictureIndex());
slide.addShape(pict);
@ -165,7 +162,6 @@ public final class TestPictures extends TestCase{
assertEquals(Picture.EMF, pictures[0].getType());
assertTrue(pictures[0] instanceof EMF);
//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();
assertTrue(Arrays.equals(src_bytes, ppt_bytes));
}
@ -177,8 +173,8 @@ public final class TestPictures extends TestCase{
SlideShow ppt = new SlideShow();
Slide slide = ppt.createSlide();
File img = new File(cwd, "tomcat.png");
int idx = ppt.addPicture(img, Picture.PNG);
byte[] src_bytes = slTests.readFile("tomcat.png");
int idx = ppt.addPicture(src_bytes, Picture.PNG);
Picture pict = new Picture(idx);
assertEquals(idx, pict.getPictureIndex());
slide.addShape(pict);
@ -205,7 +201,6 @@ public final class TestPictures extends TestCase{
assertEquals(Picture.PNG, pictures[0].getType());
assertTrue(pictures[0] instanceof PNG);
//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();
assertTrue(Arrays.equals(src_bytes, ppt_bytes));
}
@ -217,8 +212,9 @@ public final class TestPictures extends TestCase{
SlideShow ppt = new SlideShow();
Slide slide = ppt.createSlide();
File img = new File(cwd, "clock.jpg");
int idx = ppt.addPicture(img, Picture.JPEG);
byte[] src_bytes = slTests.readFile("clock.jpg");
int idx = ppt.addPicture(src_bytes, Picture.JPEG);
Picture pict = new Picture(idx);
assertEquals(idx, pict.getPictureIndex());
slide.addShape(pict);
@ -245,7 +241,6 @@ public final class TestPictures extends TestCase{
assertEquals(Picture.JPEG, pictures[0].getType());
assertTrue(pictures[0] instanceof JPEG);
//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();
assertTrue(Arrays.equals(src_bytes, ppt_bytes));
}
@ -257,13 +252,8 @@ public final class TestPictures extends TestCase{
SlideShow ppt = new SlideShow();
Slide slide = ppt.createSlide();
File img = new File(cwd, "sci_cec.dib");
// Check we can read the test DIB image
assertTrue(img.exists());
// Add the image
int idx = ppt.addPicture(img, Picture.DIB);
byte[] src_bytes = slTests.readFile("sci_cec.dib");
int idx = ppt.addPicture(src_bytes, Picture.DIB);
Picture pict = new Picture(idx);
assertEquals(idx, pict.getPictureIndex());
slide.addShape(pict);
@ -290,22 +280,10 @@ public final class TestPictures extends TestCase{
assertEquals(Picture.DIB, pictures[0].getType());
assertTrue(pictures[0] instanceof DIB);
//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();
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
*/
@ -315,7 +293,7 @@ public final class TestPictures extends TestCase{
Picture pict;
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();
PictureData[] pictures = ppt.getPictureData();
assertEquals(5, pictures.length);
@ -325,7 +303,7 @@ public final class TestPictures extends TestCase{
assertTrue(pdata instanceof JPEG);
assertEquals(Picture.JPEG, pdata.getType());
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));
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);
assertEquals(Picture.PNG, pdata.getType());
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));
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);
assertEquals(Picture.WMF, pdata.getType());
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);
//ignore the first 22 bytes - it is a WMF metafile header
b1 = new byte[src_bytes.length-22];
@ -355,7 +333,7 @@ public final class TestPictures extends TestCase{
assertTrue(pdata instanceof PICT);
assertEquals(Picture.PICT, pdata.getType());
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);
//ignore the first 512 bytes - it is a MAC specific crap
b1 = new byte[src_bytes.length-512];
@ -369,7 +347,7 @@ public final class TestPictures extends TestCase{
assertTrue(pdata instanceof EMF);
assertEquals(Picture.EMF, pdata.getType());
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));
}
@ -379,7 +357,7 @@ public final class TestPictures extends TestCase{
* crazy pictures of type 0, we do our best.
*/
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
assertEquals(2, hslf.getPictures().length);
@ -409,7 +387,7 @@ public final class TestPictures extends TestCase{
}
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
assertEquals(2, hslf.getPictures().length);
@ -453,7 +431,7 @@ public final class TestPictures extends TestCase{
}
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];
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();
Slide slide = ppt.createSlide();
File img = new File(cwd, "tomcat.png");
byte[] img = slTests.readFile("tomcat.png");
int idx = ppt.addPicture(img, Picture.PNG);
Picture pict = new Picture(idx);
pict.setPictureName("tomcat.png");

View File

@ -24,6 +24,7 @@ import java.io.ByteArrayOutputStream;
import junit.framework.TestCase;
import org.apache.poi.hslf.*;
import org.apache.poi.hslf.model.*;
import org.apache.poi.POIDataSamples;
/**
* Tests that SlideShow can re-order slides properly
@ -47,18 +48,15 @@ public final class TestReOrderingSlides extends TestCase {
* Create/open the slideshows
*/
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(filename);
hss_one = new HSLFSlideShow(slTests.openResourceAsStream("Single_Coloured_Page.ppt"));
ss_one = new SlideShow(hss_one);
filename = dirname + "/basic_test_ppt_file.ppt";
hss_two = new HSLFSlideShow(filename);
hss_two = new HSLFSlideShow(slTests.openResourceAsStream("basic_test_ppt_file.ppt"));
ss_two = new SlideShow(hss_two);
filename = dirname + "/incorrect_slide_order.ppt";
hss_three = new HSLFSlideShow(filename);
hss_three = new HSLFSlideShow(slTests.openResourceAsStream("incorrect_slide_order.ppt"));
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.Record;
import org.apache.poi.hslf.record.RecordContainer;
import org.apache.poi.POIDataSamples;
/**
* Tests that the record setup done by SlideShow
@ -37,9 +38,8 @@ public final class TestRecordSetup extends TestCase {
private HSLFSlideShow hss;
public TestRecordSetup() throws Exception {
String dirname = System.getProperty("HSLF.testdata.path");
String filename = dirname + "/basic_test_ppt_file.ppt";
hss = new HSLFSlideShow(filename);
POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
hss = new HSLFSlideShow(slTests.openResourceAsStream("basic_test_ppt_file.ppt"));
ss = new SlideShow(hss);
}

View File

@ -19,7 +19,6 @@ package org.apache.poi.hslf.usermodel;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
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.record.Record;
import org.apache.poi.hslf.record.SlideListWithText;
import org.apache.poi.POIDataSamples;
/**
* 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)
*/
public final class TestRichTextRun extends TestCase {
private static POIDataSamples _slTests = POIDataSamples.getSlideShowInstance();
// SlideShow primed on the test data
private SlideShow ss;
private SlideShow ssRichA;
@ -50,27 +52,23 @@ public final class TestRichTextRun extends TestCase {
private static String filenameC;
protected void setUp() throws Exception {
String dirname = System.getProperty("HSLF.testdata.path");
// Basic (non rich) test file
String filename = dirname + "/basic_test_ppt_file.ppt";
hss = new HSLFSlideShow(filename);
hss = new HSLFSlideShow(_slTests.openResourceAsStream("basic_test_ppt_file.ppt"));
ss = new SlideShow(hss);
// Rich test file A
filename = dirname + "/Single_Coloured_Page.ppt";
hssRichA = new HSLFSlideShow(filename);
hssRichA = new HSLFSlideShow(_slTests.openResourceAsStream("Single_Coloured_Page.ppt"));
ssRichA = new SlideShow(hssRichA);
// Rich test file B
filename = dirname + "/Single_Coloured_Page_With_Fonts_and_Alignments.ppt";
hssRichB = new HSLFSlideShow(filename);
hssRichB = new HSLFSlideShow(_slTests.openResourceAsStream("Single_Coloured_Page_With_Fonts_and_Alignments.ppt"));
ssRichB = new SlideShow(hssRichB);
// Rich test file C - has paragraph styles that run out before
// the character ones do
filenameC = dirname + "/ParagraphStylesShorterThanCharStyles.ppt";
hssRichC = new HSLFSlideShow(filenameC);
filenameC = "ParagraphStylesShorterThanCharStyles.ppt";
hssRichC = new HSLFSlideShow(_slTests.openResourceAsStream(filenameC));
ssRichC = new SlideShow(hssRichC);
}
@ -375,7 +373,7 @@ public final class TestRichTextRun extends TestCase {
*/
private void assertMatchesSLTWC(SlideShow s) throws Exception {
// 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
SlideListWithText refSLWT = refC.getDocumentRecord().getSlideListWithTexts()[1];
@ -449,7 +447,7 @@ if(false) {
}
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();
for (int i = 0; i < sl.length; i++) {
TextRun[] txt = sl[i].getTextRuns();
@ -465,9 +463,7 @@ if(false) {
}
public void testReadParagraphStyles() throws Exception {
FileInputStream is = new FileInputStream(new File(System.getProperty("HSLF.testdata.path"), "bullets.ppt"));
SlideShow ppt = new SlideShow(is);
is.close();
SlideShow ppt = new SlideShow(_slTests.openResourceAsStream("bullets.ppt"));
assertTrue("No Exceptions while reading file", true);
RichTextRun rt;
@ -560,9 +556,7 @@ if(false) {
}
public void testAddText() throws Exception {
FileInputStream is = new FileInputStream(new File(System.getProperty("HSLF.testdata.path"), "bullets.ppt"));
SlideShow ppt = new SlideShow(is);
is.close();
SlideShow ppt = new SlideShow(_slTests.openResourceAsStream("bullets.ppt"));
assertTrue("No Exceptions while reading file", true);
RichTextRun rt;

View File

@ -21,6 +21,7 @@ package org.apache.poi.hslf.usermodel;
import junit.framework.TestCase;
import org.apache.poi.hslf.*;
import org.apache.poi.hslf.model.*;
import org.apache.poi.POIDataSamples;
/**
* 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;
public TestSheetText() throws Exception {
String dirname = System.getProperty("HSLF.testdata.path");
String filename = dirname + "/basic_test_ppt_file.ppt";
HSLFSlideShow hss = new HSLFSlideShow(filename);
POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
HSLFSlideShow hss = new HSLFSlideShow(slTests.openResourceAsStream("basic_test_ppt_file.ppt"));
ss = new SlideShow(hss);
}
@ -63,9 +63,8 @@ public final class TestSheetText extends TestCase {
* (Make sure we don't screw up / throw an exception etc)
*/
public void testWithShortTextPropData() throws Exception {
String dirname = System.getProperty("HSLF.testdata.path");
String filename = dirname + "/iisd_report.ppt";
HSLFSlideShow hss = new HSLFSlideShow(filename);
POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
HSLFSlideShow hss = new HSLFSlideShow(slTests.openResourceAsStream("iisd_report.ppt"));
SlideShow sss = new SlideShow(hss);
// 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 org.apache.poi.hslf.*;
import org.apache.poi.hslf.model.*;
import org.apache.poi.POIDataSamples;
/**
* 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)
*/
public final class TestSlideOrdering extends TestCase {
private static POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
// Simple slideshow, record order matches slide order
private SlideShow ssA;
// Complex slideshow, record order doesn't match slide order
private SlideShow ssB;
public TestSlideOrdering() throws Exception {
String dirname = System.getProperty("HSLF.testdata.path");
String filenameA = dirname + "/basic_test_ppt_file.ppt";
HSLFSlideShow hssA = new HSLFSlideShow(filenameA);
HSLFSlideShow hssA = new HSLFSlideShow(slTests.openResourceAsStream("basic_test_ppt_file.ppt"));
ssA = new SlideShow(hssA);
String filenameB = dirname + "/incorrect_slide_order.ppt";
HSLFSlideShow hssB = new HSLFSlideShow(filenameB);
HSLFSlideShow hssB = new HSLFSlideShow(slTests.openResourceAsStream("incorrect_slide_order.ppt"));
ssB = new SlideShow(hssB);
}
@ -85,7 +84,9 @@ public final class TestSlideOrdering extends TestCase {
* array of reference slide titles
*/
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();
assertEquals(titles.length, slide.length);
@ -96,25 +97,23 @@ public final class TestSlideOrdering extends TestCase {
}
public void testTitles() throws Exception {
String dirname = System.getProperty("HSLF.testdata.path");
assertSlideOrdering(dirname + "/basic_test_ppt_file.ppt", new String[] {
assertSlideOrdering("basic_test_ppt_file.ppt", new String[] {
"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" });
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" });
assertSlideOrdering(dirname + "/Single_Coloured_Page.ppt",
assertSlideOrdering("Single_Coloured_Page.ppt",
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" });
assertSlideOrdering(
dirname + "/ParagraphStylesShorterThanCharStyles.ppt",
"ParagraphStylesShorterThanCharStyles.ppt",
new String[] {
"ROMANCE: AN ANALYSIS",
"AGENDA",

View File

@ -17,11 +17,10 @@
package org.apache.poi.hslf.usermodel;
import java.io.File;
import java.io.FileInputStream;
import java.util.Arrays;
import junit.framework.TestCase;
import org.apache.poi.POIDataSamples;
/**
* Test reading sound data from a ppt
@ -29,28 +28,16 @@ import junit.framework.TestCase;
* @author Yegor Kozlov
*/
public final class TestSoundData extends TestCase{
protected File cwd;
public void setUp() {
cwd = new File(System.getProperty("HSLF.testdata.path"));
}
private static POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
/**
* Read a reference sound file from disk and compare it from the data extracted from the slide show
*/
public void testSounds() throws Exception {
//read the reference sound file
File f = new File(cwd, "ringin.wav");
int length = (int)f.length();
byte[] ref_data = new byte[length];
FileInputStream is = new FileInputStream(f);
is.read(ref_data);
is.close();
byte[] ref_data = slTests.readFile("ringin.wav");
is = new FileInputStream(new File(cwd, "sound.ppt"));
SlideShow ppt = new SlideShow(is);
is.close();
SlideShow ppt = new SlideShow(slTests.openResourceAsStream("sound.ppt"));
SoundData[] sound = ppt.getSoundData();
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.exceptions.ChunkNotFoundException;
import org.apache.poi.POIDataSamples;
import junit.framework.TestCase;
@ -38,8 +39,8 @@ public final class TestBlankFileRead extends TestCase {
* Initialize this test, load up the blank.msg mapi message.
*/
public TestBlankFileRead() throws IOException {
String dirname = System.getProperty("HSMF.testdata.path");
this.mapiMessage = new MAPIMessage(dirname + "/blank.msg");
POIDataSamples samples = POIDataSamples.getHSMFInstance();
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.exceptions.ChunkNotFoundException;
import org.apache.poi.POIDataSamples;
/**
* Tests to verify that we can read attachments from msg file
@ -42,8 +43,8 @@ public class TestFileWithAttachmentsRead extends TestCase {
* @throws Exception
*/
public TestFileWithAttachmentsRead() throws IOException {
String dirname = System.getProperty("HSMF.testdata.path");
this.mapiMessage = new MAPIMessage(dirname + "/attachment_test_msg.msg");
POIDataSamples samples = POIDataSamples.getHSMFInstance();
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.exceptions.ChunkNotFoundException;
import org.apache.poi.POIDataSamples;
import junit.framework.TestCase;
@ -35,8 +36,8 @@ private MAPIMessage mapiMessage;
* @throws Exception
*/
public TestOutlook30FileRead() throws IOException {
String dirname = System.getProperty("HSMF.testdata.path");
this.mapiMessage = new MAPIMessage(dirname + "/outlook_30_msg.msg");
POIDataSamples samples = POIDataSamples.getHSMFInstance();
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.exceptions.ChunkNotFoundException;
import org.apache.poi.POIDataSamples;
import junit.framework.TestCase;
@ -38,8 +39,8 @@ private MAPIMessage mapiMessage;
* @throws Exception
*/
public TestSimpleFileRead() throws IOException {
String dirname = System.getProperty("HSMF.testdata.path");
this.mapiMessage = new MAPIMessage(dirname + "/simple_test_msg.msg");
POIDataSamples samples = POIDataSamples.getHSMFInstance();
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.poifs.filesystem.DocumentEntry;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.POIDataSamples;
public final class HWPFDocFixture
@ -38,7 +39,7 @@ public final class HWPFDocFixture
try
{
POIFSFileSystem filesystem = new POIFSFileSystem(
HWPFTestDataSamples.openSampleFileStream("test.doc"));
POIDataSamples.getDocumentInstance().openResourceAsStream("test.doc"));
DocumentEntry documentProps =
(DocumentEntry) filesystem.getRoot().getEntry("WordDocument");

View File

@ -20,29 +20,12 @@ import org.apache.poi.POIDataSamples;
import java.io.*;
public class HWPFTestDataSamples extends POIDataSamples {
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 class HWPFTestDataSamples {
public static HWPFDocument openSampleFile(String sampleFileName) {
try {
return new HWPFDocument(_inst.openResourceAsStream(sampleFileName));
InputStream is = POIDataSamples.getDocumentInstance().openResourceAsStream(sampleFileName);
return new HWPFDocument(is);
} catch (IOException 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.usermodel.Picture;
import org.apache.poi.POIDataSamples;
/**
* Test picture support in HWPF
@ -154,6 +155,6 @@ public final class TestHWPFPictures extends TestCase {
}
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.poifs.filesystem.DirectoryNode;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.POIDataSamples;
import java.io.FileInputStream;
@ -65,17 +66,16 @@ public final class TestWordExtractor extends TestCase {
private String filename6;
protected void setUp() throws Exception {
String pdirname = System.getProperty("POIFS.testdata.path");
String filename = "test2.doc";
String filename2 = "test.doc";
filename3 = pdirname + "/excel_with_embeded.xls";
filename3 = "excel_with_embeded.xls";
filename4 = "ThreeColHeadFoot.doc";
filename5 = "HeaderFooterUnicode.doc";
filename6 = "footnote.doc";
extractor = new WordExtractor(HWPFTestDataSamples.openSampleFileStream(filename));
extractor2 = new WordExtractor(HWPFTestDataSamples.openSampleFileStream(filename2));
POIDataSamples docTests = POIDataSamples.getDocumentInstance();
extractor = new WordExtractor(docTests.openResourceAsStream(filename));
extractor2 = new WordExtractor(docTests.openResourceAsStream(filename2));
// Build splat'd out text version
for(int i=0; i<p_text1.length; i++) {
@ -123,7 +123,7 @@ public final class TestWordExtractor extends TestCase {
* @throws Exception
*/
public void testExtractFromEmbeded() throws Exception {
POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(filename3));
POIFSFileSystem fs = new POIFSFileSystem(POIDataSamples.getSpreadSheetInstance().openResourceAsStream(filename3));
HWPFDocument doc;
WordExtractor extractor3;

View File

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

View File

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

View File

@ -20,26 +20,89 @@ import java.io.*;
/**
* 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;
/** <code>true</code> if standard system propery is not set,
* but the data is available on the test runtime classpath */
private boolean _sampleDataIsAvaliableOnClassPath;
private String _testDataDir;
private String _moduleDir;
/**
*
* @param dir the name of the system property that defines path to the test files
* @param classPathTestFile the name of the test file to check if resources are available from the classpath
* @param moduleDir the name of the directory containing the test files
*/
public POIDataSamples(String dir, String classPathTestFile){
_testDataDir = dir;
initialise(classPathTestFile);
private POIDataSamples(String moduleDir){
_moduleDir = moduleDir;
initialise();
}
public static POIDataSamples getSpreadSheetInstance(){
if(_instSpreadsheet == null) _instSpreadsheet = new POIDataSamples("spreadsheet");
return _instSpreadsheet;
}
public static POIDataSamples getDocumentInstance(){
if(_instDocument == null) _instDocument = new POIDataSamples("document");
return _instDocument;
}
public static POIDataSamples getSlideShowInstance(){
if(_instSlideshow == null) _instSlideshow = new POIDataSamples("slideshow");
return _instSlideshow;
}
public static POIDataSamples getDiagramInstance(){
if(_instOpenxml4j == null) _instOpenxml4j = new POIDataSamples("diagram");
return _instOpenxml4j;
}
public static POIDataSamples getOpenXML4JInstance(){
if(_instDiagram == null) _instDiagram = new POIDataSamples("openxml4j");
return _instDiagram;
}
public static POIDataSamples getPOIFSInstance(){
if(_instPOIFS == null) _instPOIFS = new POIDataSamples("poifs");
return _instPOIFS;
}
public static POIDataSamples getDDFInstance(){
if(_instDDF == null) _instDDF = new POIDataSamples("ddf");
return _instDDF;
}
public static POIDataSamples getHPSFInstance(){
if(_instHPSF == null) _instHPSF = new POIDataSamples("hpsf");
return _instHPSF;
}
public static POIDataSamples getPublisherInstance(){
if(_instHPBF == null) _instHPBF = new POIDataSamples("publisher");
return _instHPBF;
}
public static POIDataSamples getHSMFInstance(){
if(_instHSMF == null) _instHSMF = new POIDataSamples("hsmf");
return _instHSMF;
}
/**
* Opens a sample file from the test data directory
*
@ -60,24 +123,11 @@ public abstract class POIDataSamples {
}
if (_resolvedDataDir == null) {
throw new RuntimeException("Must set system property '"
+ _testDataDir
+ TEST_PROPERTY
+ "' properly before running tests");
}
File f = new File(_resolvedDataDir, sampleFileName);
if (!f.exists()) {
throw new RuntimeException("Sample file '" + sampleFileName
+ "' not found in data dir '" + _resolvedDataDir.getAbsolutePath() + "'");
}
try {
if(!sampleFileName.equals(f.getCanonicalFile().getName())){
throw new RuntimeException("File name is case-sensitive: requested '" + sampleFileName
+ "' but actual file is '" + f.getCanonicalFile().getName() + "'");
}
} catch (IOException e){
throw new RuntimeException(e);
}
File f = getFile(sampleFileName);
try {
return new FileInputStream(f);
} catch (FileNotFoundException e) {
@ -87,13 +137,32 @@ public abstract class POIDataSamples {
/**
*
* @param classPathTest test file to check if the resources are avaiable from the classpath
* @param sampleFileName the name of the test file
* @return
* @throws RuntimeException if the file was not found
*/
private void initialise(String classPathTest) {
String dataDirName = System.getProperty(_testDataDir);
public File getFile(String sampleFileName) {
File f = new File(_resolvedDataDir, sampleFileName);
if (!f.exists()) {
throw new RuntimeException("Sample file '" + sampleFileName
+ "' not found in data dir '" + _resolvedDataDir.getAbsolutePath() + "'");
}
try {
if(sampleFileName.length() > 0 && !sampleFileName.equals(f.getCanonicalFile().getName())){
throw new RuntimeException("File name is case-sensitive: requested '" + sampleFileName
+ "' but actual file is '" + f.getCanonicalFile().getName() + "'");
}
} catch (IOException e){
throw new RuntimeException(e);
}
return f;
}
private void initialise() {
String dataDirName = System.getProperty(TEST_PROPERTY);
if (dataDirName == null) {
// check to see if we can just get the resources from the classpath
InputStream is = openClasspathResource(classPathTest);
InputStream is = openClasspathResource("");
if (is != null) {
try {
is.close(); // be nice
@ -104,14 +173,12 @@ public abstract class POIDataSamples {
return;
}
throw new RuntimeException("Must set system property '"
+ _testDataDir + "' before running tests");
throw new RuntimeException("Must set system property '" +
TEST_PROPERTY + "' before running tests");
}
File dataDir = new File(dataDirName);
File dataDir = new File(dataDirName, _moduleDir);
if (!dataDir.exists()) {
throw new RuntimeException("Data dir '" + dataDirName
+ "' specified by system property '" + _testDataDir
+ "' does not exist");
throw new RuntimeException("Data dir '" + _moduleDir + " does not exist");
}
// convert to canonical file, to make any subsequent error messages
// clearer.
@ -129,7 +196,7 @@ public abstract class POIDataSamples {
* @return <code>null</code> if the sample file is not deployed on the classpath.
*/
private InputStream openClasspathResource(String sampleFileName) {
return getClass().getResourceAsStream("data/" + sampleFileName);
return getClass().getResourceAsStream("/" + _moduleDir + "/" + sampleFileName);
}
private static final class NonSeekableInputStream extends InputStream {

View File

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

View File

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

View File

@ -17,6 +17,8 @@
package org.apache.poi.hpsf.basic;
import org.apache.poi.POIDataSamples;
import java.io.File;
import java.io.FileFilter;
import java.util.logging.Logger;
@ -30,6 +32,7 @@ import java.util.logging.Logger;
* href="mailto:klute@rainer-klute.de">&lt;klute@rainer-klute.de&gt;</a>
*/
public class AllDataFilesTester {
private static final POIDataSamples _samples = POIDataSamples.getHPSFInstance();
/**
* <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
{
final String dataDirName = System.getProperty("HPSF.testdata.path");
final File dataDir = new File(dataDirName);
POIDataSamples _samples = POIDataSamples.getHPSFInstance();
final File dataDir = _samples.getFile("");
final File[] docs = dataDir.listFiles(new FileFilter()
{
public boolean accept(final File file)

View File

@ -37,6 +37,7 @@ import org.apache.poi.hpsf.PropertySetFactory;
import org.apache.poi.hpsf.Section;
import org.apache.poi.hpsf.SummaryInformation;
import org.apache.poi.hpsf.wellknown.SectionIDMap;
import org.apache.poi.POIDataSamples;
/**
* <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 IOException if any other I/O exception occurs.
*/
public void setUp() throws FileNotFoundException, IOException
public void setUp() throws IOException
{
final File dataDir =
new File(System.getProperty("HPSF.testdata.path"));
final File data = new File(dataDir, POI_FS);
POIDataSamples samples = POIDataSamples.getHPSFInstance();
final File data = samples.getFile(POI_FS);
poiFiles = Util.readPOIFiles(data);
}

View File

@ -35,6 +35,7 @@ import org.apache.poi.hpsf.PropertySet;
import org.apache.poi.hpsf.PropertySetFactory;
import org.apache.poi.hpsf.SummaryInformation;
import org.apache.poi.hpsf.Variant;
import org.apache.poi.POIDataSamples;
/**
* <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
{
final File dataDir =
new File(System.getProperty("HPSF.testdata.path"));
final File data = new File(dataDir, POI_FS);
POIDataSamples samples = POIDataSamples.getHPSFInstance();
final File data = samples.getFile(POI_FS);
poiFiles = Util.readPOIFiles(data);
}

View File

@ -25,6 +25,7 @@ import java.io.InputStream;
import junit.framework.TestCase;
import org.apache.poi.hpsf.PropertySetFactory;
import org.apache.poi.POIDataSamples;
/**
* <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()
{
final File dataDir =
new File(System.getProperty("HPSF.testdata.path"));
POIDataSamples _samples = POIDataSamples.getHPSFInstance();
final File dataDir = _samples.getFile("");
final File[] fileList = dataDir.listFiles(new FileFilter()
{
public boolean accept(final File f)

View File

@ -32,6 +32,7 @@ import org.apache.poi.hpsf.PropertySet;
import org.apache.poi.hpsf.PropertySetFactory;
import org.apache.poi.hpsf.Section;
import org.apache.poi.hpsf.SummaryInformation;
import org.apache.poi.POIDataSamples;
/**
* <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
*/
protected void setUp() {
final File dataDir =
new File(System.getProperty("HPSF.testdata.path"));
data = new File(dataDir, POI_FS);
POIDataSamples samples = POIDataSamples.getHPSFInstance();
data = samples.getFile(POI_FS);
}

View File

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

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

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

View File

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

View File

@ -30,17 +30,9 @@ import org.apache.poi.hssf.usermodel.HSSFWorkbook;
*
* @author Josh Micich
*/
public final class HSSFTestDataSamples extends POIDataSamples {
public final class HSSFTestDataSamples {
private static final HSSFTestDataSamples _inst = new HSSFTestDataSamples("HSSF.testdata.path", "SampleSS.xls");
private HSSFTestDataSamples(String dir, String classPathTestFile){
super(dir, classPathTestFile);
}
public static POIDataSamples getInstance(){
return _inst;
}
private static final POIDataSamples _inst = POIDataSamples.getSpreadSheetInstance();
public static InputStream openSampleFileStream(String sampleFileName) {
return _inst.openResourceAsStream(sampleFileName);

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

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