[Libreoffice-commits] core.git: Branch 'libreoffice-5-0' - sw/qa sw/source

Niklas Johansson sleeping.pillow at gmail.com
Mon Nov 23 03:35:11 PST 2015


 sw/qa/python/check_table.py      |   70 +++++++++++++++++++++++++++++++++++++++
 sw/source/core/docnode/ndtbl.cxx |    2 -
 2 files changed, 71 insertions(+), 1 deletion(-)

New commits:
commit d65ba563a99afb414a036101b094d34304e6a51f
Author: Niklas Johansson <sleeping.pillow at gmail.com>
Date:   Fri Oct 23 19:52:17 2015 +0200

    Make number recognition work in writer tables again
    
    It seems that number recognition in tables are not working properly
    enter 10-10-10 and it should be converted to a date but it is not.
    I tracked it down to the fix of bug fdo#32082. It looks like bSetNumFmt
    was changed to false by mistake. Since then it has changed name to
    bSetNumFormat. From what I can tell fdo#32082 still works after this
    patch, but I might have missed some nuance of that bug report.
    
    Added two tests, one for the bug mentioned above and one to check
    that number recognition is working. At least with a simple date.
    
    Reviewed-on: https://gerrit.libreoffice.org/19563
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Jan Holesovsky <kendy at collabora.com>
    (cherry picked from commit aa334d55ee34c125f6f4fdfaadbc1ed8fa33f5bc)
    
    Change-Id: Id58849a223eb602054c66c7379cd56a68a93dea2
    Reviewed-on: https://gerrit.libreoffice.org/20082
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>

diff --git a/sw/qa/python/check_table.py b/sw/qa/python/check_table.py
index f31ac91..c802425 100644
--- a/sw/qa/python/check_table.py
+++ b/sw/qa/python/check_table.py
@@ -1,10 +1,14 @@
+import math
 import unittest
 from org.libreoffice.unotest import UnoInProcess
+from com.sun.star.beans import PropertyValue
 from com.sun.star.uno import RuntimeException
 from com.sun.star.table import BorderLine
 from com.sun.star.table import BorderLine2
 from com.sun.star.table.BorderLineStyle import (DOUBLE, SOLID, EMBOSSED,\
     THICKTHIN_LARGEGAP, DASHED, DOTTED)
+from com.sun.star.util import XNumberFormats
+from com.sun.star.lang import Locale
 
 class CheckTable(unittest.TestCase):
     _uno = None
@@ -344,6 +348,72 @@ class CheckTable(unittest.TestCase):
         self.assertEqual( xTable.Data, ((1,2,3), (4,55,66), (7,88,99), (10,1111,1212)))
         xDoc.dispose()
 
