Avoid potential negative array index access to cached text.
[LibreOffice.git] / sc / qa / uitest / key_f4 / f4.py
blobd132dd5ac2cc6b5f1d80c45eb449901bb74ab7a7
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
12 from libreoffice.uno.propertyvalue import mkPropertyValues
13 from libreoffice.calc.document import get_cell_by_position
16 class keyF4(UITestCase):
17 def test_f4(self):
18 with self.ui_test.create_doc_in_start_center("calc") as document:
19 xCalcDoc = self.xUITest.getTopFocusWindow()
20 gridwin = xCalcDoc.getChild("grid_window")
21 #enter data
22 enter_text_to_cell(gridwin, "A1", "1")
23 enter_text_to_cell(gridwin, "A2", "2")
24 enter_text_to_cell(gridwin, "A3", "3")
25 enter_text_to_cell(gridwin, "B1", "=A1")
26 enter_text_to_cell(gridwin, "B2", "=A2")
27 enter_text_to_cell(gridwin, "B3", "=A3")
28 #select B1
29 gridwin.executeAction("SELECT", mkPropertyValues({"CELL": "B1"}))
30 #F4
31 gridwin.executeAction("TYPE", mkPropertyValues({"KEYCODE": "F4"}))
32 #verify
33 self.assertEqual(get_cell_by_position(document, 0, 1, 0).getValue(), 1)
34 self.assertEqual(get_cell_by_position(document, 0, 1, 0).getFormula(), "=$A$1")
35 #F4
36 gridwin.executeAction("TYPE", mkPropertyValues({"KEYCODE": "F4"}))
37 #verify
38 self.assertEqual(get_cell_by_position(document, 0, 1, 0).getValue(), 1)
39 self.assertEqual(get_cell_by_position(document, 0, 1, 0).getFormula(), "=A$1")
40 #F4
41 gridwin.executeAction("TYPE", mkPropertyValues({"KEYCODE": "F4"}))
42 #verify
43 self.assertEqual(get_cell_by_position(document, 0, 1, 0).getValue(), 1)
44 self.assertEqual(get_cell_by_position(document, 0, 1, 0).getFormula(), "=$A1")
46 #non continuous select
47 #enter data
48 enter_text_to_cell(gridwin, "C1", "=A1")
49 enter_text_to_cell(gridwin, "C2", "=A2")
50 enter_text_to_cell(gridwin, "C3", "=A3")
52 #select C1 and C3
53 gridwin.executeAction("SELECT", mkPropertyValues({"CELL": "C1"}))
54 gridwin.executeAction("SELECT", mkPropertyValues({"CELL": "C3", "EXTEND":"1"}))
55 #F4
56 gridwin.executeAction("TYPE", mkPropertyValues({"KEYCODE": "F4"}))
57 #verify
58 self.assertEqual(get_cell_by_position(document, 0, 2, 0).getValue(), 1)
59 self.assertEqual(get_cell_by_position(document, 0, 2, 0).getFormula(), "=$A$1")
60 self.assertEqual(get_cell_by_position(document, 0, 2, 2).getValue(), 3)
61 self.assertEqual(get_cell_by_position(document, 0, 2, 2).getFormula(), "=$A$3")
62 #F4
63 gridwin.executeAction("TYPE", mkPropertyValues({"KEYCODE": "F4"}))
64 #verify
65 self.assertEqual(get_cell_by_position(document, 0, 2, 0).getValue(), 1)
66 self.assertEqual(get_cell_by_position(document, 0, 2, 0).getFormula(), "=A$1")
67 self.assertEqual(get_cell_by_position(document, 0, 2, 2).getValue(), 3)
68 self.assertEqual(get_cell_by_position(document, 0, 2, 2).getFormula(), "=A$3")
69 #F4
70 gridwin.executeAction("TYPE", mkPropertyValues({"KEYCODE": "F4"}))
71 #verify
72 self.assertEqual(get_cell_by_position(document, 0, 2, 0).getValue(), 1)
73 self.assertEqual(get_cell_by_position(document, 0, 2, 0).getFormula(), "=$A1")
74 self.assertEqual(get_cell_by_position(document, 0, 2, 2).getValue(), 3)
75 self.assertEqual(get_cell_by_position(document, 0, 2, 2).getFormula(), "=$A3")
77 # vim: set shiftwidth=4 softtabstop=4 expandtab: