[Libreoffice-commits] core.git: sw/PythonTest_sw_python.mk sw/qa
Libreoffice Gerrit user
logerrit at kemper.freedesktop.org
Tue Oct 2 13:25:37 UTC 2018
sw/PythonTest_sw_python.mk | 1
sw/qa/python/check_xmodifiable2.py | 195 ++++++++++++++++++++++++++
sw/qa/python/testdocuments/WriteProtected.odt |binary
3 files changed, 196 insertions(+)
New commits:
commit e92a4bf08624159c64fcc45a9786ff2e41727bf2
Author: Serge Krot <Serge.Krot at cib.de>
AuthorDate: Fri Sep 28 19:53:36 2018 +0200
Commit: Thorsten Behrens <Thorsten.Behrens at CIB.de>
CommitDate: Tue Oct 2 15:25:14 2018 +0200
sw: new unit test for XModifiable2
Change-Id: I30c4db19db068ff73f34236776cb511280acbbd7
Reviewed-on: https://gerrit.libreoffice.org/61096
Tested-by: Jenkins
Reviewed-by: Samuel Mehrbrodt <Samuel.Mehrbrodt at cib.de>
Reviewed-by: Thorsten Behrens <Thorsten.Behrens at CIB.de>
diff --git a/sw/PythonTest_sw_python.mk b/sw/PythonTest_sw_python.mk
index 6c5a4c818fe8..37c0100fd70d 100644
--- a/sw/PythonTest_sw_python.mk
+++ b/sw/PythonTest_sw_python.mk
@@ -25,6 +25,7 @@ $(eval $(call gb_PythonTest_add_modules,sw_python,$(SRCDIR)/sw/qa/python,\
check_styles \
check_xtexttable \
check_table \
+ check_xmodifiable2 \
check_xnamedgraph \
check_xtextrangecompare \
get_expression \
diff --git a/sw/qa/python/check_xmodifiable2.py b/sw/qa/python/check_xmodifiable2.py
new file mode 100644
index 000000000000..e8b95dc2b329
--- /dev/null
+++ b/sw/qa/python/check_xmodifiable2.py
@@ -0,0 +1,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:
diff --git a/sw/qa/python/testdocuments/WriteProtected.odt b/sw/qa/python/testdocuments/WriteProtected.odt
new file mode 100644
index 000000000000..5e75e0e7f58a
Binary files /dev/null and b/sw/qa/python/testdocuments/WriteProtected.odt differ
More information about the Libreoffice-commits
mailing list