Avoid potential negative array index access to cached text.
[LibreOffice.git] / sc / qa / uitest / sort / tdf126678.py
blob80e12a5da7d0d2415d38df37c5aca1f450fd6016
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
11 from uitest.uihelper.common import select_pos
12 from uitest.uihelper.calc import enter_text_to_cell
13 from libreoffice.calc.document import get_cell_by_position
14 from libreoffice.uno.propertyvalue import mkPropertyValues
16 class tdf126678(UITestCase):
18 def execute_sort_dialog(self, gridwin, bIncludeFormats):
19 gridwin.executeAction("SELECT", mkPropertyValues({"RANGE": "A1:B3"}))
21 with self.ui_test.execute_dialog_through_command(".uno:DataSort") as xDialog:
22 xTabs = xDialog.getChild("tabcontrol")
23 select_pos(xTabs, "1")
25 xIncludeFormats = xDialog.getChild("formats")
27 if (get_state_as_dict(xIncludeFormats)["Selected"]) != bIncludeFormats:
28 xIncludeFormats.executeAction("CLICK", tuple())
31 def test_tdf126678(self):
32 with self.ui_test.create_doc_in_start_center("calc") as document:
33 xCalcDoc = self.xUITest.getTopFocusWindow()
34 gridwin = xCalcDoc.getChild("grid_window")
36 enter_text_to_cell(gridwin, "A1", "Text 2")
37 enter_text_to_cell(gridwin, "A2", "Text 3")
38 enter_text_to_cell(gridwin, "A3", "Text 1")
40 # Set the background of the corresponding cell
41 colorProperty = mkPropertyValues({"BackgroundColor": 16776960})
42 gridwin.executeAction("SELECT", mkPropertyValues({"CELL": "B2"}))
43 self.xUITest.executeCommandWithParameters(".uno:BackgroundColor", colorProperty)
45 self.execute_sort_dialog(gridwin, "false")
47 self.assertEqual("Text 1", get_cell_by_position(document, 0, 0, 0).getString())
48 self.assertEqual("Text 2", get_cell_by_position(document, 0, 0, 1).getString())
49 self.assertEqual("Text 3", get_cell_by_position(document, 0, 0, 2).getString())
51 # Sorting without option "including formats" does not include cells with cell formats
52 self.assertEqual(get_cell_by_position(document, 0, 1, 0).CellBackColor, -1)
53 self.assertEqual(get_cell_by_position(document, 0, 1, 1).CellBackColor, 16776960)
54 self.assertEqual(get_cell_by_position(document, 0, 1, 2).CellBackColor, -1)
56 self.xUITest.executeCommand(".uno:Undo")
58 self.execute_sort_dialog(gridwin, "true")
60 self.assertEqual("Text 1", get_cell_by_position(document, 0, 0, 0).getString())
61 self.assertEqual("Text 2", get_cell_by_position(document, 0, 0, 1).getString())
62 self.assertEqual("Text 3", get_cell_by_position(document, 0, 0, 2).getString())
64 # Sorting with option "including formats" includes all cells with visible cell formats
65 # tdf126678 - Without the fix in place, the test would have failed with
66 # AssertionError: -1 != 16776960
67 self.assertEqual(get_cell_by_position(document, 0, 1, 0).CellBackColor, -1)
68 self.assertEqual(get_cell_by_position(document, 0, 1, 1).CellBackColor, -1)
69 self.assertEqual(get_cell_by_position(document, 0, 1, 2).CellBackColor, 16776960)
72 # vim: set shiftwidth=4 softtabstop=4 expandtab: