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
.awt
.XWindow
;
35 import com
.sun
.star
.container
.XIndexAccess
;
36 import com
.sun
.star
.frame
.XController
;
37 import com
.sun
.star
.frame
.XDispatch
;
38 import com
.sun
.star
.frame
.XDispatchProvider
;
39 import com
.sun
.star
.frame
.XModel
;
40 import com
.sun
.star
.lang
.DisposedException
;
41 import com
.sun
.star
.lang
.XComponent
;
42 import com
.sun
.star
.lang
.XMultiServiceFactory
;
43 import com
.sun
.star
.sheet
.XSpreadsheet
;
44 import com
.sun
.star
.sheet
.XSpreadsheetDocument
;
45 import com
.sun
.star
.sheet
.XSpreadsheets
;
46 import com
.sun
.star
.table
.XCell
;
47 import com
.sun
.star
.uno
.AnyConverter
;
48 import com
.sun
.star
.uno
.Type
;
49 import com
.sun
.star
.uno
.UnoRuntime
;
50 import com
.sun
.star
.uno
.XInterface
;
51 import com
.sun
.star
.util
.URL
;
52 import com
.sun
.star
.util
.XURLTransformer
;
55 * Object implements the following interfaces:
57 * <li> <code>::com::sun::star::accessibility::XAccessibleComponent</code>
59 * <li> <code>::com::sun::star::accessibility::XAccessibleContext</code>
61 * <li> <code>::com::sun::star::accessibility::XAccessibleSelection
63 * <li><code>::com::sun::star::accessibility::XAccessibleValue</code>
65 * <li><code>::com::sun::star::accessibility::XAccessibleEventBroadcaster
68 * @see com.sun.star.accessibility.XAccessibleComponent
69 * @see com.sun.star.accessibility.XAccessibleContext
70 * @see com.sun.star.accessibility.XAccessibleSelection
71 * @see com.sun.star.accessibility.XAccessibleValue
72 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
73 * @see ifc.accessibility._XAccessibleEventBroadcaster
74 * @see ifc.accessibility._XAccessibleComponent
75 * @see ifc.accessibility._XAccessibleContext
76 * @see ifc.accessibility._XAccessibleSelection
77 * @see ifc.accessibility._XAccessibleTable
79 public class ScAccessiblePreviewCell
extends TestCase
{
80 private XSpreadsheetDocument xSheetDoc
= null;
83 * Creates a spreadsheet document.
85 protected void initialize( TestParameters tParam
, PrintWriter log
) {
86 SOfficeFactory SOF
= SOfficeFactory
.getFactory( (XMultiServiceFactory
)tParam
.getMSF() );
88 log
.println( "creating a Spreadsheet document" );
89 xSheetDoc
= SOF
.createCalcDoc(null);
90 } catch ( com
.sun
.star
.uno
.Exception e
) {
91 // Some exception occurs.FAILED
92 e
.printStackTrace( log
);
93 throw new StatusException( "Couldn't create document", e
);
98 * 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.
112 protected synchronized TestEnvironment
createTestEnvironment(TestParameters Param
, PrintWriter log
) {
116 log
.println("Getting spreadsheet") ;
117 XSpreadsheets oSheets
= xSheetDoc
.getSheets() ;
118 XIndexAccess oIndexSheets
= UnoRuntime
.queryInterface(XIndexAccess
.class, oSheets
);
119 XSpreadsheet oSheet
= (XSpreadsheet
) AnyConverter
.toObject(
120 new Type(XSpreadsheet
.class),oIndexSheets
.getByIndex(0));
122 log
.println("Getting a cell from sheet") ;
123 xCell
= oSheet
.getCellByPosition(0, 0);
124 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
125 e
.printStackTrace(log
);
126 throw new StatusException(
127 "Error getting cell object from spreadsheet document", e
);
128 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
129 e
.printStackTrace(log
);
130 throw new StatusException(
131 "Error getting cell object from spreadsheet document", e
);
132 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
133 e
.printStackTrace(log
);
134 throw new StatusException(
135 "Error getting cell object from spreadsheet document", e
);
138 xCell
.setFormula("Value");
140 XModel xModel
= UnoRuntime
.queryInterface(XModel
.class, xSheetDoc
);
142 XController xController
= xModel
.getCurrentController();
144 //switch to 'Print Preview' mode
146 XDispatchProvider xDispProv
= UnoRuntime
.queryInterface(XDispatchProvider
.class, xController
);
147 XURLTransformer xParser
= UnoRuntime
.queryInterface(XURLTransformer
.class,
148 ((XMultiServiceFactory
)Param
.getMSF()).createInstance("com.sun.star.util.URLTransformer"));
149 URL
[] aParseURL
= new URL
[1];
150 aParseURL
[0] = new URL();
151 aParseURL
[0].Complete
= ".uno:PrintPreview";
152 xParser
.parseStrict(aParseURL
);
153 URL aURL
= aParseURL
[0];
154 XDispatch xDispatcher
= xDispProv
.queryDispatch(aURL
, "", 0);
155 if(xDispatcher
!= null)
156 xDispatcher
.dispatch( aURL
, null );
157 } catch (com
.sun
.star
.uno
.Exception e
) {
158 log
.println("Couldn't change mode");
159 throw new StatusException(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(
172 (XMultiServiceFactory
) Param
.getMSF(), xModel
));
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");