git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1891579 13f79535-47bb-0310-9956-ffa450edef68tags/REL_5_1_0
import java.io.InputStream; | import java.io.InputStream; | ||||
import java.io.PrintStream; | import java.io.PrintStream; | ||||
import java.nio.charset.StandardCharsets; | import java.nio.charset.StandardCharsets; | ||||
import java.util.Arrays; | |||||
import java.util.Collections; | |||||
import java.util.HashSet; | |||||
import java.util.Set; | import java.util.Set; | ||||
import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream; | import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream; | ||||
private static final ThreadLocal<File> copyOutput = ThreadLocal.withInitial(HPSFFileHandler::getTempFile); | 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/45290.xls", | ||||
"spreadsheet/46904.xls", | "spreadsheet/46904.xls", | ||||
"spreadsheet/55982.xls", | "spreadsheet/55982.xls", | ||||
"document/word2.doc" | "document/word2.doc" | ||||
); | ); | ||||
private static Set<String> unmodifiableHashSet(String... a) { | |||||
return Collections.unmodifiableSet(new HashSet<>(Arrays.asList(a))); | |||||
} | |||||
@Override | @Override | ||||
public void handleFile(InputStream stream, String path) throws Exception { | public void handleFile(InputStream stream, String path) throws Exception { | ||||
POIFSFileSystem poifs = new POIFSFileSystem(stream); | POIFSFileSystem poifs = new POIFSFileSystem(stream); |
import java.io.FileInputStream; | import java.io.FileInputStream; | ||||
import java.io.InputStream; | import java.io.InputStream; | ||||
import java.io.PushbackInputStream; | import java.io.PushbackInputStream; | ||||
import java.util.Arrays; | |||||
import java.util.Collections; | |||||
import java.util.HashSet; | |||||
import java.util.Set; | import java.util.Set; | ||||
import org.apache.poi.openxml4j.opc.ContentTypes; | import org.apache.poi.openxml4j.opc.ContentTypes; | ||||
import org.junit.jupiter.api.Test; | import org.junit.jupiter.api.Test; | ||||
class OPCFileHandler extends AbstractFileHandler { | class OPCFileHandler extends AbstractFileHandler { | ||||
private static final Set<String> EXPECTED_FAILURES = unmodifiableHashSet( | |||||
private static final Set<String> EXPECTED_FAILURES = StressTestUtils.unmodifiableHashSet( | |||||
"document/truncated62886.docx" | "document/truncated62886.docx" | ||||
); | ); | ||||
// ignore password protected files | // ignore password protected files | ||||
if (POIXMLDocumentHandler.isEncrypted(stream)) return; | if (POIXMLDocumentHandler.isEncrypted(stream)) return; | ||||
if (EXPECTED_FAILURES.contains(path)) return; | |||||
if (StressTestUtils.excludeFile(path, EXPECTED_FAILURES)) return; | |||||
OPCPackage p = OPCPackage.open(stream); | OPCPackage p = OPCPackage.open(stream); | ||||
handleExtracting(file); | handleExtracting(file); | ||||
} | } | ||||
private static Set<String> unmodifiableHashSet(String... a) { | |||||
return Collections.unmodifiableSet(new HashSet<>(Arrays.asList(a))); | |||||
} | |||||
} | } |
/* ==================================================================== | |||||
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; | package org.apache.poi.stress; | ||||
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; | import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; | ||||
import static org.junit.jupiter.api.Assertions.assertEquals; | import static org.junit.jupiter.api.Assertions.assertEquals; | ||||
import static org.junit.jupiter.api.Assertions.assertNotNull; | import static org.junit.jupiter.api.Assertions.assertNotNull; | ||||
"**/.git/**", | "**/.git/**", | ||||
}; | }; | ||||
private static final Set<String> EXPECTED_FAILURES = unmodifiableHashSet( | |||||
private static final Set<String> EXPECTED_FAILURES = StressTestUtils.unmodifiableHashSet( | |||||
"document/truncated62886.docx" | "document/truncated62886.docx" | ||||
); | ); | ||||
@ParameterizedTest(name = "#{index} {0} {1}") | @ParameterizedTest(name = "#{index} {0} {1}") | ||||
@MethodSource("extractFiles") | @MethodSource("extractFiles") | ||||
void handleExtracting(String file, FileHandlerKnown handler, String password, Class<? extends Throwable> exClass, String exMessage) throws IOException { | 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); | System.out.println("Running extractFiles on "+file); | ||||
FileHandler fileHandler = handler.fileHandler.get(); | FileHandler fileHandler = handler.fileHandler.get(); | ||||
return msg; | return msg; | ||||
} | } | ||||
private static Set<String> unmodifiableHashSet(String... a) { | |||||
return Collections.unmodifiableSet(new HashSet<>(Arrays.asList(a))); | |||||
} | |||||
} | } |
import java.io.File; | import java.io.File; | ||||
import java.io.FileInputStream; | import java.io.FileInputStream; | ||||
import java.io.InputStream; | import java.io.InputStream; | ||||
import java.util.Arrays; | |||||
import java.util.Collections; | |||||
import java.util.HashSet; | |||||
import java.util.Set; | import java.util.Set; | ||||
import org.apache.poi.ooxml.POIXMLException; | import org.apache.poi.ooxml.POIXMLException; | ||||
import org.junit.jupiter.api.Test; | import org.junit.jupiter.api.Test; | ||||
class XWPFFileHandler extends AbstractFileHandler { | class XWPFFileHandler extends AbstractFileHandler { | ||||
private static final Set<String> EXPECTED_FAILURES = unmodifiableHashSet( | |||||
private static final Set<String> EXPECTED_FAILURES = StressTestUtils.unmodifiableHashSet( | |||||
"document/truncated62886.docx" | "document/truncated62886.docx" | ||||
); | ); | ||||
// ignore password protected files | // ignore password protected files | ||||
if (POIXMLDocumentHandler.isEncrypted(stream)) return; | if (POIXMLDocumentHandler.isEncrypted(stream)) return; | ||||
if (EXPECTED_FAILURES.contains(path)) return; | |||||
if (StressTestUtils.excludeFile(path, EXPECTED_FAILURES)) return; | |||||
try (XWPFDocument doc = new XWPFDocument(stream)) { | try (XWPFDocument doc = new XWPFDocument(stream)) { | ||||
new POIXMLDocumentHandler().handlePOIXMLDocument(doc); | new POIXMLDocumentHandler().handlePOIXMLDocument(doc); | ||||
handleExtracting(file); | handleExtracting(file); | ||||
} | } | ||||
private static Set<String> unmodifiableHashSet(String... a) { | |||||
return Collections.unmodifiableSet(new HashSet<>(Arrays.asList(a))); | |||||
} | |||||
} | } |