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.

TestXSLFSlideShow.java 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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;
  16. import junit.framework.TestCase;
  17. import org.apache.poi.POIDataSamples;
  18. import org.apache.poi.openxml4j.opc.OPCPackage;
  19. import org.apache.poi.openxml4j.opc.PackagePart;
  20. import org.apache.poi.xslf.usermodel.XSLFRelation;
  21. import org.openxmlformats.schemas.presentationml.x2006.main.CTSlideIdListEntry;
  22. import org.openxmlformats.schemas.presentationml.x2006.main.CTSlideMasterIdListEntry;
  23. public class TestXSLFSlideShow extends TestCase {
  24. private static final POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
  25. private OPCPackage pack;
  26. protected void setUp() throws Exception {
  27. pack = OPCPackage.open(slTests.openResourceAsStream("sample.pptx"));
  28. }
  29. public void testContainsMainContentType() throws Exception {
  30. boolean found = false;
  31. for(PackagePart part : pack.getParts()) {
  32. if(part.getContentType().equals(XSLFRelation.MAIN.getContentType())) {
  33. found = true;
  34. }
  35. //System.out.println(part);
  36. }
  37. assertTrue(found);
  38. }
  39. public void testOpen() throws Exception {
  40. XSLFSlideShow xml;
  41. // With the finalised uri, should be fine
  42. xml = new XSLFSlideShow(pack);
  43. // Check the core
  44. assertNotNull(xml.getPresentation());
  45. // Check it has some slides
  46. assertTrue(
  47. xml.getSlideReferences().sizeOfSldIdArray() > 0
  48. );
  49. assertTrue(
  50. xml.getSlideMasterReferences().sizeOfSldMasterIdArray() > 0
  51. );
  52. }
  53. @SuppressWarnings("deprecation")
  54. public void testSlideBasics() throws Exception {
  55. XSLFSlideShow xml = new XSLFSlideShow(pack);
  56. // Should have 1 master
  57. assertEquals(1, xml.getSlideMasterReferences().sizeOfSldMasterIdArray());
  58. // Should have three sheets
  59. assertEquals(2, xml.getSlideReferences().sizeOfSldIdArray());
  60. // Check they're as expected
  61. CTSlideIdListEntry[] slides = xml.getSlideReferences().getSldIdArray();
  62. assertEquals(256, slides[0].getId());
  63. assertEquals(257, slides[1].getId());
  64. assertEquals("rId2", slides[0].getId2());
  65. assertEquals("rId3", slides[1].getId2());
  66. // Now get those objects
  67. assertNotNull(xml.getSlide(slides[0]));
  68. assertNotNull(xml.getSlide(slides[1]));
  69. // And check they have notes as expected
  70. assertNotNull(xml.getNotes(slides[0]));
  71. assertNotNull(xml.getNotes(slides[1]));
  72. // And again for the master
  73. CTSlideMasterIdListEntry[] masters = xml.getSlideMasterReferences().getSldMasterIdArray();
  74. assertEquals(2147483648l, masters[0].getId());
  75. assertEquals("rId1", masters[0].getId2());
  76. assertNotNull(xml.getSlideMaster(masters[0]));
  77. }
  78. public void testMetadataBasics() throws Exception {
  79. XSLFSlideShow xml = new XSLFSlideShow(pack);
  80. assertNotNull(xml.getProperties().getCoreProperties());
  81. assertNotNull(xml.getProperties().getExtendedProperties());
  82. assertEquals("Microsoft Office PowerPoint", xml.getProperties().getExtendedProperties().getUnderlyingProperties().getApplication());
  83. assertEquals(0, xml.getProperties().getExtendedProperties().getUnderlyingProperties().getCharacters());
  84. assertEquals(0, xml.getProperties().getExtendedProperties().getUnderlyingProperties().getLines());
  85. assertEquals(null, xml.getProperties().getCoreProperties().getTitle());
  86. assertEquals(null, xml.getProperties().getCoreProperties().getUnderlyingProperties().getSubjectProperty().getValue());
  87. }
  88. }