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/.
11 from org
.libreoffice
.unotest
import UnoInProcess
12 from com
.sun
.star
.beans
import UnknownPropertyException
15 class TestXControlShape(unittest
.TestCase
):
19 cls
._uno
= UnoInProcess()
23 def tearDownClass(cls
):
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")
75 if __name__
== '__main__':
78 # vim: set shiftwidth=4 softtabstop=4 expandtab: