aboutsummaryrefslogtreecommitdiffstats
path: root/poi-ooxml/src
diff options
context:
space:
mode:
Diffstat (limited to 'poi-ooxml/src')
-rw-r--r--poi-ooxml/src/test/java/org/apache/poi/xslf/usermodel/TestPPTX2PNG.java93
1 files changed, 72 insertions, 21 deletions
diff --git a/poi-ooxml/src/test/java/org/apache/poi/xslf/usermodel/TestPPTX2PNG.java b/poi-ooxml/src/test/java/org/apache/poi/xslf/usermodel/TestPPTX2PNG.java
index 4226b28095..c94cf59580 100644
--- a/poi-ooxml/src/test/java/org/apache/poi/xslf/usermodel/TestPPTX2PNG.java
+++ b/poi-ooxml/src/test/java/org/apache/poi/xslf/usermodel/TestPPTX2PNG.java
@@ -25,13 +25,20 @@ import static org.junit.jupiter.api.Assumptions.assumeFalse;
import java.io.File;
import java.io.IOException;
+import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
-import java.util.function.Function;
+import java.util.Locale;
import java.util.stream.Stream;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipFile;
+import org.apache.commons.compress.archivers.sevenz.SevenZArchiveEntry;
+import org.apache.commons.compress.archivers.sevenz.SevenZFile;
import org.apache.poi.POIDataSamples;
+import org.apache.poi.poifs.filesystem.FileMagic;
import org.apache.poi.xslf.util.PPTX2PNG;
+import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
@@ -44,6 +51,7 @@ import org.junit.jupiter.params.provider.MethodSource;
class TestPPTX2PNG {
private static boolean xslfOnly;
private static final POIDataSamples samples = POIDataSamples.getSlideShowInstance();
+
private static final File basedir = null;
private static final String files =
@@ -58,38 +66,55 @@ class TestPPTX2PNG {
private static final String pdfFiles =
"alterman_security.ppt";
+ private static InputStream defStdin;
+
@BeforeAll
- public static void checkHslf() {
+ public static void init() {
try {
Class.forName("org.apache.poi.hslf.usermodel.HSLFSlideShow");
} catch (Exception e) {
xslfOnly = true;
}
+ defStdin = System.in;
}
- public static Stream<Arguments> data() {
- Function<String, Stream<Arguments>> fun = (basedir == null)
- ? (f) -> Stream.of(Arguments.of(f))
- : (f) -> Stream.of(basedir.listFiles(p -> p.getName().matches(f))).map(File::getName).map(Arguments::of);
+ @AfterAll
+ public static void resetStdin() {
+ System.setIn(defStdin);
+ }
- return Stream.of(files.split(", ?")).flatMap(fun);
+ public static Stream<Arguments> data() throws IOException {
+ if (basedir != null && basedir.getName().endsWith(".zip")) {
+ ZipFile zipFile = new ZipFile(basedir);
+ return zipFile.stream().map(f -> Arguments.of(f.getName(), f, zipFile));
+ } else if (basedir != null && basedir.getName().endsWith(".7z")) {
+ SevenZFile sevenZFile = new SevenZFile(basedir);
+ return ((ArrayList<SevenZArchiveEntry>)sevenZFile.getEntries()).stream().filter(f -> !f.isDirectory()).map(f -> Arguments.of(f.getName(), f, sevenZFile));
+ } else {
+ return Stream.of(files.split(", ?")).
+ map(basedir == null ? samples::getFile : f -> new File(basedir, f)).
+ map(f -> Arguments.of(f.getName(), f, f.getParentFile()));
+ }
}
// use filename instead of File object to omit full pathname in test name
- @ParameterizedTest
+ @ParameterizedTest(name = "{0} ({index})")
@MethodSource("data")
- void render(String pptFile) throws Exception {
- assumeFalse(xslfOnly && pptFile.matches(".*\\.(ppt|emf|wmf)$"), "ignore HSLF (.ppt) / HEMF (.emf) / HWMF (.wmf) files in no-scratchpad run");
- PPTX2PNG.main(getArgs(pptFile, "null"));
- if (svgFiles.contains(pptFile)) {
- PPTX2PNG.main(getArgs(pptFile, "svg"));
+ void render(String fileName, Object fileObj, Object fileContainer) throws Exception {
+ assumeFalse(xslfOnly && fileName.matches(".*\\.(ppt|emf|wmf)$"), "ignore HSLF (.ppt) / HEMF (.emf) / HWMF (.wmf) files in no-scratchpad run");
+ PPTX2PNG.main(getArgs(fileName, fileObj, fileContainer, "null"));
+ if (svgFiles.contains(fileName)) {
+ PPTX2PNG.main(getArgs(fileName, fileObj, fileContainer, "svg"));
+ }
+ if (pdfFiles.contains(fileName)) {
+ PPTX2PNG.main(getArgs(fileName, fileObj, fileContainer, "pdf"));
}
- if (pdfFiles.contains(pptFile)) {
- PPTX2PNG.main(getArgs(pptFile, "pdf"));
+ if (System.in != defStdin) {
+ System.in.close();
}
}
- private String[] getArgs(String pptFile, String format) throws IOException {
+ private String[] getArgs(String fileName, Object fileObj, Object fileContainer, String format) throws IOException {
File tmpDir = new File("build/tmp/");
// fix maven build errors
@@ -105,20 +130,46 @@ class TestPPTX2PNG {
// "-dump", new File("build/tmp/", pptFile+".json").getCanonicalPath(),
"-dump", "null",
"-quiet",
+ "-ignoreParse",
// "-charset", "GBK",
// "-emfHeaderBounds",
// "-textAsShapes",
+ // "-extractEmbedded",
"-fixside", "long",
"-scale", "800"
));
- if ("bug64693.pptx".equals(pptFile)) {
- args.addAll(asList(
- "-charset", "GBK"
- ));
+ String lName = fileName.toLowerCase(Locale.ROOT);
+ FileMagic inputType = null;
+ if (lName.endsWith(".emf")) {
+ inputType = FileMagic.EMF;
+ } else if (lName.endsWith(".wmf")) {
+ inputType = FileMagic.WMF;
}
- args.add((basedir == null ? samples.getFile(pptFile) : new File(basedir, pptFile)).getAbsolutePath());
+ if (inputType != null) {
+ args.add("-inputtype");
+ args.add(inputType.toString());
+ }
+
+ if (fileName.endsWith("bug64693.pptx")) {
+ args.add("-charset");
+ args.add("GBK");
+ }
+
+ if (fileObj instanceof ZipEntry) {
+ ZipEntry ze = (ZipEntry)fileObj;
+ ZipFile zf = (ZipFile)fileContainer;
+ System.setIn(zf.getInputStream(ze));
+ args.add("stdin");
+ } else if (fileObj instanceof SevenZArchiveEntry) {
+ SevenZArchiveEntry ze = (SevenZArchiveEntry)fileObj;
+ SevenZFile zf = (SevenZFile)fileContainer;
+ System.setIn(zf.getInputStream(ze));
+ args.add("stdin");
+ } else if (fileObj instanceof File) {
+ args.add(((File)fileObj).getAbsolutePath());
+ }
return args.toArray(new String[0]);
}