1 # -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*-
3 # This Source Code Form is subject to the terms of the Mozilla Public
4 # License, v. 2.0. If a copy of the MPL was not distributed with this
5 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 from uitest
.framework
import UITestCase
10 from libreoffice
.uno
.propertyvalue
import mkPropertyValues
11 from libreoffice
.calc
.document
import get_cell_by_position
13 from uitest
.uihelper
.common
import get_state_as_dict
, type_text
14 from uitest
.uihelper
.calc
import enter_text_to_cell
15 from uitest
.path
import get_srcdir_url
19 def get_url_for_data_file(file_name
):
20 return get_srcdir_url() + "/uitest/manual_tests/data/" + file_name
22 class ManualCalcTests(UITestCase
):
24 # http://manual-test.libreoffice.org/manage/case/189/
25 def test_define_database_range(self
):
27 self
.ui_test
.create_doc_in_start_center("calc")
30 xGridWin
= self
.xUITest
.getTopFocusWindow().getChild("grid_window")
31 xGridWin
.executeAction("SELECT", mkPropertyValues({"RANGE": "A1:D10"}))
33 # Execute "Define DB Range dialog"
34 self
.ui_test
.execute_modeless_dialog_through_command(".uno:DefineDBName")
36 xDefineNameDlg
= self
.xUITest
.getTopFocusWindow()
38 xEntryBox
= xDefineNameDlg
.getChild("entry")
39 type_text(xEntryBox
, "my_database")
41 xOkBtn
= xDefineNameDlg
.getChild("ok")
42 self
.ui_test
.close_dialog_through_button(xOkBtn
)
45 xGridWin
.executeAction("SELECT", mkPropertyValues({"CELL": "A1"}))
47 # Execute "Select DB Range dialog"
48 self
.ui_test
.execute_dialog_through_command(".uno:SelectDB")
49 xSelectNameDlg
= self
.xUITest
.getTopFocusWindow()
51 xListBox
= xSelectNameDlg
.getChild("treeview")
52 xListBoxState
= get_state_as_dict(xListBox
)
53 self
.assertEqual(xListBoxState
["SelectEntryCount"], "1")
54 self
.assertEqual(xListBoxState
["SelectEntryText"], "my_database")
56 xOkBtn
= xSelectNameDlg
.getChild("ok")
57 self
.ui_test
.close_dialog_through_button(xOkBtn
)
59 # Assert that the correct range has been selected
60 gridWinState
= get_state_as_dict(xGridWin
)
61 self
.assertEqual(gridWinState
["MarkedArea"], "Sheet1.A1:Sheet1.D10")
63 self
.ui_test
.close_doc()
65 # http://manual-test.libreoffice.org/manage/case/190/
66 def test_sort_data(self
):
67 self
.ui_test
.create_doc_in_start_center("calc")
70 xGridWin
= self
.xUITest
.getTopFocusWindow().getChild("grid_window")
71 enter_text_to_cell(xGridWin
, "B1", "3")
72 enter_text_to_cell(xGridWin
, "B2", "25")
73 enter_text_to_cell(xGridWin
, "B3", "17")
74 enter_text_to_cell(xGridWin
, "B4", "9")
75 enter_text_to_cell(xGridWin
, "B5", "19")
76 enter_text_to_cell(xGridWin
, "B6", "0")
77 enter_text_to_cell(xGridWin
, "B7", "107")
78 enter_text_to_cell(xGridWin
, "B8", "89")
79 enter_text_to_cell(xGridWin
, "B9", "8")
80 enter_text_to_cell(xGridWin
, "B10", "33")
82 xGridWin
.executeAction("SELECT", mkPropertyValues({"RANGE": "B1:B10"}))
84 # Execute "Sort" dialog
85 self
.ui_test
.execute_dialog_through_command(".uno:DataSort")
86 xSortDlg
= self
.xUITest
.getTopFocusWindow()
88 xOkBtn
= xSortDlg
.getChild("ok")
89 self
.ui_test
.close_dialog_through_button(xOkBtn
)
91 document
= self
.ui_test
.get_component()
93 self
.assertEqual(get_cell_by_position(document
, 0, 1, 0).getValue(), 0)
94 self
.assertEqual(get_cell_by_position(document
, 0, 1, 1).getValue(), 3)
95 self
.assertEqual(get_cell_by_position(document
, 0, 1, 2).getValue(), 8)
96 self
.assertEqual(get_cell_by_position(document
, 0, 1, 3).getValue(), 9)
97 self
.assertEqual(get_cell_by_position(document
, 0, 1, 4).getValue(), 17)
98 self
.assertEqual(get_cell_by_position(document
, 0, 1, 5).getValue(), 19)
99 self
.assertEqual(get_cell_by_position(document
, 0, 1, 6).getValue(), 25)
100 self
.assertEqual(get_cell_by_position(document
, 0, 1, 7).getValue(), 33)
101 self
.assertEqual(get_cell_by_position(document
, 0, 1, 8).getValue(), 89)
102 self
.assertEqual(get_cell_by_position(document
, 0, 1, 9).getValue(), 107)
105 self
.ui_test
.close_doc()
107 # http://manual-test.libreoffice.org/manage/case/191/
108 def test_validation(self
):
109 self
.ui_test
.create_doc_in_start_center("calc")
111 xGridWin
= self
.xUITest
.getTopFocusWindow().getChild("grid_window")
112 xGridWin
.executeAction("SELECT", mkPropertyValues({"RANGE": "A1:C10"}))
114 self
.ui_test
.execute_dialog_through_command(".uno:Validation")
115 xValidationDlg
= self
.xUITest
.getTopFocusWindow()
117 xAllowList
= xValidationDlg
.getChild("allow")
118 xAllowList
.executeAction("SELECT", mkPropertyValues({"POS": "1"}))
120 xData
= xValidationDlg
.getChild("data")
121 xData
.executeAction("SELECT", mkPropertyValues({"POS": "5"}))
123 xVal
= xValidationDlg
.getChild("max")
124 xVal
.executeAction("TYPE", mkPropertyValues({"TEXT":"0"}))
126 xOkBtn
= xValidationDlg
.getChild("ok")
127 self
.ui_test
.close_dialog_through_button(xOkBtn
)
129 def enter_text(cell
, text
):
130 enter_text_to_cell(xGridWin
, cell
, text
)
132 self
.ui_test
.execute_blocking_action(enter_text
, "ok", args
=("A1", "abc"))
133 self
.ui_test
.execute_blocking_action(enter_text
, "ok", args
=("B6", "2.18"))
135 enter_text_to_cell(xGridWin
, "C2", "24")
137 self
.ui_test
.close_doc()
139 # http://manual-test.libreoffice.org/manage/case/187/
140 def test_transpose(self
):
141 self
.ui_test
.create_doc_in_start_center("calc")
143 xGridWin
= self
.xUITest
.getTopFocusWindow().getChild("grid_window")
144 enter_text_to_cell(xGridWin
, "B3", "abcd")
145 enter_text_to_cell(xGridWin
, "B4", "edfg")
146 enter_text_to_cell(xGridWin
, "C3", "35")
147 enter_text_to_cell(xGridWin
, "C4", "5678")
149 xGridWin
.executeAction("SELECT", mkPropertyValues({"RANGE": "A1:C10"}))
151 self
.xUITest
.executeCommand(".uno:Cut")
153 xGridWin
.executeAction("SELECT", mkPropertyValues({"CELL": "A1"}))
155 self
.ui_test
.execute_dialog_through_command(".uno:PasteSpecial")
157 xPasteSpecialDlg
= self
.xUITest
.getTopFocusWindow()
159 xAllChkBox
= xPasteSpecialDlg
.getChild("paste_all")
160 xAllChkBox
.executeAction("CLICK", tuple())
162 xTransposeChkBox
= xPasteSpecialDlg
.getChild("transpose")
163 xTransposeChkBox
.executeAction("CLICK", tuple())
165 xOkBtn
= xPasteSpecialDlg
.getChild("ok")
166 self
.ui_test
.close_dialog_through_button(xOkBtn
)
168 document
= self
.ui_test
.get_component()
169 self
.assertEqual(get_cell_by_position(document
, 0, 2, 1).getString(), "abcd")
170 self
.assertEqual(get_cell_by_position(document
, 0, 2, 2).getValue(), 35)
171 self
.assertEqual(get_cell_by_position(document
, 0, 3, 1).getString(), "edfg")
172 self
.assertEqual(get_cell_by_position(document
, 0, 3, 2).getValue(), 5678)
174 self
.ui_test
.close_doc()
176 # http://manual-test.libreoffice.org/manage/case/151/
177 def test_cell_recalc(self
):
178 doc
= self
.ui_test
.load_file(get_url_for_data_file("cell_recalc.ods"))
180 xGridWin
= self
.xUITest
.getTopFocusWindow().getChild("grid_window")
181 xGridWin
.executeAction("SELECT", mkPropertyValues({"RANGE": "D2:D9"}))
182 self
.xUITest
.executeCommand(".uno:Cut")
184 self
.assertEqual(get_cell_by_position(doc
, 0, 3, 15).getValue(), 0)
186 self
.xUITest
.executeCommand(".uno:Undo")
188 for i
in range(1, 9):
189 self
.assertTrue(get_cell_by_position(doc
, 0, 3, i
).getValue() != 0)
191 self
.assertEqual(get_cell_by_position(doc
, 0, 3, 15).getValue(), 195)
193 self
.ui_test
.close_doc()
195 # http://manual-test.libreoffice.org/manage/case/143/
196 def test_random_numbers(self
):
197 self
.ui_test
.create_doc_in_start_center("calc")
198 xGridWin
= self
.xUITest
.getTopFocusWindow().getChild("grid_window")
200 xGridWin
.executeAction("SELECT", mkPropertyValues({"RANGE": "A2:A10"}))
202 self
.ui_test
.execute_modeless_dialog_through_command(".uno:RandomNumberGeneratorDialog")
203 xRandomNumberDlg
= self
.xUITest
.getTopFocusWindow()
204 xDistributionLstBox
= xRandomNumberDlg
.getChild("distribution-combo")
205 xDistributionLstBox
.executeAction("SELECT", mkPropertyValues({"POS": "1"}))
207 xMin
= xRandomNumberDlg
.getChild("parameter1-spin")
208 xMin
.executeAction("TYPE", mkPropertyValues({"KEYCODE": "CTRL+A"}))
209 xMin
.executeAction("TYPE", mkPropertyValues({"TEXT": "-2"}))
210 xMax
= xRandomNumberDlg
.getChild("parameter2-spin")
211 xMax
.executeAction("TYPE", mkPropertyValues({"KEYCODE": "CTRL+A"}))
212 xMax
.executeAction("TYPE", mkPropertyValues({"TEXT": "10"}))
214 xApplyBtn
= xRandomNumberDlg
.getChild("apply")
215 xApplyBtn
.executeAction("CLICK", tuple())
217 doc
= self
.ui_test
.get_component()
219 def check_random_values():
220 for i
in range(1, 9):
221 val
= get_cell_by_position(doc
, 0, 0, i
).getValue()
222 self
.assertTrue(val
<= 10 and val
>= -2)
224 check_random_values()
226 xOkBtn
= xRandomNumberDlg
.getChild("ok")
227 self
.ui_test
.close_dialog_through_button(xOkBtn
)
229 # we might want to check that clicking 'ok' actually changes the values
230 check_random_values()
232 self
.ui_test
.close_doc()
234 # vim: set shiftwidth=4 softtabstop=4 expandtab: