1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ScAccessiblePreviewTable.java,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
33 import java
.io
.PrintWriter
;
36 import lib
.StatusException
;
38 import lib
.TestEnvironment
;
39 import lib
.TestParameters
;
40 import util
.AccessibilityTools
;
41 import util
.SOfficeFactory
;
44 import com
.sun
.star
.accessibility
.AccessibleRole
;
45 import com
.sun
.star
.accessibility
.XAccessible
;
46 import com
.sun
.star
.accessibility
.XAccessibleAction
;
47 import com
.sun
.star
.accessibility
.XAccessibleContext
;
48 import com
.sun
.star
.awt
.XWindow
;
49 import com
.sun
.star
.container
.XIndexAccess
;
50 import com
.sun
.star
.frame
.XController
;
51 import com
.sun
.star
.frame
.XDispatch
;
52 import com
.sun
.star
.frame
.XDispatchProvider
;
53 import com
.sun
.star
.frame
.XModel
;
54 import com
.sun
.star
.lang
.XComponent
;
55 import com
.sun
.star
.lang
.XMultiServiceFactory
;
56 import com
.sun
.star
.sheet
.XSpreadsheet
;
57 import com
.sun
.star
.sheet
.XSpreadsheetDocument
;
58 import com
.sun
.star
.sheet
.XSpreadsheets
;
59 import com
.sun
.star
.table
.XCell
;
60 import com
.sun
.star
.uno
.AnyConverter
;
61 import com
.sun
.star
.uno
.Type
;
62 import com
.sun
.star
.uno
.UnoRuntime
;
63 import com
.sun
.star
.uno
.XInterface
;
64 import com
.sun
.star
.util
.URL
;
65 import com
.sun
.star
.util
.XURLTransformer
;
66 import util
.PropertyName
;
69 * Object implements the following interfaces:
71 * <li> <code>::com::sun::star::accessibility::XAccessibleComponent</code>
73 * <li> <code>::com::sun::star::accessibility::XAccessibleContext</code>
75 * <li> <code>::com::sun::star::accessibility::XAccessibleSelection
77 * <li><code>::com::sun::star::accessibility::XAccessibleTable</code>
79 * <li><code>::com::sun::star::accessibility::XAccessibleEventBroadcaster
82 * @see com.sun.star.accessibility.XAccessibleComponent
83 * @see com.sun.star.accessibility.XAccessibleContext
84 * @see com.sun.star.accessibility.XAccessibleSelection
85 * @see com.sun.star.accessibility.XAccessibleTable
86 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
87 * @see ifc.accessibility._XAccessibleEventBroadcaster
88 * @see ifc.accessibility._XAccessibleComponent
89 * @see ifc.accessibility._XAccessibleContext
90 * @see ifc.accessibility._XAccessibleSelection
91 * @see ifc.accessibility._XAccessibleTable
93 public class ScAccessiblePreviewTable
extends TestCase
{
94 static XSpreadsheetDocument xSheetDoc
= null;
97 * Creates a spreadsheet document.
99 protected void initialize( TestParameters tParam
, PrintWriter log
) {
100 SOfficeFactory SOF
= SOfficeFactory
.getFactory( (XMultiServiceFactory
)tParam
.getMSF() );
102 log
.println( "creating a Spreadsheet document" );
103 xSheetDoc
= SOF
.createCalcDoc(null);
104 } catch ( com
.sun
.star
.uno
.Exception e
) {
105 // Some exception occures.FAILED
106 e
.printStackTrace( log
);
107 throw new StatusException( "Couldn't create document", e
);
112 * Disposes a spreadsheet document.
114 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
115 log
.println( " disposing xSheetDoc " );
116 XComponent oComp
= (XComponent
)UnoRuntime
.queryInterface
117 (XComponent
.class, xSheetDoc
);
118 util
.DesktopTools
.closeDoc(oComp
);
123 * Creating a Testenvironment for the interfaces to be tested.
124 * Obtains the accessible object for a table in preview mode.
126 protected synchronized TestEnvironment
createTestEnvironment(TestParameters Param
, PrintWriter log
) {
128 XInterface oObj
= null;
132 log
.println("Getting spreadsheet") ;
133 XSpreadsheets oSheets
= xSheetDoc
.getSheets() ;
134 XIndexAccess oIndexSheets
= (XIndexAccess
)
135 UnoRuntime
.queryInterface(XIndexAccess
.class, oSheets
);
136 XSpreadsheet oSheet
= (XSpreadsheet
) AnyConverter
.toObject(
137 new Type(XSpreadsheet
.class),oIndexSheets
.getByIndex(0));
139 log
.println("Getting a cell from sheet") ;
140 xCell
= oSheet
.getCellByPosition(0, 0);
141 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
142 e
.printStackTrace(log
);
143 throw new StatusException(
144 "Error getting cell object from spreadsheet document", e
);
145 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
146 e
.printStackTrace(log
);
147 throw new StatusException(
148 "Error getting cell object from spreadsheet document", e
);
149 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
150 e
.printStackTrace(log
);
151 throw new StatusException(
152 "Error getting cell object from spreadsheet document", e
);
155 xCell
.setFormula("Value");
157 XModel xModel
= (XModel
)
158 UnoRuntime
.queryInterface(XModel
.class, xSheetDoc
);
160 XController xController
= xModel
.getCurrentController();
162 //switch to 'Print Preview' mode
164 XDispatchProvider xDispProv
= (XDispatchProvider
)
165 UnoRuntime
.queryInterface(XDispatchProvider
.class, xController
);
166 XURLTransformer xParser
= (com
.sun
.star
.util
.XURLTransformer
)
167 UnoRuntime
.queryInterface(XURLTransformer
.class,
168 ((XMultiServiceFactory
)Param
.getMSF()).createInstance("com.sun.star.util.URLTransformer"));
169 URL
[] aParseURL
= new URL
[1];
170 aParseURL
[0] = new URL();
171 aParseURL
[0].Complete
= ".uno:PrintPreview";
172 xParser
.parseStrict(aParseURL
);
173 URL aURL
= aParseURL
[0];
174 XDispatch xDispatcher
= xDispProv
.queryDispatch(aURL
, "", 0);
175 if(xDispatcher
!= null)
176 xDispatcher
.dispatch( aURL
, null );
177 } catch (com
.sun
.star
.uno
.Exception e
) {
178 log
.println("Couldn't change mode");
179 throw new StatusException(Status
.failed("Couldn't change mode"));
184 AccessibilityTools at
= new AccessibilityTools();
186 XWindow xWindow
= at
.getCurrentContainerWindow((XMultiServiceFactory
)Param
.getMSF(), xModel
);
187 XAccessible xRoot
= at
.getAccessibleObject(xWindow
);
189 at
.printAccessibleTree(log
,xRoot
, Param
.getBool(PropertyName
.DEBUG_IS_ACTIVE
));
191 at
.getAccessibleObjectForRole(xRoot
, AccessibleRole
.TABLE
);
193 oObj
= AccessibilityTools
.SearchedContext
;
195 log
.println("ImplementationName " + utils
.getImplName(oObj
));
197 TestEnvironment tEnv
= new TestEnvironment( oObj
);
199 XAccessibleContext zoomIn
=
200 at
.getAccessibleObjectForRole(xRoot
,AccessibleRole
.PUSH_BUTTON
, "Zoom In");
202 log
.println("Getting "+ zoomIn
.getAccessibleName());
204 final XAccessibleAction pressZoom
= (XAccessibleAction
)
205 UnoRuntime
.queryInterface(XAccessibleAction
.class, zoomIn
);
206 tEnv
.addObjRelation("EventProducer",
207 new ifc
.accessibility
._XAccessibleEventBroadcaster
.EventProducer() {
208 public void fireEvent() {
210 pressZoom
.doAccessibleAction(0);
211 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException ibe
) {}
218 protected void shortWait() {
221 } catch (InterruptedException e
) {
222 System
.out
.println("While waiting :" + e
);