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 .
21 from org
.libreoffice
.unotest
import UnoInProcess
22 from com
.sun
.star
.beans
import PropertyValue
23 from com
.sun
.star
.container
import ElementExistException
24 from com
.sun
.star
.lang
import IllegalArgumentException
25 from com
.sun
.star
.container
import NoSuchElementException
28 class CheckNamedPropertyValues(unittest
.TestCase
):
32 cls
._uno
= UnoInProcess()
34 cls
.xContext
= cls
._uno
.getContext()
37 def tearDownClass(cls
):
40 def test_checkNamedPropertyValues(self
):
42 xServiceManager
= self
.xContext
.ServiceManager
43 xCont
= xServiceManager
.createInstanceWithContext('com.sun.star.document.NamedPropertyValues',
46 p1
= PropertyValue(Name
="Jupp", Value
="GoodGuy")
47 prop1
= uno
.Any("[]com.sun.star.beans.PropertyValue", (p1
,))
49 p2
= PropertyValue(Name
="Horst", Value
="BadGuy")
50 prop2
= uno
.Any("[]com.sun.star.beans.PropertyValue", (p2
,))
52 self
.assertFalse(xCont
.hasElements(), "Initial container is not empty")
54 uno
.invoke(xCont
, "insertByName", ("prop1", prop1
))
56 self
.assertEqual(p1
.Name
, ret
[0].Name
)
57 self
.assertEqual(p1
.Value
, ret
[0].Value
)
59 uno
.invoke(xCont
, "replaceByName", ("prop1", prop2
))
61 self
.assertEqual(p2
.Name
, ret
[0].Name
)
62 self
.assertEqual(p2
.Value
, ret
[0].Value
)
64 xCont
.removeByName("prop1")
65 self
.assertFalse(xCont
.hasElements(), "Could not remove PropertyValue.")
66 uno
.invoke(xCont
, "insertByName", ("prop1", prop1
))
67 uno
.invoke(xCont
, "insertByName", ("prop2", prop2
))
68 self
.assertTrue(xCont
.hasElements(), "Did not insert PropertyValue")
69 names
= xCont
.getElementNames()
70 self
.assertEqual(2, len(names
), "Not all element names were returned")
72 for i
in range(len(names
)):
73 self
.assertIn(names
[i
], ["prop1", "prop2"], "Got a wrong element name")
75 with self
.assertRaises(ElementExistException
):
76 uno
.invoke(xCont
, "insertByName", ("prop2", prop1
))
78 with self
.assertRaises(IllegalArgumentException
):
79 uno
.invoke(xCont
, "insertByName", ("prop3", "Example String"))
81 with self
.assertRaises(NoSuchElementException
):
82 xCont
.removeByName("prop3")