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
.uno
.propertyvalue
import mkPropertyValues
14 from libreoffice
.calc
.document
import get_cell_by_position
17 class keyF4(UITestCase
):
19 with self
.ui_test
.create_doc_in_start_center("calc") as document
:
20 xCalcDoc
= self
.xUITest
.getTopFocusWindow()
21 gridwin
= xCalcDoc
.getChild("grid_window")
23 enter_text_to_cell(gridwin
, "A1", "1")
24 enter_text_to_cell(gridwin
, "A2", "2")
25 enter_text_to_cell(gridwin
, "A3", "3")
26 enter_text_to_cell(gridwin
, "B1", "=A1")
27 enter_text_to_cell(gridwin
, "B2", "=A2")
28 enter_text_to_cell(gridwin
, "B3", "=A3")
30 gridwin
.executeAction("SELECT", mkPropertyValues({"CELL": "B1"}))
32 gridwin
.executeAction("TYPE", mkPropertyValues({"KEYCODE": "F4"}))
34 self
.assertEqual(get_cell_by_position(document
, 0, 1, 0).getValue(), 1)
35 self
.assertEqual(get_cell_by_position(document
, 0, 1, 0).getFormula(), "=$A$1")
37 gridwin
.executeAction("TYPE", mkPropertyValues({"KEYCODE": "F4"}))
39 self
.assertEqual(get_cell_by_position(document
, 0, 1, 0).getValue(), 1)
40 self
.assertEqual(get_cell_by_position(document
, 0, 1, 0).getFormula(), "=A$1")
42 gridwin
.executeAction("TYPE", mkPropertyValues({"KEYCODE": "F4"}))
44 self
.assertEqual(get_cell_by_position(document
, 0, 1, 0).getValue(), 1)
45 self
.assertEqual(get_cell_by_position(document
, 0, 1, 0).getFormula(), "=$A1")
47 #non continuous select
49 enter_text_to_cell(gridwin
, "C1", "=A1")
50 enter_text_to_cell(gridwin
, "C2", "=A2")
51 enter_text_to_cell(gridwin
, "C3", "=A3")
54 gridwin
.executeAction("SELECT", mkPropertyValues({"CELL": "C1"}))
55 gridwin
.executeAction("SELECT", mkPropertyValues({"CELL": "C3", "EXTEND":"1"}))
57 gridwin
.executeAction("TYPE", mkPropertyValues({"KEYCODE": "F4"}))
59 self
.assertEqual(get_cell_by_position(document
, 0, 2, 0).getValue(), 1)
60 self
.assertEqual(get_cell_by_position(document
, 0, 2, 0).getFormula(), "=$A$1")
61 self
.assertEqual(get_cell_by_position(document
, 0, 2, 2).getValue(), 3)
62 self
.assertEqual(get_cell_by_position(document
, 0, 2, 2).getFormula(), "=$A$3")
64 gridwin
.executeAction("TYPE", mkPropertyValues({"KEYCODE": "F4"}))
66 self
.assertEqual(get_cell_by_position(document
, 0, 2, 0).getValue(), 1)
67 self
.assertEqual(get_cell_by_position(document
, 0, 2, 0).getFormula(), "=A$1")
68 self
.assertEqual(get_cell_by_position(document
, 0, 2, 2).getValue(), 3)
69 self
.assertEqual(get_cell_by_position(document
, 0, 2, 2).getFormula(), "=A$3")
71 gridwin
.executeAction("TYPE", mkPropertyValues({"KEYCODE": "F4"}))
73 self
.assertEqual(get_cell_by_position(document
, 0, 2, 0).getValue(), 1)
74 self
.assertEqual(get_cell_by_position(document
, 0, 2, 0).getFormula(), "=$A1")
75 self
.assertEqual(get_cell_by_position(document
, 0, 2, 2).getValue(), 3)
76 self
.assertEqual(get_cell_by_position(document
, 0, 2, 2).getFormula(), "=$A3")
79 def test_tdf39650_F4_R1C1(self
):
80 #Bug 39650 - Shift+F4 conversion from relative to absolute does not work for R1C1 syntax
81 with self
.ui_test
.create_doc_in_start_center("calc") as document
:
82 xCalcDoc
= self
.xUITest
.getTopFocusWindow()
83 gridwin
= xCalcDoc
.getChild("grid_window")
84 #* Tools --> Options --> Calc --> Formula --> Syntax = Excel R1C1
85 with self
.ui_test
.execute_dialog_through_command(".uno:OptionsTreeDialog") as xDialogOpt
:
87 xPages
= xDialogOpt
.getChild("pages")
88 xCalcEntry
= xPages
.getChild('3') # Calc
89 xCalcEntry
.executeAction("EXPAND", tuple())
90 xCalcFormulaEntry
= xCalcEntry
.getChild('4')
91 xCalcFormulaEntry
.executeAction("SELECT", tuple()) #Formula
93 formulasyntax
= xDialogOpt
.getChild("formulasyntax")
95 select_by_text(formulasyntax
, "Excel R1C1")
98 #In cell R3C3 enter "xxx".
99 enter_text_to_cell(gridwin
, "C3", "xxx")
100 # In cell R2C2 type = and then click on the xxx in R3C3.
101 enter_text_to_cell(gridwin
, "B2", "=R[1]C[1]")
102 # With cell R2C2 still selected, type Shift-F4.
103 gridwin
.executeAction("SELECT", mkPropertyValues({"CELL": "B2"}))
106 gridwin
.executeAction("TYPE", mkPropertyValues({"KEYCODE": "F4"}))
108 #This should change the formula in R2C2 from =R[1]C[1] to =R3C3.
109 self
.assertEqual(get_cell_by_position(document
, 0, 1, 1).getString(), "xxx")
110 enter_text_to_cell(gridwin
, "A1", "=FORMULA(R[1]C[1])")
111 self
.assertEqual(get_cell_by_position(document
, 0, 0, 0).getString(), "=R3C3")
113 #Give it back Tools --> Options --> Calc --> Formula --> Syntax = Calc A1
114 with self
.ui_test
.execute_dialog_through_command(".uno:OptionsTreeDialog") as xDialogOpt
:
116 xPages
= xDialogOpt
.getChild("pages")
117 xCalcEntry
= xPages
.getChild('3') # Calc
118 xCalcEntry
.executeAction("EXPAND", tuple())
119 xCalcFormulaEntry
= xCalcEntry
.getChild('4')
120 xCalcFormulaEntry
.executeAction("SELECT", tuple()) #Formula
122 formulasyntax
= xDialogOpt
.getChild("formulasyntax")
124 select_by_text(formulasyntax
, "Calc A1")
126 # vim: set shiftwidth=4 softtabstop=4 expandtab: