Avoid potential negative array index access to cached text.
[LibreOffice.git] / sc / qa / uitest / calc_tests9 / tdf80043.py
blobeb99f003887171b3eac1f74bdd4845aa74960201
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/.
10 from uitest.framework import UITestCase
11 from libreoffice.uno.propertyvalue import mkPropertyValues
12 from libreoffice.calc.document import get_cell_by_position
13 from uitest.uihelper.calc import enter_text_to_cell
14 from uitest.uihelper.common import get_state_as_dict, select_pos
16 class tdf80043(UITestCase):
17 def test_tdf80043_empty_cell(self):
18 with self.ui_test.create_doc_in_start_center("calc") as document:
19 xCalcDoc = self.xUITest.getTopFocusWindow()
20 xGridWindow = xCalcDoc.getChild("grid_window")
22 # Select an empty cell and insert a hyperlink
23 xGridWindow.executeAction("SELECT", mkPropertyValues({"CELL": "A1"}))
24 with self.ui_test.execute_dialog_through_command(".uno:HyperlinkDialog") as xDialog:
25 xTab = xDialog.getChild("tabcontrol")
26 select_pos(xTab, "0")
28 # Both fields in the hyperlink dialog should be empty
29 xTarget = xDialog.getChild("target")
30 self.assertEqual(get_state_as_dict(xTarget)["Text"], "")
31 xIndication = xDialog.getChild("indication")
32 self.assertEqual(get_state_as_dict(xIndication)["Text"], "")
34 # Insert a sample hyperlink
35 xTarget.executeAction("TYPE", mkPropertyValues({"TEXT": "http://www.libreoffice.org/"}))
36 xIndication.executeAction("TYPE", mkPropertyValues({"TEXT": "LibreOffice"}))
38 # Move focus to ensure cell is not in edit mode
39 xGridWindow.executeAction("SELECT", mkPropertyValues({"CELL": "A2"}))
40 xGridWindow.executeAction("SELECT", mkPropertyValues({"CELL": "A1"}))
42 # Check contents of the cell
43 xCell = get_cell_by_position(document, 0, 0, 0)
44 self.assertEqual(xCell.getString(), "LibreOffice")
45 xTextFields = xCell.getTextFields()
46 self.assertEqual(xTextFields.getCount(), 1)
47 self.assertEqual(xTextFields.getByIndex(0).URL, "http://www.libreoffice.org/")
49 # Reopen hyperlink dialog and check the target and the indication of the hyperlink
50 with self.ui_test.execute_dialog_through_command(".uno:HyperlinkDialog", close_button="cancel") as xDialog:
51 xTab = xDialog.getChild("tabcontrol")
52 select_pos(xTab, "0")
54 # Text should contain the text of the cell
55 xTarget = xDialog.getChild("target")
56 self.assertEqual(get_state_as_dict(xTarget)["Text"], "http://www.libreoffice.org/")
57 xIndication = xDialog.getChild("indication")
58 self.assertEqual(get_state_as_dict(xIndication)["Text"], "LibreOffice")
60 def test_tdf80043_text_cell(self):
61 with self.ui_test.create_doc_in_start_center("calc") as document:
62 xCalcDoc = self.xUITest.getTopFocusWindow()
63 xGridWindow = xCalcDoc.getChild("grid_window")
65 # Select a cell including a text and insert a hyperlink
66 enter_text_to_cell(xGridWindow, "A1", "LibreOffice")
67 # Move focus to ensure cell is not in edit mode
68 xGridWindow.executeAction("SELECT", mkPropertyValues({"CELL": "A2"}))
69 xGridWindow.executeAction("SELECT", mkPropertyValues({"CELL": "A1"}))
70 with self.ui_test.execute_dialog_through_command(".uno:HyperlinkDialog") as xDialog:
71 xTab = xDialog.getChild("tabcontrol")
72 select_pos(xTab, "0")
74 # Text should contain the text of the cell
75 xTarget = xDialog.getChild("target")
76 self.assertEqual(get_state_as_dict(xTarget)["Text"], "")
77 xIndication = xDialog.getChild("indication")
78 self.assertEqual(get_state_as_dict(xIndication)["Text"], "LibreOffice")
80 # Insert a sample hyperlink
81 xTarget.executeAction("TYPE", mkPropertyValues({"TEXT": "http://www.libreoffice.org/"}))
83 # Move focus to ensure cell is not in edit mode
84 xGridWindow.executeAction("SELECT", mkPropertyValues({"CELL": "A2"}))
85 xGridWindow.executeAction("SELECT", mkPropertyValues({"CELL": "A1"}))
87 # Check contents of the cell
88 xCell = get_cell_by_position(document, 0, 0, 0)
89 self.assertEqual(xCell.getString(), "LibreOffice")
90 xTextFields = xCell.getTextFields()
91 self.assertEqual(xTextFields.getCount(), 1)
92 self.assertEqual(xTextFields.getByIndex(0).URL, "http://www.libreoffice.org/")
94 # Reopen hyperlink dialog and check the target and the indication of the hyperlink
95 with self.ui_test.execute_dialog_through_command(".uno:HyperlinkDialog", close_button="cancel") as xDialog:
96 xTab = xDialog.getChild("tabcontrol")
97 select_pos(xTab, "0")
99 # Text should contain the text of the cell
100 xTarget = xDialog.getChild("target")
101 self.assertEqual(get_state_as_dict(xTarget)["Text"], "http://www.libreoffice.org/")
102 xIndication = xDialog.getChild("indication")
103 self.assertEqual(get_state_as_dict(xIndication)["Text"], "LibreOffice")
105 def test_tdf80043_link_text_cell(self):
106 with self.ui_test.create_doc_in_start_center("calc") as document:
107 xCalcDoc = self.xUITest.getTopFocusWindow()
108 xGridWindow = xCalcDoc.getChild("grid_window")
110 # Select a cell including a text and insert a hyperlink
111 enter_text_to_cell(xGridWindow, "A1", "LibreOffice")
112 # Move focus to ensure cell is not in edit mode
113 xGridWindow.executeAction("SELECT", mkPropertyValues({"CELL": "A2"}))
114 xGridWindow.executeAction("SELECT", mkPropertyValues({"CELL": "A1"}))
115 with self.ui_test.execute_dialog_through_command(".uno:HyperlinkDialog") as xDialog:
116 xTab = xDialog.getChild("tabcontrol")
117 select_pos(xTab, "0")
119 # Text should contain the text of the cell
120 xTarget = xDialog.getChild("target")
121 self.assertEqual(get_state_as_dict(xTarget)["Text"], "")
122 xIndication = xDialog.getChild("indication")
123 self.assertEqual(get_state_as_dict(xIndication)["Text"], "LibreOffice")
125 # Insert a sample hyperlink
126 xTarget.executeAction("TYPE", mkPropertyValues({"TEXT": "http://www.libreoffice.org/"}))
128 # Move focus to ensure cell is not in edit mode
129 xGridWindow.executeAction("SELECT", mkPropertyValues({"CELL": "A2"}))
130 xGridWindow.executeAction("SELECT", mkPropertyValues({"CELL": "A1"}))
132 # Insert an additional text without a hyperlink in the cell including a hyperlink
133 self.xUITest.executeCommand(".uno:SetInputMode")
134 enter_text_to_cell(xGridWindow, "A1", " Document Foundation")
136 # Check contents of the cell
137 xCell = get_cell_by_position(document, 0, 0, 0)
138 self.assertEqual(xCell.getString(), "LibreOffice Document Foundation")
139 xTextFields = xCell.getTextFields()
140 self.assertEqual(xTextFields.getCount(), 1)
141 self.assertEqual(xTextFields.getByIndex(0).URL, "http://www.libreoffice.org/")
143 # Move focus to ensure cell is not in edit mode
144 xGridWindow.executeAction("SELECT", mkPropertyValues({"CELL": "A2"}))
145 xGridWindow.executeAction("SELECT", mkPropertyValues({"CELL": "A1"}))
147 # Reopen hyperlink dialog and check the target and the indication of the hyperlink
148 with self.ui_test.execute_dialog_through_command(".uno:HyperlinkDialog") as xDialog:
149 xTab = xDialog.getChild("tabcontrol")
150 select_pos(xTab, "0")
152 # Text should contain the text of the cell
153 xTarget = xDialog.getChild("target")
154 self.assertEqual(get_state_as_dict(xTarget)["Text"], "")
155 xTarget.executeAction("TYPE", mkPropertyValues({"TEXT": "https://www.documentfoundation.org/"}))
156 xIndication = xDialog.getChild("indication")
157 self.assertEqual(get_state_as_dict(xIndication)["Text"], "LibreOffice Document Foundation")
159 # Check contents of the cell - move focus, otherwise text fields won't be updated
160 xGridWindow.executeAction("SELECT", mkPropertyValues({"CELL": "A2"}))
161 xCell = get_cell_by_position(document, 0, 0, 0)
162 self.assertEqual(xCell.getString(), "LibreOffice Document Foundation")
163 xTextFields = xCell.getTextFields()
164 self.assertEqual(xTextFields.getCount(), 1)
165 self.assertEqual(xTextFields.getByIndex(0).URL, "https://www.documentfoundation.org/")
167 def test_tdf80043_link_link_cell(self):
168 with self.ui_test.create_doc_in_start_center("calc") as document:
169 xCalcDoc = self.xUITest.getTopFocusWindow()
170 xGridWindow = xCalcDoc.getChild("grid_window")
172 # Select a cell including a text and insert a hyperlink
173 enter_text_to_cell(xGridWindow, "A1", "Libre")
174 # Move focus to ensure cell is not in edit mode
175 xGridWindow.executeAction("SELECT", mkPropertyValues({"CELL": "A2"}))
176 xGridWindow.executeAction("SELECT", mkPropertyValues({"CELL": "A1"}))
177 with self.ui_test.execute_dialog_through_command(".uno:HyperlinkDialog") as xDialog:
178 xTab = xDialog.getChild("tabcontrol")
179 select_pos(xTab, "0")
181 # Text should contain the text of the cell
182 xTarget = xDialog.getChild("target")
183 self.assertEqual(get_state_as_dict(xTarget)["Text"], "")
184 xIndication = xDialog.getChild("indication")
185 self.assertEqual(get_state_as_dict(xIndication)["Text"], "Libre")
187 # Insert a sample hyperlink
188 xTarget.executeAction("TYPE", mkPropertyValues({"TEXT": "http://www.libreoffice.org/"}))
190 # Move focus to ensure cell is not in edit mode
191 xGridWindow.executeAction("SELECT", mkPropertyValues({"CELL": "A2"}))
192 xGridWindow.executeAction("SELECT", mkPropertyValues({"CELL": "A1"}))
194 # Insert an additional hyperlink in the cell
195 self.xUITest.executeCommand(".uno:SetInputMode")
196 xGridWindow.executeAction("TYPE", mkPropertyValues({"KEYCODE": "Office Document Foundation"}))
197 xGridWindow.executeAction("TYPE", mkPropertyValues({"KEYCODE": "SHIFT+CTRL+LEFT"}))
198 with self.ui_test.execute_dialog_through_command(".uno:HyperlinkDialog") as xDialog:
199 xTab = xDialog.getChild("tabcontrol")
200 select_pos(xTab, "0")
202 # Text should contain the text of the cell
203 xTarget = xDialog.getChild("target")
204 self.assertEqual(get_state_as_dict(xTarget)["Text"], "")
205 xIndication = xDialog.getChild("indication")
206 self.assertEqual(get_state_as_dict(xIndication)["Text"], "Foundation")
208 # Insert a sample hyperlink
209 xTarget.executeAction("TYPE", mkPropertyValues({"TEXT": "https://www.documentfoundation.org/"}))
211 # Check contents of the cell
212 xGridWindow.executeAction("SELECT", mkPropertyValues({"CELL": "A2"}))
213 xCell = get_cell_by_position(document, 0, 0, 0)
214 self.assertEqual(xCell.getString(), "LibreOffice Document Foundation")
215 xTextFields = xCell.getTextFields()
216 self.assertEqual(xTextFields.getCount(), 2)
217 self.assertEqual(xTextFields.getByIndex(0).URL, "http://www.libreoffice.org/")
218 self.assertEqual(xTextFields.getByIndex(1).URL, "https://www.documentfoundation.org/")
220 # Move focus to ensure cell is not in edit mode
221 xGridWindow.executeAction("SELECT", mkPropertyValues({"CELL": "A2"}))
222 xGridWindow.executeAction("SELECT", mkPropertyValues({"CELL": "A1"}))
224 # Reopen hyperlink dialog and check the target and the indication of the hyperlink
225 with self.ui_test.execute_dialog_through_command(".uno:HyperlinkDialog") as xDialog:
226 xTab = xDialog.getChild("tabcontrol")
227 select_pos(xTab, "0")
229 xTarget = xDialog.getChild("target")
230 self.assertEqual(get_state_as_dict(xTarget)["Text"], "")
231 xTarget.executeAction("TYPE", mkPropertyValues({"TEXT": "https://wiki.documentfoundation.org/Main_Page"}))
232 xIndication = xDialog.getChild("indication")
233 self.assertEqual(get_state_as_dict(xIndication)["Text"], "LibreOffice Document Foundation")
235 # Check contents of the cell - move focus, otherwise text fields won't be updated
236 xGridWindow.executeAction("SELECT", mkPropertyValues({"CELL": "A2"}))
237 xCell = get_cell_by_position(document, 0, 0, 0)
238 self.assertEqual(xCell.getString(), "LibreOffice Document Foundation")
239 xTextFields = xCell.getTextFields()
240 self.assertEqual(xTextFields.getCount(), 1)
241 self.assertEqual(xTextFields.getByIndex(0).URL, "https://wiki.documentfoundation.org/Main_Page")
243 # vim: set shiftwidth=4 softtabstop=4 expandtab: