Version 6.1.0.2, tag libreoffice-6.1.0.2
[LibreOffice.git] / sw / qa / python / check_named_property_values.py
blobdd06adc60313977b70d696486d8ecbd9e08770ee
1 '''
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 .
17 '''
19 import unittest
20 import unohelper
21 import os
22 import uno
23 from org.libreoffice.unotest import UnoInProcess
24 from com.sun.star.beans import PropertyValue
25 from com.sun.star.container import XNameContainer
26 from org.libreoffice.unotest import OfficeConnection
27 from com.sun.star.container import ElementExistException
28 from com.sun.star.lang import IllegalArgumentException
29 from com.sun.star.container import NoSuchElementException
32 class CheckNamedPropertyValues(unittest.TestCase):
34 @classmethod
35 def setUpClass(cls):
36 cls._uno = UnoInProcess()
37 cls._uno.setUp()
38 cls.xContext = cls._uno.getContext()
39 cls.xDoc = cls._uno.openEmptyWriterDoc()
41 @classmethod
42 def tearDownClass(cls):
43 cls._uno.tearDown()
45 def test_checkNamedPropertyValues(self):
47 xServiceManager = self.xContext.ServiceManager
48 xCont = xServiceManager.createInstanceWithContext('com.sun.star.document.NamedPropertyValues',
49 self.xContext)
51 p1 = PropertyValue(Name="Jupp", Value="GoodGuy")
52 prop1 = uno.Any("[]com.sun.star.beans.PropertyValue", (p1,))
54 p2 = PropertyValue(Name="Horst", Value="BadGuy")
55 prop2 = uno.Any("[]com.sun.star.beans.PropertyValue", (p2,))
57 t = xCont.getElementType()
58 self.assertFalse(xCont.hasElements(), "Initial container is not empty")
60 uno.invoke(xCont, "insertByName", ("prop1", prop1))
61 ret = xCont["prop1"]
62 self.assertEqual(p1.Name, ret[0].Name)
63 self.assertEqual(p1.Value, ret[0].Value)
65 uno.invoke(xCont, "replaceByName", ("prop1", prop2))
66 ret = xCont["prop1"]
67 self.assertEqual(p2.Name, ret[0].Name)
68 self.assertEqual(p2.Value, ret[0].Value)
70 xCont.removeByName("prop1")
71 self.assertFalse(xCont.hasElements(), "Could not remove PropertyValue.")
72 uno.invoke(xCont, "insertByName", ("prop1", prop1))
73 uno.invoke(xCont, "insertByName", ("prop2", prop2))
74 self.assertTrue(xCont.hasElements(), "Did not insert PropertyValue")
75 names = xCont.getElementNames()
76 self.assertEqual(2, len(names), "Not all element names were returned")
78 for i in range(len(names)):
79 self.assertIn(names[i], ["prop1", "prop2"], "Got a wrong element name")
81 with self.assertRaises(ElementExistException):
82 uno.invoke(xCont, "insertByName", ("prop2", prop1))
84 with self.assertRaises(IllegalArgumentException):
85 uno.invoke(xCont, "insertByName", ("prop3", "Example String"))
87 with self.assertRaises(NoSuchElementException):
88 xCont.removeByName("prop3")