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/.
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
22 cls
._uno
= UnoInProcess()
24 cls
._uno
.openEmptyWriterDoc()
27 xServiceManager
= self
._uno
.xContext
.ServiceManager
28 self
.xAutoTextContainer
= xServiceManager
.createInstance(
29 "com.sun.star.text.AutoTextContainer")
32 def tearDownClass(cls
):
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']
39 self
.xAutoTextContainer
.insertNewByName(xName
+self
.GROUP_POSTFIX
)
40 self
.xAutoTextContainer
.removeByName(xName
+self
.GROUP_POSTFIX
)
42 def test_insertNewByName_Spaces(self
):
45 self
.xAutoTextContainer
.insertNewByName(xName
+self
.GROUP_POSTFIX
)
48 with self
.assertRaises(NoSuchElementException
):
49 self
.xAutoTextContainer
.removeByName(xName
+self
.GROUP_POSTFIX
)
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
80 validName2 |
= (xAutoTextGroup2
.getName() == "MYNAME"+self
.GROUP_POSTFIX
)
81 validName2 |
= (xAutoTextGroup2
.getName()[:5] == "group")
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']
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__':
126 # vim: set shiftwidth=4 softtabstop=4 expandtab: