bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _toolkit / AccessibleToolBox.java
bloba034ab9ee6c8eb296a1668173ee653ecf9ecd839
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.accessibility.XAccessibleAction;
23 import com.sun.star.awt.XWindow;
24 import com.sun.star.frame.XDesktop;
25 import com.sun.star.frame.XModel;
26 import com.sun.star.lang.XMultiServiceFactory;
27 import com.sun.star.text.XTextDocument;
28 import com.sun.star.uno.UnoRuntime;
29 import com.sun.star.uno.XInterface;
31 import java.io.PrintWriter;
33 import lib.StatusException;
34 import lib.TestCase;
35 import lib.TestEnvironment;
36 import lib.TestParameters;
38 import util.AccessibilityTools;
39 import util.DesktopTools;
40 import util.SOfficeFactory;
42 /**
43 * Test for object that implements the following interfaces :
44 * <ul>
45 * <li><code>
46 * ::com::sun::star::accessibility::XAccessibleContext</code></li>
47 * <li><code>
48 * ::com::sun::star::accessibility::XAccessibleEventBroadcaster
49 * </code></li>
50 * <li><code>
51 * ::com::sun::star::accessibility::XAccessibleComponent</code></li>
52 * <li><code>
53 * ::com::sun::star::accessibility::XAccessibleExtendedComponent</code></li>
54 * </ul> <p>
56 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
57 * @see com.sun.star.accessibility.XAccessibleContext
58 * @see com.sun.star.accessibility.XAccessibleComponent
59 * @see com.sun.star.accessibility.XAccessibleExtendedComponent
60 * @see ifc.accessibility._XAccessibleEventBroadcaster
61 * @see ifc.accessibility._XAccessibleContext
62 * @see ifc.accessibility._XAccessibleComponent
63 * @see ifc.accessibility._XAccessibleExtendedComponent
65 public class AccessibleToolBox extends TestCase {
66 private static XTextDocument xTextDoc;
68 /**
69 * Creates the Desktop service (<code>com.sun.star.frame.Desktop</code>).
71 protected void initialize(TestParameters Param, PrintWriter log) {
72 UnoRuntime.queryInterface(XDesktop.class,
73 DesktopTools.createDesktop(
74 (XMultiServiceFactory) Param.getMSF()));
77 /**
78 * Disposes the document, if exists, created in
79 * <code>createTestEnvironment</code> method.
81 protected void cleanup(TestParameters Param, PrintWriter log) {
82 log.println("disposing xTextDoc");
84 if (xTextDoc != null) {
85 util.DesktopTools.closeDoc(xTextDoc);
89 /**
90 * Creates a text document.
91 * Then obtains an accessible object with
92 * the role <code>AccessibleRole.TOOLBAR</code>.
93 * Object relations created :
94 * <ul>
95 * <li> <code>'EventProducer'</code> for
96 * {@link ifc.accessibility._XAccessibleEventBroadcaster}:
97 * grabs focus
98 * </li>
99 * </ul>
101 * @param tParam test parameters
102 * @param log writer to log information while testing
104 * @see com.sun.star.awt.Toolkit
105 * @see com.sun.star.accessibility.AccessibleRole
106 * @see ifc.accessibility._XAccessibleEventBroadcaster
107 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
109 protected TestEnvironment createTestEnvironment(TestParameters tParam,
110 PrintWriter log) {
111 log.println("creating a test environment");
113 if (xTextDoc != null) {
114 util.DesktopTools.closeDoc(xTextDoc);
117 XMultiServiceFactory msf = (XMultiServiceFactory) tParam.getMSF();
119 // get a soffice factory object
120 SOfficeFactory SOF = SOfficeFactory.getFactory(msf);
122 try {
123 log.println("creating a text document");
124 xTextDoc = SOF.createTextDoc(null);
125 } catch (com.sun.star.uno.Exception e) {
126 // Some exception occurs.FAILED
127 e.printStackTrace(log);
128 throw new StatusException("Couldn't create document", e);
131 XInterface oObj = null;
133 XWindow xWindow = UnoRuntime.queryInterface(XModel.class, xTextDoc).
134 getCurrentController().getFrame().getContainerWindow();
136 AccessibilityTools at = new AccessibilityTools();
138 XAccessible xRoot = AccessibilityTools.getAccessibleObject(xWindow);
140 AccessibilityTools.printAccessibleTree(log, xRoot, tParam.getBool(util.PropertyName.DEBUG_IS_ACTIVE));
142 oObj = AccessibilityTools.getAccessibleObjectForRole(xRoot, AccessibleRole.TOOL_BAR);
144 log.println("ImplementationName: " + util.utils.getImplName(oObj));
146 TestEnvironment tEnv = new TestEnvironment(oObj);
148 tEnv.addObjRelation("LimitedBounds", "yes");
150 XAccessible acc = AccessibilityTools.getAccessibleObject(oObj);
151 XAccessible child = null;
153 try {
154 child = acc.getAccessibleContext().getAccessibleChild(0);
155 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
158 util.dbg.printInterfaces(child);
160 final XAccessibleAction action = UnoRuntime.queryInterface(
161 XAccessibleAction.class,
162 child);
164 tEnv.addObjRelation("EventProducer",
165 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() {
166 public void fireEvent() {
167 try {
168 action.doAccessibleAction(0);
169 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
170 System.out.println("Couldn't fire event");
175 return tEnv;