2 This file is part of the LibreOffice project.
4 This Source Code Form is subject to the terms of the Mozilla Public
5 License, v. 2.0. If a copy of the MPL was not distributed with this
6 file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 This file incorporates work covered by the following license notice:
10 Licensed to the Apache Software Foundation (ASF) under one or more
11 contributor license agreements. See the NOTICE file distributed
12 with this work for additional information regarding copyright
13 ownership. The ASF licenses this file to you under the Apache
14 License, Version 2.0 (the "License"); you may not use this file
15 except in compliance with the License. You may obtain a copy of
16 the License at http://www.apache.org/licenses/LICENSE-2.0 .
22 from org
.libreoffice
.unotest
import UnoInProcess
23 from com
.sun
.star
.beans
import PropertyValue
24 from com
.sun
.star
.container
import XIndexContainer
25 from org
.libreoffice
.unotest
import OfficeConnection
26 from com
.sun
.star
.lang
import IllegalArgumentException
27 from com
.sun
.star
.lang
import IndexOutOfBoundsException
30 class CheckIndexedPropertyValues(unittest
.TestCase
):
34 cls
._uno
= UnoInProcess()
36 cls
.xContext
= cls
._uno
.getContext()
37 cls
.xDoc
= cls
._uno
.openEmptyWriterDoc()
40 def tearDownClass(cls
):
43 def test_checkIndexedPropertyValues(self
):
44 xServiceManager
= self
.xContext
.ServiceManager
45 xCont
= xServiceManager
.createInstanceWithContext('com.sun.star.document.IndexedPropertyValues',
48 p1
= PropertyValue(Name
="Jupp", Value
="GoodGuy")
49 prop1
= uno
.Any("[]com.sun.star.beans.PropertyValue", (p1
,))
51 p2
= PropertyValue(Name
="Horst", Value
="BadGuy")
52 prop2
= uno
.Any("[]com.sun.star.beans.PropertyValue", (p2
,))
54 p3
= PropertyValue(Name
="Peter", Value
="FamilyGuy")
55 prop3
= uno
.Any("[]com.sun.star.beans.PropertyValue", (p3
,))
57 t
= xCont
.getElementType()
58 self
.assertEqual(0, len(xCont
), "Initial container is not empty")
59 uno
.invoke(xCont
, "insertByIndex", (0, prop1
))
62 self
.assertEqual(p1
.Name
, ret
[0].Name
)
63 self
.assertEqual(p1
.Value
, ret
[0].Value
)
65 uno
.invoke(xCont
, "replaceByIndex", (0, prop2
))
67 self
.assertEqual(p2
.Name
, ret
[0].Name
)
68 self
.assertEqual(p2
.Value
, ret
[0].Value
)
70 xCont
.removeByIndex(0)
71 self
.assertTrue(not(xCont
.hasElements()) and len(xCont
) == 0, "Could not remove PropertyValue")
72 uno
.invoke(xCont
, "insertByIndex", (0, prop1
))
73 uno
.invoke(xCont
, "insertByIndex", (1, prop2
))
74 self
.assertTrue(xCont
.hasElements() and len(xCont
) == 2, "Did not insert PropertyValue")
76 uno
.invoke(xCont
, "insertByIndex", (1, prop2
))
77 uno
.invoke(xCont
, "insertByIndex", (1, prop3
))
79 self
.assertEqual(p3
.Name
, ret
[0].Name
)
80 self
.assertEqual(p3
.Value
, ret
[0].Value
)
82 with self
.assertRaises(IndexOutOfBoundsException
):
83 uno
.invoke(xCont
, "insertByIndex", (25, prop2
))
85 with self
.assertRaises(IndexOutOfBoundsException
):
86 xCont
.removeByIndex(25)
88 with self
.assertRaises(IllegalArgumentException
):
89 uno
.invoke(xCont
, "insertByIndex", (3, "Example String"))