diff options
author | Josh Micich <josh@apache.org> | 2008-09-18 23:14:48 +0000 |
---|---|---|
committer | Josh Micich <josh@apache.org> | 2008-09-18 23:14:48 +0000 |
commit | e78a288ddfc77af316d6be4b7eaa535ba08badd4 (patch) | |
tree | 4faa04e10bbc30edf7b8c6e248bec184a4d27791 /src/testcases/org | |
parent | 4769ade087e58d049a1e3bcf1a0d4987dcb378a2 (diff) | |
download | poi-e78a288ddfc77af316d6be4b7eaa535ba08badd4.tar.gz poi-e78a288ddfc77af316d6be4b7eaa535ba08badd4.zip |
Merged revisions 696813 via svnmerge from
https://svn.apache.org/repos/asf/poi/trunk
........
r696813 | josh | 2008-09-18 14:22:23 -0700 (Thu, 18 Sep 2008) | 1 line
Partitioning common formula logic. Introduced FormulaRenderingWorkbook interface to make merge with ooxml branch easier
........
git-svn-id: https://svn.apache.org/repos/asf/poi/branches/ooxml@696847 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/testcases/org')
10 files changed, 47 insertions, 46 deletions
diff --git a/src/testcases/org/apache/poi/hssf/eventusermodel/TestEventWorkbookBuilder.java b/src/testcases/org/apache/poi/hssf/eventusermodel/TestEventWorkbookBuilder.java index e88d274eac..a17414af74 100644 --- a/src/testcases/org/apache/poi/hssf/eventusermodel/TestEventWorkbookBuilder.java +++ b/src/testcases/org/apache/poi/hssf/eventusermodel/TestEventWorkbookBuilder.java @@ -32,6 +32,7 @@ import org.apache.poi.hssf.record.FormulaRecord; import org.apache.poi.hssf.record.Record; import org.apache.poi.hssf.record.formula.Ptg; import org.apache.poi.hssf.record.formula.Ref3DPtg; +import org.apache.poi.hssf.usermodel.HSSFEvaluationWorkbook; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.poifs.filesystem.POIFSFileSystem; /** @@ -110,7 +111,8 @@ public final class TestEventWorkbookBuilder extends TestCase { assertTrue(ptgs[0] instanceof Ref3DPtg); Ref3DPtg ptg = (Ref3DPtg)ptgs[0]; - assertEquals("Sheet1!A1", ptg.toFormulaString(stubHSSF)); + HSSFEvaluationWorkbook book = HSSFEvaluationWorkbook.create(stubHSSF); + assertEquals("Sheet1!A1", ptg.toFormulaString(book)); // Now check we get the right formula back for diff --git a/src/testcases/org/apache/poi/hssf/model/TestFormulaParser.java b/src/testcases/org/apache/poi/hssf/model/TestFormulaParser.java index e1ffc2538d..bb9f3de605 100644 --- a/src/testcases/org/apache/poi/hssf/model/TestFormulaParser.java +++ b/src/testcases/org/apache/poi/hssf/model/TestFormulaParser.java @@ -51,6 +51,7 @@ import org.apache.poi.hssf.record.formula.UnaryMinusPtg; import org.apache.poi.hssf.record.formula.UnaryPlusPtg; import org.apache.poi.hssf.usermodel.HSSFCell; import org.apache.poi.hssf.usermodel.HSSFErrorConstants; +import org.apache.poi.hssf.usermodel.HSSFEvaluationWorkbook; import org.apache.poi.hssf.usermodel.HSSFName; import org.apache.poi.hssf.usermodel.HSSFRow; import org.apache.poi.hssf.usermodel.HSSFSheet; @@ -130,13 +131,14 @@ public final class TestFormulaParser extends TestCase { public void testMacroFunction() { // testNames.xls contains a VB function called 'myFunc' HSSFWorkbook w = HSSFTestDataSamples.openSampleWorkbook("testNames.xls"); + HSSFEvaluationWorkbook book = HSSFEvaluationWorkbook.create(w); Ptg[] ptg = FormulaParser.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 NamePtg tname = (NamePtg) ptg[0]; - assertEquals("myFunc", tname.toFormulaString(w)); + assertEquals("myFunc", tname.toFormulaString(book)); AbstractFunctionPtg tfunc = (AbstractFunctionPtg) ptg[1]; assertTrue(tfunc.isExternalFunction()); @@ -871,7 +873,7 @@ public final class TestFormulaParser extends TestCase { assertEquals(2, ptgs.length); Ptg ptg0 = ptgs[0]; assertEquals(ArrayPtg.class, ptg0.getClass()); - assertEquals("{1.0,2.0,2.0,#REF!;FALSE,3.0,3.0,2.0}", ptg0.toFormulaString(null)); + assertEquals("{1.0,2.0,2.0,#REF!;FALSE,3.0,3.0,2.0}", ptg0.toFormulaString()); ArrayPtg aptg = (ArrayPtg) ptg0; Object[][] values = aptg.getTokenArrayValues(); diff --git a/src/testcases/org/apache/poi/hssf/model/TestFormulaParserIf.java b/src/testcases/org/apache/poi/hssf/model/TestFormulaParserIf.java index 6f7c4747cf..415cca33f1 100644 --- a/src/testcases/org/apache/poi/hssf/model/TestFormulaParserIf.java +++ b/src/testcases/org/apache/poi/hssf/model/TestFormulaParserIf.java @@ -33,7 +33,6 @@ import org.apache.poi.hssf.record.formula.NotEqualPtg; import org.apache.poi.hssf.record.formula.Ptg; import org.apache.poi.hssf.record.formula.RefPtg; import org.apache.poi.hssf.record.formula.StringPtg; -import org.apache.poi.hssf.usermodel.HSSFWorkbook; /** * Tests <tt>FormulaParser</tt> specifically with respect to IF() functions @@ -202,7 +201,7 @@ public final class TestFormulaParserIf extends TestCase { assertEquals(true, flag.getValue()); assertEquals("Y", y.getValue()); assertEquals("N", n.getValue()); - assertEquals("IF", funif.toFormulaString((HSSFWorkbook) null)); + assertEquals("IF", funif.toFormulaString()); assertTrue("Goto ptg exists", goto1.isGoto()); } /** diff --git a/src/testcases/org/apache/poi/hssf/record/TestSharedFormulaRecord.java b/src/testcases/org/apache/poi/hssf/record/TestSharedFormulaRecord.java index 3742342360..7a13cfe5fd 100644 --- a/src/testcases/org/apache/poi/hssf/record/TestSharedFormulaRecord.java +++ b/src/testcases/org/apache/poi/hssf/record/TestSharedFormulaRecord.java @@ -66,7 +66,7 @@ public final class TestSharedFormulaRecord extends TestCase { Ptg[] convertedFormula = SharedFormulaRecord.convertSharedFormulas(sharedFormula, 100, 200); RefPtg refPtg = (RefPtg) convertedFormula[1]; - assertEquals("$C101", refPtg.toFormulaString(null)); + assertEquals("$C101", refPtg.toFormulaString()); if (refPtg.getPtgClass() == Ptg.CLASS_REF) { throw new AssertionFailedError("Identified bug 45123"); } diff --git a/src/testcases/org/apache/poi/hssf/record/formula/TestArea3DPtg.java b/src/testcases/org/apache/poi/hssf/record/formula/TestArea3DPtg.java index e83a59b42d..b4aa683833 100644 --- a/src/testcases/org/apache/poi/hssf/record/formula/TestArea3DPtg.java +++ b/src/testcases/org/apache/poi/hssf/record/formula/TestArea3DPtg.java @@ -14,10 +14,10 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - package org.apache.poi.hssf.record.formula; +import org.apache.poi.hssf.usermodel.HSSFEvaluationWorkbook; import org.apache.poi.hssf.usermodel.HSSFWorkbook; /** @@ -27,21 +27,22 @@ import org.apache.poi.hssf.usermodel.HSSFWorkbook; */ public final class TestArea3DPtg extends AbstractPtgTestCase { - /** - * confirms that sheet names get properly escaped - */ + /** + * confirms that sheet names get properly escaped + */ public void testToFormulaString() { - + Area3DPtg target = new Area3DPtg("A1:B1", (short)0); - + String sheetName = "my sheet"; - HSSFWorkbook book = createWorkbookWithSheet(sheetName); + HSSFWorkbook wb = createWorkbookWithSheet(sheetName); + HSSFEvaluationWorkbook book = HSSFEvaluationWorkbook.create(wb); assertEquals("'my sheet'!A1:B1", target.toFormulaString(book)); - - book.setSheetName(0, "Sheet1"); - assertEquals("Sheet1!A1:B1", target.toFormulaString(book)); - - book.setSheetName(0, "C64"); - assertEquals("'C64'!A1:B1", target.toFormulaString(book)); + + wb.setSheetName(0, "Sheet1"); + assertEquals("Sheet1!A1:B1", target.toFormulaString(book)); + + wb.setSheetName(0, "C64"); + assertEquals("'C64'!A1:B1", target.toFormulaString(book)); } } 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 3a7f2f29a4..f5b80f6dac 100644 --- a/src/testcases/org/apache/poi/hssf/record/formula/TestAreaPtg.java +++ b/src/testcases/org/apache/poi/hssf/record/formula/TestAreaPtg.java @@ -21,6 +21,7 @@ package org.apache.poi.hssf.record.formula; import junit.framework.TestCase; import org.apache.poi.hssf.model.FormulaParser; +import org.apache.poi.hssf.usermodel.HSSFWorkbook; /** * Tests for {@link AreaPtg}. @@ -83,14 +84,10 @@ public final class TestAreaPtg extends TestCase { assertEquals("Relative references changed", expectedFormula2, newFormula2); } - private String shiftAllColumnsBy1(String formula) - { + private static String shiftAllColumnsBy1(String formula) { int letUsShiftColumn1By1Column=1; - - FormulaParser parser = new FormulaParser(formula,null); - parser.parse(); - - final Ptg[] ptgs = parser.getRPNPtg(); + HSSFWorkbook wb = null; + Ptg[] ptgs = FormulaParser.parse(formula, wb); for(int i=0; i<ptgs.length; i++) { Ptg ptg = ptgs[i]; @@ -101,10 +98,7 @@ public final class TestAreaPtg extends TestCase { aptg.setLastColumn((short)(aptg.getLastColumn()+letUsShiftColumn1By1Column)); } } - String newFormula = parser.toFormulaString(ptgs); + String newFormula = FormulaParser.toFormulaString(wb, ptgs); return newFormula; } - - - } diff --git a/src/testcases/org/apache/poi/hssf/record/formula/TestArrayPtg.java b/src/testcases/org/apache/poi/hssf/record/formula/TestArrayPtg.java index 2455c87ab9..df2c1f77bd 100644 --- a/src/testcases/org/apache/poi/hssf/record/formula/TestArrayPtg.java +++ b/src/testcases/org/apache/poi/hssf/record/formula/TestArrayPtg.java @@ -119,7 +119,7 @@ public final class TestArrayPtg extends TestCase { String actualFormula; try { - actualFormula = ptg.toFormulaString(null); + actualFormula = ptg.toFormulaString(); } catch (IllegalArgumentException e) { if (e.getMessage().equals("Unexpected constant class (java.lang.Boolean)")) { throw new AssertionFailedError("Identified bug 45380"); diff --git a/src/testcases/org/apache/poi/hssf/record/formula/TestRef3DPtg.java b/src/testcases/org/apache/poi/hssf/record/formula/TestRef3DPtg.java index 4de0c7bdb2..9ccb7c8945 100644 --- a/src/testcases/org/apache/poi/hssf/record/formula/TestRef3DPtg.java +++ b/src/testcases/org/apache/poi/hssf/record/formula/TestRef3DPtg.java @@ -14,10 +14,10 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - package org.apache.poi.hssf.record.formula; +import org.apache.poi.hssf.usermodel.HSSFEvaluationWorkbook; import org.apache.poi.hssf.usermodel.HSSFWorkbook; /** @@ -28,17 +28,17 @@ import org.apache.poi.hssf.usermodel.HSSFWorkbook; public final class TestRef3DPtg extends AbstractPtgTestCase { public void testToFormulaString() { - + Ref3DPtg target = new Ref3DPtg("A1", (short)0); - - HSSFWorkbook book = createWorkbookWithSheet("my sheet"); - + + HSSFWorkbook wb = createWorkbookWithSheet("my sheet"); + HSSFEvaluationWorkbook book = HSSFEvaluationWorkbook.create(wb); assertEquals("'my sheet'!A1", target.toFormulaString(book)); - book.setSheetName(0, "ProfitAndLoss"); - assertEquals("ProfitAndLoss!A1", target.toFormulaString(book)); - - book.setSheetName(0, "profit+loss"); - assertEquals("'profit+loss'!A1", target.toFormulaString(book)); + wb.setSheetName(0, "ProfitAndLoss"); + assertEquals("ProfitAndLoss!A1", target.toFormulaString(book)); + + wb.setSheetName(0, "profit+loss"); + assertEquals("'profit+loss'!A1", target.toFormulaString(book)); } } diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestFormulaEvaluatorBugs.java b/src/testcases/org/apache/poi/hssf/usermodel/TestFormulaEvaluatorBugs.java index dc4454d515..c2f11cfcc9 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestFormulaEvaluatorBugs.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestFormulaEvaluatorBugs.java @@ -202,7 +202,7 @@ public final class TestFormulaEvaluatorBugs extends TestCase { assertEquals(2, ptg.getLastColumn()); assertEquals(0, ptg.getFirstRow()); assertEquals(65535, ptg.getLastRow()); - assertEquals("C:C", ptg.toFormulaString(wb)); + assertEquals("C:C", ptg.toFormulaString()); // Will show as C:C, but won't know how many // rows it covers as we don't have the sheet @@ -316,6 +316,7 @@ public final class TestFormulaEvaluatorBugs extends TestCase { evaluator.evaluate(cell); int evalCount = evaluator.getEvaluationCount(); // With caching, the evaluationCount is 8 which is a big improvement + assertTrue(evalCount > 0); // make sure the counter is actually working if (evalCount > 10) { // Without caching, evaluating cell 'A9' takes 21845 evaluations which consumes // much time (~3 sec on Core 2 Duo 2.2GHz) diff --git a/src/testcases/org/apache/poi/hssf/util/TestAreaReference.java b/src/testcases/org/apache/poi/hssf/util/TestAreaReference.java index c9356b8527..f19aa0ca4d 100644 --- a/src/testcases/org/apache/poi/hssf/util/TestAreaReference.java +++ b/src/testcases/org/apache/poi/hssf/util/TestAreaReference.java @@ -30,6 +30,7 @@ import org.apache.poi.hssf.record.formula.MemFuncPtg; import org.apache.poi.hssf.record.formula.Ptg; import org.apache.poi.hssf.record.formula.UnionPtg; import org.apache.poi.hssf.usermodel.HSSFCell; +import org.apache.poi.hssf.usermodel.HSSFEvaluationWorkbook; import org.apache.poi.hssf.usermodel.HSSFName; import org.apache.poi.hssf.usermodel.HSSFRow; import org.apache.poi.hssf.usermodel.HSSFSheet; @@ -192,6 +193,7 @@ public final class TestAreaReference extends TestCase { InputStream is = HSSFTestDataSamples.openSampleFileStream("44167.xls"); HSSFWB wb = new HSSFWB(is); Workbook workbook = wb.getWorkbook(); + HSSFEvaluationWorkbook eb = HSSFEvaluationWorkbook.create(wb); assertEquals(1, wb.getNumberOfNames()); String sheetName = "Tabelle1"; @@ -213,10 +215,10 @@ public final class TestAreaReference extends TestCase { Area3DPtg ptgB = (Area3DPtg)def[1]; Area3DPtg ptgC = (Area3DPtg)def[2]; UnionPtg ptgD = (UnionPtg)def[3]; - assertEquals("", ptgA.toFormulaString(wb)); - assertEquals(refA, ptgB.toFormulaString(wb)); - assertEquals(refB, ptgC.toFormulaString(wb)); - assertEquals(",", ptgD.toFormulaString(wb)); + assertEquals("", ptgA.toFormulaString()); + assertEquals(refA, ptgB.toFormulaString(eb)); + assertEquals(refB, ptgC.toFormulaString(eb)); + assertEquals(",", ptgD.toFormulaString()); assertEquals(ref, nr.getAreaReference(wb)); |