diff --git a/build.xml b/build.xml
index c166848e5e..ba744faf4a 100644
--- a/build.xml
+++ b/build.xml
@@ -339,7 +339,7 @@ under the License.
-
+
@@ -1415,11 +1415,12 @@ under the License.
+
-
+
diff --git a/src/ooxml/testcases/org/apache/poi/sl/TestHeadersFooters.java b/src/ooxml/testcases/org/apache/poi/sl/TestHeadersFooters.java
index 8587b0e75e..684311f719 100644
--- a/src/ooxml/testcases/org/apache/poi/sl/TestHeadersFooters.java
+++ b/src/ooxml/testcases/org/apache/poi/sl/TestHeadersFooters.java
@@ -19,63 +19,85 @@
package org.apache.poi.sl;
+import static org.apache.poi.sl.TestTable.openSampleSlideshow;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
-import static org.apache.poi.sl.TestTable.openSampleSlideshow;
+import static org.junit.Assume.assumeFalse;
import java.io.IOException;
import java.util.List;
import org.apache.poi.hslf.model.HeadersFooters;
import org.apache.poi.hslf.usermodel.HSLFSlide;
-import org.apache.poi.hslf.usermodel.HSLFSlideShow;
import org.apache.poi.hslf.usermodel.HSLFTextParagraph;
import org.apache.poi.sl.usermodel.Shape;
import org.apache.poi.sl.usermodel.Slide;
import org.apache.poi.sl.usermodel.SlideShow;
import org.apache.poi.sl.usermodel.TextParagraph;
import org.apache.poi.sl.usermodel.TextShape;
+import org.junit.BeforeClass;
import org.junit.Test;
public class TestHeadersFooters {
- @Test
- public void bug58144() throws IOException {
- SlideShow,?> ppt1 = openSampleSlideshow("bug58144-headers-footers-2003.ppt");
- HSLFSlide sl1 = (HSLFSlide)ppt1.getSlides().get(0);
- HeadersFooters hfs1 = sl1.getHeadersFooters();
- assertNull(hfs1.getHeaderText());
- assertEquals("Confidential", hfs1.getFooterText());
- List> llp1 = sl1.getTextParagraphs();
- assertEquals("Test", HSLFTextParagraph.getText(llp1.get(0)));
- assertFalse(llp1.get(0).get(0).isHeaderOrFooter());
- ppt1.close();
+ private static boolean xslfOnly = false;
- String ppt2007s[] = {
- "bug58144-headers-footers-2007.ppt", "bug58144-headers-footers-2007.pptx"
- };
-
- for (String pptName : ppt2007s) {
- SlideShow,?> ppt2 = openSampleSlideshow(pptName);
- Slide,?> sl2 = ppt2.getSlides().get(0);
-
- if (ppt2 instanceof HSLFSlideShow) {
- HeadersFooters hfs2 = ((HSLFSlide)sl2).getHeadersFooters();
- assertNull(hfs2.getHeaderText());
- assertEquals("Slide footer", hfs2.getFooterText());
- }
-
- List extends Shape,?>> shapes = sl2.getShapes();
- TextShape,?> ts0 = (TextShape,?>)shapes.get(0);
- assertEquals("Test file", ts0.getText());
- TextShape,?> ts1 = (TextShape,?>)shapes.get(1);
- assertEquals("Has some text in the headers and footers", ts1.getText());
- TextShape,?> ts2 = (TextShape,?>)shapes.get(2);
- assertEquals("Slide footer", ts2.getText());
- List extends TextParagraph,?,?>> ltp2 = ts2.getTextParagraphs();
- assertTrue(ltp2.get(0).isHeaderOrFooter());
- ppt2.close();
+ @BeforeClass
+ public static void checkHslf() {
+ try {
+ Class.forName("org.apache.poi.hslf.usermodel.HSLFSlideShow");
+ } catch (Exception e) {
+ xslfOnly = true;
}
}
+
+
+ @Test
+ public void bug58144a() throws IOException {
+ assumeFalse(xslfOnly);
+ SlideShow,?> ppt = openSampleSlideshow("bug58144-headers-footers-2003.ppt");
+ HSLFSlide sl = (HSLFSlide)ppt.getSlides().get(0);
+ HeadersFooters hfs = sl.getHeadersFooters();
+ assertNull(hfs.getHeaderText());
+ assertEquals("Confidential", hfs.getFooterText());
+ List> llp = sl.getTextParagraphs();
+ assertEquals("Test", HSLFTextParagraph.getText(llp.get(0)));
+ assertFalse(llp.get(0).get(0).isHeaderOrFooter());
+ ppt.close();
+ }
+
+ @Test
+ public void bug58144b() throws IOException {
+ assumeFalse(xslfOnly);
+ SlideShow,?> ppt = openSampleSlideshow("bug58144-headers-footers-2007.ppt");
+ Slide,?> sl = ppt.getSlides().get(0);
+ HeadersFooters hfs2 = ((HSLFSlide)sl).getHeadersFooters();
+ assertNull(hfs2.getHeaderText());
+ assertEquals("Slide footer", hfs2.getFooterText());
+
+ testSlideShow(ppt);
+ ppt.close();
+ }
+
+ @Test
+ public void bug58144c() throws IOException {
+ SlideShow,?> ppt = openSampleSlideshow("bug58144-headers-footers-2007.pptx");
+ testSlideShow(ppt);
+ ppt.close();
+ }
+
+ private void testSlideShow(SlideShow,?> ppt) {
+ Slide,?> sl = ppt.getSlides().get(0);
+
+ List extends Shape,?>> shapes = sl.getShapes();
+ TextShape,?> ts0 = (TextShape,?>)shapes.get(0);
+ assertEquals("Test file", ts0.getText());
+ TextShape,?> ts1 = (TextShape,?>)shapes.get(1);
+ assertEquals("Has some text in the headers and footers", ts1.getText());
+ TextShape,?> ts2 = (TextShape,?>)shapes.get(2);
+ assertEquals("Slide footer", ts2.getText());
+ List extends TextParagraph,?,?>> ltp = ts2.getTextParagraphs();
+ assertTrue(ltp.get(0).isHeaderOrFooter());
+ }
}
diff --git a/src/ooxml/testcases/org/apache/poi/sl/TestTable.java b/src/ooxml/testcases/org/apache/poi/sl/TestTable.java
index ac02a62b46..2eaeee3951 100644
--- a/src/ooxml/testcases/org/apache/poi/sl/TestTable.java
+++ b/src/ooxml/testcases/org/apache/poi/sl/TestTable.java
@@ -20,6 +20,7 @@
package org.apache.poi.sl;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assume.assumeFalse;
import java.awt.geom.Rectangle2D;
import java.io.ByteArrayInputStream;
@@ -35,10 +36,22 @@ import org.apache.poi.sl.usermodel.TableCell;
import org.apache.poi.sl.usermodel.TableShape;
import org.apache.poi.sl.usermodel.TextShape.TextDirection;
import org.apache.poi.xslf.usermodel.XMLSlideShow;
+import org.junit.BeforeClass;
import org.junit.Test;
public class TestTable {
private static POIDataSamples _slTests = POIDataSamples.getSlideShowInstance();
+ private static boolean xslfOnly = false;
+
+ @BeforeClass
+ public static void checkHslf() {
+ try {
+ Class.forName("org.apache.poi.hslf.usermodel.HSLFSlideShow");
+ } catch (Exception e) {
+ xslfOnly = true;
+ }
+ }
+
/** a generic way to open a sample slideshow document **/
public static SlideShow,?> openSampleSlideshow(String sampleName) throws IOException {
@@ -54,6 +67,8 @@ public class TestTable {
@Test
public void testColWidthRowHeight() throws IOException {
+ assumeFalse(xslfOnly);
+
// Test of table dimensions of same slideshow saved as ppt/x
// to check if both return similar (points) value
SlideShow,?> ppt = openSampleSlideshow("table_test.ppt");
@@ -95,7 +110,21 @@ public class TestTable {
}
@Test
- public void testTextDirection() throws IOException {
+ public void testTextDirectionHSLF() throws IOException {
+ assumeFalse(xslfOnly);
+ SlideShow,?> ppt1 = new HSLFSlideShow();
+ testTextDirection(ppt1);
+ ppt1.close();
+ }
+
+ @Test
+ public void testTextDirectionXSLF() throws IOException {
+ SlideShow,?> ppt1 = new XMLSlideShow();
+ testTextDirection(ppt1);
+ ppt1.close();
+ }
+
+ private void testTextDirection(SlideShow,?> ppt1) throws IOException {
TextDirection tds[] = {
TextDirection.HORIZONTAL,
@@ -104,34 +133,31 @@ public class TestTable {
// TextDirection.STACKED is not supported on HSLF
};
- for (int i=0; i<2; i++) {
- SlideShow,?> ppt1 = (i == 0) ? new HSLFSlideShow() : new XMLSlideShow();
- TableShape,?> tbl1 = ppt1.createSlide().createTable(1, 3);
- tbl1.setAnchor(new Rectangle2D.Double(50, 50, 200, 200));
-
- int col = 0;
- for (TextDirection td : tds) {
- TableCell,?> c = tbl1.getCell(0, col++);
- if (c != null) {
- c.setTextDirection(td);
- c.setText("bla");
- }
+ TableShape,?> tbl1 = ppt1.createSlide().createTable(1, 3);
+ tbl1.setAnchor(new Rectangle2D.Double(50, 50, 200, 200));
+
+ int col = 0;
+ for (TextDirection td : tds) {
+ TableCell,?> c = tbl1.getCell(0, col++);
+ if (c != null) {
+ c.setTextDirection(td);
+ c.setText("bla");
}
-
- ByteArrayOutputStream bos = new ByteArrayOutputStream();
- ppt1.write(bos);
- ppt1.close();
-
- InputStream is = new ByteArrayInputStream(bos.toByteArray());
- SlideShow,?> ppt2 = SlideShowFactory.create(is);
- TableShape,?> tbl2 = (TableShape,?>)ppt2.getSlides().get(0).getShapes().get(0);
-
- col = 0;
- for (TextDirection td : tds) {
- TableCell,?> c = tbl2.getCell(0, col++);
- assertEquals(td, c.getTextDirection());
- }
- ppt2.close();
}
+
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ ppt1.write(bos);
+ ppt1.close();
+
+ InputStream is = new ByteArrayInputStream(bos.toByteArray());
+ SlideShow,?> ppt2 = SlideShowFactory.create(is);
+ TableShape,?> tbl2 = (TableShape,?>)ppt2.getSlides().get(0).getShapes().get(0);
+
+ col = 0;
+ for (TextDirection td : tds) {
+ TableCell,?> c = tbl2.getCell(0, col++);
+ assertEquals(td, c.getTextDirection());
+ }
+ ppt2.close();
}
}
diff --git a/src/ooxml/testcases/org/apache/poi/sl/draw/TestDrawPictureShape.java b/src/ooxml/testcases/org/apache/poi/sl/draw/TestDrawPictureShape.java
index 303bc833fe..809a307d50 100644
--- a/src/ooxml/testcases/org/apache/poi/sl/draw/TestDrawPictureShape.java
+++ b/src/ooxml/testcases/org/apache/poi/sl/draw/TestDrawPictureShape.java
@@ -20,6 +20,7 @@ package org.apache.poi.sl.draw;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assume.assumeFalse;
import java.awt.Dimension;
import java.awt.geom.Rectangle2D;
@@ -35,10 +36,22 @@ import org.apache.poi.sl.usermodel.Slide;
import org.apache.poi.sl.usermodel.SlideShow;
import org.apache.poi.sl.usermodel.SlideShowFactory;
import org.apache.poi.util.Units;
+import org.junit.BeforeClass;
import org.junit.Test;
public class TestDrawPictureShape {
final static POIDataSamples ssSamples = POIDataSamples.getSlideShowInstance();
+
+ private static boolean xslfOnly = false;
+
+ @BeforeClass
+ public static void checkHslf() {
+ try {
+ Class.forName("org.apache.poi.hslf.usermodel.HSLFSlideShow");
+ } catch (Exception e) {
+ xslfOnly = true;
+ }
+ }
/** a generic way to open a sample slideshow document **/
public static SlideShow,?> openSampleDocument(String sampleName) throws IOException {
@@ -53,41 +66,49 @@ public class TestDrawPictureShape {
}
@Test
- public void testResize() throws Exception {
- String files[] = { "pictures.ppt", "shapes.pptx" };
- for (String file : files) {
- SlideShow,?> ss = openSampleDocument(file);
-
- Slide,?> slide = ss.getSlides().get(0);
- PictureShape,?> picShape = null;
- for (Shape,?> shape : slide.getShapes()) {
- if (shape instanceof PictureShape) {
- picShape = (PictureShape,?>)shape;
- break;
- }
+ public void testResizeHSLF() throws IOException {
+ assumeFalse(xslfOnly);
+ testResize("pictures.ppt");
+ }
+
+ @Test
+ public void testResizeXSLF() throws IOException {
+ testResize("shapes.pptx");
+ }
+
+
+ public void testResize(String file) throws IOException {
+ SlideShow,?> ss = openSampleDocument(file);
+
+ Slide,?> slide = ss.getSlides().get(0);
+ PictureShape,?> picShape = null;
+ for (Shape,?> shape : slide.getShapes()) {
+ if (shape instanceof PictureShape) {
+ picShape = (PictureShape,?>)shape;
+ break;
}
- assertNotNull(picShape);
- PictureData pd = picShape.getPictureData();
- Dimension dimPd = pd.getImageDimension();
- new DrawPictureShape(picShape).resize();
- Dimension dimShape = new Dimension(
- (int)picShape.getAnchor().getWidth(),
- (int)picShape.getAnchor().getHeight()
- );
- assertEquals(dimPd, dimShape);
-
- double newWidth = (dimPd.getWidth()*(100d/dimPd.getHeight()));
- // ... -1 is a rounding error
- Rectangle2D expRect = new Rectangle2D.Double(rbf(50+300-newWidth, picShape), 50, rbf(newWidth, picShape), 100);
- Rectangle2D target = new Rectangle2D.Double(50,50,300,100);
- new DrawPictureShape(picShape).resize(target, RectAlign.BOTTOM_RIGHT);
- Rectangle2D actRect = picShape.getAnchor();
- assertEquals(expRect.getX(), actRect.getX(), .0001);
- assertEquals(expRect.getY(), actRect.getY(), .0001);
- assertEquals(expRect.getWidth(), actRect.getWidth(), .0001);
- assertEquals(expRect.getHeight(), actRect.getHeight(), .0001);
- ss.close();
}
+ assertNotNull(picShape);
+ PictureData pd = picShape.getPictureData();
+ Dimension dimPd = pd.getImageDimension();
+ new DrawPictureShape(picShape).resize();
+ Dimension dimShape = new Dimension(
+ (int)picShape.getAnchor().getWidth(),
+ (int)picShape.getAnchor().getHeight()
+ );
+ assertEquals(dimPd, dimShape);
+
+ double newWidth = (dimPd.getWidth()*(100d/dimPd.getHeight()));
+ // ... -1 is a rounding error
+ Rectangle2D expRect = new Rectangle2D.Double(rbf(50+300-newWidth, picShape), 50, rbf(newWidth, picShape), 100);
+ Rectangle2D target = new Rectangle2D.Double(50,50,300,100);
+ new DrawPictureShape(picShape).resize(target, RectAlign.BOTTOM_RIGHT);
+ Rectangle2D actRect = picShape.getAnchor();
+ assertEquals(expRect.getX(), actRect.getX(), .0001);
+ assertEquals(expRect.getY(), actRect.getY(), .0001);
+ assertEquals(expRect.getWidth(), actRect.getWidth(), .0001);
+ assertEquals(expRect.getHeight(), actRect.getHeight(), .0001);
+ ss.close();
}
// round back and forth - points -> master -> points
diff --git a/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestPPTX2PNG.java b/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestPPTX2PNG.java
index 9ad888da41..66e48881c3 100644
--- a/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestPPTX2PNG.java
+++ b/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestPPTX2PNG.java
@@ -19,50 +19,84 @@
package org.apache.poi.xslf.usermodel;
+import static org.junit.Assume.assumeFalse;
+
import java.io.File;
+import java.io.FileFilter;
+import java.util.Collection;
+import java.util.Set;
+import java.util.TreeSet;
+import java.util.regex.Pattern;
import org.apache.poi.POIDataSamples;
import org.apache.poi.xslf.util.PPTX2PNG;
+import org.junit.BeforeClass;
import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameter;
+import org.junit.runners.Parameterized.Parameters;
/**
- * Date: 10/26/11
- *
- * @author Yegor Kozlov
+ * Test class for testing PPTX2PNG utility which renderes .ppt and .pptx slideshows
*/
+@RunWith(Parameterized.class)
public class TestPPTX2PNG {
+ private static boolean xslfOnly = false;
+ private static final POIDataSamples samples = POIDataSamples.getSlideShowInstance();
+ private static final File basedir = null;
+ private static final String files =
+ "53446.ppt, alterman_security.ppt, alterman_security.pptx, KEY02.pptx, themes.pptx, backgrounds.pptx, layouts.pptx, sample.pptx, shapes.pptx";
+
+
+
+ @BeforeClass
+ public static void checkHslf() {
+ try {
+ Class.forName("org.apache.poi.hslf.usermodel.HSLFSlideShow");
+ } catch (Exception e) {
+ xslfOnly = true;
+ }
+ }
+
+ // use filename instead of File object to omit full pathname in test name
+ @Parameter(value = 0)
+ public String pptFile;
+
+ @Parameters(name="{0}")
+ public static Collection data() {
+ final Set data = new TreeSet();
+ for (String f : files.split(", ?")) {
+ if (basedir == null) {
+ data.add(f);
+ } else {
+ final Pattern p = Pattern.compile(f);
+ basedir.listFiles(new FileFilter(){
+ public boolean accept(File pathname) {
+ String name = pathname.getName();
+ if (p.matcher(name).matches()) {
+ data.add(name);
+ }
+ return false;
+ }
+ });
+ }
+ }
+
+ return data;
+ }
@Test
public void render() throws Exception {
- POIDataSamples samples = POIDataSamples.getSlideShowInstance();
-
-// File testFilesX[] = new File("tmp_ppt").listFiles(new FileFilter() {
-// public boolean accept(File pathname) {
-// return pathname.getName().toLowerCase().contains("ppt");
-// }
-// });
-// String testFiles[] = new String[testFilesX.length];
-// for (int i=0; i