cid#1640468 Dereference after null check
[LibreOffice.git] / sw / qa / uitest / writer_tests / comments.py
blob3e9d3a6301d83dfcdafb9033c24385df682ddb8b
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 uitest.uihelper.common import get_state_as_dict
12 from libreoffice.uno.propertyvalue import mkPropertyValues
13 #test comments
15 class Comments(UITestCase):
17 def test_comments_features(self):
19 with self.ui_test.create_doc_in_start_center("writer"):
21 xMainWindow = self.xUITest.getTopFocusWindow()
23 xwriter_edit = xMainWindow.getChild("writer_edit")
24 xwriter_edit.executeAction("TYPE", mkPropertyValues({"TEXT": "Before "}))
26 # adding new Comment
27 self.xUITest.executeCommand(".uno:InsertAnnotation")
29 # wait until the comment is available
30 xComment1 = self.ui_test.wait_until_child_is_available('Comment1')
32 xEditView1 = xComment1.getChild("editview")
33 xEditView1.executeAction("TYPE", mkPropertyValues({"TEXT": "This is the First Comment"}))
34 self.assertEqual(get_state_as_dict(xComment1)["Text"], "This is the First Comment" )
35 self.assertEqual(get_state_as_dict(xComment1)["Resolved"], "false" )
36 self.assertEqual(get_state_as_dict(xComment1)["Author"], "Unknown Author" )
37 self.assertEqual(get_state_as_dict(xComment1)["ReadOnly"], "false" )
39 xComment1.executeAction("LEAVE", mkPropertyValues({}))
41 xwriter_edit.executeAction("TYPE", mkPropertyValues({"TEXT": "After"}))
42 xwriter_edit.executeAction("SELECT", mkPropertyValues({"END_POS": "0", "START_POS": "13"}))
43 self.assertEqual(get_state_as_dict(xwriter_edit)["SelectedText"], "Before After" )
45 # test Resolve Comment
46 xComment1.executeAction("RESOLVE", mkPropertyValues({}))
47 self.assertEqual(get_state_as_dict(xComment1)["Resolved"], "true" )
49 # test Select text from Comment
50 xComment1.executeAction("SELECT", mkPropertyValues({"FROM": "0", "TO": "4"}))
51 self.assertEqual(get_state_as_dict(xComment1)["SelectedText"], "This" )
53 # test Hide then Show Comment
54 xComment1.executeAction("HIDE", mkPropertyValues({}))
55 self.assertEqual(get_state_as_dict(xComment1)["Visible"], "false" )
56 xComment1.executeAction("SHOW", mkPropertyValues({}))
57 self.assertEqual(get_state_as_dict(xComment1)["Visible"], "true" )
59 # test delete Comment
60 xComment1.executeAction("DELETE", mkPropertyValues({}))
61 self.assertTrue("Comment1" not in xMainWindow.getChildren())
64 def test_multi_comments(self):
66 with self.ui_test.create_doc_in_start_center("writer"):
68 xMainWindow = self.xUITest.getTopFocusWindow()
70 xwriter_edit = xMainWindow.getChild("writer_edit")
72 # adding 3 new Comment
73 xwriter_edit.executeAction("TYPE", mkPropertyValues({"TEXT": "Line 1"}))
74 self.xUITest.executeCommand(".uno:InsertAnnotation")
75 # wait until the comment is available
76 xComment1 = self.ui_test.wait_until_child_is_available('Comment1')
77 xEditView1 = xComment1.getChild("editview")
78 xEditView1.executeAction("TYPE", mkPropertyValues({"TEXT": "First Comment"}))
79 xComment1.executeAction("LEAVE", mkPropertyValues({}))
80 xwriter_edit.executeAction("TYPE", mkPropertyValues({"KEYCODE": "RETURN"}))
82 xwriter_edit.executeAction("TYPE", mkPropertyValues({"TEXT": "Line 2"}))
83 self.xUITest.executeCommand(".uno:InsertAnnotation")
84 # wait until the comment is available
85 xComment2 = self.ui_test.wait_until_child_is_available('Comment2')
86 xEditView2 = xComment2.getChild("editview")
87 xEditView2.executeAction("TYPE", mkPropertyValues({"TEXT": "Second Comment"}))
88 xComment2.executeAction("LEAVE", mkPropertyValues({}))
89 xwriter_edit.executeAction("TYPE", mkPropertyValues({"KEYCODE": "RETURN"}))
91 xwriter_edit.executeAction("TYPE", mkPropertyValues({"TEXT": "Line 3"}))
92 self.xUITest.executeCommand(".uno:InsertAnnotation")
93 # wait until the comment is available
94 xComment3 = self.ui_test.wait_until_child_is_available('Comment3')
95 xEditView3 = xComment3.getChild("editview")
96 xEditView3.executeAction("TYPE", mkPropertyValues({"TEXT": "Third Comment"}))
97 xComment3.executeAction("LEAVE", mkPropertyValues({}))
98 xwriter_edit.executeAction("TYPE", mkPropertyValues({"KEYCODE": "RETURN"}))
100 # Check text
101 self.assertEqual(get_state_as_dict(xComment1)["Text"], "First Comment" )
102 self.assertEqual(get_state_as_dict(xComment2)["Text"], "Second Comment" )
103 self.assertEqual(get_state_as_dict(xComment3)["Text"], "Third Comment" )
105 xComment2.executeAction("RESOLVE", mkPropertyValues({}))
106 xComment3.executeAction("RESOLVE", mkPropertyValues({}))
108 # Check Resolved
109 self.assertEqual(get_state_as_dict(xComment1)["Resolved"], "false" )
110 self.assertEqual(get_state_as_dict(xComment2)["Resolved"], "true" )
111 self.assertEqual(get_state_as_dict(xComment3)["Resolved"], "true" )
113 # Check ReadOnly
114 self.assertEqual(get_state_as_dict(xComment1)["ReadOnly"], "false" )
115 self.assertEqual(get_state_as_dict(xComment2)["ReadOnly"], "false" )
116 self.assertEqual(get_state_as_dict(xComment3)["ReadOnly"], "false" )
118 # Check Select
119 xComment1.executeAction("SELECT", mkPropertyValues({"FROM": "0", "TO": "5"}))
120 self.assertEqual(get_state_as_dict(xComment1)["SelectedText"], "First" )
122 xComment2.executeAction("SELECT", mkPropertyValues({"FROM": "0", "TO": "6"}))
123 self.assertEqual(get_state_as_dict(xComment2)["SelectedText"], "Second" )
125 xComment3.executeAction("SELECT", mkPropertyValues({"FROM": "0", "TO": "5"}))
126 self.assertEqual(get_state_as_dict(xComment3)["SelectedText"], "Third" )
128 # Check that they all are Visible
129 self.assertEqual(get_state_as_dict(xComment1)["Visible"], "true" )
130 self.assertEqual(get_state_as_dict(xComment2)["Visible"], "true" )
131 self.assertEqual(get_state_as_dict(xComment3)["Visible"], "true" )
133 # Hide all
134 xComment1.executeAction("HIDE", mkPropertyValues({}))
135 self.assertEqual(get_state_as_dict(xComment1)["Visible"], "false" )
136 xComment2.executeAction("HIDE", mkPropertyValues({}))
137 self.assertEqual(get_state_as_dict(xComment2)["Visible"], "false" )
138 xComment3.executeAction("HIDE", mkPropertyValues({}))
139 self.assertEqual(get_state_as_dict(xComment3)["Visible"], "false" )
141 # Show comment 2 only
142 xComment2.executeAction("SHOW", mkPropertyValues({}))
143 self.assertEqual(get_state_as_dict(xComment2)["Visible"], "true" )
145 # Then remove the 3 comments
146 xComment1.executeAction("DELETE", mkPropertyValues({}))
147 xComment2.executeAction("DELETE", mkPropertyValues({}))
148 xComment3.executeAction("DELETE", mkPropertyValues({}))
149 self.assertTrue("Comment1" not in xMainWindow.getChildren())
150 self.assertTrue("Comment2" not in xMainWindow.getChildren())
151 self.assertTrue("Comment3" not in xMainWindow.getChildren())
153 # vim: set shiftwidth=4 softtabstop=4 expandtab: