You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by fa...@apache.org on 2022/07/22 11:50:33 UTC

svn commit: r1902943 - in /poi/trunk/poi-ooxml/src/test/java/org/apache/poi/xslf: XSLFTestDataSamples.java usermodel/TestXSLFDiagram.java

Author: fanningpj
Date: Fri Jul 22 11:50:32 2022
New Revision: 1902943

URL: http://svn.apache.org/viewvc?rev=1902943&view=rev
Log:
add disabled test case

Modified:
    poi/trunk/poi-ooxml/src/test/java/org/apache/poi/xslf/XSLFTestDataSamples.java
    poi/trunk/poi-ooxml/src/test/java/org/apache/poi/xslf/usermodel/TestXSLFDiagram.java

Modified: poi/trunk/poi-ooxml/src/test/java/org/apache/poi/xslf/XSLFTestDataSamples.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi-ooxml/src/test/java/org/apache/poi/xslf/XSLFTestDataSamples.java?rev=1902943&r1=1902942&r2=1902943&view=diff
==============================================================================
--- poi/trunk/poi-ooxml/src/test/java/org/apache/poi/xslf/XSLFTestDataSamples.java (original)
+++ poi/trunk/poi-ooxml/src/test/java/org/apache/poi/xslf/XSLFTestDataSamples.java Fri Jul 22 11:50:32 2022
@@ -16,12 +16,15 @@
 ==================================================================== */
 package org.apache.poi.xslf;
 
+import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
 
 import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream;
 import org.apache.poi.POIDataSamples;
+import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
 import org.apache.poi.openxml4j.opc.OPCPackage;
+import org.apache.poi.openxml4j.opc.PackageAccess;
 import org.apache.poi.xslf.usermodel.XMLSlideShow;
 
 public class XSLFTestDataSamples {
@@ -34,6 +37,11 @@ public class XSLFTestDataSamples {
         }
     }
 
