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
.accessibility
.XAccessibleAction
;
35 import com
.sun
.star
.accessibility
.XAccessibleContext
;
36 import com
.sun
.star
.accessibility
.XAccessibleStateSet
;
37 import com
.sun
.star
.awt
.XWindow
;
38 import com
.sun
.star
.container
.XIndexAccess
;
39 import com
.sun
.star
.frame
.XController
;
40 import com
.sun
.star
.frame
.XDispatch
;
41 import com
.sun
.star
.frame
.XDispatchProvider
;
42 import com
.sun
.star
.frame
.XModel
;
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
.XCloseable
;
53 import com
.sun
.star
.util
.XURLTransformer
;
56 * Test for object which is represented by accessible component of
57 * a printed header in 'Page Preview' mode.
59 * Object implements the following interfaces :
61 * <li> <code>::com::sun::star::accessibility::XAccessibleComponent</code></li>
62 * <li> <code>::com::sun::star::accessibility::XAccessibleContext</code></li>
65 * @see com.sun.star.accessibility.XAccessibleComponent
66 * @see com.sun.star.accessibility.XAccessibleContext
67 * @see ifc.accessibility._XAccessibleComponent
68 * @see ifc.accessibility._XAccessibleContext
70 public class ScAccessiblePageHeaderArea
extends TestCase
{
72 private XSpreadsheetDocument xSpreadsheetDoc
= null;
75 * Called to create an instance of <code>TestEnvironment</code>
76 * with an object to test and related objects.
77 * Switches the document to Print Preview mode.
78 * Obtains accessible object for the page view.
80 * @param Param test parameters
81 * @param log writer to log information while testing
83 * @see TestEnvironment
84 * @see #getTestEnvironment
87 protected TestEnvironment
createTestEnvironment(
88 TestParameters Param
, PrintWriter log
) {
90 XInterface oObj
= null;
92 // inserting some content to have non-empty page preview
95 XSpreadsheets oSheets
= xSpreadsheetDoc
.getSheets() ;
96 XIndexAccess oIndexSheets
= UnoRuntime
.queryInterface(XIndexAccess
.class, oSheets
);
97 XSpreadsheet oSheet
= (XSpreadsheet
) AnyConverter
.toObject(
98 new Type(XSpreadsheet
.class),oIndexSheets
.getByIndex(0));
99 xCell
= oSheet
.getCellByPosition(0, 0) ;
100 xCell
.setFormula("ScAccessiblePageHeaderArea");
101 } catch(com
.sun
.star
.lang
.WrappedTargetException e
) {
102 log
.println("Exception creating page header area :");
103 e
.printStackTrace(log
);
104 } catch(com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
105 log
.println("Exception creating page header area :");
106 e
.printStackTrace(log
);
107 } catch(com
.sun
.star
.lang
.IllegalArgumentException e
) {
108 log
.println("Exception creating page header area :");
109 e
.printStackTrace(log
);
112 XModel aModel
= UnoRuntime
.queryInterface(XModel
.class, xSpreadsheetDoc
);
114 XController xController
= aModel
.getCurrentController();
116 // switching to 'Page Preview' mode
118 XDispatchProvider xDispProv
= UnoRuntime
.queryInterface(XDispatchProvider
.class, xController
);
119 XURLTransformer xParser
= UnoRuntime
.queryInterface(XURLTransformer
.class,
120 Param
.getMSF().createInstance("com.sun.star.util.URLTransformer"));
121 // Because it's an in/out parameter we must use an array of URL objects.
122 URL
[] aParseURL
= new URL
[1];
123 aParseURL
[0] = new URL();
124 aParseURL
[0].Complete
= ".uno:PrintPreview";
125 xParser
.parseStrict(aParseURL
);
126 URL aURL
= aParseURL
[0];
127 XDispatch xDispatcher
= xDispProv
.queryDispatch(aURL
, "", 0);
128 if(xDispatcher
!= null)
129 xDispatcher
.dispatch( aURL
, null );
130 } catch (com
.sun
.star
.uno
.Exception e
) {
131 throw new StatusException(e
, Status
.failed("Couldn't change mode"));
134 util
.utils
.pause(500);
136 XWindow xWindow
= AccessibilityTools
.getCurrentContainerWindow(aModel
);
137 XAccessible xRoot
= AccessibilityTools
.getAccessibleObject(xWindow
);
140 oObj
= AccessibilityTools
.getAccessibleObjectForRole
141 (xRoot
, AccessibleRole
.HEADER
, "").getAccessibleChild(0);
142 XAccessibleContext cont
= UnoRuntime
.queryInterface(XAccessibleContext
.class, oObj
);
143 XAccessibleStateSet StateSet
= cont
.getAccessibleStateSet();
144 if (StateSet
.contains((short)27)) {
145 log
.println("Object is transient");
147 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException iabe
) {
148 throw new StatusException("Couldn't find needed Child",iabe
);
151 log
.println("ImplementationName " + utils
.getImplName(oObj
));
152 AccessibilityTools
.printAccessibleTree(log
, xRoot
, Param
.getBool(util
.PropertyName
.DEBUG_IS_ACTIVE
));
154 TestEnvironment tEnv
= new TestEnvironment(oObj
);
156 XAccessibleContext zoomIn
=
157 AccessibilityTools
.getAccessibleObjectForRole(xRoot
,AccessibleRole
.PUSH_BUTTON
, "Zoom In");
159 final XAccessibleAction pressZoom
= UnoRuntime
.queryInterface(XAccessibleAction
.class, zoomIn
);
160 tEnv
.addObjRelation("EventProducer",
161 new ifc
.accessibility
._XAccessibleEventBroadcaster
.EventProducer() {
162 public void fireEvent() {
164 pressZoom
.doAccessibleAction(0);
165 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException ibe
) {}
174 * Called while disposing a <code>TestEnvironment</code>.
175 * Disposes calc document.
176 * @param Param test parameters
177 * @param log writer to log information while testing
180 protected void cleanup( TestParameters Param
, PrintWriter log
) {
181 log
.println( " disposing xSheetDoc " );
183 XCloseable oComp
= UnoRuntime
.queryInterface (XCloseable
.class, xSpreadsheetDoc
) ;
185 }catch(com
.sun
.star
.util
.CloseVetoException e
) {
186 log
.println("Couldn't close document: "+e
.getMessage());
191 * Called while the <code>TestCase</code> initialization. In the
192 * implementation does nothing. Subclasses can override to initialize
193 * objects shared among all <code>TestEnvironment</code>s.
195 * @param Param test parameters
196 * @param log writer to log information while testing
198 * @see #initializeTestCase
201 protected void initialize(TestParameters Param
, PrintWriter log
) {
202 // get a soffice factory object
203 SOfficeFactory SOF
= SOfficeFactory
.getFactory( Param
.getMSF());
206 log
.println("creating a spreadsheetdocument");
207 xSpreadsheetDoc
= SOF
.createCalcDoc(null);
208 } catch (com
.sun
.star
.uno
.Exception e
) {
209 e
.printStackTrace( log
);
210 throw new StatusException( "Couldn't create document ", e
);