Update docs now that missing record aware eventusermodel has moved
[poi.git] / src / scratchpad / testcases / org / apache / poi / hssf / usermodel / TestBug44297.java
blobce4afd36f6f109ed1480c1bd646218422e25df62
1 package org.apache.poi.hssf.usermodel;
2 /* ====================================================================
3 Licensed to the Apache Software Foundation (ASF) under one or more
4 contributor license agreements. See the NOTICE file distributed with
5 this work for additional information regarding copyright ownership.
6 The ASF licenses this file to You under the Apache License, Version 2.0
7 (the "License"); you may not use this file except in compliance with
8 the License. You may obtain a copy of the License at
10 http://www.apache.org/licenses/LICENSE-2.0
12 Unless required by applicable law or agreed to in writing, software
13 distributed under the License is distributed on an "AS IS" BASIS,
14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 See the License for the specific language governing permissions and
16 limitations under the License.
17 ==================================================================== */
19 import junit.framework.TestCase;
21 import java.io.IOException;
22 import java.io.FileInputStream;
23 import java.io.File;
25 /**
26 * Bug 44297: 32767+32768 is evaluated to -1
27 * Fix: IntPtg must operate with unsigned short. Reading signed short results in incorrect formula calculation
28 * if a formula has values in the interval [Short.MAX_VALUE, (Short.MAX_VALUE+1)*2]
30 * @author Yegor Kozlov
33 public class TestBug44297 extends TestCase {
34 protected String cwd = System.getProperty("HSSF.testdata.path");
36 public void test44297() throws IOException {
37 FileInputStream in = new FileInputStream(new File(cwd, "44297.xls"));
38 HSSFWorkbook wb = new HSSFWorkbook(in);
39 in.close();
41 HSSFRow row;
42 HSSFCell cell;
44 HSSFSheet sheet = wb.getSheetAt(0);
46 HSSFFormulaEvaluator eva = new HSSFFormulaEvaluator(sheet, wb);
48 row = (HSSFRow)sheet.getRow(0);
49 cell = row.getCell((short)0);
50 assertEquals("31+46", cell.getCellFormula());
51 eva.setCurrentRow(row);
52 assertEquals(77, eva.evaluate(cell).getNumberValue(), 0);
54 row = (HSSFRow)sheet.getRow(1);
55 cell = row.getCell((short)0);
56 assertEquals("30+53", cell.getCellFormula());
57 eva.setCurrentRow(row);
58 assertEquals(83, eva.evaluate(cell).getNumberValue(), 0);
60 row = (HSSFRow)sheet.getRow(2);
61 cell = row.getCell((short)0);
62 assertEquals("SUM(A1:A2)", cell.getCellFormula());
63 eva.setCurrentRow(row);
64 assertEquals(160, eva.evaluate(cell).getNumberValue(), 0);
66 row = (HSSFRow)sheet.getRow(4);
67 cell = row.getCell((short)0);
68 assertEquals("32767+32768", cell.getCellFormula());
69 eva.setCurrentRow(row);
70 assertEquals(65535, eva.evaluate(cell).getNumberValue(), 0);
72 row = (HSSFRow)sheet.getRow(7);
73 cell = row.getCell((short)0);
74 assertEquals("32744+42333", cell.getCellFormula());
75 eva.setCurrentRow(row);
76 assertEquals(75077, eva.evaluate(cell).getNumberValue(), 0);
78 row = (HSSFRow)sheet.getRow(8);
79 cell = row.getCell((short)0);
80 assertEquals("327680.0/32768", cell.getCellFormula());
81 eva.setCurrentRow(row);
82 assertEquals(10, eva.evaluate(cell).getNumberValue(), 0);
84 row = (HSSFRow)sheet.getRow(9);
85 cell = row.getCell((short)0);
86 assertEquals("32767+32769", cell.getCellFormula());
87 eva.setCurrentRow(row);
88 assertEquals(65536, eva.evaluate(cell).getNumberValue(), 0);
90 row = (HSSFRow)sheet.getRow(10);
91 cell = row.getCell((short)0);
92 assertEquals("35000+36000", cell.getCellFormula());
93 eva.setCurrentRow(row);
94 assertEquals(71000, eva.evaluate(cell).getNumberValue(), 0);
96 row = (HSSFRow)sheet.getRow(11);
97 cell = row.getCell((short)0);
98 assertEquals("-1000000.0-3000000.0", cell.getCellFormula());
99 eva.setCurrentRow(row);
100 assertEquals(-4000000, eva.evaluate(cell).getNumberValue(), 0);