merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / mod / _svtools / AccessibleTabBarPageList.java
blobd3d238dfb740184a0b6ddad58dbce98d6967bee9
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: AccessibleTabBarPageList.java,v $
10 * $Revision: 1.9.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 com.sun.star.drawing.XLayerManager;
33 import com.sun.star.drawing.XLayerSupplier;
34 import java.io.PrintWriter;
36 import lib.StatusException;
37 import lib.TestCase;
38 import lib.TestEnvironment;
39 import lib.TestParameters;
40 import util.AccessibilityTools;
41 import util.SOfficeFactory;
43 import com.sun.star.accessibility.AccessibleRole;
44 import com.sun.star.accessibility.XAccessible;
45 import com.sun.star.awt.XExtendedToolkit;
46 import com.sun.star.awt.XWindow;
47 import com.sun.star.lang.XComponent;
48 import com.sun.star.lang.XMultiServiceFactory;
49 import com.sun.star.uno.UnoRuntime;
50 import com.sun.star.uno.XInterface;
51 import com.sun.star.util.XCloseable;
54 /**
55 * Test for object that implements the following interfaces :
56 * <ul>
57 * <li><code>::com::sun::star::accessibility::XAccessibleComponent
58 * </code></li>
59 * <li><code>::com::sun::star::accessibility::XAccessibleContext
60 * </code></li>
61 * <li><code>::com::sun::star::accessibility::XAccessibleEventBroadcaster
62 * </code></li>
63 * <li>
64 * <code>::com::sun::star::accessibility::XAccessibleExtendedComponent
65 * </code></li>
66 * <li><code>::com::sun::star::accessibility::XAccessibleSelection
67 * </code></li>
68 * </ul> <p>
70 * @see com.sun.star.accessibility.XAccessibleSelection
71 * @see com.sun.star.accessibility.XAccessibleExtendedComponent
72 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
73 * @see com.sun.star.accessibility.XAccessibleContext
74 * @see com.sun.star.accessibility.XAccessibleComponent
75 * @see ifc.accessibility._XAccessibleSelection
76 * @see ifc.accessibility._XAccessibleComponent
77 * @see ifc.accessibility._XAccessibleExtendedComponent
78 * @see ifc.accessibility._XAccessibleEventBroadcaster
79 * @see ifc.accessibility._XAccessibleContext
81 public class AccessibleTabBarPageList extends TestCase {
82 static XComponent xDoc;
84 /**
85 * Disposes the document, if exists, created in
86 * <code>createTestEnvironment</code> method.
88 protected void cleanup(TestParameters Param, PrintWriter log) {
89 log.println("disposing xDoc");
91 if (xDoc != null) {
92 closeDoc();
96 /**
97 * Creates a spreadsheet document. Then obtains an accessible object with
98 * the role <code>AccessibleRole.PAGETABLIST</code>.
99 * Object relations created :
100 * <ul>
101 * <li> <code>'EventProducer'</code> for
102 * {@link ifc.accessibility._XAccessibleEventBroadcaster}:
103 * </li>
104 * </ul>
106 * @param tParam test parameters
107 * @param log writer to log information while testing
109 * @see com.sun.star.awt.Toolkit
110 * @see com.sun.star.accessibility.AccessibleRole
111 * @see ifc.accessibility._XAccessibleEventBroadcaster
112 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
114 protected TestEnvironment createTestEnvironment(TestParameters tParam,
115 PrintWriter log) {
116 log.println("creating a test environment");
118 if (xDoc != null) {
119 closeDoc();
122 // get a soffice factory object
123 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory) tParam.getMSF());
125 try {
126 log.println("creating a draw document");
127 xDoc = SOF.createDrawDoc(null);
128 } catch (com.sun.star.uno.Exception e) {
129 // Some exception occures.FAILED
130 e.printStackTrace(log);
131 throw new StatusException("Couldn't create document", e);
134 shortWait();
136 XInterface oObj = null;
138 try {
139 oObj = (XInterface) ( (XMultiServiceFactory) tParam.getMSF())
140 .createInstance("com.sun.star.awt.Toolkit");
141 } catch (com.sun.star.uno.Exception e) {
142 log.println("Couldn't get toolkit");
143 e.printStackTrace(log);
144 throw new StatusException("Couldn't get toolkit", e);
147 XExtendedToolkit tk = (XExtendedToolkit) UnoRuntime.queryInterface(
148 XExtendedToolkit.class, oObj);
150 AccessibilityTools at = new AccessibilityTools();
152 shortWait();
154 XWindow xWindow = (XWindow) UnoRuntime.queryInterface(XWindow.class,
155 tk.getActiveTopWindow());
157 XAccessible xRoot = at.getAccessibleObject(xWindow);
159 oObj = at.getAccessibleObjectForRole(xRoot,
160 AccessibleRole.PAGE_TAB_LIST);
162 log.println("ImplementationName: " + util.utils.getImplName(oObj));
164 TestEnvironment tEnv = new TestEnvironment(oObj);
166 tEnv.addObjRelation("XAccessibleSelection.multiSelection",
167 new Boolean(false));
169 tEnv.addObjRelation("XAccessibleSelection.OneAlwaysSelected",
170 new Boolean(true));
172 XLayerSupplier oLS = (XLayerSupplier)
173 UnoRuntime.queryInterface(XLayerSupplier.class, xDoc);
174 XInterface oLM = oLS.getLayerManager();
175 final XLayerManager xLM = (XLayerManager) UnoRuntime.queryInterface(XLayerManager.class, oLM);
178 tEnv.addObjRelation("EventProducer",
179 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() {
180 public void fireEvent() {
181 xLM.insertNewByIndex(0);
185 return tEnv;
189 * Sleeps for 0.5 sec. to allow StarOffice to react on <code>
190 * reset</code> call.
192 private void shortWait() {
193 try {
194 Thread.sleep(5000);
195 } catch (InterruptedException e) {
196 System.out.println("While waiting :" + e);
200 protected void closeDoc() {
201 XCloseable closer = (XCloseable) UnoRuntime.queryInterface(
202 XCloseable.class, xDoc);
204 try {
205 closer.close(true);
206 } catch (com.sun.star.util.CloseVetoException e) {
207 log.println("Couldn't close document " + e.getMessage());
208 } catch (com.sun.star.lang.DisposedException e) {
209 log.println("Couldn't close document " + e.getMessage());