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

View File

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

View File

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

View File

@ -27,7 +27,6 @@ import java.io.OutputStream;
import java.io.OutputStreamWriter; import java.io.OutputStreamWriter;
import java.io.PrintStream; import java.io.PrintStream;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.util.Locale;
import org.apache.commons.codec.CharEncoding; import org.apache.commons.codec.CharEncoding;
@ -149,10 +148,10 @@ public class HexDump {
chars_read = 16; chars_read = 16;
} }
buffer.append(xpad(display_offset, 8, "")); writeHex(buffer, display_offset, 8, "");
for (int k = 0; k < 16; k++) { for (int k = 0; k < 16; k++) {
if (k < chars_read) { if (k < chars_read) {
buffer.append(xpad(data[ k + j ], 2, " ")); writeHex(buffer, data[ k + j ], 2, " ");
} else { } else {
buffer.append(" "); buffer.append(" ");
} }
@ -243,12 +242,12 @@ public class HexDump {
} }
final int digits = (int) Math.round(Math.log(value.length) / Math.log(10) + 0.5); final int digits = (int) Math.round(Math.log(value.length) / Math.log(10) + 0.5);
StringBuilder retVal = new StringBuilder(); StringBuilder retVal = new StringBuilder();
retVal.append(xpad(0, digits, "")); writeHex(retVal, 0, digits, "");
retVal.append(": "); retVal.append(": ");
for(int x=0, i=-1; x < value.length; x++) { for(int x=0, i=-1; x < value.length; x++) {
if (++i == bytesPerLine) { if (++i == bytesPerLine) {
retVal.append('\n'); retVal.append('\n');
retVal.append(xpad(x, digits, "")); writeHex(retVal, x, digits, "");
retVal.append(": "); retVal.append(": ");
i = 0; i = 0;
} else if (x>0) { } else if (x>0) {
@ -266,7 +265,9 @@ public class HexDump {
* @return The result right padded with 0 * @return The result right padded with 0
*/ */
public static String toHex(short value) { 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 * @return The result right padded with 0
*/ */
public static String toHex(byte value) { 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 * @return The result right padded with 0
*/ */
public static String toHex(int value) { 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 * @return The result right padded with 0
*/ */
public static String toHex(long value) { 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' * @return string of 16 (zero padded) uppercase hex chars and prefixed with '0x'
*/ */
public static String longToHex(long value) { 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' * @return string of 8 (zero padded) uppercase hex chars and prefixed with '0x'
*/ */
public static String intToHex(int value) { 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' * @return string of 4 (zero padded) uppercase hex chars and prefixed with '0x'
*/ */
public static String shortToHex(int value) { 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' * @return string of 2 (zero padded) uppercase hex chars and prefixed with '0x'
*/ */
public static String byteToHex(int value) { public static String byteToHex(int value) {
return xpad(value & 0xFFL, 2, "0x"); StringBuilder sb = new StringBuilder(4);
} writeHex(sb, 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);
}
return sb.toString(); 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 { public static void main(String[] args) throws Exception {
File file = new File(args[0]); File file = new File(args[0]);
InputStream in = new BufferedInputStream(new FileInputStream(file)); 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")); ZipFile zipFile = ZipHelper.openZipFile(OpenXML4JTestDataSamples.getSampleFile("sample.xlsx"));
assertNotNull(zipFile); assertNotNull(zipFile);
ByteArrayOutputStream bos = new ByteArrayOutputStream(); ByteArrayOutputStream bos = new ByteArrayOutputStream(2500000);
ZipOutputStream append = new ZipOutputStream(bos); ZipOutputStream append = new ZipOutputStream(bos);
// first, copy contents from existing war // first, copy contents from existing war
Enumeration<? extends ZipEntry> entries = zipFile.entries(); Enumeration<? extends ZipEntry> entries = zipFile.entries();
@ -807,7 +807,8 @@ public final class TestPackage {
append.write(bos2.toByteArray(), 0, (int)size); append.write(bos2.toByteArray(), 0, (int)size);
byte spam[] = new byte[0x7FFF]; byte spam[] = new byte[0x7FFF];
for (int i=0; i<spam.length; i++) spam[i] = ' '; 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); append.write(spam);
size += spam.length; size += spam.length;
} }

View File

@ -24,14 +24,17 @@ import java.io.FilenameFilter;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Map;
import org.apache.poi.POIDataSamples; import org.apache.poi.POIDataSamples;
import org.apache.poi.hssf.record.crypto.Biff8EncryptionKey; import org.apache.poi.hssf.record.crypto.Biff8EncryptionKey;
import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.junit.Assume; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.junit.runners.Parameterized; import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameter; import org.junit.runners.Parameterized.Parameter;
@ -47,7 +50,11 @@ import org.junit.runners.Parameterized.Parameters;
public abstract class BaseXLSIteratingTest { public abstract class BaseXLSIteratingTest {
protected static final OutputStream NULL_OUTPUT_STREAM = new NullOutputStream(); 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}") @Parameters(name="{index}: {0}")
public static Iterable<Object[]> files() { public static Iterable<Object[]> files() {
@ -85,16 +92,15 @@ public abstract class BaseXLSIteratingTest {
public void testMain() throws Exception { 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 // 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); Biff8EncryptionKey.setCurrentUserPassword(null);
String fileName = file.getName();
if (EXCLUDED.containsKey(fileName)) {
thrown.expect(EXCLUDED.get(fileName));
}
try { try {
runOneFile(file); runOneFile(file);
} catch (Exception e) { } 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 // 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); FileInputStream stream = new FileInputStream(file);
HSSFWorkbook wb = null; HSSFWorkbook wb = null;
@ -107,6 +113,8 @@ public abstract class BaseXLSIteratingTest {
} }
stream.close(); stream.close();
} }
throw e;
} }
} }

View File

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

View File

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

View File

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

View File

@ -16,30 +16,36 @@
==================================================================== */ ==================================================================== */
package org.apache.poi.hssf.dev; package org.apache.poi.hssf.dev;
import static org.junit.Assume.assumeTrue;
import java.io.File; import java.io.File;
import java.io.PrintStream; 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.apache.poi.util.LocaleUtil;
import org.junit.Ignore; import org.junit.BeforeClass;
import org.junit.Test;
public class TestFormulaViewer extends BaseXLSIteratingTest { public class TestFormulaViewer extends BaseXLSIteratingTest {
static { @BeforeClass
// TODO: is it ok to fail these? public static void setup() {
// Look at the output of the test for the detailed stacktrace of the failures... EXCLUDED.clear();
// EXCLUDED.add("WORKBOOK_in_capitals.xls"); EXCLUDED.put("35897-type4.xls", EncryptedDocumentException.class); // unsupported crypto api header
// EXCLUDED.add("NoGutsRecords.xls"); EXCLUDED.put("51832.xls", EncryptedDocumentException.class);
// EXCLUDED.add("BOOK_in_capitals.xls"); EXCLUDED.put("xor-encryption-abc.xls", EncryptedDocumentException.class);
// EXCLUDED.add("46904.xls"); EXCLUDED.put("password.xls", EncryptedDocumentException.class);
// EXCLUDED.add("OddStyleRecord.xls"); 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 @Override
void runOneFile(File fileIn) throws Exception { void runOneFile(File fileIn) throws Exception {
PrintStream save = System.out; PrintStream save = System.out;
@ -51,6 +57,14 @@ public class TestFormulaViewer extends BaseXLSIteratingTest {
viewer.setFile(fileIn.getAbsolutePath()); viewer.setFile(fileIn.getAbsolutePath());
viewer.setList(true); viewer.setList(true);
viewer.run(); 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 { } finally {
System.setOut(save); System.setOut(save);
} }

View File

@ -23,19 +23,33 @@ import java.io.PrintStream;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.apache.poi.EncryptedDocumentException;
import org.apache.poi.POIDataSamples; 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.apache.poi.util.LocaleUtil;
import org.junit.BeforeClass;
public class TestReSave extends BaseXLSIteratingTest { public class TestReSave extends BaseXLSIteratingTest {
static { @BeforeClass
// these are likely ok to fail public static void setup() {
EXCLUDED.add("password.xls"); EXCLUDED.clear();
EXCLUDED.add("43493.xls"); // HSSFWorkbook cannot open it as well EXCLUDED.put("35897-type4.xls", EncryptedDocumentException.class); // unsupported crypto api header
EXCLUDED.add("46904.xls"); EXCLUDED.put("51832.xls", EncryptedDocumentException.class);
EXCLUDED.add("51832.xls"); // password EXCLUDED.put("xor-encryption-abc.xls", EncryptedDocumentException.class);
EXCLUDED.add("44958_1.xls"); // known bad file 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 @Override
void runOneFile(File fileIn) throws Exception { void runOneFile(File fileIn) throws Exception {
// avoid running on files leftover from previous failed runs // 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 // also try BiffViewer on the saved file
new TestBiffViewer().runOneFile(reSavedFile); new TestBiffViewer().runOneFile(reSavedFile);
try { // had one case where the re-saved could not be re-saved!
// had one case where the re-saved could not be re-saved! ReSave.main(new String[] { "-bos", reSavedFile.getAbsolutePath() });
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();
}
} finally { } finally {
// clean up the re-saved file // clean up the re-saved file
reSavedFile.delete(); reSavedFile.delete();

View File

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