Avoid potential negative array index access to cached text.
[LibreOffice.git] / qadevOOo / tests / java / mod / _toolkit / AccessibleMenuBar.java
blobd500503940dcbfc0819bc5f26b3ab279f5b9acdb
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.text.XTextDocument;
26 import com.sun.star.uno.UnoRuntime;
27 import com.sun.star.uno.XInterface;
29 import java.io.PrintWriter;
31 import lib.TestCase;
32 import lib.TestEnvironment;
33 import lib.TestParameters;
35 import util.AccessibilityTools;
36 import util.SOfficeFactory;
37 import util.utils;
40 /**
41 * Test for object which is represented accessible component of
42 * menu bar of a document. <p>
44 * Object implements the following interfaces :
45 * <ul>
46 * <li> <code>::com::sun::star::accessibility::XAccessibleExtendedComponent</code></li>
47 * <li> <code>::com::sun::star::accessibility::XAccessibleEventBroadcaster</code></li>
48 * <li> <code>::com::sun::star::accessibility::XAccessibleComponent</code></li>
49 * <li> <code>::com::sun::star::accessibility::XAccessibleSelection</code></li>
50 * <li> <code>::com::sun::star::accessibility::XAccessibleContext</code></li>
51 * </ul> <p>
53 * @see com.sun.star.accessibility.XAccessibleExtendedComponent
54 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
55 * @see com.sun.star.accessibility.XAccessibleComponent
56 * @see com.sun.star.accessibility.XAccessibleSelection
57 * @see com.sun.star.accessibility.XAccessibleContext
58 * @see ifc.accessibility._XAccessibleExtendedComponent
59 * @see ifc.accessibility._XAccessibleEventBroadcaster
60 * @see ifc.accessibility._XAccessibleComponent
61 * @see ifc.accessibility._XAccessibleSelection
62 * @see ifc.accessibility._XAccessibleContext
64 public class AccessibleMenuBar extends TestCase {
65 private static XTextDocument xTextDoc = null;
66 /**
67 * Finds accessible component with role <code>MENUBAR</code>
68 * walking through the accessible component tree of a document.
70 @Override
71 protected TestEnvironment createTestEnvironment(TestParameters Param,
72 PrintWriter log) {
73 util.utils.waitForEventIdle(Param.getMSF());
75 XWindow xWindow = UnoRuntime.queryInterface(XModel.class, xTextDoc).
76 getCurrentController().getFrame().getContainerWindow();
78 XAccessible xRoot = AccessibilityTools.getAccessibleObject(xWindow);
81 AccessibilityTools.printAccessibleTree(log, xRoot, Param.getBool(util.PropertyName.DEBUG_IS_ACTIVE));
82 XInterface oObj = AccessibilityTools.getAccessibleObjectForRole(xRoot, AccessibleRole.MENU_BAR);
84 log.println("ImplementationName " + utils.getImplName(oObj));
86 TestEnvironment tEnv = new TestEnvironment(oObj);
88 final XAccessibleComponent acomp = UnoRuntime.queryInterface(
89 XAccessibleComponent.class,
90 oObj);
92 tEnv.addObjRelation("EventProducer",
93 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() {
94 public void fireEvent() {
95 System.out.println("Grabbing focus ... ");
96 acomp.grabFocus();
98 });
100 tEnv.addObjRelation("XAccessibleSelection.OneAlwaysSelected",
101 Boolean.FALSE);
103 tEnv.addObjRelation("XAccessibleSelection.multiSelection",
104 Boolean.FALSE);
106 return tEnv;
110 * Creates writer document.
112 @Override
113 protected void initialize(TestParameters Param, PrintWriter log) throws Exception {
114 SOfficeFactory SOF = SOfficeFactory.getFactory(
115 Param.getMSF());
116 xTextDoc = SOF.createTextDoc(null);
120 * Disposes document.
122 @Override
123 protected void cleanup(TestParameters Param, PrintWriter log) {
124 util.DesktopTools.closeDoc(xTextDoc);