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/.
11 from uitest
.framework
import UITestCase
12 from uitest
.uihelper
.common
import get_state_as_dict
, get_url_for_data_file
13 from uitest
.uihelper
.common
import type_text
15 from libreoffice
.linguistic
.linguservice
import get_spellchecker
16 from libreoffice
.uno
.propertyvalue
import mkPropertyValues
17 from com
.sun
.star
.lang
import Locale
19 class SpellingAndGrammarDialog(UITestCase
):
21 def is_supported_locale(self
, language
, country
):
22 xSpellChecker
= get_spellchecker(self
.ui_test
._xContext
)
23 locales
= xSpellChecker
.getLocales()
24 for locale
in locales
:
25 if language
is not None:
26 if locale
.Language
!= language
:
29 if country
is not None:
30 if locale
.Country
!= country
:
33 # we found the correct combination
54 def test_tdf46852(self
):
55 supported_locale
= self
.is_supported_locale("en", "US")
56 if not supported_locale
:
57 self
.skipTest("no dictionary support for en_US available")
58 # This automates the steps described in the bug report tdf#46852
60 # Step 1: Create a document with repetitious misspelled words
61 with self
.ui_test
.create_doc_in_start_center("writer") as document
:
62 cursor
= document
.getCurrentController().getViewCursor()
63 # Inserted text must be en_US, so make sure to set language in current location
64 cursor
.CharLocale
= Locale("en", "US", "")
65 input_text
= self
.TDF46852_INPUT
.replace('\n', '\r') # \r = para break
66 document
.Text
.insertString(cursor
, input_text
, False)
68 # Step 2: Place cursor on 4th line after second "frogg"
70 cursor
.goLeft(1, False)
72 # Step 3: Initiate spellchecking, and make sure "Check grammar" is
74 with self
.ui_test
.execute_modeless_dialog_through_command(".uno:SpellingAndGrammarDialog", close_button
="") as xDialog
:
75 checkgrammar
= xDialog
.getChild('checkgrammar')
76 if get_state_as_dict(checkgrammar
)['Selected'] == 'true':
77 checkgrammar
.executeAction('CLICK', ())
78 self
.assertTrue(get_state_as_dict(checkgrammar
)['Selected'] == 'false')
80 # Step 4: Repetitively click on "Correct all" for each misspelling
81 # prompt until end of document is reached.
82 changeall
= xDialog
.getChild('changeall')
83 changeall
.executeAction("CLICK", ())
84 changeall
.executeAction("CLICK", ())
85 # The third time we click on changeall, the click action is going to
86 # block while two message boxes are shown, so we need to do this third
88 # Use empty close_button to open consecutive dialogs
89 with self
.ui_test
.execute_blocking_action(
90 changeall
.executeAction
, args
=('CLICK', ()), close_button
="") as dialog
:
91 # Step 5: Confirm to "Continue check at beginning of document"
92 xYesBtn
= dialog
.getChild("yes")
94 with self
.ui_test
.execute_blocking_action(
95 xYesBtn
.executeAction
, args
=('CLICK', ())):
98 output_text
= document
.Text
.getString().replace('\r\n', '\n')
99 self
.assertTrue(re
.match(self
.TDF46852_REGEX
, output_text
))
101 def test_tdf136855(self
):
102 supported_locale
= self
.is_supported_locale("en", "US")
103 if not supported_locale
:
104 self
.skipTest("no dictionary support for en_US available")
106 with self
.ui_test
.load_file(get_url_for_data_file("tdf136855.odt")) as writer_doc
:
108 with self
.ui_test
.execute_modeless_dialog_through_command(".uno:SpellingAndGrammarDialog", close_button
="close") as xDialog
:
110 xChangeBtn
= xDialog
.getChild('change')
112 # Without the fix in place, this test would have crashed here
113 xChangeBtn
.executeAction("CLICK", ())
115 output_text
= writer_doc
.Text
.getString().replace('\n', '').replace('\r', '')
116 self
.assertTrue(output_text
.startswith("xx xx xx xxxxxxxxxxix xxxxxxxxxxxxxxviii"))
118 def test_tdf66043(self
):
119 supported_locale
= self
.is_supported_locale("en", "US")
120 if not supported_locale
:
121 self
.skipTest("no dictionary support for en_US available")
122 with self
.ui_test
.load_file(get_url_for_data_file("tdf66043.fodt")) as writer_doc
:
123 # Step 1: Initiate spellchecking, and make sure "Check grammar" is
125 with self
.ui_test
.execute_modeless_dialog_through_command(".uno:SpellingAndGrammarDialog", close_button
="close") as xDialog
:
126 checkgrammar
= xDialog
.getChild('checkgrammar')
127 if get_state_as_dict(checkgrammar
)['Selected'] == 'true':
128 checkgrammar
.executeAction('CLICK', ())
129 self
.assertTrue(get_state_as_dict(checkgrammar
)['Selected'] == 'false')
131 # Step 2: Click on "Correct all" for each misspelling
132 # prompt until end of document is reached.
133 changeall
= xDialog
.getChild('changeall')
134 changeall
.executeAction("CLICK", ())
136 output_text
= writer_doc
.Text
.getString().replace('\r\n', '\n')
137 # This was "gooodgood baaad eeend" ("goood" is a deletion,
138 # "good" is an insertion by fixing the first misspelling),
139 # but now "goood" is not a misspelling because it is accepted
140 # correctly without the redline containing a deleted "o"
141 self
.assertEqual(output_text
, 'goood baaadbaaed eeend')
143 def test_tdf65535(self
):
144 supported_locale
= self
.is_supported_locale("en", "US")
145 if not supported_locale
:
146 self
.skipTest("no dictionary support for en_US available")
148 with self
.ui_test
.load_file(get_url_for_data_file("tdf65535.fodt")) as document
:
149 cursor
= document
.getCurrentController().getViewCursor()
150 # Inserted text must be en_US, so make sure to set language in current location
151 cursor
.CharLocale
= Locale("en", "US", "")
153 xMainWindow
= self
.xUITest
.getTopFocusWindow()
154 xEdit
= xMainWindow
.getChild("writer_edit")
156 # type a bad word after the word with comment
157 cursor
.goRight(5, False)
158 type_text(xEdit
, " baad")
159 cursor
.goLeft(10, False)
161 # fix the first word using the spelling dialog
162 with self
.ui_test
.execute_modeless_dialog_through_command(".uno:SpellingAndGrammarDialog", close_button
="close") as xDialog
:
163 checkgrammar
= xDialog
.getChild('checkgrammar')
164 if get_state_as_dict(checkgrammar
)['Selected'] == 'true':
165 checkgrammar
.executeAction('CLICK', ())
166 self
.assertTrue(get_state_as_dict(checkgrammar
)['Selected'] == 'false')
168 change
= xDialog
.getChild('change')
169 change
.executeAction("CLICK", ())
171 # FIXME: disabled for the sake of testing on lo-upsan build
172 # output_text = document.Text.getString()
173 # self.assertEqual(fixed_word, output_text)
175 # check the original comment
177 textfields
= document
.getTextFields()
178 for textfield
in textfields
:
179 if textfield
.supportsService("com.sun.star.text.TextField.Annotation"):
182 # This was False (lost comment)
183 self
.assertEqual(True, has_comment
)
185 def test_tdf157992(self
):
186 supported_locale
= self
.is_supported_locale("en", "US")
187 if not supported_locale
:
188 self
.skipTest("no dictionary support for en_US available")
190 with self
.ui_test
.load_file(get_url_for_data_file("tdf157992.odt")) as document
:
191 with self
.ui_test
.execute_modeless_dialog_through_command(".uno:SpellingAndGrammarDialog", close_button
="") as xDialog
:
192 sentence
= xDialog
.getChild('errorsentence')
193 sentence
.executeAction('TYPE', mkPropertyValues({'KEYCODE':'RIGHT'}))
194 sentence
.executeAction('TYPE', mkPropertyValues({'KEYCODE':'DELETE'}))
195 sentence
.executeAction('TYPE', mkPropertyValues({'KEYCODE':'DELETE'}))
196 sentence
.executeAction('TYPE', mkPropertyValues({'TEXT':'oo'}))
197 change
= xDialog
.getChild('change')
198 with self
.ui_test
.execute_blocking_action(
199 change
.executeAction
, args
=('CLICK', ()), close_button
="ok"):
200 footnotes
= document
.getFootnotes()
201 self
.assertTrue(len(footnotes
) == 1)
204 # vim: set shiftwidth=4 softtabstop=4 expandtab: