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.

TestPPTX2PNG.java 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /*
  2. * ====================================================================
  3. * Licensed to the Apache Software Foundation (ASF) under one or more
  4. * contributor license agreements. See the NOTICE file distributed with
  5. * this work for additional information regarding copyright ownership.
  6. * The ASF licenses this file to You under the Apache License, Version 2.0
  7. * (the "License"); you may not use this file except in compliance with
  8. * the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. * ====================================================================
  18. */
  19. package org.apache.poi.xslf.usermodel;
  20. import static java.util.Arrays.asList;
  21. import static org.junit.Assume.assumeFalse;
  22. import java.io.File;
  23. import java.util.ArrayList;
  24. import java.util.Collection;
  25. import java.util.List;
  26. import java.util.function.Function;
  27. import java.util.stream.Collectors;
  28. import java.util.stream.Stream;
  29. import org.apache.poi.POIDataSamples;
  30. import org.apache.poi.xslf.util.PPTX2PNG;
  31. import org.junit.BeforeClass;
  32. import org.junit.Test;
  33. import org.junit.runner.RunWith;
  34. import org.junit.runners.Parameterized;
  35. import org.junit.runners.Parameterized.Parameter;
  36. import org.junit.runners.Parameterized.Parameters;
  37. /**
  38. * Test class for testing PPTX2PNG utility which renders .ppt and .pptx slideshows
  39. */
  40. @SuppressWarnings("ConstantConditions")
  41. @RunWith(Parameterized.class)
  42. public class TestPPTX2PNG {
  43. private static boolean xslfOnly;
  44. private static final POIDataSamples samples = POIDataSamples.getSlideShowInstance();
  45. private static final File basedir = null;
  46. private static final String files =
  47. "bug64693.pptx, 53446.ppt, alterman_security.ppt, alterman_security.pptx, KEY02.pptx, themes.pptx, " +
  48. "backgrounds.pptx, layouts.pptx, sample.pptx, shapes.pptx, 54880_chinese.ppt, keyframes.pptx," +
  49. "customGeo.pptx, customGeo.ppt, wrench.emf, santa.wmf, missing-moveto.ppt, " +
  50. "64716_image1.wmf, 64716_image2.wmf, 64716_image3.wmf";
  51. @BeforeClass
  52. public static void checkHslf() {
  53. try {
  54. Class.forName("org.apache.poi.hslf.usermodel.HSLFSlideShow");
  55. } catch (Exception e) {
  56. xslfOnly = true;
  57. }
  58. }
  59. // use filename instead of File object to omit full pathname in test name
  60. @Parameter
  61. public String pptFile;
  62. @Parameters(name="{0}")
  63. public static Collection<String> data() {
  64. Function<String, Stream<String>> fun = (basedir == null) ? Stream::of :
  65. (f) -> Stream.of(basedir.listFiles(p -> p.getName().matches(f))).map(File::getName);
  66. return Stream.of(files.split(", ?")).flatMap(fun).collect(Collectors.toList());
  67. }
  68. @Test
  69. public void render() throws Exception {
  70. assumeFalse("ignore HSLF (.ppt) / HEMF (.emf) / HWMF (.wmf) files in no-scratchpad run", xslfOnly && pptFile.matches(".*\\.(ppt|emf|wmf)$"));
  71. // bug64693.pptx
  72. final List<String> args = new ArrayList<>(asList(
  73. "-format", "null", // png,gif,jpg,svg or null for test
  74. "-slide", "-1", // -1 for all
  75. "-outdir", new File("build/tmp/").getCanonicalPath(),
  76. "-outpat", "${basename}-${slideno}-${ext}.${format}",
  77. // "-dump", new File("build/tmp/", pptFile+".json").getCanonicalPath(),
  78. "-dump", "null",
  79. "-quiet",
  80. "-fixside", "long",
  81. "-scale", "800"
  82. ));
  83. if ("bug64693.pptx".equals(pptFile)) {
  84. args.addAll(asList(
  85. "-charset", "GBK"
  86. ));
  87. }
  88. args.add((basedir == null ? samples.getFile(pptFile) : new File(basedir, pptFile)).getAbsolutePath());
  89. PPTX2PNG.main(args.toArray(new String[0]));
  90. }
  91. }