merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / mod / _svtools / AccessibleTabBar.java
blobe24c36f42a29a43e7464da9e3ace355707827dfb
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: AccessibleTabBar.java,v $
10 * $Revision: 1.8.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 ************************************************************************/
30 package mod._svtools;
32 import java.io.PrintWriter;
34 import lib.StatusException;
35 import lib.TestCase;
36 import lib.TestEnvironment;
37 import lib.TestParameters;
38 import util.AccessibilityTools;
39 import util.SOfficeFactory;
41 import com.sun.star.accessibility.AccessibleRole;
42 import com.sun.star.accessibility.XAccessible;
43 import com.sun.star.awt.PosSize;
44 import com.sun.star.awt.XExtendedToolkit;
45 import com.sun.star.awt.XWindow;
46 import com.sun.star.lang.XComponent;
47 import com.sun.star.lang.XMultiServiceFactory;
48 import com.sun.star.uno.UnoRuntime;
49 import com.sun.star.uno.XInterface;
50 import com.sun.star.util.XCloseable;
53 public class AccessibleTabBar extends TestCase {
54 static XComponent xDoc;
56 /**
57 * Disposes the document, if exists, created in
58 * <code>createTestEnvironment</code> method.
60 protected void cleanup(TestParameters Param, PrintWriter log) {
61 log.println("disposing xCalcDoc");
63 if (xDoc != null) {
64 closeDoc(xDoc);
68 /**
69 * Creates a spreadsheet document. Then obtains an accessible object with
70 * the role <code>AccessibleRole.PAGETAB</code>.
71 * Object relations created :
72 * <ul>
73 * <li> <code>'EventProducer'</code> for
74 * {@link ifc.accessibility._XAccessibleEventBroadcaster}:
75 * </li>
76 * </ul>
78 * @param tParam test parameters
79 * @param log writer to log information while testing
81 * @see com.sun.star.awt.Toolkit
82 * @see com.sun.star.accessibility.AccessibleRole
83 * @see ifc.accessibility._XAccessibleEventBroadcaster
84 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
86 protected TestEnvironment createTestEnvironment(TestParameters tParam,
87 PrintWriter log) {
88 log.println("creating a test environment");
90 if (xDoc != null) {
91 closeDoc(xDoc);
94 XMultiServiceFactory msf = (XMultiServiceFactory) tParam.getMSF();
96 // get a soffice factory object
97 SOfficeFactory SOF = SOfficeFactory.getFactory(msf);
99 try {
100 log.println("creating a calc document");
101 xDoc = (XComponent) UnoRuntime.queryInterface(XComponent.class,
102 SOF.createCalcDoc(
103 null));
104 } catch (com.sun.star.uno.Exception e) {
105 // Some exception occures.FAILED
106 e.printStackTrace(log);
107 throw new StatusException("Couldn't create document", e);
110 shortWait();
112 XInterface oObj = null;
114 try {
115 oObj = (XInterface) msf.createInstance("com.sun.star.awt.Toolkit");
116 } catch (com.sun.star.uno.Exception e) {
117 log.println("Couldn't get toolkit");
118 e.printStackTrace(log);
119 throw new StatusException("Couldn't get toolkit", e);
122 XExtendedToolkit tk = (XExtendedToolkit) UnoRuntime.queryInterface(
123 XExtendedToolkit.class, oObj);
125 AccessibilityTools at = new AccessibilityTools();
127 shortWait();
129 XWindow xWindow = (XWindow) UnoRuntime.queryInterface(XWindow.class,
130 tk.getActiveTopWindow());
132 XAccessible xRoot = at.getAccessibleObject(xWindow);
133 at.printAccessibleTree(log, xRoot, tParam.getBool(util.PropertyName.DEBUG_IS_ACTIVE));
134 oObj = at.getAccessibleObjectForRole(xRoot, AccessibleRole.PANEL);
136 log.println("ImplementationName: " + util.utils.getImplName(oObj));
138 TestEnvironment tEnv = new TestEnvironment(oObj);
140 final XWindow aWin = xWindow;
142 tEnv.addObjRelation("EventProducer",
143 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() {
144 public void fireEvent() {
145 aWin.setPosSize(100,100, 500, 500, PosSize.POSSIZE);
149 return tEnv;
153 * Sleeps for 3 sec. to allow StarOffice to react on <code>
154 * reset</code> call.
156 private void shortWait() {
157 try {
158 Thread.sleep(5000);
159 } catch (InterruptedException e) {
160 System.out.println("While waiting :" + e);
164 protected void closeDoc(XComponent xDoc) {
165 XCloseable closer = (XCloseable) UnoRuntime.queryInterface(
166 XCloseable.class, xDoc);
168 try {
169 closer.close(true);
170 } catch (com.sun.star.util.CloseVetoException e) {
171 log.println("Couldn't close document " + e.getMessage());
172 } catch (java.lang.NullPointerException e) {
173 log.println("Couldn't close document " + e.getMessage());