aboutsummaryrefslogtreecommitdiffstats
path: root/src/testcases/org/apache/poi
diff options
context:
space:
mode:
authorJosh Micich <josh@apache.org>2008-09-19 02:19:58 +0000
committerJosh Micich <josh@apache.org>2008-09-19 02:19:58 +0000
commit70e85686963adf321894979ad32b8718d279468f (patch)
tree6055a081670bafe5fe17f001b5be721ed4f348b5 /src/testcases/org/apache/poi
parentaa556876b92150ad5d22c7247deb3656f538f92e (diff)
downloadpoi-70e85686963adf321894979ad32b8718d279468f.tar.gz
poi-70e85686963adf321894979ad32b8718d279468f.zip
Partitioning common formula logic. Introduced FormulaParsingWorkbook and EvaluationWorkbook interfaces to make merge with ooxml branch easier
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@696898 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/testcases/org/apache/poi')
-rw-r--r--src/testcases/org/apache/poi/hssf/eventusermodel/TestEventWorkbookBuilder.java10
-rw-r--r--src/testcases/org/apache/poi/hssf/model/TestFormulaParser.java57
-rw-r--r--src/testcases/org/apache/poi/hssf/model/TestFormulaParserEval.java18
-rw-r--r--src/testcases/org/apache/poi/hssf/model/TestOperandClassTransformer.java17
-rw-r--r--src/testcases/org/apache/poi/hssf/model/TestRVA.java2
-rw-r--r--src/testcases/org/apache/poi/hssf/record/formula/TestAreaPtg.java6
-rwxr-xr-xsrc/testcases/org/apache/poi/hssf/record/formula/TestExternalFunctionFormulas.java4
-rw-r--r--src/testcases/org/apache/poi/hssf/record/formula/TestFuncVarPtg.java4
-rw-r--r--src/testcases/org/apache/poi/hssf/record/formula/function/TestParseMissingBuiltInFuncs.java6
-rw-r--r--src/testcases/org/apache/poi/hssf/record/formula/functions/TestDate.java2
-rw-r--r--src/testcases/org/apache/poi/ss/formula/FormulaParserTestHelper.java48
11 files changed, 116 insertions, 58 deletions
diff --git a/src/testcases/org/apache/poi/hssf/eventusermodel/TestEventWorkbookBuilder.java b/src/testcases/org/apache/poi/hssf/eventusermodel/TestEventWorkbookBuilder.java
index a17414af74..2c56ea57a1 100644
--- a/src/testcases/org/apache/poi/hssf/eventusermodel/TestEventWorkbookBuilder.java
+++ b/src/testcases/org/apache/poi/hssf/eventusermodel/TestEventWorkbookBuilder.java
@@ -26,7 +26,7 @@ import junit.framework.TestCase;
import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.hssf.eventusermodel.EventWorkbookBuilder.SheetRecordCollectingListener;
-import org.apache.poi.hssf.model.FormulaParser;
+import org.apache.poi.hssf.model.HSSFFormulaParser;
import org.apache.poi.hssf.model.Workbook;
import org.apache.poi.hssf.record.FormulaRecord;
import org.apache.poi.hssf.record.Record;
@@ -101,7 +101,7 @@ public final class TestEventWorkbookBuilder extends TestCase {
// Check we can get the formula without breaking
for(int i=0; i<fRecs.length; i++) {
- FormulaParser.toFormulaString(stubHSSF, fRecs[i].getParsedExpression());
+ HSSFFormulaParser.toFormulaString(stubHSSF, fRecs[i].getParsedExpression());
}
// Peer into just one formula, and check that
@@ -123,19 +123,19 @@ public final class TestEventWorkbookBuilder extends TestCase {
fr = fRecs[0];
assertEquals(1, fr.getRow());
assertEquals(0, fr.getColumn());
- assertEquals("Sheet1!A1", FormulaParser.toFormulaString(stubHSSF, fr.getParsedExpression()));
+ assertEquals("Sheet1!A1", HSSFFormulaParser.toFormulaString(stubHSSF, fr.getParsedExpression()));
// Sheet 1 A5 is to another sheet
fr = fRecs[3];
assertEquals(4, fr.getRow());
assertEquals(0, fr.getColumn());
- assertEquals("'S2'!A1", FormulaParser.toFormulaString(stubHSSF, fr.getParsedExpression()));
+ assertEquals("'S2'!A1", HSSFFormulaParser.toFormulaString(stubHSSF, fr.getParsedExpression()));
// Sheet 1 A7 is to another sheet, range
fr = fRecs[5];
assertEquals(6, fr.getRow());
assertEquals(0, fr.getColumn());
- assertEquals("SUM(Sh3!A1:A4)", FormulaParser.toFormulaString(stubHSSF, fr.getParsedExpression()));
+ assertEquals("SUM(Sh3!A1:A4)", HSSFFormulaParser.toFormulaString(stubHSSF, fr.getParsedExpression()));
// Now, load via Usermodel and re-check
diff --git a/src/testcases/org/apache/poi/hssf/model/TestFormulaParser.java b/src/testcases/org/apache/poi/hssf/model/TestFormulaParser.java
index bb9f3de605..016fa8398c 100644
--- a/src/testcases/org/apache/poi/hssf/model/TestFormulaParser.java
+++ b/src/testcases/org/apache/poi/hssf/model/TestFormulaParser.java
@@ -21,7 +21,6 @@ import junit.framework.AssertionFailedError;
import junit.framework.TestCase;
import org.apache.poi.hssf.HSSFTestDataSamples;
-import org.apache.poi.hssf.model.FormulaParser.FormulaParseException;
import org.apache.poi.hssf.record.constant.ErrorConstant;
import org.apache.poi.hssf.record.formula.AbstractFunctionPtg;
import org.apache.poi.hssf.record.formula.AddPtg;
@@ -56,6 +55,7 @@ import org.apache.poi.hssf.usermodel.HSSFName;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+import org.apache.poi.ss.formula.FormulaParserTestHelper;
/**
* Test the low level formula parser functionality. High level tests are to
@@ -67,10 +67,13 @@ public final class TestFormulaParser extends TestCase {
* @return parsed token array already confirmed not <code>null</code>
*/
/* package */ static Ptg[] parseFormula(String formula) {
- Ptg[] result = FormulaParser.parse(formula, null);
+ Ptg[] result = HSSFFormulaParser.parse(formula, (HSSFWorkbook)null);
assertNotNull("Ptg array should not be null", result);
return result;
}
+ private static String toFormulaString(Ptg[] ptgs) {
+ return HSSFFormulaParser.toFormulaString((HSSFWorkbook)null, ptgs);
+ }
public void testSimpleFormula() {
Ptg[] ptgs = parseFormula("2+2");
@@ -133,7 +136,7 @@ public final class TestFormulaParser extends TestCase {
HSSFWorkbook w = HSSFTestDataSamples.openSampleWorkbook("testNames.xls");
HSSFEvaluationWorkbook book = HSSFEvaluationWorkbook.create(w);
- Ptg[] ptg = FormulaParser.parse("myFunc()", w);
+ Ptg[] ptg = HSSFFormulaParser.parse("myFunc()", w);
// myFunc() actually takes 1 parameter. Don't know if POI will ever be able to detect this problem
// the name gets encoded as the first arg
@@ -405,7 +408,7 @@ public final class TestFormulaParser extends TestCase {
Ptg[] ptgs = {
new FuncPtg(10),
};
- assertEquals("NA()", FormulaParser.toFormulaString(book, ptgs));
+ assertEquals("NA()", HSSFFormulaParser.toFormulaString(book, ptgs));
}
public void testPercent() {
@@ -639,11 +642,11 @@ public final class TestFormulaParser extends TestCase {
String formulaString;
Ptg[] ptgs;
ptgs = parseFormula("sum(5, 2, if(3>2, sum(A1:A2), 6))");
- formulaString = FormulaParser.toFormulaString(null, ptgs);
+ formulaString = toFormulaString(ptgs);
assertEquals("SUM(5,2,IF(3>2,SUM(A1:A2),6))", formulaString);
ptgs = parseFormula("if(1<2,sum(5, 2, if(3>2, sum(A1:A2), 6)),4)");
- formulaString = FormulaParser.toFormulaString(null, ptgs);
+ formulaString = toFormulaString(ptgs);
assertEquals("IF(1<2,SUM(5,2,IF(3>2,SUM(A1:A2),6)),4)", formulaString);
}
public void testParserErrors() {
@@ -665,12 +668,9 @@ public final class TestFormulaParser extends TestCase {
try {
parseFormula(formula);
throw new AssertionFailedError("expected parse exception");
- } catch (FormulaParseException e) {
- // expected during successful test
- assertNotNull(e.getMessage());
} catch (RuntimeException e) {
- e.printStackTrace();
- fail("Wrong exception:" + e.getMessage());
+ // expected during successful test
+ FormulaParserTestHelper.confirmParseException(e);
}
}
@@ -697,7 +697,7 @@ public final class TestFormulaParser extends TestCase {
Ptg[] ptgs = { spacePtg, new IntPtg(4), };
String formulaString;
try {
- formulaString = FormulaParser.toFormulaString(null, ptgs);
+ formulaString = toFormulaString(ptgs);
} catch (IllegalStateException e) {
if(e.getMessage().equalsIgnoreCase("too much stuff left on the stack")) {
throw new AssertionFailedError("Identified bug 44609");
@@ -709,7 +709,7 @@ public final class TestFormulaParser extends TestCase {
assertEquals("4", formulaString);
ptgs = new Ptg[] { new IntPtg(3), spacePtg, new IntPtg(4), spacePtg, AddPtg.instance, };
- formulaString = FormulaParser.toFormulaString(null, ptgs);
+ formulaString = toFormulaString(ptgs);
assertEquals("3+4", formulaString);
}
@@ -725,7 +725,7 @@ public final class TestFormulaParser extends TestCase {
DividePtg.instance,
};
try {
- FormulaParser.toFormulaString(null, ptgs);
+ toFormulaString(ptgs);
fail("Expected exception was not thrown");
} catch (IllegalStateException e) {
// expected during successful test
@@ -764,10 +764,10 @@ public final class TestFormulaParser extends TestCase {
private static void confirmArgCountMsg(String formula, String expectedMessage) {
HSSFWorkbook book = new HSSFWorkbook();
try {
- FormulaParser.parse(formula, book);
+ HSSFFormulaParser.parse(formula, book);
throw new AssertionFailedError("Didn't get parse exception as expected");
- } catch (FormulaParseException e) {
- assertEquals(expectedMessage, e.getMessage());
+ } catch (RuntimeException e) {
+ FormulaParserTestHelper.confirmParseException(e, expectedMessage);
}
}
@@ -776,15 +776,17 @@ public final class TestFormulaParser extends TestCase {
try {
parseFormula("round(3.14;2)");
throw new AssertionFailedError("Didn't get parse exception as expected");
- } catch (FormulaParseException e) {
- assertEquals("Parse error near char 10 ';' in specified formula 'round(3.14;2)'. Expected ',' or ')'", e.getMessage());
+ } catch (RuntimeException e) {
+ FormulaParserTestHelper.confirmParseException(e,
+ "Parse error near char 10 ';' in specified formula 'round(3.14;2)'. Expected ',' or ')'");
}
try {
parseFormula(" =2+2");
throw new AssertionFailedError("Didn't get parse exception as expected");
- } catch (FormulaParseException e) {
- assertEquals("The specified formula ' =2+2' starts with an equals sign which is not allowed.", e.getMessage());
+ } catch (RuntimeException e) {
+ FormulaParserTestHelper.confirmParseException(e,
+ "The specified formula ' =2+2' starts with an equals sign which is not allowed.");
}
}
@@ -819,7 +821,7 @@ public final class TestFormulaParser extends TestCase {
Ptg[] ptgs;
try {
- ptgs = FormulaParser.parse("count(pfy1)", wb);
+ ptgs = HSSFFormulaParser.parse("count(pfy1)", wb);
} catch (IllegalArgumentException e) {
if (e.getMessage().equals("Specified colIx (1012) is out of range")) {
throw new AssertionFailedError("Identified bug 45354");
@@ -835,10 +837,9 @@ public final class TestFormulaParser extends TestCase {
try {
cell.setCellFormula("count(pf1)");
throw new AssertionFailedError("Expected formula parse execption");
- } catch (FormulaParseException e) {
- if (!e.getMessage().equals("Specified named range 'pf1' does not exist in the current workbook.")) {
- throw e;
- }
+ } catch (RuntimeException e) {
+ FormulaParserTestHelper.confirmParseException(e,
+ "Specified named range 'pf1' does not exist in the current workbook.");
}
cell.setCellFormula("count(fp1)"); // plain cell ref, col is in range
}
@@ -850,14 +851,14 @@ public final class TestFormulaParser extends TestCase {
HSSFWorkbook book = new HSSFWorkbook();
book.createSheet("Sheet1");
- ptgs = FormulaParser.parse("Sheet1!A10:A40000", book);
+ ptgs = HSSFFormulaParser.parse("Sheet1!A10:A40000", book);
aptg = (AreaI) ptgs[0];
if (aptg.getLastRow() == -25537) {
throw new AssertionFailedError("Identified bug 45358");
}
assertEquals(39999, aptg.getLastRow());
- ptgs = FormulaParser.parse("Sheet1!A10:A65536", book);
+ ptgs = HSSFFormulaParser.parse("Sheet1!A10:A65536", book);
aptg = (AreaI) ptgs[0];
assertEquals(65535, aptg.getLastRow());
diff --git a/src/testcases/org/apache/poi/hssf/model/TestFormulaParserEval.java b/src/testcases/org/apache/poi/hssf/model/TestFormulaParserEval.java
index 2bede8e5f5..fbbdbd54dc 100644
--- a/src/testcases/org/apache/poi/hssf/model/TestFormulaParserEval.java
+++ b/src/testcases/org/apache/poi/hssf/model/TestFormulaParserEval.java
@@ -17,9 +17,9 @@
package org.apache.poi.hssf.model;
+import junit.framework.AssertionFailedError;
import junit.framework.TestCase;
-import org.apache.poi.hssf.model.FormulaParser.FormulaParseException;
import org.apache.poi.hssf.record.formula.FuncVarPtg;
import org.apache.poi.hssf.record.formula.NamePtg;
import org.apache.poi.hssf.record.formula.Ptg;
@@ -30,6 +30,7 @@ import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator.CellValue;
+import org.apache.poi.ss.formula.FormulaParserTestHelper;
/**
* Test the low level formula parser functionality,
@@ -51,21 +52,21 @@ public final class TestFormulaParserEval extends TestCase {
name.setNameName("testName");
name.setReference("A1:A2");
- ptgs = FormulaParser.parse("SUM(testName)", workbook);
+ ptgs = HSSFFormulaParser.parse("SUM(testName)", workbook);
assertTrue("two tokens expected, got "+ptgs.length,ptgs.length == 2);
assertEquals(NamePtg.class, ptgs[0].getClass());
assertEquals(FuncVarPtg.class, ptgs[1].getClass());
// Now make it a single cell
name.setReference("C3");
- ptgs = FormulaParser.parse("SUM(testName)", workbook);
+ ptgs = HSSFFormulaParser.parse("SUM(testName)", workbook);
assertTrue("two tokens expected, got "+ptgs.length,ptgs.length == 2);
assertEquals(NamePtg.class, ptgs[0].getClass());
assertEquals(FuncVarPtg.class, ptgs[1].getClass());
// And make it non-contiguous
name.setReference("A1:A2,C3");
- ptgs = FormulaParser.parse("SUM(testName)", workbook);
+ ptgs = HSSFFormulaParser.parse("SUM(testName)", workbook);
assertTrue("two tokens expected, got "+ptgs.length,ptgs.length == 2);
assertEquals(NamePtg.class, ptgs[0].getClass());
assertEquals(FuncVarPtg.class, ptgs[1].getClass());
@@ -89,11 +90,12 @@ public final class TestFormulaParserEval extends TestCase {
CellValue result;
try {
result = fe.evaluate(cell);
- } catch (FormulaParseException e) {
- if(e.getMessage().equals("Found reference to named range \"A\", but that named range wasn't defined!")) {
- fail("Identifed bug 44539");
+ } catch (RuntimeException e) {
+ FormulaParserTestHelper.confirmParseException(e);
+ if (!e.getMessage().equals("Found reference to named range \"A\", but that named range wasn't defined!")) {
+ throw new AssertionFailedError("Identifed bug 44539");
}
- throw new RuntimeException(e);
+ throw e;
}
assertEquals(HSSFCell.CELL_TYPE_NUMERIC, result.getCellType());
assertEquals(42.0, result.getNumberValue(), 0.0);
diff --git a/src/testcases/org/apache/poi/hssf/model/TestOperandClassTransformer.java b/src/testcases/org/apache/poi/hssf/model/TestOperandClassTransformer.java
index 47cfb574c1..530c2b09c2 100644
--- a/src/testcases/org/apache/poi/hssf/model/TestOperandClassTransformer.java
+++ b/src/testcases/org/apache/poi/hssf/model/TestOperandClassTransformer.java
@@ -23,6 +23,7 @@ import junit.framework.TestCase;
import org.apache.poi.hssf.record.formula.AbstractFunctionPtg;
import org.apache.poi.hssf.record.formula.FuncVarPtg;
import org.apache.poi.hssf.record.formula.Ptg;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
/**
* Tests specific formula examples in <tt>OperandClassTransformer</tt>.
@@ -31,9 +32,15 @@ import org.apache.poi.hssf.record.formula.Ptg;
*/
public final class TestOperandClassTransformer extends TestCase {
+ private static Ptg[] parseFormula(String formula) {
+ Ptg[] result = HSSFFormulaParser.parse(formula, (HSSFWorkbook)null);
+ assertNotNull("Ptg array should not be null", result);
+ return result;
+ }
+
public void testMdeterm() {
String formula = "MDETERM(ABS(A1))";
- Ptg[] ptgs = FormulaParser.parse(formula, null);
+ Ptg[] ptgs = parseFormula(formula);
confirmTokenClass(ptgs, 0, Ptg.CLASS_ARRAY);
confirmFuncClass(ptgs, 1, "ABS", Ptg.CLASS_ARRAY);
@@ -51,7 +58,7 @@ public final class TestOperandClassTransformer extends TestCase {
*/
public void DISABLED_testIndexPi1() {
String formula = "INDEX(PI(),1)";
- Ptg[] ptgs = FormulaParser.parse(formula, null);
+ Ptg[] ptgs = parseFormula(formula);
confirmFuncClass(ptgs, 1, "PI", Ptg.CLASS_ARRAY); // fails as of POI 3.1
confirmFuncClass(ptgs, 2, "INDEX", Ptg.CLASS_VALUE);
@@ -63,7 +70,7 @@ public final class TestOperandClassTransformer extends TestCase {
*/
public void testDirectOperandOfValueOperator() {
String formula = "COUNT(A1*1)";
- Ptg[] ptgs = FormulaParser.parse(formula, null);
+ Ptg[] ptgs = parseFormula(formula);
if (ptgs[0].getPtgClass() == Ptg.CLASS_REF) {
throw new AssertionFailedError("Identified bug 45348");
}
@@ -78,13 +85,13 @@ public final class TestOperandClassTransformer extends TestCase {
public void testRtoV() {
String formula = "lookup(A1, A3:A52, B3:B52)";
- Ptg[] ptgs = FormulaParser.parse(formula, null);
+ Ptg[] ptgs = parseFormula(formula);
confirmTokenClass(ptgs, 0, Ptg.CLASS_VALUE);
}
public void testComplexIRR_bug45041() {
String formula = "(1+IRR(SUMIF(A:A,ROW(INDIRECT(MIN(A:A)&\":\"&MAX(A:A))),B:B),0))^365-1";
- Ptg[] ptgs = FormulaParser.parse(formula, null);
+ Ptg[] ptgs = parseFormula(formula);
FuncVarPtg rowFunc = (FuncVarPtg) ptgs[10];
FuncVarPtg sumifFunc = (FuncVarPtg) ptgs[12];
diff --git a/src/testcases/org/apache/poi/hssf/model/TestRVA.java b/src/testcases/org/apache/poi/hssf/model/TestRVA.java
index 1ec7c92ae9..eb69a5cd0b 100644
--- a/src/testcases/org/apache/poi/hssf/model/TestRVA.java
+++ b/src/testcases/org/apache/poi/hssf/model/TestRVA.java
@@ -82,7 +82,7 @@ public final class TestRVA extends TestCase {
private void confirmCell(HSSFCell formulaCell, String formula, HSSFWorkbook wb) {
Ptg[] excelPtgs = FormulaExtractor.getPtgs(formulaCell);
- Ptg[] poiPtgs = FormulaParser.parse(formula, wb);
+ Ptg[] poiPtgs = HSSFFormulaParser.parse(formula, wb);
int nExcelTokens = excelPtgs.length;
int nPoiTokens = poiPtgs.length;
if (nExcelTokens != nPoiTokens) {
diff --git a/src/testcases/org/apache/poi/hssf/record/formula/TestAreaPtg.java b/src/testcases/org/apache/poi/hssf/record/formula/TestAreaPtg.java
index f5b80f6dac..84f6897748 100644
--- a/src/testcases/org/apache/poi/hssf/record/formula/TestAreaPtg.java
+++ b/src/testcases/org/apache/poi/hssf/record/formula/TestAreaPtg.java
@@ -20,7 +20,7 @@ package org.apache.poi.hssf.record.formula;
import junit.framework.TestCase;
-import org.apache.poi.hssf.model.FormulaParser;
+import org.apache.poi.hssf.model.HSSFFormulaParser;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
/**
@@ -87,7 +87,7 @@ public final class TestAreaPtg extends TestCase {
private static String shiftAllColumnsBy1(String formula) {
int letUsShiftColumn1By1Column=1;
HSSFWorkbook wb = null;
- Ptg[] ptgs = FormulaParser.parse(formula, wb);
+ Ptg[] ptgs = HSSFFormulaParser.parse(formula, wb);
for(int i=0; i<ptgs.length; i++)
{
Ptg ptg = ptgs[i];
@@ -98,7 +98,7 @@ public final class TestAreaPtg extends TestCase {
aptg.setLastColumn((short)(aptg.getLastColumn()+letUsShiftColumn1By1Column));
}
}
- String newFormula = FormulaParser.toFormulaString(wb, ptgs);
+ String newFormula = HSSFFormulaParser.toFormulaString(wb, ptgs);
return newFormula;
}
}
diff --git a/src/testcases/org/apache/poi/hssf/record/formula/TestExternalFunctionFormulas.java b/src/testcases/org/apache/poi/hssf/record/formula/TestExternalFunctionFormulas.java
index 53d51ca0f1..7098dd1a71 100755
--- a/src/testcases/org/apache/poi/hssf/record/formula/TestExternalFunctionFormulas.java
+++ b/src/testcases/org/apache/poi/hssf/record/formula/TestExternalFunctionFormulas.java
@@ -24,7 +24,7 @@ import java.io.IOException;
import junit.framework.TestCase;
import org.apache.poi.hssf.HSSFTestDataSamples;
-import org.apache.poi.hssf.model.FormulaParser;
+import org.apache.poi.hssf.model.HSSFFormulaParser;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator;
import org.apache.poi.hssf.usermodel.HSSFSheet;
@@ -52,7 +52,7 @@ public final class TestExternalFunctionFormulas extends TestCase {
public void testParse() {
HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("externalFunctionExample.xls");
- Ptg[] ptgs = FormulaParser.parse("YEARFRAC(B1,C1)", wb);
+ Ptg[] ptgs = HSSFFormulaParser.parse("YEARFRAC(B1,C1)", wb);
assertEquals(4, ptgs.length);
assertEquals(NameXPtg.class, ptgs[0].getClass());
diff --git a/src/testcases/org/apache/poi/hssf/record/formula/TestFuncVarPtg.java b/src/testcases/org/apache/poi/hssf/record/formula/TestFuncVarPtg.java
index 58ae55f26b..ec9c3d1e85 100644
--- a/src/testcases/org/apache/poi/hssf/record/formula/TestFuncVarPtg.java
+++ b/src/testcases/org/apache/poi/hssf/record/formula/TestFuncVarPtg.java
@@ -17,7 +17,7 @@
package org.apache.poi.hssf.record.formula;
-import org.apache.poi.hssf.model.FormulaParser;
+import org.apache.poi.hssf.model.HSSFFormulaParser;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import junit.framework.AssertionFailedError;
@@ -36,7 +36,7 @@ public final class TestFuncVarPtg extends TestCase {
*/
public void testOperandClass() {
HSSFWorkbook book = new HSSFWorkbook();
- Ptg[] ptgs = FormulaParser.parse("sum(A1:A2)", book);
+ Ptg[] ptgs = HSSFFormulaParser.parse("sum(A1:A2)", book);
assertEquals(2, ptgs.length);
assertEquals(AreaPtg.class, ptgs[0].getClass());
diff --git a/src/testcases/org/apache/poi/hssf/record/formula/function/TestParseMissingBuiltInFuncs.java b/src/testcases/org/apache/poi/hssf/record/formula/function/TestParseMissingBuiltInFuncs.java
index 7030c5a508..95ad2ef535 100644
--- a/src/testcases/org/apache/poi/hssf/record/formula/function/TestParseMissingBuiltInFuncs.java
+++ b/src/testcases/org/apache/poi/hssf/record/formula/function/TestParseMissingBuiltInFuncs.java
@@ -20,7 +20,7 @@ package org.apache.poi.hssf.record.formula.function;
import junit.framework.AssertionFailedError;
import junit.framework.TestCase;
-import org.apache.poi.hssf.model.FormulaParser;
+import org.apache.poi.hssf.model.HSSFFormulaParser;
import org.apache.poi.hssf.record.formula.AbstractFunctionPtg;
import org.apache.poi.hssf.record.formula.FuncPtg;
import org.apache.poi.hssf.record.formula.FuncVarPtg;
@@ -36,7 +36,7 @@ public final class TestParseMissingBuiltInFuncs extends TestCase {
private static Ptg[] parse(String formula) {
HSSFWorkbook book = new HSSFWorkbook();
- return FormulaParser.parse(formula, book);
+ return HSSFFormulaParser.parse(formula, book);
}
private static void confirmFunc(String formula, int expPtgArraySize, boolean isVarArgFunc, int funcIx) {
Ptg[] ptgs = parse(formula);
@@ -58,7 +58,7 @@ public final class TestParseMissingBuiltInFuncs extends TestCase {
// check that parsed Ptg array converts back to formula text OK
HSSFWorkbook book = new HSSFWorkbook();
- String reRenderedFormula = FormulaParser.toFormulaString(book, ptgs);
+ String reRenderedFormula = HSSFFormulaParser.toFormulaString(book, ptgs);
assertEquals(formula, reRenderedFormula);
}
diff --git a/src/testcases/org/apache/poi/hssf/record/formula/functions/TestDate.java b/src/testcases/org/apache/poi/hssf/record/formula/functions/TestDate.java
index 0c08ef5a54..b93eb7a6c7 100644
--- a/src/testcases/org/apache/poi/hssf/record/formula/functions/TestDate.java
+++ b/src/testcases/org/apache/poi/hssf/record/formula/functions/TestDate.java
@@ -76,7 +76,7 @@ public final class TestDate extends TestCase {
private void confirm(String formulaText, double expectedResult) {
cell11.setCellFormula(formulaText);
- evaluator.clearCache();
+ evaluator.clearAllCachedResultValues();
double actualValue = evaluator.evaluate(cell11).getNumberValue();
assertEquals(expectedResult, actualValue, 0);
}
diff --git a/src/testcases/org/apache/poi/ss/formula/FormulaParserTestHelper.java b/src/testcases/org/apache/poi/ss/formula/FormulaParserTestHelper.java
new file mode 100644
index 0000000000..144002279d
--- /dev/null
+++ b/src/testcases/org/apache/poi/ss/formula/FormulaParserTestHelper.java
@@ -0,0 +1,48 @@
+/* ====================================================================
+ 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.ss.formula;
+
+import junit.framework.Assert;
+import junit.framework.AssertionFailedError;
+
+import org.apache.poi.ss.formula.FormulaParser;
+import org.apache.poi.ss.formula.FormulaParser.FormulaParseException;
+/**
+ * Avoids making {@link FormulaParser#FormulaParseException} public
+ *
+ * @author Josh Micich
+ */
+public class FormulaParserTestHelper {
+ public static void confirmParseException(RuntimeException e, String expectedMessage) {
+ checkType(e);
+ Assert.assertEquals(expectedMessage, e.getMessage());
+ }
+ public static void confirmParseException(RuntimeException e) {
+ checkType(e);
+ Assert.assertNotNull(e.getMessage());
+ }
+ private static void checkType(RuntimeException e) throws AssertionFailedError {
+ if (!(e instanceof FormulaParseException)) {
+ String failMsg = "Expected FormulaParseException, but got ("
+ + e.getClass().getName() + "):";
+ System.err.println(failMsg);
+ e.printStackTrace();
+ throw new AssertionFailedError(failMsg);
+ }
+ }
+}