<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
- <name>ApachePOI</name>
+ <name>ApachePOI-bug58365</name>
<comment></comment>
<projects>
</projects>
import static org.junit.Assert.assertEquals;\r
\r
import java.io.IOException;\r
+import java.io.InputStream;\r
\r
import org.apache.poi.POIDataSamples;\r
import org.apache.poi.sl.usermodel.SlideShow;\r
import org.apache.poi.sl.usermodel.SlideShowFactory;\r
import org.apache.poi.sl.usermodel.TableShape;\r
+import org.apache.poi.xslf.XSLFTestDataSamples;\r
+import org.apache.poi.xslf.usermodel.XMLSlideShow;\r
import org.junit.Test;\r
\r
public class TestTable {\r
private static POIDataSamples _slTests = POIDataSamples.getSlideShowInstance();\r
\r
+ /** a generic way to open a sample slideshow document **/\r
+ public static SlideShow<?,?> openSampleSlideshow(String sampleName) throws IOException {\r
+ InputStream is = _slTests.openResourceAsStream(sampleName);\r
+ try {\r
+ return SlideShowFactory.create(is);\r
+ } catch (Exception e) {\r
+ throw new RuntimeException(e);\r
+ } finally {\r
+ is.close();\r
+ }\r
+ }\r
+ \r
@Test\r
public void testColWidthRowHeight() throws IOException {\r
// Test of table dimensions of same slideshow saved as ppt/x\r
// to check if both return similar (points) value\r
- SlideShow<?,?> ppt = SlideShowFactory.create(_slTests.getFile("table_test.ppt"));\r
+ SlideShow<?,?> ppt = openSampleSlideshow("table_test.ppt");\r
TableShape<?,?> ts = (TableShape<?,?>)ppt.getSlides().get(0).getShapes().get(0);\r
- int cols = ts.getNumberOfColumns();\r
- int rows = ts.getNumberOfRows();\r
\r
- SlideShow<?,?> pptx = SlideShowFactory.create(_slTests.getFile("table_test.pptx"));\r
+ SlideShow<?,?> pptx = openSampleSlideshow("table_test.pptx");\r
TableShape<?,?> tsx = (TableShape<?,?>)pptx.getSlides().get(0).getShapes().get(0);\r
- int colsx = tsx.getNumberOfColumns();\r
- int rowsx = tsx.getNumberOfRows();\r
\r
- assertEquals(cols, colsx);\r
- assertEquals(rows, rowsx);\r
+ // assume table shape should be equal to itself\r
+ confirmTableShapeEqual(ts, ts);\r
+ confirmTableShapeEqual(tsx, tsx);\r
+ \r
+ // assert ppt and pptx versions of the same table have the same shape\r
+ confirmTableShapeEqual(ts, tsx);\r
+\r
+ pptx.close();\r
+ ppt.close();\r
+ }\r
+ \r
+ private void confirmTableShapeEqual(TableShape<?,?> tableA, TableShape<?,?> tableB) {\r
+ int cols = tableA.getNumberOfColumns();\r
+ int rows = tableA.getNumberOfRows();\r
+ \r
+ int colsx = tableB.getNumberOfColumns();\r
+ int rowsx = tableB.getNumberOfRows();\r
+ \r
+ assertEquals("tables should have same number of columns", cols, colsx);\r
+ assertEquals("tables should have same number of rows", rows, rowsx);\r
\r
for (int i=0; i<cols; i++) {\r
- assertEquals(ts.getColumnWidth(i), tsx.getColumnWidth(i), 0.2);\r
+ assertEquals("Width of column " + i + " should be equal",\r
+ tableA.getColumnWidth(i), tableB.getColumnWidth(i), 0.2);\r
}\r
\r
for (int i=0; i<rows; i++) {\r
- assertEquals(ts.getRowHeight(i), tsx.getRowHeight(i), 0.3);\r
+ assertEquals("Height of row " + i + " should be equal",\r
+ tableA.getRowHeight(i), tableB.getRowHeight(i), 0.3);\r
}\r
-\r
- pptx.close();\r
- ppt.close();\r
}\r
\r
}\r
import java.awt.Dimension;
import java.awt.geom.Rectangle2D;
+import java.io.IOException;
+import java.io.InputStream;
import org.apache.poi.POIDataSamples;
+import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.sl.usermodel.PictureData;
import org.apache.poi.sl.usermodel.PictureShape;
import org.apache.poi.sl.usermodel.RectAlign;
import org.apache.poi.sl.usermodel.SlideShow;
import org.apache.poi.sl.usermodel.SlideShowFactory;
import org.apache.poi.util.Units;
+import org.apache.poi.xslf.XSLFTestDataSamples;
+import org.apache.poi.xslf.usermodel.XMLSlideShow;
import org.junit.Test;
public class TestDrawPictureShape {
final static POIDataSamples ssSamples = POIDataSamples.getSlideShowInstance();
+
+ /** a generic way to open a sample slideshow document **/
+ public static SlideShow<?,?> openSampleDocument(String sampleName) throws IOException {
+ InputStream is = ssSamples.openResourceAsStream(sampleName);
+ try {
+ return SlideShowFactory.create(is);
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ } finally {
+ is.close();
+ }
+ }
@Test
public void testResize() throws Exception {
String files[] = { "pictures.ppt", "shapes.pptx" };
for (String file : files) {
- SlideShow<?,?> ss = SlideShowFactory.create(ssSamples.getFile(file));
+ SlideShow<?,?> ss = openSampleDocument(file);
+
Slide<?,?> slide = ss.getSlides().get(0);
PictureShape<?,?> picShape = null;
for (Shape<?,?> shape : slide.getShapes()) {
\r
import java.io.ByteArrayInputStream;\r
import java.io.ByteArrayOutputStream;\r
+import java.io.IOException;\r
import java.io.InputStream;\r
+import java.io.OutputStream;\r
\r
/**\r
* @author Yegor Kozlov\r
*/\r
public class XSLFTestDataSamples {\r
\r
- public static XMLSlideShow openSampleDocument(String sampleName) {\r
+ public static XMLSlideShow openSampleDocument(String sampleName) throws IOException {\r
InputStream is = POIDataSamples.getSlideShowInstance().openResourceAsStream(sampleName);\r
try {\r
return new XMLSlideShow(OPCPackage.open(is));\r
} catch (Exception e) {\r
throw new RuntimeException(e);\r
+ } finally {\r
+ is.close();\r
}\r
}\r
\r
- public static XMLSlideShow writeOutAndReadBack(XMLSlideShow doc) {\r
+ public static XMLSlideShow writeOutAndReadBack(XMLSlideShow doc) throws IOException {\r
+ ByteArrayOutputStream baos = new ByteArrayOutputStream(4096);\r
try {\r
- ByteArrayOutputStream baos = new ByteArrayOutputStream(4096);\r
doc.write(baos);\r
- ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());\r
+ } catch (Exception e) {\r
+ throw new RuntimeException(e);\r
+ }\r
+ \r
+ InputStream bais;\r
+ bais = new ByteArrayInputStream(baos.toByteArray());\r
+ try {\r
return new XMLSlideShow(OPCPackage.open(bais));\r
} catch (Exception e) {\r
throw new RuntimeException(e);\r
+ } finally {\r
+ baos.close();\r
+ bais.close();\r
}\r
+ \r
}\r
}\r
import static org.junit.Assert.assertEquals;\r
import static org.junit.Assert.assertNotNull;\r
\r
+import java.io.IOException;\r
import java.net.URI;\r
import java.util.List;\r
\r
+import org.apache.poi.openxml4j.exceptions.InvalidFormatException;\r
import org.apache.poi.openxml4j.opc.PackageRelationship;\r
import org.apache.poi.openxml4j.opc.TargetMode;\r
import org.apache.poi.xslf.XSLFTestDataSamples;\r
public class TestXSLFHyperlink {\r
\r
@Test\r
- public void testRead(){\r
+ public void testRead() throws IOException{\r
XMLSlideShow ppt = XSLFTestDataSamples.openSampleDocument("shapes.pptx");\r
\r
XSLFSlide slide = ppt.getSlides().get(4);\r
XSLFHyperlink link3 = cell3.getTextParagraphs().get(0).getTextRuns().get(0).getHyperlink();\r
assertNotNull(link3);\r
assertEquals(URI.create("mailto:dev@poi.apache.org?subject=Hi%20There"), link3.getTargetURI());\r
+ \r
+ ppt.close();\r
}\r
\r
@Test\r
- public void testCreate() throws Exception {\r
+ public void testCreate() throws IOException, InvalidFormatException {\r
XMLSlideShow ppt = new XMLSlideShow();\r
XSLFSlide slide1 = ppt.createSlide();\r
XSLFSlide slide2 = ppt.createSlide();\r
assertEquals(id2, rel2.getId());\r
assertEquals(TargetMode.INTERNAL, rel2.getTargetMode());\r
assertEquals(XSLFRelation.SLIDE.getRelation(), rel2.getRelationshipType());\r
+ \r
+ ppt.close();\r
}\r
}
\ No newline at end of file
import org.junit.Test;\r
import org.openxmlformats.schemas.drawingml.x2006.main.STTextUnderlineType;\r
\r
+import java.io.IOException;\r
import java.util.List;\r
\r
/**\r
public class TestXSLFShape {\r
\r
@Test\r
- public void testReadTextShapes() {\r
+ public void testReadTextShapes() throws IOException {\r
XMLSlideShow ppt = XSLFTestDataSamples.openSampleDocument("shapes.pptx");\r
List<XSLFSlide> slides = ppt.getSlides();\r
\r
assertEquals("Subtitle", paragraphs2.get(0).getTextRuns().get(0).getRawText());\r
assertTrue(paragraphs2.get(0).getTextRuns().get(0).getXmlObject().getRPr().getB());\r
assertEquals("And second line", paragraphs2.get(1).getTextRuns().get(0).getRawText());\r
+ \r
+ ppt.close();\r
}\r
\r
- public void testCreateShapes() {\r
+ @Test\r
+ public void testCreateShapes() throws IOException {\r
XMLSlideShow ppt = new XMLSlideShow();\r
XSLFSlide slide = ppt.createSlide();\r
assertTrue(slide.getShapes().isEmpty());\r
assertSame(textBox, slide.getShapes().get(0));\r
\r
assertEquals("", textBox.getText());\r
- assertEquals(0, textBox.getTextParagraphs().size());\r
+ // FIXME: is this correct? Should it be starting out with 0 or 1 text paragraphs?\r
+ assertEquals(1, textBox.getTextParagraphs().size());\r
textBox.addNewTextParagraph().addNewTextRun().setText("Apache");\r
textBox.addNewTextParagraph().addNewTextRun().setText("POI");\r
assertEquals("Apache\nPOI", textBox.getText());\r
- assertEquals(2, textBox.getTextParagraphs().size());\r
+ assertEquals(3, textBox.getTextParagraphs().size());\r
+ \r
+ ppt.close();\r
}\r
\r
}
\ No newline at end of file
public class TestXSLFSlide {\r
\r
@Test\r
- public void testReadShapes(){\r
+ public void testReadShapes() throws IOException {\r
XMLSlideShow ppt = XSLFTestDataSamples.openSampleDocument("shapes.pptx");\r
List<XSLFSlide> slides = ppt.getSlides();\r
\r
XSLFTable tbl = (XSLFTable)shapes4.get(0);\r
assertEquals(3, tbl.getNumberOfColumns());\r
assertEquals(6, tbl.getNumberOfRows());\r
+ \r
+ ppt.close();\r
}\r
\r
@Test\r