sw: fixup XAutoTextContainer test
[LibreOffice.git] / sw / qa / python / check_xautotextcontainer.py
blobc460c3d0eaa62d654a99a2baa63a63c2c8fb806f
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
14 from com.sun.star.uno import RuntimeException
16 class XAutoTextContainer(unittest.TestCase):
17 # 0 indicates the path of the Office Basis layer
18 # 1 indicates the path of the user directory
19 GROUP_POSTFIX = '*1'
21 @classmethod
22 def setUpClass(cls):
23 cls._uno = UnoInProcess()
24 cls._uno.setUp()
25 cls._uno.openEmptyWriterDoc()
27 def setUp(self):
28 xServiceManager = self._uno.xContext.ServiceManager
29 self.xAutoTextContainer = xServiceManager.createInstance(
30 "com.sun.star.text.AutoTextContainer")
32 @classmethod
33 def tearDownClass(cls):
34 cls._uno.tearDown()
36 def test_insertNewByName(self):
37 # group name must contain a-z, A-z, 0-9, '_', ' ' only
38 xNames = ['Name', 'TEST', 'Name2', '_With_underscore_', 'with space', '123456']
39 for xName in xNames:
40 self.xAutoTextContainer.insertNewByName(xName+self.GROUP_POSTFIX)
41 self.xAutoTextContainer.removeByName(xName+self.GROUP_POSTFIX)
43 def test_insertNewByName_Spaces(self):
44 # add
45 xName = ' spaces '
46 self.xAutoTextContainer.insertNewByName(xName+self.GROUP_POSTFIX)
48 # try to remove
49 with self.assertRaises(NoSuchElementException):
50 self.xAutoTextContainer.removeByName(xName+self.GROUP_POSTFIX)
52 # remove trimmed
53 self.xAutoTextContainer.removeByName('spaces'+self.GROUP_POSTFIX)
55 def test_insertNewByName_Several(self):
56 xAutoTextGroup1 = self.xAutoTextContainer.insertNewByName(
57 "atc_name1"+self.GROUP_POSTFIX)
58 xAutoTextGroup2 = self.xAutoTextContainer.insertNewByName(
59 "atc_name2"+self.GROUP_POSTFIX)
60 xAutoTextGroup3 = self.xAutoTextContainer.insertNewByName(
61 "atc_name3"+self.GROUP_POSTFIX)
63 self.assertEqual("atc_name1"+self.GROUP_POSTFIX, xAutoTextGroup1.getName())
64 self.assertEqual("atc_name2"+self.GROUP_POSTFIX, xAutoTextGroup2.getName())
65 self.assertEqual("atc_name3"+self.GROUP_POSTFIX, xAutoTextGroup3.getName())
67 self.xAutoTextContainer.removeByName("atc_name1"+self.GROUP_POSTFIX)
68 self.xAutoTextContainer.removeByName("atc_name2"+self.GROUP_POSTFIX)
69 self.xAutoTextContainer.removeByName("atc_name3"+self.GROUP_POSTFIX)
71 def test_insertNewByName_DifferentCase(self):
72 xAutoTextGroup1 = self.xAutoTextContainer.insertNewByName("myname"+self.GROUP_POSTFIX)
73 xAutoTextGroup2 = self.xAutoTextContainer.insertNewByName("MYNAME"+self.GROUP_POSTFIX)
74 xAutoTextGroup3 = self.xAutoTextContainer.insertNewByName("MyName"+self.GROUP_POSTFIX)
76 self.assertEqual("myname"+self.GROUP_POSTFIX, xAutoTextGroup1.getName())
78 # Note: different platforms could support different cases
79 # in container names
80 validName2 = False
81 validName2 |= (xAutoTextGroup2.getName() == "MYNAME"+self.GROUP_POSTFIX)
82 validName2 |= (xAutoTextGroup2.getName()[:5] == "group")
84 validName3 = False
85 validName3 |= (xAutoTextGroup3.getName() == "MyName"+self.GROUP_POSTFIX)
86 validName3 |= (xAutoTextGroup3.getName()[:5] == "group")
88 self.assertTrue(validName2)
89 self.assertTrue(validName3)
91 self.xAutoTextContainer.removeByName("myname"+self.GROUP_POSTFIX)
93 xName = xAutoTextGroup2.getName()
94 xName = xName[:xName.find('*')]
95 self.xAutoTextContainer.removeByName(xName)
97 xName = xAutoTextGroup3.getName()
98 xName = xName[:xName.find('*')]
99 self.xAutoTextContainer.removeByName(xName)
101 def test_insertNewByName_Failed(self):
102 # group name must contain a-z, A-z, 0-9, '_', ' ' only
103 xNames = ['', 'Name!!!', 'Red & White', 'Name.With.Dot', 'Name-2', 'A1:B1']
104 for xName in xNames:
105 with self.assertRaises(IllegalArgumentException):
106 self.xAutoTextContainer.insertNewByName(xName)
108 def test_removeByName_Unknown(self):
109 with self.assertRaises(NoSuchElementException):
110 self.xAutoTextContainer.removeByName("Some Unknown Name")
112 def test_removeByName_DifferentCases(self):
113 self.xAutoTextContainer.insertNewByName('GroupName'+self.GROUP_POSTFIX)
115 with self.assertRaises(NoSuchElementException):
116 self.xAutoTextContainer.removeByName('groupname'+self.GROUP_POSTFIX)
118 with self.assertRaises(NoSuchElementException):
119 self.xAutoTextContainer.removeByName('GROUPNAME'+self.GROUP_POSTFIX)
121 self.xAutoTextContainer.removeByName('GroupName'+self.GROUP_POSTFIX)
124 if __name__ == '__main__':
125 unittest.main()
127 # vim: set shiftwidth=4 softtabstop=4 expandtab: