aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--build.gradle14
-rw-r--r--build.xml21
-rw-r--r--gradle/wrapper/gradle-wrapper.properties2
-rw-r--r--jenkins/create_jobs.groovy21
-rw-r--r--poi-scratchpad/src/main/java/org/apache/poi/hslf/usermodel/HSLFFill.java4
-rw-r--r--poi-scratchpad/src/main/java/org/apache/poi/hslf/usermodel/HSLFPictureShape.java4
-rw-r--r--poi-scratchpad/src/test/java/org/apache/poi/hslf/usermodel/TestBugs.java29
-rw-r--r--poi/src/main/java/org/apache/poi/util/DefaultTempFileCreationStrategy.java22
-rw-r--r--poi/src/main/java/org/apache/poi/util/TempFile.java2
-rw-r--r--poi/src/test/java/org/apache/poi/util/DefaultTempFileCreationStrategyTest.java70
-rw-r--r--test-data/slideshow/bug69697.pptbin0 -> 63488 bytes
11 files changed, 135 insertions, 54 deletions
diff --git a/build.gradle b/build.gradle
index 7f64600b0c..4abebdb9b5 100644
--- a/build.gradle
+++ b/build.gradle
@@ -34,7 +34,7 @@ plugins {
id 'com.dorongold.task-tree' version '4.0.1'
id 'org.nosphere.apache.rat' version '0.8.1'
id 'distribution'
- id 'com.github.spotbugs' version '6.1.13'
+ id 'com.github.spotbugs' version '6.1.13' // 6.2.0+ requires JDK 11
id 'de.thetaphi.forbiddenapis' version '3.9'
id 'org.sonarqube' version '4.0.0.2929'
id 'org.cyclonedx.bom' version '2.3.1'
@@ -67,7 +67,7 @@ configurations {
}
dependencies {
- antLibs("org.junit.jupiter:junit-jupiter:5.13.0")
+ antLibs("org.junit.jupiter:junit-jupiter:5.13.1")
antLibs("org.apache.ant:ant-junitlauncher:1.10.15")
}
@@ -77,7 +77,7 @@ ant.taskdef(name: "junit",
wrapper {
- gradleVersion = '8.14.1'
+ gradleVersion = '8.14.2'
}
group = 'org.apache.poi'
@@ -112,7 +112,7 @@ subprojects {
commonsCompressVersion = '1.27.1'
commonsIoVersion = '2.19.0'
commonsMathVersion = '3.6.1'
- junitVersion = '5.13.0'
+ junitVersion = '5.13.1'
log4jVersion = '2.24.3'
mockitoVersion = '4.11.0'
hamcrestVersion = '3.0'
@@ -172,7 +172,7 @@ subprojects {
dependencies {
testImplementation "org.junit.jupiter:junit-jupiter:${junitVersion}"
- testRuntimeOnly 'org.junit.platform:junit-platform-launcher:1.13.0'
+ testRuntimeOnly 'org.junit.platform:junit-platform-launcher:1.13.1'
testImplementation "org.mockito:mockito-core:${mockitoVersion}"
testImplementation "org.hamcrest:hamcrest:${hamcrestVersion}"
testImplementation "org.apache.logging.log4j:log4j-core:${log4jVersion}"
@@ -422,7 +422,7 @@ subprojects {
jvmArgs += [
// see https://github.com/java9-modularity/gradle-modules-plugin/issues/97
// opposed to the recommendation there, it doesn't work to add ... to the dependencies
- // testRuntimeOnly 'org.junit.platform:junit-platform-launcher:1.13.0'
+ // testRuntimeOnly 'org.junit.platform:junit-platform-launcher:1.13.1'
// gradles gradle-worker.jar is still not a JPMS module and thus runs as unnamed module
'--add-exports','org.junit.platform.commons/org.junit.platform.commons.util=org.apache.poi.poi',
'--add-exports','org.junit.platform.commons/org.junit.platform.commons.util=ALL-UNNAMED',
@@ -444,7 +444,7 @@ subprojects {
}
jacoco {
- toolVersion = '0.8.12'
+ toolVersion = '0.8.13'
}
jacocoTestReport {
diff --git a/build.xml b/build.xml
index ca5c5c53f1..c4efa8b8b3 100644
--- a/build.xml
+++ b/build.xml
@@ -270,14 +270,14 @@ under the License.
<dependency prefix="main.com.zaxxer" artifact="com.zaxxer:SparseBitSet:1.3" usage="main"/>
<dependency prefix="main.log4j-api" artifact="org.apache.logging.log4j:log4j-api:2.24.3" usage="main"/>
- <dependency prefix="main.junit-api" artifact="org.junit.jupiter:junit-jupiter-api:5.13.0" usage="main-tests"/>
- <dependency prefix="main.junit-jengine" artifact="org.junit.jupiter:junit-jupiter-engine:5.13.0" usage="main-tests"/>
- <dependency prefix="main.junit-params" artifact="org.junit.jupiter:junit-jupiter-params:5.13.0" usage="main-tests"/>
+ <dependency prefix="main.junit-api" artifact="org.junit.jupiter:junit-jupiter-api:5.13.1" usage="main-tests"/>
+ <dependency prefix="main.junit-jengine" artifact="org.junit.jupiter:junit-jupiter-engine:5.13.1" usage="main-tests"/>
+ <dependency prefix="main.junit-params" artifact="org.junit.jupiter:junit-jupiter-params:5.13.1" usage="main-tests"/>
<dependency prefix="main.junit-opentest4j" artifact="org.opentest4j:opentest4j:1.2.0" usage="main-tests"/>
<dependency prefix="main.junit-apiguardian" artifact="org.apiguardian:apiguardian-api:1.1.2" usage="main-tests"/>
- <dependency prefix="main.junit-pcommons" artifact="org.junit.platform:junit-platform-commons:1.13.0" usage="main-tests"/>
- <dependency prefix="main.junit-pengine" artifact="org.junit.platform:junit-platform-engine:1.13.0" usage="main-tests"/>
- <dependency prefix="main.junit-plauncher" artifact="org.junit.platform:junit-platform-launcher:1.13.0" usage="main-tests"/>
+ <dependency prefix="main.junit-pcommons" artifact="org.junit.platform:junit-platform-commons:1.13.1" usage="main-tests"/>
+ <dependency prefix="main.junit-pengine" artifact="org.junit.platform:junit-platform-engine:1.13.1" usage="main-tests"/>
+ <dependency prefix="main.junit-plauncher" artifact="org.junit.platform:junit-platform-launcher:1.13.1" usage="main-tests"/>
<dependency prefix="main.jmh" artifact="org.openjdk.jmh:jmh-core:1.35" usage="main-tests"/>
@@ -305,7 +305,7 @@ under the License.
<!-- svg/batik/pdf libs - not part of the distribution - move batik to its own directory because of JPMS module-path issues -->
<dependency prefix="svg.xml-apis-ext" artifact="xml-apis:xml-apis-ext:1.3.04" usage="ooxml-batik"/>
- <dependency prefix="svg.xmlgraphics-commons" artifact="org.apache.xmlgraphics:xmlgraphics-commons:2.9" usage="ooxml-batik"/>
+ <dependency prefix="svg.xmlgraphics-commons" artifact="org.apache.xmlgraphics:xmlgraphics-commons:2.11" usage="ooxml-batik"/>
<dependency prefix="svg.batik-anim" artifact="org.apache.xmlgraphics:batik-anim:1.19" usage="ooxml-batik"/>
<dependency prefix="svg.batik-awt-util" artifact="org.apache.xmlgraphics:batik-awt-util:1.19" usage="ooxml-batik"/>
<dependency prefix="svg.batik-bridge" artifact="org.apache.xmlgraphics:batik-bridge:1.19" usage="ooxml-batik"/>
@@ -339,12 +339,13 @@ under the License.
<!-- jars in the ooxml-test-lib directory, see the fetch-ooxml-jars target-->
<dependency prefix="ooxml.test.reflections" artifact="org.reflections:reflections:0.10.2" usage="ooxml-tests"/>
<dependency prefix="ooxml.test.guava" artifact="com.google.guava:guava:33.4.8-jre" usage="ooxml-tests"/>
+ <dependency prefix="ooxml.test.guava.failureaccess" artifact="com.google.guava:failureaccess:1.0.3" usage="ooxml-tests"/>
<dependency prefix="ooxml.test.javassist" artifact="org.javassist:javassist:3.27.0-GA" usage="ooxml-tests"/>
<dependency prefix="ooxml.test.slf4j-api" artifact="org.slf4j:slf4j-api:2.0.17" usage="ooxml-tests"/>
<dependency prefix="ooxml.test.opczip" artifact="com.github.rzymek:opczip:1.2.0" usage="ooxml-tests"/>
<!-- coverage libs -->
- <dependency prefix="jacoco" artifact="org.jacoco:jacoco:0.8.12" usage="util" packaging="zip"/>
+ <dependency prefix="jacoco" artifact="org.jacoco:jacoco:0.8.13" usage="util" packaging="zip"/>
<dependency prefix="asm" artifact="org.ow2.asm:asm:9.5" usage="util"/>
<dependency prefix="asm-commons" artifact="org.ow2.asm:asm-commons:9.5" usage="util"/>
<dependency prefix="asm-tree" artifact="org.ow2.asm:asm-tree:9.5" usage="util"/>
@@ -463,6 +464,7 @@ under the License.
<path refid="main.classpath"/>
<pathelement location="${main.output.dir}"/>
<pathelement location="${ooxml.test.guava.jar}"/>
+ <pathelement location="${ooxml.test.guava.failureaccess.jar}"/>
<pathelement location="${ooxml.test.opczip.jar}"/>
<!-- classes are omitted on test cases outside the xml-dsign area to avoid classpath poisoning -->
<!--path refid="ooxml.xmlsec.classpath"/-->
@@ -516,6 +518,7 @@ under the License.
<path id="test.ooxml.reflections.classpath">
<pathelement location="${ooxml.test.reflections.jar}"/>
<pathelement location="${ooxml.test.guava.jar}"/>
+ <pathelement location="${ooxml.test.guava.failureaccess.jar}"/>
<pathelement location="${ooxml.test.javassist.jar}"/>
</path>
@@ -834,6 +837,7 @@ under the License.
<available file="${ooxml.commons-lang3.jar}"/>
<available file="${ooxml.test.reflections.jar}"/>
<available file="${ooxml.test.guava.jar}"/>
+ <available file="${ooxml.test.guava.failureaccess.jar}"/>
<available file="${ooxml.test.javassist.jar}"/>
<available file="${ooxml.test.slf4j-api.jar}"/>
<available file="${ooxml.test.opczip.jar}"/>
@@ -877,6 +881,7 @@ under the License.
<downloadfile src="${ooxml.commons-lang3.url}" dest="${ooxml.commons-lang3.jar}"/>
<downloadfile src="${ooxml.test.reflections.url}" dest="${ooxml.test.reflections.jar}"/>
<downloadfile src="${ooxml.test.guava.url}" dest="${ooxml.test.guava.jar}"/>
+ <downloadfile src="${ooxml.test.guava.failureaccess.url}" dest="${ooxml.test.guava.failureaccess.jar}"/>
<downloadfile src="${ooxml.test.javassist.url}" dest="${ooxml.test.javassist.jar}"/>
<downloadfile src="${ooxml.test.slf4j-api.url}" dest="${ooxml.test.slf4j-api.jar}"/>
<downloadfile src="${ooxml.test.opczip.url}" dest="${ooxml.test.opczip.jar}"/>
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
index 002b867c48..ff23a68d70 100644
--- a/gradle/wrapper/gradle-wrapper.properties
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.1-bin.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.2-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
diff --git a/jenkins/create_jobs.groovy b/jenkins/create_jobs.groovy
index 6522e32de9..d112999d2c 100644
--- a/jenkins/create_jobs.groovy
+++ b/jenkins/create_jobs.groovy
@@ -35,10 +35,13 @@ def poijobs = [
disabled: true
],
[ name: 'POI-DSL-1.23', jdk: '1.23', trigger: triggerSundays, skipcigame: true,
+ // let's save some CPU cycles here, 22 is not an LTS and JDK 23/24 is out
+ disabled: true
],
- // Jenkins on ci-builds.apache.org does not support spotbugs with a new enough version of asm for Java24+
- [ name: 'POI-DSL-1.24', jdk: '1.24', trigger: triggerSundays, skipcigame: true, skipSpotbugs: true,
- // use Ant for building until Gradle supports JDK 24
+ [ name: 'POI-DSL-1.24', jdk: '1.24', trigger: triggerSundays, skipcigame: true,
+ ],
+ [ name: 'POI-DSL-1.25', jdk: '1.25', trigger: triggerSundays, skipcigame: true, skipSpotbugs: true,
+ // use Ant for building until Gradle supports JDK 25
// see https://docs.gradle.org/current/userguide/compatibility.html
// and https://github.com/gradle/gradle/issues/31625
useAnt: true
@@ -87,9 +90,14 @@ def poijobs = [
// let's save some CPU cycles here, 22 is not an LTS and JDK 23/24 is out
disabled: true
],
- [ name: 'POI-DSL-Windows-1.23', jdk: '1.23', trigger: triggerSundays, windows: true, slaves: 'Windows', skipcigame: true
+ [ name: 'POI-DSL-Windows-1.23', jdk: '1.23', trigger: triggerSundays, windows: true, slaves: 'Windows', skipcigame: true,
+ // let's save some CPU cycles here, 22 is not an LTS and JDK 23/24 is out
+ disabled: true
],
[ name: 'POI-DSL-Windows-1.24', jdk: '1.24', trigger: triggerSundays, windows: true, slaves: 'Windows', skipcigame: true,
+ ],
+ [ name: 'POI-DSL-Windows-1.25', jdk: '1.25', trigger: triggerSundays, windows: true, slaves: 'Windows', skipcigame: true,
+ skipSpotbugs: true,
// use Ant for building until Gradle supports JDK 24
// see https://docs.gradle.org/current/userguide/compatibility.html
// and https://github.com/gradle/gradle/issues/31625
@@ -116,6 +124,8 @@ def xmlbeansjobs = [
],
[ name: 'POI-XMLBeans-DSL-1.24', jdk: '1.24', trigger: triggerSundays, skipcigame: true,
],
+ [ name: 'POI-XMLBeans-DSL-1.25', jdk: '1.25', trigger: triggerSundays, skipcigame: true,
+ ],
[ name: 'POI-XMLBeans-DSL-Sonar', jdk: '1.17', trigger: triggerSundays, skipcigame: true,
sonar: true
]
@@ -144,6 +154,7 @@ def jdkMapping = [
'1.22': [ jenkinsJdk: 'jdk_22_latest', jdkVersion: 22, jdkVendor: '' ],
'1.23': [ jenkinsJdk: 'jdk_23_latest', jdkVersion: 23, jdkVendor: '' ],
'1.24': [ jenkinsJdk: 'jdk_24_latest', jdkVersion: 24, jdkVendor: '' ],
+ '1.25': [ jenkinsJdk: 'jdk_25_latest', jdkVersion: 25, jdkVendor: '' ],
'OpenJDK 1.8': [ jenkinsJdk: 'adoptopenjdk_hotspot_8u282', jdkVersion: 8, jdkVendor: 'adoptopenjdk' ],
'IBMJDK': [ jenkinsJdk: 'ibmjdk_1.8.0_261', jdkVersion: 8, jdkVendor: 'ibm' ]
]
@@ -612,6 +623,8 @@ Unfortunately we often see builds break because of changes/new machines...''')
'jdk_22_latest',
'jdk_23_latest',
'jdk_24_latest',
+ 'jdk_25_latest',
+ 'jdk_26_latest',
'adoptopenjdk_hotspot_8u282',
'ibmjdk_1.8.0_261'
)
diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hslf/usermodel/HSLFFill.java b/poi-scratchpad/src/main/java/org/apache/poi/hslf/usermodel/HSLFFill.java
index 3f9f84b6d6..3a8c767e6d 100644
--- a/poi-scratchpad/src/main/java/org/apache/poi/hslf/usermodel/HSLFFill.java
+++ b/poi-scratchpad/src/main/java/org/apache/poi/hslf/usermodel/HSLFFill.java
@@ -576,9 +576,7 @@ public final class HSLFFill {
} else {
EscherBSERecord bse = (EscherBSERecord) bstore.getChild(idx - 1);
for (HSLFPictureData pd : pict) {
-
- // Reference equals is safe because these BSE belong to the same slideshow
- if (pd.bse == bse) {
+ if (pd.getOffset() == bse.getOffset()) {
return pd;
}
}
diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hslf/usermodel/HSLFPictureShape.java b/poi-scratchpad/src/main/java/org/apache/poi/hslf/usermodel/HSLFPictureShape.java
index 71e67084e1..e10a54cb55 100644
--- a/poi-scratchpad/src/main/java/org/apache/poi/hslf/usermodel/HSLFPictureShape.java
+++ b/poi-scratchpad/src/main/java/org/apache/poi/hslf/usermodel/HSLFPictureShape.java
@@ -124,9 +124,7 @@ public class HSLFPictureShape extends HSLFSimpleShape implements PictureShape<HS
LOG.atError().log("no reference to picture data found ");
} else {
for (HSLFPictureData pd : pict) {
-
- // Reference equals is safe because these BSE belong to the same slideshow
- if (pd.bse == bse) {
+ if (pd.getOffset() == bse.getOffset()) {
return pd;
}
}
diff --git a/poi-scratchpad/src/test/java/org/apache/poi/hslf/usermodel/TestBugs.java b/poi-scratchpad/src/test/java/org/apache/poi/hslf/usermodel/TestBugs.java
index 1cd5be3cf6..575d443b5b 100644
--- a/poi-scratchpad/src/test/java/org/apache/poi/hslf/usermodel/TestBugs.java
+++ b/poi-scratchpad/src/test/java/org/apache/poi/hslf/usermodel/TestBugs.java
@@ -68,19 +68,10 @@ import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.poifs.macros.VBAMacroReader;
import org.apache.poi.sl.draw.DrawPaint;
import org.apache.poi.sl.extractor.SlideShowExtractor;
-import org.apache.poi.sl.usermodel.ColorStyle;
-import org.apache.poi.sl.usermodel.PaintStyle;
+import org.apache.poi.sl.usermodel.*;
import org.apache.poi.sl.usermodel.PaintStyle.SolidPaint;
import org.apache.poi.sl.usermodel.PictureData.PictureType;
-import org.apache.poi.sl.usermodel.Placeholder;
-import org.apache.poi.sl.usermodel.ShapeType;
-import org.apache.poi.sl.usermodel.Slide;
-import org.apache.poi.sl.usermodel.SlideShow;
-import org.apache.poi.sl.usermodel.SlideShowFactory;
-import org.apache.poi.sl.usermodel.TextBox;
-import org.apache.poi.sl.usermodel.TextParagraph;
import org.apache.poi.sl.usermodel.TextParagraph.TextAlign;
-import org.apache.poi.sl.usermodel.TextRun;
import org.apache.poi.util.LittleEndian;
import org.apache.poi.util.StringUtil;
import org.apache.poi.util.Units;
@@ -904,4 +895,22 @@ public final class TestBugs {
assertEquals(ShapeType.NOT_PRIMITIVE, shList.get(2).getShapeType());
}
}
+
+ @Test
+ void test69697() throws Exception {
+ try (HSLFSlideShow ppt = open("bug69697.ppt")) {
+ HSLFSlide slide = ppt.getSlides().get(0);
+ for (HSLFShape sh : slide.getShapes()) {
+ if (sh instanceof HSLFPictureShape) {
+ HSLFPictureShape pict = (HSLFPictureShape) sh;
+ HSLFPictureData pictData = pict.getPictureData();
+ assertNotNull(pictData, "PictureData should not be null for shape: " + pict.getShapeName());
+ byte[] data = pictData.getData();
+ assertNotNull(data, "Picture data should not be null for shape: " + pict.getShapeName());
+ PictureData.PictureType type = pictData.getType();
+ assertNotNull(type, "Picture type should not be null for shape: " + pict.getShapeName());
+ }
+ }
+ }
+ }
}
diff --git a/poi/src/main/java/org/apache/poi/util/DefaultTempFileCreationStrategy.java b/poi/src/main/java/org/apache/poi/util/DefaultTempFileCreationStrategy.java
index 9b2e711ed4..584f7dec4c 100644
--- a/poi/src/main/java/org/apache/poi/util/DefaultTempFileCreationStrategy.java
+++ b/poi/src/main/java/org/apache/poi/util/DefaultTempFileCreationStrategy.java
@@ -52,6 +52,9 @@ public class DefaultTempFileCreationStrategy implements TempFileCreationStrategy
/** The directory where the temporary files will be created (<code>null</code> to use the default directory). */
private volatile File dir;
+ /** The directory where that was passed to the constructor (<code>null</code> to use the default directory). */
+ private final File initDir;
+
/** The lock to make dir initialized only once. */
private final Lock dirLock = new ReentrantLock();
@@ -65,14 +68,23 @@ public class DefaultTempFileCreationStrategy implements TempFileCreationStrategy
}
/**
- * Creates the strategy allowing to set the
+ * Creates the strategy allowing to set a custom directory for the temporary files.
+ * <p>
+ * If you provide a non-null dir as input, it must be a directory (if it already exists).
+ * Since POI 5.4.2, this is checked at construction time. In previous versions, it was checked
+ * at the first call to {@link #createTempFile(String, String)} or {@link #createTempDirectory(String)}.
+ * </p>
*
* @param dir The directory where the temporary files will be created (<code>null</code> to use the default directory).
- *
+ * @throws IllegalArgumentException if the provided directory does not exist or is not a directory
* @see Files#createTempFile(Path, String, String, FileAttribute[])
*/
public DefaultTempFileCreationStrategy(File dir) {
+ this.initDir = dir;
this.dir = dir;
+ if (dir != null && dir.exists() && !dir.isDirectory()) {
+ throw new IllegalArgumentException("The provided file is not a directory: " + dir);
+ }
}
@Override
@@ -117,7 +129,11 @@ public class DefaultTempFileCreationStrategy implements TempFileCreationStrategy
}
protected Path getPOIFilesDirectoryPath() throws IOException {
- return Paths.get(getJavaIoTmpDir(), POIFILES);
+ if (initDir == null) {
+ return Paths.get(getJavaIoTmpDir(), POIFILES);
+ } else {
+ return initDir.toPath();
+ }
}
// Create our temp dir only once by double-checked locking
diff --git a/poi/src/main/java/org/apache/poi/util/TempFile.java b/poi/src/main/java/org/apache/poi/util/TempFile.java
index 46bf8ccc8b..e5456b13bd 100644
--- a/poi/src/main/java/org/apache/poi/util/TempFile.java
+++ b/poi/src/main/java/org/apache/poi/util/TempFile.java
@@ -27,7 +27,7 @@ public final class TempFile {
/** The strategy used by {@link #createTempFile(String, String)} to create the temporary files. */
private static TempFileCreationStrategy strategy = new DefaultTempFileCreationStrategy();
- /** Define a constant for this property as it is sometimes mistypes as "tempdir" otherwise */
+ /** Define a constant for this property as it is sometimes mistyped as "tempdir" otherwise */
public static final String JAVA_IO_TMPDIR = "java.io.tmpdir";
private TempFile() {
diff --git a/poi/src/test/java/org/apache/poi/util/DefaultTempFileCreationStrategyTest.java b/poi/src/test/java/org/apache/poi/util/DefaultTempFileCreationStrategyTest.java
index 4e4f6b779e..acbf7e5ece 100644
--- a/poi/src/test/java/org/apache/poi/util/DefaultTempFileCreationStrategyTest.java
+++ b/poi/src/test/java/org/apache/poi/util/DefaultTempFileCreationStrategyTest.java
@@ -20,11 +20,14 @@ package org.apache.poi.util;
import static org.apache.poi.util.DefaultTempFileCreationStrategy.DELETE_FILES_ON_EXIT;
import static org.apache.poi.util.DefaultTempFileCreationStrategy.POIFILES;
import static org.apache.poi.util.TempFile.JAVA_IO_TMPDIR;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.File;
import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
import org.apache.commons.io.FileUtils;
import org.junit.jupiter.api.AfterEach;
@@ -59,9 +62,61 @@ class DefaultTempFileCreationStrategyTest {
checkGetFile(strategy);
}
+ @Test
+ void testProvidedDir() throws IOException {
+ DefaultTempFileCreationStrategy parentStrategy = new DefaultTempFileCreationStrategy();
+ File dir = parentStrategy.createTempDirectory("testProvidedDir");
+ assertNotNull(dir, "Failed to create temp directory");
+ try {
+ assertTrue(Files.isDirectory(dir.toPath()), "File is not a directory: " + dir);
+ DefaultTempFileCreationStrategy testStrategy = new DefaultTempFileCreationStrategy(dir);
+ checkGetFileAndPath(testStrategy, dir.toPath());
+ } finally {
+ // Clean up the directory after the test
+ FileUtils.deleteDirectory(dir);
+ }
+ }
+
+ @Test
+ void testProvidedDirNotExists() throws IOException {
+ DefaultTempFileCreationStrategy parentStrategy = new DefaultTempFileCreationStrategy();
+ File dir = parentStrategy.createTempDirectory("testProvidedDir");
+ assertNotNull(dir, "Failed to create temp directory");
+ assertTrue(dir.delete(), "directory not deleted: " + dir);
+ try {
+ DefaultTempFileCreationStrategy testStrategy = new DefaultTempFileCreationStrategy(dir);
+ checkGetFileAndPath(testStrategy, dir.toPath());
+ } finally {
+ // Clean up the directory after the test
+ FileUtils.deleteDirectory(dir);
+ }
+ }
+
+ @Test
+ void testProvidedDirIsActuallyAPlainFile() throws IOException {
+ DefaultTempFileCreationStrategy parentStrategy = new DefaultTempFileCreationStrategy();
+ File dir = parentStrategy.createTempFile("test123", ".tmp");
+ assertNotNull(dir, "Failed to create temp file");
+ try {
+ assertThrows(IllegalArgumentException.class, () -> new DefaultTempFileCreationStrategy(dir));
+ } finally {
+ dir.delete();
+ }
+ }
+
private static void checkGetFile(DefaultTempFileCreationStrategy strategy) throws IOException {
+ checkGetFileAndPath(strategy, null);
+ }
+
+ private static void checkGetFileAndPath(DefaultTempFileCreationStrategy strategy,
+ Path path) throws IOException {
File file = strategy.createTempFile("POITest", ".tmp");
try {
+ if (path != null) {
+ assertTrue(file.toPath().startsWith(path),
+ "File path does not start with expected path: " + path);
+ }
+
assertTrue(file.getParentFile().exists(),
"Failed for " + file.getParentFile());
@@ -106,19 +161,6 @@ class DefaultTempFileCreationStrategyTest {
}
@Test
- void testCustomDir() throws IOException {
- File dirTest = File.createTempFile("POITest", ".dir");
- try {
- assertTrue(dirTest.delete());
-
- DefaultTempFileCreationStrategy strategy = new DefaultTempFileCreationStrategy(dirTest);
- checkGetFile(strategy);
- } finally {
- FileUtils.deleteDirectory(dirTest);
- }
- }
-
- @Test
void testCustomDirExists() throws IOException {
File dirTest = File.createTempFile("POITest", ".dir");
try {
@@ -146,4 +188,4 @@ class DefaultTempFileCreationStrategyTest {
FileUtils.deleteDirectory(dirTest);
}
}
-} \ No newline at end of file
+}
diff --git a/test-data/slideshow/bug69697.ppt b/test-data/slideshow/bug69697.ppt
new file mode 100644
index 0000000000..ff2cdcfbb8
--- /dev/null
+++ b/test-data/slideshow/bug69697.ppt
Binary files differ