Avoid potential negative array index access to cached text.
[LibreOffice.git] / sc / qa / uitest / sort / naturalSort.py
blob91c2f35c3f7103196f3ccc42a6901f45c40fb95f
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 uitest.uihelper.common import get_state_as_dict, select_pos
13 from libreoffice.calc.document import get_cell_by_position
14 from libreoffice.uno.propertyvalue import mkPropertyValues
17 # Testcases Sorting TCS_Sorting
18 class CalcNaturalSorting(UITestCase):
20 def test_natural_sorting_rows(self):
21 with self.ui_test.create_doc_in_start_center("calc") as document:
22 xCalcDoc = self.xUITest.getTopFocusWindow()
23 gridwin = xCalcDoc.getChild("grid_window")
24 #enter data
25 enter_text_to_cell(gridwin, "A1", "MW100SSMOU456.996JIL4")
26 enter_text_to_cell(gridwin, "A2", "MW180SSMOU456.996JIL4")
27 enter_text_to_cell(gridwin, "A3", "MW110SSMOU456.993JIL4")
28 enter_text_to_cell(gridwin, "A4", "MW180SSMOU456.994JIL4")
29 enter_text_to_cell(gridwin, "A5", "MW101SSMOU456.996JIL4")
30 #Open sort dialog by DATA - SORT
31 with self.ui_test.execute_dialog_through_command(".uno:DataSort") as xDialog:
32 xTabs = xDialog.getChild("tabcontrol")
33 select_pos(xTabs, "0")
34 xNatural = xDialog.getChild("naturalsort")
35 xNatural.executeAction("CLICK", tuple())
36 #Verify
37 self.assertEqual(get_cell_by_position(document, 0, 0, 0).getString(), "MW100SSMOU456.996JIL4")
38 self.assertEqual(get_cell_by_position(document, 0, 0, 1).getString(), "MW101SSMOU456.996JIL4")
39 self.assertEqual(get_cell_by_position(document, 0, 0, 2).getString(), "MW110SSMOU456.993JIL4")
40 self.assertEqual(get_cell_by_position(document, 0, 0, 3).getString(), "MW180SSMOU456.994JIL4")
41 self.assertEqual(get_cell_by_position(document, 0, 0, 4).getString(), "MW180SSMOU456.996JIL4")
42 #UNDO
43 self.xUITest.executeCommand(".uno:Undo")
44 #Verify
45 self.assertEqual(get_cell_by_position(document, 0, 0, 0).getString(), "MW100SSMOU456.996JIL4")
46 self.assertEqual(get_cell_by_position(document, 0, 0, 1).getString(), "MW180SSMOU456.996JIL4")
47 self.assertEqual(get_cell_by_position(document, 0, 0, 2).getString(), "MW110SSMOU456.993JIL4")
48 self.assertEqual(get_cell_by_position(document, 0, 0, 3).getString(), "MW180SSMOU456.994JIL4")
49 self.assertEqual(get_cell_by_position(document, 0, 0, 4).getString(), "MW101SSMOU456.996JIL4")
50 #enter data
51 enter_text_to_cell(gridwin, "D1", "MW-2")
52 enter_text_to_cell(gridwin, "D2", "MW-20")
53 enter_text_to_cell(gridwin, "D3", "MW-1")
54 enter_text_to_cell(gridwin, "D4", "MW-18")
56 gridwin.executeAction("SELECT", mkPropertyValues({"RANGE": "D1:D4"}))
58 #Open sort dialog by DATA - SORT
59 with self.ui_test.execute_dialog_through_command(".uno:DataSort") as xDialog:
60 xTabs = xDialog.getChild("tabcontrol")
61 select_pos(xTabs, "1")
62 xNatural = xDialog.getChild("naturalsort")
63 if (get_state_as_dict(xNatural)["Selected"]) == "false":
64 xNatural.executeAction("CLICK", tuple())
66 self.assertEqual(get_cell_by_position(document, 0, 3, 0).getString(), "MW-1")
67 self.assertEqual(get_cell_by_position(document, 0, 3, 1).getString(), "MW-2")
68 self.assertEqual(get_cell_by_position(document, 0, 3, 2).getString(), "MW-18")
69 self.assertEqual(get_cell_by_position(document, 0, 3, 3).getString(), "MW-20")
72 def test_natural_sorting_columns(self):
73 with self.ui_test.create_doc_in_start_center("calc") as document:
74 xCalcDoc = self.xUITest.getTopFocusWindow()
75 gridwin = xCalcDoc.getChild("grid_window")
76 #enter data
77 enter_text_to_cell(gridwin, "A1", "MW-2")
78 enter_text_to_cell(gridwin, "B1", "MW-20")
79 enter_text_to_cell(gridwin, "C1", "MW-1")
80 enter_text_to_cell(gridwin, "D1", "MW-18")
82 gridwin.executeAction("SELECT", mkPropertyValues({"RANGE": "A1:D1"}))
84 #Open sort dialog by DATA - SORT
85 with self.ui_test.execute_dialog_through_command(".uno:DataSort") as xDialog:
86 xTabs = xDialog.getChild("tabcontrol")
87 select_pos(xTabs, "1")
88 xNatural = xDialog.getChild("naturalsort")
89 if (get_state_as_dict(xNatural)["Selected"]) == "false":
90 xNatural.executeAction("CLICK", tuple())
91 select_pos(xTabs, "0")
92 xleftright = xDialog.getChild("rbLeftRight")
93 xleftright.executeAction("CLICK", tuple())
95 #Verify
96 self.assertEqual(get_cell_by_position(document, 0, 0, 0).getString(), "MW-1")
97 self.assertEqual(get_cell_by_position(document, 0, 1, 0).getString(), "MW-2")
98 self.assertEqual(get_cell_by_position(document, 0, 2, 0).getString(), "MW-18")
99 self.assertEqual(get_cell_by_position(document, 0, 3, 0).getString(), "MW-20")
101 # vim: set shiftwidth=4 softtabstop=4 expandtab: