tdf#130857 qt weld: Introduce QtInstanceScrolledWindow
[LibreOffice.git] / qadevOOo / tests / java / mod / _sc / ScAccessiblePageHeader.java
blob74670742c8ae8625c82bb55a0e3d507bbf5c73fd
1 /*
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 .
19 package mod._sc;
21 import java.io.PrintWriter;
23 import lib.TestCase;
24 import lib.TestEnvironment;
25 import lib.TestParameters;
26 import util.AccessibilityTools;
27 import util.SOfficeFactory;
28 import util.utils;
30 import com.sun.star.accessibility.AccessibleRole;
31 import com.sun.star.accessibility.XAccessible;
32 import com.sun.star.awt.XWindow;
33 import com.sun.star.beans.XPropertySet;
34 import com.sun.star.container.XIndexAccess;
35 import com.sun.star.container.XNameAccess;
36 import com.sun.star.frame.XController;
37 import com.sun.star.frame.XDispatch;
38 import com.sun.star.frame.XDispatchProvider;
39 import com.sun.star.frame.XModel;
40 import com.sun.star.lang.DisposedException;
41 import com.sun.star.sheet.XHeaderFooterContent;
42 import com.sun.star.sheet.XSpreadsheet;
43 import com.sun.star.sheet.XSpreadsheetDocument;
44 import com.sun.star.sheet.XSpreadsheets;
45 import com.sun.star.style.XStyle;
46 import com.sun.star.style.XStyleFamiliesSupplier;
47 import com.sun.star.table.XCell;
48 import com.sun.star.text.XText;
49 import com.sun.star.uno.AnyConverter;
50 import com.sun.star.uno.Type;
51 import com.sun.star.uno.UnoRuntime;
52 import com.sun.star.uno.XInterface;
53 import com.sun.star.util.URL;
54 import com.sun.star.util.XCloseable;
55 import com.sun.star.util.XURLTransformer;
57 /**
58 * Test for object which is represented by accessible component of
59 * a printed header in 'Page Preview' mode.
61 * Object implements the following interfaces :
62 * <ul>
63 * <li> <code>::com::sun::star::accessibility::XAccessibleComponent</code></li>
64 * <li> <code>::com::sun::star::accessibility::XAccessibleContext</code></li>
65 * </ul> <p>
67 * @see com.sun.star.accessibility.XAccessibleComponent
68 * @see com.sun.star.accessibility.XAccessibleContext
69 * @see ifc.accessibility._XAccessibleComponent
70 * @see ifc.accessibility._XAccessibleContext
72 public class ScAccessiblePageHeader extends TestCase {
74 private XSpreadsheetDocument xSpreadsheetDoc = null;
76 /**
77 * Called to create an instance of <code>TestEnvironment</code>
78 * with an object to test and related objects.
79 * Switches the document to Print Preview mode.
80 * Obtains accessible object for the page view.
82 * @param Param test parameters
83 * @param log writer to log information while testing
85 * @see TestEnvironment
86 * @see #getTestEnvironment
88 @Override
89 protected TestEnvironment createTestEnvironment(
90 TestParameters Param, PrintWriter log) throws Exception {
92 // inserting some content to have non-empty page preview
93 XCell xCell = null;
94 try {
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("ScAccessiblePageHeader");
101 } catch(com.sun.star.lang.WrappedTargetException e) {
102 log.println("Exception creating page header :");
103 e.printStackTrace(log);
104 } catch(com.sun.star.lang.IndexOutOfBoundsException e) {
105 log.println("Exception creating page header :");
106 e.printStackTrace(log);
109 XModel aModel = UnoRuntime.queryInterface(XModel.class, xSpreadsheetDoc);
111 XController xController = aModel.getCurrentController();
113 // switching to 'Page Preview' mode
114 XDispatchProvider xDispProv = UnoRuntime.queryInterface(XDispatchProvider.class, xController);
115 XURLTransformer xParser = UnoRuntime.queryInterface(XURLTransformer.class,
116 Param.getMSF().createInstance("com.sun.star.util.URLTransformer"));
117 // Because it's an in/out parameter we must use an array of URL objects.
118 URL[] aParseURL = new URL[1];
119 aParseURL[0] = new URL();
120 aParseURL[0].Complete = ".uno:PrintPreview";
121 xParser.parseStrict(aParseURL);
122 URL aURL = aParseURL[0];
123 XDispatch xDispatcher = xDispProv.queryDispatch(aURL, "", 0);
124 if(xDispatcher != null)
125 xDispatcher.dispatch( aURL, null );
127 XInterface oObj = null;
128 for (int i = 0;; ++i) {
129 Thread.sleep(500);
130 try {
131 XWindow xWindow = AccessibilityTools.getCurrentWindow(aModel);
132 XAccessible xRoot = AccessibilityTools.getAccessibleObject(xWindow);
133 if (xRoot != null) {
134 oObj = AccessibilityTools.getAccessibleObjectForRole
135 (xRoot, AccessibleRole.HEADER, "");
136 if (oObj != null) {
137 log.println("ImplementationName " + utils.getImplName(oObj));
138 AccessibilityTools.printAccessibleTree(log, xRoot, Param.getBool(util.PropertyName.DEBUG_IS_ACTIVE));
139 break;
142 } catch (DisposedException e) {
143 log.println("Ignoring DisposedException");
145 if (i == 20) { // give up after 10 sec
146 throw new RuntimeException(
147 "Couldn't get AccessibleRoot.HEADER object");
149 log.println("No HEADER found yet, retrying");
152 TestEnvironment tEnv = new TestEnvironment(oObj);
154 XStyleFamiliesSupplier StyleFam = UnoRuntime.queryInterface(
155 XStyleFamiliesSupplier.class,
156 xSpreadsheetDoc );
157 XNameAccess StyleFamNames = StyleFam.getStyleFamilies();
158 XStyle StdStyle = null;
160 XNameAccess PageStyles = (XNameAccess) AnyConverter.toObject(
161 new Type(XNameAccess.class),
162 StyleFamNames.getByName("PageStyles"));
163 StdStyle = (XStyle) AnyConverter.toObject(
164 new Type(XStyle.class), PageStyles.getByName("Default"));
166 //get the property-set
167 final XPropertySet PropSet = UnoRuntime.queryInterface(XPropertySet.class, StdStyle);
169 XHeaderFooterContent RPHC = null;
170 // creation of testobject here
171 // first we write what we are intend to do to log file
172 log.println( "creating a test environment" );
173 RPHC = (XHeaderFooterContent) AnyConverter.toObject(
174 new Type(XHeaderFooterContent.class),
175 PropSet.getPropertyValue("RightPageHeaderContent"));
177 final XHeaderFooterContent RPHC2 = RPHC;
179 final XText center = RPHC2.getCenterText();
180 final XText left = RPHC2.getLeftText();
181 final XText right = RPHC2.getRightText();
183 tEnv.addObjRelation("EventProducer",
184 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer(){
185 public void fireEvent() {
186 center.setString("CENTER");
187 left.setString("LEFT");
188 right.setString("RIGHT");
189 try {
190 PropSet.setPropertyValue("RightPageHeaderContent",RPHC2);
191 } catch (com.sun.star.beans.UnknownPropertyException e) {
192 } catch (com.sun.star.beans.PropertyVetoException e) {
193 } catch (com.sun.star.lang.IllegalArgumentException e) {
194 } catch (com.sun.star.lang.WrappedTargetException e) {}
199 return tEnv;
204 * Called while disposing a <code>TestEnvironment</code>.
205 * Disposes calc document.
206 * @param Param test parameters
207 * @param log writer to log information while testing
209 @Override
210 protected void cleanup( TestParameters Param, PrintWriter log) {
211 log.println( " disposing xSheetDoc " );
212 try {
213 XCloseable oComp = UnoRuntime.queryInterface (XCloseable.class, xSpreadsheetDoc) ;
214 oComp.close(true);
215 } catch(com.sun.star.util.CloseVetoException e) {
216 log.println("Couldn't close document: "+e.getMessage());
221 * Called while the <code>TestCase</code> initialization. In the
222 * implementation does nothing. Subclasses can override to initialize
223 * objects shared among all <code>TestEnvironment</code>s.
225 * @param Param test parameters
226 * @param log writer to log information while testing
228 * @see #initializeTestCase
230 @Override
231 protected void initialize(TestParameters Param, PrintWriter log) throws Exception {
232 // get a soffice factory object
233 SOfficeFactory SOF = SOfficeFactory.getFactory( Param.getMSF());
235 log.println("creating a spreadsheetdocument");
236 xSpreadsheetDoc = SOF.createCalcDoc(null);