Avoid potential negative array index access to cached text.
[LibreOffice.git] / sc / qa / uitest / textCase / textCase.py
blob10abb64d0c31b7ac6cf2def0e15f982aa41a0dfa
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
12 from libreoffice.calc.document import get_cell_by_position
13 from libreoffice.uno.propertyvalue import mkPropertyValues
16 class textCase(UITestCase):
17 def test_text_case_switch(self):
18 with self.ui_test.create_doc_in_start_center("calc") as document:
19 xCalcDoc = self.xUITest.getTopFocusWindow()
20 gridwin = xCalcDoc.getChild("grid_window")
22 #enter data
23 enter_text_to_cell(gridwin, "A1", "hello world")
24 enter_text_to_cell(gridwin, "A2", "libre office")
25 enter_text_to_cell(gridwin, "A4", "free suite")
26 #select
27 gridwin.executeAction("SELECT", mkPropertyValues({"RANGE": "A1:A4"}))
28 #Capitalize every word - CommandSent Name:.uno:ChangeCaseToTitleCase
29 self.xUITest.executeCommand(".uno:ChangeCaseToTitleCase")
30 #Verify
31 self.assertEqual(get_cell_by_position(document, 0, 0, 0).getString(), "Hello World")
32 self.assertEqual(get_cell_by_position(document, 0, 0, 1).getString(), "Libre Office")
33 self.assertEqual(get_cell_by_position(document, 0, 0, 2).getString(), "")
34 self.assertEqual(get_cell_by_position(document, 0, 0, 3).getString(), "Free Suite")
36 #Sentence case - CommandSent Name:.uno:ChangeCaseToSentenceCase
37 self.xUITest.executeCommand(".uno:ChangeCaseToSentenceCase")
39 self.assertEqual(get_cell_by_position(document, 0, 0, 0).getString(), "Hello world")
40 self.assertEqual(get_cell_by_position(document, 0, 0, 1).getString(), "Libre office")
41 self.assertEqual(get_cell_by_position(document, 0, 0, 2).getString(), "")
42 self.assertEqual(get_cell_by_position(document, 0, 0, 3).getString(), "Free suite")
44 #toggle case - CommandSent Name:.uno:ChangeCaseToToggleCase
45 self.xUITest.executeCommand(".uno:ChangeCaseToToggleCase")
46 self.assertEqual(get_cell_by_position(document, 0, 0, 0).getString(), "hELLO WORLD")
47 self.assertEqual(get_cell_by_position(document, 0, 0, 1).getString(), "lIBRE OFFICE")
48 self.assertEqual(get_cell_by_position(document, 0, 0, 2).getString(), "")
49 self.assertEqual(get_cell_by_position(document, 0, 0, 3).getString(), "fREE SUITE")
51 #uppercase = CommandSent Name:.uno:ChangeCaseToUpper
52 self.xUITest.executeCommand(".uno:ChangeCaseToUpper")
53 self.assertEqual(get_cell_by_position(document, 0, 0, 0).getString(), "HELLO WORLD")
54 self.assertEqual(get_cell_by_position(document, 0, 0, 1).getString(), "LIBRE OFFICE")
55 self.assertEqual(get_cell_by_position(document, 0, 0, 2).getString(), "")
56 self.assertEqual(get_cell_by_position(document, 0, 0, 3).getString(), "FREE SUITE")
58 #lowercase - CommandSent Name:.uno:ChangeCaseToLower
59 self.xUITest.executeCommand(".uno:ChangeCaseToLower")
60 self.assertEqual(get_cell_by_position(document, 0, 0, 0).getString(), "hello world")
61 self.assertEqual(get_cell_by_position(document, 0, 0, 1).getString(), "libre office")
62 self.assertEqual(get_cell_by_position(document, 0, 0, 2).getString(), "")
63 self.assertEqual(get_cell_by_position(document, 0, 0, 3).getString(), "free suite")
65 #cycle case = CommandSent Name:.uno:ChangeCaseRotateCase
66 self.xUITest.executeCommand(".uno:ChangeCaseRotateCase")
67 self.assertEqual(get_cell_by_position(document, 0, 0, 0).getString(), "Hello World")
68 self.assertEqual(get_cell_by_position(document, 0, 0, 1).getString(), "Libre Office")
69 self.assertEqual(get_cell_by_position(document, 0, 0, 2).getString(), "")
70 self.assertEqual(get_cell_by_position(document, 0, 0, 3).getString(), "Free Suite")
72 #select non continuous range
73 gridwin.executeAction("SELECT", mkPropertyValues({"RANGE": "B1:B2"}))
74 gridwin.executeAction("SELECT", mkPropertyValues({"RANGE": "A1:A2"}))
75 gridwin.executeAction("SELECT", mkPropertyValues({"RANGE": "A4:A5", "EXTEND":"1"}))
77 #lowercase - CommandSent Name:.uno:ChangeCaseToLower
78 self.xUITest.executeCommand(".uno:ChangeCaseToLower")
79 self.assertEqual(get_cell_by_position(document, 0, 0, 0).getString(), "hello world")
80 self.assertEqual(get_cell_by_position(document, 0, 0, 1).getString(), "libre office")
81 self.assertEqual(get_cell_by_position(document, 0, 0, 4).getString(), "")
82 self.assertEqual(get_cell_by_position(document, 0, 0, 3).getString(), "free suite")
84 #Capitalize every word - CommandSent Name:.uno:ChangeCaseToTitleCase
85 self.xUITest.executeCommand(".uno:ChangeCaseToTitleCase")
86 #Verify
87 self.assertEqual(get_cell_by_position(document, 0, 0, 0).getString(), "Hello World")
88 self.assertEqual(get_cell_by_position(document, 0, 0, 1).getString(), "Libre Office")
89 self.assertEqual(get_cell_by_position(document, 0, 0, 4).getString(), "")
90 self.assertEqual(get_cell_by_position(document, 0, 0, 3).getString(), "Free Suite")
92 #Sentence case - CommandSent Name:.uno:ChangeCaseToSentenceCase
93 self.xUITest.executeCommand(".uno:ChangeCaseToSentenceCase")
95 self.assertEqual(get_cell_by_position(document, 0, 0, 0).getString(), "Hello world")
96 self.assertEqual(get_cell_by_position(document, 0, 0, 1).getString(), "Libre office")
97 self.assertEqual(get_cell_by_position(document, 0, 0, 4).getString(), "")
98 self.assertEqual(get_cell_by_position(document, 0, 0, 3).getString(), "Free suite")
100 #toggle case - CommandSent Name:.uno:ChangeCaseToToggleCase
101 self.xUITest.executeCommand(".uno:ChangeCaseToToggleCase")
102 self.assertEqual(get_cell_by_position(document, 0, 0, 0).getString(), "hELLO WORLD")
103 self.assertEqual(get_cell_by_position(document, 0, 0, 1).getString(), "lIBRE OFFICE")
104 self.assertEqual(get_cell_by_position(document, 0, 0, 4).getString(), "")
105 self.assertEqual(get_cell_by_position(document, 0, 0, 3).getString(), "fREE SUITE")
107 #uppercase = CommandSent Name:.uno:ChangeCaseToUpper
108 self.xUITest.executeCommand(".uno:ChangeCaseToUpper")
109 self.assertEqual(get_cell_by_position(document, 0, 0, 0).getString(), "HELLO WORLD")
110 self.assertEqual(get_cell_by_position(document, 0, 0, 1).getString(), "LIBRE OFFICE")
111 self.assertEqual(get_cell_by_position(document, 0, 0, 4).getString(), "")
112 self.assertEqual(get_cell_by_position(document, 0, 0, 3).getString(), "FREE SUITE")
114 #lowercase - CommandSent Name:.uno:ChangeCaseToLower
115 self.xUITest.executeCommand(".uno:ChangeCaseToLower")
116 self.assertEqual(get_cell_by_position(document, 0, 0, 0).getString(), "hello world")
117 self.assertEqual(get_cell_by_position(document, 0, 0, 1).getString(), "libre office")
118 self.assertEqual(get_cell_by_position(document, 0, 0, 4).getString(), "")
119 self.assertEqual(get_cell_by_position(document, 0, 0, 3).getString(), "free suite")
121 #cycle case = CommandSent Name:.uno:ChangeCaseRotateCase
122 self.xUITest.executeCommand(".uno:ChangeCaseRotateCase")
123 self.assertEqual(get_cell_by_position(document, 0, 0, 0).getString(), "Hello world")
124 self.assertEqual(get_cell_by_position(document, 0, 0, 1).getString(), "Libre office")
125 self.assertEqual(get_cell_by_position(document, 0, 0, 4).getString(), "")
126 self.assertEqual(get_cell_by_position(document, 0, 0, 3).getString(), "Free suite")
128 # vim: set shiftwidth=4 softtabstop=4 expandtab: