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
.common
import get_state_as_dict
, get_url_for_data_file
, type_text
, select_pos
14 from uitest
.uihelper
.calc
import enter_text_to_cell
16 class ManualCalcTests(UITestCase
):
18 # http://manual-test.libreoffice.org/manage/case/189/
19 def test_define_database_range(self
):
21 with self
.ui_test
.create_doc_in_start_center("calc"):
24 xGridWin
= self
.xUITest
.getTopFocusWindow().getChild("grid_window")
25 xGridWin
.executeAction("SELECT", mkPropertyValues({"RANGE": "A1:D10"}))
27 # Execute "Define DB Range dialog"
28 with self
.ui_test
.execute_modeless_dialog_through_command(".uno:DefineDBName") as xDefineNameDlg
:
31 xEntryBox
= xDefineNameDlg
.getChild("entry")
32 type_text(xEntryBox
, "my_database")
36 xGridWin
.executeAction("SELECT", mkPropertyValues({"CELL": "A1"}))
38 # Execute "Select DB Range dialog"
39 with self
.ui_test
.execute_dialog_through_command(".uno:SelectDB") as xSelectNameDlg
:
41 xListBox
= xSelectNameDlg
.getChild("treeview")
42 xListBoxState
= get_state_as_dict(xListBox
)
43 self
.assertEqual(xListBoxState
["SelectionCount"], "1")
44 self
.assertEqual(xListBoxState
["SelectEntryText"], "my_database")
46 # Assert that the correct range has been selected
47 gridWinState
= get_state_as_dict(xGridWin
)
48 self
.assertEqual(gridWinState
["MarkedArea"], "Sheet1.A1:Sheet1.D10")
51 # http://manual-test.libreoffice.org/manage/case/190/
52 def test_sort_data(self
):
53 with self
.ui_test
.create_doc_in_start_center("calc") as document
:
56 xGridWin
= self
.xUITest
.getTopFocusWindow().getChild("grid_window")
57 enter_text_to_cell(xGridWin
, "B1", "3")
58 enter_text_to_cell(xGridWin
, "B2", "25")
59 enter_text_to_cell(xGridWin
, "B3", "17")
60 enter_text_to_cell(xGridWin
, "B4", "9")
61 enter_text_to_cell(xGridWin
, "B5", "19")
62 enter_text_to_cell(xGridWin
, "B6", "0")
63 enter_text_to_cell(xGridWin
, "B7", "107")
64 enter_text_to_cell(xGridWin
, "B8", "89")
65 enter_text_to_cell(xGridWin
, "B9", "8")
66 enter_text_to_cell(xGridWin
, "B10", "33")
68 xGridWin
.executeAction("SELECT", mkPropertyValues({"RANGE": "B1:B10"}))
70 # Execute "Sort" dialog
71 with self
.ui_test
.execute_dialog_through_command(".uno:DataSort"):
75 self
.assertEqual(get_cell_by_position(document
, 0, 1, 0).getValue(), 0)
76 self
.assertEqual(get_cell_by_position(document
, 0, 1, 1).getValue(), 3)
77 self
.assertEqual(get_cell_by_position(document
, 0, 1, 2).getValue(), 8)
78 self
.assertEqual(get_cell_by_position(document
, 0, 1, 3).getValue(), 9)
79 self
.assertEqual(get_cell_by_position(document
, 0, 1, 4).getValue(), 17)
80 self
.assertEqual(get_cell_by_position(document
, 0, 1, 5).getValue(), 19)
81 self
.assertEqual(get_cell_by_position(document
, 0, 1, 6).getValue(), 25)
82 self
.assertEqual(get_cell_by_position(document
, 0, 1, 7).getValue(), 33)
83 self
.assertEqual(get_cell_by_position(document
, 0, 1, 8).getValue(), 89)
84 self
.assertEqual(get_cell_by_position(document
, 0, 1, 9).getValue(), 107)
87 # http://manual-test.libreoffice.org/manage/case/191/
88 def test_validation(self
):
89 with self
.ui_test
.create_doc_in_start_center("calc"):
91 xGridWin
= self
.xUITest
.getTopFocusWindow().getChild("grid_window")
92 xGridWin
.executeAction("SELECT", mkPropertyValues({"RANGE": "A1:C10"}))
94 with self
.ui_test
.execute_dialog_through_command(".uno:Validation") as xValidationDlg
:
96 xAllowList
= xValidationDlg
.getChild("allow")
97 select_pos(xAllowList
, "1")
99 xData
= xValidationDlg
.getChild("data")
100 select_pos(xData
, "5")
102 xVal
= xValidationDlg
.getChild("max")
103 xVal
.executeAction("TYPE", mkPropertyValues({"TEXT":"0"}))
106 def enter_text(cell
, text
):
107 enter_text_to_cell(xGridWin
, cell
, text
)
109 with self
.ui_test
.execute_blocking_action(enter_text
, args
=("A1", "abc")):
111 with self
.ui_test
.execute_blocking_action(enter_text
, args
=("B6", "2.18")):
114 enter_text_to_cell(xGridWin
, "C2", "24")
117 # http://manual-test.libreoffice.org/manage/case/187/
118 def test_transpose(self
):
119 with self
.ui_test
.create_doc_in_start_center("calc") as document
:
121 xGridWin
= self
.xUITest
.getTopFocusWindow().getChild("grid_window")
122 enter_text_to_cell(xGridWin
, "B3", "abcd")
123 enter_text_to_cell(xGridWin
, "B4", "edfg")
124 enter_text_to_cell(xGridWin
, "C3", "35")
125 enter_text_to_cell(xGridWin
, "C4", "5678")
127 xGridWin
.executeAction("SELECT", mkPropertyValues({"RANGE": "A1:C10"}))
129 self
.xUITest
.executeCommand(".uno:Cut")
131 xGridWin
.executeAction("SELECT", mkPropertyValues({"CELL": "A1"}))
133 with self
.ui_test
.execute_dialog_through_command(".uno:PasteSpecial") as xPasteSpecialDlg
:
135 xAllChkBox
= xPasteSpecialDlg
.getChild("paste_all")
136 xAllChkBox
.executeAction("CLICK", tuple())
138 xTransposeChkBox
= xPasteSpecialDlg
.getChild("transpose")
139 xTransposeChkBox
.executeAction("CLICK", tuple())
142 self
.assertEqual(get_cell_by_position(document
, 0, 2, 1).getString(), "abcd")
143 self
.assertEqual(get_cell_by_position(document
, 0, 2, 2).getValue(), 35)
144 self
.assertEqual(get_cell_by_position(document
, 0, 3, 1).getString(), "edfg")
145 self
.assertEqual(get_cell_by_position(document
, 0, 3, 2).getValue(), 5678)
148 # http://manual-test.libreoffice.org/manage/case/151/
149 def test_cell_recalc(self
):
150 with self
.ui_test
.load_file(get_url_for_data_file("cell_recalc.ods")) as document
:
152 xGridWin
= self
.xUITest
.getTopFocusWindow().getChild("grid_window")
153 xGridWin
.executeAction("SELECT", mkPropertyValues({"RANGE": "D2:D9"}))
154 self
.xUITest
.executeCommand(".uno:Cut")
156 self
.assertEqual(get_cell_by_position(document
, 0, 3, 15).getValue(), 0)
158 self
.xUITest
.executeCommand(".uno:Undo")
160 for i
in range(1, 9):
161 self
.assertTrue(get_cell_by_position(document
, 0, 3, i
).getValue() != 0)
163 self
.assertEqual(get_cell_by_position(document
, 0, 3, 15).getValue(), 195)
165 # http://manual-test.libreoffice.org/manage/case/143/
166 def test_random_numbers(self
):
167 with self
.ui_test
.create_doc_in_start_center("calc") as document
:
168 xGridWin
= self
.xUITest
.getTopFocusWindow().getChild("grid_window")
170 xGridWin
.executeAction("SELECT", mkPropertyValues({"RANGE": "A2:A10"}))
172 with self
.ui_test
.execute_modeless_dialog_through_command(".uno:RandomNumberGeneratorDialog") as xRandomNumberDlg
:
173 xDistributionLstBox
= xRandomNumberDlg
.getChild("distribution-combo")
174 select_pos(xDistributionLstBox
, "1")
176 xMin
= xRandomNumberDlg
.getChild("parameter1-spin")
177 xMin
.executeAction("TYPE", mkPropertyValues({"KEYCODE": "CTRL+A"}))
178 xMin
.executeAction("TYPE", mkPropertyValues({"TEXT": "-2"}))
179 xMax
= xRandomNumberDlg
.getChild("parameter2-spin")
180 xMax
.executeAction("TYPE", mkPropertyValues({"KEYCODE": "CTRL+A"}))
181 xMax
.executeAction("TYPE", mkPropertyValues({"TEXT": "10"}))
183 xApplyBtn
= xRandomNumberDlg
.getChild("apply")
184 xApplyBtn
.executeAction("CLICK", tuple())
187 def check_random_values():
188 for i
in range(1, 9):
189 val
= get_cell_by_position(document
, 0, 0, i
).getValue()
190 self
.assertTrue(val
<= 10 and val
>= -2)
192 check_random_values()
195 # we might want to check that clicking 'ok' actually changes the values
196 check_random_values()
199 # vim: set shiftwidth=4 softtabstop=4 expandtab: