bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _sc / ScAccessiblePreviewTable.java
blob9f5b3b0ac2337c790cd41d6b3f789e633db1e3ed
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.awt.XWindow;
37 import com.sun.star.container.XIndexAccess;
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.lang.XComponent;
44 import com.sun.star.lang.XMultiServiceFactory;
45 import com.sun.star.sheet.XSpreadsheet;
46 import com.sun.star.sheet.XSpreadsheetDocument;
47 import com.sun.star.sheet.XSpreadsheets;
48 import com.sun.star.table.XCell;
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.XURLTransformer;
55 import util.PropertyName;
57 /**
58 * Object implements the following interfaces:
59 * <ul>
60 * <li> <code>::com::sun::star::accessibility::XAccessibleComponent</code>
61 * </li>
62 * <li> <code>::com::sun::star::accessibility::XAccessibleContext</code>
63 * </li>
64 * <li> <code>::com::sun::star::accessibility::XAccessibleSelection
65 * </code></li>
66 * <li><code>::com::sun::star::accessibility::XAccessibleTable</code>
67 * </li>
68 * <li><code>::com::sun::star::accessibility::XAccessibleEventBroadcaster
69 * </code></li>
70 * </ul>
71 * @see com.sun.star.accessibility.XAccessibleComponent
72 * @see com.sun.star.accessibility.XAccessibleContext
73 * @see com.sun.star.accessibility.XAccessibleSelection
74 * @see com.sun.star.accessibility.XAccessibleTable
75 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
76 * @see ifc.accessibility._XAccessibleEventBroadcaster
77 * @see ifc.accessibility._XAccessibleComponent
78 * @see ifc.accessibility._XAccessibleContext
79 * @see ifc.accessibility._XAccessibleSelection
80 * @see ifc.accessibility._XAccessibleTable
82 public class ScAccessiblePreviewTable extends TestCase {
83 private XSpreadsheetDocument xSheetDoc = null;
85 /**
86 * Creates a spreadsheet document.
88 protected void initialize( TestParameters tParam, PrintWriter log ) {
89 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() );
90 try {
91 log.println( "creating a Spreadsheet document" );
92 xSheetDoc = SOF.createCalcDoc(null);
93 } catch ( com.sun.star.uno.Exception e ) {
94 // Some exception occurs.FAILED
95 e.printStackTrace( log );
96 throw new StatusException( "Couldn't create document", e );
101 * Disposes a spreadsheet document.
103 protected void cleanup( TestParameters tParam, PrintWriter log ) {
104 log.println( " disposing xSheetDoc " );
105 XComponent oComp = UnoRuntime.queryInterface
106 (XComponent.class, xSheetDoc);
107 util.DesktopTools.closeDoc(oComp);
112 * Creating a Testenvironment for the interfaces to be tested.
113 * Obtains the accessible object for a table in preview mode.
115 protected synchronized TestEnvironment createTestEnvironment(TestParameters Param, 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 ((XMultiServiceFactory)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 log.println("Couldn't change mode");
163 throw new StatusException(Status.failed("Couldn't change mode"));
166 XAccessible xRoot;
167 XInterface oObj;
168 for (int i = 0;; ++i) {
169 try {
170 Thread.sleep(500);
171 } catch (InterruptedException e) {
172 throw new RuntimeException(e);
174 try {
175 xRoot = AccessibilityTools.getAccessibleObject(
176 AccessibilityTools.getCurrentContainerWindow(
177 (XMultiServiceFactory)Param.getMSF(), xModel));
178 if (xRoot != null) {
179 oObj = AccessibilityTools.getAccessibleObjectForRole(
180 xRoot, AccessibleRole.TABLE);
181 if (oObj != null) {
182 break;
185 } catch (DisposedException e) {
186 log.println("Ignoring DisposedException");
188 if (i == 20) { // give up after 10 sec
189 throw new RuntimeException(
190 "Couldn't get AccessibleRole.TABLE/PUSH_BUTTON object");
192 log.println("No TABLE/PUSH_BUTTON found yet, retrying");
195 log.println("ImplementationName " + utils.getImplName(oObj));
197 TestEnvironment tEnv = new TestEnvironment( oObj );
199 XAccessibleContext zoomIn =
200 AccessibilityTools.getAccessibleObjectForRole(xRoot,AccessibleRole.PUSH_BUTTON, "Zoom In");
202 log.println("Getting "+ zoomIn.getAccessibleName());
204 final XAccessibleAction pressZoom = UnoRuntime.queryInterface(XAccessibleAction.class, zoomIn);
205 tEnv.addObjRelation("EventProducer",
206 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() {
207 public void fireEvent() {
208 try {
209 pressZoom.doAccessibleAction(0);
210 } catch (com.sun.star.lang.IndexOutOfBoundsException ibe) {}
214 return tEnv;