Avoid potential negative array index access to cached text.
[LibreOffice.git] / sc / qa / uitest / calc_tests / columns.py
blobed594510f1755b1f30ecb4074c6b18c8b3dca940
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.common import get_state_as_dict
11 from uitest.uihelper.common import change_measurement_unit
12 from libreoffice.uno.propertyvalue import mkPropertyValues
14 class CalcColumns(UITestCase):
15 def test_column_width(self):
16 with self.ui_test.create_doc_in_start_center("calc"):
18 with change_measurement_unit(self, "Centimeter"):
19 xCalcDoc = self.xUITest.getTopFocusWindow()
20 gridwin = xCalcDoc.getChild("grid_window")
22 #select A1
23 gridwin.executeAction("SELECT", mkPropertyValues({"CELL": "A1"}))
24 #column width
25 with self.ui_test.execute_dialog_through_command(".uno:ColumnWidth") as xDialog:
26 xvalue = xDialog.getChild("value")
27 xdefault = xDialog.getChild("default")
28 self.assertEqual(get_state_as_dict(xdefault)["Selected"], "true") #default selected
30 # tdf#144247: Without the fix in place, this test would have failed with
31 # AssertionError: '2.26 cm' != '2.2578 cm'
32 self.assertEqual("2.26 cm", get_state_as_dict(xvalue)["Text"])
33 xvalue.executeAction("UP", tuple())
34 self.assertEqual("2.30 cm", get_state_as_dict(xvalue)["Text"])
35 self.assertEqual(get_state_as_dict(xdefault)["Selected"], "false") #default not selected
36 xdefault.executeAction("CLICK", tuple()) #click default
37 self.assertEqual("2.26 cm", get_state_as_dict(xvalue)["Text"])
39 #write your own value
40 xvalue.executeAction("TYPE", mkPropertyValues({"KEYCODE":"CTRL+A"}))
41 xvalue.executeAction("TYPE", mkPropertyValues({"KEYCODE":"BACKSPACE"}))
42 xvalue.executeAction("TYPE", mkPropertyValues({"TEXT":"1 cm"}))
43 # Click Ok
44 #verify
45 with self.ui_test.execute_dialog_through_command(".uno:ColumnWidth", close_button="cancel") as xDialog:
46 xvalue = xDialog.getChild("value")
47 self.assertEqual(get_state_as_dict(xvalue)["Text"], "1.00 cm")
50 def test_column_width_two_columns(self):
51 with self.ui_test.create_doc_in_start_center("calc"):
53 with change_measurement_unit(self, "Centimeter"):
54 xCalcDoc = self.xUITest.getTopFocusWindow()
55 gridwin = xCalcDoc.getChild("grid_window")
57 gridwin.executeAction("SELECT", mkPropertyValues({"CELL": "A1"}))
58 gridwin.executeAction("SELECT", mkPropertyValues({"CELL": "C1", "EXTEND":"1"}))
60 with self.ui_test.execute_dialog_through_command(".uno:ColumnWidth") as xDialog:
61 xvalue = xDialog.getChild("value")
62 #write your own value
63 xvalue.executeAction("TYPE", mkPropertyValues({"KEYCODE":"CTRL+A"}))
64 xvalue.executeAction("TYPE", mkPropertyValues({"KEYCODE":"BACKSPACE"}))
65 xvalue.executeAction("TYPE", mkPropertyValues({"TEXT":"1 cm"}))
66 # Click Ok
67 #verify
68 gridwin.executeAction("SELECT", mkPropertyValues({"CELL": "A1"}))
69 with self.ui_test.execute_dialog_through_command(".uno:ColumnWidth") as xDialog:
70 xvalue = xDialog.getChild("value")
71 self.assertEqual(get_state_as_dict(xvalue)["Text"], "1.00 cm")
73 gridwin.executeAction("SELECT", mkPropertyValues({"CELL": "C1"}))
74 with self.ui_test.execute_dialog_through_command(".uno:ColumnWidth") as xDialog:
75 xvalue = xDialog.getChild("value")
76 self.assertEqual(get_state_as_dict(xvalue)["Text"], "1.00 cm")
79 def test_column_width_copy(self):
80 with self.ui_test.create_doc_in_start_center("calc"):
82 with change_measurement_unit(self, "Centimeter"):
83 xCalcDoc = self.xUITest.getTopFocusWindow()
84 gridwin = xCalcDoc.getChild("grid_window")
86 #select A1
87 gridwin.executeAction("SELECT", mkPropertyValues({"CELL": "A1"}))
88 #column width
89 with self.ui_test.execute_dialog_through_command(".uno:ColumnWidth") as xDialog:
90 xvalue = xDialog.getChild("value")
91 xvalue.executeAction("TYPE", mkPropertyValues({"KEYCODE":"CTRL+A"}))
92 xvalue.executeAction("TYPE", mkPropertyValues({"KEYCODE":"BACKSPACE"}))
93 xvalue.executeAction("TYPE", mkPropertyValues({"TEXT":"1 cm"}))
94 # Click Ok
95 #select column 1
96 self.xUITest.executeCommand(".uno:SelectColumn")
97 #copy
98 self.xUITest.executeCommand(".uno:Copy")
99 #select C1
100 gridwin.executeAction("SELECT", mkPropertyValues({"CELL": "C1"}))
101 #paste
102 self.xUITest.executeCommand(".uno:Paste")
103 #verify
104 gridwin.executeAction("SELECT", mkPropertyValues({"CELL": "C1"}))
105 with self.ui_test.execute_dialog_through_command(".uno:ColumnWidth") as xDialog:
106 xvalue = xDialog.getChild("value")
107 self.assertEqual(get_state_as_dict(xvalue)["Text"], "1.00 cm")
110 def test_column_hide_show(self):
111 with self.ui_test.create_doc_in_start_center("calc"):
112 xCalcDoc = self.xUITest.getTopFocusWindow()
113 gridwin = xCalcDoc.getChild("grid_window")
114 #select A3
115 gridwin.executeAction("SELECT", mkPropertyValues({"CELL": "C1"}))
116 self.xUITest.executeCommand(".uno:HideColumn") #uno command moves focus one cell down
117 #verify D1
118 gridWinState = get_state_as_dict(gridwin)
119 self.assertEqual(gridWinState["CurrentColumn"], "3")
120 gridwin.executeAction("TYPE", mkPropertyValues({"KEYCODE":"LEFT"}))
121 #verify B (column C is hidden)
122 gridWinState = get_state_as_dict(gridwin)
123 self.assertEqual(gridWinState["CurrentColumn"], "1")
124 #Show hidden column: select B1:D1
125 gridwin.executeAction("SELECT", mkPropertyValues({"RANGE": "B1:D1"}))
126 self.xUITest.executeCommand(".uno:ShowColumn")
127 #verify
128 gridwin.executeAction("SELECT", mkPropertyValues({"CELL": "D1"}))
129 gridWinState = get_state_as_dict(gridwin)
130 self.assertEqual(gridWinState["CurrentColumn"], "3")
131 gridwin.executeAction("TYPE", mkPropertyValues({"KEYCODE":"LEFT"}))
132 #verify C1 (COlumn C is not hidden)
133 gridWinState = get_state_as_dict(gridwin)
134 self.assertEqual(gridWinState["CurrentColumn"], "2")
137 def test_column_test_move(self):
138 with self.ui_test.create_doc_in_start_center("calc"):
139 xCalcDoc = self.xUITest.getTopFocusWindow()
140 gridwin = xCalcDoc.getChild("grid_window")
141 #select C1
142 gridwin.executeAction("SELECT", mkPropertyValues({"CELL": "C1"}))
143 gridWinState = get_state_as_dict(gridwin)
144 self.assertEqual(gridWinState["CurrentColumn"], "2")
145 #right
146 gridwin.executeAction("TYPE", mkPropertyValues({"KEYCODE":"RIGHT"}))
147 #verify D1
148 gridWinState = get_state_as_dict(gridwin)
149 self.assertEqual(gridWinState["CurrentColumn"], "3")
150 gridwin.executeAction("TYPE", mkPropertyValues({"KEYCODE":"LEFT"}))
151 #verify C1
152 gridWinState = get_state_as_dict(gridwin)
153 self.assertEqual(gridWinState["CurrentColumn"], "2")
156 def test_tdf117522_column_width_insert_left(self):
157 with self.ui_test.create_doc_in_start_center("calc"):
159 with change_measurement_unit(self, "Centimeter"):
160 xCalcDoc = self.xUITest.getTopFocusWindow()
161 gridwin = xCalcDoc.getChild("grid_window")
163 #select C1
164 gridwin.executeAction("SELECT", mkPropertyValues({"CELL": "C1"}))
165 #column width
166 with self.ui_test.execute_dialog_through_command(".uno:ColumnWidth") as xDialog:
167 xvalue = xDialog.getChild("value")
168 xvalue.executeAction("TYPE", mkPropertyValues({"KEYCODE":"CTRL+A"}))
169 xvalue.executeAction("TYPE", mkPropertyValues({"KEYCODE":"BACKSPACE"}))
170 xvalue.executeAction("TYPE", mkPropertyValues({"TEXT":"1 cm"}))
171 # Click Ok
172 #select D1
173 gridwin.executeAction("SELECT", mkPropertyValues({"CELL": "D1"}))
174 #column width
175 with self.ui_test.execute_dialog_through_command(".uno:ColumnWidth") as xDialog:
176 xvalue = xDialog.getChild("value")
177 xvalue.executeAction("TYPE", mkPropertyValues({"KEYCODE":"CTRL+A"}))
178 xvalue.executeAction("TYPE", mkPropertyValues({"KEYCODE":"BACKSPACE"}))
179 xvalue.executeAction("TYPE", mkPropertyValues({"TEXT":"2 cm"}))
180 # Click Ok
181 #select E1
182 gridwin.executeAction("SELECT", mkPropertyValues({"CELL": "E1"}))
183 #column width
184 with self.ui_test.execute_dialog_through_command(".uno:ColumnWidth") as xDialog:
185 xvalue = xDialog.getChild("value")
186 xvalue.executeAction("TYPE", mkPropertyValues({"KEYCODE":"CTRL+A"}))
187 xvalue.executeAction("TYPE", mkPropertyValues({"KEYCODE":"BACKSPACE"}))
188 xvalue.executeAction("TYPE", mkPropertyValues({"TEXT":"3 cm"}))
189 # Click Ok
190 #select columns C-E
191 gridwin.executeAction("SELECT", mkPropertyValues({"RANGE": "C1:E1"}))
192 self.xUITest.executeCommand(".uno:SelectColumn")
193 #Insert Columns Left
194 self.xUITest.executeCommand(".uno:InsertColumnsBefore")
195 #verify
196 gridwin.executeAction("SELECT", mkPropertyValues({"CELL": "C1"}))
197 with self.ui_test.execute_dialog_through_command(".uno:ColumnWidth") as xDialog:
198 xvalue = xDialog.getChild("value")
199 self.assertEqual(get_state_as_dict(xvalue)["Text"], "1.00 cm")
201 gridwin.executeAction("SELECT", mkPropertyValues({"CELL": "D1"}))
202 with self.ui_test.execute_dialog_through_command(".uno:ColumnWidth") as xDialog:
203 xvalue = xDialog.getChild("value")
204 self.assertEqual(get_state_as_dict(xvalue)["Text"], "2.00 cm")
206 gridwin.executeAction("SELECT", mkPropertyValues({"CELL": "E1"}))
207 with self.ui_test.execute_dialog_through_command(".uno:ColumnWidth") as xDialog:
208 xvalue = xDialog.getChild("value")
209 self.assertEqual(get_state_as_dict(xvalue)["Text"], "3.00 cm")
211 gridwin.executeAction("SELECT", mkPropertyValues({"CELL": "F1"}))
212 with self.ui_test.execute_dialog_through_command(".uno:ColumnWidth") as xDialog:
213 xvalue = xDialog.getChild("value")
214 self.assertEqual(get_state_as_dict(xvalue)["Text"], "1.00 cm")
216 gridwin.executeAction("SELECT", mkPropertyValues({"CELL": "G1"}))
217 with self.ui_test.execute_dialog_through_command(".uno:ColumnWidth") as xDialog:
218 xvalue = xDialog.getChild("value")
219 self.assertEqual(get_state_as_dict(xvalue)["Text"], "2.00 cm")
221 gridwin.executeAction("SELECT", mkPropertyValues({"CELL": "H1"}))
222 with self.ui_test.execute_dialog_through_command(".uno:ColumnWidth") as xDialog:
223 xvalue = xDialog.getChild("value")
224 self.assertEqual(get_state_as_dict(xvalue)["Text"], "3.00 cm")
227 # vim: set shiftwidth=4 softtabstop=4 expandtab: