summaryrefslogtreecommitdiffstats
path: root/sw/qa/python/check_xmodifiable2.py
blob: 53082fc2865ef8e3ed7dcbf7885ca027de6e8d66 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
#! /usr/bin/env python
# -*- 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
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
import unittest
from org.libreoffice.unotest import UnoInProcess


class XModifiable2(unittest.TestCase):

    @classmethod
    def setUpClass(cls):
        cls._uno = UnoInProcess()
        cls._uno.setUp()

    @classmethod
    def tearDownClass(cls):
        cls._uno.tearDown()

    def test_XModifiable2(self):
        # initialization
        xDoc = self._uno.openEmptyWriterDoc()

        # perform unit test
        self.assertTrue(xDoc.isSetModifiedEnabled())

        self.assertTrue(xDoc.disableSetModified())
        self.assertFalse(xDoc.isSetModifiedEnabled())

        self.assertFalse(xDoc.enableSetModified())
        self.assertTrue(xDoc.isSetModifiedEnabled())

        # clean up
        xDoc.close(True)

    def test_XModifiable2_Double(self):
        # initialization
        xDoc = self._uno.openEmptyWriterDoc()

        # perform unit test
        self.assertTrue(xDoc.isSetModifiedEnabled())

        # try to disable
        # Expected return value:
        #   `TRUE` the changing of the modified state was disabled
        self.assertTrue(xDoc.disableSetModified())
        self.assertFalse(xDoc.isSetModifiedEnabled())

        # try to disable twice
        # Expected return value:
        #   `FALSE` the changing of the modified state was already disabled
        self.assertFalse(xDoc.disableSetModified())
        self.assertFalse(xDoc.isSetModifiedEnabled())

        # try to disable third time
        # Expected return value:
        #   `FALSE` the changing of the modified state was already disabled
        #   i.e. the same as in previous call
        self.assertFalse(xDoc.disableSetModified())
        self.assertFalse(xDoc.isSetModifiedEnabled())

        # try to enable
        # Expected return value:
        #   `FALSE` the changing of the modified state was enabled
        self.assertFalse(xDoc.enableSetModified())
        self.assertTrue(xDoc.isSetModifiedEnabled())

        # try to enable twice
        # Expected return value:
        #   `TRUE` the changing of the modified state was already enabled
        self.assertTrue(xDoc.enableSetModified())
        self.assertTrue(xDoc.isSetModifiedEnabled())

        # try to enable third time
        # Expected return value:
        #   `TRUE` the changing of the modified state was already enabled
        #   i.e. the same as in previous call
        self.assertTrue(xDoc.enableSetModified())
        self.assertTrue(xDoc.isSetModifiedEnabled())

        # clean up
        xDoc.close(True)

    def test_XModifiable2_setModified(self):
        # initialization
        xDoc = self._uno.openEmptyWriterDoc()

        # perform unit test
        # try to set modified flag when modification enabled
        self.assertTrue(xDoc.isSetModifiedEnabled())

        self.assertFalse(xDoc.isModified())
        xDoc.setModified(True)
        self.assertTrue(xDoc.isModified())

        xDoc.setModified(False)
        self.assertFalse(xDoc.isModified())

        # try to set modified flag when modification disabled
        self.assertTrue(xDoc.disableSetModified())
        self.assertFalse(xDoc.isSetModifiedEnabled())

        self.assertFalse(xDoc.isModified())
        xDoc.setModified(True)
        self.assertFalse(xDoc.isModified())

        self.assertFalse(xDoc.enableSetModified())
        self.assertTrue(xDoc.isSetModifiedEnabled())

        # document is still not modified
        self.assertFalse(xDoc.isModified())

        # try to set modified flag when modification enabled
        # and when we have changed the modification possibility
        self.assertTrue(xDoc.isSetModifiedEnabled())

        self.assertFalse(xDoc.isModified())
        xDoc.setModified(True)
        self.assertTrue(xDoc.isModified())

        xDoc.setModified(False)
        self.assertFalse(xDoc.isModified())

        # clean up
        xDoc.close(True)

    def test_setModified_ByContent(self):
        # initialization
        xDoc = self._uno.openEmptyWriterDoc()

        # perform unit test:
        #        set modified flag using text editing
        #        when modification of the flag is enabled
        self.assertTrue(xDoc.isSetModifiedEnabled())
        self.assertFalse(xDoc.isModified())

        cursor = xDoc.Text.createTextCursor()
        xDoc.Text.insertString(cursor, "The first paragraph", 0)

        self.assertTrue(xDoc.isSetModifiedEnabled())
        self.assertTrue(xDoc.isModified())

        # clean up
        xDoc.close(True)

    def test_setModified_ByContent_Blocked(self):
        # initialization
        xDoc = self._uno.openEmptyWriterDoc()

        # perform unit test:
        #       it is unable to set modified flag using text editing
        #       when modification of the flag was disabled
        self.assertTrue(xDoc.disableSetModified())
        self.assertFalse(xDoc.isSetModifiedEnabled())
        self.assertFalse(xDoc.isModified())

        cursor = xDoc.Text.createTextCursor()
        xDoc.Text.insertString(cursor, "The first paragraph", 0)

        self.assertFalse(xDoc.isSetModifiedEnabled())
        self.assertFalse(xDoc.isModified())

        # clean up
        xDoc.close(True)

    def test_WriteProtectedDocument(self):
        # initialization
        xDoc = self._uno.openTemplateFromTDOC('WriteProtected.odt')

        # perform unit test:
        #       it is unable to set modified flag using text editing
        #       when modification of the flag was disabled as
        #       ODT file was marked to be opened as read-only
        self.assertFalse(xDoc.isSetModifiedEnabled())
        self.assertFalse(xDoc.isModified())

        cursor = xDoc.Text.createTextCursor()
        xDoc.Text.insertString(cursor, "The first paragraph", 0)

        self.assertFalse(xDoc.isSetModifiedEnabled())
        self.assertFalse(xDoc.isModified())

        # clean up
        xDoc.close(True)


if __name__ == '__main__':
    unittest.main()

# vim: set shiftwidth=4 softtabstop=4 expandtab: