Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / sw / qa / python / check_xautotextcontainer.py
blobb01125dca3f482b427e13fc65f23468319ab741e
1 #! /usr/bin/env python
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/.
10 import unittest
11 from org.libreoffice.unotest import UnoInProcess
12 from com.sun.star.container import NoSuchElementException
13 from com.sun.star.lang import IllegalArgumentException
15 class XAutoTextContainer(unittest.TestCase):
16 # 0 indicates the path of the Office Basis layer
17 # 1 indicates the path of the user directory
18 GROUP_POSTFIX = '*1'
20 @classmethod
21 def setUpClass(cls):
22 cls._uno = UnoInProcess()
23 cls._uno.setUp()
24 cls._uno.openEmptyWriterDoc()
26 def setUp(self):
27 xServiceManager = self._uno.xContext.ServiceManager
28 self.xAutoTextContainer = xServiceManager.createInstance(
29 "com.sun.star.text.AutoTextContainer")
31 @classmethod
32 def tearDownClass(cls):
33 cls._uno.tearDown()
35 def test_insertNewByName(self):
36 # group name must contain a-z, A-z, 0-9, '_', ' ' only
37 xNames = ['Name', 'TEST', 'Name2', '_With_underscore_', 'with space', '123456']
38 for xName in xNames:
39 self.xAutoTextContainer.insertNewByName(xName+self.GROUP_POSTFIX)
40 self.xAutoTextContainer.removeByName(xName+self.GROUP_POSTFIX)
42 def test_insertNewByName_Spaces(self):
43 # add
44 xName = ' spaces '
45 self.xAutoTextContainer.insertNewByName(xName+self.GROUP_POSTFIX)
47 # try to remove
48 with self.assertRaises(NoSuchElementException):
49 self.xAutoTextContainer.removeByName(xName+self.GROUP_POSTFIX)
51 # remove trimmed
52 self.xAutoTextContainer.removeByName('spaces'+self.GROUP_POSTFIX)
54 def test_insertNewByName_Several(self):
55 xAutoTextGroup1 = self.xAutoTextContainer.insertNewByName(
56 "atc_name1"+self.GROUP_POSTFIX)
57 xAutoTextGroup2 = self.xAutoTextContainer.insertNewByName(
58 "atc_name2"+self.GROUP_POSTFIX)
59 xAutoTextGroup3 = self.xAutoTextContainer.insertNewByName(
60 "atc_name3"+self.GROUP_POSTFIX)
62 self.assertEqual("atc_name1"+self.GROUP_POSTFIX, xAutoTextGroup1.getName())
63 self.assertEqual("atc_name2"+self.GROUP_POSTFIX, xAutoTextGroup2.getName())
64 self.assertEqual("atc_name3"+self.GROUP_POSTFIX, xAutoTextGroup3.getName())
66 self.xAutoTextContainer.removeByName("atc_name1"+self.GROUP_POSTFIX)
67 self.xAutoTextContainer.removeByName("atc_name2"+self.GROUP_POSTFIX)
68 self.xAutoTextContainer.removeByName("atc_name3"+self.GROUP_POSTFIX)
70 def test_insertNewByName_DifferentCase(self):
71 xAutoTextGroup1 = self.xAutoTextContainer.insertNewByName("myname"+self.GROUP_POSTFIX)
72 xAutoTextGroup2 = self.xAutoTextContainer.insertNewByName("MYNAME"+self.GROUP_POSTFIX)
73 xAutoTextGroup3 = self.xAutoTextContainer.insertNewByName("MyName"+self.GROUP_POSTFIX)
75 self.assertEqual("myname"+self.GROUP_POSTFIX, xAutoTextGroup1.getName())
77 # Note: different platforms could support different cases
78 # in container names
79 validName2 = False
80 validName2 |= (xAutoTextGroup2.getName() == "MYNAME"+self.GROUP_POSTFIX)
81 validName2 |= (xAutoTextGroup2.getName()[:5] == "group")
83 validName3 = False
84 validName3 |= (xAutoTextGroup3.getName() == "MyName"+self.GROUP_POSTFIX)
85 validName3 |= (xAutoTextGroup3.getName()[:5] == "group")
87 self.assertTrue(validName2)
88 self.assertTrue(validName3)
90 self.xAutoTextContainer.removeByName("myname"+self.GROUP_POSTFIX)
92 xName = xAutoTextGroup2.getName()
93 xName = xName[:xName.find('*')]
94 self.xAutoTextContainer.removeByName(xName)
96 xName = xAutoTextGroup3.getName()
97 xName = xName[:xName.find('*')]
98 self.xAutoTextContainer.removeByName(xName)
100 def test_insertNewByName_Failed(self):
101 # group name must contain a-z, A-z, 0-9, '_', ' ' only
102 xNames = ['', 'Name!!!', 'Red & White', 'Name.With.Dot', 'Name-2', 'A1:B1']
103 for xName in xNames:
104 with self.assertRaises(IllegalArgumentException):
105 self.xAutoTextContainer.insertNewByName(xName)
107 def test_removeByName_Unknown(self):
108 with self.assertRaises(NoSuchElementException):
109 self.xAutoTextContainer.removeByName("Some Unknown Name")
111 def test_removeByName_DifferentCases(self):
112 self.xAutoTextContainer.insertNewByName('GroupName'+self.GROUP_POSTFIX)
114 with self.assertRaises(NoSuchElementException):
115 self.xAutoTextContainer.removeByName('groupname'+self.GROUP_POSTFIX)
117 with self.assertRaises(NoSuchElementException):
118 self.xAutoTextContainer.removeByName('GROUPNAME'+self.GROUP_POSTFIX)
120 self.xAutoTextContainer.removeByName('GroupName'+self.GROUP_POSTFIX)
123 if __name__ == '__main__':
124 unittest.main()
126 # vim: set shiftwidth=4 softtabstop=4 expandtab: