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
.beans
.XPropertySet
;
36 import com
.sun
.star
.container
.XIndexAccess
;
37 import com
.sun
.star
.container
.XNameAccess
;
38 import com
.sun
.star
.frame
.XController
;
39 import com
.sun
.star
.frame
.XDispatch
;
40 import com
.sun
.star
.frame
.XDispatchProvider
;
41 import com
.sun
.star
.frame
.XModel
;
42 import com
.sun
.star
.lang
.DisposedException
;
43 import com
.sun
.star
.lang
.XMultiServiceFactory
;
44 import com
.sun
.star
.sheet
.XHeaderFooterContent
;
45 import com
.sun
.star
.sheet
.XSpreadsheet
;
46 import com
.sun
.star
.sheet
.XSpreadsheetDocument
;
47 import com
.sun
.star
.sheet
.XSpreadsheets
;
48 import com
.sun
.star
.style
.XStyle
;
49 import com
.sun
.star
.style
.XStyleFamiliesSupplier
;
50 import com
.sun
.star
.table
.XCell
;
51 import com
.sun
.star
.text
.XText
;
52 import com
.sun
.star
.uno
.AnyConverter
;
53 import com
.sun
.star
.uno
.Type
;
54 import com
.sun
.star
.uno
.UnoRuntime
;
55 import com
.sun
.star
.uno
.XInterface
;
56 import com
.sun
.star
.util
.URL
;
57 import com
.sun
.star
.util
.XCloseable
;
58 import com
.sun
.star
.util
.XURLTransformer
;
61 * Test for object which is represented by accessible component of
62 * a printed header in 'Page Preview' mode.
64 * Object implements the following interfaces :
66 * <li> <code>::com::sun::star::accessibility::XAccessibleComponent</code></li>
67 * <li> <code>::com::sun::star::accessibility::XAccessibleContext</code></li>
70 * @see com.sun.star.accessibility.XAccessibleComponent
71 * @see com.sun.star.accessibility.XAccessibleContext
72 * @see ifc.accessibility._XAccessibleComponent
73 * @see ifc.accessibility._XAccessibleContext
75 public class ScAccessiblePageHeader
extends TestCase
{
77 private XSpreadsheetDocument xSpreadsheetDoc
= null;
80 * Called to create an instance of <code>TestEnvironment</code>
81 * with an object to test and related objects.
82 * Switches the document to Print Preview mode.
83 * Obtains accessible object for the page view.
85 * @param Param test parameters
86 * @param log writer to log information while testing
88 * @see TestEnvironment
89 * @see #getTestEnvironment
91 protected TestEnvironment
createTestEnvironment(
92 TestParameters Param
, PrintWriter log
) {
94 // inserting some content to have non-empty page preview
97 XSpreadsheets oSheets
= xSpreadsheetDoc
.getSheets() ;
98 XIndexAccess oIndexSheets
= UnoRuntime
.queryInterface(XIndexAccess
.class, oSheets
);
99 XSpreadsheet oSheet
= null;
101 oSheet
= (XSpreadsheet
) AnyConverter
.toObject(
102 new Type(XSpreadsheet
.class),oIndexSheets
.getByIndex(0));
103 } catch (com
.sun
.star
.lang
.IllegalArgumentException iae
) {
104 throw new StatusException("couldn't get sheet",iae
);
106 xCell
= oSheet
.getCellByPosition(0, 0) ;
107 xCell
.setFormula("ScAccessiblePageHeader");
108 } catch(com
.sun
.star
.lang
.WrappedTargetException e
) {
109 log
.println("Exception creating page header :");
110 e
.printStackTrace(log
);
111 } catch(com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
112 log
.println("Exception creating page header :");
113 e
.printStackTrace(log
);
116 XModel aModel
= UnoRuntime
.queryInterface(XModel
.class, xSpreadsheetDoc
);
118 XController xController
= aModel
.getCurrentController();
120 // switching to 'Page Preview' mode
122 XDispatchProvider xDispProv
= UnoRuntime
.queryInterface(XDispatchProvider
.class, xController
);
123 XURLTransformer xParser
= UnoRuntime
.queryInterface(XURLTransformer
.class,
124 ( (XMultiServiceFactory
) Param
.getMSF()).createInstance("com.sun.star.util.URLTransformer"));
125 // Because it's an in/out parameter we must use an array of URL objects.
126 URL
[] aParseURL
= new URL
[1];
127 aParseURL
[0] = new URL();
128 aParseURL
[0].Complete
= ".uno:PrintPreview";
129 xParser
.parseStrict(aParseURL
);
130 URL aURL
= aParseURL
[0];
131 XDispatch xDispatcher
= xDispProv
.queryDispatch(aURL
, "", 0);
132 if(xDispatcher
!= null)
133 xDispatcher
.dispatch( aURL
, null );
134 } catch (com
.sun
.star
.uno
.Exception e
) {
135 log
.println("Couldn't change mode");
136 throw new StatusException(Status
.failed("Couldn't change mode"));
139 XInterface oObj
= null;
140 for (int i
= 0;; ++i
) {
143 } catch (InterruptedException e
) {
144 throw new RuntimeException(e
);
147 XWindow xWindow
= AccessibilityTools
.getCurrentWindow( (XMultiServiceFactory
) Param
.getMSF(), aModel
);
148 XAccessible xRoot
= AccessibilityTools
.getAccessibleObject(xWindow
);
150 oObj
= AccessibilityTools
.getAccessibleObjectForRole
151 (xRoot
, AccessibleRole
.HEADER
, "");
153 log
.println("ImplementationName " + utils
.getImplName(oObj
));
154 AccessibilityTools
.printAccessibleTree(log
, xRoot
, Param
.getBool(util
.PropertyName
.DEBUG_IS_ACTIVE
));
158 } catch (DisposedException e
) {
159 log
.println("Ignoring DisposedException");
161 if (i
== 20) { // give up after 10 sec
162 throw new RuntimeException(
163 "Couldn't get AccessibleRoot.HEADER object");
165 log
.println("No HEADER found yet, retrying");
168 TestEnvironment tEnv
= new TestEnvironment(oObj
);
170 XStyleFamiliesSupplier StyleFam
= UnoRuntime
.queryInterface(
171 XStyleFamiliesSupplier
.class,
173 XNameAccess StyleFamNames
= StyleFam
.getStyleFamilies();
174 XStyle StdStyle
= null;
177 XNameAccess PageStyles
= (XNameAccess
) AnyConverter
.toObject(
178 new Type(XNameAccess
.class),
179 StyleFamNames
.getByName("PageStyles"));
180 StdStyle
= (XStyle
) AnyConverter
.toObject(
181 new Type(XStyle
.class), PageStyles
.getByName("Default"));
182 } catch(com
.sun
.star
.lang
.WrappedTargetException e
){
183 e
.printStackTrace(log
);
184 throw new StatusException("Couldn't get by name", e
);
185 } catch(com
.sun
.star
.container
.NoSuchElementException e
){
186 e
.printStackTrace(log
);
187 throw new StatusException("Couldn't get by name", e
);
188 } catch (com
.sun
.star
.lang
.IllegalArgumentException iae
) {
189 throw new StatusException("Couldn't convert any", iae
);
192 //get the property-set
193 final XPropertySet PropSet
= UnoRuntime
.queryInterface(XPropertySet
.class, StdStyle
);
195 XHeaderFooterContent RPHC
= null;
196 // creation of testobject here
197 // first we write what we are intend to do to log file
198 log
.println( "creating a test environment" );
200 RPHC
= (XHeaderFooterContent
) AnyConverter
.toObject(
201 new Type(XHeaderFooterContent
.class),
202 PropSet
.getPropertyValue("RightPageHeaderContent"));
203 } catch(com
.sun
.star
.lang
.WrappedTargetException e
){
204 e
.printStackTrace(log
);
205 throw new StatusException("Couldn't get HeaderContent", e
);
206 } catch(com
.sun
.star
.beans
.UnknownPropertyException e
){
207 e
.printStackTrace(log
);
208 throw new StatusException("Couldn't get HeaderContent", e
);
209 } catch(com
.sun
.star
.lang
.IllegalArgumentException e
){
210 e
.printStackTrace(log
);
211 throw new StatusException("Couldn't get HeaderContent", e
);
214 final XHeaderFooterContent RPHC2
= RPHC
;
216 final XText center
= RPHC2
.getCenterText();
217 final XText left
= RPHC2
.getLeftText();
218 final XText right
= RPHC2
.getRightText();
220 tEnv
.addObjRelation("EventProducer",
221 new ifc
.accessibility
._XAccessibleEventBroadcaster
.EventProducer(){
222 public void fireEvent() {
223 center
.setString("CENTER");
224 left
.setString("LEFT");
225 right
.setString("RIGHT");
227 PropSet
.setPropertyValue("RightPageHeaderContent",RPHC2
);
228 } catch (com
.sun
.star
.beans
.UnknownPropertyException e
) {
229 } catch (com
.sun
.star
.beans
.PropertyVetoException e
) {
230 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
231 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {}
241 * Called while disposing a <code>TestEnvironment</code>.
242 * Disposes calc document.
243 * @param Param test parameters
244 * @param log writer to log information while testing
246 protected void cleanup( TestParameters Param
, PrintWriter log
) {
247 log
.println( " disposing xSheetDoc " );
249 XCloseable oComp
= UnoRuntime
.queryInterface (XCloseable
.class, xSpreadsheetDoc
) ;
251 } catch(com
.sun
.star
.util
.CloseVetoException e
) {
252 log
.println("Couldn't close document: "+e
.getMessage());
257 * Called while the <code>TestCase</code> initialization. In the
258 * implementation does nothing. Subclasses can override to initialize
259 * objects shared among all <code>TestEnvironment</code>s.
261 * @param Param test parameters
262 * @param log writer to log information while testing
264 * @see #initializeTestCase
266 protected void initialize(TestParameters Param
, PrintWriter log
) {
267 // get a soffice factory object
268 SOfficeFactory SOF
= SOfficeFactory
.getFactory( (XMultiServiceFactory
) Param
.getMSF());
271 log
.println("creating a spreadsheetdocument");
272 xSpreadsheetDoc
= SOF
.createCalcDoc(null);
273 } catch (com
.sun
.star
.uno
.Exception e
) {
274 e
.printStackTrace( log
);
275 throw new StatusException( "Couldn't create document ", e
);