1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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 ************************************************************************/
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
;
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
;
57 * Test for object that implements the following interfaces :
59 * <li><code>::com::sun::star::accessibility::XAccessibleComponent
61 * <li><code>::com::sun::star::accessibility::XAccessibleContext
63 * <li><code>::com::sun::star::accessibility::XAccessibleEventBroadcaster
66 * <code>::com::sun::star::accessibility::XAccessibleExtendedComponent
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
;
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");
91 util
.DesktopTools
.closeDoc(xDoc
);
96 * Creates a spreadsheet document. Then obtains an accessible object with
97 * the role <code>AccessibleRole.PAGETAB</code>.
98 * Object relations created :
100 * <li> <code>'EventProducer'</code> for
101 * {@link ifc.accessibility._XAccessibleEventBroadcaster}:
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
,
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());
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
);
134 XInterface oObj
= null;
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();
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,
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() {
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");
186 * Sleeps for 0.5 sec. to allow StarOffice to react on <code>
189 private void shortWait() {
192 } catch (InterruptedException e
) {
193 System
.out
.println("While waiting :" + e
) ;