[Libreoffice-commits] core.git: sc/qa sc/source

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Tue Oct 2 14:33:18 UTC 2018


 sc/qa/uitest/calc_tests2/tdf120174.py |   35 ++++++++++++++++++++++++++++++++++
 sc/source/core/tool/formularesult.cxx |   11 ++++++++++
 2 files changed, 46 insertions(+)

New commits:
commit 4cb160d58c62e6214f86ba94c9c2834dab6cfe8f
Author:     Dennis Francis <dennis.francis at collabora.co.uk>
AuthorDate: Sat Sep 29 21:39:19 2018 +0530
Commit:     Michael Meeks <michael.meeks at collabora.com>
CommitDate: Tue Oct 2 16:32:55 2018 +0200

    tdf#120174 : Always copy mbValueCached flag in Assign()
    
    so that fast result return maintains correctness.
    
    Although not necessary for fixing this bug,
    lets take advantage of fast result return in the case
    of empty result token by setting mfValue to 0.0 and
    setting mbValueCached flag.
    
    The fast result return was implemented in :-
    
    <commit-header>
    commit 77f7b4768a79e5a8489b163670e0ce10fbd07c49
    Author: Dennis Francis <dennis.francis at collabora.co.uk>
    Date:   Wed Jul 11 17:19:28 2018 +0530
    
        Allow fast result return for formula-cells with...
    
        "double" result which is a very frequent use-case.
        This improves overall running times in most cases,
        not just for the threaded path.
    
        Change-Id: I18d10ee3cea613923e2057e746a6a8187bb18647
        Reviewed-on: https://gerrit.libreoffice.org/59395
        Tested-by: Jenkins
        Reviewed-by: Luboš Luňák <l.lunak at collabora.com>
    </commit-header>
    
    Also added a ui-test for the fix. A normal unit test would
    have sufficed, but I could not get it to reproduce the issue
    from a ucalc environment somehow.
    
    Change-Id: I9b95b571b596a7bb68768ea0de8ee4334448b540
    Reviewed-on: https://gerrit.libreoffice.org/61140
    Reviewed-by: Michael Meeks <michael.meeks at collabora.com>
    Tested-by: Jenkins

diff --git a/sc/qa/uitest/calc_tests2/tdf120174.py b/sc/qa/uitest/calc_tests2/tdf120174.py
new file mode 100644
index 000000000000..e078147a9c6f
--- /dev/null
+++ b/sc/qa/uitest/calc_tests2/tdf120174.py
@@ -0,0 +1,35 @@
+# -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*-
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+from uitest.framework import UITestCase
+from libreoffice.calc.document import get_cell_by_position
+from libreoffice.uno.propertyvalue import mkPropertyValues
+from uitest.uihelper.calc import enter_text_to_cell
+import org.libreoffice.unotest
+import pathlib
+
+def get_url_for_data_file(file_name):
+    return pathlib.Path(org.libreoffice.unotest.makeCopyFromTDOC(file_name)).as_uri()
+
+class tdf120174(UITestCase):
+    def test_tdf120174(self):
+        calc_doc = self.ui_test.create_doc_in_start_center("calc")
+        xCalcDoc = self.xUITest.getTopFocusWindow()
+        gridwin = xCalcDoc.getChild("grid_window")
+        document = self.ui_test.get_component()
+        enter_text_to_cell(gridwin, "A1", "121")
+        enter_text_to_cell(gridwin, "B1", "=A1")
+        self.assertEqual(get_cell_by_position(document, 0, 1, 0).getValue(), 121) # B1
+        gridwin.executeAction("SELECT", mkPropertyValues({"CELL": "A1"}))
+        # Delete contents of A1
+        gridwin.executeAction("TYPE", mkPropertyValues({"KEYCODE": "DELETE"}))
+        # Before the fix the result would be still 121.
+        self.assertEqual(get_cell_by_position(document, 0, 1, 0).getValue(), 0) # B1
+        self.xUITest.executeCommand(".uno:Undo")
+        self.assertEqual(get_cell_by_position(document, 0, 1, 0).getValue(), 121) # B1
+        self.ui_test.close_doc()
+
+# vim: set shiftwidth=4 softtabstop=4 expandtab:
diff --git a/sc/source/core/tool/formularesult.cxx b/sc/source/core/tool/formularesult.cxx
index 4387af07511e..629072ece09f 100644
--- a/sc/source/core/tool/formularesult.cxx
+++ b/sc/source/core/tool/formularesult.cxx
@@ -107,6 +107,10 @@ void ScFormulaResult::ResolveToken( const formula::FormulaToken * p )
                 p->DecRef();
                 mbToken = false;
                 meMultiline = MULTILINE_FALSE;
+                // Take advantage of fast double result return for empty result token.
+                // by setting mfValue to 0 and turning on mbValueCached flag.
+                mfValue = 0.0;
+                mbValueCached = true;
                 break;
             case formula::svDouble:
                 mfValue = p->GetDouble();
@@ -132,6 +136,11 @@ void ScFormulaResult::Assign( const ScFormulaResult & r )
 {
     if (this == &r)
         return;
+
+    // It is important to reset the value-cache flag to that of the source
+    // unconditionally.
+    mbValueCached = r.mbValueCached;
+
     if (r.mbEmpty)
     {
         if (mbToken && mpToken)
@@ -140,6 +149,8 @@ void ScFormulaResult::Assign( const ScFormulaResult & r )
         mbEmpty = true;
         mbEmptyDisplayedAsString = r.mbEmptyDisplayedAsString;
         meMultiline = r.meMultiline;
+        // here r.mfValue will be 0.0 which is ensured in ResolveToken().
+        mfValue = 0.0;
     }
     else if (r.mbToken)
     {


More information about the Libreoffice-commits mailing list