1# -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*- 2# 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/. 6# 7from uitest.framework import UITestCase 8from uitest.uihelper.common import get_state_as_dict 9from uitest.uihelper.common import select_pos 10from uitest.uihelper.calc import enter_text_to_cell 11from libreoffice.calc.document import get_sheet_from_doc 12from libreoffice.calc.conditional_format import get_conditional_format_from_sheet 13from uitest.debug import sleep 14from libreoffice.calc.document import get_cell_by_position 15from libreoffice.uno.propertyvalue import mkPropertyValues 16 17class movingAverage(UITestCase): 18 def test_moving_average_column(self): 19 calc_doc = self.ui_test.create_doc_in_start_center("calc") 20 xCalcDoc = self.xUITest.getTopFocusWindow() 21 gridwin = xCalcDoc.getChild("grid_window") 22 document = self.ui_test.get_component() 23 #fill data 24 enter_text_to_cell(gridwin, "A1", "1") 25 enter_text_to_cell(gridwin, "A2", "0") 26 enter_text_to_cell(gridwin, "A3", "0") 27 enter_text_to_cell(gridwin, "A4", "0") 28 enter_text_to_cell(gridwin, "A5", "0") 29 enter_text_to_cell(gridwin, "A7", "0") 30 enter_text_to_cell(gridwin, "A8", "0") 31 enter_text_to_cell(gridwin, "A9", "0") 32 enter_text_to_cell(gridwin, "A10", "0") 33 enter_text_to_cell(gridwin, "A11", "0") 34 enter_text_to_cell(gridwin, "A12", "0") 35 enter_text_to_cell(gridwin, "A13", "0") 36 37 enter_text_to_cell(gridwin, "B1", "0") 38 enter_text_to_cell(gridwin, "B2", "0") 39 enter_text_to_cell(gridwin, "B3", "1") 40 enter_text_to_cell(gridwin, "B4", "0") 41 enter_text_to_cell(gridwin, "B5", "0") 42 enter_text_to_cell(gridwin, "B6", "0") 43 enter_text_to_cell(gridwin, "B7", "0") 44 enter_text_to_cell(gridwin, "B8", "0") 45 enter_text_to_cell(gridwin, "B9", "0") 46 enter_text_to_cell(gridwin, "B10", "0") 47 enter_text_to_cell(gridwin, "B11", "0") 48 enter_text_to_cell(gridwin, "B12", "0") 49 enter_text_to_cell(gridwin, "B13", "0") 50 51 gridwin.executeAction("SELECT", mkPropertyValues({"RANGE": "A1:B13"})) 52 self.ui_test.execute_modeless_dialog_through_command(".uno:MovingAverageDialog") 53 xDialog = self.xUITest.getTopFocusWindow() 54 xinputrangeedit = xDialog.getChild("input-range-edit") 55 xoutputrangeedit = xDialog.getChild("output-range-edit") 56 xgroupedbyrowsradio = xDialog.getChild("groupedby-rows-radio") 57 xgroupedbycolumnsradio = xDialog.getChild("groupedby-columns-radio") 58 xintervalspin = xDialog.getChild("interval-spin") 59 60 xinputrangeedit.executeAction("TYPE", mkPropertyValues({"KEYCODE":"CTRL+A"})) 61 xinputrangeedit.executeAction("TYPE", mkPropertyValues({"KEYCODE":"BACKSPACE"})) 62 xinputrangeedit.executeAction("TYPE", mkPropertyValues({"TEXT":"$Sheet1.$A$1:$B$13"})) 63 xoutputrangeedit.executeAction("TYPE", mkPropertyValues({"KEYCODE":"CTRL+A"})) 64 xoutputrangeedit.executeAction("TYPE", mkPropertyValues({"KEYCODE":"BACKSPACE"})) 65 xoutputrangeedit.executeAction("TYPE", mkPropertyValues({"TEXT":"$F$1"})) 66 xintervalspin.executeAction("TYPE", mkPropertyValues({"KEYCODE":"CTRL+A"})) 67 xintervalspin.executeAction("TYPE", mkPropertyValues({"KEYCODE":"BACKSPACE"})) 68 xintervalspin.executeAction("TYPE", mkPropertyValues({"TEXT":"3"})) 69 xOKBtn = xDialog.getChild("ok") 70 self.ui_test.close_dialog_through_button(xOKBtn) 71 #Verify 72 self.assertEqual(get_cell_by_position(document, 0, 5, 0).getString(), "Column 1") 73 self.assertEqual(get_cell_by_position(document, 0, 5, 1).getString(), "#N/A") 74 self.assertEqual(round(get_cell_by_position(document, 0, 5, 2).getValue(),8), 0.33333333) 75 self.assertEqual(get_cell_by_position(document, 0, 5, 3).getValue(), 0) 76 self.assertEqual(get_cell_by_position(document, 0, 5, 4).getValue(), 0) 77 self.assertEqual(get_cell_by_position(document, 0, 5, 5).getValue(), 0) 78 self.assertEqual(get_cell_by_position(document, 0, 5, 6).getValue(), 0) 79 self.assertEqual(get_cell_by_position(document, 0, 5, 7).getValue(), 0) 80 self.assertEqual(get_cell_by_position(document, 0, 5, 8).getValue(), 0) 81 self.assertEqual(get_cell_by_position(document, 0, 5, 9).getValue(), 0) 82 self.assertEqual(get_cell_by_position(document, 0, 5, 10).getValue(), 0) 83 self.assertEqual(get_cell_by_position(document, 0, 5, 11).getValue(), 0) 84 self.assertEqual(get_cell_by_position(document, 0, 5, 12).getValue(), 0) 85 self.assertEqual(get_cell_by_position(document, 0, 5, 13).getString(), "#N/A") 86 87 88 self.assertEqual(get_cell_by_position(document, 0, 6, 0).getString(), "Column 2") 89 self.assertEqual(get_cell_by_position(document, 0, 6, 1).getString(), "#N/A") 90 self.assertEqual(round(get_cell_by_position(document, 0, 6, 2).getValue(),8), 0.33333333) 91 self.assertEqual(round(get_cell_by_position(document, 0, 6, 3).getValue(),8), 0.33333333) 92 self.assertEqual(round(get_cell_by_position(document, 0, 6, 4).getValue(),8), 0.33333333) 93 self.assertEqual(get_cell_by_position(document, 0, 6, 5).getValue(), 0) 94 self.assertEqual(get_cell_by_position(document, 0, 6, 6).getValue(), 0) 95 self.assertEqual(get_cell_by_position(document, 0, 6, 7).getValue(), 0) 96 self.assertEqual(get_cell_by_position(document, 0, 6, 9).getValue(), 0) 97 self.assertEqual(get_cell_by_position(document, 0, 6, 10).getValue(), 0) 98 self.assertEqual(get_cell_by_position(document, 0, 6, 11).getValue(), 0) 99 self.assertEqual(get_cell_by_position(document, 0, 6, 12).getValue(), 0) 100 self.assertEqual(get_cell_by_position(document, 0, 6, 13).getString(), "#N/A") 101 102 #undo 103 self.xUITest.executeCommand(".uno:Undo") 104 self.assertEqual(get_cell_by_position(document, 0, 5, 0).getString(), "") 105 106 # test cancel button 107 self.ui_test.execute_modeless_dialog_through_command(".uno:MovingAverageDialog") 108 xDialog = self.xUITest.getTopFocusWindow() 109 xCancelBtn = xDialog.getChild("cancel") 110 self.ui_test.close_dialog_through_button(xCancelBtn) 111 112 self.ui_test.close_doc() 113 114 def test_moving_average_row(self): 115 calc_doc = self.ui_test.create_doc_in_start_center("calc") 116 xCalcDoc = self.xUITest.getTopFocusWindow() 117 gridwin = xCalcDoc.getChild("grid_window") 118 document = self.ui_test.get_component() 119 #fill data 120 enter_text_to_cell(gridwin, "A1", "1") 121 enter_text_to_cell(gridwin, "A2", "0") 122 enter_text_to_cell(gridwin, "A3", "0") 123 enter_text_to_cell(gridwin, "A4", "0") 124 enter_text_to_cell(gridwin, "A5", "0") 125 enter_text_to_cell(gridwin, "A7", "0") 126 enter_text_to_cell(gridwin, "A8", "0") 127 enter_text_to_cell(gridwin, "A9", "0") 128 enter_text_to_cell(gridwin, "A10", "0") 129 enter_text_to_cell(gridwin, "A11", "0") 130 enter_text_to_cell(gridwin, "A12", "0") 131 enter_text_to_cell(gridwin, "A13", "0") 132 133 enter_text_to_cell(gridwin, "B1", "0") 134 enter_text_to_cell(gridwin, "B2", "0") 135 enter_text_to_cell(gridwin, "B3", "1") 136 enter_text_to_cell(gridwin, "B4", "0") 137 enter_text_to_cell(gridwin, "B5", "0") 138 enter_text_to_cell(gridwin, "B6", "0") 139 enter_text_to_cell(gridwin, "B7", "0") 140 enter_text_to_cell(gridwin, "B8", "0") 141 enter_text_to_cell(gridwin, "B9", "0") 142 enter_text_to_cell(gridwin, "B10", "0") 143 enter_text_to_cell(gridwin, "B11", "0") 144 enter_text_to_cell(gridwin, "B12", "0") 145 enter_text_to_cell(gridwin, "B13", "0") 146 147 gridwin.executeAction("SELECT", mkPropertyValues({"RANGE": "A1:B13"})) 148 self.ui_test.execute_modeless_dialog_through_command(".uno:MovingAverageDialog") 149 xDialog = self.xUITest.getTopFocusWindow() 150 xinputrangeedit = xDialog.getChild("input-range-edit") 151 xoutputrangeedit = xDialog.getChild("output-range-edit") 152 xgroupedbyrowsradio = xDialog.getChild("groupedby-rows-radio") 153 xgroupedbycolumnsradio = xDialog.getChild("groupedby-columns-radio") 154 xintervalspin = xDialog.getChild("interval-spin") 155 156 xinputrangeedit.executeAction("TYPE", mkPropertyValues({"KEYCODE":"CTRL+A"})) 157 xinputrangeedit.executeAction("TYPE", mkPropertyValues({"KEYCODE":"BACKSPACE"})) 158 xinputrangeedit.executeAction("TYPE", mkPropertyValues({"TEXT":"$Sheet1.$A$1:$B$13"})) 159 xoutputrangeedit.executeAction("TYPE", mkPropertyValues({"KEYCODE":"CTRL+A"})) 160 xoutputrangeedit.executeAction("TYPE", mkPropertyValues({"KEYCODE":"BACKSPACE"})) 161 xoutputrangeedit.executeAction("TYPE", mkPropertyValues({"TEXT":"$F$1"})) 162 xintervalspin.executeAction("TYPE", mkPropertyValues({"KEYCODE":"CTRL+A"})) 163 xintervalspin.executeAction("TYPE", mkPropertyValues({"KEYCODE":"BACKSPACE"})) 164 xintervalspin.executeAction("TYPE", mkPropertyValues({"TEXT":"3"})) 165 xgroupedbyrowsradio.executeAction("CLICK", tuple()) 166 xOKBtn = xDialog.getChild("ok") 167 self.ui_test.close_dialog_through_button(xOKBtn) 168 #Verify 169 self.assertEqual(get_cell_by_position(document, 0, 5, 0).getString(), "Row 1") 170 self.assertEqual(get_cell_by_position(document, 0, 5, 1).getString(), "#N/A") 171 self.assertEqual(get_cell_by_position(document, 0, 5, 2).getString(), "#N/A") 172 173 self.assertEqual(get_cell_by_position(document, 0, 6, 0).getString(), "Row 2") 174 self.assertEqual(get_cell_by_position(document, 0, 6, 1).getString(), "#N/A") 175 self.assertEqual(get_cell_by_position(document, 0, 6, 2).getString(), "#N/A") 176 #undo 177 self.xUITest.executeCommand(".uno:Undo") 178 self.assertEqual(get_cell_by_position(document, 0, 5, 0).getString(), "") 179 180 self.ui_test.close_doc() 181 182# vim: set shiftwidth=4 softtabstop=4 expandtab: 183