+    def test_tdf32082(self):
+        xDoc = CheckTable._uno.openEmptyWriterDoc()
+        xDocFrame = xDoc.CurrentController.Frame
+        xContext = CheckTable._uno.getContext()
+        xServiceManager = xContext.ServiceManager
+        xDispatcher = xServiceManager.createInstanceWithContext(
+            'com.sun.star.frame.DispatchHelper', xContext)
+        xTable = xDoc.createInstance("com.sun.star.text.TextTable")
+        xTable.initialize(1,1)
+        xCursor = xDoc.Text.createTextCursor()
+        xDoc.Text.insertTextContent(xCursor, xTable, False)
+        # Setup numberformat for the cell
+        xNumberFormats = xDoc.NumberFormats
+        xLocale = Locale('en', 'US', '')
+        formatString = '#,##0.00 [$€-407];[RED]-#,##0.00 [$€-407]'
+        key = xNumberFormats.queryKey(formatString, xLocale, True)
+        if key == -1:
+            key = xNumberFormats.addNew(formatString, xLocale)
+        # Apply the format on the first cell
+        xTable.getCellByPosition(0,0).NumberFormat = key
+        xDispatcher.executeDispatch(xDocFrame, '.uno:GoToStartOfDoc', '', 0, ())
+        xDispatcher.executeDispatch(xDocFrame, '.uno:InsertText', '', 0,
+                                   (PropertyValue('Text', 0, '3', 0),))
+        xDispatcher.executeDispatch(xDocFrame, '.uno:JumpToNextCell', '', 0, ())
+        # Check that the formatting we set up is not destroyed
+        self.assertEquals(xTable.getCellByPosition(0,0).getString(), '3.00 €')
+        self.assertEquals(xTable.getCellByPosition(0,0).getValue(), 3)
+        # Verify that it works with number recognition turned on as well
+        xDispatcher.executeDispatch(xDocFrame, '.uno:TableNumberRecognition', '', 0,
+                                   (PropertyValue('TableNumberRecognition', 0, True, 0),))
+        xDispatcher.executeDispatch(xDocFrame, '.uno:InsertText', '', 0,
+                                   (PropertyValue('Text', 0, '4', 0),))
+        xDispatcher.executeDispatch(xDocFrame, '.uno:JumpToNextCell', '', 0, ())
+        self.assertEquals(xTable.getCellByPosition(0,1).getString(), '4.00 €')
+        self.assertEquals(xTable.getCellByPosition(0,1).getValue(), 4)
+        xDoc.dispose()
+
+    def test_numberRecognition(self):
+        xDoc = CheckTable._uno.openEmptyWriterDoc()
+        xDocFrame = xDoc.CurrentController.Frame
+        xContext = CheckTable._uno.getContext()
+        xServiceManager = xContext.ServiceManager
+        xDispatcher = xServiceManager.createInstanceWithContext(
+            'com.sun.star.frame.DispatchHelper', xContext)
+        xTable = xDoc.createInstance('com.sun.star.text.TextTable')
+        xTable.initialize(2,1)
+        xCursor = xDoc.Text.createTextCursor()
+        xDoc.Text.insertTextContent(xCursor, xTable, False)
+        xDispatcher.executeDispatch(xDocFrame, '.uno:GoToStartOfDoc', '', 0, ())
+        xDispatcher.executeDispatch(xDocFrame, '.uno:InsertText', '', 0,
+                                   (PropertyValue('Text', 0, '15-10-30', 0),))
+        xDispatcher.executeDispatch(xDocFrame, '.uno:JumpToNextCell', '', 0, ())
+        # Without number recognition 15-10-30 should not be interperated as a date
+        self.assertEquals(xTable.getCellByPosition(0,0).getString(), '15-10-30')
+        self.assertEquals(xTable.getCellByPosition(0,0).getValue(), 0)
+        # Activate number recognition
+        xDispatcher.executeDispatch(xDocFrame, '.uno:TableNumberRecognition', '', 0,
+                                   (PropertyValue('TableNumberRecognition', 0, True, 0),))
+        xDispatcher.executeDispatch(xDocFrame, '.uno:InsertText', '', 0,
+                                   (PropertyValue('Text', 0, '15-10-30', 0),))
+        xDispatcher.executeDispatch(xDocFrame, '.uno:JumpToNextCell', '', 0, ())
+        # With number recognition it should now be a date, confirm by checking
+        # the string and value of the cell.
+        self.assertEquals(xTable.getCellByPosition(0,1).getString(), '2015-10-30')
+        self.assertEquals(xTable.getCellByPosition(0,1).getValue(), 42307.0)
+        xDoc.dispose()
 if __name__ == '__main__':
     unittest.main()
 
diff --git a/sw/source/core/docnode/ndtbl.cxx b/sw/source/core/docnode/ndtbl.cxx
index 7a77906..0b9b1dc 100644
--- a/sw/source/core/docnode/ndtbl.cxx
+++ b/sw/source/core/docnode/ndtbl.cxx
@@ -4043,7 +4043,7 @@ void SwDoc::ChkBoxNumFormat( SwTableBox& rBox, bool bCallUpdate )
             SfxItemSet aBoxSet( GetAttrPool(), RES_BOXATR_FORMAT, RES_BOXATR_VALUE );
 
             bool bLockModify = true;
-            bool bSetNumberFormat = false;
+            bool bSetNumberFormat = IsInsTableFormatNum();
             const bool bForceNumberFormat = IsInsTableFormatNum() && IsInsTableChangeNumFormat();
 
             // if the user forced a number format in this cell previously,


More information about the Libreoffice-commits mailing list