bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _sc / ScAccessiblePreviewHeaderCell.java
blobe9fea34ed9a83faccfab748e11a1b2caad17f7a0
1 /*
2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 package mod._sc;
20 import java.io.PrintWriter;
22 import lib.Status;
23 import lib.StatusException;
24 import lib.TestCase;
25 import lib.TestEnvironment;
26 import lib.TestParameters;
27 import util.AccessibilityTools;
28 import util.SOfficeFactory;
29 import util.utils;
31 import com.sun.star.accessibility.AccessibleRole;
32 import com.sun.star.accessibility.XAccessible;
33 import com.sun.star.awt.XWindow;
34 import com.sun.star.beans.XPropertySet;
35 import com.sun.star.container.XIndexAccess;
36 import com.sun.star.container.XNameAccess;
37 import com.sun.star.frame.XController;
38 import com.sun.star.frame.XDispatch;
39 import com.sun.star.frame.XDispatchProvider;
40 import com.sun.star.frame.XModel;
41 import com.sun.star.lang.DisposedException;
42 import com.sun.star.lang.XComponent;
43 import com.sun.star.lang.XMultiServiceFactory;
44 import com.sun.star.sheet.XSpreadsheet;
45 import com.sun.star.sheet.XSpreadsheetDocument;
46 import com.sun.star.sheet.XSpreadsheets;
47 import com.sun.star.style.XStyleFamiliesSupplier;
48 import com.sun.star.table.XCell;
49 import com.sun.star.uno.AnyConverter;
50 import com.sun.star.uno.Type;
51 import com.sun.star.uno.UnoRuntime;
52 import com.sun.star.uno.XInterface;
53 import com.sun.star.util.URL;
54 import com.sun.star.util.XCloseable;
55 import com.sun.star.util.XURLTransformer;
58 /**
59 * Object implements the following interfaces:
60 * <ul>
61 * <li> <code>::com::sun::star::accessibility::XAccessibleComponent</code>
62 * </li>
63 * <li> <code>::com::sun::star::accessibility::XAccessibleContext</code>
64 * </li>
65 * <li> <code>::com::sun::star::accessibility::XAccessibleSelection
66 * </code></li>
67 * <li><code>::com::sun::star::accessibility::XAccessibleValue</code>
68 * </li>
69 * <li><code>::com::sun::star::accessibility::XAccessibleEventBroadcaster
70 * </code></li>
71 * </ul>
72 * @see com.sun.star.accessibility.XAccessibleComponent
73 * @see com.sun.star.accessibility.XAccessibleContext
74 * @see com.sun.star.accessibility.XAccessibleSelection
75 * @see com.sun.star.accessibility.XAccessibleValue
76 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
77 * @see ifc.accessibility._XAccessibleEventBroadcaster
78 * @see ifc.accessibility._XAccessibleComponent
79 * @see ifc.accessibility._XAccessibleContext
80 * @see ifc.accessibility._XAccessibleSelection
81 * @see ifc.accessibility._XAccessibleTable
83 public class ScAccessiblePreviewHeaderCell extends TestCase {
84 private XSpreadsheetDocument xSheetDoc = null;
86 /**
87 * Creates a spreadsheet document.
89 protected void initialize(TestParameters tParam, PrintWriter log) {
92 /**
93 * Disposes a spreadsheet document.
95 protected void cleanup(TestParameters tParam, PrintWriter log) {
96 log.println(" disposing xSheetDoc ");
98 if (xSheetDoc != null) {
99 try {
100 XCloseable oComp = UnoRuntime.queryInterface(
101 XCloseable.class, xSheetDoc);
102 oComp.close(true);
103 xSheetDoc = null;
104 } catch (com.sun.star.util.CloseVetoException e) {
105 e.printStackTrace(log);
106 } catch (com.sun.star.lang.DisposedException e) {
107 log.println("document already disposed");
108 xSheetDoc = null;
114 * Creating a Testenvironment for the interfaces to be tested.
115 * Sets a value of the cell 'A1'. Sets the property 'PrintHeaders'
116 * of the style 'Default' of the family 'PageStyles' to true.
117 * Switchs the document to preview mode and then obtains the
118 * accessible object for the header cell.
120 protected synchronized TestEnvironment createTestEnvironment(TestParameters Param,
121 PrintWriter log) {
122 if (xSheetDoc != null) {
123 XComponent oComp = UnoRuntime.queryInterface(
124 XComponent.class, xSheetDoc);
125 util.DesktopTools.closeDoc(oComp);
128 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory) Param.getMSF());
130 try {
131 log.println("creating a Spreadsheet document");
132 xSheetDoc = SOF.createCalcDoc(null);
133 } catch (com.sun.star.uno.Exception e) {
134 // Some exception occurs.FAILED
135 e.printStackTrace(log);
136 throw new StatusException("Couldn't create document", e);
139 XModel xModel = UnoRuntime.queryInterface(XModel.class,
140 xSheetDoc);
142 XController xController = xModel.getCurrentController();
144 //setting value of cell A1
145 XCell xCell = null;
147 try {
148 log.println("Getting spreadsheet");
150 XSpreadsheets oSheets = xSheetDoc.getSheets();
151 XIndexAccess oIndexSheets = UnoRuntime.queryInterface(
152 XIndexAccess.class, oSheets);
153 XSpreadsheet oSheet = (XSpreadsheet) AnyConverter.toObject(
154 new Type(XSpreadsheet.class),
155 oIndexSheets.getByIndex(0));
157 log.println("Getting a cell from sheet");
158 xCell = oSheet.getCellByPosition(0, 0);
159 } catch (com.sun.star.lang.WrappedTargetException e) {
160 e.printStackTrace(log);
161 throw new StatusException(
162 "Error getting cell object from spreadsheet document", e);
163 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
164 e.printStackTrace(log);
165 throw new StatusException(
166 "Error getting cell object from spreadsheet document", e);
167 } catch (com.sun.star.lang.IllegalArgumentException e) {
168 e.printStackTrace(log);
169 throw new StatusException(
170 "Error getting cell object from spreadsheet document", e);
173 xCell.setFormula("Value");
175 //setting property 'PrintHeaders' of the style 'Default'
176 XStyleFamiliesSupplier xSFS = UnoRuntime.queryInterface(
177 XStyleFamiliesSupplier.class,
178 xSheetDoc);
179 XNameAccess xNA = xSFS.getStyleFamilies();
180 XPropertySet xPropSet = null;
182 try {
183 Object oPageStyles = xNA.getByName("PageStyles");
184 xNA = UnoRuntime.queryInterface(XNameAccess.class,
185 oPageStyles);
187 Object oDefStyle = xNA.getByName("Default");
188 xPropSet = UnoRuntime.queryInterface(
189 XPropertySet.class, oDefStyle);
190 } catch (com.sun.star.lang.WrappedTargetException e) {
191 e.printStackTrace(log);
192 throw new StatusException(Status.failed("Couldn't get element"));
193 } catch (com.sun.star.container.NoSuchElementException e) {
194 e.printStackTrace(log);
195 throw new StatusException(Status.failed("Couldn't get element"));
198 try {
199 xPropSet.setPropertyValue("PrintHeaders", new Boolean(true));
200 } catch (com.sun.star.lang.WrappedTargetException e) {
201 e.printStackTrace(log);
202 throw new StatusException(Status.failed(
203 "Couldn't set property 'PrintHeaders'"));
204 } catch (com.sun.star.lang.IllegalArgumentException e) {
205 e.printStackTrace(log);
206 throw new StatusException(Status.failed(
207 "Couldn't set property 'PrintHeaders'"));
208 } catch (com.sun.star.beans.PropertyVetoException e) {
209 e.printStackTrace(log);
210 throw new StatusException(Status.failed(
211 "Couldn't set property 'PrintHeaders'"));
212 } catch (com.sun.star.beans.UnknownPropertyException e) {
213 e.printStackTrace(log);
214 throw new StatusException(Status.failed(
215 "Couldn't set property 'PrintHeaders'"));
218 //switching to 'Print Preview' mode
219 try {
220 XDispatchProvider xDispProv = UnoRuntime.queryInterface(
221 XDispatchProvider.class,
222 xController);
223 XURLTransformer xParser = UnoRuntime.queryInterface(
224 XURLTransformer.class,
225 ( (XMultiServiceFactory) Param.getMSF())
226 .createInstance("com.sun.star.util.URLTransformer"));
227 URL[] aParseURL = new URL[1];
228 aParseURL[0] = new URL();
229 aParseURL[0].Complete = ".uno:PrintPreview";
230 xParser.parseStrict(aParseURL);
232 URL aURL = aParseURL[0];
233 XDispatch xDispatcher = xDispProv.queryDispatch(aURL, "", 0);
235 if (xDispatcher != null) {
236 xDispatcher.dispatch(aURL, null);
238 } catch (com.sun.star.uno.Exception e) {
239 log.println("Couldn't change mode");
240 throw new StatusException(Status.failed("Couldn't change mode"));
243 XInterface oObj = null;
244 for (int i = 0;; ++i) {
245 try {
246 Thread.sleep(500);
247 } catch (InterruptedException e) {
248 throw new RuntimeException(e);
250 try {
251 XAccessible xRoot = AccessibilityTools.getAccessibleObject(
252 AccessibilityTools.getCurrentWindow(
253 (XMultiServiceFactory) Param.getMSF(), xModel));
254 if (xRoot != null) {
255 oObj = AccessibilityTools.getAccessibleObjectForRole(
256 xRoot, AccessibleRole.TABLE, "A");
257 if (oObj == null) {
258 log.println("Version with a fixed #103863#?");
259 oObj = AccessibilityTools.getAccessibleObjectForRole(
260 xRoot, AccessibleRole.TABLE_CELL, true);
262 if (oObj != null) {
263 break;
266 } catch (DisposedException e) {
267 log.println("Ignoring DisposedException");
269 if (i == 20) { // give up after 10 sec
270 throw new RuntimeException(
271 "Couldn't get AccessibleRolte.TABLE/TABLE_CELL object");
273 log.println("No TABLE/TABLE_CELL found yet, retrying");
276 log.println("ImplementationName " + utils.getImplName(oObj));
278 TestEnvironment tEnv = new TestEnvironment(oObj);
280 tEnv.addObjRelation("EventProducer",
281 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() {
282 public void fireEvent() {
286 return tEnv;