]> source.dussan.org Git - poi.git/commitdiff
Add disabled unit tests for bug #56737, which currently fails (differently) for HSSF...
authorNick Burch <nick@apache.org>
Thu, 17 Jul 2014 16:18:39 +0000 (16:18 +0000)
committerNick Burch <nick@apache.org>
Thu, 17 Jul 2014 16:18:39 +0000 (16:18 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1611400 13f79535-47bb-0310-9956-ffa450edef68

src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java
src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java
test-data/spreadsheet/56737.xls [new file with mode: 0644]
test-data/spreadsheet/56737.xlsx [new file with mode: 0644]

index 93d906f5e300de2431f2176e346e329e1ab74c21..423220c66eb448e44a3182b1b58ddbc3599c5e5a 100644 (file)
@@ -1653,6 +1653,45 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
         assertEquals("0", formatter.formatCellValue(cell));
     }
     
+    /**
+     * Formulas which reference named ranges, either in other
+     *  sheets, or workbook scoped but in other workbooks.
+     * Currently failing with errors like
+     * org.apache.poi.ss.formula.FormulaParseException: Cell reference expected after sheet name at index 9
+     * org.apache.poi.ss.formula.FormulaParseException: Parse error near char 0 '[' in specified formula '[0]!NR_Global_B2'. Expected number, string, or defined name 
+     */
+    @Ignore
+    @Test
+    public void bug56737() throws IOException {
+        Workbook wb = XSSFTestDataSamples.openSampleWorkbook("56737.xlsx");
+        
+        // Check the named range definitions
+        Name nSheetScope = wb.getName("NR_To_A1");
+        Name nWBScope = wb.getName("NR_Global_B2");
+
+        assertNotNull(nSheetScope);
+        assertNotNull(nWBScope);
+        
+        assertEquals("Defines!$A$1", nSheetScope.getRefersToFormula());
+        assertEquals("Defines!$B$2", nWBScope.getRefersToFormula());
+        
+        // Check the different kinds of formulas
+        Sheet s = wb.getSheetAt(0);
+        Cell cRefSName = s.getRow(1).getCell(3);
+        Cell cRefWName = s.getRow(2).getCell(3);
+        
+        assertEquals("Defines!NR_To_A1", cRefSName.getCellFormula());
+        assertEquals("[0]!NR_Global_B2", cRefWName.getCellFormula());
+        
+        // Try to evaluate them
+        FormulaEvaluator eval = wb.getCreationHelper().createFormulaEvaluator();
+        assertEquals("Test A1", eval.evaluate(cRefSName).getStringValue());
+        assertEquals(142, (int)eval.evaluate(cRefWName).getNumberValue());
+        
+        // Try to evaluate everything
+        eval.evaluateAll();
+    }
+
     private void saveAndReloadReport(Workbook wb, File outFile) throws IOException {
         // run some method on the font to verify if it is "disconnected" already
         //for(short i = 0;i < 256;i++)
index 141a8e448330b2e88d1a3ab16748cc5460ae35e2..5d03b45d3f8a1489fbb3f7591bc197fdc62ab836 100644 (file)
@@ -67,6 +67,7 @@ import org.apache.poi.ss.usermodel.Cell;
 import org.apache.poi.ss.usermodel.CellStyle;
 import org.apache.poi.ss.usermodel.DataFormat;
 import org.apache.poi.ss.usermodel.DataFormatter;
+import org.apache.poi.ss.usermodel.FormulaEvaluator;
 import org.apache.poi.ss.usermodel.Name;
 import org.apache.poi.ss.usermodel.Row;
 import org.apache.poi.ss.usermodel.Sheet;
@@ -2611,4 +2612,42 @@ public final class TestBugs extends BaseTestBugzillaIssues {
         wb = HSSFTestDataSamples.writeOutAndReadBack(wb);
         assertEquals(0, wb.getNumberOfSheets());
     }
+    
+    /**
+     * Formulas which reference named ranges, either in other
+     *  sheets, or workbook scoped but in other workbooks.
+     * Currently failing with 
+     * java.lang.RuntimeException: Unexpected eval class (org.apache.poi.ss.formula.eval.NameXEval)
+     */
+    @Ignore
+    @Test
+    public void bug56737() throws IOException {
+        Workbook wb = openSample("56737.xls");
+        
+        // Check the named range definitions
+        Name nSheetScope = wb.getName("NR_To_A1");
+        Name nWBScope = wb.getName("NR_Global_B2");
+
+        assertNotNull(nSheetScope);
+        assertNotNull(nWBScope);
+        
+        assertEquals("Defines!$A$1", nSheetScope.getRefersToFormula());
+        assertEquals("Defines!$B$2", nWBScope.getRefersToFormula());
+        
+        // Check the different kinds of formulas
+        Sheet s = wb.getSheetAt(0);
+        Cell cRefSName = s.getRow(1).getCell(3);
+        Cell cRefWName = s.getRow(2).getCell(3);
+        
+        assertEquals("Defines!NR_To_A1", cRefSName.getCellFormula());
+        assertEquals("'56737.xls'!NR_Global_B2", cRefWName.getCellFormula());
+        
+        // Try to evaluate them
+        FormulaEvaluator eval = wb.getCreationHelper().createFormulaEvaluator();
+        assertEquals("Test A1", eval.evaluate(cRefSName).getStringValue());
+        assertEquals(142, (int)eval.evaluate(cRefWName).getNumberValue());
+        
+        // Try to evaluate everything
+        eval.evaluateAll();
+    }
 }
diff --git a/test-data/spreadsheet/56737.xls b/test-data/spreadsheet/56737.xls
new file mode 100644 (file)
index 0000000..59ab233
Binary files /dev/null and b/test-data/spreadsheet/56737.xls differ
diff --git a/test-data/spreadsheet/56737.xlsx b/test-data/spreadsheet/56737.xlsx
new file mode 100644 (file)
index 0000000..3783483
Binary files /dev/null and b/test-data/spreadsheet/56737.xlsx differ