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
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
23 cls
._uno
= UnoInProcess()
25 cls
._uno
.openEmptyWriterDoc()
28 xServiceManager
= self
._uno
.xContext
.ServiceManager
29 self
.xAutoTextContainer
= xServiceManager
.createInstance(
30 "com.sun.star.text.AutoTextContainer")
33 def tearDownClass(cls
):
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']
40 self
.xAutoTextContainer
.insertNewByName(xName
+self
.GROUP_POSTFIX
)
41 self
.xAutoTextContainer
.removeByName(xName
+self
.GROUP_POSTFIX
)
43 def test_insertNewByName_Spaces(self
):
46 self
.xAutoTextContainer
.insertNewByName(xName
+self
.GROUP_POSTFIX
)
49 with self
.assertRaises(NoSuchElementException
):
50 self
.xAutoTextContainer
.removeByName(xName
+self
.GROUP_POSTFIX
)
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
81 validName2 |
= (xAutoTextGroup2
.getName() == "MYNAME"+self
.GROUP_POSTFIX
)
82 validName2 |
= (xAutoTextGroup2
.getName()[:5] == "group")
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']
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__':
127 # vim: set shiftwidth=4 softtabstop=4 expandtab: