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 .
21 import java
.io
.PrintWriter
;
24 import lib
.TestEnvironment
;
25 import lib
.TestParameters
;
26 import util
.AccessibilityTools
;
27 import util
.SOfficeFactory
;
30 import com
.sun
.star
.accessibility
.AccessibleRole
;
31 import com
.sun
.star
.accessibility
.XAccessible
;
32 import com
.sun
.star
.accessibility
.XAccessibleAction
;
33 import com
.sun
.star
.accessibility
.XAccessibleContext
;
34 import com
.sun
.star
.container
.XIndexAccess
;
35 import com
.sun
.star
.frame
.XController
;
36 import com
.sun
.star
.frame
.XDispatch
;
37 import com
.sun
.star
.frame
.XDispatchProvider
;
38 import com
.sun
.star
.frame
.XModel
;
39 import com
.sun
.star
.lang
.DisposedException
;
40 import com
.sun
.star
.lang
.XComponent
;
41 import com
.sun
.star
.sheet
.XSpreadsheet
;
42 import com
.sun
.star
.sheet
.XSpreadsheetDocument
;
43 import com
.sun
.star
.sheet
.XSpreadsheets
;
44 import com
.sun
.star
.table
.XCell
;
45 import com
.sun
.star
.uno
.AnyConverter
;
46 import com
.sun
.star
.uno
.Type
;
47 import com
.sun
.star
.uno
.UnoRuntime
;
48 import com
.sun
.star
.uno
.XInterface
;
49 import com
.sun
.star
.util
.URL
;
50 import com
.sun
.star
.util
.XURLTransformer
;
53 * Object implements the following interfaces:
55 * <li> <code>::com::sun::star::accessibility::XAccessibleComponent</code>
57 * <li> <code>::com::sun::star::accessibility::XAccessibleContext</code>
59 * <li> <code>::com::sun::star::accessibility::XAccessibleSelection
61 * <li><code>::com::sun::star::accessibility::XAccessibleTable</code>
63 * <li><code>::com::sun::star::accessibility::XAccessibleEventBroadcaster
66 * @see com.sun.star.accessibility.XAccessibleComponent
67 * @see com.sun.star.accessibility.XAccessibleContext
68 * @see com.sun.star.accessibility.XAccessibleSelection
69 * @see com.sun.star.accessibility.XAccessibleTable
70 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
71 * @see ifc.accessibility._XAccessibleEventBroadcaster
72 * @see ifc.accessibility._XAccessibleComponent
73 * @see ifc.accessibility._XAccessibleContext
74 * @see ifc.accessibility._XAccessibleSelection
75 * @see ifc.accessibility._XAccessibleTable
77 public class ScAccessiblePreviewTable
extends TestCase
{
78 private XSpreadsheetDocument xSheetDoc
= null;
81 * Creates a spreadsheet document.
84 protected void initialize( TestParameters tParam
, PrintWriter log
) throws Exception
{
85 SOfficeFactory SOF
= SOfficeFactory
.getFactory( tParam
.getMSF() );
86 log
.println( "creating a Spreadsheet document" );
87 xSheetDoc
= SOF
.createCalcDoc(null);
91 * Disposes a spreadsheet document.
94 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
95 log
.println( " disposing xSheetDoc " );
96 XComponent oComp
= UnoRuntime
.queryInterface
97 (XComponent
.class, xSheetDoc
);
98 util
.DesktopTools
.closeDoc(oComp
);
103 * Creating a TestEnvironment for the interfaces to be tested.
104 * Obtains the accessible object for a table in preview mode.
107 protected TestEnvironment
createTestEnvironment(final TestParameters Param
,
108 final PrintWriter log
) throws Exception
{
110 log
.println("Getting spreadsheet") ;
111 XSpreadsheets oSheets
= xSheetDoc
.getSheets() ;
112 XIndexAccess oIndexSheets
= UnoRuntime
.queryInterface(XIndexAccess
.class, oSheets
);
113 XSpreadsheet oSheet
= (XSpreadsheet
) AnyConverter
.toObject(
114 new Type(XSpreadsheet
.class),oIndexSheets
.getByIndex(0));
116 log
.println("Getting a cell from sheet") ;
117 XCell xCell
= oSheet
.getCellByPosition(0, 0);
118 xCell
.setFormula("Value");
120 XModel xModel
= UnoRuntime
.queryInterface(XModel
.class, xSheetDoc
);
122 XController xController
= xModel
.getCurrentController();
124 //switch to 'Print Preview' mode
125 XDispatchProvider xDispProv
= UnoRuntime
.queryInterface(XDispatchProvider
.class, xController
);
126 XURLTransformer xParser
= UnoRuntime
.queryInterface(XURLTransformer
.class,
127 Param
.getMSF().createInstance("com.sun.star.util.URLTransformer"));
128 URL
[] aParseURL
= new URL
[1];
129 aParseURL
[0] = new URL();
130 aParseURL
[0].Complete
= ".uno:PrintPreview";
131 xParser
.parseStrict(aParseURL
);
132 URL aURL
= aParseURL
[0];
133 XDispatch xDispatcher
= xDispProv
.queryDispatch(aURL
, "", 0);
134 if(xDispatcher
!= null)
135 xDispatcher
.dispatch( aURL
, null );
139 for (int i
= 0;; ++i
) {
142 xRoot
= AccessibilityTools
.getAccessibleObject(
143 AccessibilityTools
.getCurrentContainerWindow(
146 oObj
= AccessibilityTools
.getAccessibleObjectForRole(
147 xRoot
, AccessibleRole
.TABLE
);
152 } catch (DisposedException e
) {
153 log
.println("Ignoring DisposedException");
155 if (i
== 20) { // give up after 10 sec
156 throw new RuntimeException(
157 "Couldn't get AccessibleRole.TABLE/PUSH_BUTTON object");
159 log
.println("No TABLE/PUSH_BUTTON found yet, retrying");
162 log
.println("ImplementationName " + utils
.getImplName(oObj
));
164 TestEnvironment tEnv
= new TestEnvironment( oObj
);
166 XAccessibleContext zoomIn
=
167 AccessibilityTools
.getAccessibleObjectForRole(xRoot
,AccessibleRole
.PUSH_BUTTON
, "Zoom In");
169 log
.println("Getting \"" + zoomIn
.getAccessibleName() + "\" which is a \"" + UnoRuntime
.queryInterface(com
.sun
.star
.lang
.XServiceInfo
.class, zoomIn
).getImplementationName() + "\"");
171 final XAccessibleAction pressZoom
= UnoRuntime
.queryInterface(XAccessibleAction
.class, zoomIn
);
172 tEnv
.addObjRelation("EventProducer",
173 new ifc
.accessibility
._XAccessibleEventBroadcaster
.EventProducer() {
174 public void fireEvent() {
176 pressZoom
.doAccessibleAction(0);
177 // the action is not triggered on the preview table
178 // but some toolbar button - this will indirectly
179 // trigger a table event but only from VCL main loop
180 utils
.waitForEventIdle(Param
.getMSF());
181 // sadly it turns out that idle is not enough...
183 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException ibe
) {
184 log
.println("ScAccessiblePreviewTable: IndexOutOfBoundsException from pressZoom.doAccessibleAction(0)");
185 } catch (InterruptedException ex
) {}