cid#1640468 Dereference after null check
[LibreOffice.git] / sw / qa / uitest / findReplace / findSimilarity.py
blobf12dcaea27aa8b90f4f6f5509123d925c5d2d4f6
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 libreoffice.uno.propertyvalue import mkPropertyValues
11 from uitest.uihelper.common import get_state_as_dict, get_url_for_data_file
13 #Find similarities
15 class findSimilarities(UITestCase):
16 def test_find_similarities(self):
17 with self.ui_test.load_file(get_url_for_data_file("findReplace.odt")):
18 xWriterDoc = self.xUITest.getTopFocusWindow()
19 xWriterEdit = xWriterDoc.getChild("writer_edit")
20 #verify: we are on page 1
21 self.assertEqual(get_state_as_dict(xWriterEdit)["CurrentPage"], "1")
22 # search and replace dialog
23 #find = seco
24 with self.ui_test.execute_modeless_dialog_through_command(".uno:SearchDialog", close_button="") as xDialog:
25 searchterm = xDialog.getChild("searchterm")
26 searchterm.executeAction("TYPE", mkPropertyValues({"TEXT":"seco"})) #seco
27 # check similarities, button similarities, set values = 1; close dialog with OK
29 similarity = xDialog.getChild("similarity")
30 if get_state_as_dict(similarity)['Selected'] == 'false':
31 similarity.executeAction("CLICK", tuple())
33 similaritybtn = xDialog.getChild("similaritybtn")
35 with self.ui_test.execute_blocking_action(similaritybtn.executeAction, args=('CLICK', ())) as dialog:
36 otherfld = dialog.getChild("otherfld")
37 longerfld = dialog.getChild("longerfld")
38 shorterfld = dialog.getChild("shorterfld")
39 otherfld.executeAction("DOWN", tuple())
40 longerfld.executeAction("DOWN", tuple())
41 shorterfld.executeAction("DOWN", tuple())
43 #open dialog again, verify values = 1; close dialog with cancel
44 with self.ui_test.execute_blocking_action(similaritybtn.executeAction, args=('CLICK', ()), close_button="cancel") as dialog:
45 otherfld = dialog.getChild("otherfld")
46 longerfld = dialog.getChild("longerfld")
47 shorterfld = dialog.getChild("shorterfld")
48 self.assertEqual(get_state_as_dict(otherfld)["Text"], "1")
49 self.assertEqual(get_state_as_dict(longerfld)["Text"], "1")
50 self.assertEqual(get_state_as_dict(shorterfld)["Text"], "1")
52 xsearch = xDialog.getChild("search")
53 xsearch.executeAction("CLICK", tuple())
54 # Find next - not found
55 self.assertEqual(get_state_as_dict(xWriterEdit)["CurrentPage"], "1")
56 #find = secon
57 searchterm.executeAction("TYPE", mkPropertyValues({"KEYCODE":"CTRL+A"}))
58 searchterm.executeAction("TYPE", mkPropertyValues({"KEYCODE":"BACKSPACE"}))
59 searchterm.executeAction("TYPE", mkPropertyValues({"TEXT":"secon"}))
60 # Find next - verify: we are on page 2
61 xsearch = xDialog.getChild("search")
62 xsearch.executeAction("CLICK", tuple())
63 self.assertEqual(get_state_as_dict(xWriterEdit)["CurrentPage"], "2")
64 xWriterEdit.executeAction("TYPE", mkPropertyValues({"KEYCODE": "LEFT"})) #word "second" is selected
65 #find = irst
66 searchterm.executeAction("TYPE", mkPropertyValues({"KEYCODE":"CTRL+A"}))
67 searchterm.executeAction("TYPE", mkPropertyValues({"KEYCODE":"BACKSPACE"}))
68 searchterm.executeAction("TYPE", mkPropertyValues({"TEXT":"irst"}))
69 # Find next - verify: we are on page 1
70 xsearch.executeAction("CLICK", tuple())
71 self.assertEqual(get_state_as_dict(xWriterEdit)["CurrentPage"], "1")
73 # vim: set shiftwidth=4 softtabstop=4 expandtab: