Update git submodules
[LibreOffice.git] / sc / qa / uitest / range_name / tdf119954.py
blob8bea8d6c3c6f0bb9eb3091da5c02eaeacccaabf3
1 # -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*-
3 # This file is part of the LibreOffice project.
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/.
9 from uitest.framework import UITestCase
10 from uitest.uihelper.calc import enter_text_to_cell
11 from uitest.uihelper.common import get_url_for_data_file, type_text
12 from uitest.uihelper.keyboard import select_all
14 from libreoffice.calc.document import get_cell_by_position
15 from libreoffice.uno.propertyvalue import mkPropertyValues
18 # Bug 119954 - Using a second defined database range in formula expression switches to first range.
19 class tdf119954(UITestCase):
20 def test_tdf119954_second_db_range(self):
21 with self.ui_test.load_file(get_url_for_data_file("tdf119954.ods")) as calc_doc:
22 xCalcDoc = self.xUITest.getTopFocusWindow()
23 gridwin = xCalcDoc.getChild("grid_window")
24 #* new document
25 #* in A1 enter 1
26 #* in C3 enter 2
27 #* on A1 define a database range 'aaa' with $Sheet1.$A$1
28 #* on C3 define a database range 'bbb' with $Sheet2.$C$3
29 #* in any cell enter formula =bbb
30 # => result is 1 instead of 2
31 #* place cell cursor on that formula cell again
32 # => see that the formula is =aaa instead of =bbb
34 gridwin.executeAction("SELECT", mkPropertyValues({"CELL": "A1"}))
35 with self.ui_test.execute_modeless_dialog_through_command(".uno:DefineDBName") as xDefineNameDlg:
36 xEntryBox = xDefineNameDlg.getChild("entry")
37 type_text(xEntryBox, "aaa")
38 add = xDefineNameDlg.getChild("add")
39 assign = xDefineNameDlg.getChild("assign")
40 add.executeAction("CLICK", tuple())
42 gridwin.executeAction("SELECT", mkPropertyValues({"CELL": "A1"}))
43 with self.ui_test.execute_modeless_dialog_through_command(".uno:DefineDBName") as xDefineNameDlg:
44 xEntryBox = xDefineNameDlg.getChild("entry")
45 add = xDefineNameDlg.getChild("add")
46 assign = xDefineNameDlg.getChild("assign")
47 select_all(xEntryBox)
48 type_text(xEntryBox, "bbb")
49 select_all(assign)
50 type_text(assign, "$Sheet2.$C$3")
51 add.executeAction("CLICK", tuple())
53 enter_text_to_cell(gridwin, "B2", "=bbb")
54 gridwin.executeAction("TYPE", mkPropertyValues({"KEYCODE": "RETURN"}))
55 self.assertEqual(get_cell_by_position(calc_doc, 0, 1, 1).getValue(), 2)
57 enter_text_to_cell(gridwin, "C2", "=aaa")
58 gridwin.executeAction("TYPE", mkPropertyValues({"KEYCODE": "RETURN"}))
59 self.assertEqual(get_cell_by_position(calc_doc, 0, 2, 1).getValue(), 1)
61 self.xUITest.executeCommand(".uno:Undo")
62 self.xUITest.executeCommand(".uno:Undo")
63 self.assertEqual(get_cell_by_position(calc_doc, 0, 2, 1).getValue(), 0)
64 self.assertEqual(get_cell_by_position(calc_doc, 0, 1, 1).getValue(), 0)
65 self.assertEqual(get_cell_by_position(calc_doc, 0, 1, 2).getFormula(), "")
66 self.assertEqual(get_cell_by_position(calc_doc, 0, 1, 1).getFormula(), "")
68 # check cancel button
69 with self.ui_test.execute_modeless_dialog_through_command(".uno:DefineDBName", close_button="cancel"):
70 pass
72 # vim: set shiftwidth=4 softtabstop=4 expandtab: