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
.calc
import enter_text_to_cell
15 #https://www.linuxtopia.org/online_books/office_guides/openoffice_3_calc_user_guide/openoffice_calc_Multiple_operations_Multiple_operations_in_columns_or_rows.html
17 class multipleOperations(UITestCase
):
19 def test_multiple_operations_one_variable(self
):
20 with self
.ui_test
.create_doc_in_start_center("calc") as document
:
21 xCalcDoc
= self
.xUITest
.getTopFocusWindow()
22 xGridWindow
= xCalcDoc
.getChild("grid_window")
25 enter_text_to_cell(xGridWindow
, "B1", "10")
26 enter_text_to_cell(xGridWindow
, "B2", "2")
27 enter_text_to_cell(xGridWindow
, "B3", "10000")
28 enter_text_to_cell(xGridWindow
, "B4", "2000")
29 enter_text_to_cell(xGridWindow
, "B5", "=B4*(B1-B2)-B3")
31 enter_text_to_cell(xGridWindow
, "D2", "500")
32 enter_text_to_cell(xGridWindow
, "D3", "1000")
33 enter_text_to_cell(xGridWindow
, "D4", "1500")
34 enter_text_to_cell(xGridWindow
, "D5", "2000")
35 enter_text_to_cell(xGridWindow
, "D6", "2500")
36 enter_text_to_cell(xGridWindow
, "D7", "3000")
37 enter_text_to_cell(xGridWindow
, "D8", "3500")
38 enter_text_to_cell(xGridWindow
, "D9", "4000")
39 enter_text_to_cell(xGridWindow
, "D10", "4500")
40 enter_text_to_cell(xGridWindow
, "D11", "5000")
41 #Select the range D2:E11
42 xGridWindow
.executeAction("SELECT", mkPropertyValues({"RANGE": "D2:E11"}))
43 #Choose Data > Multiple Operations.
44 with self
.ui_test
.execute_modeless_dialog_through_command(".uno:TableOperationDialog") as xDialog
:
45 #Formulas = B5 ; Column input cell = B4
46 formulas
= xDialog
.getChild("formulas")
47 col
= xDialog
.getChild("col")
48 formulas
.executeAction("TYPE", mkPropertyValues({"TEXT":"$B$5"}))
49 col
.executeAction("TYPE", mkPropertyValues({"TEXT":"$B$4"}))
51 self
.assertEqual(get_cell_by_position(document
, 0, 4, 1).getValue(), -6000)
52 self
.assertEqual(get_cell_by_position(document
, 0, 4, 2).getValue(), -2000)
53 self
.assertEqual(get_cell_by_position(document
, 0, 4, 3).getValue(), 2000)
54 self
.assertEqual(get_cell_by_position(document
, 0, 4, 4).getValue(), 6000)
55 self
.assertEqual(get_cell_by_position(document
, 0, 4, 5).getValue(), 10000)
56 self
.assertEqual(get_cell_by_position(document
, 0, 4, 6).getValue(), 14000)
57 self
.assertEqual(get_cell_by_position(document
, 0, 4, 7).getValue(), 18000)
58 self
.assertEqual(get_cell_by_position(document
, 0, 4, 8).getValue(), 22000)
59 self
.assertEqual(get_cell_by_position(document
, 0, 4, 9).getValue(), 26000)
60 self
.assertEqual(get_cell_by_position(document
, 0, 4, 10).getValue(), 30000)
62 def test_multiple_operations_several_formulas(self
):
63 with self
.ui_test
.create_doc_in_start_center("calc") as document
:
64 xCalcDoc
= self
.xUITest
.getTopFocusWindow()
65 xGridWindow
= xCalcDoc
.getChild("grid_window")
68 enter_text_to_cell(xGridWindow
, "B1", "10")
69 enter_text_to_cell(xGridWindow
, "B2", "2")
70 enter_text_to_cell(xGridWindow
, "B3", "10000")
71 enter_text_to_cell(xGridWindow
, "B4", "2000")
72 enter_text_to_cell(xGridWindow
, "B5", "=B4*(B1-B2)-B3")
73 enter_text_to_cell(xGridWindow
, "C5", "=B5/B4")
75 enter_text_to_cell(xGridWindow
, "D2", "500")
76 enter_text_to_cell(xGridWindow
, "D3", "1000")
77 enter_text_to_cell(xGridWindow
, "D4", "1500")
78 enter_text_to_cell(xGridWindow
, "D5", "2000")
79 enter_text_to_cell(xGridWindow
, "D6", "2500")
80 enter_text_to_cell(xGridWindow
, "D7", "3000")
81 enter_text_to_cell(xGridWindow
, "D8", "3500")
82 enter_text_to_cell(xGridWindow
, "D9", "4000")
83 enter_text_to_cell(xGridWindow
, "D10", "4500")
84 enter_text_to_cell(xGridWindow
, "D11", "5000")
85 #Select the range D2:F11
86 xGridWindow
.executeAction("SELECT", mkPropertyValues({"RANGE": "D2:F11"}))
87 #Choose Data > Multiple Operations.
88 with self
.ui_test
.execute_modeless_dialog_through_command(".uno:TableOperationDialog") as xDialog
:
89 #Formulas = B5 ; Column input cell = B4
90 formulas
= xDialog
.getChild("formulas")
91 col
= xDialog
.getChild("col")
92 formulas
.executeAction("TYPE", mkPropertyValues({"TEXT":"$B$5:$C$5"}))
93 col
.executeAction("TYPE", mkPropertyValues({"TEXT":"$B$4"}))
95 self
.assertEqual(get_cell_by_position(document
, 0, 4, 1).getValue(), -6000)
96 self
.assertEqual(get_cell_by_position(document
, 0, 4, 2).getValue(), -2000)
97 self
.assertEqual(get_cell_by_position(document
, 0, 4, 3).getValue(), 2000)
98 self
.assertEqual(get_cell_by_position(document
, 0, 4, 4).getValue(), 6000)
99 self
.assertEqual(get_cell_by_position(document
, 0, 4, 5).getValue(), 10000)
100 self
.assertEqual(get_cell_by_position(document
, 0, 4, 6).getValue(), 14000)
101 self
.assertEqual(get_cell_by_position(document
, 0, 4, 7).getValue(), 18000)
102 self
.assertEqual(get_cell_by_position(document
, 0, 4, 8).getValue(), 22000)
103 self
.assertEqual(get_cell_by_position(document
, 0, 4, 9).getValue(), 26000)
104 self
.assertEqual(get_cell_by_position(document
, 0, 4, 10).getValue(), 30000)
106 self
.assertEqual(get_cell_by_position(document
, 0, 5, 1).getValue(), -12)
107 self
.assertEqual(get_cell_by_position(document
, 0, 5, 2).getValue(), -2)
108 self
.assertEqual(round(get_cell_by_position(document
, 0, 5, 3).getValue(),2), 1.33)
109 self
.assertEqual(get_cell_by_position(document
, 0, 5, 4).getValue(), 3)
110 self
.assertEqual(get_cell_by_position(document
, 0, 5, 5).getValue(), 4)
111 self
.assertEqual(round(get_cell_by_position(document
, 0, 5, 6).getValue(),2), 4.67)
112 self
.assertEqual(round(get_cell_by_position(document
, 0, 5, 7).getValue(),2), 5.14)
113 self
.assertEqual(get_cell_by_position(document
, 0, 5, 8).getValue(), 5.5)
114 self
.assertEqual(round(get_cell_by_position(document
, 0, 5, 9).getValue(),2), 5.78)
115 self
.assertEqual(get_cell_by_position(document
, 0, 5, 10).getValue(), 6)
118 # vim: set shiftwidth=4 softtabstop=4 expandtab: