[Libreoffice-commits] core.git: Branch 'feature/inherited-number-format-removal' - 2 commits - sc/inc sc/qa sc/source

Markus Mohrhard markus.mohrhard at googlemail.com
Sat May 25 05:51:49 PDT 2013


 sc/inc/formulacell.hxx              |    5 
 sc/qa/unit/ucalc.cxx                |  342 +++++++++++++++++++++---------------
 sc/source/core/data/column2.cxx     |    5 
 sc/source/core/data/formulacell.cxx |   21 --
 sc/source/core/tool/cellform.cxx    |    4 
 sc/source/core/tool/interpr4.cxx    |    2 
 sc/source/ui/unoobj/chart2uno.cxx   |   12 -
 7 files changed, 211 insertions(+), 180 deletions(-)

New commits:
commit 48c0d09e8218f00ec038c94dea635ee1bcc67c47
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date:   Sat May 25 14:45:53 2013 +0200

    let us use clean test environments
    
    The additional typing and the duplicated code benefit cleaner test
    execution. Test failures might be hidden by a dirty test environment or
    random test failures might be produced by it.
    
    Change-Id: I97283009b65facbaad82e41ae6f1258430684438

diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx
index 091872f..d1ca50d 100644
--- a/sc/qa/unit/ucalc.cxx
+++ b/sc/qa/unit/ucalc.cxx
@@ -101,7 +101,17 @@ public:
     void testRangeList();
     void testInput();
     void testFormulaHashAndTag();
-    void testCellFunctions();
+    void testFuncSUM();
+    void testFuncPRODUCT();
+    void testFuncN();
+    void testFuncCOUNTIF();
+    void testFuncNUMBERVALUE();
+    void testFuncVLOOKUP();
+    void testFuncMATCH();
+    void testFuncCELL();
+    void testFuncDATEDIF();
+    void testFuncINDIRECT();
+    void testFuncIFERROR();
     void testCopyToDocument();
     /**
      * Make sure the SHEETS function gets properly updated during sheet
@@ -261,7 +271,17 @@ public:
     CPPUNIT_TEST(testRangeList);
     CPPUNIT_TEST(testInput);
     CPPUNIT_TEST(testFormulaHashAndTag);
-    CPPUNIT_TEST(testCellFunctions);
+    CPPUNIT_TEST(testFuncSUM);
+    CPPUNIT_TEST(testFuncPRODUCT);
+    CPPUNIT_TEST(testFuncN);
+    CPPUNIT_TEST(testFuncCOUNTIF);
+    CPPUNIT_TEST(testFuncNUMBERVALUE);
+    CPPUNIT_TEST(testFuncVLOOKUP);
+    CPPUNIT_TEST(testFuncMATCH);
+    CPPUNIT_TEST(testFuncCELL);
+    CPPUNIT_TEST(testFuncDATEDIF);
+    CPPUNIT_TEST(testFuncINDIRECT);
+    CPPUNIT_TEST(testFuncIFERROR);
     CPPUNIT_TEST(testCopyToDocument);
     CPPUNIT_TEST(testSheetsFunc);
     CPPUNIT_TEST(testVolatileFunc);
@@ -493,90 +513,106 @@ void Test::testInput()
     m_pDoc->DeleteTab(0);
 }
 
-void testFuncSUM(ScDocument* pDoc)
+void Test::testFuncSUM()
 {
+    OUString aTabName("foo");
+    CPPUNIT_ASSERT_MESSAGE ("failed to insert sheet",
+                            m_pDoc->InsertTab (0, aTabName));
+
     double val = 1;
     double result;
-    pDoc->SetValue (0, 0, 0, val);
-    pDoc->SetValue (0, 1, 0, val);
-    pDoc->SetString (0, 2, 0, OUString("=SUM(A1:A2)"));
-    pDoc->CalcAll();
-    pDoc->GetValue (0, 2, 0, result);
+    m_pDoc->SetValue (0, 0, 0, val);
+    m_pDoc->SetValue (0, 1, 0, val);
+    m_pDoc->SetString (0, 2, 0, OUString("=SUM(A1:A2)"));
+    m_pDoc->CalcAll();
+    m_pDoc->GetValue (0, 2, 0, result);
     CPPUNIT_ASSERT_MESSAGE ("calculation failed", result == 2.0);
+
+    m_pDoc->DeleteTab(0);
 }
 
-void testFuncPRODUCT(ScDocument* pDoc)
+void Test::testFuncPRODUCT()
 {
+    OUString aTabName("foo");
+    CPPUNIT_ASSERT_MESSAGE ("failed to insert sheet",
+                            m_pDoc->InsertTab (0, aTabName));
+
     double val = 1;
     double result;
-    pDoc->SetValue(0, 0, 0, val);
+    m_pDoc->SetValue(0, 0, 0, val);
     val = 2;
-    pDoc->SetValue(0, 1, 0, val);
+    m_pDoc->SetValue(0, 1, 0, val);
     val = 3;
-    pDoc->SetValue(0, 2, 0, val);
-    pDoc->SetString(0, 3, 0, OUString("=PRODUCT(A1:A3)"));
-    pDoc->CalcAll();
-    pDoc->GetValue(0, 3, 0, result);
+    m_pDoc->SetValue(0, 2, 0, val);
+    m_pDoc->SetString(0, 3, 0, OUString("=PRODUCT(A1:A3)"));
+    m_pDoc->CalcAll();
+    m_pDoc->GetValue(0, 3, 0, result);
     CPPUNIT_ASSERT_MESSAGE("Calculation of PRODUCT failed", result == 6.0);
 
-    pDoc->SetString(0, 4, 0, OUString("=PRODUCT({1;2;3})"));
-    pDoc->CalcAll();
-    pDoc->GetValue(0, 4, 0, result);
+    m_pDoc->SetString(0, 4, 0, OUString("=PRODUCT({1;2;3})"));
+    m_pDoc->CalcAll();
+    m_pDoc->GetValue(0, 4, 0, result);
     CPPUNIT_ASSERT_MESSAGE("Calculation of PRODUCT with inline array failed", result == 6.0);
+
+    m_pDoc->DeleteTab(0);
 }
 
-void testFuncN(ScDocument* pDoc)
+void Test::testFuncN()
 {
+    OUString aTabName("foo");
+    CPPUNIT_ASSERT_MESSAGE ("failed to insert sheet",
+                            m_pDoc->InsertTab (0, aTabName));
+
     double result;
 
     // Clear the area first.
-    clearRange(pDoc, ScRange(0, 0, 0, 1, 20, 0));
+    clearRange(m_pDoc, ScRange(0, 0, 0, 1, 20, 0));
 
     // Put values to reference.
     double val = 0;
-    pDoc->SetValue(0, 0, 0, val);
-    pDoc->SetString(0, 2, 0, OUString("Text"));
+    m_pDoc->SetValue(0, 0, 0, val);
+    m_pDoc->SetString(0, 2, 0, OUString("Text"));
     val = 1;
-    pDoc->SetValue(0, 3, 0, val);
+    m_pDoc->SetValue(0, 3, 0, val);
     val = -1;
-    pDoc->SetValue(0, 4, 0, val);
+    m_pDoc->SetValue(0, 4, 0, val);
     val = 12.3;
-    pDoc->SetValue(0, 5, 0, val);
-    pDoc->SetString(0, 6, 0, OUString("'12.3"));
+    m_pDoc->SetValue(0, 5, 0, val);
+    m_pDoc->SetString(0, 6, 0, OUString("'12.3"));
 
     // Cell references
-    pDoc->SetString(1, 0, 0, OUString("=N(A1)"));
-    pDoc->SetString(1, 1, 0, OUString("=N(A2)"));
-    pDoc->SetString(1, 2, 0, OUString("=N(A3)"));
-    pDoc->SetString(1, 3, 0, OUString("=N(A4)"));
-    pDoc->SetString(1, 4, 0, OUString("=N(A5)"));
-    pDoc->SetString(1, 5, 0, OUString("=N(A6)"));
-    pDoc->SetString(1, 6, 0, OUString("=N(A9)"));
+    m_pDoc->SetString(1, 0, 0, OUString("=N(A1)"));
+    m_pDoc->SetString(1, 1, 0, OUString("=N(A2)"));
+    m_pDoc->SetString(1, 2, 0, OUString("=N(A3)"));
+    m_pDoc->SetString(1, 3, 0, OUString("=N(A4)"));
+    m_pDoc->SetString(1, 4, 0, OUString("=N(A5)"));
+    m_pDoc->SetString(1, 5, 0, OUString("=N(A6)"));
+    m_pDoc->SetString(1, 6, 0, OUString("=N(A9)"));
 
     // In-line values
-    pDoc->SetString(1, 7, 0, OUString("=N(0)"));
-    pDoc->SetString(1, 8, 0, OUString("=N(1)"));
-    pDoc->SetString(1, 9, 0, OUString("=N(-1)"));
-    pDoc->SetString(1, 10, 0, OUString("=N(123)"));
-    pDoc->SetString(1, 11, 0, OUString("=N(\"\")"));
-    pDoc->SetString(1, 12, 0, OUString("=N(\"12\")"));
-    pDoc->SetString(1, 13, 0, OUString("=N(\"foo\")"));
+    m_pDoc->SetString(1, 7, 0, OUString("=N(0)"));
+    m_pDoc->SetString(1, 8, 0, OUString("=N(1)"));
+    m_pDoc->SetString(1, 9, 0, OUString("=N(-1)"));
+    m_pDoc->SetString(1, 10, 0, OUString("=N(123)"));
+    m_pDoc->SetString(1, 11, 0, OUString("=N(\"\")"));
+    m_pDoc->SetString(1, 12, 0, OUString("=N(\"12\")"));
+    m_pDoc->SetString(1, 13, 0, OUString("=N(\"foo\")"));
 
     // Range references
-    pDoc->SetString(2, 2, 0, OUString("=N(A1:A8)"));
-    pDoc->SetString(2, 3, 0, OUString("=N(A1:A8)"));
-    pDoc->SetString(2, 4, 0, OUString("=N(A1:A8)"));
-    pDoc->SetString(2, 5, 0, OUString("=N(A1:A8)"));
+    m_pDoc->SetString(2, 2, 0, OUString("=N(A1:A8)"));
+    m_pDoc->SetString(2, 3, 0, OUString("=N(A1:A8)"));
+    m_pDoc->SetString(2, 4, 0, OUString("=N(A1:A8)"));
+    m_pDoc->SetString(2, 5, 0, OUString("=N(A1:A8)"));
 
     // Calculate and check the results.
-    pDoc->CalcAll();
+    m_pDoc->CalcAll();
     double checks1[] = {
         0, 0,  0,    1, -1, 12.3, 0, // cell reference
         0, 1, -1, 123,  0,    0, 0   // in-line values
     };
     for (size_t i = 0; i < SAL_N_ELEMENTS(checks1); ++i)
     {
-        pDoc->GetValue(1, i, 0, result);
+        m_pDoc->GetValue(1, i, 0, result);
         bool bGood = result == checks1[i];
         if (!bGood)
         {
@@ -589,7 +625,7 @@ void testFuncN(ScDocument* pDoc)
     };
     for (size_t i = 0; i < SAL_N_ELEMENTS(checks2); ++i)
     {
-        pDoc->GetValue(1, i+2, 0, result);
+        m_pDoc->GetValue(1, i+2, 0, result);
         bool bGood = result == checks2[i];
         if (!bGood)
         {
@@ -597,14 +633,20 @@ void testFuncN(ScDocument* pDoc)
             CPPUNIT_ASSERT_MESSAGE("Unexpected result for N", false);
         }
     }
+
+    m_pDoc->DeleteTab(0);
 }
 
-void testFuncCOUNTIF(ScDocument* pDoc)
+void Test::testFuncCOUNTIF()
 {
     // COUNTIF (test case adopted from OOo i#36381)
 
+    OUString aTabName("foo");
+    CPPUNIT_ASSERT_MESSAGE ("failed to insert sheet",
+                            m_pDoc->InsertTab (0, aTabName));
+
     // Empty A1:A39 first.
-    clearRange(pDoc, ScRange(0, 0, 0, 0, 40, 0));
+    clearRange(m_pDoc, ScRange(0, 0, 0, 0, 40, 0));
 
     // Raw data (rows 1 through 9)
     const char* aData[] = {
@@ -621,9 +663,9 @@ void testFuncCOUNTIF(ScDocument* pDoc)
 
     SCROW nRows = SAL_N_ELEMENTS(aData);
     for (SCROW i = 0; i < nRows; ++i)
-        pDoc->SetString(0, i, 0, OUString::createFromAscii(aData[i]));
+        m_pDoc->SetString(0, i, 0, OUString::createFromAscii(aData[i]));
 
-    printRange(pDoc, ScRange(0, 0, 0, 0, 8, 0), "data range for COUNTIF");
+    printRange(m_pDoc, ScRange(0, 0, 0, 0, 8, 0), "data range for COUNTIF");
 
     // formulas and results
     struct {
@@ -646,15 +688,15 @@ void testFuncCOUNTIF(ScDocument* pDoc)
     for (SCROW i = 0; i < nRows; ++i)
     {
         SCROW nRow = 20 + i;
-        pDoc->SetString(0, nRow, 0, OUString::createFromAscii(aChecks[i].pFormula));
+        m_pDoc->SetString(0, nRow, 0, OUString::createFromAscii(aChecks[i].pFormula));
     }
-    pDoc->CalcAll();
+    m_pDoc->CalcAll();
 
     for (SCROW i = 0; i < nRows; ++i)
     {
         double result;
         SCROW nRow = 20 + i;
-        pDoc->GetValue(0, nRow, 0, result);
+        m_pDoc->GetValue(0, nRow, 0, result);
         bool bGood = result == aChecks[i].fResult;
         if (!bGood)
         {
@@ -667,22 +709,28 @@ void testFuncCOUNTIF(ScDocument* pDoc)
     // Don't count empty strings when searching for a number.
 
     // Clear A1:A2.
-    clearRange(pDoc, ScRange(0, 0, 0, 0, 1, 0));
+    clearRange(m_pDoc, ScRange(0, 0, 0, 0, 1, 0));
 
-    pDoc->SetString(0, 0, 0, OUString("=\"\""));
-    pDoc->SetString(0, 1, 0, OUString("=COUNTIF(A1;1)"));
-    pDoc->CalcAll();
+    m_pDoc->SetString(0, 0, 0, OUString("=\"\""));
+    m_pDoc->SetString(0, 1, 0, OUString("=COUNTIF(A1;1)"));
+    m_pDoc->CalcAll();
 
-    double result = pDoc->GetValue(0, 1, 0);
+    double result = m_pDoc->GetValue(0, 1, 0);
     CPPUNIT_ASSERT_MESSAGE("We shouldn't count empty string as valid number.", result == 0.0);
+
+    m_pDoc->DeleteTab(0);
 }
 
-void testFuncIFERROR(ScDocument* pDoc)
+void Test::testFuncIFERROR()
 {
     // IFERROR/IFNA (fdo#56124)
 
+    OUString aTabName("foo");
+    CPPUNIT_ASSERT_MESSAGE ("failed to insert sheet",
+                            m_pDoc->InsertTab (0, aTabName));
+
     // Empty A1:A39 first.
-    clearRange(pDoc, ScRange(0, 0, 0, 0, 40, 0));
+    clearRange(m_pDoc, ScRange(0, 0, 0, 0, 40, 0));
 
     // Raw data (rows 1 through 12)
     const char* aData[] = {
@@ -702,9 +750,9 @@ void testFuncIFERROR(ScDocument* pDoc)
 
     SCROW nRows = SAL_N_ELEMENTS(aData);
     for (SCROW i = 0; i < nRows; ++i)
-        pDoc->SetString(0, i, 0, OUString::createFromAscii(aData[i]));
+        m_pDoc->SetString(0, i, 0, OUString::createFromAscii(aData[i]));
 
-    printRange(pDoc, ScRange(0, 0, 0, 0, nRows-1, 0), "data range for IFERROR/IFNA");
+    printRange(m_pDoc, ScRange(0, 0, 0, 0, nRows-1, 0), "data range for IFERROR/IFNA");
 
     // formulas and results
     struct {
@@ -729,32 +777,38 @@ void testFuncIFERROR(ScDocument* pDoc)
     for (SCROW i = 0; i < nRows-2; ++i)
     {
         SCROW nRow = 20 + i;
-        pDoc->SetString(0, nRow, 0, OUString::createFromAscii(aChecks[i].pFormula));
+        m_pDoc->SetString(0, nRow, 0, OUString::createFromAscii(aChecks[i].pFormula));
     }
 
     // Create a matrix range in last two rows of the range above, actual data
     // of the placeholders.
     ScMarkData aMark;
     aMark.SelectOneTable(0);
-    pDoc->InsertMatrixFormula(0, 20 + nRows-2, 0, 20 + nRows-1, aMark, "=IFERROR(3*A11:A12;1998)", NULL);
+    m_pDoc->InsertMatrixFormula(0, 20 + nRows-2, 0, 20 + nRows-1, aMark, "=IFERROR(3*A11:A12;1998)", NULL);
 
-    pDoc->CalcAll();
+    m_pDoc->CalcAll();
 
     for (SCROW i = 0; i < nRows; ++i)
     {
         SCROW nRow = 20 + i;
-        OUString aResult = pDoc->GetString(0, nRow, 0);
+        OUString aResult = m_pDoc->GetString(0, nRow, 0);
         CPPUNIT_ASSERT_EQUAL_MESSAGE(
             aChecks[i].pFormula, OUString::createFromAscii( aChecks[i].pResult), aResult);
     }
+
+    m_pDoc->DeleteTab(0);
 }
 
-void testFuncNUMBERVALUE( ScDocument* pDoc )
+void Test::testFuncNUMBERVALUE()
 {
     // NUMBERVALUE fdo#57180
 
+    OUString aTabName("foo");
+    CPPUNIT_ASSERT_MESSAGE ("failed to insert sheet",
+                            m_pDoc->InsertTab (0, aTabName));
+
     // Empty A1:A39 first.
-    clearRange(pDoc, ScRange(0, 0, 0, 0, 40, 0));
+    clearRange(m_pDoc, ScRange(0, 0, 0, 0, 40, 0));
 
     // Raw data (rows 1 through 6)
     const char* aData[] = {
@@ -768,9 +822,9 @@ void testFuncNUMBERVALUE( ScDocument* pDoc )
 
     SCROW nRows = SAL_N_ELEMENTS(aData);
     for (SCROW i = 0; i < nRows; ++i)
-        pDoc->SetString(0, i, 0, OUString::createFromAscii(aData[i]));
+        m_pDoc->SetString(0, i, 0, OUString::createFromAscii(aData[i]));
 
-    printRange(pDoc, ScRange(0, 0, 0, 0, nRows - 1, 0), "data range for NUMBERVALUE");
+    printRange(m_pDoc, ScRange(0, 0, 0, 0, nRows - 1, 0), "data range for NUMBERVALUE");
 
     // formulas and results
     struct {
@@ -790,25 +844,31 @@ void testFuncNUMBERVALUE( ScDocument* pDoc )
     for (SCROW i = 0; i < nRows; ++i)
     {
         SCROW nRow = 20 + i;
-        pDoc->SetString(0, nRow, 0, OUString::createFromAscii(aChecks[i].pFormula));
+        m_pDoc->SetString(0, nRow, 0, OUString::createFromAscii(aChecks[i].pFormula));
     }
-    pDoc->CalcAll();
+    m_pDoc->CalcAll();
 
     for (SCROW i = 0; i < nRows; ++i)
     {
         SCROW nRow = 20 + i;
-        OUString aResult = pDoc->GetString(0, nRow, 0);
+        OUString aResult = m_pDoc->GetString(0, nRow, 0);
         CPPUNIT_ASSERT_EQUAL_MESSAGE(
             aChecks[i].pFormula, OUString::createFromAscii( aChecks[i].pResult), aResult);
     }
+
+    m_pDoc->DeleteTab(0);
 }
 
-void testFuncVLOOKUP(ScDocument* pDoc)
+void Test::testFuncVLOOKUP()
 {
     // VLOOKUP
 
+    OUString aTabName("foo");
+    CPPUNIT_ASSERT_MESSAGE ("failed to insert sheet",
+                            m_pDoc->InsertTab (0, aTabName));
+
     // Clear A1:F40.
-    clearRange(pDoc, ScRange(0, 0, 0, 5, 39, 0));
+    clearRange(m_pDoc, ScRange(0, 0, 0, 5, 39, 0));
 
     // Raw data
     const char* aData[][2] = {
@@ -832,11 +892,11 @@ void testFuncVLOOKUP(ScDocument* pDoc)
     // Insert raw data into A1:B14.
     for (SCROW i = 0; aData[i][0]; ++i)
     {
-        pDoc->SetString(0, i, 0, OUString::createFromAscii(aData[i][0]));
-        pDoc->SetString(1, i, 0, OUString::createFromAscii(aData[i][1]));
+        m_pDoc->SetString(0, i, 0, OUString::createFromAscii(aData[i][0]));
+        m_pDoc->SetString(1, i, 0, OUString::createFromAscii(aData[i][1]));
     }
 
-    printRange(pDoc, ScRange(0, 0, 0, 1, 13, 0), "raw data for VLOOKUP");
+    printRange(m_pDoc, ScRange(0, 0, 0, 1, 13, 0), "raw data for VLOOKUP");
 
     // Formula data
     struct {
@@ -865,11 +925,11 @@ void testFuncVLOOKUP(ScDocument* pDoc)
     // Insert formula data into D1:E18.
     for (size_t i = 0; i < SAL_N_ELEMENTS(aChecks); ++i)
     {
-        pDoc->SetString(3, i, 0, OUString::createFromAscii(aChecks[i].pLookup));
-        pDoc->SetString(4, i, 0, OUString::createFromAscii(aChecks[i].pFormula));
+        m_pDoc->SetString(3, i, 0, OUString::createFromAscii(aChecks[i].pLookup));
+        m_pDoc->SetString(4, i, 0, OUString::createFromAscii(aChecks[i].pFormula));
     }
-    pDoc->CalcAll();
-    printRange(pDoc, ScRange(3, 0, 0, 4, 17, 0), "formula data for VLOOKUP");
+    m_pDoc->CalcAll();
+    printRange(m_pDoc, ScRange(3, 0, 0, 4, 17, 0), "formula data for VLOOKUP");
 
     // Verify results.
     for (size_t i = 0; i < SAL_N_ELEMENTS(aChecks); ++i)
@@ -878,7 +938,7 @@ void testFuncVLOOKUP(ScDocument* pDoc)
             // Skip the header row.
             continue;
 
-        OUString aRes = pDoc->GetString(4, i, 0);
+        OUString aRes = m_pDoc->GetString(4, i, 0);
         bool bGood = aRes.equalsAscii(aChecks[i].pRes);
         if (!bGood)
         {
@@ -887,6 +947,8 @@ void testFuncVLOOKUP(ScDocument* pDoc)
             CPPUNIT_ASSERT_MESSAGE("Unexpected result for VLOOKUP", false);
         }
     }
+
+    m_pDoc->DeleteTab(0);
 }
 
 struct NumStrCheck {
@@ -938,9 +1000,13 @@ void runTestMATCH(ScDocument* pDoc, const char* aData[_DataSize], StrStrCheck aC
     }
 }
 
-void testFuncMATCH(ScDocument* pDoc)
+void Test::testFuncMATCH()
 {
-    clearRange(pDoc, ScRange(0, 0, 0, 4, 40, 0));
+    OUString aTabName("foo");
+    CPPUNIT_ASSERT_MESSAGE ("failed to insert sheet",
+                            m_pDoc->InsertTab (0, aTabName));
+
+    clearRange(m_pDoc, ScRange(0, 0, 0, 4, 40, 0));
     {
         // Ascending in-exact match
 
@@ -979,7 +1045,7 @@ void testFuncMATCH(ScDocument* pDoc)
             { "Charlie", "12" }
         };
 
-        runTestMATCH<SAL_N_ELEMENTS(aData),SAL_N_ELEMENTS(aChecks),1>(pDoc, aData, aChecks);
+        runTestMATCH<SAL_N_ELEMENTS(aData),SAL_N_ELEMENTS(aChecks),1>(m_pDoc, aData, aChecks);
     }
 
     {
@@ -1021,19 +1087,25 @@ void testFuncMATCH(ScDocument* pDoc)
             { "David", "#N/A" }
         };
 
-        runTestMATCH<SAL_N_ELEMENTS(aData),SAL_N_ELEMENTS(aChecks),-1>(pDoc, aData, aChecks);
+        runTestMATCH<SAL_N_ELEMENTS(aData),SAL_N_ELEMENTS(aChecks),-1>(m_pDoc, aData, aChecks);
     }
+
+    m_pDoc->DeleteTab(0);
 }
 
-void testFuncCELL(ScDocument* pDoc)
+void Test::testFuncCELL()
 {
-    clearRange(pDoc, ScRange(0, 0, 0, 2, 20, 0)); // Clear A1:C21.
+    OUString aTabName("foo");
+    CPPUNIT_ASSERT_MESSAGE ("failed to insert sheet",
+                            m_pDoc->InsertTab (0, aTabName));
+
+    clearRange(m_pDoc, ScRange(0, 0, 0, 2, 20, 0)); // Clear A1:C21.
 
     {
         const char* pContent = "Some random text";
-        pDoc->SetString(2, 9, 0, OUString::createFromAscii(pContent)); // Set this value to C10.
+        m_pDoc->SetString(2, 9, 0, OUString::createFromAscii(pContent)); // Set this value to C10.
         double val = 1.2;
-        pDoc->SetValue(2, 0, 0, val); // Set numeric value to C1;
+        m_pDoc->SetValue(2, 0, 0, val); // Set numeric value to C1;
 
         // We don't test: FILENAME, FORMAT, WIDTH, PROTECT, PREFIX
         StrStrCheck aChecks[] = {
@@ -1050,20 +1122,26 @@ void testFuncCELL(ScDocument* pDoc)
         };
 
         for (size_t i = 0; i < SAL_N_ELEMENTS(aChecks); ++i)
-            pDoc->SetString(0, i, 0, OUString::createFromAscii(aChecks[i].pVal));
-        pDoc->CalcAll();
+            m_pDoc->SetString(0, i, 0, OUString::createFromAscii(aChecks[i].pVal));
+        m_pDoc->CalcAll();
 
         for (size_t i = 0; i < SAL_N_ELEMENTS(aChecks); ++i)
         {
-            OUString aVal = pDoc->GetString(0, i, 0);
+            OUString aVal = m_pDoc->GetString(0, i, 0);
             CPPUNIT_ASSERT_MESSAGE("Unexpected result for CELL", aVal.equalsAscii(aChecks[i].pRes));
         }
     }
+
+    m_pDoc->DeleteTab(0);
 }
 
 /** See also test case document fdo#44456 sheet cpearson */
-void testFuncDATEDIF( ScDocument* pDoc )
+void Test::testFuncDATEDIF()
 {
+    OUString aTabName("foo");
+    CPPUNIT_ASSERT_MESSAGE ("failed to insert sheet",
+                            m_pDoc->InsertTab (0, aTabName));
+
     const char* aData[][5] = {
         { "2007-01-01", "2007-01-10",  "d",   "9", "=DATEDIF(A1;B1;C1)" } ,
         { "2007-01-01", "2007-01-31",  "m",   "0", "=DATEDIF(A2;B2;C2)" } ,
@@ -1082,44 +1160,49 @@ void testFuncDATEDIF( ScDocument* pDoc )
         { "2007-01-02", "2007-01-01", "md", "Err:502", "=DATEDIF(A15;B15;C15)" }    // fail date1 > date2
     };
 
-    clearRange( pDoc, ScRange(0, 0, 0, 4, SAL_N_ELEMENTS(aData), 0));
+    clearRange( m_pDoc, ScRange(0, 0, 0, 4, SAL_N_ELEMENTS(aData), 0));
     ScAddress aPos(0,0,0);
-    ScRange aDataRange = insertRangeData( pDoc, aPos, aData, SAL_N_ELEMENTS(aData));
+    ScRange aDataRange = insertRangeData( m_pDoc, aPos, aData, SAL_N_ELEMENTS(aData));
     CPPUNIT_ASSERT_MESSAGE("failed to insert range data at correct position", aDataRange.aStart == aPos);
 
-    pDoc->CalcAll();
+    m_pDoc->CalcAll();
 
     for (size_t i = 0; i < SAL_N_ELEMENTS(aData); ++i)
     {
-        OUString aVal = pDoc->GetString( 4, i, 0);
+        OUString aVal = m_pDoc->GetString( 4, i, 0);
         //std::cout << "row "<< i << ": " << OUStringToOString( aVal, RTL_TEXTENCODING_UTF8).getStr() << ", expected " << aData[i][3] << std::endl;
         CPPUNIT_ASSERT_MESSAGE("Unexpected result for DATEDIF", aVal.equalsAscii( aData[i][3]));
     }
+
+    m_pDoc->DeleteTab(0);
 }
 
-void testFuncINDIRECT(ScDocument* pDoc)
+void Test::testFuncINDIRECT()
 {
-    clearRange(pDoc, ScRange(0, 0, 0, 0, 10, 0)); // Clear A1:A11
-    OUString aTabName;
-    bool bGood = pDoc->GetName(0, aTabName);
+    OUString aTabName("foo");
+    CPPUNIT_ASSERT_MESSAGE ("failed to insert sheet",
+                            m_pDoc->InsertTab (0, aTabName));
+    clearRange(m_pDoc, ScRange(0, 0, 0, 0, 10, 0)); // Clear A1:A11
+
+    bool bGood = m_pDoc->GetName(0, aTabName);
     CPPUNIT_ASSERT_MESSAGE("failed to get sheet name.", bGood);
 
     OUString aTest = "Test", aRefErr = "#REF!";
-    pDoc->SetString(0, 10, 0, aTest);
-    CPPUNIT_ASSERT_MESSAGE("Unexpected cell value.", pDoc->GetString(0,10,0) == aTest);
+    m_pDoc->SetString(0, 10, 0, aTest);
+    CPPUNIT_ASSERT_MESSAGE("Unexpected cell value.", m_pDoc->GetString(0,10,0) == aTest);
 
     OUString aPrefix = "=INDIRECT(\"";
 
     OUString aFormula = aPrefix + aTabName + ".A11\")"; // Calc A1
-    pDoc->SetString(0, 0, 0, aFormula);
+    m_pDoc->SetString(0, 0, 0, aFormula);
     aFormula = aPrefix + aTabName + "!A11\")"; // Excel A1
-    pDoc->SetString(0, 1, 0, aFormula);
+    m_pDoc->SetString(0, 1, 0, aFormula);
     aFormula = aPrefix + aTabName + "!R11C1\")"; // Excel R1C1
-    pDoc->SetString(0, 2, 0, aFormula);
+    m_pDoc->SetString(0, 2, 0, aFormula);
     aFormula = aPrefix + aTabName + "!R11C1\";0)"; // Excel R1C1 (forced)
-    pDoc->SetString(0, 3, 0, aFormula);
+    m_pDoc->SetString(0, 3, 0, aFormula);
 
-    pDoc->CalcAll();
+    m_pDoc->CalcAll();
     {
         // Default is to use the current formula syntax, which is Calc A1.
         const OUString* aChecks[] = {
@@ -1128,7 +1211,7 @@ void testFuncINDIRECT(ScDocument* pDoc)
 
         for (size_t i = 0; i < SAL_N_ELEMENTS(aChecks); ++i)
         {
-            OUString aVal = pDoc->GetString(0, i, 0);
+            OUString aVal = m_pDoc->GetString(0, i, 0);
             CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong value!", *aChecks[i], aVal);
         }
     }
@@ -1136,7 +1219,7 @@ void testFuncINDIRECT(ScDocument* pDoc)
     ScCalcConfig aConfig;
     aConfig.meStringRefAddressSyntax = formula::FormulaGrammar::CONV_OOO;
     ScInterpreter::SetGlobalConfig(aConfig);
-    pDoc->CalcAll();
+    m_pDoc->CalcAll();
     {
         // Explicit Calc A1 syntax
         const OUString* aChecks[] = {
@@ -1145,14 +1228,14 @@ void testFuncINDIRECT(ScDocument* pDoc)
 
         for (size_t i = 0; i < SAL_N_ELEMENTS(aChecks); ++i)
         {
-            OUString aVal = pDoc->GetString(0, i, 0);
+            OUString aVal = m_pDoc->GetString(0, i, 0);
             CPPUNIT_ASSERT_MESSAGE("Wrong value!", aVal == *aChecks[i]);
         }
     }
 
     aConfig.meStringRefAddressSyntax = formula::FormulaGrammar::CONV_XL_A1;
     ScInterpreter::SetGlobalConfig(aConfig);
-    pDoc->CalcAll();
+    m_pDoc->CalcAll();
     {
         // Excel A1 syntax
         const OUString* aChecks[] = {
@@ -1161,14 +1244,14 @@ void testFuncINDIRECT(ScDocument* pDoc)
 
         for (size_t i = 0; i < SAL_N_ELEMENTS(aChecks); ++i)
         {
-            OUString aVal = pDoc->GetString(0, i, 0);
+            OUString aVal = m_pDoc->GetString(0, i, 0);
             CPPUNIT_ASSERT_MESSAGE("Wrong value!", aVal == *aChecks[i]);
         }
     }
 
     aConfig.meStringRefAddressSyntax = formula::FormulaGrammar::CONV_XL_R1C1;
     ScInterpreter::SetGlobalConfig(aConfig);
-    pDoc->CalcAll();
+    m_pDoc->CalcAll();
     {
         // Excel R1C1 syntax
         const OUString* aChecks[] = {
@@ -1177,10 +1260,12 @@ void testFuncINDIRECT(ScDocument* pDoc)
 
         for (size_t i = 0; i < SAL_N_ELEMENTS(aChecks); ++i)
         {
-            OUString aVal = pDoc->GetString(0, i, 0);
+            OUString aVal = m_pDoc->GetString(0, i, 0);
             CPPUNIT_ASSERT_MESSAGE("Wrong value!", aVal == *aChecks[i]);
         }
     }
+
+    m_pDoc->DeleteTab(0);
 }
 
 void Test::testFormulaHashAndTag()
@@ -1274,27 +1359,6 @@ void Test::testFormulaHashAndTag()
     m_pDoc->DeleteTab(0);
 }
 
-void Test::testCellFunctions()
-{
-    OUString aTabName("foo");
-    CPPUNIT_ASSERT_MESSAGE ("failed to insert sheet",
-                            m_pDoc->InsertTab (0, aTabName));
-
-    testFuncSUM(m_pDoc);
-    testFuncPRODUCT(m_pDoc);
-    testFuncN(m_pDoc);
-    testFuncCOUNTIF(m_pDoc);
-    testFuncIFERROR(m_pDoc);
-    testFuncNUMBERVALUE(m_pDoc);
-    testFuncVLOOKUP(m_pDoc);
-    testFuncMATCH(m_pDoc);
-    testFuncCELL(m_pDoc);
-    testFuncDATEDIF(m_pDoc);
-    testFuncINDIRECT(m_pDoc);
-
-    m_pDoc->DeleteTab(0);
-}
-
 void Test::testCopyToDocument()
 {
     CPPUNIT_ASSERT_MESSAGE ("failed to insert sheet", m_pDoc->InsertTab (0, "src"));
commit 1a8591970e52dd806af2f9baf8ea5b9f4322fa21
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date:   Sat May 25 14:26:21 2013 +0200

    accept this result as bug fixed
    
    We still have the number format type in ScFormulaCell. Removing that one
    from ScFormulaCell is more work and needs much more inspection than
    removing the formula index. Additionally we should inspect all callers
    of ScFormulaCell::GetStandardFormat as most of them are useless when we
    know that a cell has a fixed number format.
    
    Change-Id: I3ad55a0c072da0fc4046d6c7245ed734a1dcaabc

diff --git a/sc/inc/formulacell.hxx b/sc/inc/formulacell.hxx
index 49941f9..cd9767c 100644
--- a/sc/inc/formulacell.hxx
+++ b/sc/inc/formulacell.hxx
@@ -70,10 +70,9 @@ private:
     ScFormulaCell*  pPreviousTrack;
     ScFormulaCell*  pNextTrack;
     ScFormulaCellGroupRef xGroup;       // re-factoring hack - group of formulae we're part of.
-    sal_uLong       nFormatIndex;       // Number format set by calculation
-    short           nFormatType;        // Number format type set by calculation
     sal_uInt16      nSeenInIteration;   // Iteration cycle in which the cell was last encountered
     sal_uInt8       cMatrixFlag;        // One of ScMatrixMode
+    short           nFormatType;
     bool            bDirty         : 1; // Must be (re)calculated
     bool            bChanged       : 1; // Whether something changed regarding display/representation
     bool            bRunning       : 1; // Already interpreting right now
@@ -147,6 +146,7 @@ public:
     bool            NeedsListening() const { return bNeedListening; }
     void            SetNeedsListening( bool bVar ) { bNeedListening = bVar; }
     void            SetNeedNumberFormat( bool bVal ) { mbNeedsNumberFormat = bVal; }
+    short           GetFormatType() const { return nFormatType; }
     void            Compile(const OUString& rFormula,
                             bool bNoListening = false,
                             const formula::FormulaGrammar::Grammar = formula::FormulaGrammar::GRAM_DEFAULT );
@@ -208,7 +208,6 @@ public:
     sal_uInt16      GetMatrixEdge( ScAddress& rOrgPos );
     sal_uInt16      GetErrCode();   // interpret first if necessary
     sal_uInt16      GetRawError();  // don't interpret, just return code or result error
-    short           GetFormatType() const                   { return nFormatType; }
     sal_uInt8       GetMatrixFlag() const                   { return cMatrixFlag; }
     ScTokenArray*   GetCode() const                         { return pCode; }
 
diff --git a/sc/source/core/data/column2.cxx b/sc/source/core/data/column2.cxx
index 9e489ac..ae10d7b 100644
--- a/sc/source/core/data/column2.cxx
+++ b/sc/source/core/data/column2.cxx
@@ -157,10 +157,7 @@ long ScColumn::GetNeededSize(
         // #i111387# disable automatic line breaks only for "General" number format
         if (bBreak && aCell.hasNumeric() && ( nFormat % SV_COUNTRY_LANGUAGE_OFFSET ) == 0 )
         {
-            // also take formula result type into account for number format
-            if (aCell.meType != CELLTYPE_FORMULA ||
-                (aCell.mpFormula->GetStandardFormat(*pFormatter, nFormat) % SV_COUNTRY_LANGUAGE_OFFSET) == 0)
-                bBreak = false;
+            bBreak = false;
         }
 
         //  get other attributes from pattern and conditional formatting
diff --git a/sc/source/core/data/formulacell.cxx b/sc/source/core/data/formulacell.cxx
index abb9561..d5651c7 100644
--- a/sc/source/core/data/formulacell.cxx
+++ b/sc/source/core/data/formulacell.cxx
@@ -400,10 +400,9 @@ ScFormulaCell::ScFormulaCell( ScDocument* pDoc, const ScAddress& rPos,
     pNext(0),
     pPreviousTrack(0),
     pNextTrack(0),
-    nFormatIndex(0),
-    nFormatType( NUMBERFORMAT_NUMBER ),
     nSeenInIteration(0),
     cMatrixFlag ( cMatInd ),
+    nFormatType ( NUMBERFORMAT_NUMBER ),
     bDirty( true ), // -> Because of the use of the Auto Pilot Function was: cMatInd != 0
     bChanged( false ),
     bRunning( false ),
@@ -435,10 +434,9 @@ ScFormulaCell::ScFormulaCell( ScDocument* pDoc, const ScAddress& rPos,
     pNext(0),
     pPreviousTrack(0),
     pNextTrack(0),
-    nFormatIndex(0),
-    nFormatType( NUMBERFORMAT_NUMBER ),
     nSeenInIteration(0),
     cMatrixFlag ( cInd ),
+    nFormatType ( NUMBERFORMAT_NUMBER ),
     bDirty( NULL != pArr ), // -> Because of the use of the Auto Pilot Function was: cInd != 0
     bChanged( false ),
     bRunning( false ),
@@ -480,10 +478,9 @@ ScFormulaCell::ScFormulaCell( const ScFormulaCell& rCell, ScDocument& rDoc, cons
     pNext(0),
     pPreviousTrack(0),
     pNextTrack(0),
-    nFormatIndex( &rDoc == rCell.pDocument ? rCell.nFormatIndex : 0 ),
-    nFormatType( rCell.nFormatType ),
     nSeenInIteration(0),
     cMatrixFlag ( rCell.cMatrixFlag ),
+    nFormatType( rCell.nFormatType ),
     bDirty( rCell.bDirty ),
     bChanged( rCell.bChanged ),
     bRunning( false ),
@@ -767,7 +764,6 @@ void ScFormulaCell::CompileTokenArray( bool bNoListening )
         if( !pCode->GetCodeError() )
         {
             nFormatType = aComp.GetNumFormatType();
-            nFormatIndex = 0;
             bChanged = true;
             aResult.SetToken( NULL);
             bCompile = false;
@@ -817,7 +813,6 @@ void ScFormulaCell::CompileXML( ScProgress& rProgress )
         if( !pCode->GetCodeError() )
         {
             nFormatType = aComp.GetNumFormatType();
-            nFormatIndex = 0;
             bChanged = true;
             bCompile = false;
             StartListeningTo( pDocument );
@@ -868,7 +863,6 @@ void ScFormulaCell::CalcAfterLoad()
         aComp.SetGrammar(pDocument->GetGrammar());
         bSubTotal = aComp.CompileTokenArray();
         nFormatType = aComp.GetNumFormatType();
-        nFormatIndex = 0;
         bDirty = true;
         bCompile = false;
         bNewCompiled = true;
@@ -1295,7 +1289,7 @@ void ScFormulaCell::InterpretTail( ScInterpretTailParameter eTailParam )
 
         if( mbNeedsNumberFormat )
         {
-            sal_uInt16 nFormatType = p->GetRetFormatType();
+            nFormatType = p->GetRetFormatType();
             sal_Int32 nFormatIndex = p->GetRetFormatIndex();
 
             // don't set text format as hard format
@@ -1375,11 +1369,6 @@ void ScFormulaCell::InterpretTail( ScInterpretTailParameter eTailParam )
           && nFormatType != NUMBERFORMAT_DATETIME )
         {
             sal_uLong nFormat = pDocument->GetNumberFormat( aPos );
-            if ( nFormatIndex && (nFormat % SV_COUNTRY_LANGUAGE_OFFSET) == 0 )
-                nFormat = nFormatIndex;
-            if ( (nFormat % SV_COUNTRY_LANGUAGE_OFFSET) == 0 )
-                nFormat = ScGlobal::GetStandardFormat(
-                    *pDocument->GetFormatTable(), nFormat, nFormatType );
             aResult.SetDouble( pDocument->RoundValueAsShown(
                         aResult.GetDouble(), nFormat));
         }
@@ -1505,8 +1494,6 @@ void ScFormulaCell::GetMatColsRows( SCCOL & nCols, SCROW & nRows ) const
 
 sal_uLong ScFormulaCell::GetStandardFormat( SvNumberFormatter& rFormatter, sal_uLong nFormat ) const
 {
-    if ( nFormatIndex && (nFormat % SV_COUNTRY_LANGUAGE_OFFSET) == 0 )
-        return nFormatIndex;
     //! not ScFormulaCell::IsValue(), that could reinterpret the formula again.
     if ( aResult.IsValue() )
         return ScGlobal::GetStandardFormat( aResult.GetDouble(), rFormatter, nFormat, nFormatType );
diff --git a/sc/source/core/tool/cellform.cxx b/sc/source/core/tool/cellform.cxx
index cb7ce81..6846874 100644
--- a/sc/source/core/tool/cellform.cxx
+++ b/sc/source/core/tool/cellform.cxx
@@ -203,10 +203,6 @@ OUString ScCellFormat::GetString(
                 {
                     sal_uInt16 nErrCode = pFCell->GetErrCode();
 
-                    // get the number format only after interpretation (GetErrCode):
-                    if ((nFormat % SV_COUNTRY_LANGUAGE_OFFSET) == 0) nFormat = pFCell->GetStandardFormat(rFormatter,
-                                                                                                         nFormat);
-
                     if (nErrCode != 0) aString = ScGlobal::GetErrorString(nErrCode);
                     else if (pFCell->IsEmptyDisplayedAsString()) aString = OUString();
                     else if (pFCell->IsValue())
diff --git a/sc/source/core/tool/interpr4.cxx b/sc/source/core/tool/interpr4.cxx
index b4a72e5..cf2af0b 100644
--- a/sc/source/core/tool/interpr4.cxx
+++ b/sc/source/core/tool/interpr4.cxx
@@ -170,8 +170,6 @@ sal_uLong ScInterpreter::GetCellNumberFormat( const ScAddress& rPos, ScRefCellVa
         else
             nErr = 0;
         nFormat = pDok->GetNumberFormat( rPos );
-        if (rCell.meType == CELLTYPE_FORMULA && ((nFormat % SV_COUNTRY_LANGUAGE_OFFSET) == 0))
-            nFormat = rCell.mpFormula->GetStandardFormat(*pFormatter, nFormat);
     }
 
     SetError(nErr);
diff --git a/sc/source/ui/unoobj/chart2uno.cxx b/sc/source/ui/unoobj/chart2uno.cxx
index 38036b7..5bce20d 100644
--- a/sc/source/ui/unoobj/chart2uno.cxx
+++ b/sc/source/ui/unoobj/chart2uno.cxx
@@ -3258,17 +3258,7 @@ namespace {
 sal_uLong getDisplayNumberFormat(ScDocument* pDoc, const ScAddress& rPos)
 {
     sal_uLong nFormat = pDoc->GetNumberFormat(rPos); // original format from cell.
-    SvNumberFormatter* pFormatter = pDoc->GetFormatTable();
-    if (!pFormatter)
-        return nFormat;
-
-    ScRefCellValue aCell;
-    aCell.assign(*pDoc, rPos);
-    if (aCell.isEmpty() || aCell.meType != CELLTYPE_FORMULA || nFormat)
-        return nFormat;
-
-    // With formula cell, the format may be inferred from the formula result.
-    return aCell.mpFormula->GetStandardFormat(*pFormatter, nFormat);
+    return nFormat;
 }
 
 }


More information about the Libreoffice-commits mailing list