bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _toolkit / AccessibleMenuBar.java
blobf894aaf4c1381d86a6810d9f023645818e5d4e36
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.XAccessibleComponent;
23 import com.sun.star.awt.XWindow;
24 import com.sun.star.frame.XModel;
25 import com.sun.star.lang.XMultiServiceFactory;
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.SOfficeFactory;
39 import util.utils;
42 /**
43 * Test for object which is represented accessible component of
44 * menu bar of a document. <p>
46 * Object implements the following interfaces :
47 * <ul>
48 * <li> <code>::com::sun::star::accessibility::XAccessibleExtendedComponent</code></li>
49 * <li> <code>::com::sun::star::accessibility::XAccessibleEventBroadcaster</code></li>
50 * <li> <code>::com::sun::star::accessibility::XAccessibleComponent</code></li>
51 * <li> <code>::com::sun::star::accessibility::XAccessibleSelection</code></li>
52 * <li> <code>::com::sun::star::accessibility::XAccessibleContext</code></li>
53 * </ul> <p>
55 * @see com.sun.star.accessibility.XAccessibleExtendedComponent
56 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
57 * @see com.sun.star.accessibility.XAccessibleComponent
58 * @see com.sun.star.accessibility.XAccessibleSelection
59 * @see com.sun.star.accessibility.XAccessibleContext
60 * @see ifc.accessibility._XAccessibleExtendedComponent
61 * @see ifc.accessibility._XAccessibleEventBroadcaster
62 * @see ifc.accessibility._XAccessibleComponent
63 * @see ifc.accessibility._XAccessibleSelection
64 * @see ifc.accessibility._XAccessibleContext
66 public class AccessibleMenuBar extends TestCase {
67 private static XTextDocument xTextDoc = null;
68 /**
69 * Finds accessible component with role <code>MENUBAR</code>
70 * walking through the accessible component tree of a document.
72 protected TestEnvironment createTestEnvironment(TestParameters Param,
73 PrintWriter log) {
74 shortWait();
76 AccessibilityTools at = new AccessibilityTools();
78 XWindow xWindow = UnoRuntime.queryInterface(XModel.class, xTextDoc).
79 getCurrentController().getFrame().getContainerWindow();
81 XAccessible xRoot = AccessibilityTools.getAccessibleObject(xWindow);
84 AccessibilityTools.printAccessibleTree(log, xRoot, Param.getBool(util.PropertyName.DEBUG_IS_ACTIVE));
85 XInterface oObj = AccessibilityTools.getAccessibleObjectForRole(xRoot, AccessibleRole.MENU_BAR);
87 log.println("ImplementationName " + utils.getImplName(oObj));
89 TestEnvironment tEnv = new TestEnvironment(oObj);
91 final XAccessibleComponent acomp = UnoRuntime.queryInterface(
92 XAccessibleComponent.class,
93 oObj);
95 tEnv.addObjRelation("EventProducer",
96 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() {
97 public void fireEvent() {
98 System.out.println("Grabbing focus ... ");
99 acomp.grabFocus();
103 tEnv.addObjRelation("XAccessibleSelection.OneAlwaysSelected",
104 new Boolean(false));
106 tEnv.addObjRelation("XAccessibleSelection.multiSelection",
107 new Boolean(false));
109 return tEnv;
113 * Creates writer document.
115 protected void initialize(TestParameters Param, PrintWriter log) {
116 try {
117 SOfficeFactory SOF = SOfficeFactory.getFactory(
118 (XMultiServiceFactory) Param.getMSF());
119 xTextDoc = SOF.createTextDoc(null);
120 } catch (com.sun.star.uno.Exception e) {
121 throw new StatusException("Can't create document", e);
126 * Disposes document.
128 protected void cleanup(TestParameters Param, PrintWriter log) {
129 util.DesktopTools.closeDoc(xTextDoc);
133 * Sleeps for 0.5 sec. to allow StarOffice to react on <code>
134 * reset</code> call.
136 private void shortWait() {
137 try {
138 Thread.sleep(500);
139 } catch (InterruptedException e) {
140 log.println("While waiting :" + e);