Avoid potential negative array index access to cached text.
[LibreOffice.git] / sc / qa / uitest / autofilter2 / tdf122260.py
blob878e7bce4da41f690800f20a8fb63fa5b92f2127
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 libreoffice.uno.propertyvalue import mkPropertyValues
11 from libreoffice.calc.document import is_row_hidden
12 from uitest.uihelper.common import get_url_for_data_file
14 #Bug 122260 - EDITING Autofilters not properly cleared
15 class tdf122260(UITestCase):
16 def check_value_in_AutoFilter(self, gridwin, columnIndex, valueIndex):
17 # open filter pop-up window
18 self.assertIsNotNone(gridwin)
19 gridwin.executeAction("LAUNCH", mkPropertyValues({"AUTOFILTER": "", "COL": columnIndex, "ROW": "0"}))
20 xFloatWindow = self.xUITest.getFloatWindow()
21 self.assertIsNotNone(xFloatWindow)
23 # get check list
24 xCheckListMenu = xFloatWindow.getChild("FilterDropDown")
25 self.assertIsNotNone(xCheckListMenu)
27 xTreeList = xCheckListMenu.getChild("check_list_box")
28 self.assertIsNotNone(xTreeList)
30 # on/off required checkbox
31 xEntry = xTreeList.getChild(valueIndex)
32 self.assertIsNotNone(xEntry)
33 xEntry.executeAction("CLICK", tuple())
35 # close pop-up window
36 xOkBtn = xFloatWindow.getChild("ok")
37 self.assertIsNotNone(xOkBtn)
38 xOkBtn.executeAction("CLICK", tuple())
40 def get_values_count_in_AutoFilter(self, gridwin, columnIndex):
41 # open filter pop-up window
42 self.assertIsNotNone(gridwin)
43 gridwin.executeAction("LAUNCH", mkPropertyValues({"AUTOFILTER": "", "COL": columnIndex, "ROW": "0"}))
44 xFloatWindow = self.xUITest.getFloatWindow()
45 self.assertIsNotNone(xFloatWindow)
47 # get check list
48 xCheckListMenu = xFloatWindow.getChild("FilterDropDown")
49 self.assertIsNotNone(xCheckListMenu)
51 xTreeList = xCheckListMenu.getChild("check_list_box")
52 self.assertIsNotNone(xTreeList)
54 valuesCount = len(xTreeList.getChildren())
56 # close pop-up window
57 xOkBtn = xFloatWindow.getChild("ok")
58 self.assertIsNotNone(xOkBtn)
59 xOkBtn.executeAction("CLICK", tuple())
61 return valuesCount
63 def test_tdf122260_autofilter(self):
64 with self.ui_test.load_file(get_url_for_data_file("tdf122260.ods")) as calc_doc:
65 xCalcDoc = self.xUITest.getTopFocusWindow()
66 gridwin = xCalcDoc.getChild("grid_window")
67 self.assertIsNotNone(gridwin)
69 # filter out b1
70 self.check_value_in_AutoFilter(gridwin, "1", "0")
71 # filter out a2 (as a1 is filtered out a2 is the first item)
72 self.check_value_in_AutoFilter(gridwin, "0", "0")
73 # return back a2 (as a1 is filtered out a2 is the first item)
74 self.check_value_in_AutoFilter(gridwin, "0", "0")
76 # check rows visibility
77 # row-0 is row with headers
78 self.assertTrue(is_row_hidden(calc_doc, 1))
79 self.assertFalse(is_row_hidden(calc_doc, 2))
80 self.assertFalse(is_row_hidden(calc_doc, 3))
81 self.assertFalse(is_row_hidden(calc_doc, 4))
83 # check if "b1" is accessible in filter of the column-b
84 # (so all values of the column B are available)
85 self.assertEqual(4, self.get_values_count_in_AutoFilter(gridwin, "1"))
87 # vim: set shiftwidth=4 softtabstop=4 expandtab: