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