Version 6.1.0.2, tag libreoffice-6.1.0.2
[LibreOffice.git] / sw / qa / python / check_indexed_property_values.py
blob5609aa4225cb0ace48bf749bca4b86d127a7cb33
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 uno
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):
32 @classmethod
33 def setUpClass(cls):
34 cls._uno = UnoInProcess()
35 cls._uno.setUp()
36 cls.xContext = cls._uno.getContext()
37 cls.xDoc = cls._uno.openEmptyWriterDoc()
39 @classmethod
40 def tearDownClass(cls):
41 cls._uno.tearDown()
43 def test_checkIndexedPropertyValues(self):
44 xServiceManager = self.xContext.ServiceManager
45 xCont = xServiceManager.createInstanceWithContext('com.sun.star.document.IndexedPropertyValues',
46 self.xContext)
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))
61 ret = xCont[0]
62 self.assertEqual(p1.Name, ret[0].Name)
63 self.assertEqual(p1.Value, ret[0].Value)
65 uno.invoke(xCont, "replaceByIndex", (0, prop2))
66 ret = xCont[0]
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))
78 ret = xCont[1]
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"))