bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _toolkit / AccessibleToolBoxItem.java
blob3bf80fa2c6698162a27551eec110788b42819357
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;
43 /**
44 * Test for object that implements the following interfaces :
45 * <ul>
46 * <li><code>
47 * ::com::sun::star::accessibility::XAccessibleContext</code></li>
48 * <li><code>
49 * ::com::sun::star::accessibility::XAccessibleEventBroadcaster
50 * </code></li>
51 * <li><code>
52 * ::com::sun::star::accessibility::XAccessibleComponent</code></li>
53 * <li><code>
54 * ::com::sun::star::accessibility::XAccessibleExtendedComponent
55 * </code></li>
56 * <li><code>
57 * ::com::sun::star::accessibility::XAccessibleAction</code></li>
58 * <li><code>
59 * ::com::sun::star::accessibility::XAccessibleText</code></li>
60 * <li><code>
61 * ::com::sun::star::accessibility::XAccessibleValue</code></li>
62 * </ul> <p>
64 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
65 * @see com.sun.star.accessibility.XAccessibleContext
66 * @see com.sun.star.accessibility.XAccessibleComponent
67 * @see com.sun.star.accessibility.XAccessibleExtendedComponent
68 * @see com.sun.star.accessibility.XAccessibleAction
69 * @see com.sun.star.accessibility.XAccessibleText
70 * @see com.sun.star.accessibility.XAccessibleValue
71 * @see ifc.accessibility._XAccessibleEventBroadcaster
72 * @see ifc.accessibility._XAccessibleContext
73 * @see ifc.accessibility._XAccessibleComponent
74 * @see ifc.accessibility._XAccessibleExtendedComponent
75 * @see ifc.accessibility._XAccessibleAction
76 * @see ifc.accessibility._XAccessibleText
77 * @see ifc.accessibility._XAccessibleValue
79 public class AccessibleToolBoxItem extends TestCase {
80 private static XTextDocument xTextDoc;
82 /**
83 * Creates the Desktop service (<code>com.sun.star.frame.Desktop</code>).
85 protected void initialize(TestParameters Param, PrintWriter log) {
86 UnoRuntime.queryInterface(XDesktop.class,
87 DesktopTools.createDesktop(
88 (XMultiServiceFactory) Param.getMSF()));
91 /**
92 * Disposes the document, if exists, created in
93 * <code>createTestEnvironment</code> method.
95 protected void cleanup(TestParameters Param, PrintWriter log) {
96 log.println("disposing xTextDoc");
98 if (xTextDoc != null) {
99 closeDoc();
104 * Creates a text document.
105 * Then obtains an accessible object with
106 * the role <code>AccessibleRole.PUSHBUTTON</code> and with the name
107 * <code>"Bold"</code>.
108 * Object relations created :
109 * <ul>
110 * <li> <code>'EventProducer'</code> for
111 * {@link ifc.accessibility._XAccessibleEventBroadcaster}</li>
112 * <li> <code>'XAccessibleText.Text'</code> for
113 * {@link ifc.accessibility._XAccessibleText}: the name of button</li>
114 * </ul>
116 * @param tParam test parameters
117 * @param log writer to log information while testing
119 * @see com.sun.star.awt.Toolkit
120 * @see com.sun.star.accessibility.AccessibleRole
121 * @see ifc.accessibility._XAccessibleEventBroadcaster
122 * @see ifc.accessibility._XAccessibleText
123 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
124 * @see com.sun.star.accessibility.XAccessibleText
126 protected TestEnvironment createTestEnvironment(TestParameters tParam,
127 PrintWriter log) {
128 log.println("creating a test environment");
130 if (xTextDoc != null) {
131 closeDoc();
134 // get a soffice factory object
135 SOfficeFactory SOF = SOfficeFactory.getFactory(
136 (XMultiServiceFactory) tParam.getMSF());
138 try {
139 log.println("creating a text document");
140 xTextDoc = SOF.createTextDoc(null);
141 } catch (com.sun.star.uno.Exception e) {
142 // Some exception occurs.FAILED
143 e.printStackTrace(log);
144 throw new StatusException("Couldn't create document", e);
147 XModel aModel = UnoRuntime.queryInterface(XModel.class,
148 xTextDoc);
150 XInterface oObj = null;
152 AccessibilityTools at = new AccessibilityTools();
154 XWindow xWindow = AccessibilityTools.getCurrentContainerWindow(
155 (XMultiServiceFactory) tParam.getMSF(),
156 aModel);
158 XAccessible xRoot = AccessibilityTools.getAccessibleObject(xWindow);
161 AccessibilityTools.printAccessibleTree(log, xRoot, tParam.getBool(util.PropertyName.DEBUG_IS_ACTIVE));
162 oObj = AccessibilityTools.getAccessibleObjectForRole(xRoot,
163 AccessibleRole.TOGGLE_BUTTON,
164 "Bold");
166 log.println("ImplementationName: " + util.utils.getImplName(oObj));
168 TestEnvironment tEnv = new TestEnvironment(oObj);
170 tEnv.addObjRelation("EditOnly",
171 "This method isn't supported in this dialog");
173 tEnv.addObjRelation("LimitedBounds", "yes");
175 final XAccessibleAction oAction = UnoRuntime.queryInterface(
176 XAccessibleAction.class,
177 oObj);
179 tEnv.addObjRelation("EventProducer",
180 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() {
181 public void fireEvent() {
182 try {
183 oAction.doAccessibleAction(0);
184 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
189 tEnv.addObjRelation("XAccessibleText.Text", "Bold");
191 return tEnv;
194 protected void closeDoc() {
195 util.DesktopTools.closeDoc(xTextDoc);