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 .
20 import com
.sun
.star
.accessibility
.AccessibleRole
;
21 import com
.sun
.star
.accessibility
.XAccessible
;
22 import com
.sun
.star
.awt
.PosSize
;
23 import com
.sun
.star
.awt
.Rectangle
;
24 import com
.sun
.star
.awt
.XExtendedToolkit
;
25 import com
.sun
.star
.awt
.XWindow
;
26 import com
.sun
.star
.frame
.XDesktop
;
27 import com
.sun
.star
.frame
.XModel
;
28 import com
.sun
.star
.text
.XTextDocument
;
29 import com
.sun
.star
.uno
.UnoRuntime
;
30 import com
.sun
.star
.uno
.XInterface
;
32 import java
.io
.PrintWriter
;
34 import lib
.StatusException
;
36 import lib
.TestEnvironment
;
37 import lib
.TestParameters
;
39 import util
.AccessibilityTools
;
40 import util
.DesktopTools
;
41 import util
.SOfficeFactory
;
45 * Test for object that implements the following interfaces :
48 * ::com::sun::star::accessibility::XAccessibleContext</code></li>
50 * ::com::sun::star::accessibility::XAccessibleEventBroadcaster
53 * ::com::sun::star::accessibility::XAccessibleComponent</code></li>
55 * ::com::sun::star::accessibility::XAccessibleExtendedComponent
58 * ::com::sun::star::accessibility::XAccessibleAction</code></li>
60 * ::com::sun::star::accessibility::XAccessibleText</code></li>
62 * ::com::sun::star::accessibility::XAccessibleValue</code></li>
65 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
66 * @see com.sun.star.accessibility.XAccessibleContext
67 * @see com.sun.star.accessibility.XAccessibleComponent
68 * @see com.sun.star.accessibility.XAccessibleExtendedComponent
69 * @see com.sun.star.accessibility.XAccessibleAction
70 * @see com.sun.star.accessibility.XAccessibleText
71 * @see com.sun.star.accessibility.XAccessibleValue
72 * @see ifc.accessibility._XAccessibleEventBroadcaster
73 * @see ifc.accessibility._XAccessibleContext
74 * @see ifc.accessibility._XAccessibleComponent
75 * @see ifc.accessibility._XAccessibleExtendedComponent
76 * @see ifc.accessibility._XAccessibleAction
77 * @see ifc.accessibility._XAccessibleText
78 * @see ifc.accessibility._XAccessibleValue
80 public class AccessibleWindow
extends TestCase
{
81 private static XTextDocument xTextDoc
;
84 * Creates the Desktop service (<code>com.sun.star.frame.Desktop</code>).
87 protected void initialize(TestParameters Param
, PrintWriter log
) {
88 UnoRuntime
.queryInterface(XDesktop
.class,
89 DesktopTools
.createDesktop(
94 * Disposes the document, if exists, created in
95 * <code>createTestEnvironment</code> method.
98 protected void cleanup(TestParameters Param
, PrintWriter log
) {
99 log
.println("disposing xTextDoc");
101 if (xTextDoc
!= null) {
102 util
.DesktopTools
.closeDoc(xTextDoc
);
107 * Creates a text document.
108 * Then obtains an accessible object with
109 * the role <code>AccessibleRole.PUSHBUTTON</code> and with the name
110 * <code>"Bold"</code>.
111 * Object relations created :
113 * <li> <code>'EventProducer'</code> for
114 * {@link ifc.accessibility._XAccessibleEventBroadcaster}</li>
115 * <li> <code>'XAccessibleText.Text'</code> for
116 * {@link ifc.accessibility._XAccessibleText}: the name of button</li>
119 * @param tParam test parameters
120 * @param log writer to log information while testing
122 * @see com.sun.star.awt.Toolkit
123 * @see com.sun.star.accessibility.AccessibleRole
124 * @see ifc.accessibility._XAccessibleEventBroadcaster
125 * @see ifc.accessibility._XAccessibleText
126 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
127 * @see com.sun.star.accessibility.XAccessibleText
130 protected TestEnvironment
createTestEnvironment(TestParameters tParam
,
132 log
.println("creating a test environment");
134 if (xTextDoc
!= null) {
135 util
.DesktopTools
.closeDoc(xTextDoc
);
138 // get a soffice factory object
139 SOfficeFactory SOF
= SOfficeFactory
.getFactory(
142 XInterface toolkit
= null;
145 log
.println("creating a text document");
146 xTextDoc
= SOF
.createTextDoc(null);
147 toolkit
= (XInterface
) tParam
.getMSF().createInstance(
148 "com.sun.star.awt.Toolkit");
149 } catch (com
.sun
.star
.uno
.Exception e
) {
150 // Some exception occurs.FAILED
151 e
.printStackTrace(log
);
152 throw new StatusException("Couldn't create document", e
);
155 XModel aModel
= UnoRuntime
.queryInterface(XModel
.class,
158 XInterface oObj
= null;
160 XWindow xWindow
= AccessibilityTools
.getCurrentWindow(
163 XAccessible xRoot
= AccessibilityTools
.getAccessibleObject(xWindow
);
165 AccessibilityTools
.printAccessibleTree(log
, xRoot
, tParam
.getBool(util
.PropertyName
.DEBUG_IS_ACTIVE
));
167 oObj
= AccessibilityTools
.getAccessibleObjectForRole(xRoot
, AccessibleRole
.PANEL
);
169 log
.println("ImplementationName: " + util
.utils
.getImplName(oObj
));
171 TestEnvironment tEnv
= new TestEnvironment(oObj
);
173 final XExtendedToolkit tk
= UnoRuntime
.queryInterface(
174 XExtendedToolkit
.class, toolkit
);
176 tEnv
.addObjRelation("EventProducer",
177 new ifc
.accessibility
._XAccessibleEventBroadcaster
.EventProducer() {
178 public void fireEvent() {
179 XWindow xWin
= UnoRuntime
.queryInterface(
180 XWindow
.class, tk
.getActiveTopWindow());
181 Rectangle newPosSize
= xWin
.getPosSize();
182 newPosSize
.Width
= newPosSize
.Width
- 20;
183 newPosSize
.Height
= newPosSize
.Height
- 20;
184 newPosSize
.X
= newPosSize
.X
+ 20;
185 newPosSize
.Y
= newPosSize
.Y
+ 20;
186 xWin
.setPosSize(newPosSize
.X
, newPosSize
.Y
, newPosSize
.Width
,
187 newPosSize
.Height
, PosSize
.POSSIZE
);