aboutsummaryrefslogtreecommitdiffstats
path: root/src/scratchpad/testcases/org/apache/poi/hslf/usermodel
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/usermodel
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/usermodel')
-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
4 files changed, 46 insertions, 50 deletions
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();