]> source.dussan.org Git - poi.git/commitdiff
bug 60219: add disabled unit test for parsing formulas containing external workbook...
authorJaven O'Neal <onealj@apache.org>
Sat, 8 Oct 2016 23:41:08 +0000 (23:41 +0000)
committerJaven O'Neal <onealj@apache.org>
Sat, 8 Oct 2016 23:41:08 +0000 (23:41 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1763937 13f79535-47bb-0310-9956-ffa450edef68

src/ooxml/testcases/org/apache/poi/ss/formula/TestFormulaParser.java

index 9f40ca363a4852b77280f1536189c3385633d023..dfbbd4281cda522e6e78c4f749dfe65b1bf03669 100644 (file)
@@ -28,11 +28,12 @@ import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 import org.apache.poi.ss.formula.ptg.AbstractFunctionPtg;
 import org.apache.poi.ss.formula.ptg.NameXPxg;
 import org.apache.poi.ss.formula.ptg.Ptg;
+import org.apache.poi.ss.formula.ptg.Ref3DPxg;
 import org.apache.poi.ss.formula.ptg.StringPtg;
 import org.apache.poi.xssf.XSSFTestDataSamples;
 import org.apache.poi.xssf.usermodel.XSSFEvaluationWorkbook;
 import org.apache.poi.xssf.usermodel.XSSFWorkbook;
-
+import org.junit.Ignore;
 import org.junit.Test;
 
 /**
@@ -169,4 +170,39 @@ public class TestFormulaParser {
             assertNotNull(e.getMessage());
         }
     }
+    
+    // trivial case for bug 60219: FormulaParser can't parse external references when sheet name is quoted
+    @Test
+    public void testParseExternalReferencesWithUnquotedSheetName() throws Exception {
+        XSSFWorkbook wb = new XSSFWorkbook();
+        XSSFEvaluationWorkbook fpwb = XSSFEvaluationWorkbook.create(wb);
+        Ptg[] ptgs = FormulaParser.parse("[1]Sheet1!A1", fpwb, FormulaType.CELL, -1);
+        // org.apache.poi.ss.formula.ptg.Ref3DPxg [ [workbook=1] sheet=Sheet 1 ! A1]
+        assertEquals("Ptgs length", 1, ptgs.length);
+        assertTrue("Ptg class", ptgs[0] instanceof Ref3DPxg);
+        Ref3DPxg pxg = (Ref3DPxg) ptgs[0];
+        assertEquals("External workbook number", 1, pxg.getExternalWorkbookNumber());
+        assertEquals("Sheet name", "Sheet1", pxg.getSheetName());
+        assertEquals("Row", 0, pxg.getRow());
+        assertEquals("Column", 0, pxg.getColumn());
+        wb.close();
+    }
+    
+    // bug 60219: FormulaParser can't parse external references when sheet name is quoted
+    @Ignore
+    @Test
+    public void testParseExternalReferencesWithQuotedSheetName() throws Exception {
+        XSSFWorkbook wb = new XSSFWorkbook();
+        XSSFEvaluationWorkbook fpwb = XSSFEvaluationWorkbook.create(wb);
+        Ptg[] ptgs = FormulaParser.parse("'[1]Sheet 1'!A1", fpwb, FormulaType.CELL, -1);
+        // org.apache.poi.ss.formula.ptg.Ref3DPxg [ [workbook=1] sheet=Sheet 1 ! A1]
+        assertEquals("Ptgs length", 1, ptgs.length);
+        assertTrue("Ptg class", ptgs[0] instanceof Ref3DPxg);
+        Ref3DPxg pxg = (Ref3DPxg) ptgs[0];
+        assertEquals("External workbook number", 1, pxg.getExternalWorkbookNumber());
+        assertEquals("Sheet name", "Sheet 1", pxg.getSheetName());
+        assertEquals("Row", 0, pxg.getRow());
+        assertEquals("Column", 0, pxg.getColumn());
+        wb.close();
+    }
 }