tdf#130857 qt weld: Introduce QtInstanceScrolledWindow
[LibreOffice.git] / qadevOOo / tests / java / mod / _sc / ScAccessiblePreviewHeaderCell.java
blob911b65aecba41ee38de3c89fc0234c8c6987e79d
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 .
18 package mod._sc;
20 import java.io.PrintWriter;
22 import lib.TestCase;
23 import lib.TestEnvironment;
24 import lib.TestParameters;
25 import util.AccessibilityTools;
26 import util.SOfficeFactory;
27 import util.utils;
29 import com.sun.star.accessibility.AccessibleRole;
30 import com.sun.star.accessibility.XAccessible;
31 import com.sun.star.beans.XPropertySet;
32 import com.sun.star.container.XIndexAccess;
33 import com.sun.star.container.XNameAccess;
34 import com.sun.star.frame.XController;
35 import com.sun.star.frame.XDispatch;
36 import com.sun.star.frame.XDispatchProvider;
37 import com.sun.star.frame.XModel;
38 import com.sun.star.lang.DisposedException;
39 import com.sun.star.lang.XComponent;
40 import com.sun.star.sheet.XSpreadsheet;
41 import com.sun.star.sheet.XSpreadsheetDocument;
42 import com.sun.star.sheet.XSpreadsheets;
43 import com.sun.star.style.XStyleFamiliesSupplier;
44 import com.sun.star.table.XCell;
45 import com.sun.star.uno.AnyConverter;
46 import com.sun.star.uno.Type;
47 import com.sun.star.uno.UnoRuntime;
48 import com.sun.star.uno.XInterface;
49 import com.sun.star.util.URL;
50 import com.sun.star.util.XCloseable;
51 import com.sun.star.util.XURLTransformer;
54 /**
55 * Object implements the following interfaces:
56 * <ul>
57 * <li> <code>::com::sun::star::accessibility::XAccessibleComponent</code>
58 * </li>
59 * <li> <code>::com::sun::star::accessibility::XAccessibleContext</code>
60 * </li>
61 * <li> <code>::com::sun::star::accessibility::XAccessibleSelection
62 * </code></li>
63 * <li><code>::com::sun::star::accessibility::XAccessibleValue</code>
64 * </li>
65 * <li><code>::com::sun::star::accessibility::XAccessibleEventBroadcaster
66 * </code></li>
67 * </ul>
68 * @see com.sun.star.accessibility.XAccessibleComponent
69 * @see com.sun.star.accessibility.XAccessibleContext
70 * @see com.sun.star.accessibility.XAccessibleSelection
71 * @see com.sun.star.accessibility.XAccessibleValue
72 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
73 * @see ifc.accessibility._XAccessibleEventBroadcaster
74 * @see ifc.accessibility._XAccessibleComponent
75 * @see ifc.accessibility._XAccessibleContext
76 * @see ifc.accessibility._XAccessibleSelection
77 * @see ifc.accessibility._XAccessibleTable
79 public class ScAccessiblePreviewHeaderCell extends TestCase {
80 private XSpreadsheetDocument xSheetDoc = null;
82 /**
83 * Creates a spreadsheet document.
85 @Override
86 protected void initialize(TestParameters tParam, PrintWriter log) throws Exception {
89 /**
90 * Disposes a spreadsheet document.
92 @Override
93 protected void cleanup(TestParameters tParam, PrintWriter log) {
94 log.println(" disposing xSheetDoc ");
96 if (xSheetDoc != null) {
97 try {
98 XCloseable oComp = UnoRuntime.queryInterface(
99 XCloseable.class, xSheetDoc);
100 oComp.close(true);
101 xSheetDoc = null;
102 } catch (com.sun.star.util.CloseVetoException e) {
103 e.printStackTrace(log);
104 } catch (com.sun.star.lang.DisposedException e) {
105 log.println("document already disposed");
106 xSheetDoc = null;
112 * Creating a TestEnvironment for the interfaces to be tested.
113 * Sets a value of the cell 'A1'. Sets the property 'PrintHeaders'
114 * of the style 'Default' of the family 'PageStyles' to true.
115 * Switch the document to preview mode and then obtains the
116 * accessible object for the header cell.
118 @Override
119 protected TestEnvironment createTestEnvironment(TestParameters Param,
120 PrintWriter log) throws Exception {
121 if (xSheetDoc != null) {
122 XComponent oComp = UnoRuntime.queryInterface(
123 XComponent.class, xSheetDoc);
124 util.DesktopTools.closeDoc(oComp);
127 SOfficeFactory SOF = SOfficeFactory.getFactory( Param.getMSF());
129 log.println("creating a Spreadsheet document");
130 xSheetDoc = SOF.createCalcDoc(null);
132 XModel xModel = UnoRuntime.queryInterface(XModel.class,
133 xSheetDoc);
135 XController xController = xModel.getCurrentController();
137 //setting value of cell A1
138 XCell xCell = null;
140 log.println("Getting spreadsheet");
142 XSpreadsheets oSheets = xSheetDoc.getSheets();
143 XIndexAccess oIndexSheets = UnoRuntime.queryInterface(
144 XIndexAccess.class, oSheets);
145 XSpreadsheet oSheet = (XSpreadsheet) AnyConverter.toObject(
146 new Type(XSpreadsheet.class),
147 oIndexSheets.getByIndex(0));
149 log.println("Getting a cell from sheet");
150 xCell = oSheet.getCellByPosition(0, 0);
152 xCell.setFormula("Value");
154 //setting property 'PrintHeaders' of the style 'Default'
155 XStyleFamiliesSupplier xSFS = UnoRuntime.queryInterface(
156 XStyleFamiliesSupplier.class,
157 xSheetDoc);
158 XNameAccess xNA = xSFS.getStyleFamilies();
159 XPropertySet xPropSet = null;
161 Object oPageStyles = xNA.getByName("PageStyles");
162 xNA = UnoRuntime.queryInterface(XNameAccess.class,
163 oPageStyles);
165 Object oDefStyle = xNA.getByName("Default");
166 xPropSet = UnoRuntime.queryInterface(
167 XPropertySet.class, oDefStyle);
169 xPropSet.setPropertyValue("PrintHeaders", Boolean.TRUE);
171 //switching to 'Print Preview' mode
172 XDispatchProvider xDispProv = UnoRuntime.queryInterface(
173 XDispatchProvider.class,
174 xController);
175 XURLTransformer xParser = UnoRuntime.queryInterface(
176 XURLTransformer.class,
177 Param.getMSF()
178 .createInstance("com.sun.star.util.URLTransformer"));
179 URL[] aParseURL = new URL[1];
180 aParseURL[0] = new URL();
181 aParseURL[0].Complete = ".uno:PrintPreview";
182 xParser.parseStrict(aParseURL);
184 URL aURL = aParseURL[0];
185 XDispatch xDispatcher = xDispProv.queryDispatch(aURL, "", 0);
187 if (xDispatcher != null) {
188 xDispatcher.dispatch(aURL, null);
191 XInterface oObj = null;
192 for (int i = 0;; ++i) {
193 Thread.sleep(500);
194 try {
195 XAccessible xRoot = AccessibilityTools.getAccessibleObject(
196 AccessibilityTools.getCurrentWindow(
197 xModel));
198 if (xRoot != null) {
199 oObj = AccessibilityTools.getAccessibleObjectForRole(
200 xRoot, AccessibleRole.TABLE, "A");
201 if (oObj == null) {
202 log.println("Version with a fixed #103863#?");
203 oObj = AccessibilityTools.getAccessibleObjectForRole(
204 xRoot, AccessibleRole.TABLE_CELL, true);
206 if (oObj != null) {
207 break;
210 } catch (DisposedException e) {
211 log.println("Ignoring DisposedException");
213 if (i == 20) { // give up after 10 sec
214 throw new RuntimeException(
215 "Couldn't get AccessibleRole.TABLE/TABLE_CELL object");
217 log.println("No TABLE/TABLE_CELL found yet, retrying");
220 log.println("ImplementationName " + utils.getImplName(oObj));
222 TestEnvironment tEnv = new TestEnvironment(oObj);
224 tEnv.addObjRelation("EventProducer",
225 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() {
226 public void fireEvent() {
230 return tEnv;