import java.io.InputStream;
import java.io.PrintStream;
import java.nio.charset.StandardCharsets;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.HashSet;
import java.util.Set;
import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream;
private static final ThreadLocal<File> copyOutput = ThreadLocal.withInitial(HPSFFileHandler::getTempFile);
- static final Set<String> EXCLUDES_HANDLE_ADD = unmodifiableHashSet(
+ static final Set<String> EXCLUDES_HANDLE_ADD = StressTestUtils.unmodifiableHashSet(
"spreadsheet/45290.xls",
"spreadsheet/46904.xls",
"spreadsheet/55982.xls",
"document/word2.doc"
);
- private static Set<String> unmodifiableHashSet(String... a) {
- return Collections.unmodifiableSet(new HashSet<>(Arrays.asList(a)));
- }
-
-
@Override
public void handleFile(InputStream stream, String path) throws Exception {
POIFSFileSystem poifs = new POIFSFileSystem(stream);
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.PushbackInputStream;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.HashSet;
import java.util.Set;
import org.apache.poi.openxml4j.opc.ContentTypes;
import org.junit.jupiter.api.Test;
class OPCFileHandler extends AbstractFileHandler {
- private static final Set<String> EXPECTED_FAILURES = unmodifiableHashSet(
+ private static final Set<String> EXPECTED_FAILURES = StressTestUtils.unmodifiableHashSet(
"document/truncated62886.docx"
);
// ignore password protected files
if (POIXMLDocumentHandler.isEncrypted(stream)) return;
- if (EXPECTED_FAILURES.contains(path)) return;
+ if (StressTestUtils.excludeFile(path, EXPECTED_FAILURES)) return;
OPCPackage p = OPCPackage.open(stream);
handleExtracting(file);
}
-
- private static Set<String> unmodifiableHashSet(String... a) {
- return Collections.unmodifiableSet(new HashSet<>(Arrays.asList(a)));
- }
}
--- /dev/null
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+package org.apache.poi.stress;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+public class StressTestUtils {
+ static Set<String> unmodifiableHashSet(String... a) {
+ return Collections.unmodifiableSet(new HashSet<>(Arrays.asList(a)));
+ }
+
+ static boolean excludeFile(String path, Set<String> excludeSet) {
+ String modifiedPath = path.replace('\\', '/');
+ return excludeSet.contains(modifiedPath);
+ }
+}
==================================================================== */
package org.apache.poi.stress;
-
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
"**/.git/**",
};
- private static final Set<String> EXPECTED_FAILURES = unmodifiableHashSet(
+ private static final Set<String> EXPECTED_FAILURES = StressTestUtils.unmodifiableHashSet(
"document/truncated62886.docx"
);
@ParameterizedTest(name = "#{index} {0} {1}")
@MethodSource("extractFiles")
void handleExtracting(String file, FileHandlerKnown handler, String password, Class<? extends Throwable> exClass, String exMessage) throws IOException {
- if (EXPECTED_FAILURES.contains(file)) return;
+ if (StressTestUtils.excludeFile(file, EXPECTED_FAILURES)) return;
System.out.println("Running extractFiles on "+file);
FileHandler fileHandler = handler.fileHandler.get();
return msg;
}
-
- private static Set<String> unmodifiableHashSet(String... a) {
- return Collections.unmodifiableSet(new HashSet<>(Arrays.asList(a)));
- }
}
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.HashSet;
import java.util.Set;
import org.apache.poi.ooxml.POIXMLException;
import org.junit.jupiter.api.Test;
class XWPFFileHandler extends AbstractFileHandler {
- private static final Set<String> EXPECTED_FAILURES = unmodifiableHashSet(
+ private static final Set<String> EXPECTED_FAILURES = StressTestUtils.unmodifiableHashSet(
"document/truncated62886.docx"
);
// ignore password protected files
if (POIXMLDocumentHandler.isEncrypted(stream)) return;
- if (EXPECTED_FAILURES.contains(path)) return;
+ if (StressTestUtils.excludeFile(path, EXPECTED_FAILURES)) return;
try (XWPFDocument doc = new XWPFDocument(stream)) {
new POIXMLDocumentHandler().handlePOIXMLDocument(doc);
handleExtracting(file);
}
-
- private static Set<String> unmodifiableHashSet(String... a) {
- return Collections.unmodifiableSet(new HashSet<>(Arrays.asList(a)));
- }
}
\ No newline at end of file