Avoid potential negative array index access to cached text.
[LibreOffice.git] / sc / qa / uitest / search_replace / tdf44398.py
blob0fe70817a082144ae6e6f454542848f276888c3e
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_state_as_dict
13 from libreoffice.calc.document import get_cell_by_position
14 from libreoffice.uno.propertyvalue import mkPropertyValues
17 # Bug 44398 - : Find, replace, regular expression bug
18 class tdf44398(UITestCase):
19 def test_tdf44398_find_replace_regexp(self):
20 with self.ui_test.create_doc_in_start_center("calc") as document:
21 xCalcDoc = self.xUITest.getTopFocusWindow()
22 gridwin = xCalcDoc.getChild("grid_window")
24 # 1. A1 => 123456
25 enter_text_to_cell(gridwin, "A1", "123456")
26 # 2. ctrl-h, in dialog
27 # Search: ([0-9])
28 # Replace: $1
29 # check regular expression
30 # hit replace all
32 with self.ui_test.execute_modeless_dialog_through_command(".uno:SearchDialog", close_button="close") as xDialog:
33 searchterm = xDialog.getChild("searchterm")
34 searchterm.executeAction("TYPE", mkPropertyValues({"KEYCODE":"CTRL+A"}))
35 searchterm.executeAction("TYPE", mkPropertyValues({"KEYCODE":"BACKSPACE"}))
36 searchterm.executeAction("TYPE", mkPropertyValues({"TEXT":"([0-9])"}))
37 replaceterm = xDialog.getChild("replaceterm")
38 replaceterm.executeAction("TYPE", mkPropertyValues({"TEXT":"$1"})) #replace textbox
39 regexp = xDialog.getChild("regexp")
40 regexp.executeAction("CLICK", tuple())
41 self.assertEqual("true", get_state_as_dict(regexp)['Selected'])
42 replaceall = xDialog.getChild("replaceall")
43 replaceall.executeAction("CLICK", tuple())
45 # Deselect regex button, otherwise it might affect other tests
46 regexp.executeAction("CLICK", tuple())
47 self.assertEqual("false", get_state_as_dict(regexp)['Selected'])
49 #verify 3. A1 => 123456
50 self.assertEqual(get_cell_by_position(document, 0, 0, 0).getString(), "123456")
53 def test_tdf44398_find_replace_regexp_string(self):
54 with self.ui_test.create_doc_in_start_center("calc") as document:
55 xCalcDoc = self.xUITest.getTopFocusWindow()
56 gridwin = xCalcDoc.getChild("grid_window")
58 # 1. A1 => VarNumberA
59 enter_text_to_cell(gridwin, "A1", "VarNumberA")
60 gridwin.executeAction("TYPE", mkPropertyValues({"KEYCODE":"RIGHT"}))
61 # 2. ctrl-h, in dialog
62 # Search: ([A-Z])
63 # Replace: <space>$1
64 # check regular expression
65 # check case
66 # hit replace all
68 with self.ui_test.execute_modeless_dialog_through_command(".uno:SearchDialog", close_button="close") as xDialog:
69 searchterm = xDialog.getChild("searchterm")
70 searchterm.executeAction("TYPE", mkPropertyValues({"KEYCODE":"CTRL+A"}))
71 searchterm.executeAction("TYPE", mkPropertyValues({"KEYCODE":"BACKSPACE"}))
72 searchterm.executeAction("TYPE", mkPropertyValues({"TEXT":"([A-Z])"}))
73 replaceterm = xDialog.getChild("replaceterm")
74 replaceterm.executeAction("TYPE", mkPropertyValues({"TEXT":" $1"})) #replace textbox
75 regexp = xDialog.getChild("regexp")
76 regexp.executeAction("CLICK", tuple())
77 self.assertEqual("true", get_state_as_dict(regexp)['Selected'])
78 matchcase = xDialog.getChild("matchcase")
79 matchcase.executeAction("CLICK", tuple()) #case
81 replaceall = xDialog.getChild("replaceall")
82 replaceall.executeAction("CLICK", tuple())
84 # Deselect regex button, otherwise it might affect other tests
85 regexp.executeAction("CLICK", tuple())
86 self.assertEqual("false", get_state_as_dict(regexp)['Selected'])
88 #verify A1 => ' Var Number A'
89 self.assertEqual(get_cell_by_position(document, 0, 0, 0).getString(), " Var Number A")
91 # vim: set shiftwidth=4 softtabstop=4 expandtab: