summaryrefslogtreecommitdiffstats
path: root/sc/qa/uitest/textCase/textCase.py
blob: 7dbb6d2a41d54d9fe091976781916d7565718589 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*-
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
from uitest.framework import UITestCase
from uitest.uihelper.common import get_state_as_dict, get_url_for_data_file
from uitest.uihelper.common import select_pos
from uitest.uihelper.calc import enter_text_to_cell
from libreoffice.calc.document import get_cell_by_position
from libreoffice.uno.propertyvalue import mkPropertyValues

class textCase(UITestCase):
    def test_text_case_switch(self):
        with self.ui_test.create_doc_in_start_center("calc") as document:
            xCalcDoc = self.xUITest.getTopFocusWindow()
            gridwin = xCalcDoc.getChild("grid_window")

            #enter data
            enter_text_to_cell(gridwin, "A1", "hello world")
            enter_text_to_cell(gridwin, "A2", "libre office")
            enter_text_to_cell(gridwin, "A4", "free suite")
            #select
            gridwin.executeAction("SELECT", mkPropertyValues({"RANGE": "A1:A4"}))
            #Capitalize every word - CommandSent Name:.uno:ChangeCaseToTitleCase
            self.xUITest.executeCommand(".uno:ChangeCaseToTitleCase")
            #Verify
            self.assertEqual(get_cell_by_position(document, 0, 0, 0).getString(), "Hello World")
            self.assertEqual(get_cell_by_position(document, 0, 0, 1).getString(), "Libre Office")
            self.assertEqual(get_cell_by_position(document, 0, 0, 2).getString(), "")
            self.assertEqual(get_cell_by_position(document, 0, 0, 3).getString(), "Free Suite")

            #Sentence case - CommandSent Name:.uno:ChangeCaseToSentenceCase
            self.xUITest.executeCommand(".uno:ChangeCaseToSentenceCase")

            self.assertEqual(get_cell_by_position(document, 0, 0, 0).getString(), "Hello world")
            self.assertEqual(get_cell_by_position(document, 0, 0, 1).getString(), "Libre office")
            self.assertEqual(get_cell_by_position(document, 0, 0, 2).getString(), "")
            self.assertEqual(get_cell_by_position(document, 0, 0, 3).getString(), "Free suite")

            #toggle case - CommandSent Name:.uno:ChangeCaseToToggleCase
            self.xUITest.executeCommand(".uno:ChangeCaseToToggleCase")
            self.assertEqual(get_cell_by_position(document, 0, 0, 0).getString(), "hELLO WORLD")
            self.assertEqual(get_cell_by_position(document, 0, 0, 1).getString(), "lIBRE OFFICE")
            self.assertEqual(get_cell_by_position(document, 0, 0, 2).getString(), "")
            self.assertEqual(get_cell_by_position(document, 0, 0, 3).getString(), "fREE SUITE")

            #uppercase = CommandSent Name:.uno:ChangeCaseToUpper
            self.xUITest.executeCommand(".uno:ChangeCaseToUpper")
            self.assertEqual(get_cell_by_position(document, 0, 0, 0).getString(), "HELLO WORLD")
            self.assertEqual(get_cell_by_position(document, 0, 0, 1).getString(), "LIBRE OFFICE")
            self.assertEqual(get_cell_by_position(document, 0, 0, 2).getString(), "")
            self.assertEqual(get_cell_by_position(document, 0, 0, 3).getString(), "FREE SUITE")

            #lowercase - CommandSent Name:.uno:ChangeCaseToLower
            self.xUITest.executeCommand(".uno:ChangeCaseToLower")
            self.assertEqual(get_cell_by_position(document, 0, 0, 0).getString(), "hello world")
            self.assertEqual(get_cell_by_position(document, 0, 0, 1).getString(), "libre office")
            self.assertEqual(get_cell_by_position(document, 0, 0, 2).getString(), "")
            self.assertEqual(get_cell_by_position(document, 0, 0, 3).getString(), "free suite")

            #cycle case = CommandSent Name:.uno:ChangeCaseRotateCase
            self.xUITest.executeCommand(".uno:ChangeCaseRotateCase")
            self.assertEqual(get_cell_by_position(document, 0, 0, 0).getString(), "Hello World")
            self.assertEqual(get_cell_by_position(document, 0, 0, 1).getString(), "Libre Office")
            self.assertEqual(get_cell_by_position(document, 0, 0, 2).getString(), "")
            self.assertEqual(get_cell_by_position(document, 0, 0, 3).getString(), "Free Suite")

            #select non continuous range
            gridwin.executeAction("SELECT", mkPropertyValues({"RANGE": "B1:B2"}))
            gridwin.executeAction("SELECT", mkPropertyValues({"RANGE": "A1:A2"}))
            gridwin.executeAction("SELECT", mkPropertyValues({"RANGE": "A4:A5", "EXTEND":"1"}))

            #lowercase - CommandSent Name:.uno:ChangeCaseToLower
            self.xUITest.executeCommand(".uno:ChangeCaseToLower")
            self.assertEqual(get_cell_by_position(document, 0, 0, 0).getString(), "hello world")
            self.assertEqual(get_cell_by_position(document, 0, 0, 1).getString(), "libre office")
            self.assertEqual(get_cell_by_position(document, 0, 0, 4).getString(), "")
            self.assertEqual(get_cell_by_position(document, 0, 0, 3).getString(), "free suite")

            #Capitalize every word - CommandSent Name:.uno:ChangeCaseToTitleCase
            self.xUITest.executeCommand(".uno:ChangeCaseToTitleCase")
            #Verify
            self.assertEqual(get_cell_by_position(document, 0, 0, 0).getString(), "Hello World")
            self.assertEqual(get_cell_by_position(document, 0, 0, 1).getString(), "Libre Office")
            self.assertEqual(get_cell_by_position(document, 0, 0, 4).getString(), "")
            self.assertEqual(get_cell_by_position(document, 0, 0, 3).getString(), "Free Suite")

            #Sentence case - CommandSent Name:.uno:ChangeCaseToSentenceCase
            self.xUITest.executeCommand(".uno:ChangeCaseToSentenceCase")

            self.assertEqual(get_cell_by_position(document, 0, 0, 0).getString(), "Hello world")
            self.assertEqual(get_cell_by_position(document, 0, 0, 1).getString(), "Libre office")
            self.assertEqual(get_cell_by_position(document, 0, 0, 4).getString(), "")
            self.assertEqual(get_cell_by_position(document, 0, 0, 3).getString(), "Free suite")

            #toggle case - CommandSent Name:.uno:ChangeCaseToToggleCase
            self.xUITest.executeCommand(".uno:ChangeCaseToToggleCase")
            self.assertEqual(get_cell_by_position(document, 0, 0, 0).getString(), "hELLO WORLD")
            self.assertEqual(get_cell_by_position(document, 0, 0, 1).getString(), "lIBRE OFFICE")
            self.assertEqual(get_cell_by_position(document, 0, 0, 4).getString(), "")
            self.assertEqual(get_cell_by_position(document, 0, 0, 3).getString(), "fREE SUITE")

            #uppercase = CommandSent Name:.uno:ChangeCaseToUpper
            self.xUITest.executeCommand(".uno:ChangeCaseToUpper")
            self.assertEqual(get_cell_by_position(document, 0, 0, 0).getString(), "HELLO WORLD")
            self.assertEqual(get_cell_by_position(document, 0, 0, 1).getString(), "LIBRE OFFICE")
            self.assertEqual(get_cell_by_position(document, 0, 0, 4).getString(), "")
            self.assertEqual(get_cell_by_position(document, 0, 0, 3).getString(), "FREE SUITE")

            #lowercase - CommandSent Name:.uno:ChangeCaseToLower
            self.xUITest.executeCommand(".uno:ChangeCaseToLower")
            self.assertEqual(get_cell_by_position(document, 0, 0, 0).getString(), "hello world")
            self.assertEqual(get_cell_by_position(document, 0, 0, 1).getString(), "libre office")
            self.assertEqual(get_cell_by_position(document, 0, 0, 4).getString(), "")
            self.assertEqual(get_cell_by_position(document, 0, 0, 3).getString(), "free suite")

            #cycle case = CommandSent Name:.uno:ChangeCaseRotateCase
            self.xUITest.executeCommand(".uno:ChangeCaseRotateCase")
            self.assertEqual(get_cell_by_position(document, 0, 0, 0).getString(), "Hello world")
            self.assertEqual(get_cell_by_position(document, 0, 0, 1).getString(), "Libre office")
            self.assertEqual(get_cell_by_position(document, 0, 0, 4).getString(), "")
            self.assertEqual(get_cell_by_position(document, 0, 0, 3).getString(), "Free suite")

    def test_tdf119162_Cycle_Case(self):
        #Bug 119162 - Format > Text > Cycle Case on attached example file hangs Calc reproducibly
        with self.ui_test.load_file(get_url_for_data_file("tdf119162.xls")) as calc_doc:
            xCalcDoc = self.xUITest.getTopFocusWindow()
            gridwin = xCalcDoc.getChild("grid_window")
            #1.Open the attached .xls file
            #2. Select column A
            gridwin.executeAction("SELECT", mkPropertyValues({"CELL": "A1"}))
            #3. Select [Format] > [Text] > [Cycle Case]
            self.xUITest.executeCommand(".uno:ChangeCaseRotateCase")
            self.xUITest.executeCommand(".uno:ChangeCaseToLower")
            #Actual Results:Freezes LibreOffice
            self.assertEqual(get_cell_by_position(calc_doc, 0, 0, 0).getString(), "test\n")

# vim: set shiftwidth=4 softtabstop=4 expandtab: