Avoid potential negative array index access to cached text.
[LibreOffice.git] / sc / qa / uitest / autofilter2 / tdf140754.py
blob1d298f832e3fb887cbf9f160ac5f93cb993bf27d
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/.
9 from uitest.framework import UITestCase
10 from uitest.uihelper.common import get_state_as_dict, get_url_for_data_file
11 from libreoffice.uno.propertyvalue import mkPropertyValues
12 from libreoffice.calc.document import get_cell_by_position
14 class tdf140754(UITestCase):
16 def test_tdf140754(self):
18 with self.ui_test.load_file(get_url_for_data_file("tdf140754.ods")) as calc_doc:
20 #Make sure 'multi-threaded calculation' is enabled
21 with self.ui_test.execute_dialog_through_command(".uno:OptionsTreeDialog") as xDialogOpt:
23 xPages = xDialogOpt.getChild("pages")
24 xCalcEntry = xPages.getChild('3')
25 xCalcEntry.executeAction("EXPAND", tuple())
26 xCalcCalculateEntry = xCalcEntry.getChild('3')
27 xCalcCalculateEntry.executeAction("SELECT", tuple())
29 self.assertEqual('true', get_state_as_dict(xDialogOpt.getChild('threadingenabled'))["Selected"])
33 self.assertEqual(0, get_cell_by_position(calc_doc, 0, 0, 30).getValue())
34 self.assertEqual(0, get_cell_by_position(calc_doc, 0, 0, 82).getValue())
35 self.assertEqual(1, get_cell_by_position(calc_doc, 0, 0, 238).getValue())
36 self.assertEqual(28, get_cell_by_position(calc_doc, 0, 0, 265).getValue())
37 self.assertEqual(28, get_cell_by_position(calc_doc, 0, 0, 1370).getValue())
39 xCalcDoc = self.xUITest.getTopFocusWindow()
40 gridwin = xCalcDoc.getChild("grid_window")
42 gridwin.executeAction("LAUNCH", mkPropertyValues({"AUTOFILTER": "", "COL": "2", "ROW": "0"}))
43 xFloatWindow = self.xUITest.getFloatWindow()
44 xAll = xFloatWindow.getChild("toggle_all")
45 xAll.executeAction("CLICK", tuple())
47 xCheckListMenu = xFloatWindow.getChild("FilterDropDown")
48 xList = xCheckListMenu.getChild("check_list_box")
49 # since tdf#117267, we are showing the hidden filter rows as inactive elements (25 active + 140 inactive)
50 self.assertEqual(165, len(xList.getChildren()))
52 for i in range(165):
53 xChild = xList.getChild(str(i))
54 if i < 25:
55 self.assertEqual("true", get_state_as_dict(xChild)["IsChecked"])
56 else:
57 self.assertEqual("false", get_state_as_dict(xChild)["IsChecked"])
59 # Without the fix in place, this test would have crashed here
60 xOkBtn = xFloatWindow.getChild("ok")
61 xOkBtn.executeAction("CLICK", tuple())
63 self.assertEqual(0, get_cell_by_position(calc_doc, 0, 0, 30).getValue())
64 self.assertEqual(1, get_cell_by_position(calc_doc, 0, 0, 82).getValue())
65 self.assertEqual(39, get_cell_by_position(calc_doc, 0, 0, 238).getValue())
66 self.assertEqual(66, get_cell_by_position(calc_doc, 0, 0, 265).getValue())
67 self.assertEqual(282, get_cell_by_position(calc_doc, 0, 0, 1370).getValue())
69 gridwin.executeAction("LAUNCH", mkPropertyValues({"AUTOFILTER": "", "COL": "6", "ROW": "0"}))
70 xFloatWindow = self.xUITest.getFloatWindow()
71 xAll = xFloatWindow.getChild("toggle_all")
72 xAll.executeAction("CLICK", tuple())
74 xCheckListMenu = xFloatWindow.getChild("FilterDropDown")
75 xList = xCheckListMenu.getChild("check_list_box")
76 # since tdf#117267, we are showing the hidden filter rows as inactive elements (10 active + 35 inactive)
77 self.assertEqual(45, len(xList.getChildren()))
79 for i in range(45):
80 xChild = xList.getChild(str(i))
81 if i < 10:
82 self.assertEqual("true", get_state_as_dict(xChild)["IsChecked"])
83 else:
84 self.assertEqual("false", get_state_as_dict(xChild)["IsChecked"])
86 xOkBtn = xFloatWindow.getChild("ok")
87 xOkBtn.executeAction("CLICK", tuple())
89 self.assertEqual(1, get_cell_by_position(calc_doc, 0, 0, 30).getValue())
90 self.assertEqual(11, get_cell_by_position(calc_doc, 0, 0, 82).getValue())
91 self.assertEqual(69, get_cell_by_position(calc_doc, 0, 0, 238).getValue())
92 self.assertEqual(96, get_cell_by_position(calc_doc, 0, 0, 265).getValue())
93 self.assertEqual(411, get_cell_by_position(calc_doc, 0, 0, 1370).getValue())
95 # vim: set shiftwidth=4 softtabstop=4 expandtab: