tdf#130857 qt weld: Introduce QtInstanceScrolledWindow
[LibreOffice.git] / qadevOOo / tests / java / mod / _sc / ScAccessiblePageHeaderArea.java
blob611c8f7abb7850e8b3bdaeff2e6f30e73678b6fe
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.*;
31 import com.sun.star.awt.XWindow;
32 import com.sun.star.container.XIndexAccess;
33 import com.sun.star.frame.XController;
34 import com.sun.star.frame.XDispatch;
35 import com.sun.star.frame.XDispatchProvider;
36 import com.sun.star.frame.XModel;
37 import com.sun.star.sheet.XSpreadsheet;
38 import com.sun.star.sheet.XSpreadsheetDocument;
39 import com.sun.star.sheet.XSpreadsheets;
40 import com.sun.star.table.XCell;
41 import com.sun.star.uno.AnyConverter;
42 import com.sun.star.uno.Type;
43 import com.sun.star.uno.UnoRuntime;
44 import com.sun.star.uno.XInterface;
45 import com.sun.star.util.URL;
46 import com.sun.star.util.XCloseable;
47 import com.sun.star.util.XURLTransformer;
49 /**
50 * Test for object which is represented by accessible component of
51 * a printed header in 'Page Preview' mode.
53 * Object implements the following interfaces :
54 * <ul>
55 * <li> <code>::com::sun::star::accessibility::XAccessibleComponent</code></li>
56 * <li> <code>::com::sun::star::accessibility::XAccessibleContext</code></li>
57 * </ul> <p>
59 * @see com.sun.star.accessibility.XAccessibleComponent
60 * @see com.sun.star.accessibility.XAccessibleContext
61 * @see ifc.accessibility._XAccessibleComponent
62 * @see ifc.accessibility._XAccessibleContext
64 public class ScAccessiblePageHeaderArea extends TestCase {
66 private XSpreadsheetDocument xSpreadsheetDoc = null;
68 /**
69 * Called to create an instance of <code>TestEnvironment</code>
70 * with an object to test and related objects.
71 * Switches the document to Print Preview mode.
72 * Obtains accessible object for the page view.
74 * @param Param test parameters
75 * @param log writer to log information while testing
77 * @see TestEnvironment
78 * @see #getTestEnvironment
80 @Override
81 protected TestEnvironment createTestEnvironment(
82 TestParameters Param, PrintWriter log) throws Exception {
84 XInterface oObj = null;
86 // inserting some content to have non-empty page preview
87 XCell xCell = null;
88 try {
89 XSpreadsheets oSheets = xSpreadsheetDoc.getSheets() ;
90 XIndexAccess oIndexSheets = UnoRuntime.queryInterface(XIndexAccess.class, oSheets);
91 XSpreadsheet oSheet = (XSpreadsheet) AnyConverter.toObject(
92 new Type(XSpreadsheet.class),oIndexSheets.getByIndex(0));
93 xCell = oSheet.getCellByPosition(0, 0) ;
94 xCell.setFormula("ScAccessiblePageHeaderArea");
95 } catch(com.sun.star.lang.WrappedTargetException e) {
96 log.println("Exception creating page header area :");
97 e.printStackTrace(log);
98 } catch(com.sun.star.lang.IndexOutOfBoundsException e) {
99 log.println("Exception creating page header area :");
100 e.printStackTrace(log);
101 } catch(com.sun.star.lang.IllegalArgumentException e) {
102 log.println("Exception creating page header area :");
103 e.printStackTrace(log);
106 XModel aModel = UnoRuntime.queryInterface(XModel.class, xSpreadsheetDoc);
108 XController xController = aModel.getCurrentController();
110 // switching to 'Page Preview' mode
111 XDispatchProvider xDispProv = UnoRuntime.queryInterface(XDispatchProvider.class, xController);
112 XURLTransformer xParser = UnoRuntime.queryInterface(XURLTransformer.class,
113 Param.getMSF().createInstance("com.sun.star.util.URLTransformer"));
114 // Because it's an in/out parameter we must use an array of URL objects.
115 URL[] aParseURL = new URL[1];
116 aParseURL[0] = new URL();
117 aParseURL[0].Complete = ".uno:PrintPreview";
118 xParser.parseStrict(aParseURL);
119 URL aURL = aParseURL[0];
120 XDispatch xDispatcher = xDispProv.queryDispatch(aURL, "", 0);
121 if(xDispatcher != null)
122 xDispatcher.dispatch( aURL, null );
124 util.utils.waitForEventIdle(Param.getMSF());
126 XWindow xWindow = AccessibilityTools.getCurrentContainerWindow(aModel);
127 XAccessible xRoot = AccessibilityTools.getAccessibleObject(xWindow);
129 oObj = AccessibilityTools.getAccessibleObjectForRole
130 (xRoot, AccessibleRole.HEADER, "").getAccessibleChild(0);
131 XAccessibleContext cont = UnoRuntime.queryInterface(XAccessibleContext.class, oObj);
132 long StateSet = cont.getAccessibleStateSet();
133 if ((StateSet & AccessibleStateType.TRANSIENT) != 0) {
134 log.println("Object is transient");
137 log.println("ImplementationName " + utils.getImplName(oObj));
138 AccessibilityTools.printAccessibleTree(log, xRoot, Param.getBool(util.PropertyName.DEBUG_IS_ACTIVE));
140 TestEnvironment tEnv = new TestEnvironment(oObj);
142 XAccessibleContext zoomIn =
143 AccessibilityTools.getAccessibleObjectForRole(xRoot,AccessibleRole.PUSH_BUTTON, "Zoom In");
145 final XAccessibleAction pressZoom = UnoRuntime.queryInterface(XAccessibleAction.class, zoomIn);
146 tEnv.addObjRelation("EventProducer",
147 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() {
148 public void fireEvent() {
149 try {
150 pressZoom.doAccessibleAction(0);
151 } catch (com.sun.star.lang.IndexOutOfBoundsException ibe) {
152 System.out.println("caught exception: " + ibe);
157 return tEnv;
162 * Called while disposing a <code>TestEnvironment</code>.
163 * Disposes calc document.
164 * @param Param test parameters
165 * @param log writer to log information while testing
167 @Override
168 protected void cleanup( TestParameters Param, PrintWriter log) {
169 log.println( " disposing xSheetDoc " );
170 try {
171 XCloseable oComp = UnoRuntime.queryInterface (XCloseable.class, xSpreadsheetDoc) ;
172 oComp.close(true);
173 }catch(com.sun.star.util.CloseVetoException e) {
174 log.println("Couldn't close document: "+e.getMessage());
179 * Called while the <code>TestCase</code> initialization. In the
180 * implementation does nothing. Subclasses can override to initialize
181 * objects shared among all <code>TestEnvironment</code>s.
183 * @param Param test parameters
184 * @param log writer to log information while testing
186 * @see #initializeTestCase
188 @Override
189 protected void initialize(TestParameters Param, PrintWriter log) throws Exception {
190 // get a soffice factory object
191 SOfficeFactory SOF = SOfficeFactory.getFactory( Param.getMSF());
193 log.println("creating a spreadsheetdocument");
194 xSpreadsheetDoc = SOF.createCalcDoc(null);