merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / mod / _sc / ScAccessiblePreviewHeaderCell.java
blob6017cb571dc7d5c2730ef14142d5016d9dcf2146
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: ScAccessiblePreviewHeaderCell.java,v $
10 * $Revision: 1.11 $
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._sc;
32 import java.io.PrintWriter;
34 import lib.Status;
35 import lib.StatusException;
36 import lib.TestCase;
37 import lib.TestEnvironment;
38 import lib.TestParameters;
39 import util.AccessibilityTools;
40 import util.SOfficeFactory;
41 import util.utils;
43 import com.sun.star.accessibility.AccessibleRole;
44 import com.sun.star.accessibility.XAccessible;
45 import com.sun.star.awt.XWindow;
46 import com.sun.star.beans.XPropertySet;
47 import com.sun.star.container.XIndexAccess;
48 import com.sun.star.container.XNameAccess;
49 import com.sun.star.frame.XController;
50 import com.sun.star.frame.XDispatch;
51 import com.sun.star.frame.XDispatchProvider;
52 import com.sun.star.frame.XModel;
53 import com.sun.star.lang.XComponent;
54 import com.sun.star.lang.XMultiServiceFactory;
55 import com.sun.star.sheet.XSpreadsheet;
56 import com.sun.star.sheet.XSpreadsheetDocument;
57 import com.sun.star.sheet.XSpreadsheets;
58 import com.sun.star.style.XStyleFamiliesSupplier;
59 import com.sun.star.table.XCell;
60 import com.sun.star.uno.AnyConverter;
61 import com.sun.star.uno.Type;
62 import com.sun.star.uno.UnoRuntime;
63 import com.sun.star.uno.XInterface;
64 import com.sun.star.util.URL;
65 import com.sun.star.util.XCloseable;
66 import com.sun.star.util.XURLTransformer;
69 /**
70 * Object implements the following interfaces:
71 * <ul>
72 * <li> <code>::com::sun::star::accessibility::XAccessibleComponent</code>
73 * </li>
74 * <li> <code>::com::sun::star::accessibility::XAccessibleContext</code>
75 * </li>
76 * <li> <code>::com::sun::star::accessibility::XAccessibleSelection
77 * </code></li>
78 * <li><code>::com::sun::star::accessibility::XAccessibleValue</code>
79 * </li>
80 * <li><code>::com::sun::star::accessibility::XAccessibleEventBroadcaster
81 * </code></li>
82 * </ul>
83 * @see com.sun.star.accessibility.XAccessibleComponent
84 * @see com.sun.star.accessibility.XAccessibleContext
85 * @see com.sun.star.accessibility.XAccessibleSelection
86 * @see com.sun.star.accessibility.XAccessibleValue
87 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
88 * @see ifc.accessibility._XAccessibleEventBroadcaster
89 * @see ifc.accessibility._XAccessibleComponent
90 * @see ifc.accessibility._XAccessibleContext
91 * @see ifc.accessibility._XAccessibleSelection
92 * @see ifc.accessibility._XAccessibleTable
94 public class ScAccessiblePreviewHeaderCell extends TestCase {
95 static XSpreadsheetDocument xSheetDoc = null;
97 /**
98 * Creates a spreadsheet document.
100 protected void initialize(TestParameters tParam, PrintWriter log) {
104 * Disposes a spreadsheet document.
106 protected void cleanup(TestParameters tParam, PrintWriter log) {
107 log.println(" disposing xSheetDoc ");
109 if (xSheetDoc != null) {
110 try {
111 XCloseable oComp = (XCloseable) UnoRuntime.queryInterface(
112 XCloseable.class, xSheetDoc);
113 oComp.close(true);
114 xSheetDoc = null;
115 } catch (com.sun.star.util.CloseVetoException e) {
116 e.printStackTrace(log);
117 } catch (com.sun.star.lang.DisposedException e) {
118 log.println("document already disposed");
119 xSheetDoc = null;
125 * Creating a Testenvironment for the interfaces to be tested.
126 * Sets a value of the cell 'A1'. Sets the property 'PrintHeaders'
127 * of the style 'Default' of the family 'PageStyles' to true.
128 * Switchs the document to preview mode and then obtains the
129 * accessible object for the header cell.
131 protected synchronized TestEnvironment createTestEnvironment(TestParameters Param,
132 PrintWriter log) {
133 XInterface oObj = null;
135 if (xSheetDoc != null) {
136 XComponent oComp = (XComponent) UnoRuntime.queryInterface(
137 XComponent.class, xSheetDoc);
138 util.DesktopTools.closeDoc(oComp);
141 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory) Param.getMSF());
143 try {
144 log.println("creating a Spreadsheet document");
145 xSheetDoc = SOF.createCalcDoc(null);
146 } catch (com.sun.star.uno.Exception e) {
147 // Some exception occures.FAILED
148 e.printStackTrace(log);
149 throw new StatusException("Couldn't create document", e);
152 XModel xModel = (XModel) UnoRuntime.queryInterface(XModel.class,
153 xSheetDoc);
155 XController xController = xModel.getCurrentController();
157 //setting value of cell A1
158 XCell xCell = null;
160 try {
161 log.println("Getting spreadsheet");
163 XSpreadsheets oSheets = xSheetDoc.getSheets();
164 XIndexAccess oIndexSheets = (XIndexAccess) UnoRuntime.queryInterface(
165 XIndexAccess.class, oSheets);
166 XSpreadsheet oSheet = (XSpreadsheet) AnyConverter.toObject(
167 new Type(XSpreadsheet.class),
168 oIndexSheets.getByIndex(0));
170 log.println("Getting a cell from sheet");
171 xCell = oSheet.getCellByPosition(0, 0);
172 } catch (com.sun.star.lang.WrappedTargetException e) {
173 e.printStackTrace(log);
174 throw new StatusException(
175 "Error getting cell object from spreadsheet document", e);
176 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
177 e.printStackTrace(log);
178 throw new StatusException(
179 "Error getting cell object from spreadsheet document", e);
180 } catch (com.sun.star.lang.IllegalArgumentException e) {
181 e.printStackTrace(log);
182 throw new StatusException(
183 "Error getting cell object from spreadsheet document", e);
186 xCell.setFormula("Value");
188 //setting property 'PrintHeaders' of the style 'Default'
189 XStyleFamiliesSupplier xSFS = (XStyleFamiliesSupplier) UnoRuntime.queryInterface(
190 XStyleFamiliesSupplier.class,
191 xSheetDoc);
192 XNameAccess xNA = xSFS.getStyleFamilies();
193 XPropertySet xPropSet = null;
195 try {
196 Object oPageStyles = xNA.getByName("PageStyles");
197 xNA = (XNameAccess) UnoRuntime.queryInterface(XNameAccess.class,
198 oPageStyles);
200 Object oDefStyle = xNA.getByName("Default");
201 xPropSet = (XPropertySet) UnoRuntime.queryInterface(
202 XPropertySet.class, oDefStyle);
203 } catch (com.sun.star.lang.WrappedTargetException e) {
204 e.printStackTrace(log);
205 throw new StatusException(Status.failed("Couldn't get element"));
206 } catch (com.sun.star.container.NoSuchElementException e) {
207 e.printStackTrace(log);
208 throw new StatusException(Status.failed("Couldn't get element"));
211 try {
212 xPropSet.setPropertyValue("PrintHeaders", new Boolean(true));
213 } catch (com.sun.star.lang.WrappedTargetException e) {
214 e.printStackTrace(log);
215 throw new StatusException(Status.failed(
216 "Couldn't set property 'PrintHeaders'"));
217 } catch (com.sun.star.lang.IllegalArgumentException e) {
218 e.printStackTrace(log);
219 throw new StatusException(Status.failed(
220 "Couldn't set property 'PrintHeaders'"));
221 } catch (com.sun.star.beans.PropertyVetoException e) {
222 e.printStackTrace(log);
223 throw new StatusException(Status.failed(
224 "Couldn't set property 'PrintHeaders'"));
225 } catch (com.sun.star.beans.UnknownPropertyException e) {
226 e.printStackTrace(log);
227 throw new StatusException(Status.failed(
228 "Couldn't set property 'PrintHeaders'"));
231 //switching to 'Print Preview' mode
232 try {
233 XDispatchProvider xDispProv = (XDispatchProvider) UnoRuntime.queryInterface(
234 XDispatchProvider.class,
235 xController);
236 XURLTransformer xParser = (com.sun.star.util.XURLTransformer) UnoRuntime.queryInterface(
237 XURLTransformer.class,
238 ( (XMultiServiceFactory) Param.getMSF())
239 .createInstance("com.sun.star.util.URLTransformer"));
240 URL[] aParseURL = new URL[1];
241 aParseURL[0] = new URL();
242 aParseURL[0].Complete = ".uno:PrintPreview";
243 xParser.parseStrict(aParseURL);
245 URL aURL = aParseURL[0];
246 XDispatch xDispatcher = xDispProv.queryDispatch(aURL, "", 0);
248 if (xDispatcher != null) {
249 xDispatcher.dispatch(aURL, null);
251 } catch (com.sun.star.uno.Exception e) {
252 log.println("Couldn't change mode");
253 throw new StatusException(Status.failed("Couldn't change mode"));
256 shortWait();
258 AccessibilityTools at = new AccessibilityTools();
260 XWindow xWindow = at.getCurrentWindow( (XMultiServiceFactory) Param.getMSF(), xModel);
261 XAccessible xRoot = at.getAccessibleObject(xWindow);
263 oObj = at.getAccessibleObjectForRole(xRoot, AccessibleRole.TABLE, "A");
265 if (oObj == null) {
266 log.println("Version with a fixed #103863#");
267 oObj = at.getAccessibleObjectForRole(xRoot,
268 AccessibleRole.TABLE_CELL,
269 true);
272 log.println("ImplementationName " + utils.getImplName(oObj));
274 TestEnvironment tEnv = new TestEnvironment(oObj);
276 tEnv.addObjRelation("EventProducer",
277 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() {
278 public void fireEvent() {
282 return tEnv;
286 * Sleeps for 0.5 sec. to allow StarOffice to react on <code>
287 * reset</code> call.
289 private void shortWait() {
290 try {
291 Thread.currentThread().sleep(500);
292 } catch (InterruptedException e) {
293 System.out.println("While waiting :" + e);