]> source.dussan.org Git - poi.git/commitdiff
Continue with 55747 / 55324 testing
authorNick Burch <nick@apache.org>
Wed, 12 Aug 2015 19:46:54 +0000 (19:46 +0000)
committerNick Burch <nick@apache.org>
Wed, 12 Aug 2015 19:46:54 +0000 (19:46 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1695603 13f79535-47bb-0310-9956-ffa450edef68

src/testcases/org/apache/poi/hssf/usermodel/TestFormulaEvaluatorBugs.java

index 17334a077b90e0b67cb2a80f09ef3dc61ee4f4a8..b3b25f5c9faa22fcd80c35a0c60ae1c0c1adec0b 100644 (file)
@@ -417,7 +417,8 @@ public final class TestFormulaEvaluatorBugs extends TestCase {
                assertEquals(ErrorEval.NA, ve);
        }
 
-       public void test55747_55324() throws Exception {
+       @SuppressWarnings("resource")
+    public void test55747_55324() throws Exception {
            HSSFWorkbook wb = new HSSFWorkbook();
         HSSFFormulaEvaluator ev = wb.getCreationHelper().createFormulaEvaluator();
         HSSFSheet ws = wb.createSheet();
@@ -464,7 +465,12 @@ public final class TestFormulaEvaluatorBugs extends TestCase {
         // Evaluate
         ev.evaluateAll();
         
-        // Check the MID Ptgs have V RefPtgs for A1
+        // Save and re-load
+        wb = HSSFTestDataSamples.writeOutAndReadBack(wb);
+        ws = wb.getSheetAt(0);
+        
+        // Check the MID Ptgs in Row 2 have V RefPtgs for A1
+        row = ws.getRow(1);
         for (int i=1; i<=4; i++) {
             cell = row.getCell(i);
             Ptg[] ptgs = getPtgs(cell);
@@ -479,33 +485,55 @@ public final class TestFormulaEvaluatorBugs extends TestCase {
         
         // H1, MID is used in the expression IF checks, so A1 should be V
         cell = row.getCell(CellReference.convertColStringToIndex("H"));
+        assertRefPtgA1('V', getPtgs(cell), 0);
         
-        // E1, MID is used in the FALSE route, so A1 should be V
+        // E1, MID is used in the FALSE route, so:
+        //  A1 should be V in the IF check
+        //  A1 should be R in the FALSE route
+        cell = row.getCell(CellReference.convertColStringToIndex("E"));
+        assertRefPtgA1('V', getPtgs(cell), 0);
+        assertRefPtgA1('R', getPtgs(cell), 6);
         
-        // 
+        // Check that, for B1, D1, F1 and G1, the references to A1
+        //  from all of IF check, True and False are V
+        cell = row.getCell(CellReference.convertColStringToIndex("B"));
+        assertRefPtgA1('V', getPtgs(cell), 0);
+//      assertRefPtgA1('V', getPtgs(cell), 4); // FIXME!
         
-        // Check that, for E1 and H1, the A1 in the IF is a V, but in the
-        //  True -> MID is an R
-        for (int cn : new int[] { 4, 7 }) {
-            cell = row.getCell(cn);
-            
-            FormulaRecordAggregate agg = (FormulaRecordAggregate)cell.getCellValueRecord();
-            FormulaRecord rec = agg.getFormulaRecord();
-            
-            // 1st is the 
-            assertEquals(RefPtg.class, rec.getParsedExpression()[0].getClass());
-            assertEquals('V', ((RefPtg)rec.getParsedExpression()[0]).getRVAType());
-            assertEquals(0,   ((RefPtg)rec.getParsedExpression()[0]).getRow());
-            assertEquals(0,   ((RefPtg)rec.getParsedExpression()[0]).getColumn());
-        }
+        cell = row.getCell(CellReference.convertColStringToIndex("D"));
+        assertRefPtgA1('V', getPtgs(cell), 0);
+//      assertRefPtgA1('V', getPtgs(cell), 6); // FIXME!
+        
+        cell = row.getCell(CellReference.convertColStringToIndex("F"));
+        assertRefPtgA1('V', getPtgs(cell), 0);
+//      assertRefPtgA1('V', getPtgs(cell), 4); // FIXME!
+//      assertRefPtgA1('V', getPtgs(cell), 9); // FIXME!
         
-        // Check that, for B1, D1, F1 and G1 
+        cell = row.getCell(CellReference.convertColStringToIndex("G"));
+        assertRefPtgA1('V', getPtgs(cell), 0);
+//      assertRefPtgA1('V', getPtgs(cell), 4); // FIXME!
+//      assertRefPtgA1('V', getPtgs(cell), 9); // FIXME!
         
-        // Check our values
-        // TODO
         
-        // Check our PTGs
-        // TODO
+        // Check our cached values were correctly evaluated
+        cell = row.getCell(CellReference.convertColStringToIndex("A"));
+        assertEquals("abc", cell.getStringCellValue());
+        cell = row.getCell(CellReference.convertColStringToIndex("B"));
+        assertEquals("ab", cell.getStringCellValue());
+        cell = row.getCell(CellReference.convertColStringToIndex("C"));
+        assertEquals("A", cell.getStringCellValue());
+        cell = row.getCell(CellReference.convertColStringToIndex("D"));
+        assertEquals("ab", cell.getStringCellValue());
+        cell = row.getCell(CellReference.convertColStringToIndex("E"));
+        assertEquals("X", cell.getStringCellValue());
+        cell = row.getCell(CellReference.convertColStringToIndex("F"));
+        assertEquals("bc", cell.getStringCellValue());
+        cell = row.getCell(CellReference.convertColStringToIndex("G"));
+        assertEquals("ab", cell.getStringCellValue());
+        cell = row.getCell(CellReference.convertColStringToIndex("H"));
+        assertEquals("A", cell.getStringCellValue());
+
+        // Enable this block to write out, and check in Excel
 //FileOutputStream out = new FileOutputStream("/tmp/test.xls");
 //wb.write(out);
 //out.close();
@@ -520,8 +548,8 @@ public final class TestFormulaEvaluatorBugs extends TestCase {
        private void assertRefPtgA1(char rv, Ptg[] ptgs, int at) {
            Ptg ptg = ptgs[at];
         assertEquals(RefPtg.class, ptg.getClass());
-        assertEquals(0,   ((RefPtg)ptg).getRow());
-        assertEquals(0,   ((RefPtg)ptg).getColumn());
-        assertEquals('V', ((RefPtg)ptg).getRVAType());
+        assertEquals(0,  ((RefPtg)ptg).getRow());
+        assertEquals(0,  ((RefPtg)ptg).getColumn());
+        assertEquals(rv, ((RefPtg)ptg).getRVAType());
        }
 }