added extra RVA test case (for bug 45206)

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@668014 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Josh Micich 2008-06-15 22:26:06 +00:00
parent e1de21bc09
commit 473ac7ad05
3 changed files with 17 additions and 16 deletions

View File

@ -15,11 +15,10 @@
limitations under the License. limitations under the License.
==================================================================== */ ==================================================================== */
package org.apache.poi.hssf.record.formula; package org.apache.poi.hssf.record.formula;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.record.RecordInputStream; import org.apache.poi.hssf.record.RecordInputStream;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.util.CellReference; import org.apache.poi.hssf.util.CellReference;
import org.apache.poi.hssf.util.RangeAddress; import org.apache.poi.hssf.util.RangeAddress;
import org.apache.poi.hssf.util.SheetReferences; import org.apache.poi.hssf.util.SheetReferences;
@ -69,16 +68,15 @@ public class Ref3DPtg extends OperandPtg {
} }
public String toString() { public String toString() {
StringBuffer buffer = new StringBuffer(); CellReference cr = new CellReference(getRow(), getColumn(), !isRowRelative(),!isColRelative());
StringBuffer sb = new StringBuffer();
buffer.append("Ref3dPtg\n"); sb.append(getClass().getName());
buffer.append("Index to Extern Sheet = " + getExternSheetIndex()).append("\n"); sb.append(" [");
buffer.append("Row = " + getRow()).append("\n"); sb.append("sheetIx=").append(getExternSheetIndex());
buffer.append("Col = " + getColumn()).append("\n"); sb.append(" ! ");
buffer.append("ColRowRel= " sb.append(cr.formatAsString());
+ isRowRelative()).append("\n"); sb.append("]");
buffer.append("ColRel = " + isColRelative()).append("\n"); return sb.toString();
return buffer.toString();
} }
public void writeBytes(byte [] array, int offset) { public void writeBytes(byte [] array, int offset) {

View File

@ -23,7 +23,6 @@ import junit.framework.TestCase;
import org.apache.poi.hssf.HSSFTestDataSamples; import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.hssf.record.formula.AttrPtg; import org.apache.poi.hssf.record.formula.AttrPtg;
import org.apache.poi.hssf.record.formula.Ptg; import org.apache.poi.hssf.record.formula.Ptg;
import org.apache.poi.hssf.record.formula.RefPtgBase;
import org.apache.poi.hssf.usermodel.FormulaExtractor; import org.apache.poi.hssf.usermodel.FormulaExtractor;
import org.apache.poi.hssf.usermodel.HSSFCell; import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow; import org.apache.poi.hssf.usermodel.HSSFRow;
@ -60,7 +59,7 @@ public final class TestRVA extends TestCase {
} }
String formula = cell.getCellFormula(); String formula = cell.getCellFormula();
try { try {
confirmCell(cell, formula); confirmCell(cell, formula, wb);
} catch (AssertionFailedError e) { } catch (AssertionFailedError e) {
System.err.println("Problem with row[" + rowIx + "] formula '" + formula + "'"); System.err.println("Problem with row[" + rowIx + "] formula '" + formula + "'");
System.err.println(e.getMessage()); System.err.println(e.getMessage());
@ -79,9 +78,9 @@ public final class TestRVA extends TestCase {
} }
} }
private void confirmCell(HSSFCell formulaCell, String formula) { private void confirmCell(HSSFCell formulaCell, String formula, HSSFWorkbook wb) {
Ptg[] excelPtgs = FormulaExtractor.getPtgs(formulaCell); Ptg[] excelPtgs = FormulaExtractor.getPtgs(formulaCell);
Ptg[] poiPtgs = FormulaParser.parse(formula, null); Ptg[] poiPtgs = FormulaParser.parse(formula, wb);
int nExcelTokens = excelPtgs.length; int nExcelTokens = excelPtgs.length;
int nPoiTokens = poiPtgs.length; int nPoiTokens = poiPtgs.length;
if (nExcelTokens != nPoiTokens) { if (nExcelTokens != nPoiTokens) {
@ -122,6 +121,10 @@ public final class TestRVA extends TestCase {
} }
sb.append(NEW_LINE); sb.append(NEW_LINE);
} }
if (false) { // set 'true' to see trace of RVA values
System.out.println(formula);
System.out.println(sb.toString());
}
if (hasMismatch) { if (hasMismatch) {
throw new AssertionFailedError(sb.toString()); throw new AssertionFailedError(sb.toString());
} }