Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / sw / qa / python / xcontrolshape.py
blob899c0c20b8632ffc446b4d1eca5550e64f71273c
1 #! /usr/bin/env python
2 # -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*-
4 # This file is part of the LibreOffice project.
6 # This Source Code Form is subject to the terms of the Mozilla Public
7 # License, v. 2.0. If a copy of the MPL was not distributed with this
8 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 import unittest
11 from org.libreoffice.unotest import UnoInProcess
12 from com.sun.star.beans import UnknownPropertyException
15 class TestXControlShape(unittest.TestCase):
17 @classmethod
18 def setUpClass(cls):
19 cls._uno = UnoInProcess()
20 cls._uno.setUp()
22 @classmethod
23 def tearDownClass(cls):
24 if cls._uno:
25 cls._uno.tearDown()
27 def test_getAndSetControlShape(self):
28 xDoc = self.__class__._uno.openDocFromTDOC("xcontrolshape.odt")
29 self.assertIsNotNone(xDoc)
31 xDrawPage = xDoc.getDrawPage()
32 self.assertIsNotNone(xDrawPage)
34 # Date picker has control
35 xShapeDatePicker = xDrawPage[0]
36 self.assertIsNotNone(xShapeDatePicker)
37 self.assertIsNotNone(xShapeDatePicker.getControl())
39 # Combobox also has control
40 xShapeCombo = xDrawPage[1]
41 self.assertIsNotNone(xShapeCombo)
42 self.assertIsNotNone(xShapeCombo.getControl())
44 # Simple draw shape has no ControlShape
45 xShapeSimple = xDrawPage[2]
46 self.assertIsNotNone(xShapeSimple)
47 # Shape has no XControlShape interface and we get AttributeError exception
48 # during getControl() call
49 with self.assertRaises(AttributeError):
50 self.assertIsNone(xShapeSimple.getControl())
52 xOldControlShape = xShapeCombo.getControl()
54 # Combo box was a combo box and had no "Date" attribute"
55 with self.assertRaises(UnknownPropertyException):
56 xShapeCombo.getControl().getPropertyValue("Date")
58 # We are setting new Control Shape
59 xShapeCombo.setControl(xShapeDatePicker.getControl())
61 # And we can get date with some value
62 xDate = xShapeCombo.getControl().getPropertyValue("Date")
63 self.assertIsNotNone(xDate)
64 self.assertTrue(xDate.Day > 0 and xDate.Month > 0 and xDate.Year > 0)
66 # Return back original controlshape
67 xShapeCombo.setControl(xOldControlShape)
68 # ...and ensure that date no longer available
69 with self.assertRaises(UnknownPropertyException):
70 xShapeCombo.getControl().getPropertyValue("Date")
72 xDoc.close(True)
75 if __name__ == '__main__':
76 unittest.main()
78 # vim: set shiftwidth=4 softtabstop=4 expandtab: