Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / sw / qa / python / check_indexed_property_values.py
blobd6d314adc8943a5f3d112b12342a8dd1bd8b4f24
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 uno
21 from org.libreoffice.unotest import UnoInProcess
22 from com.sun.star.beans import PropertyValue
23 from com.sun.star.lang import IllegalArgumentException
24 from com.sun.star.lang import IndexOutOfBoundsException
27 class CheckIndexedPropertyValues(unittest.TestCase):
29 @classmethod
30 def setUpClass(cls):
31 cls._uno = UnoInProcess()
32 cls._uno.setUp()
33 cls.xContext = cls._uno.getContext()
35 @classmethod
36 def tearDownClass(cls):
37 cls._uno.tearDown()
39 def test_checkIndexedPropertyValues(self):
40 xServiceManager = self.xContext.ServiceManager
41 xCont = xServiceManager.createInstanceWithContext('com.sun.star.document.IndexedPropertyValues',
42 self.xContext)
44 p1 = PropertyValue(Name="Jupp", Value="GoodGuy")
45 prop1 = uno.Any("[]com.sun.star.beans.PropertyValue", (p1,))
47 p2 = PropertyValue(Name="Horst", Value="BadGuy")
48 prop2 = uno.Any("[]com.sun.star.beans.PropertyValue", (p2,))
50 p3 = PropertyValue(Name="Peter", Value="FamilyGuy")
51 prop3 = uno.Any("[]com.sun.star.beans.PropertyValue", (p3,))
53 self.assertEqual(0, len(xCont), "Initial container is not empty")
54 uno.invoke(xCont, "insertByIndex", (0, prop1))
56 ret = xCont[0]
57 self.assertEqual(p1.Name, ret[0].Name)
58 self.assertEqual(p1.Value, ret[0].Value)
60 uno.invoke(xCont, "replaceByIndex", (0, prop2))
61 ret = xCont[0]
62 self.assertEqual(p2.Name, ret[0].Name)
63 self.assertEqual(p2.Value, ret[0].Value)
65 xCont.removeByIndex(0)
66 self.assertTrue(not(xCont.hasElements()) and len(xCont) == 0, "Could not remove PropertyValue")
67 uno.invoke(xCont, "insertByIndex", (0, prop1))
68 uno.invoke(xCont, "insertByIndex", (1, prop2))
69 self.assertTrue(xCont.hasElements() and len(xCont) == 2, "Did not insert PropertyValue")
71 uno.invoke(xCont, "insertByIndex", (1, prop2))
72 uno.invoke(xCont, "insertByIndex", (1, prop3))
73 ret = xCont[1]
74 self.assertEqual(p3.Name, ret[0].Name)
75 self.assertEqual(p3.Value, ret[0].Value)
77 with self.assertRaises(IndexOutOfBoundsException):
78 uno.invoke(xCont, "insertByIndex", (25, prop2))
80 with self.assertRaises(IndexOutOfBoundsException):
81 xCont.removeByIndex(25)
83 with self.assertRaises(IllegalArgumentException):
84 uno.invoke(xCont, "insertByIndex", (3, "Example String"))