merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / mod / _svtools / AccessibleTabBarPage.java
blob6268e35fb60a8568558c1e385258730ac4755b82
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: AccessibleTabBarPage.java,v $
10 * $Revision: 1.11.8.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 package mod._svtools;
33 import com.sun.star.accessibility.AccessibleRole;
34 import com.sun.star.accessibility.XAccessibleComponent;
35 import com.sun.star.accessibility.XAccessibleContext;
36 import com.sun.star.awt.Point;
37 import java.awt.Robot;
38 import java.awt.event.InputEvent;
39 import java.io.PrintWriter;
41 import lib.StatusException;
42 import lib.TestCase;
43 import lib.TestEnvironment;
44 import lib.TestParameters;
45 import util.AccessibilityTools;
46 import util.SOfficeFactory;
48 import com.sun.star.accessibility.XAccessible;
49 import com.sun.star.awt.XExtendedToolkit;
50 import com.sun.star.awt.XWindow;
51 import com.sun.star.lang.XComponent;
52 import com.sun.star.lang.XMultiServiceFactory;
53 import com.sun.star.uno.UnoRuntime;
54 import com.sun.star.uno.XInterface;
56 /**
57 * Test for object that implements the following interfaces :
58 * <ul>
59 * <li><code>::com::sun::star::accessibility::XAccessibleComponent
60 * </code></li>
61 * <li><code>::com::sun::star::accessibility::XAccessibleContext
62 * </code></li>
63 * <li><code>::com::sun::star::accessibility::XAccessibleEventBroadcaster
64 * </code></li>
65 * <li>
66 * <code>::com::sun::star::accessibility::XAccessibleExtendedComponent
67 * </code></li>
68 * </ul> <p>
70 * @see com.sun.star.accessibility.XAccessibleExtendedComponent
71 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
72 * @see com.sun.star.accessibility.XAccessibleContext
73 * @see com.sun.star.accessibility.XAccessibleComponent
74 * @see ifc.accessibility._XAccessibleComponent
75 * @see ifc.accessibility._XAccessibleExtendedComponent
76 * @see ifc.accessibility._XAccessibleEventBroadcaster
77 * @see ifc.accessibility._XAccessibleContext
79 public class AccessibleTabBarPage extends TestCase {
81 static XComponent xDoc;
83 /**
84 * Disposes the document, if exists, created in
85 * <code>createTestEnvironment</code> method.
87 protected void cleanup( TestParameters Param, PrintWriter log) {
89 log.println("disposing xCalcDoc");
90 if (xDoc != null) {
91 util.DesktopTools.closeDoc(xDoc);
95 /**
96 * Creates a spreadsheet document. Then obtains an accessible object with
97 * the role <code>AccessibleRole.PAGETAB</code>.
98 * Object relations created :
99 * <ul>
100 * <li> <code>'EventProducer'</code> for
101 * {@link ifc.accessibility._XAccessibleEventBroadcaster}:
102 * </li>
103 * </ul>
105 * @param tParam test parameters
106 * @param log writer to log information while testing
108 * @see com.sun.star.awt.Toolkit
109 * @see com.sun.star.accessibility.AccessibleRole
110 * @see ifc.accessibility._XAccessibleEventBroadcaster
111 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
113 protected TestEnvironment createTestEnvironment(TestParameters tParam,
114 PrintWriter log) {
116 log.println( "creating a test environment" );
118 if (xDoc != null) xDoc.dispose();
120 // get a soffice factory object
121 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF());
123 try {
124 log.println( "creating a calc document" );
125 xDoc = (XComponent) UnoRuntime.queryInterface(XComponent.class, SOF.createCalcDoc(null));// SOF.createDrawDoc(null);
126 } catch ( com.sun.star.uno.Exception e ) {
127 // Some exception occures.FAILED
128 e.printStackTrace( log );
129 throw new StatusException( "Couldn't create document", e );
132 shortWait();
134 XInterface oObj = null;
136 try {
137 oObj = (XInterface) ((XMultiServiceFactory)tParam.getMSF()).createInstance
138 ("com.sun.star.awt.Toolkit") ;
139 } catch (com.sun.star.uno.Exception e) {
140 log.println("Couldn't get toolkit");
141 e.printStackTrace(log);
142 throw new StatusException("Couldn't get toolkit", e );
146 XExtendedToolkit tk = (XExtendedToolkit)
147 UnoRuntime.queryInterface(XExtendedToolkit.class, oObj);
150 AccessibilityTools at = new AccessibilityTools();
152 shortWait();
154 XWindow xWindow = (XWindow)
155 UnoRuntime.queryInterface(XWindow.class,tk.getActiveTopWindow());
157 XAccessible xRoot = at.getAccessibleObject(xWindow);
158 at.printAccessibleTree(log, xRoot, tParam.getBool(util.PropertyName.DEBUG_IS_ACTIVE));
159 oObj = at.getAccessibleObjectForRole(xRoot, AccessibleRole.PAGE_TAB, "Sheet1");
160 XAccessibleContext acc = at.getAccessibleObjectForRole(xRoot, AccessibleRole.PAGE_TAB, "Sheet2");
161 XAccessibleComponent accComp = (XAccessibleComponent) UnoRuntime.queryInterface(
162 XAccessibleComponent.class,
163 acc);
164 final Point point = accComp.getLocationOnScreen();
165 log.println("ImplementationName: " + util.utils.getImplName(oObj));
167 TestEnvironment tEnv = new TestEnvironment( oObj );
168 tEnv.addObjRelation("Destroy","yes");
169 tEnv.addObjRelation("EventProducer",
170 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer(){
171 public void fireEvent() {
172 try {
173 Robot rob = new Robot();
174 rob.mouseMove(point.X + 25, point.Y + 5);
175 rob.mousePress(InputEvent.BUTTON1_MASK);
176 } catch (java.awt.AWTException e) {
177 System.out.println("couldn't fire event");
182 return tEnv;
186 * Sleeps for 0.5 sec. to allow StarOffice to react on <code>
187 * reset</code> call.
189 private void shortWait() {
190 try {
191 Thread.sleep(5000);
192 } catch (InterruptedException e) {
193 System.out.println("While waiting :" + e) ;