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/.
10 from uitest
.framework
import UITestCase
11 from libreoffice
.uno
.propertyvalue
import mkPropertyValues
12 from uitest
.uihelper
.common
import get_state_as_dict
, get_url_for_data_file
, type_text
14 class writerWordCount(UITestCase
):
16 def test_word_count_dialog(self
):
18 with self
.ui_test
.create_doc_in_start_center("writer"):
19 xWriterDoc
= self
.xUITest
.getTopFocusWindow()
20 xWriterEdit
= xWriterDoc
.getChild("writer_edit")
22 type_text(xWriterEdit
, "Test for word count dialog") #type text
23 xWriterEdit
.executeAction("SELECT", mkPropertyValues({"START_POS": "0", "END_POS": "8"})) #select two words
25 with self
.ui_test
.execute_modeless_dialog_through_command(".uno:WordCountDialog", close_button
="close") as xDialog
:
27 xselectwords
= xDialog
.getChild("selectwords")
28 xdocwords
= xDialog
.getChild("docwords")
29 xselectchars
= xDialog
.getChild("selectchars")
30 xdocchars
= xDialog
.getChild("docchars")
31 xselectcharsnospaces
= xDialog
.getChild("selectcharsnospaces")
32 xdoccharsnospaces
= xDialog
.getChild("doccharsnospaces")
33 xselectcjkchars
= xDialog
.getChild("selectcjkchars")
34 xdoccjkchars
= xDialog
.getChild("doccjkchars")
36 self
.assertEqual(get_state_as_dict(xselectwords
)["Text"], "2")
37 self
.assertEqual(get_state_as_dict(xdocwords
)["Text"], "5")
38 self
.assertEqual(get_state_as_dict(xselectchars
)["Text"], "8")
39 self
.assertEqual(get_state_as_dict(xdocchars
)["Text"], "26")
40 self
.assertEqual(get_state_as_dict(xselectcharsnospaces
)["Text"], "7")
41 self
.assertEqual(get_state_as_dict(xdoccharsnospaces
)["Text"], "22")
42 self
.assertEqual(get_state_as_dict(xselectcjkchars
)["Text"], "0")
43 self
.assertEqual(get_state_as_dict(xdoccjkchars
)["Text"], "0")
46 def test_tdf68347(self
):
47 #Bug 68347 - Incorrect word count in a document with recorded changes
48 with self
.ui_test
.load_file(get_url_for_data_file("tdf68347.odt")):
49 xWriterDoc
= self
.xUITest
.getTopFocusWindow()
50 xWriterEdit
= xWriterDoc
.getChild("writer_edit")
52 xWriterEdit
.executeAction("SELECT", mkPropertyValues({"START_POS": "24", "END_POS": "39"})) #select two words
54 with self
.ui_test
.execute_modeless_dialog_through_command(".uno:WordCountDialog", close_button
="close") as xDialog
:
55 xselectwords
= xDialog
.getChild("selectwords")
56 xdocwords
= xDialog
.getChild("docwords")
57 xselectchars
= xDialog
.getChild("selectchars")
58 xdocchars
= xDialog
.getChild("docchars")
59 xselectcharsnospaces
= xDialog
.getChild("selectcharsnospaces")
60 xselectcjkchars
= xDialog
.getChild("selectcjkchars")
61 xdoccjkchars
= xDialog
.getChild("doccjkchars")
63 self
.assertEqual(get_state_as_dict(xselectwords
)["Text"], "4")
64 self
.assertEqual(get_state_as_dict(xdocwords
)["Text"], "12")
65 self
.assertEqual(get_state_as_dict(xselectchars
)["Text"], "15")
66 self
.assertEqual(get_state_as_dict(xdocchars
)["Text"], "54")
67 self
.assertEqual(get_state_as_dict(xselectcharsnospaces
)["Text"], "12")
68 #Bug 117703 Word Count: Wrong result for "Characters excluding spaces"
69 #self.assertEqual(get_state_as_dict(xdoccharsnospaces)["Text"], "44")
70 self
.assertEqual(get_state_as_dict(xselectcjkchars
)["Text"], "0")
71 self
.assertEqual(get_state_as_dict(xdoccjkchars
)["Text"], "0")
73 def test_tdf91100(self
):
74 with self
.ui_test
.create_doc_in_start_center("writer"):
76 with self
.ui_test
.execute_modeless_dialog_through_command(".uno:WordCountDialog", close_button
="close"):
79 def test_tdf58050(self
):
80 with self
.ui_test
.load_file(get_url_for_data_file("tdf58050.html")):
82 with self
.ui_test
.execute_modeless_dialog_through_command(".uno:WordCountDialog", close_button
="close") as xDialog
:
84 xselectwords
= xDialog
.getChild("selectwords")
85 xdocwords
= xDialog
.getChild("docwords")
86 xselectchars
= xDialog
.getChild("selectchars")
87 xdocchars
= xDialog
.getChild("docchars")
88 xselectcharsnospaces
= xDialog
.getChild("selectcharsnospaces")
89 xdoccharsnospaces
= xDialog
.getChild("doccharsnospaces")
90 xselectcjkchars
= xDialog
.getChild("selectcjkchars")
91 xdoccjkchars
= xDialog
.getChild("doccjkchars")
93 self
.assertEqual(get_state_as_dict(xselectwords
)["Text"], "0")
94 self
.assertEqual(get_state_as_dict(xdocwords
)["Text"], "3")
95 self
.assertEqual(get_state_as_dict(xselectchars
)["Text"], "0")
96 self
.assertEqual(get_state_as_dict(xdocchars
)["Text"], "14")
97 self
.assertEqual(get_state_as_dict(xselectcharsnospaces
)["Text"], "0")
98 self
.assertEqual(get_state_as_dict(xdoccharsnospaces
)["Text"], "12")
99 self
.assertEqual(get_state_as_dict(xselectcjkchars
)["Text"], "0")
100 self
.assertEqual(get_state_as_dict(xdoccjkchars
)["Text"], "0")
102 def test_word_count_interpunction_counted_tdf56975_a(self
):
104 with self
.ui_test
.create_doc_in_start_center("writer"):
105 xWriterDoc
= self
.xUITest
.getTopFocusWindow()
106 xWriterEdit
= xWriterDoc
.getChild("writer_edit")
107 #Open writer, enter "Testing one two! Test?"
108 type_text(xWriterEdit
, "Testing one two! Test?")
109 #-> LO says: 4 words. SUCCESS! :)
110 with self
.ui_test
.execute_modeless_dialog_through_command(".uno:WordCountDialog", close_button
="close") as xDialog
:
112 xselectwords
= xDialog
.getChild("selectwords")
113 xdocwords
= xDialog
.getChild("docwords")
114 xselectchars
= xDialog
.getChild("selectchars")
115 xdocchars
= xDialog
.getChild("docchars")
116 xselectcharsnospaces
= xDialog
.getChild("selectcharsnospaces")
117 xdoccharsnospaces
= xDialog
.getChild("doccharsnospaces")
118 xselectcjkchars
= xDialog
.getChild("selectcjkchars")
119 xdoccjkchars
= xDialog
.getChild("doccjkchars")
121 self
.assertEqual(get_state_as_dict(xselectwords
)["Text"], "0")
122 self
.assertEqual(get_state_as_dict(xdocwords
)["Text"], "4")
123 self
.assertEqual(get_state_as_dict(xselectchars
)["Text"], "0")
124 self
.assertEqual(get_state_as_dict(xdocchars
)["Text"], "22")
125 self
.assertEqual(get_state_as_dict(xselectcharsnospaces
)["Text"], "0")
126 self
.assertEqual(get_state_as_dict(xdoccharsnospaces
)["Text"], "19")
127 self
.assertEqual(get_state_as_dict(xselectcjkchars
)["Text"], "0")
128 self
.assertEqual(get_state_as_dict(xdoccjkchars
)["Text"], "0")
131 def test_word_count_interpunction_counted_tdf56975_b(self
):
133 with self
.ui_test
.create_doc_in_start_center("writer"):
134 xWriterDoc
= self
.xUITest
.getTopFocusWindow()
135 xWriterEdit
= xWriterDoc
.getChild("writer_edit")
136 #1. Create a new text document.
137 #2. Type-in the words:
138 # This is a test sentence.
139 type_text(xWriterEdit
, "This is a test sentence.")
140 #3. Open the word count dialogue.
141 # Word count in both, dialogue and status line, shows 5 words.
142 with self
.ui_test
.execute_modeless_dialog_through_command(".uno:WordCountDialog", close_button
="close") as xDialog
:
144 xselectwords
= xDialog
.getChild("selectwords")
145 xdocwords
= xDialog
.getChild("docwords")
146 xselectchars
= xDialog
.getChild("selectchars")
147 xdocchars
= xDialog
.getChild("docchars")
148 xselectcharsnospaces
= xDialog
.getChild("selectcharsnospaces")
149 xdoccharsnospaces
= xDialog
.getChild("doccharsnospaces")
150 xselectcjkchars
= xDialog
.getChild("selectcjkchars")
151 xdoccjkchars
= xDialog
.getChild("doccjkchars")
153 self
.assertEqual(get_state_as_dict(xselectwords
)["Text"], "0")
154 self
.assertEqual(get_state_as_dict(xdocwords
)["Text"], "5")
155 self
.assertEqual(get_state_as_dict(xselectchars
)["Text"], "0")
156 self
.assertEqual(get_state_as_dict(xdocchars
)["Text"], "24")
157 self
.assertEqual(get_state_as_dict(xselectcharsnospaces
)["Text"], "0")
158 self
.assertEqual(get_state_as_dict(xdoccharsnospaces
)["Text"], "20")
159 self
.assertEqual(get_state_as_dict(xselectcjkchars
)["Text"], "0")
160 self
.assertEqual(get_state_as_dict(xdoccjkchars
)["Text"], "0")
161 #4. Select the space between 'a' and 'test'.
162 xWriterEdit
.executeAction("SELECT", mkPropertyValues({"START_POS": "9", "END_POS": "10"}))
163 #5. Replace selection by a non-breaking space by pressing Shift+Ctrl+Space. Don't move the cursor.
164 self
.xUITest
.executeCommand(".uno:InsertNonBreakingSpace")
165 # Word count in dialogue shows 4 words, whereas in the status line it shows 5 words.
166 with self
.ui_test
.execute_modeless_dialog_through_command(".uno:WordCountDialog", close_button
="close") as xDialog
:
168 xselectwords
= xDialog
.getChild("selectwords")
169 xdocwords
= xDialog
.getChild("docwords")
170 xselectchars
= xDialog
.getChild("selectchars")
171 xdocchars
= xDialog
.getChild("docchars")
172 xselectcharsnospaces
= xDialog
.getChild("selectcharsnospaces")
173 xdoccharsnospaces
= xDialog
.getChild("doccharsnospaces")
174 xselectcjkchars
= xDialog
.getChild("selectcjkchars")
175 xdoccjkchars
= xDialog
.getChild("doccjkchars")
177 self
.assertEqual(get_state_as_dict(xselectwords
)["Text"], "0")
178 self
.assertEqual(get_state_as_dict(xdocwords
)["Text"], "5")
179 self
.assertEqual(get_state_as_dict(xselectchars
)["Text"], "0")
180 self
.assertEqual(get_state_as_dict(xdocchars
)["Text"], "24")
181 self
.assertEqual(get_state_as_dict(xselectcharsnospaces
)["Text"], "0")
182 self
.assertEqual(get_state_as_dict(xdoccharsnospaces
)["Text"], "20")
183 self
.assertEqual(get_state_as_dict(xselectcjkchars
)["Text"], "0")
184 self
.assertEqual(get_state_as_dict(xdoccjkchars
)["Text"], "0")
185 #6. Move the cursor by pressing Left.
186 self
.xUITest
.executeCommand(".uno:GoLeft")
187 # Word count in both, dialogue and status line, shows 5 words.
188 with self
.ui_test
.execute_modeless_dialog_through_command(".uno:WordCountDialog", close_button
="close") as xDialog
:
190 xselectwords
= xDialog
.getChild("selectwords")
191 xdocwords
= xDialog
.getChild("docwords")
192 xselectchars
= xDialog
.getChild("selectchars")
193 xdocchars
= xDialog
.getChild("docchars")
194 xselectcharsnospaces
= xDialog
.getChild("selectcharsnospaces")
195 xdoccharsnospaces
= xDialog
.getChild("doccharsnospaces")
196 xselectcjkchars
= xDialog
.getChild("selectcjkchars")
197 xdoccjkchars
= xDialog
.getChild("doccjkchars")
199 self
.assertEqual(get_state_as_dict(xselectwords
)["Text"], "0")
200 self
.assertEqual(get_state_as_dict(xdocwords
)["Text"], "5")
201 self
.assertEqual(get_state_as_dict(xselectchars
)["Text"], "0")
202 self
.assertEqual(get_state_as_dict(xdocchars
)["Text"], "24")
203 self
.assertEqual(get_state_as_dict(xselectcharsnospaces
)["Text"], "0")
204 self
.assertEqual(get_state_as_dict(xdoccharsnospaces
)["Text"], "20")
205 self
.assertEqual(get_state_as_dict(xselectcjkchars
)["Text"], "0")
206 self
.assertEqual(get_state_as_dict(xdoccjkchars
)["Text"], "0")
208 def test_tdf51816(self
):
209 with self
.ui_test
.load_file(get_url_for_data_file("tdf51816.odt")):
210 #1. Open attached document
211 #2. Tools> Word count
212 with self
.ui_test
.execute_modeless_dialog_through_command(".uno:WordCountDialog", close_button
="close") as xDialog
:
213 xselectwords
= xDialog
.getChild("selectwords")
214 xselectchars
= xDialog
.getChild("selectchars")
215 xselectcharsnospaces
= xDialog
.getChild("selectcharsnospaces")
217 #3. Click after "At nunc" then <Ctrl><Shift><Left>
218 self
.xUITest
.executeCommand(".uno:GoRight")
219 self
.xUITest
.executeCommand(".uno:GoRight")
220 self
.xUITest
.executeCommand(".uno:GoRight")
221 self
.xUITest
.executeCommand(".uno:GoRight")
222 self
.xUITest
.executeCommand(".uno:GoRight")
223 self
.xUITest
.executeCommand(".uno:GoRight")
224 self
.xUITest
.executeCommand(".uno:GoRight")
225 self
.xUITest
.executeCommand(".uno:WordLeftSel")
227 #needs to wait, because Word count dialog is already open and it takes time to refresh the counter
228 #Expected result : Words 1 & Characters 4 #Actual result : Words 0 & Characters 0
229 self
.ui_test
.wait_until_property_is_updated(xselectwords
, "Text", "1")
230 self
.assertEqual(get_state_as_dict(xselectwords
)["Text"], "1")
231 self
.assertEqual(get_state_as_dict(xselectchars
)["Text"], "4")
233 #4. Click after "At nunc" then <Shift><Home>
234 self
.xUITest
.executeCommand(".uno:StartOfParaSel")
236 #needs to wait, because Word count dialog is already open and it takes time to refresh the counter
237 #Expected result : Words 2 & Characters 7 & excluding space 6 #Actual result : Words 0 & Characters 0
238 self
.ui_test
.wait_until_property_is_updated(xselectwords
, "Text", "2")
239 self
.assertEqual(get_state_as_dict(xselectwords
)["Text"], "2")
240 self
.assertEqual(get_state_as_dict(xselectchars
)["Text"], "7")
242 self
.assertEqual(get_state_as_dict(xselectcharsnospaces
)["Text"], "6")
245 def test_tdf117703(self
):
246 with self
.ui_test
.load_file(get_url_for_data_file("tdf117703.odt")):
247 self
.xUITest
.getTopFocusWindow()
249 self
.xUITest
.executeCommand(".uno:SelectAll")
251 with self
.ui_test
.execute_modeless_dialog_through_command(".uno:WordCountDialog", close_button
="close") as xDialog
:
253 xselectwords
= xDialog
.getChild("selectwords")
254 xdocwords
= xDialog
.getChild("docwords")
255 xselectchars
= xDialog
.getChild("selectchars")
256 xdocchars
= xDialog
.getChild("docchars")
257 xselectcharsnospaces
= xDialog
.getChild("selectcharsnospaces")
258 xdoccharsnospaces
= xDialog
.getChild("doccharsnospaces")
259 xselectcjkchars
= xDialog
.getChild("selectcjkchars")
260 xdoccjkchars
= xDialog
.getChild("doccjkchars")
262 self
.assertEqual(get_state_as_dict(xselectwords
)["Text"], "12")
263 self
.assertEqual(get_state_as_dict(xdocwords
)["Text"], "12")
264 self
.assertEqual(get_state_as_dict(xselectchars
)["Text"], "54")
265 self
.assertEqual(get_state_as_dict(xdocchars
)["Text"], "54")
267 # Without the fix in place it would have failed with: AssertionError: '0' != '44'
268 self
.assertEqual(get_state_as_dict(xselectcharsnospaces
)["Text"], "44")
269 self
.assertEqual(get_state_as_dict(xdoccharsnospaces
)["Text"], "44")
270 self
.assertEqual(get_state_as_dict(xselectcjkchars
)["Text"], "0")
271 self
.assertEqual(get_state_as_dict(xdoccjkchars
)["Text"], "0")
273 # vim: set shiftwidth=4 softtabstop=4 expandtab: