bump product version to 5.0.4.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _sc / ScAccessiblePreviewTable.java
blobbb3e728b698b84b48f9aa24c0e98e85ba33e629c
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.Status;
24 import lib.StatusException;
25 import lib.TestCase;
26 import lib.TestEnvironment;
27 import lib.TestParameters;
28 import util.AccessibilityTools;
29 import util.SOfficeFactory;
30 import util.utils;
32 import com.sun.star.accessibility.AccessibleRole;
33 import com.sun.star.accessibility.XAccessible;
34 import com.sun.star.accessibility.XAccessibleAction;
35 import com.sun.star.accessibility.XAccessibleContext;
36 import com.sun.star.container.XIndexAccess;
37 import com.sun.star.frame.XController;
38 import com.sun.star.frame.XDispatch;
39 import com.sun.star.frame.XDispatchProvider;
40 import com.sun.star.frame.XModel;
41 import com.sun.star.lang.DisposedException;
42 import com.sun.star.lang.XComponent;
43 import com.sun.star.sheet.XSpreadsheet;
44 import com.sun.star.sheet.XSpreadsheetDocument;
45 import com.sun.star.sheet.XSpreadsheets;
46 import com.sun.star.table.XCell;
47 import com.sun.star.uno.AnyConverter;
48 import com.sun.star.uno.Type;
49 import com.sun.star.uno.UnoRuntime;
50 import com.sun.star.uno.XInterface;
51 import com.sun.star.util.URL;
52 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::XAccessibleTable</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.XAccessibleTable
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 ScAccessiblePreviewTable extends TestCase {
80 private XSpreadsheetDocument xSheetDoc = null;
82 /**
83 * Creates a spreadsheet document.
85 @Override
86 protected void initialize( TestParameters tParam, PrintWriter log ) {
87 SOfficeFactory SOF = SOfficeFactory.getFactory( tParam.getMSF() );
88 try {
89 log.println( "creating a Spreadsheet document" );
90 xSheetDoc = SOF.createCalcDoc(null);
91 } catch ( com.sun.star.uno.Exception e ) {
92 // Some exception occurs.FAILED
93 e.printStackTrace( log );
94 throw new StatusException( "Couldn't create document", e );
98 /**
99 * Disposes a spreadsheet document.
101 @Override
102 protected void cleanup( TestParameters tParam, PrintWriter log ) {
103 log.println( " disposing xSheetDoc " );
104 XComponent oComp = UnoRuntime.queryInterface
105 (XComponent.class, xSheetDoc);
106 util.DesktopTools.closeDoc(oComp);
111 * Creating a Testenvironment for the interfaces to be tested.
112 * Obtains the accessible object for a table in preview mode.
114 @Override
115 protected synchronized TestEnvironment createTestEnvironment(final TestParameters Param, final PrintWriter log) {
117 XCell xCell = null;
119 try {
120 log.println("Getting spreadsheet") ;
121 XSpreadsheets oSheets = xSheetDoc.getSheets() ;
122 XIndexAccess oIndexSheets = UnoRuntime.queryInterface(XIndexAccess.class, oSheets);
123 XSpreadsheet oSheet = (XSpreadsheet) AnyConverter.toObject(
124 new Type(XSpreadsheet.class),oIndexSheets.getByIndex(0));
126 log.println("Getting a cell from sheet") ;
127 xCell = oSheet.getCellByPosition(0, 0);
128 } catch (com.sun.star.lang.WrappedTargetException e) {
129 e.printStackTrace(log);
130 throw new StatusException(
131 "Error getting cell object from spreadsheet document", e);
132 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
133 e.printStackTrace(log);
134 throw new StatusException(
135 "Error getting cell object from spreadsheet document", e);
136 } catch (com.sun.star.lang.IllegalArgumentException e) {
137 e.printStackTrace(log);
138 throw new StatusException(
139 "Error getting cell object from spreadsheet document", e);
142 xCell.setFormula("Value");
144 XModel xModel = UnoRuntime.queryInterface(XModel.class, xSheetDoc);
146 XController xController = xModel.getCurrentController();
148 //switch to 'Print Preview' mode
149 try {
150 XDispatchProvider xDispProv = UnoRuntime.queryInterface(XDispatchProvider.class, xController);
151 XURLTransformer xParser = UnoRuntime.queryInterface(XURLTransformer.class,
152 Param.getMSF().createInstance("com.sun.star.util.URLTransformer"));
153 URL[] aParseURL = new URL[1];
154 aParseURL[0] = new URL();
155 aParseURL[0].Complete = ".uno:PrintPreview";
156 xParser.parseStrict(aParseURL);
157 URL aURL = aParseURL[0];
158 XDispatch xDispatcher = xDispProv.queryDispatch(aURL, "", 0);
159 if(xDispatcher != null)
160 xDispatcher.dispatch( aURL, null );
161 } catch (com.sun.star.uno.Exception e) {
162 throw new StatusException(e, Status.failed("Couldn't change mode"));
165 XAccessible xRoot;
166 XInterface oObj;
167 for (int i = 0;; ++i) {
168 try {
169 Thread.sleep(500);
170 } catch (InterruptedException e) {
171 throw new RuntimeException(e);
173 try {
174 xRoot = AccessibilityTools.getAccessibleObject(
175 AccessibilityTools.getCurrentContainerWindow(
176 xModel));
177 if (xRoot != null) {
178 oObj = AccessibilityTools.getAccessibleObjectForRole(
179 xRoot, AccessibleRole.TABLE);
180 if (oObj != null) {
181 break;
184 } catch (DisposedException e) {
185 log.println("Ignoring DisposedException");
187 if (i == 20) { // give up after 10 sec
188 throw new RuntimeException(
189 "Couldn't get AccessibleRole.TABLE/PUSH_BUTTON object");
191 log.println("No TABLE/PUSH_BUTTON found yet, retrying");
194 log.println("ImplementationName " + utils.getImplName(oObj));
196 TestEnvironment tEnv = new TestEnvironment( oObj );
198 XAccessibleContext zoomIn =
199 AccessibilityTools.getAccessibleObjectForRole(xRoot,AccessibleRole.PUSH_BUTTON, "Zoom In");
201 log.println("Getting \"" + zoomIn.getAccessibleName() + "\" which is a \"" + UnoRuntime.queryInterface(com.sun.star.lang.XServiceInfo.class, zoomIn).getImplementationName() + "\"");
203 final XAccessibleAction pressZoom = UnoRuntime.queryInterface(XAccessibleAction.class, zoomIn);
204 tEnv.addObjRelation("EventProducer",
205 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() {
206 public void fireEvent() {
207 try {
208 pressZoom.doAccessibleAction(0);
209 // the action is not triggered on the preview table
210 // but some toolbar button - this will indirectly
211 // trigger a table event but only from VCL main loop
212 utils.waitForEventIdle(Param.getMSF());
213 // sadly it turns out that idle is not enough...
214 Thread.sleep(500);
215 } catch (com.sun.star.lang.IndexOutOfBoundsException ibe) {
216 log.println("ScAccessiblePreviewTable: IndexOutOfBoundsException from pressZoom.doAccessibleAction(0)");
217 } catch (InterruptedException ex) {}
221 return tEnv;