Avoid potential negative array index access to cached text.
[LibreOffice.git] / sc / qa / uitest / conditional_format / tdf119178.py
blob04a30fc5169b4c8d4e76569536a297a8dc9d4e16
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, select_by_text
11 from uitest.uihelper.calc import enter_text_to_cell
12 from libreoffice.uno.propertyvalue import mkPropertyValues
14 class tdf119178(UITestCase):
16 def test_tdf119178(self):
18 with self.ui_test.create_doc_in_start_center("calc"):
19 xCalcDoc = self.xUITest.getTopFocusWindow()
20 gridwin = xCalcDoc.getChild("grid_window")
22 enter_text_to_cell(gridwin, "A15", "test")
24 gridwin.executeAction("SELECT", mkPropertyValues({"CELL": "A1"}))
26 with self.ui_test.execute_modeless_dialog_through_command(".uno:ConditionalFormatDialog", close_button="") as xCondFormatDlg:
28 xRange = xCondFormatDlg.getChild("edassign")
29 xRange.executeAction("TYPE", mkPropertyValues({"KEYCODE":"CTRL+A"}))
30 xRange.executeAction("TYPE", mkPropertyValues({"KEYCODE":"BACKSPACE"}))
31 xRange.executeAction("TYPE", mkPropertyValues({"TEXT": "$B$15"}))
33 xType = xCondFormatDlg.getChild("type")
34 select_by_text(xType, "Formula is")
36 # After changing the type, the dialog is recalculated
37 xCondFormatDlg = self.xUITest.getTopFocusWindow()
39 xStyle = xCondFormatDlg.getChild("style")
40 select_by_text(xStyle, "Error")
42 xFormula = xCondFormatDlg.getChild("formula")
43 xFormula.executeAction("TYPE", mkPropertyValues({"TEXT": "$A15 = \"test\""}))
45 xOkBtn = xCondFormatDlg.getChild("ok")
46 self.ui_test.close_dialog_through_button(xOkBtn)
48 # Check the conditional format is correctly displayed in the manager
49 with self.ui_test.execute_dialog_through_command(".uno:ConditionalFormatManagerDialog") as xCondFormatMgr:
50 aExpectedResult = 'B15\tFormula is $A15 = "test"'
51 xList = xCondFormatMgr.getChild("CONTAINER")
52 self.assertEqual(1, len(xList.getChildren()))
54 # Without the fix in place, this test would have failed with
55 # AssertionError: 'B15\tFormula is $A15 = "test"' != 'B15\tFormula is $A29 = "test"'
56 self.assertEqual(aExpectedResult, get_state_as_dict(xList.getChild('0'))['Text'])
58 # vim: set shiftwidth=4 softtabstop=4 expandtab: