bump product version to 5.0.4.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _toolkit / AccessibleToolBoxItem.java
blobcc24b53efd15c6eb7f0788d931b252dca6bb41f4
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.text.XTextDocument;
27 import com.sun.star.uno.UnoRuntime;
28 import com.sun.star.uno.XInterface;
30 import java.io.PrintWriter;
32 import lib.StatusException;
33 import lib.TestCase;
34 import lib.TestEnvironment;
35 import lib.TestParameters;
37 import util.AccessibilityTools;
38 import util.DesktopTools;
39 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
54 * </code></li>
55 * <li><code>
56 * ::com::sun::star::accessibility::XAccessibleAction</code></li>
57 * <li><code>
58 * ::com::sun::star::accessibility::XAccessibleText</code></li>
59 * <li><code>
60 * ::com::sun::star::accessibility::XAccessibleValue</code></li>
61 * </ul> <p>
63 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
64 * @see com.sun.star.accessibility.XAccessibleContext
65 * @see com.sun.star.accessibility.XAccessibleComponent
66 * @see com.sun.star.accessibility.XAccessibleExtendedComponent
67 * @see com.sun.star.accessibility.XAccessibleAction
68 * @see com.sun.star.accessibility.XAccessibleText
69 * @see com.sun.star.accessibility.XAccessibleValue
70 * @see ifc.accessibility._XAccessibleEventBroadcaster
71 * @see ifc.accessibility._XAccessibleContext
72 * @see ifc.accessibility._XAccessibleComponent
73 * @see ifc.accessibility._XAccessibleExtendedComponent
74 * @see ifc.accessibility._XAccessibleAction
75 * @see ifc.accessibility._XAccessibleText
76 * @see ifc.accessibility._XAccessibleValue
78 public class AccessibleToolBoxItem extends TestCase {
79 private static XTextDocument xTextDoc;
81 /**
82 * Creates the Desktop service (<code>com.sun.star.frame.Desktop</code>).
84 @Override
85 protected void initialize(TestParameters Param, PrintWriter log) {
86 UnoRuntime.queryInterface(XDesktop.class,
87 DesktopTools.createDesktop(
88 Param.getMSF()));
91 /**
92 * Disposes the document, if exists, created in
93 * <code>createTestEnvironment</code> method.
95 @Override
96 protected void cleanup(TestParameters Param, PrintWriter log) {
97 log.println("disposing xTextDoc");
99 if (xTextDoc != null) {
100 closeDoc();
105 * Creates a text document.
106 * Then obtains an accessible object with
107 * the role <code>AccessibleRole.PUSHBUTTON</code> and with the name
108 * <code>"Bold"</code>.
109 * Object relations created :
110 * <ul>
111 * <li> <code>'EventProducer'</code> for
112 * {@link ifc.accessibility._XAccessibleEventBroadcaster}</li>
113 * <li> <code>'XAccessibleText.Text'</code> for
114 * {@link ifc.accessibility._XAccessibleText}: the name of button</li>
115 * </ul>
117 * @param tParam test parameters
118 * @param log writer to log information while testing
120 * @see com.sun.star.awt.Toolkit
121 * @see com.sun.star.accessibility.AccessibleRole
122 * @see ifc.accessibility._XAccessibleEventBroadcaster
123 * @see ifc.accessibility._XAccessibleText
124 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
125 * @see com.sun.star.accessibility.XAccessibleText
127 @Override
128 protected TestEnvironment createTestEnvironment(TestParameters tParam,
129 PrintWriter log) {
130 log.println("creating a test environment");
132 if (xTextDoc != null) {
133 closeDoc();
136 // get a soffice factory object
137 SOfficeFactory SOF = SOfficeFactory.getFactory(
138 tParam.getMSF());
140 try {
141 log.println("creating a text document");
142 xTextDoc = SOF.createTextDoc(null);
143 } catch (com.sun.star.uno.Exception e) {
144 // Some exception occurs.FAILED
145 e.printStackTrace(log);
146 throw new StatusException("Couldn't create document", e);
149 XModel aModel = UnoRuntime.queryInterface(XModel.class,
150 xTextDoc);
152 XInterface oObj = null;
154 XWindow xWindow = AccessibilityTools.getCurrentContainerWindow(
155 aModel);
157 XAccessible xRoot = AccessibilityTools.getAccessibleObject(xWindow);
160 AccessibilityTools.printAccessibleTree(log, xRoot, tParam.getBool(util.PropertyName.DEBUG_IS_ACTIVE));
161 oObj = AccessibilityTools.getAccessibleObjectForRole(xRoot,
162 AccessibleRole.TOGGLE_BUTTON,
163 "Bold");
165 log.println("ImplementationName: " + util.utils.getImplName(oObj));
167 TestEnvironment tEnv = new TestEnvironment(oObj);
169 tEnv.addObjRelation("EditOnly",
170 "This method isn't supported in this dialog");
172 tEnv.addObjRelation("LimitedBounds", "yes");
174 final XAccessibleAction oAction = UnoRuntime.queryInterface(
175 XAccessibleAction.class,
176 oObj);
178 tEnv.addObjRelation("EventProducer",
179 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() {
180 public void fireEvent() {
181 try {
182 oAction.doAccessibleAction(0);
183 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
188 tEnv.addObjRelation("XAccessibleText.Text", "Bold");
190 return tEnv;
193 protected void closeDoc() {
194 util.DesktopTools.closeDoc(xTextDoc);