bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _toolkit / AccessibleWindow.java
blob6f0f887305967ab92216ae308bb48f4c83d677eb
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 .
18 package mod._toolkit;
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.lang.XMultiServiceFactory;
29 import com.sun.star.text.XTextDocument;
30 import com.sun.star.uno.UnoRuntime;
31 import com.sun.star.uno.XInterface;
33 import java.io.PrintWriter;
35 import lib.StatusException;
36 import lib.TestCase;
37 import lib.TestEnvironment;
38 import lib.TestParameters;
40 import util.AccessibilityTools;
41 import util.DesktopTools;
42 import util.SOfficeFactory;
45 /**
46 * Test for object that implements the following interfaces :
47 * <ul>
48 * <li><code>
49 * ::com::sun::star::accessibility::XAccessibleContext</code></li>
50 * <li><code>
51 * ::com::sun::star::accessibility::XAccessibleEventBroadcaster
52 * </code></li>
53 * <li><code>
54 * ::com::sun::star::accessibility::XAccessibleComponent</code></li>
55 * <li><code>
56 * ::com::sun::star::accessibility::XAccessibleExtendedComponent
57 * </code></li>
58 * <li><code>
59 * ::com::sun::star::accessibility::XAccessibleAction</code></li>
60 * <li><code>
61 * ::com::sun::star::accessibility::XAccessibleText</code></li>
62 * <li><code>
63 * ::com::sun::star::accessibility::XAccessibleValue</code></li>
64 * </ul> <p>
66 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
67 * @see com.sun.star.accessibility.XAccessibleContext
68 * @see com.sun.star.accessibility.XAccessibleComponent
69 * @see com.sun.star.accessibility.XAccessibleExtendedComponent
70 * @see com.sun.star.accessibility.XAccessibleAction
71 * @see com.sun.star.accessibility.XAccessibleText
72 * @see com.sun.star.accessibility.XAccessibleValue
73 * @see ifc.accessibility._XAccessibleEventBroadcaster
74 * @see ifc.accessibility._XAccessibleContext
75 * @see ifc.accessibility._XAccessibleComponent
76 * @see ifc.accessibility._XAccessibleExtendedComponent
77 * @see ifc.accessibility._XAccessibleAction
78 * @see ifc.accessibility._XAccessibleText
79 * @see ifc.accessibility._XAccessibleValue
81 public class AccessibleWindow extends TestCase {
82 private static XTextDocument xTextDoc;
84 /**
85 * 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(
90 (XMultiServiceFactory) Param.getMSF()));
93 /**
94 * Disposes the document, if exists, created in
95 * <code>createTestEnvironment</code> method.
97 protected void cleanup(TestParameters Param, PrintWriter log) {
98 log.println("disposing xTextDoc");
100 if (xTextDoc != null) {
101 util.DesktopTools.closeDoc(xTextDoc);
106 * Creates a text document.
107 * Then obtains an accessible object with
108 * the role <code>AccessibleRole.PUSHBUTTON</code> and with the name
109 * <code>"Bold"</code>.
110 * Object relations created :
111 * <ul>
112 * <li> <code>'EventProducer'</code> for
113 * {@link ifc.accessibility._XAccessibleEventBroadcaster}</li>
114 * <li> <code>'XAccessibleText.Text'</code> for
115 * {@link ifc.accessibility._XAccessibleText}: the name of button</li>
116 * </ul>
118 * @param tParam test parameters
119 * @param log writer to log information while testing
121 * @see com.sun.star.awt.Toolkit
122 * @see com.sun.star.accessibility.AccessibleRole
123 * @see ifc.accessibility._XAccessibleEventBroadcaster
124 * @see ifc.accessibility._XAccessibleText
125 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
126 * @see com.sun.star.accessibility.XAccessibleText
128 protected TestEnvironment createTestEnvironment(TestParameters tParam,
129 PrintWriter log) {
130 log.println("creating a test environment");
132 if (xTextDoc != null) {
133 util.DesktopTools.closeDoc(xTextDoc);
136 // get a soffice factory object
137 SOfficeFactory SOF = SOfficeFactory.getFactory(
138 (XMultiServiceFactory) tParam.getMSF());
140 XInterface toolkit = null;
142 try {
143 log.println("creating a text document");
144 xTextDoc = SOF.createTextDoc(null);
145 toolkit = (XInterface) ((XMultiServiceFactory) tParam.getMSF()).createInstance(
146 "com.sun.star.awt.Toolkit");
147 } catch (com.sun.star.uno.Exception e) {
148 // Some exception occurs.FAILED
149 e.printStackTrace(log);
150 throw new StatusException("Couldn't create document", e);
153 XModel aModel = UnoRuntime.queryInterface(XModel.class,
154 xTextDoc);
156 XInterface oObj = null;
158 AccessibilityTools at = new AccessibilityTools();
160 XWindow xWindow = AccessibilityTools.getCurrentWindow(
161 (XMultiServiceFactory) tParam.getMSF(),
162 aModel);
164 XAccessible xRoot = AccessibilityTools.getAccessibleObject(xWindow);
166 AccessibilityTools.printAccessibleTree(log, xRoot, tParam.getBool(util.PropertyName.DEBUG_IS_ACTIVE));
168 oObj = AccessibilityTools.getAccessibleObjectForRole(xRoot, AccessibleRole.PANEL);
170 log.println("ImplementationName: " + util.utils.getImplName(oObj));
172 TestEnvironment tEnv = new TestEnvironment(oObj);
174 final XExtendedToolkit tk = UnoRuntime.queryInterface(
175 XExtendedToolkit.class, toolkit);
177 tEnv.addObjRelation("EventProducer",
178 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() {
179 public void fireEvent() {
180 XWindow xWin = UnoRuntime.queryInterface(
181 XWindow.class, tk.getActiveTopWindow());
182 Rectangle newPosSize = xWin.getPosSize();
183 newPosSize.Width = newPosSize.Width - 20;
184 newPosSize.Height = newPosSize.Height - 20;
185 newPosSize.X = newPosSize.X + 20;
186 newPosSize.Y = newPosSize.Y + 20;
187 xWin.setPosSize(newPosSize.X, newPosSize.Y, newPosSize.Width,
188 newPosSize.Height, PosSize.POSSIZE);
192 return tEnv;