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
.lang
.XMultiServiceFactory
;
44 import com
.sun
.star
.sheet
.XSpreadsheet
;
45 import com
.sun
.star
.sheet
.XSpreadsheetDocument
;
46 import com
.sun
.star
.sheet
.XSpreadsheets
;
47 import com
.sun
.star
.table
.XCell
;
48 import com
.sun
.star
.uno
.AnyConverter
;
49 import com
.sun
.star
.uno
.Type
;
50 import com
.sun
.star
.uno
.UnoRuntime
;
51 import com
.sun
.star
.uno
.XInterface
;
52 import com
.sun
.star
.util
.URL
;
53 import com
.sun
.star
.util
.XCloseable
;
54 import com
.sun
.star
.util
.XURLTransformer
;
57 * Test for object which is represented by accessible component of
58 * a printed header in 'Page Preview' mode.
60 * Object implements the following interfaces :
62 * <li> <code>::com::sun::star::accessibility::XAccessibleComponent</code></li>
63 * <li> <code>::com::sun::star::accessibility::XAccessibleContext</code></li>
66 * @see com.sun.star.accessibility.XAccessibleComponent
67 * @see com.sun.star.accessibility.XAccessibleContext
68 * @see ifc.accessibility._XAccessibleComponent
69 * @see ifc.accessibility._XAccessibleContext
71 public class ScAccessiblePageHeaderArea
extends TestCase
{
73 private XSpreadsheetDocument xSpreadsheetDoc
= null;
76 * Called to create an instance of <code>TestEnvironment</code>
77 * with an object to test and related objects.
78 * Switches the document to Print Preview mode.
79 * Obtains accessible object for the page view.
81 * @param Param test parameters
82 * @param log writer to log information while testing
84 * @see TestEnvironment
85 * @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 ( (XMultiServiceFactory
) 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 log
.println("Couldn't change mode");
132 throw new StatusException(Status
.failed("Couldn't change mode"));
137 } catch (InterruptedException ex
) {}
139 AccessibilityTools at
= new AccessibilityTools();
141 XWindow xWindow
= AccessibilityTools
.getCurrentContainerWindow( (XMultiServiceFactory
) Param
.getMSF(), aModel
);
142 XAccessible xRoot
= AccessibilityTools
.getAccessibleObject(xWindow
);
145 oObj
= AccessibilityTools
.getAccessibleObjectForRole
146 (xRoot
, AccessibleRole
.HEADER
, "").getAccessibleChild(0);
147 XAccessibleContext cont
= UnoRuntime
.queryInterface(XAccessibleContext
.class, oObj
);
148 XAccessibleStateSet StateSet
= cont
.getAccessibleStateSet();
149 if (StateSet
.contains((short)27)) {
150 log
.println("Object is transient");
152 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException iabe
) {
153 throw new StatusException("Couldn't find needed Child",iabe
);
156 log
.println("ImplementationName " + utils
.getImplName(oObj
));
157 AccessibilityTools
.printAccessibleTree(log
, xRoot
, Param
.getBool(util
.PropertyName
.DEBUG_IS_ACTIVE
));
159 TestEnvironment tEnv
= new TestEnvironment(oObj
);
161 XAccessibleContext zoomIn
=
162 AccessibilityTools
.getAccessibleObjectForRole(xRoot
,AccessibleRole
.PUSH_BUTTON
, "Zoom In");
164 final XAccessibleAction pressZoom
= UnoRuntime
.queryInterface(XAccessibleAction
.class, zoomIn
);
165 tEnv
.addObjRelation("EventProducer",
166 new ifc
.accessibility
._XAccessibleEventBroadcaster
.EventProducer() {
167 public void fireEvent() {
169 pressZoom
.doAccessibleAction(0);
170 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException ibe
) {}
179 * Called while disposing a <code>TestEnvironment</code>.
180 * Disposes calc document.
181 * @param Param test parameters
182 * @param log writer to log information while testing
184 protected void cleanup( TestParameters Param
, PrintWriter log
) {
185 log
.println( " disposing xSheetDoc " );
187 XCloseable oComp
= UnoRuntime
.queryInterface (XCloseable
.class, xSpreadsheetDoc
) ;
189 }catch(com
.sun
.star
.util
.CloseVetoException e
) {
190 log
.println("Couldn't close document: "+e
.getMessage());
195 * Called while the <code>TestCase</code> initialization. In the
196 * implementation does nothing. Subclasses can override to initialize
197 * objects shared among all <code>TestEnvironment</code>s.
199 * @param Param test parameters
200 * @param log writer to log information while testing
202 * @see #initializeTestCase
204 protected void initialize(TestParameters Param
, PrintWriter log
) {
205 // get a soffice factory object
206 SOfficeFactory SOF
= SOfficeFactory
.getFactory( (XMultiServiceFactory
) Param
.getMSF());
209 log
.println("creating a spreadsheetdocument");
210 xSpreadsheetDoc
= SOF
.createCalcDoc(null);
211 } catch (com
.sun
.star
.uno
.Exception e
) {
212 e
.printStackTrace( log
);
213 throw new StatusException( "Couldn't create document ", e
);