Debian Codegraph @

dbaccess/qa/uitest/edit_field/tdf75509.py

raw symbols SCIP
1 # -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*-
2 #
3 # This file is part of the LibreOffice project.
4 #
5 # This Source Code Form is subject to the terms of the Mozilla Public
6 # License, v. 2.0. If a copy of the MPL was not distributed with this
7 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 #
9 from uitest.framework import UITestCase
10 from uitest.uihelper.common import get_url_for_data_file, get_state_as_dict
11
12 from libreoffice.uno.propertyvalue import mkPropertyValues
13
14 #Bug 75509 - Incorrect display of digits in default Numeric formatting
15 # of a field when language isn't English
16 class tdf75509(UITestCase):
17 def test_tdf75509(self):
18 # The sample file is an HSQLDB database with a single table. Aside from the primary key, the
19 # table has two numeric type fields each with 2 decimal places. One of them is called
20 # “FrenchField” and is set to a French locale (ie, the decimal separator is “,”) and the
21 # other is called “EnglishField” and is set to a US English locale.
22 with self.ui_test.load_file(get_url_for_data_file("tdf75509.odb")) as document:
23 xDbWindow = self.xUITest.getTopFocusWindow()
24
25 self.xUITest.executeCommand(".uno:DBViewTables")
26 # The above command is run asynchronously via an event on the main thread so we need to
27 # wait until it is dispatched before executing the next command
28 xToolkit = self.xContext.ServiceManager.createInstance('com.sun.star.awt.Toolkit')
29 xToolkit.waitUntilAllIdlesDispatched()
30
31 # We just want to select the single table in the list of tables but it seems difficult
32 # to get access to the treeview window for it because there are multiple treeviews in a
33 # hierarchy of windows with no name. However AppController handles SelectAll and that
34 # does the trick
35 self.xUITest.executeCommand(".uno:SelectAll")
36
37 with self.ui_test.open_subcomponent_through_command(".uno:DBTableEdit") as xTableFrame:
38 xTableWindow = self.xUITest.getWindow(xTableFrame.getContainerWindow())
39
40 xTableEditor = xTableWindow.getChild("DBTableEditor")
41
42 # Select the “FrenchField” row
43 xTableEditor.executeAction("TYPE", mkPropertyValues({"KEYCODE": "DOWN"}))
44
45 # Type a value with the comma decimal separator into the default value field
46 xDefaultValue = xTableWindow.getChild("DefaultValue")
47
48 xDefaultValue.executeAction("FOCUS", tuple())
49 xDefaultValue.executeAction("SET", mkPropertyValues({"TEXT": "3,14"}))
50
51 # Focus something else so that the example text will get updated
52 xTableEditor.executeAction("FOCUS", tuple())
53
54 # The example format should be updated to reflect the default value
55 xFormatText = xTableWindow.getChild("FormatText")
56 self.assertEqual(get_state_as_dict(xFormatText)["Text"], "3,14")
57
58 # Select the “EnglishField"
59 xTableEditor.executeAction("TYPE", mkPropertyValues({"KEYCODE": "DOWN"}))
60
61 # Perform the same tests with the “.” decimal separator
62 xDefaultValue.executeAction("FOCUS", tuple())
63 xDefaultValue.executeAction("SET", mkPropertyValues({"TEXT": "2.72"}))
64 xTableEditor.executeAction("FOCUS", tuple())
65 self.assertEqual(get_state_as_dict(xFormatText)["Text"], "2.72")
66
67 # Save the table (ie, just the table, not the actual database file to disk)
68 self.xUITest.executeCommandForProvider(".uno:Save", xTableFrame)
69
70 with self.ui_test.open_subcomponent_through_command(".uno:DBTableOpen") as xTableFrame:
71 xTableWindow = self.xUITest.getWindow(xTableFrame.getContainerWindow())
72
73 # Focus the “FrenchField” input in the table
74 xGrid = xTableWindow.getChild("DBGrid")
75 xGrid.executeAction("FOCUS", tuple())
76 xGrid.executeAction("TYPE", mkPropertyValues({"KEYCODE": "TAB"}))
77
78 # It should have the default value with a comma separator
79 xEdit = self.xUITest.getFocusWindow()
80 self.assertEqual(get_state_as_dict(xEdit)["Text"], "3,14")
81
82 # Focus the “EnglishField” input in the table
83 xGrid.executeAction("TYPE", mkPropertyValues({"KEYCODE": "TAB"}))
84
85 # It should have the default value with a dot separator
86 xEdit = self.xUITest.getFocusWindow()
87 self.assertEqual(get_state_as_dict(xEdit)["Text"], "2.72")
88
89 # Modify the field so that the we can save the record
90 xEdit.executeAction("SET", mkPropertyValues({"TEXT": "2.71"}))
91
92 self.xUITest.executeCommandForProvider(".uno:RecSave", xTableFrame)
93
94 # Check that the default values actually entered the database
95 xDbController = self.ui_test.get_desktop().getActiveFrame().getController()
96 xConnection = xDbController.ActiveConnection
97 xStatement = xConnection.createStatement()
98 xResultSet = xStatement.executeQuery("SELECT \"FrenchField\", \"EnglishField\" "
99 "FROM \"Table1\"")
100 self.assertTrue(xResultSet.next())
101 self.assertEqual(xResultSet.getString(1), "3.14")
102 self.assertEqual(xResultSet.getString(2), "2.71")
103
104 # vim: set shiftwidth=4 softtabstop=4 expandtab: