aboutsummaryrefslogtreecommitdiffstats
path: root/src/scratchpad/testcases/org/apache/poi/hslf
diff options
context:
space:
mode:
authorAndreas Beeker <kiwiwings@apache.org>2017-05-31 14:10:18 +0000
committerAndreas Beeker <kiwiwings@apache.org>2017-05-31 14:10:18 +0000
commit90cb7589f293b8879225d2300a8ab09d0f4f1b72 (patch)
tree7be911ddccb4d41d4a15ece222eed8bc6718eb20 /src/scratchpad/testcases/org/apache/poi/hslf
parent217b2c2725535fbf133a23a6f19fc7695cbefb76 (diff)
downloadpoi-90cb7589f293b8879225d2300a8ab09d0f4f1b72.tar.gz
poi-90cb7589f293b8879225d2300a8ab09d0f4f1b72.zip
fix eclipse resource leak warnings
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1797043 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/scratchpad/testcases/org/apache/poi/hslf')
-rw-r--r--src/scratchpad/testcases/org/apache/poi/hslf/TestReWrite.java16
-rw-r--r--src/scratchpad/testcases/org/apache/poi/hslf/extractor/TestExtractor.java2
-rw-r--r--src/scratchpad/testcases/org/apache/poi/hslf/model/TestLine.java9
-rw-r--r--src/scratchpad/testcases/org/apache/poi/hslf/model/TestPPFont.java8
-rw-r--r--src/scratchpad/testcases/org/apache/poi/hslf/model/TestSlideMaster.java38
-rw-r--r--src/scratchpad/testcases/org/apache/poi/hslf/model/TestTextRunReWrite.java56
-rw-r--r--src/scratchpad/testcases/org/apache/poi/hslf/record/TestExHyperlink.java104
-rw-r--r--src/scratchpad/testcases/org/apache/poi/hslf/record/TestExObjList.java18
-rw-r--r--src/scratchpad/testcases/org/apache/poi/hslf/record/TestSound.java27
-rw-r--r--src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestFontRendering.java5
-rw-r--r--src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestNumberedList2.java22
-rw-r--r--src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestReOrderingSlides.java65
-rw-r--r--src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestRichTextRun.java4
13 files changed, 175 insertions, 199 deletions
diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/TestReWrite.java b/src/scratchpad/testcases/org/apache/poi/hslf/TestReWrite.java
index e54cc0cacc..cdcb89ec0d 100644
--- a/src/scratchpad/testcases/org/apache/poi/hslf/TestReWrite.java
+++ b/src/scratchpad/testcases/org/apache/poi/hslf/TestReWrite.java
@@ -101,15 +101,15 @@ public final class TestReWrite {
// Check all of them in turn
for (POIFSFileSystem npf : new POIFSFileSystem[] { npfS, npfF, npfRF }) {
// Check that the "PowerPoint Document" sections have the same size
- DocumentEntry oProps = (DocumentEntry)pfs.getRoot().getEntry("PowerPoint Document");
- DocumentEntry nProps = (DocumentEntry)npf.getRoot().getEntry("PowerPoint Document");
+ DocumentEntry oProps = (DocumentEntry)pfs.getRoot().getEntry(HSLFSlideShow.POWERPOINT_DOCUMENT);
+ DocumentEntry nProps = (DocumentEntry)npf.getRoot().getEntry(HSLFSlideShow.POWERPOINT_DOCUMENT);
assertEquals(oProps.getSize(),nProps.getSize());
// Check that they contain the same data
byte[] _oData = new byte[oProps.getSize()];
byte[] _nData = new byte[nProps.getSize()];
- pfs.createDocumentInputStream("PowerPoint Document").read(_oData);
- npf.createDocumentInputStream("PowerPoint Document").read(_nData);
+ pfs.createDocumentInputStream(HSLFSlideShow.POWERPOINT_DOCUMENT).read(_oData);
+ npf.createDocumentInputStream(HSLFSlideShow.POWERPOINT_DOCUMENT).read(_nData);
for(int i=0; i<_oData.length; i++) {
//System.out.println(i + "\t" + Integer.toHexString(i));
assertEquals(_oData[i], _nData[i]);
@@ -174,15 +174,15 @@ public final class TestReWrite {
POIFSFileSystem npfs = new POIFSFileSystem(bais);
// Check that the "PowerPoint Document" sections have the same size
- DocumentEntry oProps = (DocumentEntry)pfs.getRoot().getEntry("PowerPoint Document");
- DocumentEntry nProps = (DocumentEntry)npfs.getRoot().getEntry("PowerPoint Document");
+ DocumentEntry oProps = (DocumentEntry)pfs.getRoot().getEntry(HSLFSlideShow.POWERPOINT_DOCUMENT);
+ DocumentEntry nProps = (DocumentEntry)npfs.getRoot().getEntry(HSLFSlideShow.POWERPOINT_DOCUMENT);
assertEquals(oProps.getSize(),nProps.getSize());
// Check that they contain the same data
byte[] _oData = new byte[oProps.getSize()];
byte[] _nData = new byte[nProps.getSize()];
- pfs.createDocumentInputStream("PowerPoint Document").read(_oData);
- npfs.createDocumentInputStream("PowerPoint Document").read(_nData);
+ pfs.createDocumentInputStream(HSLFSlideShow.POWERPOINT_DOCUMENT).read(_oData);
+ npfs.createDocumentInputStream(HSLFSlideShow.POWERPOINT_DOCUMENT).read(_nData);
for(int i=0; i<_oData.length; i++) {
if(_oData[i] != _nData[i])
System.out.println(i + "\t" + Integer.toHexString(i));
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 da5b283b1d..281173e23f 100644
--- a/src/scratchpad/testcases/org/apache/poi/hslf/extractor/TestExtractor.java
+++ b/src/scratchpad/testcases/org/apache/poi/hslf/extractor/TestExtractor.java
@@ -191,7 +191,7 @@ public final class TestExtractor {
private PowerPointExtractor assertExtractFromEmbedded(DirectoryNode root, String entryName, String expected)
throws IOException {
DirectoryNode dir = (DirectoryNode)root.getEntry(entryName);
- assertTrue(dir.hasEntry("PowerPoint Document"));
+ assertTrue(dir.hasEntry(HSLFSlideShow.POWERPOINT_DOCUMENT));
// Check the first file
HSLFSlideShowImpl ppt = new HSLFSlideShowImpl(dir);
diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestLine.java b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestLine.java
index c601ca04b7..4643600e5b 100644
--- a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestLine.java
+++ b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestLine.java
@@ -18,23 +18,22 @@
package org.apache.poi.hslf.model;
import java.awt.Color;
+import java.io.IOException;
+import org.apache.poi.hslf.usermodel.HSLFLine;
import org.apache.poi.hslf.usermodel.HSLFSlide;
import org.apache.poi.hslf.usermodel.HSLFSlideShow;
-import org.apache.poi.hslf.usermodel.HSLFLine;
import org.apache.poi.sl.usermodel.StrokeStyle.LineCompound;
import org.apache.poi.sl.usermodel.StrokeStyle.LineDash;
import org.junit.Test;
/**
* Test Line shape.
- *
- * @author Yegor Kozlov
*/
public final class TestLine {
@Test
- public void testCreateLines() {
+ public void testCreateLines() throws IOException {
HSLFSlideShow ppt = new HSLFSlideShow();
HSLFSlide slide = ppt.createSlide();
@@ -127,5 +126,7 @@ public final class TestLine {
line.setLineCompound(LineCompound.DOUBLE);
line.setLineWidth(8.0);
slide.addShape(line);
+
+ ppt.close();
}
}
diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestPPFont.java b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestPPFont.java
index 4c69862c3b..2a1a6afa7e 100644
--- a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestPPFont.java
+++ b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestPPFont.java
@@ -19,19 +19,19 @@ package org.apache.poi.hslf.model;
import static org.junit.Assert.assertEquals;
+import java.io.IOException;
+
import org.apache.poi.hslf.usermodel.HSLFSlideShow;
import org.junit.Test;
/**
* Test adding fonts to the presenataion resources
- *
- * @author Yegor Kozlov
*/
public final class TestPPFont {
@Test
- public void testCreate() {
+ public void testCreate() throws IOException {
HSLFSlideShow ppt = new HSLFSlideShow();
assertEquals(1, ppt.getNumberOfFonts());
assertEquals("Arial", ppt.getFont(0).getFontName());
@@ -53,5 +53,7 @@ public final class TestPPFont {
assertEquals(PPFont.WINGDINGS.getFontName(), font3.getFontName());
assertEquals(PPFont.SYMBOL_CHARSET, font3.getCharSet());
assertEquals(PPFont.VARIABLE_PITCH, font3.getPitchAndFamily());
+
+ ppt.close();
}
}
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 23a3d156fa..b18683dddd 100644
--- a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestSlideMaster.java
+++ b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestSlideMaster.java
@@ -22,19 +22,25 @@ import static org.junit.Assert.assertTrue;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
+import java.io.IOException;
import java.util.List;
import org.apache.poi.POIDataSamples;
import org.apache.poi.hslf.model.textproperties.CharFlagsTextProp;
import org.apache.poi.hslf.record.Environment;
import org.apache.poi.hslf.record.TextHeaderAtom;
-import org.apache.poi.hslf.usermodel.*;
+import org.apache.poi.hslf.usermodel.HSLFMasterSheet;
+import org.apache.poi.hslf.usermodel.HSLFSlide;
+import org.apache.poi.hslf.usermodel.HSLFSlideMaster;
+import org.apache.poi.hslf.usermodel.HSLFSlideShow;
+import org.apache.poi.hslf.usermodel.HSLFSlideShowImpl;
+import org.apache.poi.hslf.usermodel.HSLFTextParagraph;
+import org.apache.poi.hslf.usermodel.HSLFTextRun;
+import org.apache.poi.hslf.usermodel.HSLFTitleMaster;
import org.junit.Test;
/**
* Tests for SlideMaster
- *
- * @author Yegor Kozlov
*/
public final class TestSlideMaster {
private static POIDataSamples _slTests = POIDataSamples.getSlideShowInstance();
@@ -44,7 +50,7 @@ public final class TestSlideMaster {
* Check we can read their attributes.
*/
@Test
- public void testSlideMaster() throws Exception {
+ public void testSlideMaster() throws IOException {
HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("slide_master.ppt"));
Environment env = ppt.getDocumentRecord().getEnvironment();
@@ -79,13 +85,15 @@ public final class TestSlideMaster {
int b2 = master.get(1).getStyleAttribute(TextHeaderAtom.BODY_TYPE, 0, "bullet.font", false).getValue();
assertEquals("Arial", env.getFontCollection().getFontWithId(b1));
assertEquals("Georgia", env.getFontCollection().getFontWithId(b2));
+
+ ppt.close();
}
/**
* Test we can read default text attributes for a title master sheet
*/
@Test
- public void testTitleMasterTextAttributes() throws Exception {
+ public void testTitleMasterTextAttributes() throws IOException {
HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("slide_master.ppt"));
List<HSLFTitleMaster> master = ppt.getTitleMasters();
assertEquals(1, master.size());
@@ -101,13 +109,15 @@ public final class TestSlideMaster {
assertEquals(true, prop2.getSubValue(CharFlagsTextProp.BOLD_IDX));
assertEquals(false, prop2.getSubValue(CharFlagsTextProp.ITALIC_IDX));
assertEquals(false, prop2.getSubValue(CharFlagsTextProp.UNDERLINE_IDX));
+
+ ppt.close();
}
/**
* Slide 3 has title layout and follows the TitleMaster. Verify that.
*/
@Test
- public void testTitleMaster() throws Exception {
+ public void testTitleMaster() throws IOException {
HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("slide_master.ppt"));
HSLFSlide slide = ppt.getSlides().get(2);
HSLFMasterSheet masterSheet = slide.getMasterSheet();
@@ -131,7 +141,9 @@ public final class TestSlideMaster {
}
}
+ ppt.close();
}
+
/**
* If a style attribute is not set ensure it is read from the master
*/
@@ -178,13 +190,14 @@ public final class TestSlideMaster {
}
}
+ ppt.close();
}
/**
* Check we can dynamically assign a slide master to a slide.
*/
@Test
- public void testChangeSlideMaster() throws Exception {
+ public void testChangeSlideMaster() throws IOException {
HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("slide_master.ppt"));
List<HSLFSlideMaster> master = ppt.getSlideMasters();
List<HSLFSlide> slide = ppt.getSlides();
@@ -212,6 +225,8 @@ public final class TestSlideMaster {
for (HSLFSlide s : slide) {
assertEquals(sheetNo, s.getMasterSheet()._getSheetNumber());
}
+
+ ppt.close();
}
/**
@@ -219,10 +234,10 @@ public final class TestSlideMaster {
* (typical for the "bullted body" placeholder)
*/
@Test
- public void testIndentation() throws Exception {
+ public void testIndentation() throws IOException {
HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("slide_master.ppt"));
HSLFSlide slide = ppt.getSlides().get(0);
-
+
for (List<HSLFTextParagraph> tparas : slide.getTextParagraphs()) {
HSLFTextParagraph tpara = tparas.get(0);
if (tpara.getRunType() == TextHeaderAtom.TITLE_TYPE){
@@ -238,7 +253,6 @@ public final class TestSlideMaster {
}
}
}
-
+ ppt.close();
}
-
-}
+} \ No newline at end of file
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 85070a3d51..d5343e1f03 100644
--- a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestTextRunReWrite.java
+++ b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestTextRunReWrite.java
@@ -17,14 +17,19 @@
package org.apache.poi.hslf.model;
+import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
+import java.io.IOException;
import java.util.List;
import org.apache.poi.POIDataSamples;
-import org.apache.poi.hslf.usermodel.*;
+import org.apache.poi.hslf.usermodel.HSLFSlideShow;
+import org.apache.poi.hslf.usermodel.HSLFTextParagraph;
+import org.apache.poi.hslf.usermodel.HSLFTextRun;
+import org.apache.poi.poifs.filesystem.DirectoryNode;
import org.apache.poi.poifs.filesystem.DocumentEntry;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.junit.Before;
@@ -34,16 +39,10 @@ import org.junit.Test;
* Tests that if we load something up, get a TextRun, set the text
* to be the same as it was before, and write it all back out again,
* that we don't break anything in the process.
- *
- * @author Nick Burch (nick at torchbox dot com)
*/
public final class TestTextRunReWrite {
// HSLFSlideShow primed on the test data
- private HSLFSlideShowImpl hss;
- // HSLFSlideShow primed on the test data
private HSLFSlideShow ss;
- // POIFS primed on the test data
- private POIFSFileSystem pfs;
/**
* Load up a test PPT file with rich data
@@ -52,13 +51,11 @@ public final class TestTextRunReWrite {
public void setUp() throws Exception {
POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
String filename = "Single_Coloured_Page_With_Fonts_and_Alignments.ppt";
- pfs = new POIFSFileSystem(slTests.openResourceAsStream(filename));
- hss = new HSLFSlideShowImpl(pfs);
- ss = new HSLFSlideShow(hss);
+ ss = new HSLFSlideShow(slTests.openResourceAsStream(filename));
}
@Test
- public void testWritesOutTheSameNonRich() throws Exception {
+ public void testWritesOutTheSameNonRich() throws IOException {
// Ensure the text lengths are as we'd expect to start with
assertEquals(1, ss.getSlides().size());
assertEquals(2, ss.getSlides().get(0).getTextParagraphs().size());
@@ -103,23 +100,24 @@ public final class TestTextRunReWrite {
POIFSFileSystem npfs = new POIFSFileSystem(bais);
// Check that the "PowerPoint Document" sections have the same size
- DocumentEntry oProps = (DocumentEntry)pfs.getRoot().getEntry("PowerPoint Document");
- DocumentEntry nProps = (DocumentEntry)npfs.getRoot().getEntry("PowerPoint Document");
+ DirectoryNode oDir = ss.getSlideShowImpl().getDirectory();
+
+ DocumentEntry oProps = (DocumentEntry)oDir.getEntry(HSLFSlideShow.POWERPOINT_DOCUMENT);
+ DocumentEntry nProps = (DocumentEntry)npfs.getRoot().getEntry(HSLFSlideShow.POWERPOINT_DOCUMENT);
assertEquals(oProps.getSize(),nProps.getSize());
// Check that they contain the same data
byte[] _oData = new byte[oProps.getSize()];
byte[] _nData = new byte[nProps.getSize()];
- pfs.createDocumentInputStream("PowerPoint Document").read(_oData);
- npfs.createDocumentInputStream("PowerPoint Document").read(_nData);
- for(int i=0; i<_oData.length; i++) {
-// System.out.println(i + "\t" + Integer.toHexString(i));
- assertEquals(_oData[i], _nData[i]);
- }
+ oDir.createDocumentInputStream(HSLFSlideShow.POWERPOINT_DOCUMENT).read(_oData);
+ npfs.createDocumentInputStream(HSLFSlideShow.POWERPOINT_DOCUMENT).read(_nData);
+ assertArrayEquals(_oData, _nData);
+
+ npfs.close();
}
@Test
- public void testWritesOutTheSameRich() throws Exception {
+ public void testWritesOutTheSameRich() throws IOException {
// Grab the first text run on the first sheet
List<HSLFTextParagraph> tr1 = ss.getSlides().get(0).getTextParagraphs().get(0);
@@ -160,18 +158,20 @@ public final class TestTextRunReWrite {
POIFSFileSystem npfs = new POIFSFileSystem(bais);
// Check that the "PowerPoint Document" sections have the same size
- DocumentEntry oProps = (DocumentEntry)pfs.getRoot().getEntry("PowerPoint Document");
- DocumentEntry nProps = (DocumentEntry)npfs.getRoot().getEntry("PowerPoint Document");
+ DirectoryNode oDir = ss.getSlideShowImpl().getDirectory();
+
+ DocumentEntry oProps = (DocumentEntry)oDir.getEntry(HSLFSlideShow.POWERPOINT_DOCUMENT);
+ DocumentEntry nProps = (DocumentEntry)npfs.getRoot().getEntry(HSLFSlideShow.POWERPOINT_DOCUMENT);
assertEquals(oProps.getSize(),nProps.getSize());
// Check that they contain the same data
byte[] _oData = new byte[oProps.getSize()];
byte[] _nData = new byte[nProps.getSize()];
- pfs.createDocumentInputStream("PowerPoint Document").read(_oData);
- npfs.createDocumentInputStream("PowerPoint Document").read(_nData);
- for(int i=0; i<_oData.length; i++) {
-// System.out.println(i + "\t" + Integer.toHexString(i) + "\t" + _oData[i]);
- assertEquals(_oData[i], _nData[i]);
- }
+
+ oDir.createDocumentInputStream(HSLFSlideShow.POWERPOINT_DOCUMENT).read(_oData);
+ npfs.createDocumentInputStream(HSLFSlideShow.POWERPOINT_DOCUMENT).read(_nData);
+ assertArrayEquals(_oData, _nData);
+
+ npfs.close();
}
}
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 dfd840b1b7..360bbd5d1a 100644
--- a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestExHyperlink.java
+++ b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestExHyperlink.java
@@ -18,86 +18,48 @@
package org.apache.poi.hslf.record;
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
import java.io.ByteArrayOutputStream;
+import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
-import junit.framework.AssertionFailedError;
-import junit.framework.TestCase;
-
+import org.apache.poi.POIDataSamples;
import org.apache.poi.hslf.usermodel.HSLFSlideShow;
import org.apache.poi.hslf.usermodel.HSLFSlideShowImpl;
-import org.apache.poi.POIDataSamples;
+import org.junit.Test;
/**
* Tests that ExHyperlink works properly.
- *
- * @author Nick Burch (nick at torchbox dot com)
*/
-public final class TestExHyperlink extends TestCase {
- // From a real file
- private final byte[] data_a = new byte[] {
- 0x0F, 00, 0xD7-256, 0x0F, 0xA8-256, 00, 00, 00,
-
- 00, 00, 0xD3-256, 0x0F, 04, 00, 00, 00,
- 03, 00, 00, 00,
-
- 00, 00, 0xBA-256, 0x0F, 0x46, 00, 00, 00,
- 0x68, 00, 0x74, 00, 0x74, 00, 0x70, 00,
- 0x3A, 00, 0x2F, 00, 0x2F, 00, 0x6A, 00,
- 0x61, 00, 0x6B, 00, 0x61, 00, 0x72, 00,
- 0x74, 00, 0x61, 00, 0x2E, 00, 0x61, 00,
- 0x70, 00, 0x61, 00, 0x63, 00, 0x68, 00,
- 0x65, 00, 0x2E, 00, 0x6F, 00, 0x72, 00,
- 0x67, 00, 0x2F, 00, 0x70, 00, 0x6F, 00,
- 0x69, 00, 0x2F, 00, 0x68, 00, 0x73, 00,
- 0x73, 00, 0x66, 00, 0x2F, 00,
-
- 0x10, 00, 0xBA-256, 0x0F, 0x46, 00, 00, 00,
- 0x68, 00, 0x74, 00, 0x74, 00, 0x70, 00,
- 0x3A, 00, 0x2F, 00, 0x2F, 00, 0x6A, 00,
- 0x61, 00, 0x6B, 00, 0x61, 00, 0x72, 00,
- 0x74, 00, 0x61, 00, 0x2E, 00, 0x61, 00,
- 0x70, 00, 0x61, 00, 0x63, 00, 0x68, 00,
- 0x65, 00, 0x2E, 00, 0x6F, 00, 0x72, 00,
- 0x67, 00, 0x2F, 00, 0x70, 00, 0x6F, 00,
- 0x69, 00, 0x2F, 00, 0x68, 00, 0x73, 00,
- 0x73, 00, 0x66, 00, 0x2F, 00
- };
-
- public void testRecordType() {
- ExHyperlink eh = new ExHyperlink(data_a, 0, data_a.length);
- assertEquals(4055l, eh.getRecordType());
- }
-
- public void testNumber() {
- ExHyperlink eh = new ExHyperlink(data_a, 0, data_a.length);
- assertEquals(3, eh.getExHyperlinkAtom().getNumber());
- }
-
- public void testLinkURL() {
- ExHyperlink eh = new ExHyperlink(data_a, 0, data_a.length);
- assertEquals("http://jakarta.apache.org/poi/hssf/", eh.getLinkURL());
+public final class TestExHyperlink {
+ @Test
+ public void testReadWrite() throws IOException {
+ // From a real file
+ byte[] exHyperlinkBytes = org.apache.poi.poifs.storage.RawDataUtil.decompress(
+ "H4sIAAAAAAAAAONnuM6/ggEELvOzAElmMHsXvxuQzGAoAcICBisGfSDMYkhkyAbi"+
+ "IqBYIoMeEBcAcTJQVSqQlw8UTweqKgCyMoF0BkMxEKYBWQJUNQ0A/k1x3rAAAAA="
+ );
+ ExHyperlink exHyperlink = new ExHyperlink(exHyperlinkBytes, 0, exHyperlinkBytes.length);
+
+
+ assertEquals(4055l, exHyperlink.getRecordType());
+ assertEquals(3, exHyperlink.getExHyperlinkAtom().getNumber());
+ String expURL = "http://jakarta.apache.org/poi/hssf/";
+ assertEquals(expURL, exHyperlink.getLinkURL());
+ assertEquals(expURL, exHyperlink._getDetailsA());
+ assertEquals(expURL, exHyperlink._getDetailsB());
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ exHyperlink.writeOut(baos);
+ assertArrayEquals(exHyperlinkBytes, baos.toByteArray());
}
- public void testDetails() {
- ExHyperlink eh = new ExHyperlink(data_a, 0, data_a.length);
- assertEquals("http://jakarta.apache.org/poi/hssf/", eh._getDetailsA());
- assertEquals("http://jakarta.apache.org/poi/hssf/", eh._getDetailsB());
- }
-
- public void testWrite() throws Exception {
- ExHyperlink eh = new ExHyperlink(data_a, 0, data_a.length);
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- eh.writeOut(baos);
- byte[] b = baos.toByteArray();
- assertEquals(data_a.length, b.length);
- for(int i=0; i<data_a.length; i++) {
- assertEquals(data_a[i],b[i]);
- }
- }
-
- public void testRealFile() throws Exception {
+ @Test
+ public void testRealFile() throws IOException {
POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
HSLFSlideShowImpl hss = new HSLFSlideShowImpl(slTests.openResourceAsStream("WithLinks.ppt"));
HSLFSlideShow ss = new HSLFSlideShow(hss);
@@ -111,9 +73,8 @@ public final class TestExHyperlink extends TestCase {
exObjList = (ExObjList)rec;
}
}
- if (exObjList == null) {
- throw new AssertionFailedError("exObjList must not be null");
- }
+
+ assertNotNull(exObjList);
// Within that, grab out the Hyperlink atoms
List<ExHyperlink> linksA = new ArrayList<ExHyperlink>();
@@ -145,5 +106,6 @@ public final class TestExHyperlink extends TestCase {
assertEquals(4, links[3].getExHyperlinkAtom().getNumber());
assertEquals("http://jakarta.apache.org/hslf/", links[3].getLinkURL());
+ ss.close();
}
}
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 88f6884df4..e3abda1d11 100644
--- a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestExObjList.java
+++ b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestExObjList.java
@@ -18,22 +18,21 @@
package org.apache.poi.hslf.record;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
-import org.apache.poi.hslf.usermodel.HSLFSlideShow;
-import org.apache.poi.hslf.usermodel.HSLFSlideShowImpl;
import org.apache.poi.POIDataSamples;
+import org.apache.poi.hslf.usermodel.HSLFSlideShow;
+import org.junit.Test;
/**
* Tests that ExObjList works properly.
- *
- * @author Nick Burch (nick at torchbox dot com)
*/
-public class TestExObjList extends TestCase {
- public void testRealFile() throws Exception {
+public class TestExObjList {
+ @Test
+ public void testRealFile() throws Exception {
POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
- HSLFSlideShowImpl hss = new HSLFSlideShowImpl(slTests.openResourceAsStream("WithLinks.ppt"));
- HSLFSlideShow ss = new HSLFSlideShow(hss);
+ HSLFSlideShow ss = new HSLFSlideShow(slTests.openResourceAsStream("WithLinks.ppt"));
// Get the document
Document doc = ss.getDocumentRecord();
@@ -65,5 +64,6 @@ public class TestExObjList extends TestCase {
assertEquals(4, links[3].getExHyperlinkAtom().getNumber());
assertEquals("http://jakarta.apache.org/hslf/", links[3].getLinkURL());
+ ss.close();
}
}
diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestSound.java b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestSound.java
index 24e21d6749..6829d72886 100644
--- a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestSound.java
+++ b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestSound.java
@@ -18,20 +18,22 @@
package org.apache.poi.hslf.record;
import static org.junit.Assert.assertArrayEquals;
-import junit.framework.AssertionFailedError;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.io.IOException;
import org.apache.poi.POIDataSamples;
import org.apache.poi.hslf.usermodel.HSLFSlideShow;
+import org.junit.Test;
/**
* Tests Sound-related records: SoundCollection(2020), Sound(2022) and
* SoundData(2023)).
- *
- * @author Yegor Kozlov
*/
-public final class TestSound extends TestCase {
- public void testRealFile() throws Exception {
+public final class TestSound {
+ @Test
+ public void testRealFile() throws IOException {
POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
HSLFSlideShow ppt = new HSLFSlideShow(slTests.openResourceAsStream("sound.ppt"));
@@ -46,9 +48,7 @@ public final class TestSound extends TestCase {
break;
}
}
- if (soundCollection == null) {
- throw new AssertionFailedError("soundCollection must not be null");
- }
+ assertNotNull(soundCollection);
Sound sound = null;
Record[] sound_ch = soundCollection.getChildRecords();
@@ -59,9 +59,8 @@ public final class TestSound extends TestCase {
k++;
}
}
- if (sound == null) {
- throw new AssertionFailedError("sound must not be null");
- }
+
+ assertNotNull(sound);
assertEquals(1, k);
assertEquals("ringin.wav", sound.getSoundName());
@@ -70,5 +69,7 @@ public final class TestSound extends TestCase {
byte[] ref_data = slTests.readFile("ringin.wav");
assertArrayEquals(ref_data, sound.getSoundData());
- }
+
+ ppt.close();
+ }
}
diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestFontRendering.java b/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestFontRendering.java
index e768d79357..1e5147eb9e 100644
--- a/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestFontRendering.java
+++ b/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestFontRendering.java
@@ -23,6 +23,7 @@ import static org.junit.Assume.assumeTrue;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
+import java.awt.FontFormatException;
import java.awt.Graphics2D;
import java.awt.GraphicsEnvironment;
import java.awt.RenderingHints;
@@ -31,6 +32,7 @@ import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
import java.awt.image.DataBufferByte;
import java.io.File;
+import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.HashMap;
@@ -51,7 +53,7 @@ public class TestFontRendering {
// @Ignore2("This fails on some systems because fonts are rendered slightly different")
@Test
- public void bug55902mixedFontWithChineseCharacters() throws Exception {
+ public void bug55902mixedFontWithChineseCharacters() throws IOException, FontFormatException {
// font files need to be downloaded first via
// ant test-scratchpad-download-resources
String fontFiles[][] = {
@@ -117,5 +119,6 @@ public class TestFontRendering {
}
assertArrayEquals("Expected to have matching raster-arrays, but found differences", expectedData, actualData);
+ ss.close();
}
}
diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestNumberedList2.java b/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestNumberedList2.java
index 297f57c61c..32ac8f4172 100644
--- a/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestNumberedList2.java
+++ b/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestNumberedList2.java
@@ -19,14 +19,19 @@
package org.apache.poi.hslf.usermodel;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import java.io.IOException;
import java.util.List;
import org.apache.poi.POIDataSamples;
import org.apache.poi.hslf.model.textproperties.TextPFException9;
import org.apache.poi.hslf.model.textproperties.TextPropCollection;
-import org.apache.poi.hslf.record.*;
+import org.apache.poi.hslf.record.EscherTextboxWrapper;
+import org.apache.poi.hslf.record.StyleTextProp9Atom;
+import org.apache.poi.hslf.record.StyleTextPropAtom;
import org.apache.poi.sl.usermodel.AutoNumberingScheme;
import org.junit.Test;
@@ -36,14 +41,12 @@ import org.junit.Test;
* if a paragraph has autonumber ()
* @see <a href="http://social.msdn.microsoft.com/Forums/mr-IN/os_binaryfile/thread/650888db-fabd-4b95-88dc-f0455f6e2d28">
* PPT: Missing TextAutoNumberScheme structure providing the style of the number bullets</a>
- *
- * @author Alex Nikiforov [mailto:anikif@gmail.com]
*/
public final class TestNumberedList2 {
private static POIDataSamples _slTests = POIDataSamples.getSlideShowInstance();
@Test
- public void testNumberedList() throws Exception {
+ public void testNumberedList() throws IOException {
HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("numbers2.ppt"));
assertTrue("No Exceptions while reading file", true);
@@ -51,8 +54,11 @@ public final class TestNumberedList2 {
assertEquals(2, slides.size());
checkSlide0(slides.get(0));
checkSlide1(slides.get(1));
- }
- private void checkSlide0(final HSLFSlide s) {
+
+ ppt.close();
+ }
+
+ private void checkSlide0(final HSLFSlide s) {
final StyleTextProp9Atom[] numberedListArray = s.getNumberedListInfo();
assertNotNull(numberedListArray);
assertEquals(2, numberedListArray.length);
@@ -89,6 +95,7 @@ public final class TestNumberedList2 {
checkSingleRunWrapper(44, styleAtoms[0]);
checkSingleRunWrapper(130, styleAtoms[1]);
}
+
private void checkSlide1(final HSLFSlide s) {
final StyleTextProp9Atom[] numberedListArray = s.getNumberedListInfo();
assertNotNull(numberedListArray);
@@ -119,6 +126,7 @@ public final class TestNumberedList2 {
checkSingleRunWrapper(67, styleAtoms[1]);
checkSingleRunWrapper(70, styleAtoms[2]);
}
+
private void checkSingleRunWrapper(final int exceptedLength, final EscherTextboxWrapper wrapper) {
final StyleTextPropAtom styleTextPropAtom = wrapper.getStyleTextPropAtom();
final List<TextPropCollection> textProps = styleTextPropAtom.getCharacterStyles();
diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestReOrderingSlides.java b/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestReOrderingSlides.java
index c8a3d3761d..0de5029966 100644
--- a/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestReOrderingSlides.java
+++ b/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestReOrderingSlides.java
@@ -22,15 +22,15 @@ import static org.junit.Assert.assertEquals;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
+import java.io.IOException;
import org.apache.poi.POIDataSamples;
+import org.apache.poi.hslf.HSLFTestDataSamples;
import org.junit.Before;
import org.junit.Test;
/**
* Tests that SlideShow can re-order slides properly
- *
- * @author Nick Burch (nick at torchbox dot com)
*/
public final class TestReOrderingSlides {
// A SlideShow with one slide
@@ -66,7 +66,7 @@ public final class TestReOrderingSlides {
* Test that we can "re-order" a slideshow with only 1 slide on it
*/
@Test
- public void testReOrder1() throws Exception {
+ public void testReOrder1() throws IOException {
// Has one slide
assertEquals(1, ss_one.getSlides().size());
HSLFSlide s1 = ss_one.getSlides().get(0);
@@ -80,12 +80,7 @@ public final class TestReOrderingSlides {
ss_one.reorderSlide(1, 1);
// Write out, and read back in
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- hss_one.write(baos);
- ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
-
- HSLFSlideShowImpl hss_read = new HSLFSlideShowImpl(bais);
- HSLFSlideShow ss_read = new HSLFSlideShow(hss_read);
+ HSLFSlideShow ss_read = HSLFTestDataSamples.writeOutAndReadBack(ss_one);
// Check it still has 1 slide
assertEquals(1, ss_read.getSlides().size());
@@ -95,6 +90,8 @@ public final class TestReOrderingSlides {
assertEquals(256, s1._getSheetNumber());
assertEquals(3, s1._getSheetRefId());
assertEquals(1, s1.getSlideNumber());
+
+ ss_read.close();
}
/**
@@ -102,7 +99,7 @@ public final class TestReOrderingSlides {
* two slides in it
*/
@Test
- public void testReOrder2() throws Exception {
+ public void testReOrder2() throws IOException {
// Has two slides
assertEquals(2, ss_two.getSlides().size());
HSLFSlide s1 = ss_two.getSlides().get(0);
@@ -121,12 +118,7 @@ public final class TestReOrderingSlides {
ss_two.reorderSlide(2, 2);
// Write out, and read back in
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- hss_two.write(baos);
- ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
-
- HSLFSlideShowImpl hss_read = new HSLFSlideShowImpl(bais);
- HSLFSlideShow ss_read = new HSLFSlideShow(hss_read);
+ HSLFSlideShow ss_read = HSLFTestDataSamples.writeOutAndReadBack(ss_two);
// Check it still has 2 slides
assertEquals(2, ss_read.getSlides().size());
@@ -140,13 +132,15 @@ public final class TestReOrderingSlides {
assertEquals(257, s2._getSheetNumber());
assertEquals(6, s2._getSheetRefId());
assertEquals(2, s2.getSlideNumber());
- }
+
+ ss_read.close();
+ }
/**
* Test re-ordering slides in a slideshow with 2 slides on it
*/
@Test
- public void testReOrder2swap() throws Exception {
+ public void testReOrder2swap() throws IOException {
// Has two slides
assertEquals(2, ss_two.getSlides().size());
HSLFSlide s1 = ss_two.getSlides().get(0);
@@ -165,12 +159,7 @@ public final class TestReOrderingSlides {
ss_two.reorderSlide(2, 1);
// Write out, and read back in
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- hss_two.write(baos);
- ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
-
- HSLFSlideShowImpl hss_read = new HSLFSlideShowImpl(bais);
- HSLFSlideShow ss_read = new HSLFSlideShow(hss_read);
+ HSLFSlideShow ss_read = HSLFTestDataSamples.writeOutAndReadBack(ss_two);
// Check it still has 2 slides
assertEquals(2, ss_read.getSlides().size());
@@ -184,14 +173,16 @@ public final class TestReOrderingSlides {
assertEquals(256, s2._getSheetNumber());
assertEquals(4, s2._getSheetRefId());
assertEquals(2, s2.getSlideNumber());
- }
+
+ ss_read.close();
+ }
/**
* Test doing a dummy re-order on a slideshow with
* three slides in it
*/
@Test
- public void testReOrder3() throws Exception {
+ public void testReOrder3() throws IOException {
// Has three slides
assertEquals(3, ss_three.getSlides().size());
HSLFSlide s1 = ss_three.getSlides().get(0);
@@ -215,12 +206,7 @@ public final class TestReOrderingSlides {
ss_three.reorderSlide(2, 2);
// Write out, and read back in
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- hss_three.write(baos);
- ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
-
- HSLFSlideShowImpl hss_read = new HSLFSlideShowImpl(bais);
- HSLFSlideShow ss_read = new HSLFSlideShow(hss_read);
+ HSLFSlideShow ss_read = HSLFTestDataSamples.writeOutAndReadBack(ss_three);
// Check it still has 3 slides
assertEquals(3, ss_read.getSlides().size());
@@ -239,13 +225,15 @@ public final class TestReOrderingSlides {
assertEquals(257, s3._getSheetNumber());
assertEquals(4, s3._getSheetRefId());
assertEquals(3, s3.getSlideNumber());
- }
+
+ ss_read.close();
+ }
/**
* Test re-ordering slides in a slideshow with 3 slides on it
*/
@Test
- public void testReOrder3swap() throws Exception {
+ public void testReOrder3swap() throws IOException {
// Has three slides
assertEquals(3, ss_three.getSlides().size());
HSLFSlide s1 = ss_three.getSlides().get(0);
@@ -282,12 +270,7 @@ public final class TestReOrderingSlides {
assertEquals("Slide 1", ((HSLFTextShape)s3.getShapes().get(0)).getText());
// Write out, and read back in
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- hss_three.write(baos);
- ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
-
- HSLFSlideShowImpl hss_read = new HSLFSlideShowImpl(bais);
- HSLFSlideShow ss_read = new HSLFSlideShow(hss_read);
+ HSLFSlideShow ss_read = HSLFTestDataSamples.writeOutAndReadBack(ss_three);
// Check it still has 3 slides
assertEquals(3, ss_read.getSlides().size());
@@ -311,5 +294,7 @@ public final class TestReOrderingSlides {
assertEquals(s3._getSheetNumber(), _s3._getSheetNumber());
assertEquals(s3._getSheetRefId(), _s3._getSheetRefId());
assertEquals(3, s3.getSlideNumber());
+
+ ss_read.close();
}
}
diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestRichTextRun.java b/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestRichTextRun.java
index b32a20182a..9c978cb8c8 100644
--- a/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestRichTextRun.java
+++ b/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestRichTextRun.java
@@ -397,7 +397,7 @@ public final class TestRichTextRun {
private static void assertMatchesFileC(HSLFSlideShow s) throws IOException {
// Grab the bytes of the file
NPOIFSFileSystem fs = new NPOIFSFileSystem(HSLFTestDataSamples.openSampleFileStream(filenameC));
- InputStream is = fs.createDocumentInputStream("PowerPoint Document");
+ InputStream is = fs.createDocumentInputStream(HSLFSlideShow.POWERPOINT_DOCUMENT);
byte[] raw_file = IOUtils.toByteArray(is);
is.close();
fs.close();
@@ -406,7 +406,7 @@ public final class TestRichTextRun {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
s.write(baos);
fs = new NPOIFSFileSystem(new ByteArrayInputStream(baos.toByteArray()));
- is = fs.createDocumentInputStream("PowerPoint Document");
+ is = fs.createDocumentInputStream(HSLFSlideShow.POWERPOINT_DOCUMENT);
byte[] raw_ss = IOUtils.toByteArray(is);
is.close();
fs.close();