Avoid potential negative array index access to cached text.
[LibreOffice.git] / sc / qa / uitest / search_replace / tdf39917.py
blob3a0b06467445a7327b8919b7e7ea2f893c9df9a7
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 select_by_text
13 from libreoffice.calc.document import get_cell_by_position
14 from libreoffice.uno.propertyvalue import mkPropertyValues
16 # Bug 39917 - EDITING Find/Replace modifies formula in R1C1 syntax to invalid lowercase
17 class tdf39917(UITestCase):
18 def change_formula_syntax(self, syntax):
19 with self.ui_test.execute_dialog_through_command(".uno:OptionsTreeDialog") as xDialogOpt:
21 xPages = xDialogOpt.getChild("pages")
22 xCalcEntry = xPages.getChild('3')
23 xCalcEntry.executeAction("EXPAND", tuple())
24 xCalcFormulaEntry = xCalcEntry.getChild('4')
25 xCalcFormulaEntry.executeAction("SELECT", tuple())
27 xFormulaSyntax = xDialogOpt.getChild('formulasyntax')
28 select_by_text(xFormulaSyntax, syntax)
30 def test_tdf39917_find_replace_R1C1(self):
31 with self.ui_test.create_doc_in_start_center("calc") as document:
32 xCalcDoc = self.xUITest.getTopFocusWindow()
33 gridwin = xCalcDoc.getChild("grid_window")
35 try:
36 self.change_formula_syntax("Excel R1C1")
38 #1. Create a workbook with 3 sheets: Page1, Page2, Page3.
39 # 2. Tools -> Options -> LibreOffice Calc -> Formula: Set syntax to Excel A1
40 # 5. Fill fields:
42 with self.ui_test.execute_dialog_through_command(".uno:Insert") as xDialog:
43 after = xDialog.getChild("after")
44 after.executeAction("CLICK", tuple())
45 nameed = xDialog.getChild("nameed")
46 nameed.executeAction("TYPE", mkPropertyValues({"KEYCODE":"CTRL+A"}))
47 nameed.executeAction("TYPE", mkPropertyValues({"KEYCODE":"BACKSPACE"}))
48 nameed.executeAction("TYPE", mkPropertyValues({"TEXT":"Page2"}))
49 with self.ui_test.execute_dialog_through_command(".uno:Insert") as xDialog:
50 after = xDialog.getChild("after")
51 after.executeAction("CLICK", tuple())
52 nameed = xDialog.getChild("nameed")
53 nameed.executeAction("TYPE", mkPropertyValues({"KEYCODE":"CTRL+A"}))
54 nameed.executeAction("TYPE", mkPropertyValues({"KEYCODE":"BACKSPACE"}))
55 nameed.executeAction("TYPE", mkPropertyValues({"TEXT":"Page3"}))
56 gridwin.executeAction("TYPE", mkPropertyValues({"KEYCODE":"RIGHT"}))
57 # 3. Type in (for example) B4: =Page2!B4
58 enter_text_to_cell(gridwin, "B4", "=Page2!RC")
59 # 4. Edit -> Find and Replace
60 # Find: Page2
61 # Replace: Page3
62 # 6. Press Replace all
63 with self.ui_test.execute_modeless_dialog_through_command(".uno:SearchDialog", close_button="close") as xDialog:
64 searchterm = xDialog.getChild("searchterm")
65 searchterm.executeAction("TYPE", mkPropertyValues({"KEYCODE":"CTRL+A"}))
66 searchterm.executeAction("TYPE", mkPropertyValues({"KEYCODE":"BACKSPACE"}))
67 searchterm.executeAction("TYPE", mkPropertyValues({"TEXT":"Page2"}))
68 replaceterm = xDialog.getChild("replaceterm")
69 replaceterm.executeAction("TYPE", mkPropertyValues({"TEXT":"Page3"})) #replace textbox
70 replace = xDialog.getChild("replace")
71 replace.executeAction("CLICK", tuple())
72 replace.executeAction("CLICK", tuple())
74 #verify
75 enter_text_to_cell(gridwin, "A1", "=FORMULA(R[3]C[1])")
76 self.assertEqual(get_cell_by_position(document, 0, 0, 0).getString(), "=Page3!RC")
77 finally:
78 self.change_formula_syntax("Calc A1")
80 # vim: set shiftwidth=4 softtabstop=4 expandtab: