Ver código fonte

More tests for bug #45365, but still not able to reproduce it

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@682999 13f79535-47bb-0310-9956-ffa450edef68
tags/REL_3_2_FINAL
Nick Burch 16 anos atrás
pai
commit
d0aeb2c0e0

+ 7
- 5
src/java/org/apache/poi/hssf/eventusermodel/FormatTrackingHSSFListener.java Ver arquivo

@@ -16,11 +16,7 @@
==================================================================== */
package org.apache.poi.hssf.eventusermodel;

import java.text.DateFormat;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;
@@ -33,7 +29,6 @@ import org.apache.poi.hssf.record.NumberRecord;
import org.apache.poi.hssf.record.Record;
import org.apache.poi.hssf.usermodel.HSSFDataFormat;
import org.apache.poi.hssf.usermodel.HSSFDataFormatter;
import org.apache.poi.hssf.usermodel.HSSFDateUtil;

/**
* A proxy HSSFListener that keeps track of the document
@@ -50,6 +45,13 @@ public class FormatTrackingHSSFListener implements HSSFListener {
this.childListener = childListener;
}
protected int getNumberOfCustomFormats() {
return customFormatRecords.size();
}
protected int getNumberOfExtendedFormats() {
return xfRecords.size();
}
/**
* Process this record ourselves, and then
* pass it on to our child listener

BIN
src/testcases/org/apache/poi/hssf/data/45365-2.xls Ver arquivo


+ 33
- 19
src/testcases/org/apache/poi/hssf/eventusermodel/TestFormatTrackingHSSFListener.java Ver arquivo

@@ -62,31 +62,45 @@ public final class TestFormatTrackingHSSFListener extends TestCase {
/**
* Ensure that all number and formula records can be
* turned into strings without problems
* turned into strings without problems.
* For now, we're just looking to get text back, no
* exceptions thrown, but in future we might also
* want to check the exact strings!
*/
public void testTurnToString() throws Exception {
processFile("45365.xls");
for(int i=0; i<mockListen._records.size(); i++) {
Record r = (Record)mockListen._records.get(i);
CellValueRecordInterface cvr = null;
String[] files = new String[] {
"45365.xls", "45365-2.xls", "MissingBits.xls"
};
for(int k=0; k<files.length; k++) {
processFile(files[k]);
if(r instanceof NumberRecord) {
cvr = (CellValueRecordInterface)r;
}
if(r instanceof FormulaRecord) {
cvr = (CellValueRecordInterface)r;
}
// Check we found our formats
assertTrue(listener.getNumberOfCustomFormats() > 5);
assertTrue(listener.getNumberOfExtendedFormats() > 5);
if(cvr != null) {
// Should always give us a string
String s = listener.formatNumberDateCell(cvr);
assertNotNull(s);
assertTrue(s.length() > 0);
// Now check we can turn all the numeric
// cells into strings without error
for(int i=0; i<mockListen._records.size(); i++) {
Record r = (Record)mockListen._records.get(i);
CellValueRecordInterface cvr = null;
if(r instanceof NumberRecord) {
cvr = (CellValueRecordInterface)r;
}
if(r instanceof FormulaRecord) {
cvr = (CellValueRecordInterface)r;
}
if(cvr != null) {
// Should always give us a string
String s = listener.formatNumberDateCell(cvr);
assertNotNull(s);
assertTrue(s.length() > 0);
}
}
// TODO - test some specific format strings
}
// TODO - test some specific format strings
}
private static final class MockHSSFListener implements HSSFListener {

Carregando…
Cancelar
Salvar