aboutsummaryrefslogtreecommitdiffstats
path: root/src/testcases/org/apache/poi/hssf/usermodel/TestBug43093.java
blob: ce072e9e014e9ebcb00d2c1367739fdcc78dfa07 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/* ====================================================================
   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 junit.framework.TestCase;

public 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++) {
			
			HSSFRow   row = sht.createRow (r);
			for (short c=0; c < 4; c++) {
			
				HSSFCell cel = row.createCell(c);
				/**/     cel.setCellValue(sheet*100 + r*10 + c);
			}
		}
	}

	public void testBug43093() throws Exception {
			HSSFWorkbook     xlw    = new HSSFWorkbook();

			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)");

			HSSFFormulaEvaluator eva = new HSSFFormulaEvaluator(s2, xlw);
			eva.setCurrentRow(s2r3);
			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);
	}
}