Avoid potential negative array index access to cached text.
[LibreOffice.git] / sc / qa / uitest / autofilter2 / tdf126306.py
blob2ebb3789bf8ff52feba3d17da94dcdf892fe847c
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.calc import enter_text_to_cell
11 from libreoffice.uno.propertyvalue import mkPropertyValues
12 from libreoffice.calc.document import get_cell_by_position
13 from libreoffice.calc.document import is_row_hidden
15 class tdf126306(UITestCase):
16 def check_values(self, document, results):
17 for i, value in enumerate(results, start=1):
18 self.assertEqual(get_cell_by_position(document, 0, 0, i).getValue(), value)
20 def check_row_hidden(self, document, results = [True] * 14):
21 for i, value in enumerate(results, start=1):
22 bVisible = not is_row_hidden(document, i)
23 self.assertEqual(bVisible, value)
25 def test_run(self):
26 with self.ui_test.create_doc_in_start_center("calc") as document:
27 calcDoc = self.xUITest.getTopFocusWindow()
28 xGridWin = calcDoc.getChild("grid_window")
30 default_values = [25, 1023, 17, 9, 19, 0, 107, 89, 8, 453, 33, 3, 25, 204]
32 for i, value in enumerate(default_values, start=2):
33 enter_text_to_cell(xGridWin, "A" + str(i), str(value))
35 xGridWin.executeAction("SELECT", mkPropertyValues({"RANGE": "A1:A15"}))
37 with self.ui_test.execute_dialog_through_command(".uno:DataFilterAutoFilter", close_button="yes"):
38 pass
40 self.assertEqual(document.getPropertyValue("UnnamedDatabaseRanges").getByTable(0).AutoFilter, True)
42 self.check_values(document, default_values)
43 self.check_row_hidden(document)
45 # Sort ascending button
46 xGridWin.executeAction("LAUNCH", mkPropertyValues({"AUTOFILTER": "", "COL": "0", "ROW": "0"}))
47 xFloatWindow = self.xUITest.getFloatWindow()
48 xMenu = xFloatWindow.getChild("menu")
49 xMenu.executeAction("TYPE", mkPropertyValues({"KEYCODE":"SPACE"}))
50 xMenu.executeAction("TYPE", mkPropertyValues({"KEYCODE":"RETURN"}))
52 sort_asc_values = [0, 3, 8, 9, 17, 19, 25, 25, 33, 89, 107, 204, 453, 1023]
53 self.check_values(document, sort_asc_values)
54 self.check_row_hidden(document)
56 #Undo
57 self.xUITest.executeCommand(".uno:Undo")
58 self.check_values(document, default_values)
59 self.check_row_hidden(document)
61 # Sort descending button
62 xGridWin.executeAction("LAUNCH", mkPropertyValues({"AUTOFILTER": "", "COL": "0", "ROW": "0"}))
63 xFloatWindow = self.xUITest.getFloatWindow()
64 xMenu = xFloatWindow.getChild("menu")
65 xMenu.executeAction("TYPE", mkPropertyValues({"KEYCODE":"DOWN"}))
66 xMenu.executeAction("TYPE", mkPropertyValues({"KEYCODE":"RETURN"}))
68 sort_des_values = [1023, 453, 204, 107, 89, 33, 25, 25, 19, 17, 9, 8, 3, 0]
69 self.check_values(document, sort_des_values)
70 self.check_row_hidden(document)
72 #Undo
73 self.xUITest.executeCommand(".uno:Undo")
74 self.check_values(document, default_values)
75 self.check_row_hidden(document)
77 # Top 10 button
78 xGridWin.executeAction("LAUNCH", mkPropertyValues({"AUTOFILTER": "", "COL": "0", "ROW": "0"}))
79 xFloatWindow = self.xUITest.getFloatWindow()
80 xMenu = xFloatWindow.getChild("menu")
81 xMenu.executeAction("TYPE", mkPropertyValues({"KEYCODE":"DOWN"}))
82 xMenu.executeAction("TYPE", mkPropertyValues({"KEYCODE":"DOWN"}))
83 xMenu.executeAction("TYPE", mkPropertyValues({"KEYCODE":"DOWN"}))
84 xMenu.executeAction("TYPE", mkPropertyValues({"KEYCODE":"DOWN"}))
85 xMenu.executeAction("TYPE", mkPropertyValues({"KEYCODE":"RETURN"}))
86 xSubFloatWindow = self.xUITest.getFloatWindow()
87 xSubMenu = xSubFloatWindow.getChild("menu")
88 xSubMenu.executeAction("TYPE", mkPropertyValues({"KEYCODE":"DOWN"}))
89 xSubMenu.executeAction("TYPE", mkPropertyValues({"KEYCODE":"DOWN"}))
90 xSubMenu.executeAction("TYPE", mkPropertyValues({"KEYCODE":"RETURN"}))
92 top10_hidden_values = [True, True, True, False, True, False, True,
93 True, False, True, True, False, True, True]
95 #Values are the same
96 self.check_values(document, default_values)
97 self.check_row_hidden(document, top10_hidden_values)
99 #Undo
100 self.xUITest.executeCommand(".uno:Undo")
101 self.check_values(document, default_values)
102 self.check_row_hidden(document)
104 # Empty button
105 xGridWin.executeAction("LAUNCH", mkPropertyValues({"AUTOFILTER": "", "COL": "0", "ROW": "0"}))
106 xFloatWindow = self.xUITest.getFloatWindow()
107 xMenu = xFloatWindow.getChild("menu")
108 xMenu.executeAction("TYPE", mkPropertyValues({"KEYCODE":"DOWN"}))
109 xMenu.executeAction("TYPE", mkPropertyValues({"KEYCODE":"DOWN"}))
110 xMenu.executeAction("TYPE", mkPropertyValues({"KEYCODE":"DOWN"}))
111 xMenu.executeAction("TYPE", mkPropertyValues({"KEYCODE":"DOWN"}))
112 xMenu.executeAction("TYPE", mkPropertyValues({"KEYCODE":"RETURN"}))
113 xSubFloatWindow = self.xUITest.getFloatWindow()
114 xSubMenu = xSubFloatWindow.getChild("menu")
115 xSubMenu.executeAction("TYPE", mkPropertyValues({"KEYCODE":"RETURN"}))
117 empty_values = [False] * 14
118 #Values are the same
119 self.check_values(document, default_values)
120 self.check_row_hidden(document, empty_values)
122 #Undo
123 self.xUITest.executeCommand(".uno:Undo")
124 self.check_values(document, default_values)
125 self.check_row_hidden(document)
127 # Not Empty button
128 xGridWin.executeAction("LAUNCH", mkPropertyValues({"AUTOFILTER": "", "COL": "0", "ROW": "0"}))
129 xFloatWindow = self.xUITest.getFloatWindow()
130 xMenu = xFloatWindow.getChild("menu")
131 xMenu.executeAction("TYPE", mkPropertyValues({"KEYCODE":"DOWN"}))
132 xMenu.executeAction("TYPE", mkPropertyValues({"KEYCODE":"DOWN"}))
133 xMenu.executeAction("TYPE", mkPropertyValues({"KEYCODE":"DOWN"}))
134 xMenu.executeAction("TYPE", mkPropertyValues({"KEYCODE":"DOWN"}))
135 xMenu.executeAction("TYPE", mkPropertyValues({"KEYCODE":"RETURN"}))
136 xSubFloatWindow = self.xUITest.getFloatWindow()
137 xSubMenu = xSubFloatWindow.getChild("menu")
138 xSubMenu.executeAction("TYPE", mkPropertyValues({"KEYCODE":"DOWN"}))
139 xSubMenu.executeAction("TYPE", mkPropertyValues({"KEYCODE":"RETURN"}))
141 #Nothing should change
142 self.check_values(document, default_values)
143 self.check_row_hidden(document)
145 #Undo
146 self.xUITest.executeCommand(".uno:Undo")
147 self.check_values(document, default_values)
148 self.check_row_hidden(document)
150 # finish
152 # vim: set shiftwidth=4 softtabstop=4 expandtab: