bump product version to 5.0.4.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _toolkit / AccessibleMenu.java
blob5c83d76d4f0b324496486b5a516ef6b43a213717
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.accessibility.XAccessibleContext;
24 import com.sun.star.accessibility.XAccessibleText;
25 import com.sun.star.awt.XWindow;
26 import com.sun.star.frame.XModel;
27 import com.sun.star.lang.XMultiServiceFactory;
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;
35 import lib.TestCase;
36 import lib.TestEnvironment;
37 import lib.TestParameters;
39 import util.AccessibilityTools;
40 import util.SOfficeFactory;
41 import util.utils;
44 /**
45 * Test for object which is represented accessible component of
46 * main menu of a document. <p>
48 * Object implements the following interfaces :
49 * <ul>
50 * <li> <code>::com::sun::star::accessibility::XAccessibleEventBroadcaster</code></li>
51 * <li> <code>::com::sun::star::accessibility::XAccessibleAction</code></li>
52 * <li> <code>::com::sun::star::accessibility::XAccessibleSelection</code></li>
53 * <li> <code>::com::sun::star::accessibility::XAccessibleValue</code></li>
54 * <li> <code>::com::sun::star::accessibility::XAccessibleExtendedComponent</code></li>
55 * <li> <code>::com::sun::star::accessibility::XAccessibleComponent</code></li>
56 * <li> <code>::com::sun::star::accessibility::XAccessibleText</code></li>
57 * <li> <code>::com::sun::star::accessibility::XAccessibleContext</code></li>
58 * </ul> <p>
60 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
61 * @see com.sun.star.accessibility.XAccessibleAction
62 * @see com.sun.star.accessibility.XAccessibleSelection
63 * @see com.sun.star.accessibility.XAccessibleValue
64 * @see com.sun.star.accessibility.XAccessibleExtendedComponent
65 * @see com.sun.star.accessibility.XAccessibleComponent
66 * @see com.sun.star.accessibility.XAccessibleText
67 * @see com.sun.star.accessibility.XAccessibleContext
68 * @see ifc.accessibility._XAccessibleEventBroadcaster
69 * @see ifc.accessibility._XAccessibleAction
70 * @see ifc.accessibility._XAccessibleSelection
71 * @see ifc.accessibility._XAccessibleValue
72 * @see ifc.accessibility._XAccessibleExtendedComponent
73 * @see ifc.accessibility._XAccessibleComponent
74 * @see ifc.accessibility._XAccessibleText
75 * @see ifc.accessibility._XAccessibleContext
77 public class AccessibleMenu extends TestCase {
78 private static XTextDocument xTextDoc = null;
79 /**
80 * Finds accessible component with role <code>MENU</code>
81 * walking through the accessible component tree of a document.
83 @Override
84 protected TestEnvironment createTestEnvironment(TestParameters Param,
85 PrintWriter log) {
86 XMultiServiceFactory msf = Param.getMSF();
88 try {
89 SOfficeFactory SOF = SOfficeFactory.getFactory(msf);
90 xTextDoc = SOF.createTextDoc(null);
91 } catch (com.sun.star.uno.Exception e) {
92 throw new StatusException("Can't create document", e);
95 util.utils.pause(500);
97 XWindow xWindow = UnoRuntime.queryInterface(XModel.class, xTextDoc).
98 getCurrentController().getFrame().getContainerWindow();
100 XAccessible xRoot = AccessibilityTools.getAccessibleObject(xWindow);
102 AccessibilityTools.printAccessibleTree(log, xRoot, Param.getBool(util.PropertyName.DEBUG_IS_ACTIVE));
103 XAccessibleContext menubar = AccessibilityTools.getAccessibleObjectForRole(xRoot,
104 AccessibleRole.MENU_BAR);
105 XInterface oObj = null;
106 Object menu2 = null;
108 try {
109 oObj = menubar.getAccessibleChild(2);
110 menu2 = menubar.getAccessibleChild(1);
111 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
114 log.println("ImplementationName " + utils.getImplName(oObj));
116 TestEnvironment tEnv = new TestEnvironment(oObj);
118 final XAccessibleAction act1 = UnoRuntime.queryInterface(
119 XAccessibleAction.class, oObj);
120 final XAccessibleAction act2 = UnoRuntime.queryInterface(
121 XAccessibleAction.class, menu2);
123 tEnv.addObjRelation("EventProducer",
124 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() {
125 public void fireEvent() {
126 try {
127 act2.doAccessibleAction(0);
129 util.utils.pause(500);
131 act1.doAccessibleAction(0);
132 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
137 XAccessibleText text = UnoRuntime.queryInterface(
138 XAccessibleText.class, oObj);
140 tEnv.addObjRelation("XAccessibleText.Text", text.getText());
142 tEnv.addObjRelation("EditOnly", "Can't change or select Text in Menu");
144 tEnv.addObjRelation("LimitedBounds", "yes");
146 tEnv.addObjRelation("XAccessibleSelection.OneAlwaysSelected",
147 Boolean.FALSE);
149 tEnv.addObjRelation("XAccessibleSelection.multiSelection",
150 Boolean.FALSE);
152 return tEnv;
155 @Override
156 protected void cleanup(TestParameters Param, PrintWriter log) {
157 try {
158 util.DesktopTools.closeDoc(xTextDoc);
159 } catch (com.sun.star.lang.DisposedException e) {
160 log.println("Object already disposed");
165 * Creates a new writer document
167 @Override
168 protected void initialize(TestParameters Param, PrintWriter log) {