Avoid potential negative array index access to cached text.
[LibreOffice.git] / sc / qa / uitest / calc_tests9 / pivotTable.py
blobbb985429f9401a05e9ba11290024b0a4e27b5586
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 uitest.uihelper.common import get_state_as_dict, get_url_for_data_file
13 from libreoffice.calc.document import get_cell_by_position
15 class pivotTable(UITestCase):
17 def test_cancelButton(self):
19 # This is basically a test for cf93998eb5abc193d95ae5433bf4dfd11a9d62d8
20 # Without the fix in place, this test would have crashed
22 with self.ui_test.load_file(get_url_for_data_file("basicPivotTable.ods")):
24 xCalcDoc = self.xUITest.getTopFocusWindow()
25 gridwin = xCalcDoc.getChild("grid_window")
27 gridwin.executeAction("SELECT", mkPropertyValues({"TABLE": "1"}))
29 self.xUITest.executeCommand(".uno:GoUp")
32 with self.ui_test.execute_dialog_through_command(".uno:DataDataPilotRun") as xDialog:
33 xFields = xDialog.getChild("listbox-fields")
34 self.assertEqual(2, len(xFields.getChildren()))
35 self.assertEqual("qtX", get_state_as_dict(xFields.getChild('0'))['Text'])
36 self.assertEqual("qtY", get_state_as_dict(xFields.getChild('1'))['Text'])
38 xColumns = xDialog.getChild("listbox-column")
39 self.assertEqual(1, len(xColumns.getChildren()))
40 self.assertEqual("Data", get_state_as_dict(xColumns.getChild('0'))['Text'])
42 xPage = xDialog.getChild("listbox-page")
43 self.assertEqual(1, len(xPage.getChildren()))
44 xPageChild = xPage.getChild('0')
45 self.assertEqual("qtX", get_state_as_dict(xPageChild)['Text'])
47 with self.ui_test.execute_blocking_action(xPageChild.executeAction, args=('DOUBLECLICK', ())) as dialog:
48 optionBtn = dialog.getChild("options")
50 with self.ui_test.execute_blocking_action(optionBtn.executeAction, args=('CLICK', ())) as dialog2:
51 xEmptyLine = dialog2.getChild("emptyline")
53 xEmptyLine.executeAction("CLICK", tuple())
54 self.assertEqual('true', get_state_as_dict(xEmptyLine)['Selected'])
56 with self.ui_test.execute_blocking_action(optionBtn.executeAction, args=('CLICK', ()), close_button="cancel") as dialog2:
57 xEmptyLine = dialog2.getChild("emptyline")
59 xEmptyLine.executeAction("CLICK", tuple())
60 self.assertEqual('false', get_state_as_dict(xEmptyLine)['Selected'])
62 with self.ui_test.execute_blocking_action(optionBtn.executeAction, args=('CLICK', ())) as dialog2:
63 xEmptyLine = dialog2.getChild("emptyline")
65 self.assertEqual('true', get_state_as_dict(xEmptyLine)['Selected'])
67 def test_popup(self):
68 with self.ui_test.load_file(get_url_for_data_file("pivotTable.ods")) as calc_doc:
70 xCalcDoc = self.xUITest.getTopFocusWindow()
71 gridwin = xCalcDoc.getChild("grid_window")
73 self.assertEqual("a", get_cell_by_position(calc_doc, 0, 3, 1).getString())
74 self.assertEqual("b", get_cell_by_position(calc_doc, 0, 3, 2).getString())
75 self.assertEqual("m", get_cell_by_position(calc_doc, 0, 4, 1).getString())
76 self.assertEqual("n", get_cell_by_position(calc_doc, 0, 4, 2).getString())
77 self.assertEqual("1", get_cell_by_position(calc_doc, 0, 5, 1).getString())
78 self.assertEqual("1", get_cell_by_position(calc_doc, 0, 5, 2).getString())
80 gridwin.executeAction("LAUNCH", mkPropertyValues({"PIVOTTABLE": "", "COL": "3", "ROW": "0"}))
81 xFloatWindow = self.xUITest.getFloatWindow()
82 xCheckListMenu = xFloatWindow.getChild("FilterDropDown")
84 xTreeList = xCheckListMenu.getChild("check_list_box")
85 xFirstEntry = xTreeList.getChild("0")
87 xFirstEntry.executeAction("CLICK", tuple())
89 xOkBtn = xFloatWindow.getChild("ok")
90 xOkBtn.executeAction("CLICK", tuple())
92 self.assertEqual("b", get_cell_by_position(calc_doc, 0, 3, 1).getString())
93 self.assertEqual("Total Result", get_cell_by_position(calc_doc, 0, 3, 2).getString())
94 self.assertEqual("n", get_cell_by_position(calc_doc, 0, 4, 1).getString())
95 self.assertEqual("", get_cell_by_position(calc_doc, 0, 4, 2).getString())
96 self.assertEqual("1", get_cell_by_position(calc_doc, 0, 5, 1).getString())
97 self.assertEqual("1", get_cell_by_position(calc_doc, 0, 5, 2).getString())
99 # vim: set shiftwidth=4 softtabstop=4 expandtab: