bump product version to 6.3.0.0.beta1
[LibreOffice.git] / uitest / manual_tests / calc.py
blob1b7897983a38b6a5b7cc0e323273b3736ba3f4d8
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
16 import org.libreoffice.unotest
17 import pathlib
18 import time
20 def get_url_for_data_file(file_name):
21 return pathlib.Path(org.libreoffice.unotest.makeCopyFromTDOC(file_name)).as_uri()
23 class ManualCalcTests(UITestCase):
25 # http://manual-test.libreoffice.org/manage/case/189/
26 def test_define_database_range(self):
28 self.ui_test.create_doc_in_start_center("calc")
30 # Select range A1:D10
31 xGridWin = self.xUITest.getTopFocusWindow().getChild("grid_window")
32 xGridWin.executeAction("SELECT", mkPropertyValues({"RANGE": "A1:D10"}))
34 # Execute "Define DB Range dialog"
35 self.ui_test.execute_modeless_dialog_through_command(".uno:DefineDBName")
37 xDefineNameDlg = self.xUITest.getTopFocusWindow()
39 xEntryBox = xDefineNameDlg.getChild("entry")
40 type_text(xEntryBox, "my_database")
42 xOkBtn = xDefineNameDlg.getChild("ok")
43 self.ui_test.close_dialog_through_button(xOkBtn)
45 # Deselect range
46 xGridWin.executeAction("SELECT", mkPropertyValues({"CELL": "A1"}))
48 # Execute "Select DB Range dialog"
49 self.ui_test.execute_dialog_through_command(".uno:SelectDB")
50 xSelectNameDlg = self.xUITest.getTopFocusWindow()
52 xListBox = xSelectNameDlg.getChild("treeview")
53 xListBoxState = get_state_as_dict(xListBox)
54 self.assertEqual(xListBoxState["SelectionCount"], "1")
55 self.assertEqual(xListBoxState["SelectEntryText"], "my_database")
57 xOkBtn = xSelectNameDlg.getChild("ok")
58 self.ui_test.close_dialog_through_button(xOkBtn)
60 # Assert that the correct range has been selected
61 gridWinState = get_state_as_dict(xGridWin)
62 self.assertEqual(gridWinState["MarkedArea"], "Sheet1.A1:Sheet1.D10")
64 self.ui_test.close_doc()
66 # http://manual-test.libreoffice.org/manage/case/190/
67 def test_sort_data(self):
68 self.ui_test.create_doc_in_start_center("calc")
70 # Insert data
71 xGridWin = self.xUITest.getTopFocusWindow().getChild("grid_window")
72 enter_text_to_cell(xGridWin, "B1", "3")
73 enter_text_to_cell(xGridWin, "B2", "25")
74 enter_text_to_cell(xGridWin, "B3", "17")
75 enter_text_to_cell(xGridWin, "B4", "9")
76 enter_text_to_cell(xGridWin, "B5", "19")
77 enter_text_to_cell(xGridWin, "B6", "0")
78 enter_text_to_cell(xGridWin, "B7", "107")
79 enter_text_to_cell(xGridWin, "B8", "89")
80 enter_text_to_cell(xGridWin, "B9", "8")
81 enter_text_to_cell(xGridWin, "B10", "33")
83 xGridWin.executeAction("SELECT", mkPropertyValues({"RANGE": "B1:B10"}))
85 # Execute "Sort" dialog
86 self.ui_test.execute_dialog_through_command(".uno:DataSort")
87 xSortDlg = self.xUITest.getTopFocusWindow()
89 xOkBtn = xSortDlg.getChild("ok")
90 self.ui_test.close_dialog_through_button(xOkBtn)
92 document = self.ui_test.get_component()
94 self.assertEqual(get_cell_by_position(document, 0, 1, 0).getValue(), 0)
95 self.assertEqual(get_cell_by_position(document, 0, 1, 1).getValue(), 3)
96 self.assertEqual(get_cell_by_position(document, 0, 1, 2).getValue(), 8)
97 self.assertEqual(get_cell_by_position(document, 0, 1, 3).getValue(), 9)
98 self.assertEqual(get_cell_by_position(document, 0, 1, 4).getValue(), 17)
99 self.assertEqual(get_cell_by_position(document, 0, 1, 5).getValue(), 19)
100 self.assertEqual(get_cell_by_position(document, 0, 1, 6).getValue(), 25)
101 self.assertEqual(get_cell_by_position(document, 0, 1, 7).getValue(), 33)
102 self.assertEqual(get_cell_by_position(document, 0, 1, 8).getValue(), 89)
103 self.assertEqual(get_cell_by_position(document, 0, 1, 9).getValue(), 107)
105 time.sleep(2)
106 self.ui_test.close_doc()
108 # http://manual-test.libreoffice.org/manage/case/191/
109 def test_validation(self):
110 self.ui_test.create_doc_in_start_center("calc")
112 xGridWin = self.xUITest.getTopFocusWindow().getChild("grid_window")
113 xGridWin.executeAction("SELECT", mkPropertyValues({"RANGE": "A1:C10"}))
115 self.ui_test.execute_dialog_through_command(".uno:Validation")
116 xValidationDlg = self.xUITest.getTopFocusWindow()
118 xAllowList = xValidationDlg.getChild("allow")
119 xAllowList.executeAction("SELECT", mkPropertyValues({"POS": "1"}))
121 xData = xValidationDlg.getChild("data")
122 xData.executeAction("SELECT", mkPropertyValues({"POS": "5"}))
124 xVal = xValidationDlg.getChild("max")
125 xVal.executeAction("TYPE", mkPropertyValues({"TEXT":"0"}))
127 xOkBtn = xValidationDlg.getChild("ok")
128 self.ui_test.close_dialog_through_button(xOkBtn)
130 def enter_text(cell, text):
131 enter_text_to_cell(xGridWin, cell, text)
133 self.ui_test.execute_blocking_action(enter_text, "ok", args=("A1", "abc"))
134 self.ui_test.execute_blocking_action(enter_text, "ok", args=("B6", "2.18"))
136 enter_text_to_cell(xGridWin, "C2", "24")
138 self.ui_test.close_doc()
140 # http://manual-test.libreoffice.org/manage/case/187/
141 def test_transpose(self):
142 self.ui_test.create_doc_in_start_center("calc")
144 xGridWin = self.xUITest.getTopFocusWindow().getChild("grid_window")
145 enter_text_to_cell(xGridWin, "B3", "abcd")
146 enter_text_to_cell(xGridWin, "B4", "edfg")
147 enter_text_to_cell(xGridWin, "C3", "35")
148 enter_text_to_cell(xGridWin, "C4", "5678")
150 xGridWin.executeAction("SELECT", mkPropertyValues({"RANGE": "A1:C10"}))
152 self.xUITest.executeCommand(".uno:Cut")
154 xGridWin.executeAction("SELECT", mkPropertyValues({"CELL": "A1"}))
156 self.ui_test.execute_dialog_through_command(".uno:PasteSpecial")
158 xPasteSpecialDlg = self.xUITest.getTopFocusWindow()
160 xAllChkBox = xPasteSpecialDlg.getChild("paste_all")
161 xAllChkBox.executeAction("CLICK", tuple())
163 xTransposeChkBox = xPasteSpecialDlg.getChild("transpose")
164 xTransposeChkBox.executeAction("CLICK", tuple())
166 xOkBtn = xPasteSpecialDlg.getChild("ok")
167 self.ui_test.close_dialog_through_button(xOkBtn)
169 document = self.ui_test.get_component()
170 self.assertEqual(get_cell_by_position(document, 0, 2, 1).getString(), "abcd")
171 self.assertEqual(get_cell_by_position(document, 0, 2, 2).getValue(), 35)
172 self.assertEqual(get_cell_by_position(document, 0, 3, 1).getString(), "edfg")
173 self.assertEqual(get_cell_by_position(document, 0, 3, 2).getValue(), 5678)
175 self.ui_test.close_doc()
177 # http://manual-test.libreoffice.org/manage/case/151/
178 def test_cell_recalc(self):
179 doc = self.ui_test.load_file(get_url_for_data_file("cell_recalc.ods"))
181 xGridWin = self.xUITest.getTopFocusWindow().getChild("grid_window")
182 xGridWin.executeAction("SELECT", mkPropertyValues({"RANGE": "D2:D9"}))
183 self.xUITest.executeCommand(".uno:Cut")
185 self.assertEqual(get_cell_by_position(doc, 0, 3, 15).getValue(), 0)
187 self.xUITest.executeCommand(".uno:Undo")
189 for i in range(1, 9):
190 self.assertTrue(get_cell_by_position(doc, 0, 3, i).getValue() != 0)
192 self.assertEqual(get_cell_by_position(doc, 0, 3, 15).getValue(), 195)
194 self.ui_test.close_doc()
196 # http://manual-test.libreoffice.org/manage/case/143/
197 def test_random_numbers(self):
198 self.ui_test.create_doc_in_start_center("calc")
199 xGridWin = self.xUITest.getTopFocusWindow().getChild("grid_window")
201 xGridWin.executeAction("SELECT", mkPropertyValues({"RANGE": "A2:A10"}))
203 self.ui_test.execute_modeless_dialog_through_command(".uno:RandomNumberGeneratorDialog")
204 xRandomNumberDlg = self.xUITest.getTopFocusWindow()
205 xDistributionLstBox = xRandomNumberDlg.getChild("distribution-combo")
206 xDistributionLstBox.executeAction("SELECT", mkPropertyValues({"POS": "1"}))
208 xMin = xRandomNumberDlg.getChild("parameter1-spin")
209 xMin.executeAction("TYPE", mkPropertyValues({"KEYCODE": "CTRL+A"}))
210 xMin.executeAction("TYPE", mkPropertyValues({"TEXT": "-2"}))
211 xMax = xRandomNumberDlg.getChild("parameter2-spin")
212 xMax.executeAction("TYPE", mkPropertyValues({"KEYCODE": "CTRL+A"}))
213 xMax.executeAction("TYPE", mkPropertyValues({"TEXT": "10"}))
215 xApplyBtn = xRandomNumberDlg.getChild("apply")
216 xApplyBtn.executeAction("CLICK", tuple())
218 doc = self.ui_test.get_component()
220 def check_random_values():
221 for i in range(1, 9):
222 val = get_cell_by_position(doc, 0, 0, i).getValue()
223 self.assertTrue(val <= 10 and val >= -2)
225 check_random_values()
227 xOkBtn = xRandomNumberDlg.getChild("ok")
228 self.ui_test.close_dialog_through_button(xOkBtn)
230 # we might want to check that clicking 'ok' actually changes the values
231 check_random_values()
233 self.ui_test.close_doc()
235 # vim: set shiftwidth=4 softtabstop=4 expandtab: