aboutsummaryrefslogtreecommitdiffstats
path: root/src/testcases
diff options
context:
space:
mode:
authorNick Burch <nick@apache.org>2008-08-09 22:55:33 +0000
committerNick Burch <nick@apache.org>2008-08-09 22:55:33 +0000
commit77002f649179f617360d3bd93a0fad01616cc093 (patch)
tree1cd026d73201eaa166eef127d6fc73bc526bb461 /src/testcases
parent157a78a1d047fc69242ed1fce98969d5f765c963 (diff)
downloadpoi-77002f649179f617360d3bd93a0fad01616cc093.tar.gz
poi-77002f649179f617360d3bd93a0fad01616cc093.zip
Merged revisions 638786-638802,638805-638811,638813-638814,638816-639230,639233-639241,639243-639253,639255-639486,639488-639601,639603-639835,639837-639917,639919-640056,640058-640710,640712-641156,641158-641184,641186-641795,641797-641798,641800-641933,641935-641963,641965-641966,641968-641995,641997-642230,642232-642562,642564-642565,642568-642570,642572-642573,642576-642736,642739-642877,642879,642881-642890,642892-642903,642905-642945,642947-643624,643626-643653,643655-643669,643671,643673-643830,643832-643833,643835-644342,644344-644472,644474-644508,644510-645347,645349-645351,645353-645559,645561-645565,645568-645951,645953-646193,646195-646311,646313-646404,646406-646665,646667-646853,646855-646869,646871-647151,647153-647185,647187-647277,647279-647566,647568-647573,647575,647578-647711,647714-647737,647739-647823,647825-648155,648157-648202,648204-648273,648275,648277-648302,648304-648333,648335-648588,648590-648622,648625-648673,648675-649141,649144,649146-649556,649558-649795,649799,649801-649910,649912-649913,649915-650128,650131-650132,650134-650137,650140-650914,650916-651991,651993-652284,652286-652287,652289,652291,652293-652297,652299-652328,652330-652425,652427-652445,652447-652560,652562-652933,652935,652937-652993,652995-653116,653118-653124,653126-653483,653487-653519,653522-653550,653552-653607,653609-653667,653669-653674,653676-653814,653817-653830,653832-653891,653893-653944,653946-654055,654057-654355,654357-654365,654367-654648,654651-655215,655217-655277,655279-655281,655283-655911,655913-656212,656214,656216-656251,656253-656698,656700-656756,656758-656892,656894-657135,657137-657165,657168-657179,657181-657354,657356-657357,657359-657701,657703-657874,657876-658032,658034-658284,658286,658288-658301,658303-658307,658309-658321,658323-658335,658337-658348,658351,658353-658832,658834-658983,658985,658987-659066,659068-659402,659404-659428,659430-659451,659453-659454,659456-659461,659463-659477,659479-659524,659526-659571,659574,659576-660255,660257-660262,660264-660279,660281-660343,660345-660473,660475-660827,660829-660833,660835-660888,660890-663321,663323-663435,663437-663764,663766-663854,663856-664219,664221-664489,664494-664514,664516-668013,668015-668142,668144-668152,668154,668156-668256,668258,668260-669139,669141-669455,669457-669657,669659-669808,669810-670189,670191-671321,671323-672229,672231-672549,672551-672552,672554-672561,672563-672566,672568,672571-673049,673051-673852,673854-673862,673864-673986,673988-673996,673998-674347,674349-674890,674892-674910,674912-674936,674938-674952,674954-675078,675080-675085,675087-675217,675219-675660,675662-675670,675672-675716,675718-675726,675728-675733,675735-675775,675777-675782,675784,675786-675791,675794-675852,675854-676200,676202,676204,676206-676220,676222-676309,676311-676456,676458-676994,676996-677027,677030-677040,677042-677056,677058-677375,677377-677968,677970-677971,677973,677975-677994,677996-678286,678288-678538,678540-680393,680395-680469,680471-680529,680531-680852,680854-681529,681531-681571,681573-682224,682226,682228,682231-682281,682283-682335,682337-682507,682509,682512-682517,682519-682532,682534-682619,682622-682777,682779-682998,683000-683019,683021-683022,683024-683080,683082-683092,683094-683095,683097-683127,683129-683131,683133-683166,683168-683698,683700-683705,683707-683757,683759-683787,683789-683870,683872-683879,683881-683900,683902-684066,684068-684074,684076-684222,684224-684254,684257-684370 via svnmerge from
https://svn.apache.org/repos/asf/poi/trunk ........ r684282 | nick | 2008-08-09 16:58:24 +0100 (Sat, 09 Aug 2008) | 1 line Prepare to change how we do ranges, to handle different kinds of text in the cp area ........ r684287 | nick | 2008-08-09 17:24:20 +0100 (Sat, 09 Aug 2008) | 1 line Start to document the whole FIB stuff better ........ r684293 | nick | 2008-08-09 17:46:39 +0100 (Sat, 09 Aug 2008) | 1 line Add lots more getters/setters for useful things to the FIB ........ r684299 | nick | 2008-08-09 18:23:42 +0100 (Sat, 09 Aug 2008) | 1 line More tests to show that the range based stuff is working properly ........ r684302 | nick | 2008-08-09 18:33:29 +0100 (Sat, 09 Aug 2008) | 1 line More header and footer files, this time with unicode in it too ........ r684309 | nick | 2008-08-09 18:58:35 +0100 (Sat, 09 Aug 2008) | 1 line More range tests, which show that we do have a bug in the hwpf unicode support ........ r684318 | josh | 2008-08-09 20:29:23 +0100 (Sat, 09 Aug 2008) | 1 line Converted rows map within HSSFSheet to use Integer keys ........ r684319 | nick | 2008-08-09 20:34:38 +0100 (Sat, 09 Aug 2008) | 1 line Big big unicode rationalisation in text piece code ........ r684321 | josh | 2008-08-09 20:47:39 +0100 (Sat, 09 Aug 2008) | 1 line added getRowIndex() to HSSFCell, deprecated HSSFFormulaEvaluator.setCurrentRow() ........ r684322 | nick | 2008-08-09 20:56:37 +0100 (Sat, 09 Aug 2008) | 1 line Get most of the hwpf tests passing again ........ r684336 | nick | 2008-08-09 21:31:48 +0100 (Sat, 09 Aug 2008) | 1 line Improve FIB updating on range changes, and add passing tests for non unicode paragraph properties ........ r684349 | nick | 2008-08-09 22:31:28 +0100 (Sat, 09 Aug 2008) | 1 line Start on headers/footers support ........ r684355 | nick | 2008-08-09 22:46:14 +0100 (Sat, 09 Aug 2008) | 1 line Tests to show that header stuff all works right ........ r684362 | nick | 2008-08-09 23:08:34 +0100 (Sat, 09 Aug 2008) | 1 line Add header/footer support to HWPF WordExtractor ........ r684370 | nick | 2008-08-09 23:24:47 +0100 (Sat, 09 Aug 2008) | 1 line Disable a few HWPF tests that aren't working while the unicode/paragraph bug is outstanding ........ git-svn-id: https://svn.apache.org/repos/asf/poi/branches/ooxml@684374 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/testcases')
-rw-r--r--src/testcases/org/apache/poi/hssf/model/TestFormulaParserEval.java29
-rwxr-xr-xsrc/testcases/org/apache/poi/hssf/record/formula/eval/TestCircularReferences.java25
-rwxr-xr-xsrc/testcases/org/apache/poi/hssf/record/formula/eval/TestExternalFunction.java3
-rwxr-xr-xsrc/testcases/org/apache/poi/hssf/record/formula/eval/TestFormulaBugs.java21
-rw-r--r--src/testcases/org/apache/poi/hssf/record/formula/eval/TestFormulasFromSpreadsheet.java40
-rwxr-xr-xsrc/testcases/org/apache/poi/hssf/record/formula/eval/TestPercentEval.java5
-rwxr-xr-xsrc/testcases/org/apache/poi/hssf/record/formula/functions/TestCountFuncs.java1
-rw-r--r--src/testcases/org/apache/poi/hssf/record/formula/functions/TestDate.java123
-rwxr-xr-xsrc/testcases/org/apache/poi/hssf/record/formula/functions/TestIsBlank.java6
-rw-r--r--src/testcases/org/apache/poi/hssf/record/formula/functions/TestLookupFunctionsFromSpreadsheet.java47
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestBug42464.java1
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestBug43093.java42
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java152
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestFormulaEvaluatorBugs.java61
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestFormulaEvaluatorDocs.java70
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestHSSFCell.java197
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestHSSFDataFormatter.java20
17 files changed, 373 insertions, 470 deletions
diff --git a/src/testcases/org/apache/poi/hssf/model/TestFormulaParserEval.java b/src/testcases/org/apache/poi/hssf/model/TestFormulaParserEval.java
index b200515ff9..d89ffee3eb 100644
--- a/src/testcases/org/apache/poi/hssf/model/TestFormulaParserEval.java
+++ b/src/testcases/org/apache/poi/hssf/model/TestFormulaParserEval.java
@@ -38,42 +38,34 @@ import org.apache.poi.ss.usermodel.FormulaEvaluator.CellValue;
*/
public final class TestFormulaParserEval extends TestCase {
- public void testWithNamedRange() throws Exception {
+ public void testWithNamedRange() {
HSSFWorkbook workbook = new HSSFWorkbook();
- FormulaParser fp;
Ptg[] ptgs;
HSSFSheet s = workbook.createSheet("Foo");
- s.createRow(0).createCell((short)0).setCellValue(1.1);
- s.createRow(1).createCell((short)0).setCellValue(2.3);
- s.createRow(2).createCell((short)2).setCellValue(3.1);
+ s.createRow(0).createCell(0).setCellValue(1.1);
+ s.createRow(1).createCell(0).setCellValue(2.3);
+ s.createRow(2).createCell(2).setCellValue(3.1);
HSSFName name = workbook.createName();
name.setNameName("testName");
name.setReference("A1:A2");
- fp = HSSFFormulaEvaluator.getUnderlyingParser(workbook, "SUM(testName)");
- fp.parse();
- ptgs = fp.getRPNPtg();
+ ptgs = FormulaParser.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");
-
- fp = HSSFFormulaEvaluator.getUnderlyingParser(workbook, "SUM(testName)");
- fp.parse();
- ptgs = fp.getRPNPtg();
+ ptgs = FormulaParser.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");
- fp = HSSFFormulaEvaluator.getUnderlyingParser(workbook, "SUM(testName)");
- fp.parse();
- ptgs = fp.getRPNPtg();
+ ptgs = FormulaParser.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());
@@ -86,15 +78,14 @@ public final class TestFormulaParserEval extends TestCase {
wb.setSheetName(0, "Sheet1");
HSSFRow row = sheet.createRow(0);
- HSSFCell cell = row.createCell((short)0);
+ HSSFCell cell = row.createCell(0);
cell.setCellFormula("SUM(A32769:A32770)");
// put some values in the cells to make the evaluation more interesting
- sheet.createRow(32768).createCell((short)0).setCellValue(31);
- sheet.createRow(32769).createCell((short)0).setCellValue(11);
+ sheet.createRow(32768).createCell(0).setCellValue(31);
+ sheet.createRow(32769).createCell(0).setCellValue(11);
HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(sheet, wb);
- fe.setCurrentRow(row);
CellValue result;
try {
result = fe.evaluate(cell);
diff --git a/src/testcases/org/apache/poi/hssf/record/formula/eval/TestCircularReferences.java b/src/testcases/org/apache/poi/hssf/record/formula/eval/TestCircularReferences.java
index 97ddfdf220..ee20479872 100755
--- a/src/testcases/org/apache/poi/hssf/record/formula/eval/TestCircularReferences.java
+++ b/src/testcases/org/apache/poi/hssf/record/formula/eval/TestCircularReferences.java
@@ -35,10 +35,9 @@ public final class TestCircularReferences extends TestCase {
/**
* Translates StackOverflowError into AssertionFailedError
*/
- private static CellValue evaluateWithCycles(HSSFWorkbook wb, HSSFSheet sheet, HSSFRow row, HSSFCell testCell)
+ private static CellValue evaluateWithCycles(HSSFWorkbook wb, HSSFSheet sheet, HSSFCell testCell)
throws AssertionFailedError {
HSSFFormulaEvaluator evaluator = new HSSFFormulaEvaluator(sheet, wb);
- evaluator.setCurrentRow(row);
try {
return evaluator.evaluate(testCell);
} catch (StackOverflowError e) {
@@ -63,12 +62,12 @@ public final class TestCircularReferences extends TestCase {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("Sheet1");
- short colB = 1;
+ int colB = 1;
sheet.createRow(0).createCell(colB).setCellValue(1);
sheet.createRow(1).createCell(colB).setCellValue(2);
sheet.createRow(2).createCell(colB).setCellValue(3);
HSSFRow row4 = sheet.createRow(3);
- HSSFCell testCell = row4.createCell((short)0);
+ HSSFCell testCell = row4.createCell(0);
// This formula should evaluate to the contents of B2,
testCell.setCellFormula("INDEX(A1:B4,2,2)");
// However the range A1:B4 also includes the current cell A4. If the other parameters
@@ -76,7 +75,7 @@ public final class TestCircularReferences extends TestCase {
// arguments before invoking operators, POI must handle such potential cycles gracefully.
- CellValue cellValue = evaluateWithCycles(wb, sheet, row4, testCell);
+ CellValue cellValue = evaluateWithCycles(wb, sheet, testCell);
assertTrue(cellValue.getCellType() == HSSFCell.CELL_TYPE_NUMERIC);
assertEquals(2, cellValue.getNumberValue(), 0);
@@ -91,12 +90,11 @@ public final class TestCircularReferences extends TestCase {
HSSFSheet sheet = wb.createSheet("Sheet1");
HSSFRow row = sheet.createRow(0);
- HSSFCell testCell = row.createCell((short)0);
+ HSSFCell testCell = row.createCell(0);
testCell.setCellFormula("A1");
HSSFFormulaEvaluator evaluator = new HSSFFormulaEvaluator(sheet, wb);
- evaluator.setCurrentRow(row);
- CellValue cellValue = evaluateWithCycles(wb, sheet, row, testCell);
+ CellValue cellValue = evaluateWithCycles(wb, sheet, testCell);
confirmCycleErrorCode(cellValue);
}
@@ -110,15 +108,14 @@ public final class TestCircularReferences extends TestCase {
HSSFSheet sheet = wb.createSheet("Sheet1");
HSSFRow row = sheet.createRow(0);
- row.createCell((short)0).setCellFormula("B1");
- row.createCell((short)1).setCellFormula("C1");
- row.createCell((short)2).setCellFormula("D1");
- HSSFCell testCell = row.createCell((short)3);
+ row.createCell(0).setCellFormula("B1");
+ row.createCell(1).setCellFormula("C1");
+ row.createCell(2).setCellFormula("D1");
+ HSSFCell testCell = row.createCell(3);
testCell.setCellFormula("A1");
HSSFFormulaEvaluator evaluator = new HSSFFormulaEvaluator(sheet, wb);
- evaluator.setCurrentRow(row);
- CellValue cellValue = evaluateWithCycles(wb, sheet, row, testCell);
+ CellValue cellValue = evaluateWithCycles(wb, sheet, testCell);
confirmCycleErrorCode(cellValue);
}
diff --git a/src/testcases/org/apache/poi/hssf/record/formula/eval/TestExternalFunction.java b/src/testcases/org/apache/poi/hssf/record/formula/eval/TestExternalFunction.java
index 647b6330f2..9e6c7bce6a 100755
--- a/src/testcases/org/apache/poi/hssf/record/formula/eval/TestExternalFunction.java
+++ b/src/testcases/org/apache/poi/hssf/record/formula/eval/TestExternalFunction.java
@@ -40,7 +40,7 @@ public final class TestExternalFunction extends TestCase {
HSSFSheet sheet = wb.createSheet();
wb.setSheetName(0, "Sheet1");
HSSFRow row = sheet.createRow(0);
- HSSFCell cell = row.createCell((short)0);
+ HSSFCell cell = row.createCell(0);
HSSFName hssfName = wb.createName();
hssfName.setNameName("myFunc");
@@ -50,7 +50,6 @@ public final class TestExternalFunction extends TestCase {
assertEquals("myFunc()", actualFormula);
HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(sheet, wb);
- fe.setCurrentRow(row);
CellValue evalResult = fe.evaluate(cell);
// Check the return value from ExternalFunction.evaluate()
diff --git a/src/testcases/org/apache/poi/hssf/record/formula/eval/TestFormulaBugs.java b/src/testcases/org/apache/poi/hssf/record/formula/eval/TestFormulaBugs.java
index a614d6f193..da110a020c 100755
--- a/src/testcases/org/apache/poi/hssf/record/formula/eval/TestFormulaBugs.java
+++ b/src/testcases/org/apache/poi/hssf/record/formula/eval/TestFormulaBugs.java
@@ -67,7 +67,6 @@ public final class TestFormulaBugs extends TestCase {
// We might as well evaluate the formula
HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(sheet, wb);
- fe.setCurrentRow(row);
CellValue cv = fe.evaluate(cell);
assertEquals(HSSFCell.CELL_TYPE_NUMERIC, cv.getCellType());
@@ -84,20 +83,20 @@ public final class TestFormulaBugs extends TestCase {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("input");
// input row 0
- HSSFRow row = sheet.createRow((short) 0);
- HSSFCell cell = row.createCell((short) 0);
- cell = row.createCell((short) 1);
+ HSSFRow row = sheet.createRow(0);
+ HSSFCell cell = row.createCell(0);
+ cell = row.createCell(1);
cell.setCellValue(1); // B1
// input row 1
- row = sheet.createRow((short) 1);
- cell = row.createCell((short) 1);
+ row = sheet.createRow(1);
+ cell = row.createCell(1);
cell.setCellValue(999); // B2
int rno = 4;
row = sheet.createRow(rno);
- cell = row.createCell((short) 1); // B5
+ cell = row.createCell(1); // B5
cell.setCellFormula("isnumber(b1)");
- cell = row.createCell((short) 3); // D5
+ cell = row.createCell(3); // D5
cell.setCellFormula("IF(ISNUMBER(b1),b1,b2)");
if (false) { // set true to check excel file manually
@@ -113,7 +112,6 @@ public final class TestFormulaBugs extends TestCase {
// use POI's evaluator as an extra sanity check
HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(sheet, wb);
- fe.setCurrentRow(row);
CellValue cv;
cv = fe.evaluate(cell);
assertEquals(HSSFCell.CELL_TYPE_NUMERIC, cv.getCellType());
@@ -132,7 +130,7 @@ public final class TestFormulaBugs extends TestCase {
HSSFSheet sheet1 = wb.createSheet("Sheet1");
HSSFRow row = sheet1.createRow(0);
- HSSFCell cell = row.createCell((short) 0);
+ HSSFCell cell = row.createCell(0);
// it's important to create the referenced sheet first
HSSFSheet sheet2 = wb.createSheet("A"); // note name 'A'
@@ -165,7 +163,6 @@ public final class TestFormulaBugs extends TestCase {
double expectedResult = (4.0 * 8.0 + 5.0 * 9.0) / 10.0;
HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(sheet1, wb);
- fe.setCurrentRow(row);
CellValue cv = fe.evaluate(cell);
assertEquals(HSSFCell.CELL_TYPE_NUMERIC, cv.getCellType());
@@ -174,6 +171,6 @@ public final class TestFormulaBugs extends TestCase {
private static void addCell(HSSFSheet sheet, int rowIx, int colIx,
double value) {
- sheet.createRow(rowIx).createCell((short) colIx).setCellValue(value);
+ sheet.createRow(rowIx).createCell(colIx).setCellValue(value);
}
}
diff --git a/src/testcases/org/apache/poi/hssf/record/formula/eval/TestFormulasFromSpreadsheet.java b/src/testcases/org/apache/poi/hssf/record/formula/eval/TestFormulasFromSpreadsheet.java
index 546d16d057..ffe4bffc0a 100644
--- a/src/testcases/org/apache/poi/hssf/record/formula/eval/TestFormulasFromSpreadsheet.java
+++ b/src/testcases/org/apache/poi/hssf/record/formula/eval/TestFormulasFromSpreadsheet.java
@@ -1,19 +1,19 @@
-/*
-* 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.
-*/
+/* ====================================================================
+ 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;
@@ -70,7 +70,7 @@ public final class TestFormulasFromSpreadsheet extends TestCase {
/**
* Index of the column that contains the function names
*/
- public static final short COLUMN_INDEX_FUNCTION_NAME = 1; // Column 'B'
+ public static final int COLUMN_INDEX_FUNCTION_NAME = 1; // Column 'B'
/**
* Used to indicate when there are no more functions left
@@ -97,7 +97,7 @@ public final class TestFormulasFromSpreadsheet extends TestCase {
private int _evaluationFailureCount;
private int _evaluationSuccessCount;
- private static final Cell getExpectedValueCell(Row row, short columnIndex) {
+ private static final Cell getExpectedValueCell(Row row, int columnIndex) {
if (row == null) {
return null;
}
@@ -239,10 +239,9 @@ public final class TestFormulasFromSpreadsheet extends TestCase {
int result = Result.NO_EVALUATIONS_FOUND; // so far
short endcolnum = formulasRow.getLastCellNum();
- evaluator.setCurrentRow(formulasRow);
// iterate across the row for all the evaluation cases
- for (short colnum=SS.COLUMN_INDEX_FIRST_TEST_VALUE; colnum < endcolnum; colnum++) {
+ for (int colnum=SS.COLUMN_INDEX_FIRST_TEST_VALUE; colnum < endcolnum; colnum++) {
Cell c = formulasRow.getCell(colnum);
if (c == null || c.getCellType() != Cell.CELL_TYPE_FORMULA) {
continue;
@@ -298,7 +297,6 @@ public final class TestFormulasFromSpreadsheet extends TestCase {
for(int i=startIx; i<endIx; i++) {
ps.println("\tat " + stes[i].toString());
}
-
}
/**
diff --git a/src/testcases/org/apache/poi/hssf/record/formula/eval/TestPercentEval.java b/src/testcases/org/apache/poi/hssf/record/formula/eval/TestPercentEval.java
index 699e27fc9a..e027605dfa 100755
--- a/src/testcases/org/apache/poi/hssf/record/formula/eval/TestPercentEval.java
+++ b/src/testcases/org/apache/poi/hssf/record/formula/eval/TestPercentEval.java
@@ -59,12 +59,11 @@ public final class TestPercentEval extends TestCase {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("Sheet1");
HSSFRow row = sheet.createRow(0);
- HSSFCell cell = row.createCell((short)0);
+ HSSFCell cell = row.createCell(0);
cell.setCellFormula("B1%");
- row.createCell((short)1).setCellValue(50.0);
+ row.createCell(1).setCellValue(50.0);
HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(sheet, wb);
- fe.setCurrentRow(row);
CellValue cv;
try {
cv = fe.evaluate(cell);
diff --git a/src/testcases/org/apache/poi/hssf/record/formula/functions/TestCountFuncs.java b/src/testcases/org/apache/poi/hssf/record/formula/functions/TestCountFuncs.java
index 763eb9820c..de1714ce21 100755
--- a/src/testcases/org/apache/poi/hssf/record/formula/functions/TestCountFuncs.java
+++ b/src/testcases/org/apache/poi/hssf/record/formula/functions/TestCountFuncs.java
@@ -290,7 +290,6 @@ public final class TestCountFuncs extends TestCase {
continue;
}
HSSFCell cell = row.getCell(COL_IX_ACTUAL);
- fe.setCurrentRow(row);
CellValue cv = fe.evaluate(cell);
double actualValue = cv.getNumberValue();
double expectedValue = row.getCell(COL_IX_EXPECTED).getNumericCellValue();
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 2c5e152ab8..83c9fcd34c 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
@@ -1,100 +1,83 @@
-/*
- * Created on Sep 11, 2007
- *
- * The Copyright statements and Licenses for the commons application may be
- * found in the file LICENSE.txt
- */
+/* ====================================================================
+ 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.functions;
import junit.framework.TestCase;
-import org.apache.poi.hssf.usermodel.HSSFRow;
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.hssf.usermodel.HSSFFormulaEvaluator;
/**
* @author Pavel Krupets (pkrupets at palmtreebusiness dot com)
*/
-public class TestDate extends TestCase {
+public final class TestDate extends TestCase {
+
+ private HSSFCell cell11;
+ private HSSFFormulaEvaluator evaluator;
+
public void setUp() {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("new sheet");
- HSSFRow row1 = sheet.createRow((short) 0);
-
- this.cell11 = row1.createCell((short) 0);
-
- this.evaluator = new HSSFFormulaEvaluator(sheet, wb);
- this.evaluator.setCurrentRow(row1);
+ cell11 = sheet.createRow(0).createCell(0);
+ cell11.setCellType(HSSFCell.CELL_TYPE_FORMULA);
+ evaluator = new HSSFFormulaEvaluator(sheet, wb);
}
/**
- * Test disabled pending a fix in the formula parser
+ * Test disabled pending a fix in the formula evaluator
+ * TODO - create MissingArgEval and modify the formula evaluator to handle this
*/
- public void DISABLEDtestSomeArgumentsMissing() throws Exception {
- this.cell11.setCellFormula("DATE(, 1, 0)");
- assertEquals(0.0, this.evaluator.evaluate(this.cell11).getNumberValue(), 0);
-
- this.cell11.setCellFormula("DATE(, 1, 1)");
- assertEquals(1.0, this.evaluator.evaluate(this.cell11).getNumberValue(), 0);
+ public void DISABLEDtestSomeArgumentsMissing() {
+ confirm("DATE(, 1, 0)", 0.0);
+ confirm("DATE(, 1, 1)", 1.0);
}
- public void testValid() throws Exception {
- this.cell11.setCellType(HSSFCell.CELL_TYPE_FORMULA);
-
- this.cell11.setCellFormula("DATE(1900, 1, 1)");
- assertEquals(1, this.evaluator.evaluate(this.cell11).getNumberValue(), 0);
-
- this.cell11.setCellFormula("DATE(1900, 1, 32)");
- assertEquals(32, this.evaluator.evaluate(this.cell11).getNumberValue(), 0);
-
- this.cell11.setCellFormula("DATE(1900, 222, 1)");
- assertEquals(6727, this.evaluator.evaluate(this.cell11).getNumberValue(), 0);
-
- this.cell11.setCellFormula("DATE(1900, 2, 0)");
- assertEquals(31, this.evaluator.evaluate(this.cell11).getNumberValue(), 0);
-
- this.cell11.setCellFormula("DATE(2000, 1, 222)");
- assertEquals(36747.00, this.evaluator.evaluate(this.cell11).getNumberValue(), 0);
-
- this.cell11.setCellFormula("DATE(2007, 1, 1)");
- assertEquals(39083, this.evaluator.evaluate(this.cell11).getNumberValue(), 0);
+ public void testValid() {
+
+ confirm("DATE(1900, 1, 1)", 1);
+ confirm("DATE(1900, 1, 32)", 32);
+ confirm("DATE(1900, 222, 1)", 6727);
+ confirm("DATE(1900, 2, 0)", 31);
+ confirm("DATE(2000, 1, 222)", 36747.00);
+ confirm("DATE(2007, 1, 1)", 39083);
}
public void testBugDate() {
- this.cell11.setCellFormula("DATE(1900, 2, 29)");
- assertEquals(60, this.evaluator.evaluate(this.cell11).getNumberValue(), 0);
-
- this.cell11.setCellFormula("DATE(1900, 2, 30)");
- assertEquals(61, this.evaluator.evaluate(this.cell11).getNumberValue(), 0);
-
- this.cell11.setCellFormula("DATE(1900, 1, 222)");
- assertEquals(222, this.evaluator.evaluate(this.cell11).getNumberValue(), 0);
-
- this.cell11.setCellFormula("DATE(1900, 1, 2222)");
- assertEquals(2222, this.evaluator.evaluate(this.cell11).getNumberValue(), 0);
-
- this.cell11.setCellFormula("DATE(1900, 1, 22222)");
- assertEquals(22222, this.evaluator.evaluate(this.cell11).getNumberValue(), 0);
+ confirm("DATE(1900, 2, 29)", 60);
+ confirm("DATE(1900, 2, 30)", 61);
+ confirm("DATE(1900, 1, 222)", 222);
+ confirm("DATE(1900, 1, 2222)", 2222);
+ confirm("DATE(1900, 1, 22222)", 22222);
}
public void testPartYears() {
- this.cell11.setCellFormula("DATE(4, 1, 1)");
- assertEquals(1462.00, this.evaluator.evaluate(this.cell11).getNumberValue(), 0);
-
- this.cell11.setCellFormula("DATE(14, 1, 1)");
- assertEquals(5115.00, this.evaluator.evaluate(this.cell11).getNumberValue(), 0);
-
- this.cell11.setCellFormula("DATE(104, 1, 1)");
- assertEquals(37987.00, this.evaluator.evaluate(this.cell11).getNumberValue(), 0);
-
- this.cell11.setCellFormula("DATE(1004, 1, 1)");
- assertEquals(366705.00, this.evaluator.evaluate(this.cell11).getNumberValue(), 0);
+ confirm("DATE(4, 1, 1)", 1462.00);
+ confirm("DATE(14, 1, 1)", 5115.00);
+ confirm("DATE(104, 1, 1)", 37987.00);
+ confirm("DATE(1004, 1, 1)", 366705.00);
}
-
- private HSSFCell cell11;
- private HSSFFormulaEvaluator evaluator;
+
+ private void confirm(String formulaText, double expectedResult) {
+ cell11.setCellFormula(formulaText);
+ double actualValue = evaluator.evaluate(cell11).getNumberValue();
+ assertEquals(expectedResult, actualValue, 0);
+ }
}
diff --git a/src/testcases/org/apache/poi/hssf/record/formula/functions/TestIsBlank.java b/src/testcases/org/apache/poi/hssf/record/formula/functions/TestIsBlank.java
index 90389eeaa8..62cc32e957 100755
--- a/src/testcases/org/apache/poi/hssf/record/formula/functions/TestIsBlank.java
+++ b/src/testcases/org/apache/poi/hssf/record/formula/functions/TestIsBlank.java
@@ -32,8 +32,6 @@ import org.apache.poi.ss.usermodel.FormulaEvaluator.CellValue;
*/
public final class TestIsBlank extends TestCase {
-
-
public void test3DArea() {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet1 = wb.createSheet();
@@ -41,13 +39,12 @@ public final class TestIsBlank extends TestCase {
wb.createSheet();
wb.setSheetName(1, "Sheet2");
HSSFRow row = sheet1.createRow(0);
- HSSFCell cell = row.createCell((short)0);
+ HSSFCell cell = row.createCell(0);
cell.setCellFormula("isblank(Sheet2!A1:A1)");
HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(sheet1, wb);
- fe.setCurrentRow(row);
CellValue result = fe.evaluate(cell);
assertEquals(HSSFCell.CELL_TYPE_BOOLEAN, result.getCellType());
assertEquals(true, result.getBooleanValue());
@@ -57,6 +54,5 @@ public final class TestIsBlank extends TestCase {
result = fe.evaluate(cell);
assertEquals(HSSFCell.CELL_TYPE_BOOLEAN, result.getCellType());
assertEquals(true, result.getBooleanValue());
-
}
}
diff --git a/src/testcases/org/apache/poi/hssf/record/formula/functions/TestLookupFunctionsFromSpreadsheet.java b/src/testcases/org/apache/poi/hssf/record/formula/functions/TestLookupFunctionsFromSpreadsheet.java
index 1ff0ff6629..fe0bab0a0d 100644
--- a/src/testcases/org/apache/poi/hssf/record/formula/functions/TestLookupFunctionsFromSpreadsheet.java
+++ b/src/testcases/org/apache/poi/hssf/record/formula/functions/TestLookupFunctionsFromSpreadsheet.java
@@ -1,25 +1,22 @@
-/*
-* 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.
-*/
+/* ====================================================================
+ 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.functions;
-import java.io.FileInputStream;
-import java.io.IOException;
import java.io.PrintStream;
import junit.framework.Assert;
@@ -70,10 +67,10 @@ public final class TestLookupFunctionsFromSpreadsheet extends TestCase {
/** Row (zero-based) in each sheet where the evaluation cases start. */
public static final int START_TEST_CASES_ROW_INDEX = 4; // Row '5'
/** Index of the column that contains the function names */
- public static final short COLUMN_INDEX_MARKER = 0; // Column 'A'
- public static final short COLUMN_INDEX_EVALUATION = 1; // Column 'B'
- public static final short COLUMN_INDEX_EXPECTED_RESULT = 2; // Column 'C'
- public static final short COLUMN_ROW_COMMENT = 3; // Column 'D'
+ public static final int COLUMN_INDEX_MARKER = 0; // Column 'A'
+ public static final int COLUMN_INDEX_EVALUATION = 1; // Column 'B'
+ public static final int COLUMN_INDEX_EXPECTED_RESULT = 2; // Column 'C'
+ public static final int COLUMN_ROW_COMMENT = 3; // Column 'D'
/** Used to indicate when there are no more test cases on the current sheet */
public static final String TEST_CASES_END_MARKER = "<end>";
@@ -240,7 +237,6 @@ public final class TestLookupFunctionsFromSpreadsheet extends TestCase {
if (c == null || c.getCellType() != HSSFCell.CELL_TYPE_FORMULA) {
continue;
}
- evaluator.setCurrentRow(r);
CellValue actualValue = evaluator.evaluate(c);
HSSFCell expectedValueCell = r.getCell(SS.COLUMN_INDEX_EXPECTED_RESULT);
String rowComment = getRowCommentColumnValue(r);
@@ -307,9 +303,8 @@ public final class TestLookupFunctionsFromSpreadsheet extends TestCase {
throw new RuntimeException("First sheet's name was '" + firstSheetName + "' but expected '" + SS.README_SHEET_NAME + "'");
}
HSSFSheet sheet = workbook.getSheetAt(0);
- String specifiedClassName = sheet.getRow(2).getCell((short)0).getRichStringCellValue().getString();
+ String specifiedClassName = sheet.getRow(2).getCell(0).getRichStringCellValue().getString();
assertEquals("Test class name in spreadsheet comment", getClass().getName(), specifiedClassName);
-
}
@@ -362,7 +357,7 @@ public final class TestLookupFunctionsFromSpreadsheet extends TestCase {
if(r == null) {
return null;
}
- HSSFCell cell = r.getCell((short) colIndex);
+ HSSFCell cell = r.getCell(colIndex);
if(cell == null) {
return null;
}
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestBug42464.java b/src/testcases/org/apache/poi/hssf/usermodel/TestBug42464.java
index c209054117..9cdf07cd66 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/TestBug42464.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestBug42464.java
@@ -51,7 +51,6 @@ public final class TestBug42464 extends TestCase {
Iterator it = s.rowIterator();
while(it.hasNext()) {
HSSFRow r = (HSSFRow)it.next();
- eval.setCurrentRow(r);
process(r, eval);
}
}
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestBug43093.java b/src/testcases/org/apache/poi/hssf/usermodel/TestBug43093.java
index ce072e9e01..1989d7d4e7 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/TestBug43093.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestBug43093.java
@@ -19,41 +19,43 @@ package org.apache.poi.hssf.usermodel;
import junit.framework.TestCase;
-public class TestBug43093 extends TestCase {
+/**
+ *
+ */
+public final class TestBug43093 extends TestCase {
private static void addNewSheetWithCellsA1toD4(HSSFWorkbook book, int sheet) {
HSSFSheet sht = book .createSheet("s" + sheet);
- for (short r=0; r < 4; r++) {
+ for (int r=0; r < 4; r++) {
HSSFRow row = sht.createRow (r);
- for (short c=0; c < 4; c++) {
+ for (int c=0; c < 4; c++) {
HSSFCell cel = row.createCell(c);
- /**/ cel.setCellValue(sheet*100 + r*10 + c);
+ cel.setCellValue(sheet*100 + r*10 + c);
}
}
}
- public void testBug43093() throws Exception {
- HSSFWorkbook xlw = new HSSFWorkbook();
+ public void testBug43093() {
+ HSSFWorkbook xlw = new HSSFWorkbook();
- addNewSheetWithCellsA1toD4(xlw, 1);
- addNewSheetWithCellsA1toD4(xlw, 2);
- addNewSheetWithCellsA1toD4(xlw, 3);
- addNewSheetWithCellsA1toD4(xlw, 4);
+ addNewSheetWithCellsA1toD4(xlw, 1);
+ addNewSheetWithCellsA1toD4(xlw, 2);
+ addNewSheetWithCellsA1toD4(xlw, 3);
+ addNewSheetWithCellsA1toD4(xlw, 4);
- HSSFSheet s2 = xlw.getSheet("s2");
- HSSFRow s2r3 = s2.getRow(3);
- HSSFCell s2E4 = s2r3.createCell((short)4);
- /**/ s2E4.setCellFormula("SUM(s3!B2:C3)");
+ HSSFSheet s2 = xlw.getSheet("s2");
+ HSSFRow s2r3 = s2.getRow(3);
+ HSSFCell s2E4 = s2r3.createCell(4);
+ s2E4.setCellFormula("SUM(s3!B2:C3)");
- HSSFFormulaEvaluator eva = new HSSFFormulaEvaluator(s2, xlw);
- eva.setCurrentRow(s2r3);
- double d = eva.evaluate(s2E4).getNumberValue();
+ HSSFFormulaEvaluator eva = new HSSFFormulaEvaluator(s2, xlw);
+ double d = eva.evaluate(s2E4).getNumberValue();
- // internalEvaluate(...) Area3DEval.: 311+312+321+322 expected
- assertEquals(d, (double)(311+312+321+322), 0.0000001);
- // System.out.println("Area3DEval ok.: 311+312+321+322=" + d);
+ // internalEvaluate(...) Area3DEval.: 311+312+321+322 expected
+ assertEquals(d, (311+312+321+322), 0.0000001);
+ // System.out.println("Area3DEval ok.: 311+312+321+322=" + d);
}
}
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java b/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java
index 3343757ad7..08646b3e64 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java
@@ -80,7 +80,7 @@ public final class TestBugs extends TestCase {
HSSFWorkbook wb = openSample("15228.xls");
HSSFSheet s = wb.getSheetAt(0);
HSSFRow r = s.createRow(0);
- HSSFCell c = r.createCell((short)0);
+ HSSFCell c = r.createCell(0);
c.setCellValue(10);
writeTestOutputFileForViewing(wb, "test15228");
}
@@ -89,7 +89,7 @@ public final class TestBugs extends TestCase {
HSSFWorkbook wb = openSample("13796.xls");
HSSFSheet s = wb.getSheetAt(0);
HSSFRow r = s.createRow(0);
- HSSFCell c = r.createCell((short)0);
+ HSSFCell c = r.createCell(0);
c.setCellValue(10);
writeOutAndReadBack(wb);
}
@@ -99,7 +99,7 @@ public final class TestBugs extends TestCase {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet s = wb.createSheet();
HSSFRow r = s.createRow(0);
- r.createCell((short)0).setCellFormula("HYPERLINK( \"http://jakarta.apache.org\", \"Jakarta\" )");
+ r.createCell(0).setCellFormula("HYPERLINK( \"http://jakarta.apache.org\", \"Jakarta\" )");
writeTestOutputFileForViewing(wb, "test23094");
}
@@ -111,8 +111,8 @@ public final class TestBugs extends TestCase {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("My sheet");
- HSSFRow row = sheet.createRow( (short) 0 );
- HSSFCell cell = row.createCell( (short) 0 );
+ HSSFRow row = sheet.createRow( 0 );
+ HSSFCell cell = row.createCell( 0 );
cell.setCellFormula("HYPERLINK(\"http://google.com\",\"Google\")");
writeOutAndReadBack(wb);
@@ -144,9 +144,9 @@ public final class TestBugs extends TestCase {
HSSFSheet sheet = wb.getSheetAt(0);
HSSFRow row = sheet.getRow(5);
- HSSFCell cell = row.getCell((short)3);
+ HSSFCell cell = row.getCell(3);
if (cell == null)
- cell = row.createCell((short)3);
+ cell = row.createCell(3);
// Write test
cell.setCellType(HSSFCell.CELL_TYPE_STRING);
@@ -155,9 +155,9 @@ public final class TestBugs extends TestCase {
// change existing numeric cell value
HSSFRow oRow = sheet.getRow(14);
- HSSFCell oCell = oRow.getCell((short)4);
+ HSSFCell oCell = oRow.getCell(4);
oCell.setCellValue(75);
- oCell = oRow.getCell((short)5);
+ oCell = oRow.getCell(5);
setCellText(oCell, "0.3");
writeTestOutputFileForViewing(wb, "test15375");
@@ -179,13 +179,13 @@ public final class TestBugs extends TestCase {
tmp2 = "Test2" + i;
tmp3 = "Test3" + i;
- HSSFRow row = sheet.createRow((short)i);
+ HSSFRow row = sheet.createRow(i);
- HSSFCell cell = row.createCell((short)0);
+ HSSFCell cell = row.createCell(0);
setCellText(cell, tmp1);
- cell = row.createCell((short)1);
+ cell = row.createCell(1);
setCellText(cell, tmp2);
- cell = row.createCell((short)2);
+ cell = row.createCell(2);
setCellText(cell, tmp3);
}
writeTestOutputFileForViewing(wb, "test15375-2");
@@ -205,16 +205,16 @@ public final class TestBugs extends TestCase {
HSSFRow rw = null ;
HSSFCell cell =null;
- rw = sheet.createRow((short)0) ;
+ rw = sheet.createRow(0) ;
//Header row
- for(short j=0; j<col_cnt; j++){
+ for(int j=0; j<col_cnt; j++){
cell = rw.createCell(j) ;
setCellText(cell, "Col " + (j+1)) ;
}
for(int i=1; i<rw_cnt; i++){
- rw = sheet.createRow((short)i) ;
- for(short j=0; j<col_cnt; j++){
+ rw = sheet.createRow(i) ;
+ for(int j=0; j<col_cnt; j++){
cell = rw.createCell(j) ;
setCellText(cell, "Row:" + (i+1) + ",Column:" + (j+1)) ;
}
@@ -279,7 +279,7 @@ public final class TestBugs extends TestCase {
HSSFRow row = sheet.getRow(rowIndex);
int cells = row.getLastCellNum();
- for (short cellIndex = 0; cellIndex < cells; cellIndex++) {
+ for (int cellIndex = 0; cellIndex < cells; cellIndex++) {
row.getCell(cellIndex);
}
}
@@ -291,12 +291,12 @@ public final class TestBugs extends TestCase {
book.createSheet("TEST");
HSSFSheet sheet = book.cloneSheet(0);
book.setSheetName(1,"CLONE");
- sheet.createRow(0).createCell((short)0).setCellValue(new HSSFRichTextString("Test"));
+ sheet.createRow(0).createCell(0).setCellValue(new HSSFRichTextString("Test"));
book = writeOutAndReadBack(book);
sheet = book.getSheet("CLONE");
HSSFRow row = sheet.getRow(0);
- HSSFCell cell = row.getCell((short)0);
+ HSSFCell cell = row.getCell(0);
assertEquals("Test", cell.getRichStringCellValue().getString());
}
@@ -338,14 +338,14 @@ public final class TestBugs extends TestCase {
HSSFWorkbook w = openSample("25695.xls");
- HSSFCell a1 = w.getSheetAt(0).getRow(0).getCell((short) 0);
- HSSFCell a2 = w.getSheetAt(0).getRow(0).getCell((short) 1);
- HSSFCell b1 = w.getSheetAt(0).getRow(1).getCell((short) 0);
- HSSFCell b2 = w.getSheetAt(0).getRow(1).getCell((short) 1);
- HSSFCell c1 = w.getSheetAt(0).getRow(2).getCell((short) 0);
- HSSFCell c2 = w.getSheetAt(0).getRow(2).getCell((short) 1);
- HSSFCell d1 = w.getSheetAt(0).getRow(3).getCell((short) 0);
- HSSFCell d2 = w.getSheetAt(0).getRow(3).getCell((short) 1);
+ HSSFCell a1 = w.getSheetAt(0).getRow(0).getCell(0);
+ HSSFCell a2 = w.getSheetAt(0).getRow(0).getCell(1);
+ HSSFCell b1 = w.getSheetAt(0).getRow(1).getCell(0);
+ HSSFCell b2 = w.getSheetAt(0).getRow(1).getCell(1);
+ HSSFCell c1 = w.getSheetAt(0).getRow(2).getCell(0);
+ HSSFCell c2 = w.getSheetAt(0).getRow(2).getCell(1);
+ HSSFCell d1 = w.getSheetAt(0).getRow(3).getCell(0);
+ HSSFCell d2 = w.getSheetAt(0).getRow(3).getCell(1);
if (false) {
// THAI code page
@@ -368,14 +368,14 @@ public final class TestBugs extends TestCase {
HSSFWorkbook rw = writeOutAndReadBack(w);
- HSSFCell ra1 = rw.getSheetAt(0).getRow(0).getCell((short) 0);
- HSSFCell ra2 = rw.getSheetAt(0).getRow(0).getCell((short) 1);
- HSSFCell rb1 = rw.getSheetAt(0).getRow(1).getCell((short) 0);
- HSSFCell rb2 = rw.getSheetAt(0).getRow(1).getCell((short) 1);
- HSSFCell rc1 = rw.getSheetAt(0).getRow(2).getCell((short) 0);
- HSSFCell rc2 = rw.getSheetAt(0).getRow(2).getCell((short) 1);
- HSSFCell rd1 = rw.getSheetAt(0).getRow(3).getCell((short) 0);
- HSSFCell rd2 = rw.getSheetAt(0).getRow(3).getCell((short) 1);
+ HSSFCell ra1 = rw.getSheetAt(0).getRow(0).getCell(0);
+ HSSFCell ra2 = rw.getSheetAt(0).getRow(0).getCell(1);
+ HSSFCell rb1 = rw.getSheetAt(0).getRow(1).getCell(0);
+ HSSFCell rb2 = rw.getSheetAt(0).getRow(1).getCell(1);
+ HSSFCell rc1 = rw.getSheetAt(0).getRow(2).getCell(0);
+ HSSFCell rc2 = rw.getSheetAt(0).getRow(2).getCell(1);
+ HSSFCell rd1 = rw.getSheetAt(0).getRow(3).getCell(0);
+ HSSFCell rd2 = rw.getSheetAt(0).getRow(3).getCell(1);
confirmSameCellText(a1, ra1);
confirmSameCellText(b1, rb1);
@@ -427,7 +427,7 @@ public final class TestBugs extends TestCase {
wb.setSheetName(0, "Sheet1");
HSSFRow row = sheet.createRow(0);
- HSSFCell cell = row.createCell((short)0);
+ HSSFCell cell = row.createCell(0);
String formulaText =
"IF(ROUND(A2*B2*C2,2)>ROUND(B2*D2,2),ROUND(A2*B2*C2,2),ROUND(B2*D2,2))";
cell.setCellFormula(formulaText);
@@ -489,7 +489,7 @@ public final class TestBugs extends TestCase {
for(int i = 1; i < 400; i++) {
HSSFRow row = sheet.getRow(i);
if(row != null) {
- row.getCell((short)0);
+ row.getCell(0);
}
}
@@ -499,7 +499,7 @@ public final class TestBugs extends TestCase {
for(int i = 1; i < 400; i++) {
HSSFRow row = sheet.getRow(i);
if(row != null) {
- row.getCell((short)0);
+ row.getCell(0);
}
}
}
@@ -523,7 +523,7 @@ public final class TestBugs extends TestCase {
for (int i = sheet.getFirstRowNum(); i <= sheet.getLastRowNum(); i++) {
HSSFRow row = sheet.getRow(i);
if (row != null) {
- HSSFCell cell = row .getCell((short)0);
+ HSSFCell cell = row .getCell(0);
assertEquals(HSSFCell.CELL_TYPE_STRING, cell.getCellType());
count++;
}
@@ -632,11 +632,11 @@ public final class TestBugs extends TestCase {
HSSFSheet workSheet = workBook.createSheet("Sheet1");
HSSFCell cell;
HSSFRow row = workSheet.createRow(0);
- cell = row.createCell((short)0, HSSFCell.CELL_TYPE_NUMERIC);
+ cell = row.createCell(0, HSSFCell.CELL_TYPE_NUMERIC);
cell.setCellValue(1.0);
- cell = row.createCell((short)1, HSSFCell.CELL_TYPE_NUMERIC);
+ cell = row.createCell(1, HSSFCell.CELL_TYPE_NUMERIC);
cell.setCellValue(2.0);
- cell = row.createCell((short)2, HSSFCell.CELL_TYPE_FORMULA);
+ cell = row.createCell(2, HSSFCell.CELL_TYPE_FORMULA);
cell.setCellFormula("SUM(A1:B1)");
writeOutAndReadBack(wb);
@@ -753,12 +753,12 @@ public final class TestBugs extends TestCase {
// Textual value
HSSFRow r1 = s.getRow(0);
- HSSFCell c1 = r1.getCell((short)1);
+ HSSFCell c1 = r1.getCell(1);
assertEquals("=CHOOSE(2,A2,A3,A4)", c1.getRichStringCellValue().toString());
// Formula Value
HSSFRow r2 = s.getRow(1);
- HSSFCell c2 = r2.getCell((short)1);
+ HSSFCell c2 = r2.getCell(1);
assertEquals(25, (int)c2.getNumericCellValue());
try {
@@ -900,7 +900,7 @@ public final class TestBugs extends TestCase {
* Had a problem apparently, not sure what as it
* works just fine...
*/
- public void test44891() throws Exception {
+ public void test44891() {
HSSFWorkbook wb = openSample("44891.xls");
assertTrue("no errors reading sample xls", true);
writeOutAndReadBack(wb);
@@ -912,7 +912,7 @@ public final class TestBugs extends TestCase {
*
* Works fine with poi-3.1-beta1.
*/
- public void test44235() throws Exception {
+ public void test44235() {
HSSFWorkbook wb = openSample("44235.xls");
assertTrue("no errors reading sample xls", true);
writeOutAndReadBack(wb);
@@ -927,16 +927,16 @@ public final class TestBugs extends TestCase {
public void test21334() {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sh = wb.createSheet();
- HSSFCell cell = sh.createRow(0).createCell((short)0);
+ HSSFCell cell = sh.createRow(0).createCell(0);
String formula = "SUM(IF(FREQUENCY(IF(LEN(V4:V220)>0,MATCH(V4:V220,V4:V220,0),\"\"),IF(LEN(V4:V220)>0,MATCH(V4:V220,V4:V220,0),\"\"))>0,1))";
cell.setCellFormula(formula);
HSSFWorkbook wb_sv = writeOutAndReadBack(wb);
- HSSFCell cell_sv = wb_sv.getSheetAt(0).getRow(0).getCell((short)0);
+ HSSFCell cell_sv = wb_sv.getSheetAt(0).getRow(0).getCell(0);
assertEquals(formula, cell_sv.getCellFormula());
}
- public void test36947() throws Exception {
+ public void test36947() {
HSSFWorkbook wb = openSample("36947.xls");
assertTrue("no errors reading sample xls", true);
writeOutAndReadBack(wb);
@@ -948,12 +948,12 @@ public final class TestBugs extends TestCase {
*/
public void test42448(){
HSSFWorkbook wb = new HSSFWorkbook();
- HSSFCell cell = wb.createSheet().createRow(0).createCell((short)0);
+ HSSFCell cell = wb.createSheet().createRow(0).createCell(0);
cell.setCellFormula("SUMPRODUCT(A!C7:A!C67, B8:B68) / B69");
assertTrue("no errors parsing formula", true);
}
- public void test39634() throws Exception {
+ public void test39634() {
HSSFWorkbook wb = openSample("39634.xls");
assertTrue("no errors reading sample xls", true);
writeOutAndReadBack(wb);
@@ -965,7 +965,7 @@ public final class TestBugs extends TestCase {
* HSSFObjectData
* @throws Exception
*/
- public void test44840() throws Exception {
+ public void test44840() {
HSSFWorkbook wb = openSample("WithCheckBoxes.xls");
// Take a look at the embeded objects
@@ -993,7 +993,11 @@ public final class TestBugs extends TestCase {
try {
obj.getDirectory();
fail();
- } catch(FileNotFoundException e) {}
+ } catch(FileNotFoundException e) {
+ // expectd during successful test
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
}
/**
@@ -1002,7 +1006,7 @@ public final class TestBugs extends TestCase {
* used for printing stuff.
* Currently broken, as we change the Ptg
*/
- public void test30978() throws Exception {
+ public void test30978() {
HSSFWorkbook wb = openSample("30978-alt.xls");
assertEquals(1, wb.getNumberOfNames());
assertEquals(3, wb.getNumberOfSheets());
@@ -1058,15 +1062,15 @@ public final class TestBugs extends TestCase {
/**
* Test that fonts get added properly
*/
- public void test45338() throws Exception {
+ public void test45338() {
HSSFWorkbook wb = new HSSFWorkbook();
assertEquals(4, wb.getNumberOfFonts());
HSSFSheet s = wb.createSheet();
s.createRow(0);
s.createRow(1);
- HSSFCell c1 = s.getRow(0).createCell((short)0);
- HSSFCell c2 = s.getRow(1).createCell((short)0);
+ HSSFCell c1 = s.getRow(0).createCell(0);
+ HSSFCell c2 = s.getRow(1).createCell(0);
assertEquals(4, wb.getNumberOfFonts());
@@ -1142,15 +1146,14 @@ public final class TestBugs extends TestCase {
/**
* From the mailing list - ensure we can handle a formula
* containing a zip code, eg ="70164"
- * @throws Exception
*/
- public void testZipCodeFormulas() throws Exception {
+ public void testZipCodeFormulas() {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet s = wb.createSheet();
s.createRow(0);
- HSSFCell c1 = s.getRow(0).createCell((short)0);
- HSSFCell c2 = s.getRow(0).createCell((short)1);
- HSSFCell c3 = s.getRow(0).createCell((short)2);
+ HSSFCell c1 = s.getRow(0).createCell(0);
+ HSSFCell c2 = s.getRow(0).createCell(1);
+ HSSFCell c3 = s.getRow(0).createCell(2);
// As number and string
c1.setCellFormula("70164");
@@ -1178,7 +1181,6 @@ public final class TestBugs extends TestCase {
// Now evaluate, they should all be changed
HSSFFormulaEvaluator eval = new HSSFFormulaEvaluator(s, wb);
- eval.setCurrentRow(s.getRow(0));
eval.evaluateFormulaCell(c1);
eval.evaluateFormulaCell(c2);
eval.evaluateFormulaCell(c3);
@@ -1196,9 +1198,9 @@ public final class TestBugs extends TestCase {
// Write and read
HSSFWorkbook nwb = writeOutAndReadBack(wb);
HSSFSheet ns = nwb.getSheetAt(0);
- HSSFCell nc1 = ns.getRow(0).getCell((short)0);
- HSSFCell nc2 = ns.getRow(0).getCell((short)1);
- HSSFCell nc3 = ns.getRow(0).getCell((short)2);
+ HSSFCell nc1 = ns.getRow(0).getCell(0);
+ HSSFCell nc2 = ns.getRow(0).getCell(1);
+ HSSFCell nc3 = ns.getRow(0).getCell(2);
// Re-check
assertEquals(70164.0, nc1.getNumericCellValue(), 0.00001);
@@ -1243,7 +1245,7 @@ public final class TestBugs extends TestCase {
* For now, blows up with an exception from ExtPtg
* Expected ExpPtg to be converted from Shared to Non-Shared...
*/
- public void DISABLEDtest43623() throws Exception {
+ public void DISABLEDtest43623() {
HSSFWorkbook wb = openSample("43623.xls");
assertEquals(1, wb.getNumberOfSheets());
@@ -1274,7 +1276,7 @@ public final class TestBugs extends TestCase {
* People are all getting confused about the last
* row and cell number
*/
- public void test30635() throws Exception {
+ public void test30635() {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet s = wb.createSheet();
@@ -1303,17 +1305,17 @@ public final class TestBugs extends TestCase {
assertEquals(0, r.getPhysicalNumberOfCells());
// Add a cell, things move off -1
- r.createCell((short)0);
+ r.createCell(0);
assertEquals(0, r.getFirstCellNum());
assertEquals(1, r.getLastCellNum()); // last cell # + 1
assertEquals(1, r.getPhysicalNumberOfCells());
- r.createCell((short)1);
+ r.createCell(1);
assertEquals(0, r.getFirstCellNum());
assertEquals(2, r.getLastCellNum()); // last cell # + 1
assertEquals(2, r.getPhysicalNumberOfCells());
- r.createCell((short)4);
+ r.createCell(4);
assertEquals(0, r.getFirstCellNum());
assertEquals(5, r.getLastCellNum()); // last cell # + 1
assertEquals(3, r.getPhysicalNumberOfCells());
@@ -1322,7 +1324,7 @@ public final class TestBugs extends TestCase {
/**
* Data Tables - ptg 0x2
*/
- public void test44958() throws Exception {
+ public void test44958() {
HSSFWorkbook wb = openSample("44958.xls");
HSSFSheet s;
HSSFRow r;
@@ -1353,7 +1355,7 @@ public final class TestBugs extends TestCase {
/**
* 45322: HSSFSheet.autoSizeColumn fails when style.getDataFormat() returns -1
*/
- public void test45322() throws Exception {
+ public void test45322() {
HSSFWorkbook wb = openSample("44958.xls");
HSSFSheet sh = wb.getSheetAt(0);
for(short i=0; i < 30; i++) sh.autoSizeColumn(i);
@@ -1363,7 +1365,7 @@ public final class TestBugs extends TestCase {
* We used to add too many UncalcRecords to sheets
* with diagrams on. Don't any more
*/
- public void test45414() throws Exception {
+ public void test45414() {
HSSFWorkbook wb = openSample("WithThreeCharts.xls");
wb.getSheetAt(0).setForceFormulaRecalculation(true);
wb.getSheetAt(1).setForceFormulaRecalculation(false);
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestFormulaEvaluatorBugs.java b/src/testcases/org/apache/poi/hssf/usermodel/TestFormulaEvaluatorBugs.java
index 318fcd2bf6..7dbb9c3e16 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/TestFormulaEvaluatorBugs.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestFormulaEvaluatorBugs.java
@@ -59,11 +59,11 @@ public final class TestFormulaEvaluatorBugs extends TestCase {
HSSFSheet sheet = wb.getSheetAt(0);
HSSFRow row = sheet.getRow(0);
- row.getCell((short) 0).setCellValue(4.2);
- row.getCell((short) 2).setCellValue(25);
+ row.getCell(0).setCellValue(4.2);
+ row.getCell(2).setCellValue(25);
HSSFFormulaEvaluator.evaluateAllFormulaCells(wb);
- assertEquals(4.2 * 25, row.getCell((short) 3).getNumericCellValue(), 0.0001);
+ assertEquals(4.2 * 25, row.getCell(3).getNumericCellValue(), 0.0001);
// Save
File existing = new File(tmpDirName, "44636-existing.xls");
@@ -77,14 +77,14 @@ public final class TestFormulaEvaluatorBugs extends TestCase {
sheet = wb.createSheet();
row = sheet.createRow(0);
- row.createCell((short) 0).setCellValue(1.2);
- row.createCell((short) 1).setCellValue(4.2);
+ row.createCell(0).setCellValue(1.2);
+ row.createCell(1).setCellValue(4.2);
row = sheet.createRow(1);
- row.createCell((short) 0).setCellFormula("SUM(A1:B1)");
+ row.createCell(0).setCellFormula("SUM(A1:B1)");
HSSFFormulaEvaluator.evaluateAllFormulaCells(wb);
- assertEquals(5.4, row.getCell((short) 0).getNumericCellValue(), 0.0001);
+ assertEquals(5.4, row.getCell(0).getNumericCellValue(), 0.0001);
// Save
File scratch = new File(tmpDirName, "44636-scratch.xls");
@@ -113,57 +113,48 @@ public final class TestFormulaEvaluatorBugs extends TestCase {
HSSFFormulaEvaluator eva = new HSSFFormulaEvaluator(sheet, wb);
row = sheet.getRow(0);
- cell = row.getCell((short) 0);
+ cell = row.getCell(0);
assertEquals("31+46", cell.getCellFormula());
- eva.setCurrentRow(row);
assertEquals(77, eva.evaluate(cell).getNumberValue(), 0);
row = sheet.getRow(1);
- cell = row.getCell((short) 0);
+ cell = row.getCell(0);
assertEquals("30+53", cell.getCellFormula());
- eva.setCurrentRow(row);
assertEquals(83, eva.evaluate(cell).getNumberValue(), 0);
row = sheet.getRow(2);
- cell = row.getCell((short) 0);
+ cell = row.getCell(0);
assertEquals("SUM(A1:A2)", cell.getCellFormula());
- eva.setCurrentRow(row);
assertEquals(160, eva.evaluate(cell).getNumberValue(), 0);
row = sheet.getRow(4);
- cell = row.getCell((short) 0);
+ cell = row.getCell(0);
assertEquals("32767+32768", cell.getCellFormula());
- eva.setCurrentRow(row);
assertEquals(65535, eva.evaluate(cell).getNumberValue(), 0);
row = sheet.getRow(7);
- cell = row.getCell((short) 0);
+ cell = row.getCell(0);
assertEquals("32744+42333", cell.getCellFormula());
- eva.setCurrentRow(row);
assertEquals(75077, eva.evaluate(cell).getNumberValue(), 0);
row = sheet.getRow(8);
- cell = row.getCell((short) 0);
+ cell = row.getCell(0);
assertEquals("327680.0/32768", cell.getCellFormula());
- eva.setCurrentRow(row);
assertEquals(10, eva.evaluate(cell).getNumberValue(), 0);
row = sheet.getRow(9);
- cell = row.getCell((short) 0);
+ cell = row.getCell(0);
assertEquals("32767+32769", cell.getCellFormula());
- eva.setCurrentRow(row);
assertEquals(65536, eva.evaluate(cell).getNumberValue(), 0);
row = sheet.getRow(10);
- cell = row.getCell((short) 0);
+ cell = row.getCell(0);
assertEquals("35000+36000", cell.getCellFormula());
- eva.setCurrentRow(row);
assertEquals(71000, eva.evaluate(cell).getNumberValue(), 0);
row = sheet.getRow(11);
- cell = row.getCell((short) 0);
+ cell = row.getCell(0);
assertEquals("-1000000.0-3000000.0", cell.getCellFormula());
- eva.setCurrentRow(row);
assertEquals(-4000000, eva.evaluate(cell).getNumberValue(), 0);
}
@@ -189,7 +180,7 @@ public final class TestFormulaEvaluatorBugs extends TestCase {
HSSFRow rowSUM2D = sheet.getRow(5);
// Test the sum
- HSSFCell cellSUM = rowSUM.getCell((short) 0);
+ HSSFCell cellSUM = rowSUM.getCell(0);
FormulaRecordAggregate frec = (FormulaRecordAggregate) cellSUM.getCellValueRecord();
List ops = frec.getFormulaRecord().getParsedExpression();
@@ -210,7 +201,6 @@ public final class TestFormulaEvaluatorBugs extends TestCase {
// rows it covers as we don't have the sheet
// to hand when turning the Ptgs into a string
assertEquals("SUM(C:C)", cellSUM.getCellFormula());
- eva.setCurrentRow(rowSUM);
// But the evaluator knows the sheet, so it
// can do it properly
@@ -219,15 +209,13 @@ public final class TestFormulaEvaluatorBugs extends TestCase {
// Test the index
// Again, the formula string will be right but
// lacking row count, evaluated will be right
- HSSFCell cellIDX = rowIDX.getCell((short) 0);
+ HSSFCell cellIDX = rowIDX.getCell(0);
assertEquals("INDEX(C:C,2,1)", cellIDX.getCellFormula());
- eva.setCurrentRow(rowIDX);
assertEquals(2, eva.evaluate(cellIDX).getNumberValue(), 0);
// Across two colums
- HSSFCell cellSUM2D = rowSUM2D.getCell((short) 0);
+ HSSFCell cellSUM2D = rowSUM2D.getCell(0);
assertEquals("SUM(C:D)", cellSUM2D.getCellFormula());
- eva.setCurrentRow(rowSUM2D);
assertEquals(66, eva.evaluate(cellSUM2D).getNumberValue(), 0);
}
@@ -239,12 +227,11 @@ public final class TestFormulaEvaluatorBugs extends TestCase {
HSSFSheet sheet = wb.createSheet();
wb.setSheetName(0, "Sheet1");
HSSFRow row = sheet.createRow(0);
- HSSFCell cell = row.createCell((short) 0);
+ HSSFCell cell = row.createCell(0);
cell.setCellFormula("1=1");
HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(sheet, wb);
- fe.setCurrentRow(row);
try {
fe.evaluateInCell(cell);
} catch (NumberFormatException e) {
@@ -267,7 +254,6 @@ public final class TestFormulaEvaluatorBugs extends TestCase {
for (Iterator rows = s.rowIterator(); rows.hasNext();) {
HSSFRow r = (HSSFRow) rows.next();
- eval.setCurrentRow(r);
for (Iterator cells = r.cellIterator(); cells.hasNext();) {
HSSFCell c = (HSSFCell) cells.next();
@@ -281,10 +267,9 @@ public final class TestFormulaEvaluatorBugs extends TestCase {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("Sheet1");
HSSFRow row = sheet.createRow(1);
- HSSFCell cell = row.createCell((short) 0);
+ HSSFCell cell = row.createCell(0);
cell.setCellFormula("na()"); // this formula evaluates to an Excel error code '#N/A'
HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(sheet, wb);
- fe.setCurrentRow(row);
try {
fe.evaluateInCell(cell);
} catch (NumberFormatException e) {
@@ -320,8 +305,6 @@ public final class TestFormulaEvaluatorBugs extends TestCase {
final HSSFFormulaEvaluator evaluator = new
HSSFFormulaEvaluator(sheet, wb);
- evaluator.setCurrentRow(excelRow);
-
now = System.currentTimeMillis();
evaluator.evaluate(excelCell);
then = System.currentTimeMillis();
@@ -333,8 +316,6 @@ public final class TestFormulaEvaluatorBugs extends TestCase {
final HSSFFormulaEvaluator evaluator = new
HSSFFormulaEvaluator(sheet, wb);
- evaluator.setCurrentRow(excelRow);
-
now = System.currentTimeMillis();
evaluator.evaluate(excelCell);
then = System.currentTimeMillis();
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestFormulaEvaluatorDocs.java b/src/testcases/org/apache/poi/hssf/usermodel/TestFormulaEvaluatorDocs.java
index 6c2e3b6412..bed8869d54 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/TestFormulaEvaluatorDocs.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestFormulaEvaluatorDocs.java
@@ -1,3 +1,20 @@
+/* ====================================================================
+ 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.usermodel;
import java.util.Iterator;
@@ -9,15 +26,12 @@ import junit.framework.TestCase;
* http://poi.apache.org/hssf/eval.html
* all actually works as we'd expect them to
*/
-public class TestFormulaEvaluatorDocs extends TestCase {
- protected void setUp() throws Exception {
- super.setUp();
- }
+public final class TestFormulaEvaluatorDocs extends TestCase {
/**
* http://poi.apache.org/hssf/eval.html#EvaluateAll
*/
- public void testEvaluateAll() throws Exception {
+ public void testEvaluateAll() {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet s1 = wb.createSheet();
HSSFSheet s2 = wb.createSheet();
@@ -28,21 +42,21 @@ public class TestFormulaEvaluatorDocs extends TestCase {
HSSFRow s1r2 = s1.createRow(1);
HSSFRow s2r1 = s2.createRow(0);
- HSSFCell s1r1c1 = s1r1.createCell((short)0);
- HSSFCell s1r1c2 = s1r1.createCell((short)1);
- HSSFCell s1r1c3 = s1r1.createCell((short)2);
+ HSSFCell s1r1c1 = s1r1.createCell(0);
+ HSSFCell s1r1c2 = s1r1.createCell(1);
+ HSSFCell s1r1c3 = s1r1.createCell(2);
s1r1c1.setCellValue(22.3);
s1r1c2.setCellValue(33.4);
s1r1c3.setCellFormula("SUM(A1:B1)");
- HSSFCell s1r2c1 = s1r2.createCell((short)0);
- HSSFCell s1r2c2 = s1r2.createCell((short)1);
- HSSFCell s1r2c3 = s1r2.createCell((short)2);
+ HSSFCell s1r2c1 = s1r2.createCell(0);
+ HSSFCell s1r2c2 = s1r2.createCell(1);
+ HSSFCell s1r2c3 = s1r2.createCell(2);
s1r2c1.setCellValue(-1.2);
s1r2c2.setCellValue(-3.4);
s1r2c3.setCellFormula("SUM(A2:B2)");
- HSSFCell s2r1c1 = s2r1.createCell((short)0);
+ HSSFCell s2r1c1 = s2r1.createCell(0);
s2r1c1.setCellFormula("S1!A1");
// Not evaluated yet
@@ -58,7 +72,6 @@ public class TestFormulaEvaluatorDocs extends TestCase {
for(Iterator rit = sheet.rowIterator(); rit.hasNext();) {
HSSFRow r = (HSSFRow)rit.next();
- evaluator.setCurrentRow(r);
for(Iterator cit = r.cellIterator(); cit.hasNext();) {
HSSFCell c = (HSSFCell)cit.next();
@@ -73,17 +86,17 @@ public class TestFormulaEvaluatorDocs extends TestCase {
}
// Check now as expected
- assertEquals(55.7, wb.getSheetAt(0).getRow(0).getCell((short)2).getNumericCellValue(), 0);
- assertEquals("SUM(A1:B1)", wb.getSheetAt(0).getRow(0).getCell((short)2).getCellFormula());
- assertEquals(HSSFCell.CELL_TYPE_FORMULA, wb.getSheetAt(0).getRow(0).getCell((short)2).getCellType());
+ assertEquals(55.7, wb.getSheetAt(0).getRow(0).getCell(2).getNumericCellValue(), 0);
+ assertEquals("SUM(A1:B1)", wb.getSheetAt(0).getRow(0).getCell(2).getCellFormula());
+ assertEquals(HSSFCell.CELL_TYPE_FORMULA, wb.getSheetAt(0).getRow(0).getCell(2).getCellType());
- assertEquals(-4.6, wb.getSheetAt(0).getRow(1).getCell((short)2).getNumericCellValue(), 0);
- assertEquals("SUM(A2:B2)", wb.getSheetAt(0).getRow(1).getCell((short)2).getCellFormula());
- assertEquals(HSSFCell.CELL_TYPE_FORMULA, wb.getSheetAt(0).getRow(1).getCell((short)2).getCellType());
+ assertEquals(-4.6, wb.getSheetAt(0).getRow(1).getCell(2).getNumericCellValue(), 0);
+ assertEquals("SUM(A2:B2)", wb.getSheetAt(0).getRow(1).getCell(2).getCellFormula());
+ assertEquals(HSSFCell.CELL_TYPE_FORMULA, wb.getSheetAt(0).getRow(1).getCell(2).getCellType());
- assertEquals(22.3, wb.getSheetAt(1).getRow(0).getCell((short)0).getNumericCellValue(), 0);
- assertEquals("'S1'!A1", wb.getSheetAt(1).getRow(0).getCell((short)0).getCellFormula());
- assertEquals(HSSFCell.CELL_TYPE_FORMULA, wb.getSheetAt(1).getRow(0).getCell((short)0).getCellType());
+ assertEquals(22.3, wb.getSheetAt(1).getRow(0).getCell(0).getNumericCellValue(), 0);
+ assertEquals("'S1'!A1", wb.getSheetAt(1).getRow(0).getCell(0).getCellFormula());
+ assertEquals(HSSFCell.CELL_TYPE_FORMULA, wb.getSheetAt(1).getRow(0).getCell(0).getCellType());
// Now do the alternate call, which zaps the formulas
@@ -94,7 +107,6 @@ public class TestFormulaEvaluatorDocs extends TestCase {
for(Iterator rit = sheet.rowIterator(); rit.hasNext();) {
HSSFRow r = (HSSFRow)rit.next();
- evaluator.setCurrentRow(r);
for(Iterator cit = r.cellIterator(); cit.hasNext();) {
HSSFCell c = (HSSFCell)cit.next();
@@ -105,13 +117,13 @@ public class TestFormulaEvaluatorDocs extends TestCase {
}
}
- assertEquals(55.7, wb.getSheetAt(0).getRow(0).getCell((short)2).getNumericCellValue(), 0);
- assertEquals(HSSFCell.CELL_TYPE_NUMERIC, wb.getSheetAt(0).getRow(0).getCell((short)2).getCellType());
+ assertEquals(55.7, wb.getSheetAt(0).getRow(0).getCell(2).getNumericCellValue(), 0);
+ assertEquals(HSSFCell.CELL_TYPE_NUMERIC, wb.getSheetAt(0).getRow(0).getCell(2).getCellType());
- assertEquals(-4.6, wb.getSheetAt(0).getRow(1).getCell((short)2).getNumericCellValue(), 0);
- assertEquals(HSSFCell.CELL_TYPE_NUMERIC, wb.getSheetAt(0).getRow(1).getCell((short)2).getCellType());
+ assertEquals(-4.6, wb.getSheetAt(0).getRow(1).getCell(2).getNumericCellValue(), 0);
+ assertEquals(HSSFCell.CELL_TYPE_NUMERIC, wb.getSheetAt(0).getRow(1).getCell(2).getCellType());
- assertEquals(22.3, wb.getSheetAt(1).getRow(0).getCell((short)0).getNumericCellValue(), 0);
- assertEquals(HSSFCell.CELL_TYPE_NUMERIC, wb.getSheetAt(1).getRow(0).getCell((short)0).getCellType());
+ assertEquals(22.3, wb.getSheetAt(1).getRow(0).getCell(0).getNumericCellValue(), 0);
+ assertEquals(HSSFCell.CELL_TYPE_NUMERIC, wb.getSheetAt(1).getRow(0).getCell(0).getCellType());
}
}
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFCell.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFCell.java
index c3d73cf4a7..da5d2cc6a9 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFCell.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFCell.java
@@ -17,12 +17,6 @@
package org.apache.poi.hssf.usermodel;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
import java.util.Date;
import java.util.GregorianCalendar;
@@ -32,7 +26,6 @@ import junit.framework.TestCase;
import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.hssf.model.Sheet;
import org.apache.poi.hssf.util.HSSFColor;
-import org.apache.poi.util.TempFile;
/**
* Tests various functionity having to do with HSSFCell. For instance support for
@@ -47,23 +40,15 @@ public final class TestHSSFCell extends TestCase {
return HSSFTestDataSamples.openSampleWorkbook(sampleFileName);
}
private static HSSFWorkbook writeOutAndReadBack(HSSFWorkbook original) {
-
- try {
- ByteArrayOutputStream baos = new ByteArrayOutputStream(4096);
- original.write(baos);
- ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
- return new HSSFWorkbook(bais);
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
+ return HSSFTestDataSamples.writeOutAndReadBack(original);
}
- public void testSetValues() throws Exception {
+ public void testSetValues() {
HSSFWorkbook book = new HSSFWorkbook();
HSSFSheet sheet = book.createSheet("test");
HSSFRow row = sheet.createRow(0);
- HSSFCell cell = row.createCell((short)0);
+ HSSFCell cell = row.createCell(0);
cell.setCellValue(1.2);
assertEquals(1.2, cell.getNumericCellValue(), 0.0001);
@@ -85,54 +70,42 @@ public final class TestHSSFCell extends TestCase {
/**
* test that Boolean and Error types (BoolErrRecord) are supported properly.
*/
- public void testBoolErr()
- throws java.io.IOException {
-
- File file = TempFile.createTempFile("testBoolErr",".xls");
- FileOutputStream out = new FileOutputStream(file);
- HSSFWorkbook wb = new HSSFWorkbook();
- HSSFSheet s = wb.createSheet("testSheet1");
- HSSFRow r = null;
- HSSFCell c = null;
- r = s.createRow((short)0);
- c=r.createCell((short)1);
- //c.setCellType(HSSFCell.CELL_TYPE_BOOLEAN);
- c.setCellValue(true);
-
- c=r.createCell((short)2);
- //c.setCellType(HSSFCell.CELL_TYPE_BOOLEAN);
- c.setCellValue(false);
-
- r = s.createRow((short)1);
- c=r.createCell((short)1);
- //c.setCellType(HSSFCell.CELL_TYPE_ERROR);
- c.setCellErrorValue((byte)0);
-
- c=r.createCell((short)2);
- //c.setCellType(HSSFCell.CELL_TYPE_ERROR);
- c.setCellErrorValue((byte)7);
-
-
- wb.write(out);
- out.close();
-
- assertTrue("file exists",file.exists());
-
- FileInputStream in = new FileInputStream(file);
- wb = new HSSFWorkbook(in);
- s = wb.getSheetAt(0);
- r = s.getRow(0);
- c = r.getCell((short)1);
- assertTrue("boolean value 0,1 = true",c.getBooleanCellValue());
- c = r.getCell((short)2);
- assertTrue("boolean value 0,2 = false",c.getBooleanCellValue()==false);
- r = s.getRow(1);
- c = r.getCell((short)1);
- assertTrue("boolean value 0,1 = 0",c.getErrorCellValue() == 0);
- c = r.getCell((short)2);
- assertTrue("boolean value 0,2 = 7",c.getErrorCellValue() == 7);
-
- in.close();
+ public void testBoolErr() {
+
+ HSSFWorkbook wb = new HSSFWorkbook();
+ HSSFSheet s = wb.createSheet("testSheet1");
+ HSSFRow r = null;
+ HSSFCell c = null;
+ r = s.createRow((short)0);
+ c=r.createCell(1);
+ //c.setCellType(HSSFCell.CELL_TYPE_BOOLEAN);
+ c.setCellValue(true);
+
+ c=r.createCell(2);
+ //c.setCellType(HSSFCell.CELL_TYPE_BOOLEAN);
+ c.setCellValue(false);
+
+ r = s.createRow((short)1);
+ c=r.createCell(1);
+ //c.setCellType(HSSFCell.CELL_TYPE_ERROR);
+ c.setCellErrorValue((byte)0);
+
+ c=r.createCell(2);
+ //c.setCellType(HSSFCell.CELL_TYPE_ERROR);
+ c.setCellErrorValue((byte)7);
+
+ wb = writeOutAndReadBack(wb);
+ s = wb.getSheetAt(0);
+ r = s.getRow(0);
+ c = r.getCell(1);
+ assertTrue("boolean value 0,1 = true",c.getBooleanCellValue());
+ c = r.getCell(2);
+ assertTrue("boolean value 0,2 = false",c.getBooleanCellValue()==false);
+ r = s.getRow(1);
+ c = r.getCell(1);
+ assertTrue("boolean value 0,1 = 0",c.getErrorCellValue() == 0);
+ c = r.getCell(2);
+ assertTrue("boolean value 0,2 = 7",c.getErrorCellValue() == 7);
}
/**
@@ -140,7 +113,7 @@ public final class TestHSSFCell extends TestCase {
* is working properly. Conversion of the date is also an issue,
* but there's a separate unit test for that.
*/
- public void testDateWindowingRead() throws Exception {
+ public void testDateWindowingRead() {
GregorianCalendar cal = new GregorianCalendar(2000,0,1); // Jan. 1, 2000
Date date = cal.getTime();
@@ -150,7 +123,7 @@ public final class TestHSSFCell extends TestCase {
assertEquals("Date from file using 1900 Date Windowing",
date.getTime(),
- sheet.getRow(0).getCell((short)0)
+ sheet.getRow(0).getCell(0)
.getDateCellValue().getTime());
// now check a file with 1904 Date Windowing
@@ -159,7 +132,7 @@ public final class TestHSSFCell extends TestCase {
assertEquals("Date from file using 1904 Date Windowing",
date.getTime(),
- sheet.getRow(0).getCell((short)0)
+ sheet.getRow(0).getCell(0)
.getDateCellValue().getTime());
}
@@ -169,7 +142,7 @@ public final class TestHSSFCell extends TestCase {
* previous test ({@link #testDateWindowingRead}) fails, the
* results of this test are meaningless.
*/
- public void testDateWindowingWrite() throws Exception {
+ public void testDateWindowingWrite() {
GregorianCalendar cal = new GregorianCalendar(2000,0,1); // Jan. 1, 2000
Date date = cal.getTime();
@@ -199,7 +172,7 @@ public final class TestHSSFCell extends TestCase {
HSSFCell cell = row.getCell(colIdx);
if (cell == null) {
- cell = row.createCell((short)colIdx);
+ cell = row.createCell(colIdx);
}
cell.setCellValue(date);
}
@@ -214,8 +187,7 @@ public final class TestHSSFCell extends TestCase {
/**
* Tests that the active cell can be correctly read and set
*/
- public void testActiveCell() throws Exception
- {
+ public void testActiveCell() {
//read in sample
HSSFWorkbook book = openSample("Simple.xls");
@@ -228,7 +200,7 @@ public final class TestHSSFCell extends TestCase {
1, s.getActiveCellRow());
//modify position through HSSFCell
- HSSFCell cell = umSheet.createRow(3).createCell((short) 2);
+ HSSFCell cell = umSheet.createRow(3).createCell(2);
cell.setAsActiveCell();
assertEquals("After modify, active cell should be in col 2",
(short) 2, s.getActiveCellCol());
@@ -270,14 +242,14 @@ public final class TestHSSFCell extends TestCase {
cs.setBorderBottom((short)1);
r = s.createRow((short)0);
- c=r.createCell((short)0);
+ c=r.createCell(0);
c.setCellStyle(cs);
c.setCellFormula("2*3");
wb = writeOutAndReadBack(wb);
s = wb.getSheetAt(0);
r = s.getRow(0);
- c = r.getCell((short)0);
+ c = r.getCell(0);
assertTrue("Formula Cell at 0,0", (c.getCellType()==c.CELL_TYPE_FORMULA));
cs = c.getCellStyle();
@@ -298,7 +270,7 @@ public final class TestHSSFCell extends TestCase {
HSSFWorkbook wb = openSample("WithHyperlink.xls");
HSSFSheet sheet = wb.getSheetAt(0);
- HSSFCell cell = sheet.getRow(4).getCell((short)0);
+ HSSFCell cell = sheet.getRow(4).getCell(0);
HSSFHyperlink link = cell.getHyperlink();
assertNotNull(link);
@@ -311,13 +283,13 @@ public final class TestHSSFCell extends TestCase {
/**
* Test reading hyperlinks
*/
- public void testWithTwoHyperlinks() throws Exception {
+ public void testWithTwoHyperlinks() {
HSSFWorkbook wb = openSample("WithTwoHyperLinks.xls");
HSSFSheet sheet = wb.getSheetAt(0);
- HSSFCell cell1 = sheet.getRow(4).getCell((short)0);
+ HSSFCell cell1 = sheet.getRow(4).getCell(0);
HSSFHyperlink link1 = cell1.getHyperlink();
assertNotNull(link1);
assertEquals("Foo", link1.getLabel());
@@ -325,55 +297,46 @@ public final class TestHSSFCell extends TestCase {
assertEquals(4, link1.getFirstRow());
assertEquals(0, link1.getFirstColumn());
- HSSFCell cell2 = sheet.getRow(8).getCell((short)1);
+ HSSFCell cell2 = sheet.getRow(8).getCell(1);
HSSFHyperlink link2 = cell2.getHyperlink();
assertNotNull(link2);
assertEquals("Bar", link2.getLabel());
assertEquals("http://poi.apache.org/hssf/", link2.getAddress());
assertEquals(8, link2.getFirstRow());
assertEquals(1, link2.getFirstColumn());
-
}
/*tests the toString() method of HSSFCell*/
- public void testToString() throws Exception {
+ public void testToString() {
HSSFWorkbook wb = new HSSFWorkbook();
- HSSFSheet s = wb.createSheet("Sheet1");
- HSSFRow r = s.createRow(0);
- HSSFCell c;
- c=r.createCell((short) 0); c.setCellValue(true);
- assertEquals("Boolean", "TRUE", c.toString());
- c=r.createCell((short) 1); c.setCellValue(1.5);
- assertEquals("Numeric", "1.5", c.toString());
- c=r.createCell((short)(2)); c.setCellValue(new HSSFRichTextString("Astring"));
- assertEquals("String", "Astring", c.toString());
- c=r.createCell((short) 3); c.setCellErrorValue((byte) 7);
- assertEquals("Error", "#ERR7", c.toString());
- c=r.createCell((short)4); c.setCellFormula("A1+B1");
- assertEquals("Formula", "A1+B1", c.toString());
-
+ HSSFRow r = wb.createSheet("Sheet1").createRow(0);
+
+ r.createCell(0).setCellValue(true);
+ r.createCell(1).setCellValue(1.5);
+ r.createCell(2).setCellValue(new HSSFRichTextString("Astring"));
+ r.createCell(3).setCellErrorValue((byte)HSSFErrorConstants.ERROR_DIV_0);
+ r.createCell(4).setCellFormula("A1+B1");
+
+ assertEquals("Boolean", "TRUE", r.getCell(0).toString());
+ assertEquals("Numeric", "1.5", r.getCell(1).toString());
+ assertEquals("String", "Astring", r.getCell(2).toString());
+ assertEquals("Error", "#DIV/0!", r.getCell(3).toString());
+ assertEquals("Formula", "A1+B1", r.getCell(4).toString());
+
//Write out the file, read it in, and then check cell values
- File f = File.createTempFile("testCellToString",".xls");
- wb.write(new FileOutputStream(f));
- wb = new HSSFWorkbook(new FileInputStream(f));
- assertTrue("File exists and can be read", f.canRead());
-
- s = wb.getSheetAt(0);r=s.getRow(0);
- c=r.getCell((short) 0);
- assertEquals("Boolean", "TRUE", c.toString());
- c=r.getCell((short) 1);
- assertEquals("Numeric", "1.5", c.toString());
- c=r.getCell((short)(2));
- assertEquals("String", "Astring", c.toString());
- c=r.getCell((short) 3);
- assertEquals("Error", "#ERR7", c.toString());
- c=r.getCell((short)4);
- assertEquals("Formula", "A1+B1", c.toString());
+ wb = writeOutAndReadBack(wb);
+
+ r = wb.getSheetAt(0).getRow(0);
+ assertEquals("Boolean", "TRUE", r.getCell(0).toString());
+ assertEquals("Numeric", "1.5", r.getCell(1).toString());
+ assertEquals("String", "Astring", r.getCell(2).toString());
+ assertEquals("Error", "#DIV/0!", r.getCell(3).toString());
+ assertEquals("Formula", "A1+B1", r.getCell(4).toString());
}
public void testSetStringInFormulaCell_bug44606() {
HSSFWorkbook wb = new HSSFWorkbook();
- HSSFCell cell = wb.createSheet("Sheet1").createRow(0).createCell((short)0);
+ HSSFCell cell = wb.createSheet("Sheet1").createRow(0).createCell(0);
cell.setCellFormula("B1&C1");
try {
cell.setCellValue(new HSSFRichTextString("hello"));
@@ -404,8 +367,8 @@ public final class TestHSSFCell extends TestCase {
fail();
} catch(IllegalArgumentException e) {}
- HSSFCell cellA = wbA.createSheet().createRow(0).createCell((short)0);
- HSSFCell cellB = wbB.createSheet().createRow(0).createCell((short)0);
+ HSSFCell cellA = wbA.createSheet().createRow(0).createCell(0);
+ HSSFCell cellB = wbB.createSheet().createRow(0).createCell(0);
cellA.setCellStyle(styA);
cellB.setCellStyle(styB);
@@ -418,9 +381,5 @@ public final class TestHSSFCell extends TestCase {
fail();
} catch(IllegalArgumentException e) {}
}
-
- public static void main(String [] args) {
- junit.textui.TestRunner.run(TestHSSFCell.class);
- }
}
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFDataFormatter.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFDataFormatter.java
index e24f30da61..f1be47fd1b 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFDataFormatter.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFDataFormatter.java
@@ -19,7 +19,6 @@ package org.apache.poi.hssf.usermodel;
import java.text.DecimalFormat;
import java.text.Format;
-import java.util.Date;
import java.util.Iterator;
import junit.framework.TestCase;
@@ -96,7 +95,7 @@ public final class TestHSSFDataFormatter extends TestCase {
// create cells with good date patterns
for (int i = 0; i < goodDatePatterns.length; i++) {
- HSSFCell cell = row.createCell((short) i);
+ HSSFCell cell = row.createCell(i);
cell.setCellValue(dateNum);
HSSFCellStyle cellStyle = wb.createCellStyle();
cellStyle.setDataFormat(format.getFormat(goodDatePatterns[i]));
@@ -106,7 +105,7 @@ public final class TestHSSFDataFormatter extends TestCase {
// create cells with num patterns
for (int i = 0; i < goodNumPatterns.length; i++) {
- HSSFCell cell = row.createCell((short) i);
+ HSSFCell cell = row.createCell(i);
cell.setCellValue(-1234567890.12345);
HSSFCellStyle cellStyle = wb.createCellStyle();
cellStyle.setDataFormat(format.getFormat(goodNumPatterns[i]));
@@ -116,7 +115,7 @@ public final class TestHSSFDataFormatter extends TestCase {
// create cells with bad num patterns
for (int i = 0; i < badNumPatterns.length; i++) {
- HSSFCell cell = row.createCell((short) i);
+ HSSFCell cell = row.createCell(i);
cell.setCellValue(1234567890.12345);
HSSFCellStyle cellStyle = wb.createCellStyle();
cellStyle.setDataFormat(format.getFormat(badNumPatterns[i]));
@@ -127,7 +126,7 @@ public final class TestHSSFDataFormatter extends TestCase {
{ // Zip + 4 format
row = sheet.createRow(3);
- HSSFCell cell = row.createCell((short) 0);
+ HSSFCell cell = row.createCell(0);
cell.setCellValue(123456789);
HSSFCellStyle cellStyle = wb.createCellStyle();
cellStyle.setDataFormat(format.getFormat("00000-0000"));
@@ -136,7 +135,7 @@ public final class TestHSSFDataFormatter extends TestCase {
{ // Phone number format
row = sheet.createRow(4);
- HSSFCell cell = row.createCell((short) 0);
+ HSSFCell cell = row.createCell(0);
cell.setCellValue(5551234567D);
HSSFCellStyle cellStyle = wb.createCellStyle();
cellStyle.setDataFormat(format.getFormat("[<=9999999]###-####;(###) ###-####"));
@@ -145,7 +144,7 @@ public final class TestHSSFDataFormatter extends TestCase {
{ // SSN format
row = sheet.createRow(5);
- HSSFCell cell = row.createCell((short) 0);
+ HSSFCell cell = row.createCell(0);
cell.setCellValue(444551234);
HSSFCellStyle cellStyle = wb.createCellStyle();
cellStyle.setDataFormat(format.getFormat("000-00-0000"));
@@ -154,7 +153,7 @@ public final class TestHSSFDataFormatter extends TestCase {
{ // formula cell
row = sheet.createRow(6);
- HSSFCell cell = row.createCell((short) 0);
+ HSSFCell cell = row.createCell(0);
cell.setCellType(HSSFCell.CELL_TYPE_FORMULA);
cell.setCellFormula("SUM(12.25,12.25)/100");
HSSFCellStyle cellStyle = wb.createCellStyle();
@@ -231,7 +230,6 @@ public final class TestHSSFDataFormatter extends TestCase {
// null test-- null cell should result in empty String
assertEquals(formatter.formatCellValue(null), "");
-
}
public void testGetFormattedCellValueHSSFCellHSSFFormulaEvaluator() {
@@ -246,14 +244,10 @@ public final class TestHSSFDataFormatter extends TestCase {
// now with a formula evaluator
HSSFFormulaEvaluator evaluator = new HSSFFormulaEvaluator(wb.getSheetAt(0), wb);
- //! must set current row !
- evaluator.setCurrentRow(row);
log(formatter.formatCellValue(cell, evaluator) + "\t\t\t (with evaluator)");
assertEquals("24.50%", formatter.formatCellValue(cell,evaluator));
}
-
-
/**
* Test using a default number format. The format should be used when a
* format pattern cannot be parsed by DecimalFormat.