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 .
20 import java
.io
.PrintWriter
;
23 import lib
.StatusException
;
25 import lib
.TestEnvironment
;
26 import lib
.TestParameters
;
27 import util
.AccessibilityTools
;
28 import util
.SOfficeFactory
;
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
;
59 * Object implements the following interfaces:
61 * <li> <code>::com::sun::star::accessibility::XAccessibleComponent</code>
63 * <li> <code>::com::sun::star::accessibility::XAccessibleContext</code>
65 * <li> <code>::com::sun::star::accessibility::XAccessibleSelection
67 * <li><code>::com::sun::star::accessibility::XAccessibleValue</code>
69 * <li><code>::com::sun::star::accessibility::XAccessibleEventBroadcaster
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;
87 * Creates a spreadsheet document.
89 protected void initialize(TestParameters tParam
, PrintWriter log
) {
93 * Disposes a spreadsheet document.
95 protected void cleanup(TestParameters tParam
, PrintWriter log
) {
96 log
.println(" disposing xSheetDoc ");
98 if (xSheetDoc
!= null) {
100 XCloseable oComp
= UnoRuntime
.queryInterface(
101 XCloseable
.class, xSheetDoc
);
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");
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
,
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());
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,
142 XController xController
= xModel
.getCurrentController();
144 //setting value of cell A1
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,
179 XNameAccess xNA
= xSFS
.getStyleFamilies();
180 XPropertySet xPropSet
= null;
183 Object oPageStyles
= xNA
.getByName("PageStyles");
184 xNA
= UnoRuntime
.queryInterface(XNameAccess
.class,
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"));
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
220 XDispatchProvider xDispProv
= UnoRuntime
.queryInterface(
221 XDispatchProvider
.class,
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
) {
247 } catch (InterruptedException e
) {
248 throw new RuntimeException(e
);
251 XAccessible xRoot
= AccessibilityTools
.getAccessibleObject(
252 AccessibilityTools
.getCurrentWindow(
253 (XMultiServiceFactory
) Param
.getMSF(), xModel
));
255 oObj
= AccessibilityTools
.getAccessibleObjectForRole(
256 xRoot
, AccessibleRole
.TABLE
, "A");
258 log
.println("Version with a fixed #103863#?");
259 oObj
= AccessibilityTools
.getAccessibleObjectForRole(
260 xRoot
, AccessibleRole
.TABLE_CELL
, true);
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() {