summaryrefslogtreecommitdiff
path: root/sc/qa/uitest/calc_tests6/multipleOperations.py
blob: 83868c824aa514d47e103eb6134389e76144f88b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*-
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

from uitest.framework import UITestCase
from libreoffice.uno.propertyvalue import mkPropertyValues
from libreoffice.calc.document import get_cell_by_position
from uitest.uihelper.calc import enter_text_to_cell

#https://www.linuxtopia.org/online_books/office_guides/openoffice_3_calc_user_guide/openoffice_calc_Multiple_operations_Multiple_operations_in_columns_or_rows.html

class multipleOperations(UITestCase):

   def test_multiple_operations_one_variable(self):
        with self.ui_test.create_doc_in_start_center_guarded("calc") as document:
            xCalcDoc = self.xUITest.getTopFocusWindow()
            xGridWindow = xCalcDoc.getChild("grid_window")

            #enter data
            enter_text_to_cell(xGridWindow, "B1", "10")
            enter_text_to_cell(xGridWindow, "B2", "2")
            enter_text_to_cell(xGridWindow, "B3", "10000")
            enter_text_to_cell(xGridWindow, "B4", "2000")
            enter_text_to_cell(xGridWindow, "B5", "=B4*(B1-B2)-B3")

            enter_text_to_cell(xGridWindow, "D2", "500")
            enter_text_to_cell(xGridWindow, "D3", "1000")
            enter_text_to_cell(xGridWindow, "D4", "1500")
            enter_text_to_cell(xGridWindow, "D5", "2000")
            enter_text_to_cell(xGridWindow, "D6", "2500")
            enter_text_to_cell(xGridWindow, "D7", "3000")
            enter_text_to_cell(xGridWindow, "D8", "3500")
            enter_text_to_cell(xGridWindow, "D9", "4000")
            enter_text_to_cell(xGridWindow, "D10", "4500")
            enter_text_to_cell(xGridWindow, "D11", "5000")
            #Select the range D2:E11
            xGridWindow.executeAction("SELECT", mkPropertyValues({"RANGE": "D2:E11"}))
            #Choose Data > Multiple Operations.
            self.ui_test.execute_modeless_dialog_through_command(".uno:TableOperationDialog")
            xDialog = self.xUITest.getTopFocusWindow()
            #Formulas = B5 ; Column input cell = B4
            formulas = xDialog.getChild("formulas")
            col = xDialog.getChild("col")
            formulas.executeAction("TYPE", mkPropertyValues({"TEXT":"$B$5"}))
            col.executeAction("TYPE", mkPropertyValues({"TEXT":"$B$4"}))
            xOKBtn = xDialog.getChild("ok")
            self.ui_test.close_dialog_through_button(xOKBtn)
            #verify
            self.assertEqual(get_cell_by_position(document, 0, 4, 1).getValue(), -6000)
            self.assertEqual(get_cell_by_position(document, 0, 4, 2).getValue(), -2000)
            self.assertEqual(get_cell_by_position(document, 0, 4, 3).getValue(), 2000)
            self.assertEqual(get_cell_by_position(document, 0, 4, 4).getValue(), 6000)
            self.assertEqual(get_cell_by_position(document, 0, 4, 5).getValue(), 10000)
            self.assertEqual(get_cell_by_position(document, 0, 4, 6).getValue(), 14000)
            self.assertEqual(get_cell_by_position(document, 0, 4, 7).getValue(), 18000)
            self.assertEqual(get_cell_by_position(document, 0, 4, 8).getValue(), 22000)
            self.assertEqual(get_cell_by_position(document, 0, 4, 9).getValue(), 26000)
            self.assertEqual(get_cell_by_position(document, 0, 4, 10).getValue(), 30000)

   def test_multiple_operations_several_formulas(self):
        with self.ui_test.create_doc_in_start_center_guarded("calc") as document:
            xCalcDoc = self.xUITest.getTopFocusWindow()
            xGridWindow = xCalcDoc.getChild("grid_window")

            #enter data
            enter_text_to_cell(xGridWindow, "B1", "10")
            enter_text_to_cell(xGridWindow, "B2", "2")
            enter_text_to_cell(xGridWindow, "B3", "10000")
            enter_text_to_cell(xGridWindow, "B4", "2000")
            enter_text_to_cell(xGridWindow, "B5", "=B4*(B1-B2)-B3")
            enter_text_to_cell(xGridWindow, "C5", "=B5/B4")

            enter_text_to_cell(xGridWindow, "D2", "500")
            enter_text_to_cell(xGridWindow, "D3", "1000")
            enter_text_to_cell(xGridWindow, "D4", "1500")
            enter_text_to_cell(xGridWindow, "D5", "2000")
            enter_text_to_cell(xGridWindow, "D6", "2500")
            enter_text_to_cell(xGridWindow, "D7", "3000")
            enter_text_to_cell(xGridWindow, "D8", "3500")
            enter_text_to_cell(xGridWindow, "D9", "4000")
            enter_text_to_cell(xGridWindow, "D10", "4500")
            enter_text_to_cell(xGridWindow, "D11", "5000")
            #Select the range D2:F11
            xGridWindow.executeAction("SELECT", mkPropertyValues({"RANGE": "D2:F11"}))
            #Choose Data > Multiple Operations.
            self.ui_test.execute_modeless_dialog_through_command(".uno:TableOperationDialog")
            xDialog = self.xUITest.getTopFocusWindow()
            #Formulas = B5 ; Column input cell = B4
            formulas = xDialog.getChild("formulas")
            col = xDialog.getChild("col")
            formulas.executeAction("TYPE", mkPropertyValues({"TEXT":"$B$5:$C$5"}))
            col.executeAction("TYPE", mkPropertyValues({"TEXT":"$B$4"}))
            xOKBtn = xDialog.getChild("ok")
            self.ui_test.close_dialog_through_button(xOKBtn)
            #verify
            self.assertEqual(get_cell_by_position(document, 0, 4, 1).getValue(), -6000)
            self.assertEqual(get_cell_by_position(document, 0, 4, 2).getValue(), -2000)
            self.assertEqual(get_cell_by_position(document, 0, 4, 3).getValue(), 2000)
            self.assertEqual(get_cell_by_position(document, 0, 4, 4).getValue(), 6000)
            self.assertEqual(get_cell_by_position(document, 0, 4, 5).getValue(), 10000)
            self.assertEqual(get_cell_by_position(document, 0, 4, 6).getValue(), 14000)
            self.assertEqual(get_cell_by_position(document, 0, 4, 7).getValue(), 18000)
            self.assertEqual(get_cell_by_position(document, 0, 4, 8).getValue(), 22000)
            self.assertEqual(get_cell_by_position(document, 0, 4, 9).getValue(), 26000)
            self.assertEqual(get_cell_by_position(document, 0, 4, 10).getValue(), 30000)

            self.assertEqual(get_cell_by_position(document, 0, 5, 1).getValue(), -12)
            self.assertEqual(get_cell_by_position(document, 0, 5, 2).getValue(), -2)
            self.assertEqual(round(get_cell_by_position(document, 0, 5, 3).getValue(),2), 1.33)
            self.assertEqual(get_cell_by_position(document, 0, 5, 4).getValue(), 3)
            self.assertEqual(get_cell_by_position(document, 0, 5, 5).getValue(), 4)
            self.assertEqual(round(get_cell_by_position(document, 0, 5, 6).getValue(),2), 4.67)
            self.assertEqual(round(get_cell_by_position(document, 0, 5, 7).getValue(),2), 5.14)
            self.assertEqual(get_cell_by_position(document, 0, 5, 8).getValue(), 5.5)
            self.assertEqual(round(get_cell_by_position(document, 0, 5, 9).getValue(),2), 5.78)
            self.assertEqual(get_cell_by_position(document, 0, 5, 10).getValue(), 6)


# vim: set shiftwidth=4 softtabstop=4 expandtab: