diff options
author | Dominik Stadler <centic@apache.org> | 2015-01-04 10:23:01 +0000 |
---|---|---|
committer | Dominik Stadler <centic@apache.org> | 2015-01-04 10:23:01 +0000 |
commit | e8317cea561b8b0ba7760579980ccc42a840adae (patch) | |
tree | 0fb7fad402d12f5f7b2f0c73c0f27782a2106139 /src/excelant | |
parent | 3329608dd0911b687926674f6f519bd7fa4b9267 (diff) | |
download | poi-e8317cea561b8b0ba7760579980ccc42a840adae.tar.gz poi-e8317cea561b8b0ba7760579980ccc42a840adae.zip |
Add unit tests for XSSFTextRun and TextPainter, slightly more tests for XSSFSheet and enhance unit tests for XWPFParagraph and ExcelAntTest
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1649309 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/excelant')
3 files changed, 154 insertions, 1 deletions
diff --git a/src/excelant/testcases/org/apache/poi/ss/excelant/MockExcelAntWorkbookHandler.java b/src/excelant/testcases/org/apache/poi/ss/excelant/MockExcelAntWorkbookHandler.java new file mode 100644 index 0000000000..ffdb2f2fa7 --- /dev/null +++ b/src/excelant/testcases/org/apache/poi/ss/excelant/MockExcelAntWorkbookHandler.java @@ -0,0 +1,37 @@ +/* + * 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.excelant; + +import static org.junit.Assert.assertNotNull; + +import org.apache.poi.ss.usermodel.Workbook; + +public class MockExcelAntWorkbookHandler implements IExcelAntWorkbookHandler { + public static boolean executed = false; + public static Workbook workbook = null; + + + public void setWorkbook(Workbook workbook) { + MockExcelAntWorkbookHandler.workbook = workbook; + } + + public void execute() { + executed = true; + assertNotNull(workbook); + } +} diff --git a/src/excelant/testcases/org/apache/poi/ss/excelant/TestBuildFile.java b/src/excelant/testcases/org/apache/poi/ss/excelant/TestBuildFile.java index 732eead09d..df1993be0b 100644 --- a/src/excelant/testcases/org/apache/poi/ss/excelant/TestBuildFile.java +++ b/src/excelant/testcases/org/apache/poi/ss/excelant/TestBuildFile.java @@ -48,6 +48,12 @@ public class TestBuildFile extends BuildFileTest { assertLogContaining("Succeeded when evaluating 'MortgageCalculator'!$B$4.");
}
+ public void testEvaluateNoDetails() {
+ executeTarget("test-evaluate-nodetails");
+ assertLogContaining("Using input file: " + BuildFileTest.getDataDir() + "/spreadsheet/excelant.xls");
+ assertLogNotContaining("Succeeded when evaluating 'MortgageCalculator'!$B$4.");
+ }
+
public void testPrecision() {
executeTarget("test-precision");
@@ -61,12 +67,25 @@ public class TestBuildFile extends BuildFileTest { assertLogContaining("2/3 tests passed");
}
+ public void testPrecisionFail() {
+ expectSpecificBuildException("test-precision-fails", "precision not matched",
+ "\tFailed to evaluate cell 'MortgageCalculator'!$B$4. It evaluated to 2285.5761494145563 when the value of 2285.576149 with precision of 1.0E-10 was expected.");
+ }
+
public void testPassOnError() {
executeTarget("test-passonerror");
}
public void testFailOnError() {
expectBuildException("test-failonerror", "fail on error");
+ assertLogContaining("Using input file: " + BuildFileTest.getDataDir() + "/spreadsheet/excelant.xls");
+ assertLogNotContaining("failed because 1 of 0 evaluations failed to evaluate correctly. Failed to evaluate cell 'MortageCalculatorFunction'!$D$3");
+ }
+
+ public void testFailOnErrorNoDetails() {
+ expectBuildException("test-failonerror-nodetails", "fail on error");
+ assertLogNotContaining("Using input file: " + BuildFileTest.getDataDir() + "/spreadsheet/excelant.xls");
+ assertLogNotContaining("failed because 1 of 0 evaluations failed to evaluate correctly. Failed to evaluate cell 'MortageCalculatorFunction'!$D$3");
}
public void testUdf() {
@@ -78,4 +97,23 @@ public class TestBuildFile extends BuildFileTest { executeTarget("test-settext");
assertLogContaining("1/1 tests passed");
}
+
+ public void testAddHandler() {
+ executeTarget("test-addhandler");
+ assertLogContaining("Using input file: " + BuildFileTest.getDataDir() + "/spreadsheet/excelant.xls");
+ assertLogContaining("Succeeded when evaluating 'MortgageCalculator'!$B$4.");
+
+ assertNotNull("The workbook should have been passed to the handler", MockExcelAntWorkbookHandler.workbook);
+ assertTrue("The handler should have been executed", MockExcelAntWorkbookHandler.executed);
+ }
+
+ public void testAddHandlerWrongClass() {
+ executeTarget("test-addhandler-wrongclass");
+ assertLogContaining("Using input file: " + BuildFileTest.getDataDir() + "/spreadsheet/excelant.xls");
+ assertLogContaining("Succeeded when evaluating 'MortgageCalculator'!$B$4.");
+ }
+
+ public void testAddHandlerFails() {
+ expectSpecificBuildException("test-addhandler-fails", "NullPointException", null);
+ }
}
diff --git a/src/excelant/testcases/org/apache/poi/ss/excelant/tests.xml b/src/excelant/testcases/org/apache/poi/ss/excelant/tests.xml index 6d938897f8..d387aab365 100644 --- a/src/excelant/testcases/org/apache/poi/ss/excelant/tests.xml +++ b/src/excelant/testcases/org/apache/poi/ss/excelant/tests.xml @@ -57,6 +57,18 @@ under the License. </poi:excelant> </target> + <target name="test-evaluate-nodetails"> + <poi:excelant fileName="${data.dir.name}/spreadsheet/excelant.xls"> + <poi:test showSuccessDetails="false"> + <poi:setDouble cell="'MortgageCalculator'!$B$1" value="240000"/> + <poi:setDouble cell="'MortgageCalculator'!$B$2" value ="0.11"/> + <poi:setDouble cell="'MortgageCalculator'!$B$3" value ="30"/> + <poi:evaluate showDelta="true" cell="'MortgageCalculator'!$B$4" + expectedValue="2285.576149" precision="1.0E-4" /> + </poi:test> + </poi:excelant> + </target> + <target name="test-precision"> <poi:excelant fileName="${data.dir.name}/spreadsheet/excelant.xls"> <poi:precision value="1.0E-4"/> @@ -85,7 +97,22 @@ under the License. expectedValue="2285.576149" precision="1.0E-10"/> </poi:test> - </poi:excelant> + </poi:excelant> + </target> + + <target name="test-precision-fails"> + <poi:excelant fileName="${data.dir.name}/spreadsheet/excelant.xls"> + <poi:precision value="1.0E-4"/> + + <poi:test name="tiny-precision" showFailureDetail="true" showSuccessDetails="true"> + <poi:setDouble cell="'MortgageCalculator'!$B$1" value="240000"/> + <poi:setDouble cell="'MortgageCalculator'!$B$2" value ="0.11"/> + <poi:setDouble cell="'MortgageCalculator'!$B$3" value ="30"/> + <poi:evaluate showDelta="true" cell="'MortgageCalculator'!$B$4" + expectedValue="2285.576149" precision="1.0E-10" requiredToPass="true"/> + </poi:test> + + </poi:excelant> </target> <!-- @@ -120,6 +147,19 @@ under the License. </poi:excelant> </target> + <target name="test-failonerror-notdetails"> + <poi:excelant fileName="${data.dir.name}/spreadsheet/excelant.xls" failOnError="true"> + + <poi:test name="failonerror" showFailureDetail="false" showSuccessDetails="false"> + <poi:setDouble cell="'MortageCalculatorFunction'!$D$1" value="1"/> + <poi:setDouble cell="'MortageCalculatorFunction'!$D$2" value="2"/> + <poi:setFormula cell="'MortageCalculatorFunction'!$D$3" value ="SUM(D1:D2)"/> + <poi:evaluate showDelta="true" cell="'MortageCalculatorFunction'!$D$3" expectedValue="2"/> + </poi:test> + + </poi:excelant> + </target> + <!-- Evaluation of user-defined functions --> <target name="test-udf"> <poi:excelant fileName="${data.dir.name}/spreadsheet/excelant.xls"> @@ -145,4 +185,42 @@ under the License. </poi:excelant> </target> + <target name="test-addhandler"> + <poi:excelant fileName="${data.dir.name}/spreadsheet/excelant.xls"> + <poi:test showSuccessDetails="true"> + <poi:handler className="org.apache.poi.ss.excelant.MockExcelAntWorkbookHandler"/> + <poi:setDouble cell="'MortgageCalculator'!$B$1" value="240000"/> + <poi:setDouble cell="'MortgageCalculator'!$B$2" value ="0.11"/> + <poi:setDouble cell="'MortgageCalculator'!$B$3" value ="30"/> + <poi:evaluate showDelta="true" cell="'MortgageCalculator'!$B$4" + expectedValue="2285.576149" precision="1.0E-4" /> + </poi:test> + </poi:excelant> + </target> + + <target name="test-addhandler-wrongclass"> + <poi:excelant fileName="${data.dir.name}/spreadsheet/excelant.xls"> + <poi:test showSuccessDetails="true"> + <poi:handler className="java.lang.String"/> + <poi:setDouble cell="'MortgageCalculator'!$B$1" value="240000"/> + <poi:setDouble cell="'MortgageCalculator'!$B$2" value ="0.11"/> + <poi:setDouble cell="'MortgageCalculator'!$B$3" value ="30"/> + <poi:evaluate showDelta="true" cell="'MortgageCalculator'!$B$4" + expectedValue="2285.576149" precision="1.0E-4" /> + </poi:test> + </poi:excelant> + </target> + + <target name="test-addhandler-fails"> + <poi:excelant fileName="${data.dir.name}/spreadsheet/excelant.xls"> + <poi:test showSuccessDetails="true"> + <poi:handler/> + <poi:setDouble cell="'MortgageCalculator'!$B$1" value="240000"/> + <poi:setDouble cell="'MortgageCalculator'!$B$2" value ="0.11"/> + <poi:setDouble cell="'MortgageCalculator'!$B$3" value ="30"/> + <poi:evaluate showDelta="true" cell="'MortgageCalculator'!$B$4" + expectedValue="2285.576149" precision="1.0E-4" /> + </poi:test> + </poi:excelant> + </target> </project> |