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.

TestPPTXMLDump.java 3.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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.hslf.dev;
  16. import org.apache.poi.EmptyFileException;
  17. import org.apache.poi.hslf.HSLFTestDataSamples;
  18. import org.junit.jupiter.api.Test;
  19. import java.io.File;
  20. import java.io.FileNotFoundException;
  21. import java.io.IOException;
  22. import java.util.Collections;
  23. import java.util.HashSet;
  24. import java.util.Set;
  25. import static org.junit.jupiter.api.Assertions.assertThrows;
  26. public class TestPPTXMLDump extends BaseTestPPTIterating {
  27. static final Set<String> LOCAL_EXCLUDED = new HashSet<>();
  28. static {
  29. LOCAL_EXCLUDED.add("clusterfuzz-testcase-minimized-POIHSLFFuzzer-5306877435838464.ppt");
  30. LOCAL_EXCLUDED.add("clusterfuzz-testcase-minimized-POIHSLFFuzzer-6032591399288832.ppt");
  31. LOCAL_EXCLUDED.add("clusterfuzz-testcase-minimized-POIHSLFFuzzer-6360479850954752.ppt");
  32. LOCAL_EXCLUDED.add("ppt_with_png_encrypted.ppt");
  33. }
  34. @Test
  35. void testMain() throws Exception {
  36. PPTXMLDump.main(new String[0]);
  37. PPTXMLDump.main(new String[]{
  38. HSLFTestDataSamples.getSampleFile("slide_master.ppt").getAbsolutePath(),
  39. HSLFTestDataSamples.getSampleFile("pictures.ppt").getAbsolutePath()
  40. });
  41. assertThrows(EmptyFileException.class, () -> PPTXMLDump.main(new String[]{"invalidfile"}));
  42. }
  43. @Override
  44. void runOneFile(File pFile) throws Exception {
  45. try {
  46. PPTXMLDump.main(new String[]{pFile.getAbsolutePath()});
  47. if (LOCAL_EXCLUDED.contains(pFile.getName())) {
  48. throw new IllegalStateException("Expected failure for file " + pFile + ", but processing did not throw an exception");
  49. }
  50. } catch (IndexOutOfBoundsException | IOException e) {
  51. if (!LOCAL_EXCLUDED.contains(pFile.getName())) {
  52. throw e;
  53. }
  54. }
  55. // work around two files which works here but not in other tests
  56. if (pFile.getName().equals("clusterfuzz-testcase-minimized-POIFuzzer-5429732352851968.ppt") ||
  57. pFile.getName().equals("clusterfuzz-testcase-minimized-POIFuzzer-5681320547975168.ppt") ||
  58. pFile.getName().equals("clusterfuzz-testcase-minimized-POIHSLFFuzzer-5231088823566336.ppt") ||
  59. pFile.getName().equals("clusterfuzz-testcase-minimized-POIFuzzer-6411649193738240.ppt") ||
  60. pFile.getName().equals("clusterfuzz-testcase-minimized-POIHSLFFuzzer-4838893004128256.ppt")) {
  61. throw new FileNotFoundException();
  62. }
  63. }
  64. @Override
  65. protected Set<String> getFailedEncryptedFiles() {
  66. return Collections.emptySet();
  67. }
  68. @Override
  69. protected Set<String> getFailedOldFiles() {
  70. return Collections.emptySet();
  71. }
  72. }