+    public static XMLSlideShow openSampleDocumentReadOnly(String sampleName) throws InvalidFormatException {
+        File file = POIDataSamples.getSlideShowInstance().getFile(sampleName);
+        return new XMLSlideShow(OPCPackage.open(file, PackageAccess.READ));
+    }
+
     public static XMLSlideShow writeOutAndReadBack(XMLSlideShow doc) throws IOException {
         try (UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream(4096)) {
             doc.write(baos);

Modified: poi/trunk/poi-ooxml/src/test/java/org/apache/poi/xslf/usermodel/TestXSLFDiagram.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi-ooxml/src/test/java/org/apache/poi/xslf/usermodel/TestXSLFDiagram.java?rev=1902943&r1=1902942&r2=1902943&view=diff
==============================================================================
--- poi/trunk/poi-ooxml/src/test/java/org/apache/poi/xslf/usermodel/TestXSLFDiagram.java (original)
+++ poi/trunk/poi-ooxml/src/test/java/org/apache/poi/xslf/usermodel/TestXSLFDiagram.java Fri Jul 22 11:50:32 2022
@@ -16,15 +16,18 @@
 ==================================================================== */
 package org.apache.poi.xslf.usermodel;
 
+import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
 import org.apache.poi.openxml4j.opc.ContentTypes;
 import org.apache.poi.sl.usermodel.ColorStyle;
 import org.apache.poi.sl.usermodel.PaintStyle;
 import org.apache.poi.sl.usermodel.TextParagraph.TextAlign;
 import org.apache.poi.util.LocaleUtil;
 import org.apache.poi.xslf.XSLFTestDataSamples;
+import org.junit.jupiter.api.Disabled;
 import org.junit.jupiter.api.Test;
 
 import java.awt.Color;
+import java.io.IOException;
 import java.util.List;
 import java.util.stream.Collectors;
 
@@ -52,80 +55,94 @@ public class TestXSLFDiagram {
     }
 
     @Test
-    public void testHasDiagram() {
-        XMLSlideShow inputPptx = XSLFTestDataSamples.openSampleDocument(SIMPLE_DIAGRAM);
-        List<XSLFDiagram> diagrams = extractDiagrams(inputPptx);
-        assertEquals(1, diagrams.size());
+    public void testHasDiagram() throws IOException {
+        try (XMLSlideShow inputPptx = XSLFTestDataSamples.openSampleDocument(SIMPLE_DIAGRAM)) {
+            List<XSLFDiagram> diagrams = extractDiagrams(inputPptx);
+            assertEquals(1, diagrams.size());
+
+            XSLFDiagram diagram = diagrams.get(0);
+            assertTrue(diagram.hasDiagram());
+        }
+    }
 
-        XSLFDiagram diagram = diagrams.get(0);
-        assertTrue(diagram.hasDiagram());
+    @Disabled("https://bz.apache.org/bugzilla/show_bug.cgi?id=66176#c2")
+    @Test
+    public void testHasDiagramReadOnlyFile() throws IOException, InvalidFormatException {
+        try (XMLSlideShow inputPptx = XSLFTestDataSamples.openSampleDocumentReadOnly(SIMPLE_DIAGRAM)) {
+            List<XSLFDiagram> diagrams = extractDiagrams(inputPptx);
+            assertEquals(1, diagrams.size());
+
+            XSLFDiagram diagram = diagrams.get(0);
+            assertTrue(diagram.hasDiagram());
+        }
     }
 
     @Test
-    public void testDiagramContainsShapes() {
-        XMLSlideShow inputPptx = XSLFTestDataSamples.openSampleDocument(SIMPLE_DIAGRAM);
-        List<XSLFDiagram> diagrams = extractDiagrams(inputPptx);
-        assertEquals(1, diagrams.size());
-
-        XSLFDiagram diagram = diagrams.get(0);
-        XSLFGroupShape groupShape = diagram.getGroupShape();
-        assertNotNull(groupShape);
-
-        // The Group gets the same positioning as the SmartArt. This can be much wider/taller than the content inside.
-        assertEquals(groupShape.getAnchor().getWidth(), 113.375, 1E-4);
-        assertEquals(groupShape.getAnchor().getHeight(), 74, 1E-4);
-        assertEquals(groupShape.getAnchor().getX(), -16.75, 1E-4);
-        assertEquals(groupShape.getAnchor().getY(), 5.5, 1E-4);
-
-        List<XSLFShape> shapes = groupShape.getShapes();
-        // 4 shapes, 3 text boxes, one shape does not have any text inside it
-        assertEquals(7, shapes.size());
-
-        // Shape 1 - Yellow Circle - "abc" center aligned
-        String accent4Hex = "#ffc000"; // yellow
-        XSLFAutoShape yellowCircle = (XSLFAutoShape) shapes.get(0);
-        assertTrue(yellowCircle.getText().isEmpty());
-        assertEquals(accent4Hex, colorToHex(yellowCircle.getFillColor()));
-
-        XSLFAutoShape yellowCircleText = (XSLFAutoShape) shapes.get(1);
-        assertEquals(yellowCircleText.getText(), "abc");
-        assertEquals(TextAlign.CENTER, yellowCircleText.getTextParagraphs().get(0).getTextAlign());
-
-        // Shape 2 - Gradient Blue & Purple - "def" left aligned
-        XSLFAutoShape gradientCircle = (XSLFAutoShape) shapes.get(2);
-        assertTrue(gradientCircle.getFillPaint() instanceof PaintStyle.GradientPaint);
-        assertTrue(gradientCircle.getText().isEmpty());
-
-        XSLFAutoShape gradientCircleText = (XSLFAutoShape) shapes.get(3);
-        assertEquals(gradientCircleText.getText(), "def");
-        // Even with left justification, the text is rendered on the right side of the circle because SmartArt defines
-        // a better visual placement for the textbox inside the txXfrm property.
-        assertEquals(1, gradientCircleText.getTextParagraphs().size());
-        XSLFTextParagraph paragraph = gradientCircleText.getTextParagraphs().get(0);
-        assertEquals(TextAlign.LEFT, paragraph.getTextAlign());
-        assertEquals(1, paragraph.getTextRuns().size());
-        XSLFTextRun textRun = paragraph.getTextRuns().get(0);
-        assertTrue(textRun.isBold());
-        assertTrue(textRun.isItalic());
-
-        // Shape 3 - Green Circle with theme color - "ghi" right aligned
-        XSLFAutoShape greenCircle = (XSLFAutoShape) shapes.get(4);
-        ColorStyle greenCircleColorStyle = ((PaintStyle.SolidPaint) greenCircle.getFillPaint()).getSolidColor();
-        // The circle uses the yellow accent4 color but has HSL adjustments that make it green
-        assertEquals(hexToColor(accent4Hex), greenCircleColorStyle.getColor());
-        assertEquals(50004, greenCircleColorStyle.getAlpha()); // 50% transparency
-        assertEquals(6533927, greenCircleColorStyle.getHueOff());
-        assertEquals(6405, greenCircleColorStyle.getLumOff());
-        assertEquals(-27185, greenCircleColorStyle.getSatOff());
-
-        XSLFAutoShape greenCircleText = (XSLFAutoShape) shapes.get(5);
-        assertEquals(greenCircleText.getText(), "ghi");
-        assertEquals(TextAlign.RIGHT, greenCircleText.getTextParagraphs().get(0).getTextAlign());
-
-        // Shape 4 - Circle with Picture Fill - no text
-        XSLFAutoShape pictureShape = (XSLFAutoShape) shapes.get(6);
-        assertTrue(pictureShape.getText().isEmpty());
-        XSLFTexturePaint texturePaint = (XSLFTexturePaint) pictureShape.getFillPaint();
-        assertEquals(ContentTypes.IMAGE_JPEG, texturePaint.getContentType());
+    public void testDiagramContainsShapes() throws IOException {
+        try (XMLSlideShow inputPptx = XSLFTestDataSamples.openSampleDocument(SIMPLE_DIAGRAM)) {
+            List<XSLFDiagram> diagrams = extractDiagrams(inputPptx);
+            assertEquals(1, diagrams.size());
+
+            XSLFDiagram diagram = diagrams.get(0);
+            XSLFGroupShape groupShape = diagram.getGroupShape();
+            assertNotNull(groupShape);
+
+            // The Group gets the same positioning as the SmartArt. This can be much wider/taller than the content inside.
+            assertEquals(groupShape.getAnchor().getWidth(), 113.375, 1E-4);
+            assertEquals(groupShape.getAnchor().getHeight(), 74, 1E-4);
+            assertEquals(groupShape.getAnchor().getX(), -16.75, 1E-4);
+            assertEquals(groupShape.getAnchor().getY(), 5.5, 1E-4);
+
+            List<XSLFShape> shapes = groupShape.getShapes();
+            // 4 shapes, 3 text boxes, one shape does not have any text inside it
+            assertEquals(7, shapes.size());
+
+            // Shape 1 - Yellow Circle - "abc" center aligned
+            String accent4Hex = "#ffc000"; // yellow
+            XSLFAutoShape yellowCircle = (XSLFAutoShape) shapes.get(0);
+            assertTrue(yellowCircle.getText().isEmpty());
+            assertEquals(accent4Hex, colorToHex(yellowCircle.getFillColor()));
+
+            XSLFAutoShape yellowCircleText = (XSLFAutoShape) shapes.get(1);
+            assertEquals(yellowCircleText.getText(), "abc");
+            assertEquals(TextAlign.CENTER, yellowCircleText.getTextParagraphs().get(0).getTextAlign());
+
+            // Shape 2 - Gradient Blue & Purple - "def" left aligned
+            XSLFAutoShape gradientCircle = (XSLFAutoShape) shapes.get(2);
+            assertTrue(gradientCircle.getFillPaint() instanceof PaintStyle.GradientPaint);
+            assertTrue(gradientCircle.getText().isEmpty());
+
+            XSLFAutoShape gradientCircleText = (XSLFAutoShape) shapes.get(3);
+            assertEquals(gradientCircleText.getText(), "def");
+            // Even with left justification, the text is rendered on the right side of the circle because SmartArt defines
+            // a better visual placement for the textbox inside the txXfrm property.
+            assertEquals(1, gradientCircleText.getTextParagraphs().size());
+            XSLFTextParagraph paragraph = gradientCircleText.getTextParagraphs().get(0);
+            assertEquals(TextAlign.LEFT, paragraph.getTextAlign());
+            assertEquals(1, paragraph.getTextRuns().size());
+            XSLFTextRun textRun = paragraph.getTextRuns().get(0);
+            assertTrue(textRun.isBold());
+            assertTrue(textRun.isItalic());
+
+            // Shape 3 - Green Circle with theme color - "ghi" right aligned
+            XSLFAutoShape greenCircle = (XSLFAutoShape) shapes.get(4);
+            ColorStyle greenCircleColorStyle = ((PaintStyle.SolidPaint) greenCircle.getFillPaint()).getSolidColor();
+            // The circle uses the yellow accent4 color but has HSL adjustments that make it green
+            assertEquals(hexToColor(accent4Hex), greenCircleColorStyle.getColor());
+            assertEquals(50004, greenCircleColorStyle.getAlpha()); // 50% transparency
+            assertEquals(6533927, greenCircleColorStyle.getHueOff());
+            assertEquals(6405, greenCircleColorStyle.getLumOff());
+            assertEquals(-27185, greenCircleColorStyle.getSatOff());
+
+            XSLFAutoShape greenCircleText = (XSLFAutoShape) shapes.get(5);
+            assertEquals(greenCircleText.getText(), "ghi");
+            assertEquals(TextAlign.RIGHT, greenCircleText.getTextParagraphs().get(0).getTextAlign());
+
+            // Shape 4 - Circle with Picture Fill - no text
+            XSLFAutoShape pictureShape = (XSLFAutoShape) shapes.get(6);
+            assertTrue(pictureShape.getText().isEmpty());
+            XSLFTexturePaint texturePaint = (XSLFTexturePaint) pictureShape.getFillPaint();
+            assertEquals(ContentTypes.IMAGE_JPEG, texturePaint.getContentType());
+        }
     }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org