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
.sheet
.XHeaderFooterContent
;
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
.style
.XStyle
;
48 import com
.sun
.star
.style
.XStyleFamiliesSupplier
;
49 import com
.sun
.star
.table
.XCell
;
50 import com
.sun
.star
.text
.XText
;
51 import com
.sun
.star
.uno
.AnyConverter
;
52 import com
.sun
.star
.uno
.Type
;
53 import com
.sun
.star
.uno
.UnoRuntime
;
54 import com
.sun
.star
.uno
.XInterface
;
55 import com
.sun
.star
.util
.URL
;
56 import com
.sun
.star
.util
.XCloseable
;
57 import com
.sun
.star
.util
.XURLTransformer
;
60 * Test for object which is represented by accessible component of
61 * a printed header in 'Page Preview' mode.
63 * Object implements the following interfaces :
65 * <li> <code>::com::sun::star::accessibility::XAccessibleComponent</code></li>
66 * <li> <code>::com::sun::star::accessibility::XAccessibleContext</code></li>
69 * @see com.sun.star.accessibility.XAccessibleComponent
70 * @see com.sun.star.accessibility.XAccessibleContext
71 * @see ifc.accessibility._XAccessibleComponent
72 * @see ifc.accessibility._XAccessibleContext
74 public class ScAccessiblePageHeader
extends TestCase
{
76 private XSpreadsheetDocument xSpreadsheetDoc
= null;
79 * Called to create an instance of <code>TestEnvironment</code>
80 * with an object to test and related objects.
81 * Switches the document to Print Preview mode.
82 * Obtains accessible object for the page view.
84 * @param Param test parameters
85 * @param log writer to log information while testing
87 * @see TestEnvironment
88 * @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 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 throw new StatusException(e
, Status
.failed("Couldn't change mode"));
138 XInterface oObj
= null;
139 for (int i
= 0;; ++i
) {
142 } catch (InterruptedException e
) {
143 throw new RuntimeException(e
);
146 XWindow xWindow
= AccessibilityTools
.getCurrentWindow(aModel
);
147 XAccessible xRoot
= AccessibilityTools
.getAccessibleObject(xWindow
);
149 oObj
= AccessibilityTools
.getAccessibleObjectForRole
150 (xRoot
, AccessibleRole
.HEADER
, "");
152 log
.println("ImplementationName " + utils
.getImplName(oObj
));
153 AccessibilityTools
.printAccessibleTree(log
, xRoot
, Param
.getBool(util
.PropertyName
.DEBUG_IS_ACTIVE
));
157 } catch (DisposedException e
) {
158 log
.println("Ignoring DisposedException");
160 if (i
== 20) { // give up after 10 sec
161 throw new RuntimeException(
162 "Couldn't get AccessibleRoot.HEADER object");
164 log
.println("No HEADER found yet, retrying");
167 TestEnvironment tEnv
= new TestEnvironment(oObj
);
169 XStyleFamiliesSupplier StyleFam
= UnoRuntime
.queryInterface(
170 XStyleFamiliesSupplier
.class,
172 XNameAccess StyleFamNames
= StyleFam
.getStyleFamilies();
173 XStyle StdStyle
= null;
176 XNameAccess PageStyles
= (XNameAccess
) AnyConverter
.toObject(
177 new Type(XNameAccess
.class),
178 StyleFamNames
.getByName("PageStyles"));
179 StdStyle
= (XStyle
) AnyConverter
.toObject(
180 new Type(XStyle
.class), PageStyles
.getByName("Default"));
181 } catch(com
.sun
.star
.lang
.WrappedTargetException e
){
182 e
.printStackTrace(log
);
183 throw new StatusException("Couldn't get by name", e
);
184 } catch(com
.sun
.star
.container
.NoSuchElementException e
){
185 e
.printStackTrace(log
);
186 throw new StatusException("Couldn't get by name", e
);
187 } catch (com
.sun
.star
.lang
.IllegalArgumentException iae
) {
188 throw new StatusException("Couldn't convert any", iae
);
191 //get the property-set
192 final XPropertySet PropSet
= UnoRuntime
.queryInterface(XPropertySet
.class, StdStyle
);
194 XHeaderFooterContent RPHC
= null;
195 // creation of testobject here
196 // first we write what we are intend to do to log file
197 log
.println( "creating a test environment" );
199 RPHC
= (XHeaderFooterContent
) AnyConverter
.toObject(
200 new Type(XHeaderFooterContent
.class),
201 PropSet
.getPropertyValue("RightPageHeaderContent"));
202 } catch(com
.sun
.star
.lang
.WrappedTargetException e
){
203 e
.printStackTrace(log
);
204 throw new StatusException("Couldn't get HeaderContent", e
);
205 } catch(com
.sun
.star
.beans
.UnknownPropertyException e
){
206 e
.printStackTrace(log
);
207 throw new StatusException("Couldn't get HeaderContent", e
);
208 } catch(com
.sun
.star
.lang
.IllegalArgumentException e
){
209 e
.printStackTrace(log
);
210 throw new StatusException("Couldn't get HeaderContent", e
);
213 final XHeaderFooterContent RPHC2
= RPHC
;
215 final XText center
= RPHC2
.getCenterText();
216 final XText left
= RPHC2
.getLeftText();
217 final XText right
= RPHC2
.getRightText();
219 tEnv
.addObjRelation("EventProducer",
220 new ifc
.accessibility
._XAccessibleEventBroadcaster
.EventProducer(){
221 public void fireEvent() {
222 center
.setString("CENTER");
223 left
.setString("LEFT");
224 right
.setString("RIGHT");
226 PropSet
.setPropertyValue("RightPageHeaderContent",RPHC2
);
227 } catch (com
.sun
.star
.beans
.UnknownPropertyException e
) {
228 } catch (com
.sun
.star
.beans
.PropertyVetoException e
) {
229 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
230 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {}
240 * Called while disposing a <code>TestEnvironment</code>.
241 * Disposes calc document.
242 * @param Param test parameters
243 * @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
267 protected void initialize(TestParameters Param
, PrintWriter log
) {
268 // get a soffice factory object
269 SOfficeFactory SOF
= SOfficeFactory
.getFactory( Param
.getMSF());
272 log
.println("creating a spreadsheetdocument");
273 xSpreadsheetDoc
= SOF
.createCalcDoc(null);
274 } catch (com
.sun
.star
.uno
.Exception e
) {
275 e
.printStackTrace( log
);
276 throw new StatusException( "Couldn't create document ", e
);