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
.StatusException
;
26 import lib
.TestEnvironment
;
27 import lib
.TestParameters
;
28 import util
.AccessibilityTools
;
29 import util
.SOfficeFactory
;
32 import com
.sun
.star
.accessibility
.AccessibleRole
;
33 import com
.sun
.star
.accessibility
.XAccessible
;
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::XAccessibleValue</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.XAccessibleValue
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 ScAccessiblePreviewCell
extends TestCase
{
78 private XSpreadsheetDocument xSheetDoc
= null;
81 * Creates a spreadsheet document.
84 protected void initialize( TestParameters tParam
, PrintWriter log
) {
85 SOfficeFactory SOF
= SOfficeFactory
.getFactory( tParam
.getMSF() );
87 log
.println( "creating a Spreadsheet document" );
88 xSheetDoc
= SOF
.createCalcDoc(null);
89 } catch ( com
.sun
.star
.uno
.Exception e
) {
90 // Some exception occurs.FAILED
91 e
.printStackTrace( log
);
92 throw new StatusException( "Couldn't create document", e
);
97 * Disposes a spreadsheet document.
100 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
101 log
.println( " disposing xSheetDoc " );
102 XComponent oComp
= UnoRuntime
.queryInterface
103 (XComponent
.class, xSheetDoc
);
104 util
.DesktopTools
.closeDoc(oComp
);
109 * Creating a Testenvironment for the interfaces to be tested.
110 * Obtains the accessible object for a one of cell in preview mode.
113 protected synchronized TestEnvironment
createTestEnvironment(TestParameters Param
, PrintWriter log
) {
117 log
.println("Getting spreadsheet") ;
118 XSpreadsheets oSheets
= xSheetDoc
.getSheets() ;
119 XIndexAccess oIndexSheets
= UnoRuntime
.queryInterface(XIndexAccess
.class, oSheets
);
120 XSpreadsheet oSheet
= (XSpreadsheet
) AnyConverter
.toObject(
121 new Type(XSpreadsheet
.class),oIndexSheets
.getByIndex(0));
123 log
.println("Getting a cell from sheet") ;
124 xCell
= oSheet
.getCellByPosition(0, 0);
125 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
126 e
.printStackTrace(log
);
127 throw new StatusException(
128 "Error getting cell object from spreadsheet document", e
);
129 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
130 e
.printStackTrace(log
);
131 throw new StatusException(
132 "Error getting cell object from spreadsheet document", e
);
133 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
134 e
.printStackTrace(log
);
135 throw new StatusException(
136 "Error getting cell object from spreadsheet document", e
);
139 xCell
.setFormula("Value");
141 XModel xModel
= UnoRuntime
.queryInterface(XModel
.class, xSheetDoc
);
143 XController xController
= xModel
.getCurrentController();
145 //switch to 'Print Preview' mode
147 XDispatchProvider xDispProv
= UnoRuntime
.queryInterface(XDispatchProvider
.class, xController
);
148 XURLTransformer xParser
= UnoRuntime
.queryInterface(XURLTransformer
.class,
149 Param
.getMSF().createInstance("com.sun.star.util.URLTransformer"));
150 URL
[] aParseURL
= new URL
[1];
151 aParseURL
[0] = new URL();
152 aParseURL
[0].Complete
= ".uno:PrintPreview";
153 xParser
.parseStrict(aParseURL
);
154 URL aURL
= aParseURL
[0];
155 XDispatch xDispatcher
= xDispProv
.queryDispatch(aURL
, "", 0);
156 if(xDispatcher
!= null)
157 xDispatcher
.dispatch( aURL
, null );
158 } catch (com
.sun
.star
.uno
.Exception e
) {
159 throw new StatusException(e
, Status
.failed("Couldn't change mode"));
162 XInterface oObj
= null;
163 for (int i
= 0;; ++i
) {
166 } catch (InterruptedException e
) {
167 throw new RuntimeException(e
);
170 XAccessible xRoot
= AccessibilityTools
.getAccessibleObject(
171 AccessibilityTools
.getCurrentWindow(
174 oObj
= AccessibilityTools
.getAccessibleObjectForRole(
175 xRoot
, AccessibleRole
.TABLE_CELL
, true);
180 } catch (DisposedException e
) {
181 log
.println("Ignoring DisposedException");
183 if (i
== 20) { // give up after 10 sec
184 throw new RuntimeException(
185 "Couldn't get AccessibleRole.TABLE_CELL object");
187 log
.println("No TABLE_CELL found yet, retrying");
190 log
.println("ImplementationName " + utils
.getImplName(oObj
));
192 TestEnvironment tEnv
= new TestEnvironment( oObj
);
194 tEnv
.addObjRelation("EventProducer",
195 new ifc
.accessibility
._XAccessibleEventBroadcaster
.EventProducer(){
196 public void fireEvent() {
197 System
.out
.println("Fire Event");