aboutsummaryrefslogtreecommitdiffstats
path: root/src/testcases/org/apache
diff options
context:
space:
mode:
authorJosh Micich <josh@apache.org>2008-10-09 06:46:17 +0000
committerJosh Micich <josh@apache.org>2008-10-09 06:46:17 +0000
commiteb12a8716f8b5ec11d19ab1aea8603e8bbd316ad (patch)
treefbcf4426c5c0e4a5abf771b3ccbe5d33d8c67ac9 /src/testcases/org/apache
parentf55bd82eef46bdb16b64fb1dbeef4cd90c97727c (diff)
downloadpoi-eb12a8716f8b5ec11d19ab1aea8603e8bbd316ad.tar.gz
poi-eb12a8716f8b5ec11d19ab1aea8603e8bbd316ad.zip
Merged revisions 701756,702231 via svnmerge from
https://svn.apache.org/repos/asf/poi/trunk ........ r701756 | josh | 2008-10-05 00:22:12 -0700 (Sun, 05 Oct 2008) | 1 line Fixing comments and formatting inside Record subclasses ........ r702231 | josh | 2008-10-06 12:13:41 -0700 (Mon, 06 Oct 2008) | 1 line Fix for 43354 - made the formula evaluator capable of handling missing function arguments ........ git-svn-id: https://svn.apache.org/repos/asf/poi/branches/ooxml@703070 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/testcases/org/apache')
-rwxr-xr-xsrc/testcases/org/apache/poi/hssf/record/formula/eval/AllFormulaEvalTests.java1
-rw-r--r--src/testcases/org/apache/poi/hssf/record/formula/eval/TestMissingArgEval.java74
2 files changed, 75 insertions, 0 deletions
diff --git a/src/testcases/org/apache/poi/hssf/record/formula/eval/AllFormulaEvalTests.java b/src/testcases/org/apache/poi/hssf/record/formula/eval/AllFormulaEvalTests.java
index fe37a3c84b..a26539cdd2 100755
--- a/src/testcases/org/apache/poi/hssf/record/formula/eval/AllFormulaEvalTests.java
+++ b/src/testcases/org/apache/poi/hssf/record/formula/eval/AllFormulaEvalTests.java
@@ -36,6 +36,7 @@ public class AllFormulaEvalTests {
result.addTestSuite(TestExternalFunction.class);
result.addTestSuite(TestFormulaBugs.class);
result.addTestSuite(TestFormulasFromSpreadsheet.class);
+ result.addTestSuite(TestMissingArgEval.class);
result.addTestSuite(TestPercentEval.class);
result.addTestSuite(TestRangeEval.class);
result.addTestSuite(TestUnaryPlusEval.class);
diff --git a/src/testcases/org/apache/poi/hssf/record/formula/eval/TestMissingArgEval.java b/src/testcases/org/apache/poi/hssf/record/formula/eval/TestMissingArgEval.java
new file mode 100644
index 0000000000..2a830b080b
--- /dev/null
+++ b/src/testcases/org/apache/poi/hssf/record/formula/eval/TestMissingArgEval.java
@@ -0,0 +1,74 @@
+/* ====================================================================
+ 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.hssf.record.formula.eval;
+
+import java.util.EmptyStackException;
+
+import junit.framework.AssertionFailedError;
+import junit.framework.TestCase;
+
+import org.apache.poi.hssf.usermodel.HSSFCell;
+import org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator;
+import org.apache.poi.hssf.usermodel.HSSFSheet;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+import org.apache.poi.ss.usermodel.CellValue;
+
+/**
+ * Tests for {@link MissingArgEval}
+ *
+ * @author Josh Micich
+ */
+public final class TestMissingArgEval extends TestCase {
+
+ public void testEvaluateMissingArgs() {
+ HSSFWorkbook wb = new HSSFWorkbook();
+ HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(wb);
+ HSSFSheet sheet = wb.createSheet("Sheet1");
+ HSSFCell cell = sheet.createRow(0).createCell(0);
+
+ cell.setCellFormula("if(true,)");
+ fe.clearAllCachedResultValues();
+ CellValue cv;
+ try {
+ cv = fe.evaluate(cell);
+ } catch (EmptyStackException e) {
+ throw new AssertionFailedError("Missing args evaluation not implemented (bug 43354");
+ }
+ // MissingArg -> BlankEval -> zero (as formula result)
+ assertEquals(0.0, cv.getNumberValue(), 0.0);
+
+ // MissingArg -> BlankEval -> empty string (in concatenation)
+ cell.setCellFormula("\"abc\"&if(true,)");
+ fe.clearAllCachedResultValues();
+ assertEquals("abc", fe.evaluate(cell).getStringValue());
+ }
+
+ public void testCountFuncs() {
+ HSSFWorkbook wb = new HSSFWorkbook();
+ HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(wb);
+ HSSFSheet sheet = wb.createSheet("Sheet1");
+ HSSFCell cell = sheet.createRow(0).createCell(0);
+
+ cell.setCellFormula("COUNT(C5,,,,)"); // 4 missing args, C5 is blank
+ assertEquals(4.0, fe.evaluate(cell).getNumberValue(), 0.0);
+
+ cell.setCellFormula("COUNTA(C5,,)"); // 2 missing args, C5 is blank
+ fe.clearAllCachedResultValues();
+ assertEquals(2.0, fe.evaluate(cell).getNumberValue(), 0.0);
+ }
+}