2 # -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*-
4 # This file is part of the LibreOffice project.
6 # This Source Code Form is subject to the terms of the Mozilla Public
7 # License, v. 2.0. If a copy of the MPL was not distributed with this
8 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
11 from org
.libreoffice
.unotest
import UnoInProcess
14 class XModifiable2(unittest
.TestCase
):
18 cls
._uno
= UnoInProcess()
22 def tearDownClass(cls
):
25 def test_XModifiable2(self
):
27 xDoc
= self
._uno
.openEmptyWriterDoc()
30 self
.assertTrue(xDoc
.isSetModifiedEnabled())
32 self
.assertTrue(xDoc
.disableSetModified())
33 self
.assertFalse(xDoc
.isSetModifiedEnabled())
35 self
.assertFalse(xDoc
.enableSetModified())
36 self
.assertTrue(xDoc
.isSetModifiedEnabled())
41 def test_XModifiable2_Double(self
):
43 xDoc
= self
._uno
.openEmptyWriterDoc()
46 self
.assertTrue(xDoc
.isSetModifiedEnabled())
49 # Expected return value:
50 # `TRUE` the changing of the modified state was disabled
51 self
.assertTrue(xDoc
.disableSetModified())
52 self
.assertFalse(xDoc
.isSetModifiedEnabled())
54 # try to disable twice
55 # Expected return value:
56 # `FALSE` the changing of the modified state was already disabled
57 self
.assertFalse(xDoc
.disableSetModified())
58 self
.assertFalse(xDoc
.isSetModifiedEnabled())
60 # try to disable third time
61 # Expected return value:
62 # `FALSE` the changing of the modified state was already disabled
63 # i.e. the same as in previous call
64 self
.assertFalse(xDoc
.disableSetModified())
65 self
.assertFalse(xDoc
.isSetModifiedEnabled())
68 # Expected return value:
69 # `FALSE` the changing of the modified state was enabled
70 self
.assertFalse(xDoc
.enableSetModified())
71 self
.assertTrue(xDoc
.isSetModifiedEnabled())
74 # Expected return value:
75 # `TRUE` the changing of the modified state was already enabled
76 self
.assertTrue(xDoc
.enableSetModified())
77 self
.assertTrue(xDoc
.isSetModifiedEnabled())
79 # try to enable third time
80 # Expected return value:
81 # `TRUE` the changing of the modified state was already enabled
82 # i.e. the same as in previous call
83 self
.assertTrue(xDoc
.enableSetModified())
84 self
.assertTrue(xDoc
.isSetModifiedEnabled())
89 def test_XModifiable2_setModified(self
):
91 xDoc
= self
._uno
.openEmptyWriterDoc()
94 # try to set modified flag when modification enabled
95 self
.assertTrue(xDoc
.isSetModifiedEnabled())
97 self
.assertFalse(xDoc
.isModified())
98 xDoc
.setModified(True)
99 self
.assertTrue(xDoc
.isModified())
101 xDoc
.setModified(False)
102 self
.assertFalse(xDoc
.isModified())
104 # try to set modified flag when modification disabled
105 self
.assertTrue(xDoc
.disableSetModified())
106 self
.assertFalse(xDoc
.isSetModifiedEnabled())
108 self
.assertFalse(xDoc
.isModified())
109 xDoc
.setModified(True)
110 self
.assertFalse(xDoc
.isModified())
112 self
.assertFalse(xDoc
.enableSetModified())
113 self
.assertTrue(xDoc
.isSetModifiedEnabled())
115 # document is still not modified
116 self
.assertFalse(xDoc
.isModified())
118 # try to set modified flag when modification enabled
119 # and when we have changed the modification possibility
120 self
.assertTrue(xDoc
.isSetModifiedEnabled())
122 self
.assertFalse(xDoc
.isModified())
123 xDoc
.setModified(True)
124 self
.assertTrue(xDoc
.isModified())
126 xDoc
.setModified(False)
127 self
.assertFalse(xDoc
.isModified())
132 def test_setModified_ByContent(self
):
134 xDoc
= self
._uno
.openEmptyWriterDoc()
137 # set modified flag using text editing
138 # when modification of the flag is enabled
139 self
.assertTrue(xDoc
.isSetModifiedEnabled())
140 self
.assertFalse(xDoc
.isModified())
142 cursor
= xDoc
.Text
.createTextCursor()
143 xDoc
.Text
.insertString(cursor
, "The first paragraph", 0)
145 self
.assertTrue(xDoc
.isSetModifiedEnabled())
146 self
.assertTrue(xDoc
.isModified())
151 def test_setModified_ByContent_Blocked(self
):
153 xDoc
= self
._uno
.openEmptyWriterDoc()
156 # it is unable to set modified flag using text editing
157 # when modification of the flag was disabled
158 self
.assertTrue(xDoc
.disableSetModified())
159 self
.assertFalse(xDoc
.isSetModifiedEnabled())
160 self
.assertFalse(xDoc
.isModified())
162 cursor
= xDoc
.Text
.createTextCursor()
163 xDoc
.Text
.insertString(cursor
, "The first paragraph", 0)
165 self
.assertFalse(xDoc
.isSetModifiedEnabled())
166 self
.assertFalse(xDoc
.isModified())
171 def test_WriteProtectedDocument(self
):
173 xDoc
= self
._uno
.openTemplateFromTDOC('WriteProtected.odt')
176 # it is able to set modified flag using text editing despite
177 # ODT file was marked to be opened as read-only
178 self
.assertTrue(xDoc
.isSetModifiedEnabled())
179 self
.assertFalse(xDoc
.isModified())
181 cursor
= xDoc
.Text
.createTextCursor()
182 xDoc
.Text
.insertString(cursor
, "The first paragraph", 0)
184 self
.assertTrue(xDoc
.isSetModifiedEnabled())
185 self
.assertTrue(xDoc
.isModified())
191 if __name__
== '__main__':
194 # vim: set shiftwidth=4 softtabstop=4 expandtab: