a few performance fixes to speed-up the tests

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1750867 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Andreas Beeker 2016-06-30 22:59:46 +00:00
parent 0c9e0cb608
commit 6eab79528b
12 changed files with 251 additions and 157 deletions

View File

@ -204,8 +204,8 @@ import org.apache.poi.util.StringUtil;
* @see #main
*/
public final class BiffViewer {
static final String NEW_LINE_CHARS = System.getProperty("line.separator");
private static POILogger logger = POILogFactory.getLogger(BiffViewer.class);
private static final char[] NEW_LINE_CHARS = System.getProperty("line.separator").toCharArray();
private static final POILogger logger = POILogFactory.getLogger(BiffViewer.class);
private BiffViewer() {
// no instances of this class
@ -804,39 +804,55 @@ public final class BiffViewer {
}
private static void hexDumpLine(Writer w, byte[] data, int lineStartAddress, int lineDataOffset, int startDelta, int endDelta) {
if (startDelta >= endDelta) {
final char[] buf = new char[8+2*COLUMN_SEPARATOR.length+DUMP_LINE_LEN*3-1+DUMP_LINE_LEN+NEW_LINE_CHARS.length];
if (startDelta >= endDelta) {
throw new IllegalArgumentException("Bad start/end delta");
}
int idx=0;
try {
writeHex(w, lineStartAddress, 8);
w.write(COLUMN_SEPARATOR);
writeHex(buf, idx, lineStartAddress, 8);
idx = arraycopy(COLUMN_SEPARATOR, buf, idx+8);
// raw hex data
for (int i=0; i< DUMP_LINE_LEN; i++) {
if (i>0) {
w.write(" ");
buf[idx++] = ' ';
}
if (i >= startDelta && i < endDelta) {
writeHex(w, data[lineDataOffset+i], 2);
writeHex(buf, idx, data[lineDataOffset+i], 2);
} else {
w.write(" ");
buf[idx] = ' ';
buf[idx+1] = ' ';
}
idx += 2;
}
w.write(COLUMN_SEPARATOR);
idx = arraycopy(COLUMN_SEPARATOR, buf, idx);
// interpreted ascii
for (int i=0; i< DUMP_LINE_LEN; i++) {
char ch = ' ';
if (i >= startDelta && i < endDelta) {
w.write(getPrintableChar(data[lineDataOffset+i]));
} else {
w.write(" ");
ch = getPrintableChar(data[lineDataOffset+i]);
}
buf[idx++] = ch;
}
w.write(NEW_LINE_CHARS);
idx = arraycopy(NEW_LINE_CHARS, buf, idx);
w.write(buf, 0, idx);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
private static int arraycopy(char[] in, char[] out, int pos) {
int idx = pos;
for (char c : in) {
out[idx++] = c;
}
return idx;
}
private static char getPrintableChar(byte b) {
char ib = (char) (b & 0x00FF);
if (ib < 32 || ib > 126) {
@ -845,14 +861,12 @@ public final class BiffViewer {
return ib;
}
private static void writeHex(Writer w, int value, int nDigits) throws IOException {
char[] buf = new char[nDigits];
private static void writeHex(char buf[], int startInBuf, int value, int nDigits) throws IOException {
int acc = value;
for(int i=nDigits-1; i>=0; i--) {
int digit = acc & 0x0F;
buf[i] = (char) (digit < 10 ? ('0' + digit) : ('A' + digit - 10));
acc >>= 4;
buf[startInBuf+i] = (char) (digit < 10 ? ('0' + digit) : ('A' + digit - 10));
acc >>>= 4;
}
w.write(buf);
}
}

View File

@ -98,7 +98,7 @@ public class FormulaViewer
StringBuffer buf = new StringBuffer();
if (token instanceof ExpPtg) return;
buf.append(((OperationPtg) token).toFormulaString());
buf.append(token.toFormulaString());
buf.append(sep);
switch (token.getPtgClass()) {
case Ptg.CLASS_REF :

View File

@ -17,8 +17,10 @@
package org.apache.poi.hssf.dev;
import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.OutputStream;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
@ -29,13 +31,19 @@ import org.apache.poi.hssf.usermodel.HSSFWorkbook;
*
* Usage: ReSave [-dg] input.xls
* -dg initialize drawings, causes to re-build escher aggregates in all sheets
* -bos only write to memory instead of a file
*/
public class ReSave {
public static void main(String[] args) throws Exception {
boolean initDrawing = false;
boolean saveToMemory = false;
ByteArrayOutputStream bos = new ByteArrayOutputStream();
for(String filename : args) {
if(filename.equals("-dg")) initDrawing = true;
else {
if(filename.equals("-dg")) {
initDrawing = true;
} else if(filename.equals("-bos")) {
saveToMemory = true;
} else {
System.out.print("reading " + filename + "...");
FileInputStream is = new FileInputStream(filename);
HSSFWorkbook wb = new HSSFWorkbook(is);
@ -48,18 +56,26 @@ public class ReSave {
/*HSSFPatriarch dg =*/ sheet.getDrawingPatriarch();
}
}
String outputFile = filename.replace(".xls", "-saved.xls");
System.out.print("saving to " + outputFile + "...");
FileOutputStream out = new FileOutputStream(outputFile);
OutputStream os;
if (saveToMemory) {
bos.reset();
os = bos;
} else {
String outputFile = filename.replace(".xls", "-saved.xls");
System.out.print("saving to " + outputFile + "...");
os = new FileOutputStream(outputFile);
}
try {
wb.write(out);
wb.write(os);
} finally {
out.close();
os.close();
}
System.out.println("done");
} finally {
wb.close();
is.close();
}
}
}

View File

@ -27,7 +27,6 @@ import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintStream;
import java.nio.charset.Charset;
import java.util.Locale;
import org.apache.commons.codec.CharEncoding;
@ -149,10 +148,10 @@ public class HexDump {
chars_read = 16;
}
buffer.append(xpad(display_offset, 8, ""));
writeHex(buffer, display_offset, 8, "");
for (int k = 0; k < 16; k++) {
if (k < chars_read) {
buffer.append(xpad(data[ k + j ], 2, " "));
writeHex(buffer, data[ k + j ], 2, " ");
} else {
buffer.append(" ");
}
@ -243,12 +242,12 @@ public class HexDump {
}
final int digits = (int) Math.round(Math.log(value.length) / Math.log(10) + 0.5);
StringBuilder retVal = new StringBuilder();
retVal.append(xpad(0, digits, ""));
writeHex(retVal, 0, digits, "");
retVal.append(": ");
for(int x=0, i=-1; x < value.length; x++) {
if (++i == bytesPerLine) {
retVal.append('\n');
retVal.append(xpad(x, digits, ""));
writeHex(retVal, x, digits, "");
retVal.append(": ");
i = 0;
} else if (x>0) {
@ -266,7 +265,9 @@ public class HexDump {
* @return The result right padded with 0
*/
public static String toHex(short value) {
return xpad(value & 0xFFFF, 4, "");
StringBuilder sb = new StringBuilder(4);
writeHex(sb, value & 0xFFFF, 4, "");
return sb.toString();
}
/**
@ -276,7 +277,9 @@ public class HexDump {
* @return The result right padded with 0
*/
public static String toHex(byte value) {
return xpad(value & 0xFF, 2, "");
StringBuilder sb = new StringBuilder(2);
writeHex(sb, value & 0xFF, 2, "");
return sb.toString();
}
/**
@ -286,7 +289,9 @@ public class HexDump {
* @return The result right padded with 0
*/
public static String toHex(int value) {
return xpad(value & 0xFFFFFFFFL, 8, "");
StringBuilder sb = new StringBuilder(8);
writeHex(sb, value & 0xFFFFFFFFL, 8, "");
return sb.toString();
}
/**
@ -296,7 +301,9 @@ public class HexDump {
* @return The result right padded with 0
*/
public static String toHex(long value) {
return xpad(value, 16, "");
StringBuilder sb = new StringBuilder(16);
writeHex(sb, value, 16, "");
return sb.toString();
}
/**
@ -352,46 +359,51 @@ public class HexDump {
* @return string of 16 (zero padded) uppercase hex chars and prefixed with '0x'
*/
public static String longToHex(long value) {
return xpad(value, 16, "0x");
StringBuilder sb = new StringBuilder(18);
writeHex(sb, value, 16, "0x");
return sb.toString();
}
/**
* @return string of 8 (zero padded) uppercase hex chars and prefixed with '0x'
*/
public static String intToHex(int value) {
return xpad(value & 0xFFFFFFFFL, 8, "0x");
StringBuilder sb = new StringBuilder(10);
writeHex(sb, value & 0xFFFFFFFFL, 8, "0x");
return sb.toString();
}
/**
* @return string of 4 (zero padded) uppercase hex chars and prefixed with '0x'
*/
public static String shortToHex(int value) {
return xpad(value & 0xFFFFL, 4, "0x");
StringBuilder sb = new StringBuilder(6);
writeHex(sb, value & 0xFFFFL, 4, "0x");
return sb.toString();
}
/**
* @return string of 2 (zero padded) uppercase hex chars and prefixed with '0x'
*/
public static String byteToHex(int value) {
return xpad(value & 0xFFL, 2, "0x");
}
private static String xpad(long value, int pad, String prefix) {
String sv = Long.toHexString(value).toUpperCase(Locale.ROOT);
int len = sv.length();
if ((pad == 0 || len == pad) && "".equals(prefix)) return sv;
StringBuilder sb = new StringBuilder(prefix);
if (len < pad) {
sb.append("0000000000000000", 0, pad-len);
sb.append(sv);
} else if (len > pad) {
sb.append(sv, len-pad, len);
} else {
sb.append(sv);
}
StringBuilder sb = new StringBuilder(4);
writeHex(sb, value & 0xFFL, 2, "0x");
return sb.toString();
}
private static void writeHex(StringBuilder sb, long value, int nDigits, String prefix) {
sb.append(prefix);
char[] buf = new char[nDigits];
long acc = value;
for(int i=nDigits-1; i>=0; i--) {
int digit = (int)(acc & 0x0F);
buf[i] = (char) (digit < 10 ? ('0' + digit) : ('A' + digit - 10));
acc >>>= 4;
}
sb.append(buf);
}
public static void main(String[] args) throws Exception {
File file = new File(args[0]);
InputStream in = new BufferedInputStream(new FileInputStream(file));

View File

@ -786,7 +786,7 @@ public final class TestPackage {
ZipFile zipFile = ZipHelper.openZipFile(OpenXML4JTestDataSamples.getSampleFile("sample.xlsx"));
assertNotNull(zipFile);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ByteArrayOutputStream bos = new ByteArrayOutputStream(2500000);
ZipOutputStream append = new ZipOutputStream(bos);
// first, copy contents from existing war
Enumeration<? extends ZipEntry> entries = zipFile.entries();
@ -807,7 +807,8 @@ public final class TestPackage {
append.write(bos2.toByteArray(), 0, (int)size);
byte spam[] = new byte[0x7FFF];
for (int i=0; i<spam.length; i++) spam[i] = ' ';
while (size < 0x7FFF0000) {
// 0x7FFF0000 is the maximum for 32-bit zips, but less still works
while (size < 0x7FFF00) {
append.write(spam);
size += spam.length;
}

View File

@ -24,14 +24,17 @@ import java.io.FilenameFilter;
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import org.apache.poi.POIDataSamples;
import org.apache.poi.hssf.record.crypto.Biff8EncryptionKey;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.junit.Assume;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameter;
@ -47,7 +50,11 @@ import org.junit.runners.Parameterized.Parameters;
public abstract class BaseXLSIteratingTest {
protected static final OutputStream NULL_OUTPUT_STREAM = new NullOutputStream();
protected static final List<String> EXCLUDED = new ArrayList<String>();
@Rule
public ExpectedException thrown = ExpectedException.none();
protected static final Map<String,Class<? extends Throwable>> EXCLUDED =
new HashMap<String,Class<? extends Throwable>>();
@Parameters(name="{index}: {0}")
public static Iterable<Object[]> files() {
@ -85,16 +92,15 @@ public abstract class BaseXLSIteratingTest {
public void testMain() throws Exception {
// we had intermittent problems when this was set differently somehow, let's try to set it here so it always is set correctly for these tests
Biff8EncryptionKey.setCurrentUserPassword(null);
String fileName = file.getName();
if (EXCLUDED.containsKey(fileName)) {
thrown.expect(EXCLUDED.get(fileName));
}
try {
runOneFile(file);
} catch (Exception e) {
Assume.assumeFalse("File " + file + " is excluded currently",
EXCLUDED.contains(file.getName()));
System.out.println("Failed: " + file);
e.printStackTrace();
// try to read it in HSSFWorkbook to quickly fail if we cannot read the file there at all and thus probably should use EXCLUDED instead
FileInputStream stream = new FileInputStream(file);
HSSFWorkbook wb = null;
@ -107,6 +113,8 @@ public abstract class BaseXLSIteratingTest {
}
stream.close();
}
throw e;
}
}

View File

@ -21,22 +21,29 @@ import java.io.FileInputStream;
import java.io.InputStream;
import java.io.PrintStream;
import org.apache.poi.EncryptedDocumentException;
import org.apache.poi.hssf.OldExcelFormatException;
import org.apache.poi.hssf.record.RecordInputStream;
import org.junit.BeforeClass;
public class TestBiffDrawingToXml extends BaseXLSIteratingTest {
static {
EXCLUDED.add("35897-type4.xls"); // unsupported crypto api header
EXCLUDED.add("43493.xls"); // HSSFWorkbook cannot open it as well
EXCLUDED.add("46904.xls");
EXCLUDED.add("44958_1.xls");
EXCLUDED.add("51832.xls");
EXCLUDED.add("59074.xls");
EXCLUDED.add("password.xls");
EXCLUDED.add("testEXCEL_2.xls"); // Biff 2 / Excel 2, pre-OLE2
EXCLUDED.add("testEXCEL_3.xls"); // Biff 3 / Excel 3, pre-OLE2
EXCLUDED.add("testEXCEL_4.xls"); // Biff 4 / Excel 4, pre-OLE2
EXCLUDED.add("testEXCEL_5.xls"); // Biff 5 / Excel 5
EXCLUDED.add("testEXCEL_95.xls"); // Biff 5 / Excel 95
EXCLUDED.add("xor-encryption-abc.xls");
}
@BeforeClass
public static void setup() {
EXCLUDED.clear();
EXCLUDED.put("35897-type4.xls", EncryptedDocumentException.class); // unsupported crypto api header
EXCLUDED.put("51832.xls", EncryptedDocumentException.class);
EXCLUDED.put("xor-encryption-abc.xls", EncryptedDocumentException.class);
EXCLUDED.put("password.xls", EncryptedDocumentException.class);
EXCLUDED.put("46904.xls", OldExcelFormatException.class);
EXCLUDED.put("59074.xls", OldExcelFormatException.class);
EXCLUDED.put("testEXCEL_2.xls", OldExcelFormatException.class); // Biff 2 / Excel 2, pre-OLE2
EXCLUDED.put("testEXCEL_3.xls", OldExcelFormatException.class); // Biff 3 / Excel 3, pre-OLE2
EXCLUDED.put("testEXCEL_4.xls", OldExcelFormatException.class); // Biff 4 / Excel 4, pre-OLE2
EXCLUDED.put("testEXCEL_5.xls", OldExcelFormatException.class); // Biff 5 / Excel 5
EXCLUDED.put("testEXCEL_95.xls", OldExcelFormatException.class); // Biff 5 / Excel 95
EXCLUDED.put("43493.xls", RecordInputStream.LeftoverDataException.class); // HSSFWorkbook cannot open it as well
EXCLUDED.put("44958_1.xls", RecordInputStream.LeftoverDataException.class);
}
@Override
void runOneFile(File pFile) throws Exception {

View File

@ -22,28 +22,32 @@ import java.io.InputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import org.apache.poi.EncryptedDocumentException;
import org.apache.poi.hssf.OldExcelFormatException;
import org.apache.poi.hssf.record.RecordInputStream;
import org.apache.poi.poifs.filesystem.NPOIFSFileSystem;
import org.apache.poi.util.LocaleUtil;
import org.junit.BeforeClass;
public class TestBiffViewer extends BaseXLSIteratingTest {
static {
// these are likely ok to fail
EXCLUDED.add("XRefCalc.xls"); // "Buffer overrun"
EXCLUDED.add("50833.xls"); // "Name is too long" when setting username
EXCLUDED.add("OddStyleRecord.xls");
EXCLUDED.add("NoGutsRecords.xls");
EXCLUDED.add("51832.xls"); // password
EXCLUDED.add("43493.xls"); // HSSFWorkbook cannot open it as well
EXCLUDED.add("password.xls");
EXCLUDED.add("46904.xls");
EXCLUDED.add("59074.xls"); // Biff 5 / Excel 95
EXCLUDED.add("35897-type4.xls"); // unsupported crypto api header
EXCLUDED.add("xor-encryption-abc.xls"); // unsupported XOR-encryption
EXCLUDED.add("testEXCEL_2.xls"); // Biff 2 / Excel 2, pre-OLE2
EXCLUDED.add("testEXCEL_3.xls"); // Biff 3 / Excel 3, pre-OLE2
EXCLUDED.add("testEXCEL_4.xls"); // Biff 4 / Excel 4, pre-OLE2
EXCLUDED.add("testEXCEL_5.xls"); // Biff 5 / Excel 5
EXCLUDED.add("testEXCEL_95.xls"); // Biff 5 / Excel 95
@BeforeClass
public static void setup() {
EXCLUDED.clear();
EXCLUDED.put("35897-type4.xls", EncryptedDocumentException.class); // unsupported crypto api header
EXCLUDED.put("51832.xls", EncryptedDocumentException.class);
EXCLUDED.put("xor-encryption-abc.xls", EncryptedDocumentException.class);
EXCLUDED.put("password.xls", EncryptedDocumentException.class);
EXCLUDED.put("46904.xls", OldExcelFormatException.class);
EXCLUDED.put("59074.xls", OldExcelFormatException.class);
EXCLUDED.put("testEXCEL_2.xls", OldExcelFormatException.class); // Biff 2 / Excel 2, pre-OLE2
EXCLUDED.put("testEXCEL_3.xls", OldExcelFormatException.class); // Biff 3 / Excel 3, pre-OLE2
EXCLUDED.put("testEXCEL_4.xls", OldExcelFormatException.class); // Biff 4 / Excel 4, pre-OLE2
EXCLUDED.put("testEXCEL_5.xls", OldExcelFormatException.class); // Biff 5 / Excel 5
EXCLUDED.put("testEXCEL_95.xls", OldExcelFormatException.class); // Biff 5 / Excel 95
EXCLUDED.put("43493.xls", RecordInputStream.LeftoverDataException.class); // HSSFWorkbook cannot open it as well
// EXCLUDED.put("44958_1.xls", RecordInputStream.LeftoverDataException.class);
EXCLUDED.put("50833.xls", IllegalArgumentException.class); // "Name is too long" when setting username
EXCLUDED.put("XRefCalc.xls", RuntimeException.class); // "Buffer overrun"
}
@Override

View File

@ -20,26 +20,31 @@ import java.io.File;
import java.io.IOException;
import java.io.PrintStream;
import org.apache.poi.EncryptedDocumentException;
import org.apache.poi.hssf.OldExcelFormatException;
import org.apache.poi.hssf.record.RecordInputStream;
import org.apache.poi.util.LocaleUtil;
import org.junit.BeforeClass;
public class TestEFBiffViewer extends BaseXLSIteratingTest {
static {
// these are likely ok to fail
EXCLUDED.add("XRefCalc.xls");
EXCLUDED.add("password.xls");
EXCLUDED.add("51832.xls"); // password
EXCLUDED.add("xor-encryption-abc.xls"); // password, ty again later!
EXCLUDED.add("43493.xls"); // HSSFWorkbook cannot open it as well
EXCLUDED.add("44958_1.xls"); // known bad file
EXCLUDED.add("46904.xls"); // Exception, too old
EXCLUDED.add("47251_1.xls"); // Broken test file
EXCLUDED.add("testEXCEL_3.xls"); // Biff 3 / Excel 3, pre-OLE2
EXCLUDED.add("testEXCEL_4.xls"); // old unsupported format
EXCLUDED.add("testEXCEL_5.xls"); // old unsupported format
EXCLUDED.add("testEXCEL_95.xls"); // old unsupported format
EXCLUDED.add("35897-type4.xls"); // unsupported encryption
EXCLUDED.add("59074.xls"); // Biff 5 / Excel 95
}
@BeforeClass
public static void setup() {
EXCLUDED.clear();
EXCLUDED.put("35897-type4.xls", EncryptedDocumentException.class); // unsupported crypto api header
EXCLUDED.put("51832.xls", EncryptedDocumentException.class);
EXCLUDED.put("xor-encryption-abc.xls", EncryptedDocumentException.class);
EXCLUDED.put("password.xls", EncryptedDocumentException.class);
EXCLUDED.put("46904.xls", OldExcelFormatException.class);
EXCLUDED.put("59074.xls", OldExcelFormatException.class);
EXCLUDED.put("testEXCEL_2.xls", OldExcelFormatException.class); // Biff 2 / Excel 2, pre-OLE2
EXCLUDED.put("testEXCEL_3.xls", OldExcelFormatException.class); // Biff 3 / Excel 3, pre-OLE2
EXCLUDED.put("testEXCEL_4.xls", OldExcelFormatException.class); // Biff 4 / Excel 4, pre-OLE2
EXCLUDED.put("testEXCEL_5.xls", OldExcelFormatException.class); // Biff 5 / Excel 5
EXCLUDED.put("testEXCEL_95.xls", OldExcelFormatException.class); // Biff 5 / Excel 95
EXCLUDED.put("43493.xls", RecordInputStream.LeftoverDataException.class); // HSSFWorkbook cannot open it as well
EXCLUDED.put("44958_1.xls", RecordInputStream.LeftoverDataException.class);
EXCLUDED.put("XRefCalc.xls", RuntimeException.class); // "Buffer overrun"
}
@Override
void runOneFile(File fileIn) throws IOException {

View File

@ -16,30 +16,36 @@
==================================================================== */
package org.apache.poi.hssf.dev;
import static org.junit.Assume.assumeTrue;
import java.io.File;
import java.io.PrintStream;
import org.apache.poi.EncryptedDocumentException;
import org.apache.poi.hssf.OldExcelFormatException;
import org.apache.poi.hssf.record.RecordInputStream;
import org.apache.poi.util.LocaleUtil;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.BeforeClass;
public class TestFormulaViewer extends BaseXLSIteratingTest {
static {
// TODO: is it ok to fail these?
// Look at the output of the test for the detailed stacktrace of the failures...
// EXCLUDED.add("WORKBOOK_in_capitals.xls");
// EXCLUDED.add("NoGutsRecords.xls");
// EXCLUDED.add("BOOK_in_capitals.xls");
// EXCLUDED.add("46904.xls");
// EXCLUDED.add("OddStyleRecord.xls");
}
@BeforeClass
public static void setup() {
EXCLUDED.clear();
EXCLUDED.put("35897-type4.xls", EncryptedDocumentException.class); // unsupported crypto api header
EXCLUDED.put("51832.xls", EncryptedDocumentException.class);
EXCLUDED.put("xor-encryption-abc.xls", EncryptedDocumentException.class);
EXCLUDED.put("password.xls", EncryptedDocumentException.class);
EXCLUDED.put("46904.xls", OldExcelFormatException.class);
EXCLUDED.put("59074.xls", OldExcelFormatException.class);
EXCLUDED.put("testEXCEL_2.xls", OldExcelFormatException.class); // Biff 2 / Excel 2, pre-OLE2
EXCLUDED.put("testEXCEL_3.xls", OldExcelFormatException.class); // Biff 3 / Excel 3, pre-OLE2
EXCLUDED.put("testEXCEL_4.xls", OldExcelFormatException.class); // Biff 4 / Excel 4, pre-OLE2
EXCLUDED.put("testEXCEL_5.xls", OldExcelFormatException.class); // Biff 5 / Excel 5
EXCLUDED.put("testEXCEL_95.xls", OldExcelFormatException.class); // Biff 5 / Excel 95
EXCLUDED.put("43493.xls", RecordInputStream.LeftoverDataException.class); // HSSFWorkbook cannot open it as well
EXCLUDED.put("44958_1.xls", RecordInputStream.LeftoverDataException.class);
}
@Override
@Ignore("Not yet done, nearly all files fail with various errors, remove this method when done to use the one from the abstract base class!...")
@Test
public void testMain() throws Exception {
}
@Override
void runOneFile(File fileIn) throws Exception {
PrintStream save = System.out;
@ -51,6 +57,14 @@ public class TestFormulaViewer extends BaseXLSIteratingTest {
viewer.setFile(fileIn.getAbsolutePath());
viewer.setList(true);
viewer.run();
} catch (RuntimeException re) {
String m = re.getMessage();
if (m.startsWith("toFormulaString") || m.startsWith("3D references")) {
// TODO: fix those cases, but ignore them for now ...
assumeTrue(true);
} else {
throw re;
}
} finally {
System.setOut(save);
}

View File

@ -23,19 +23,33 @@ import java.io.PrintStream;
import java.util.ArrayList;
import java.util.List;
import org.apache.poi.EncryptedDocumentException;
import org.apache.poi.POIDataSamples;
import org.apache.poi.hssf.OldExcelFormatException;
import org.apache.poi.hssf.record.RecordInputStream;
import org.apache.poi.util.LocaleUtil;
import org.junit.BeforeClass;
public class TestReSave extends BaseXLSIteratingTest {
static {
// these are likely ok to fail
EXCLUDED.add("password.xls");
EXCLUDED.add("43493.xls"); // HSSFWorkbook cannot open it as well
EXCLUDED.add("46904.xls");
EXCLUDED.add("51832.xls"); // password
EXCLUDED.add("44958_1.xls"); // known bad file
}
@BeforeClass
public static void setup() {
EXCLUDED.clear();
EXCLUDED.put("35897-type4.xls", EncryptedDocumentException.class); // unsupported crypto api header
EXCLUDED.put("51832.xls", EncryptedDocumentException.class);
EXCLUDED.put("xor-encryption-abc.xls", EncryptedDocumentException.class);
EXCLUDED.put("password.xls", EncryptedDocumentException.class);
EXCLUDED.put("46904.xls", OldExcelFormatException.class);
EXCLUDED.put("59074.xls", OldExcelFormatException.class);
EXCLUDED.put("testEXCEL_2.xls", OldExcelFormatException.class); // Biff 2 / Excel 2, pre-OLE2
EXCLUDED.put("testEXCEL_3.xls", OldExcelFormatException.class); // Biff 3 / Excel 3, pre-OLE2
EXCLUDED.put("testEXCEL_4.xls", OldExcelFormatException.class); // Biff 4 / Excel 4, pre-OLE2
EXCLUDED.put("testEXCEL_5.xls", OldExcelFormatException.class); // Biff 5 / Excel 5
EXCLUDED.put("testEXCEL_95.xls", OldExcelFormatException.class); // Biff 5 / Excel 95
EXCLUDED.put("43493.xls", RecordInputStream.LeftoverDataException.class); // HSSFWorkbook cannot open it as well
EXCLUDED.put("44958_1.xls", RecordInputStream.LeftoverDataException.class);
EXCLUDED.put("XRefCalc.xls", RuntimeException.class); // "Buffer overrun"
}
@Override
void runOneFile(File fileIn) throws Exception {
// avoid running on files leftover from previous failed runs
@ -55,13 +69,8 @@ public class TestReSave extends BaseXLSIteratingTest {
// also try BiffViewer on the saved file
new TestBiffViewer().runOneFile(reSavedFile);
try {
// had one case where the re-saved could not be re-saved!
ReSave.main(new String[] { reSavedFile.getAbsolutePath() });
} finally {
// clean up the re-re-saved file
new File(fileIn.getParentFile(), reSavedFile.getName().replace(".xls", "-saved.xls")).delete();
}
// had one case where the re-saved could not be re-saved!
ReSave.main(new String[] { "-bos", reSavedFile.getAbsolutePath() });
} finally {
// clean up the re-saved file
reSavedFile.delete();

View File

@ -20,18 +20,22 @@ import java.io.File;
import java.io.IOException;
import java.io.PrintStream;
import org.apache.poi.hssf.OldExcelFormatException;
import org.apache.poi.util.LocaleUtil;
import org.junit.BeforeClass;
public class TestRecordLister extends BaseXLSIteratingTest {
static {
// these are likely ok to fail
EXCLUDED.add("46904.xls");
EXCLUDED.add("testEXCEL_3.xls"); // Biff 3 / Excel 3, pre-OLE2
EXCLUDED.add("testEXCEL_4.xls"); // old unsupported format
EXCLUDED.add("testEXCEL_5.xls"); // Biff 5 / Excel 5
EXCLUDED.add("testEXCEL_95.xls"); // Biff 5 / Excel 95
EXCLUDED.add("59074.xls"); // Biff 5 / Excel 95
}
@BeforeClass
public static void setup() {
EXCLUDED.clear();
EXCLUDED.put("46904.xls", OldExcelFormatException.class);
EXCLUDED.put("59074.xls", OldExcelFormatException.class);
EXCLUDED.put("testEXCEL_2.xls", OldExcelFormatException.class); // Biff 2 / Excel 2, pre-OLE2
EXCLUDED.put("testEXCEL_3.xls", OldExcelFormatException.class); // Biff 3 / Excel 3, pre-OLE2
EXCLUDED.put("testEXCEL_4.xls", OldExcelFormatException.class); // Biff 4 / Excel 4, pre-OLE2
EXCLUDED.put("testEXCEL_5.xls", OldExcelFormatException.class); // Biff 5 / Excel 5
EXCLUDED.put("testEXCEL_95.xls", OldExcelFormatException.class); // Biff 5 / Excel 95
}
@Override
void runOneFile(File fileIn) throws IOException {