sw/PythonTest_sw_python.mk           |    1 
 sw/qa/python/check_xautotextgroup.py |  150 +++++++++++++++++++++++++++++++++++
 2 files changed, 151 insertions(+)

New commits:
commit c690fb0fa0f1e1e9ebdc782321b0b166f61e76f0
Author:     Serge Krot <serge.k...@cib.de>
AuthorDate: Tue Oct 2 18:59:29 2018 +0200
Commit:     Thorsten Behrens <thorsten.behr...@cib.de>
CommitDate: Fri Nov 23 00:07:39 2018 +0100

    sw: new unit test for XAutoTextGroup
    
    Change-Id: I3928248b73025f304c0e1ef7b5f86349df9a3c8d
    Reviewed-on: https://gerrit.libreoffice.org/61267
    Tested-by: Jenkins
    Reviewed-by: Thorsten Behrens <thorsten.behr...@cib.de>

diff --git a/sw/PythonTest_sw_python.mk b/sw/PythonTest_sw_python.mk
index 836c6e06378a..0dc15f929de0 100644
--- a/sw/PythonTest_sw_python.mk
+++ b/sw/PythonTest_sw_python.mk
@@ -27,6 +27,7 @@ $(eval $(call 
gb_PythonTest_add_modules,sw_python,$(SRCDIR)/sw/qa/python,\
        check_xtexttable \
        check_table \
        check_xautotextcontainer \
+       check_xautotextgroup \
        check_xmodifiable2 \
        check_xnamedgraph \
        check_xrefreshable \
diff --git a/sw/qa/python/check_xautotextgroup.py 
b/sw/qa/python/check_xautotextgroup.py
new file mode 100644
index 000000000000..a41987103e6b
--- /dev/null
+++ b/sw/qa/python/check_xautotextgroup.py
@@ -0,0 +1,150 @@
+#! /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
+from com.sun.star.container import ElementExistException
+from com.sun.star.container import NoSuchElementException
+from com.sun.star.uno import RuntimeException
+
+
+class XAutoTextGroup(unittest.TestCase):
+    # 0 indicates the path of the Office Basis layer
+    # 1 indicates the path of the user directory
+    GROUP_NAME = 'atg_name1*1'
+
+    @classmethod
+    def setUpClass(cls):
+        cls._uno = UnoInProcess()
+        cls._uno.setUp()
+        cls._uno.openEmptyWriterDoc()
+
+    def setUp(self):
+        self.xAutoTextContainer = self.createAutoTextContainer()
+        self.xAutoTextGroup = self.insertNewGroup(self.xAutoTextContainer)
+
+        self.xText = self._uno.getDoc().getText()
+        self.xCursor = self.xText.createTextCursor()
+        self.xRange = self.xCursor.getStart()
+
+    def tearDown(self):
+        self.xAutoTextContainer.removeByName(self.GROUP_NAME)
+
+    @classmethod
+    def tearDownClass(cls):
+        cls._uno.tearDown()
+
+    def test_XAutoTextGroup(self):
+        xName = 'Name'
+        xTitle = 'Title'
+
+        titlesBefore = self.xAutoTextGroup.getTitles()
+
+        self.xAutoTextGroup.insertNewByName(xName, xTitle, self.xRange)
+        self.assertNotEqual(titlesBefore, self.xAutoTextGroup.getTitles())
+
+        self.xAutoTextGroup.removeByName(xName)
+        self.assertEqual(titlesBefore, self.xAutoTextGroup.getTitles())
+
+    def test_XAutoTextGroup_NoTitle(self):
+        xName = 'Name'
+
+        titlesBefore = self.xAutoTextGroup.getTitles()
+
+        self.xAutoTextGroup.insertNewByName(xName, xName, self.xRange)
+        self.assertNotEqual(titlesBefore, self.xAutoTextGroup.getTitles())
+
+        self.xAutoTextGroup.removeByName(xName)
+        self.assertEqual(titlesBefore, self.xAutoTextGroup.getTitles())
+
+    def test_insertNewByName_Twice(self):
+        xName = 'Name'
+        xTitle = 'Title'
+
+        self.xAutoTextGroup.insertNewByName(xName, xTitle, self.xRange)
+
+        with self.assertRaises(ElementExistException):
+            self.xAutoTextGroup.insertNewByName(xName, xTitle, self.xRange)
+
+        self.xAutoTextGroup.removeByName(xName)
+
+    def test_renameByName(self):
+        xName = 'Name'
+        xTitle = 'Title'
+
+        xNewName = 'New Name'
+        xNewTitle = 'New Title'
+
+        self.xAutoTextGroup.insertNewByName(xName, xTitle, self.xRange)
+        self.xAutoTextGroup.renameByName(xName, xNewName, xNewTitle)
+
+        titlesBefore = self.xAutoTextGroup.getTitles()
+        with self.assertRaises(NoSuchElementException):
+            self.xAutoTextGroup.removeByName(xName)
+        titlesAfter = self.xAutoTextGroup.getTitles()
+        self.assertEqual(titlesBefore, titlesAfter)
+
+        self.xAutoTextGroup.removeByName(xNewName)
+        titlesAfter2 = self.xAutoTextGroup.getTitles()
+        self.assertNotEqual(titlesBefore, titlesAfter2)
+
+    def test_renameByName_Failed(self):
+        xName = 'Name'
+        xTitle = 'Title'
+
+        xNewName = 'New Name'
+        xNewTitle = 'New Title'
+
+        self.xAutoTextGroup.insertNewByName(xName, xTitle, self.xRange)
+        self.xAutoTextGroup.insertNewByName(xNewName, xNewTitle, self.xRange)
+
+        with self.assertRaises(ElementExistException):
+            self.xAutoTextGroup.renameByName(xName, xNewName, xNewTitle)
+
+        self.xAutoTextGroup.removeByName(xName)
+        self.xAutoTextGroup.removeByName(xNewName)
+
+    def test_removeByName_Twice(self):
+        xName = 'Name'
+        xTitle = 'Title'
+
+        self.xAutoTextGroup.insertNewByName(xName, xTitle, self.xRange)
+        self.xAutoTextGroup.removeByName(xName)
+
+        # 2nd attempt should fail
+        with self.assertRaises(NoSuchElementException):
+            self.xAutoTextGroup.removeByName(xName)
+
+    def test_removeByName_Empty(self):
+        with self.assertRaises(NoSuchElementException):
+            self.xAutoTextGroup.removeByName('')
+
+    def test_removeByName_NoSuchElement(self):
+        with self.assertRaises(NoSuchElementException):
+            self.xAutoTextGroup.removeByName('ForSureNotExistName1')
+
+    def createAutoTextContainer(self):
+        xServiceManager = self._uno.xContext.ServiceManager
+        self.assertIsNotNone(xServiceManager)
+        xAutoTextContainer = 
xServiceManager.createInstance("com.sun.star.text.AutoTextContainer")
+        self.assertIsNotNone(xAutoTextContainer)
+
+        return xAutoTextContainer
+
+    def insertNewGroup(self, xAutoTextContainer):
+        self.assertIsNotNone(xAutoTextContainer)
+        xAutoTextGroup = xAutoTextContainer.insertNewByName(self.GROUP_NAME)
+        self.assertIsNotNone(xAutoTextGroup)
+        return xAutoTextGroup
+
+
+if __name__ == '__main__':
+    unittest.main()
+
+# vim: set shiftwidth=4 softtabstop=4 expandtab:
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to