You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

TestXSLFSlide.java 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /* ====================================================================
  2. Licensed to the Apache Software Foundation (ASF) under one or more
  3. contributor license agreements. See the NOTICE file distributed with
  4. this work for additional information regarding copyright ownership.
  5. The ASF licenses this file to You under the Apache License, Version 2.0
  6. (the "License"); you may not use this file except in compliance with
  7. the License. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. ==================================================================== */
  15. package org.apache.poi.xslf.usermodel;
  16. import junit.framework.TestCase;
  17. import org.apache.poi.xslf.XSLFTestDataSamples;
  18. /**
  19. * @author Yegor Kozlov
  20. */
  21. public class TestXSLFSlide extends TestCase {
  22. public void testReadShapes(){
  23. XMLSlideShow ppt = XSLFTestDataSamples.openSampleDocument("shapes.pptx");
  24. XSLFSlide[] slides = ppt.getSlides();
  25. XSLFSlide slide1 = slides[0];
  26. XSLFShape[] shapes1 = slide1.getShapes();
  27. assertEquals(7, shapes1.length);
  28. assertEquals("TextBox 3", shapes1[0].getShapeName());
  29. assertTrue(shapes1[0] instanceof XSLFTextBox);
  30. XSLFAutoShape sh0 = (XSLFAutoShape)shapes1[0];
  31. assertEquals("Learning PPTX", sh0.getText());
  32. assertEquals("Straight Connector 5", shapes1[1].getShapeName());
  33. assertTrue(shapes1[1] instanceof XSLFConnectorShape);
  34. assertEquals("Freeform 6", shapes1[2].getShapeName());
  35. assertTrue(shapes1[2] instanceof XSLFFreeformShape);
  36. XSLFAutoShape sh2 = (XSLFAutoShape)shapes1[2];
  37. assertEquals("Cloud", sh2.getText());
  38. assertEquals("Picture 1", shapes1[3].getShapeName());
  39. assertTrue(shapes1[3] instanceof XSLFPictureShape);
  40. assertEquals("Table 2", shapes1[4].getShapeName());
  41. assertTrue(shapes1[4] instanceof XSLFGraphicFrame);
  42. assertEquals("Straight Arrow Connector 7", shapes1[5].getShapeName());
  43. assertTrue(shapes1[5] instanceof XSLFConnectorShape);
  44. assertEquals("Elbow Connector 9", shapes1[6].getShapeName());
  45. assertTrue(shapes1[6] instanceof XSLFConnectorShape);
  46. // titles on slide2
  47. XSLFSlide slide2 = slides[1];
  48. XSLFShape[] shapes2 = slide2.getShapes();
  49. assertEquals(2, shapes2.length);
  50. assertTrue(shapes2[0] instanceof XSLFAutoShape);
  51. assertEquals("PPTX Title", ((XSLFAutoShape)shapes2[0]).getText());
  52. assertTrue(shapes2[1] instanceof XSLFAutoShape);
  53. assertEquals("Subtitle\nAnd second line", ((XSLFAutoShape)shapes2[1]).getText());
  54. // group shape on slide3
  55. XSLFSlide slide3 = slides[2];
  56. XSLFShape[] shapes3 = slide3.getShapes();
  57. assertEquals(1, shapes3.length);
  58. assertTrue(shapes3[0] instanceof XSLFGroupShape);
  59. XSLFShape[] groupShapes = ((XSLFGroupShape)shapes3[0]).getShapes();
  60. assertEquals(3, groupShapes.length);
  61. assertTrue(groupShapes[0] instanceof XSLFAutoShape);
  62. assertEquals("Rectangle 1", groupShapes[0].getShapeName());
  63. assertTrue(groupShapes[1] instanceof XSLFAutoShape);
  64. assertEquals("Oval 2", groupShapes[1].getShapeName());
  65. assertTrue(groupShapes[2] instanceof XSLFAutoShape);
  66. assertEquals("Right Arrow 3", groupShapes[2].getShapeName());
  67. XSLFSlide slide4 = slides[3];
  68. XSLFShape[] shapes4 = slide4.getShapes();
  69. assertEquals(1, shapes4.length);
  70. assertTrue(shapes4[0] instanceof XSLFTable);
  71. XSLFTable tbl = (XSLFTable)shapes4[0];
  72. assertEquals(3, tbl.getNumberOfColumns());
  73. assertEquals(6, tbl.getNumberOfRows());
  74. }
  75. public void testCreateSlide(){
  76. XMLSlideShow ppt = new XMLSlideShow();
  77. assertEquals(0, ppt.getSlides().length);
  78. XSLFSlide slide = ppt.createSlide();
  79. assertTrue(slide.getFollowMasterGraphics());
  80. slide.setFollowMasterGraphics(false);
  81. assertFalse(slide.getFollowMasterGraphics());
  82. slide.setFollowMasterGraphics(true);
  83. assertTrue(slide.getFollowMasterGraphics());
  84. }
  85. }