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: ScAccessiblePageHeaderArea.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
.accessibility
.XAccessibleStateSet
;
49 import com
.sun
.star
.awt
.XWindow
;
50 import com
.sun
.star
.container
.XIndexAccess
;
51 import com
.sun
.star
.frame
.XController
;
52 import com
.sun
.star
.frame
.XDispatch
;
53 import com
.sun
.star
.frame
.XDispatchProvider
;
54 import com
.sun
.star
.frame
.XModel
;
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
.XCloseable
;
66 import com
.sun
.star
.util
.XURLTransformer
;
69 * Test for object which is represented by accessible component of
70 * a printed header in 'Page Preview' mode.
72 * Object implements the following interfaces :
74 * <li> <code>::com::sun::star::accessibility::XAccessibleComponent</code></li>
75 * <li> <code>::com::sun::star::accessibility::XAccessibleContext</code></li>
78 * @see com.sun.star.accessibility.XAccessibleComponent
79 * @see com.sun.star.accessibility.XAccessibleContext
80 * @see ifc.n.star.accessibility._XAccessibleComponent
81 * @see ifc.n.star.accessibility._XAccessibleContext
83 public class ScAccessiblePageHeaderArea
extends TestCase
{
85 static XSpreadsheetDocument xSpreadsheetDoc
= null;
88 * Called to create an instance of <code>TestEnvironment</code>
89 * with an object to test and related objects.
90 * Switchs the document to Print Preview mode.
91 * Obtains accissible object for the page view.
93 * @param tParam test parameters
94 * @param log writer to log information while testing
96 * @see TestEnvironment
97 * @see #getTestEnvironment()
99 protected TestEnvironment
createTestEnvironment(
100 TestParameters Param
, PrintWriter log
) {
102 XInterface oObj
= null;
104 // inserting some content to have non-empty page preview
107 XSpreadsheets oSheets
= xSpreadsheetDoc
.getSheets() ;
108 XIndexAccess oIndexSheets
= (XIndexAccess
)
109 UnoRuntime
.queryInterface(XIndexAccess
.class, oSheets
);
110 XSpreadsheet oSheet
= (XSpreadsheet
) AnyConverter
.toObject(
111 new Type(XSpreadsheet
.class),oIndexSheets
.getByIndex(0));
112 xCell
= oSheet
.getCellByPosition(0, 0) ;
113 xCell
.setFormula("ScAccessiblePageHeaderArea");
114 } catch(com
.sun
.star
.lang
.WrappedTargetException e
) {
115 log
.println("Exception ceating relation :");
116 e
.printStackTrace(log
);
117 } catch(com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
118 log
.println("Exception ceating relation :");
119 e
.printStackTrace(log
);
120 } catch(com
.sun
.star
.lang
.IllegalArgumentException e
) {
121 log
.println("Exception ceating relation :");
122 e
.printStackTrace(log
);
125 XModel aModel
= (XModel
)
126 UnoRuntime
.queryInterface(XModel
.class, xSpreadsheetDoc
);
128 XController xController
= aModel
.getCurrentController();
130 // switching to 'Page Preview' mode
132 XDispatchProvider xDispProv
= (XDispatchProvider
)
133 UnoRuntime
.queryInterface(XDispatchProvider
.class, xController
);
134 XURLTransformer xParser
= (com
.sun
.star
.util
.XURLTransformer
)
135 UnoRuntime
.queryInterface(XURLTransformer
.class,
136 ( (XMultiServiceFactory
) Param
.getMSF()).createInstance("com.sun.star.util.URLTransformer"));
137 // Because it's an in/out parameter we must use an array of URL objects.
138 URL
[] aParseURL
= new URL
[1];
139 aParseURL
[0] = new URL();
140 aParseURL
[0].Complete
= ".uno:PrintPreview";
141 xParser
.parseStrict(aParseURL
);
142 URL aURL
= aParseURL
[0];
143 XDispatch xDispatcher
= xDispProv
.queryDispatch(aURL
, "", 0);
144 if(xDispatcher
!= null)
145 xDispatcher
.dispatch( aURL
, null );
146 } catch (com
.sun
.star
.uno
.Exception e
) {
147 log
.println("Couldn't change mode");
148 throw new StatusException(Status
.failed("Couldn't change mode"));
153 } catch (InterruptedException ex
) {}
155 AccessibilityTools at
= new AccessibilityTools();
157 XWindow xWindow
= at
.getCurrentContainerWindow( (XMultiServiceFactory
) Param
.getMSF(), aModel
);
158 XAccessible xRoot
= at
.getAccessibleObject(xWindow
);
161 oObj
= at
.getAccessibleObjectForRole
162 (xRoot
, AccessibleRole
.HEADER
, "").getAccessibleChild(0);
163 XAccessibleContext cont
= (XAccessibleContext
)
164 UnoRuntime
.queryInterface(XAccessibleContext
.class, oObj
);
165 XAccessibleStateSet StateSet
= cont
.getAccessibleStateSet();
166 if (StateSet
.contains((short)27)) {
167 log
.println("Object is transient");
169 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException iabe
) {
170 throw new StatusException("Couldn't find needed Child",iabe
);
173 log
.println("ImplementationName " + utils
.getImplName(oObj
));
174 at
.printAccessibleTree(log
, xRoot
, Param
.getBool(util
.PropertyName
.DEBUG_IS_ACTIVE
));
176 TestEnvironment tEnv
= new TestEnvironment(oObj
);
178 XAccessibleContext zoomIn
=
179 at
.getAccessibleObjectForRole(xRoot
,AccessibleRole
.PUSH_BUTTON
, "Zoom In");
181 final XAccessibleAction pressZoom
= (XAccessibleAction
)
182 UnoRuntime
.queryInterface(XAccessibleAction
.class, zoomIn
);
183 tEnv
.addObjRelation("EventProducer",
184 new ifc
.accessibility
._XAccessibleEventBroadcaster
.EventProducer() {
185 public void fireEvent() {
187 pressZoom
.doAccessibleAction(0);
188 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException ibe
) {}
197 * Called while disposing a <code>TestEnvironment</code>.
198 * Disposes calc document.
199 * @param tParam test parameters
200 * @param tEnv the environment to cleanup
201 * @param log writer to log information while testing
203 protected void cleanup( TestParameters Param
, PrintWriter log
) {
204 log
.println( " disposing xSheetDoc " );
206 XCloseable oComp
= (XCloseable
)
207 UnoRuntime
.queryInterface (XCloseable
.class, xSpreadsheetDoc
) ;
209 }catch(com
.sun
.star
.util
.CloseVetoException e
) {
210 log
.println("Couldn't close document: "+e
.getMessage());
215 * Called while the <code>TestCase</code> initialization. In the
216 * implementation does nothing. Subclasses can override to initialize
217 * objects shared among all <code>TestEnvironment</code>s.
219 * @param tParam test parameters
220 * @param log writer to log information while testing
222 * @see #initializeTestCase()
224 protected void initialize(TestParameters Param
, PrintWriter log
) {
225 // get a soffice factory object
226 SOfficeFactory SOF
= SOfficeFactory
.getFactory( (XMultiServiceFactory
) Param
.getMSF());
229 log
.println("creating a spreadsheetdocument");
230 xSpreadsheetDoc
= SOF
.createCalcDoc(null);
231 } catch (com
.sun
.star
.uno
.Exception e
) {
232 e
.printStackTrace( log
);
233 throw new StatusException( "Couldn't create document ", e
);