summaryrefslogtreecommitdiff
path: root/sw/qa/uitest/writer_tests4/spellDialog.py
diff options
context:
space:
mode:
Diffstat (limited to 'sw/qa/uitest/writer_tests4/spellDialog.py')
-rw-r--r--sw/qa/uitest/writer_tests4/spellDialog.py219
1 files changed, 148 insertions, 71 deletions
diff --git a/sw/qa/uitest/writer_tests4/spellDialog.py b/sw/qa/uitest/writer_tests4/spellDialog.py
index 635a9abfb5e7..76804053f7e7 100644
--- a/sw/qa/uitest/writer_tests4/spellDialog.py
+++ b/sw/qa/uitest/writer_tests4/spellDialog.py
@@ -1,3 +1,6 @@
+# -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*-
+#
+# This file is part of the LibreOffice project.
#
# 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
@@ -7,8 +10,10 @@
import re
from uitest.framework import UITestCase
from uitest.uihelper.common import get_state_as_dict, get_url_for_data_file
+from uitest.uihelper.common import type_text
from libreoffice.linguistic.linguservice import get_spellchecker
+from libreoffice.uno.propertyvalue import mkPropertyValues
from com.sun.star.lang import Locale
class SpellingAndGrammarDialog(UITestCase):
@@ -17,23 +22,17 @@ class SpellingAndGrammarDialog(UITestCase):
xSpellChecker = get_spellchecker(self.ui_test._xContext)
locales = xSpellChecker.getLocales()
for locale in locales:
- if language != None:
+ if language is not None:
if locale.Language != language:
continue
- if country != None:
+ if country is not None:
if locale.Country != country:
continue
# we found the correct combination
return True
- def launch_dialog(self):
- self.ui_test.execute_modeless_dialog_through_command(
- ".uno:SpellingAndGrammarDialog")
-
- return self.xUITest.getTopFocusWindow()
-
TDF46852_INPUT = """\
dogg
dogg
@@ -59,69 +58,147 @@ frog, dogg, catt"""
# This automates the steps described in the bug report tdf#46852
# Step 1: Create a document with repetitious misspelled words
- self.ui_test.create_doc_in_start_center("writer")
- document = self.ui_test.get_component()
- cursor = document.getCurrentController().getViewCursor()
- # Inserted text must be en_US, so make sure to set language in current location
- cursor.CharLocale = Locale("en", "US", "")
- input_text = self.TDF46852_INPUT.replace('\n', '\r') # \r = para break
- document.Text.insertString(cursor, input_text, False)
-
- # Step 2: Place cursor on 4th line after second "frogg"
- cursor.goUp(2, False)
- cursor.goLeft(1, False)
-
- # Step 3: Initiate spellchecking, and make sure "Check grammar" is
- # unchecked
- spell_dialog = self.launch_dialog()
- checkgrammar = spell_dialog.getChild('checkgrammar')
- if get_state_as_dict(checkgrammar)['Selected'] == 'true':
- checkgrammar.executeAction('CLICK', ())
- self.assertTrue(get_state_as_dict(checkgrammar)['Selected'] == 'false')
-
- # Step 4: Repetitively click on "Correct all" for each misspelling
- # prompt until end of document is reached.
- changeall = spell_dialog.getChild('changeall')
- changeall.executeAction("CLICK", ())
- changeall.executeAction("CLICK", ())
- # The third time we click on changeall, the click action is going to
- # block while two message boxes are shown, so we need to do this third
- # click specially:
- self.ui_test.execute_blocking_action(
- changeall.executeAction, args=('CLICK', ()),
- # Step 5: Confirm to "Continue check at beginning of document"
- dialog_handler=lambda dialog :
- self.ui_test.execute_blocking_action(
- dialog.getChild('yes').executeAction, 'ok', ('CLICK', ())
- )
- )
-
- output_text = document.Text.getString().replace('\r\n', '\n')
- self.assertTrue(re.match(self.TDF46852_REGEX, output_text))
+ with self.ui_test.create_doc_in_start_center("writer") as document:
+ cursor = document.getCurrentController().getViewCursor()
+ # Inserted text must be en_US, so make sure to set language in current location
+ cursor.CharLocale = Locale("en", "US", "")
+ input_text = self.TDF46852_INPUT.replace('\n', '\r') # \r = para break
+ document.Text.insertString(cursor, input_text, False)
+
+ # Step 2: Place cursor on 4th line after second "frogg"
+ cursor.goUp(2, False)
+ cursor.goLeft(1, False)
+
+ # Step 3: Initiate spellchecking, and make sure "Check grammar" is
+ # unchecked
+ with self.ui_test.execute_modeless_dialog_through_command(".uno:SpellingAndGrammarDialog", close_button="") as xDialog:
+ checkgrammar = xDialog.getChild('checkgrammar')
+ if get_state_as_dict(checkgrammar)['Selected'] == 'true':
+ checkgrammar.executeAction('CLICK', ())
+ self.assertEqual('false', get_state_as_dict(checkgrammar)['Selected'])
+
+ # Step 4: Repetitively click on "Correct all" for each misspelling
+ # prompt until end of document is reached.
+ changeall = xDialog.getChild('changeall')
+ changeall.executeAction("CLICK", ())
+ changeall.executeAction("CLICK", ())
+ # The third time we click on changeall, the click action is going to
+ # block while two message boxes are shown, so we need to do this third
+ # click specially
+ # Use empty close_button to open consecutive dialogs
+ with self.ui_test.execute_blocking_action(
+ changeall.executeAction, args=('CLICK', ()), close_button="") as dialog:
+ # Step 5: Confirm to "Continue check at beginning of document"
+ xYesBtn = dialog.getChild("yes")
+
+ with self.ui_test.execute_blocking_action(
+ xYesBtn.executeAction, args=('CLICK', ())):
+ pass
+
+ output_text = document.Text.getString().replace('\r\n', '\n')
+ self.assertTrue(re.match(self.TDF46852_REGEX, output_text))
+
+ def test_tdf136855(self):
+ supported_locale = self.is_supported_locale("en", "US")
+ if not supported_locale:
+ self.skipTest("no dictionary support for en_US available")
+
+ with self.ui_test.load_file(get_url_for_data_file("tdf136855.odt")) as writer_doc:
+
+ with self.ui_test.execute_modeless_dialog_through_command(".uno:SpellingAndGrammarDialog", close_button="close") as xDialog:
+
+ xChangeBtn = xDialog.getChild('change')
+ for i in range(6):
+ # Without the fix in place, this test would have crashed here
+ xChangeBtn.executeAction("CLICK", ())
+
+ output_text = writer_doc.Text.getString().replace('\n', '').replace('\r', '')
+ self.assertTrue(output_text.startswith("xx xx xx xxxxxxxxxxix xxxxxxxxxxxxxxviii"))
def test_tdf66043(self):
- writer_doc = self.ui_test.load_file(get_url_for_data_file("tdf66043.fodt"))
- document = self.ui_test.get_component()
- # Step 1: Initiate spellchecking, and make sure "Check grammar" is
- # unchecked
- spell_dialog = self.launch_dialog()
- checkgrammar = spell_dialog.getChild('checkgrammar')
- if get_state_as_dict(checkgrammar)['Selected'] == 'true':
- checkgrammar.executeAction('CLICK', ())
- self.assertTrue(get_state_as_dict(checkgrammar)['Selected'] == 'false')
-
- # Step 2: Click on "Correct all" for each misspelling
- # prompt until end of document is reached.
- changeall = spell_dialog.getChild('changeall')
- changeall.executeAction("CLICK", ())
-
- xCloseBtn = spell_dialog.getChild("close")
- xCloseBtn.executeAction("CLICK", tuple())
-
- output_text = document.Text.getString().replace('\r\n', '\n')
- # This was "gooodgood baaad eeend" ("goood" is a deletion,
- # "good" is an insertion by fixing the first misspelling),
- # but now "goood" is not a misspelling because it is accepted
- # correctly without the redline containing a deleted "o"
- self.assertEqual(output_text, 'goood baaadbaaed eeend')
+ supported_locale = self.is_supported_locale("en", "US")
+ if not supported_locale:
+ self.skipTest("no dictionary support for en_US available")
+ with self.ui_test.load_file(get_url_for_data_file("tdf66043.fodt")) as writer_doc:
+ # Step 1: Initiate spellchecking, and make sure "Check grammar" is
+ # unchecked
+ with self.ui_test.execute_modeless_dialog_through_command(".uno:SpellingAndGrammarDialog", close_button="close") as xDialog:
+ checkgrammar = xDialog.getChild('checkgrammar')
+ if get_state_as_dict(checkgrammar)['Selected'] == 'true':
+ checkgrammar.executeAction('CLICK', ())
+ self.assertEqual('false', get_state_as_dict(checkgrammar)['Selected'])
+
+ # Step 2: Click on "Correct all" for each misspelling
+ # prompt until end of document is reached.
+ changeall = xDialog.getChild('changeall')
+ changeall.executeAction("CLICK", ())
+
+ output_text = writer_doc.Text.getString().replace('\r\n', '\n')
+ # This was "gooodgood baaad eeend" ("goood" is a deletion,
+ # "good" is an insertion by fixing the first misspelling),
+ # but now "goood" is not a misspelling because it is accepted
+ # correctly without the redline containing a deleted "o"
+ self.assertEqual(output_text, 'goood baaadbaaed eeend')
+
+ def test_tdf65535(self):
+ supported_locale = self.is_supported_locale("en", "US")
+ if not supported_locale:
+ self.skipTest("no dictionary support for en_US available")
+
+ with self.ui_test.load_file(get_url_for_data_file("tdf65535.fodt")) as document:
+ cursor = document.getCurrentController().getViewCursor()
+ # Inserted text must be en_US, so make sure to set language in current location
+ cursor.CharLocale = Locale("en", "US", "")
+
+ xMainWindow = self.xUITest.getTopFocusWindow()
+ xEdit = xMainWindow.getChild("writer_edit")
+
+ # type a bad word after the word with comment
+ cursor.goRight(5, False)
+ type_text(xEdit, " baad")
+ cursor.goLeft(10, False)
+
+ # fix the first word using the spelling dialog
+ with self.ui_test.execute_modeless_dialog_through_command(".uno:SpellingAndGrammarDialog", close_button="close") as xDialog:
+ checkgrammar = xDialog.getChild('checkgrammar')
+ if get_state_as_dict(checkgrammar)['Selected'] == 'true':
+ checkgrammar.executeAction('CLICK', ())
+ self.assertEqual('false', get_state_as_dict(checkgrammar)['Selected'])
+
+ change = xDialog.getChild('change')
+ change.executeAction("CLICK", ())
+
+ # FIXME: disabled for the sake of testing on lo-upsan build
+ # output_text = document.Text.getString()
+ # self.assertEqual(fixed_word, output_text)
+
+ # check the original comment
+ has_comment = False
+ textfields = document.getTextFields()
+ for textfield in textfields:
+ if textfield.supportsService("com.sun.star.text.TextField.Annotation"):
+ has_comment = True
+
+ # This was False (lost comment)
+ self.assertEqual(True, has_comment)
+
+ def test_tdf157992(self):
+ supported_locale = self.is_supported_locale("en", "US")
+ if not supported_locale:
+ self.skipTest("no dictionary support for en_US available")
+ with self.ui_test.load_file(get_url_for_data_file("tdf157992.odt")) as document:
+ with self.ui_test.execute_modeless_dialog_through_command(".uno:SpellingAndGrammarDialog", close_button="") as xDialog:
+ sentence = xDialog.getChild('errorsentence')
+ sentence.executeAction('TYPE', mkPropertyValues({'KEYCODE':'RIGHT'}))
+ sentence.executeAction('TYPE', mkPropertyValues({'KEYCODE':'DELETE'}))
+ sentence.executeAction('TYPE', mkPropertyValues({'KEYCODE':'DELETE'}))
+ sentence.executeAction('TYPE', mkPropertyValues({'TEXT':'oo'}))
+ change = xDialog.getChild('change')
+ with self.ui_test.execute_blocking_action(
+ change.executeAction, args=('CLICK', ()), close_button="ok"):
+ footnotes = document.getFootnotes()
+ self.assertTrue(len(footnotes) == 1)
+
+
+# vim: set shiftwidth=4 softtabstop=4 expandtab: