merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / mod / _sc / ScAccessiblePreviewCell.java
blobb461acbd02b70d6fc75b6fbee241ae77e067612a
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ScAccessiblePreviewCell.java,v $
10 * $Revision: 1.11 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 package mod._sc;
33 import java.io.PrintWriter;
35 import lib.Status;
36 import lib.StatusException;
37 import lib.TestCase;
38 import lib.TestEnvironment;
39 import lib.TestParameters;
40 import util.AccessibilityTools;
41 import util.SOfficeFactory;
42 import util.utils;
44 import com.sun.star.accessibility.AccessibleRole;
45 import com.sun.star.accessibility.XAccessible;
46 import com.sun.star.awt.XWindow;
47 import com.sun.star.container.XIndexAccess;
48 import com.sun.star.frame.XController;
49 import com.sun.star.frame.XDispatch;
50 import com.sun.star.frame.XDispatchProvider;
51 import com.sun.star.frame.XModel;
52 import com.sun.star.lang.XComponent;
53 import com.sun.star.lang.XMultiServiceFactory;
54 import com.sun.star.sheet.XSpreadsheet;
55 import com.sun.star.sheet.XSpreadsheetDocument;
56 import com.sun.star.sheet.XSpreadsheets;
57 import com.sun.star.table.XCell;
58 import com.sun.star.uno.AnyConverter;
59 import com.sun.star.uno.Type;
60 import com.sun.star.uno.UnoRuntime;
61 import com.sun.star.uno.XInterface;
62 import com.sun.star.util.URL;
63 import com.sun.star.util.XURLTransformer;
65 /**
66 * Object implements the following interfaces:
67 * <ul>
68 * <li> <code>::com::sun::star::accessibility::XAccessibleComponent</code>
69 * </li>
70 * <li> <code>::com::sun::star::accessibility::XAccessibleContext</code>
71 * </li>
72 * <li> <code>::com::sun::star::accessibility::XAccessibleSelection
73 * </code></li>
74 * <li><code>::com::sun::star::accessibility::XAccessibleValue</code>
75 * </li>
76 * <li><code>::com::sun::star::accessibility::XAccessibleEventBroadcaster
77 * </code></li>
78 * </ul>
79 * @see com.sun.star.accessibility.XAccessibleComponent
80 * @see com.sun.star.accessibility.XAccessibleContext
81 * @see com.sun.star.accessibility.XAccessibleSelection
82 * @see com.sun.star.accessibility.XAccessibleValue
83 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
84 * @see ifc.accessibility._XAccessibleEventBroadcaster
85 * @see ifc.accessibility._XAccessibleComponent
86 * @see ifc.accessibility._XAccessibleContext
87 * @see ifc.accessibility._XAccessibleSelection
88 * @see ifc.accessibility._XAccessibleTable
90 public class ScAccessiblePreviewCell extends TestCase {
91 static XSpreadsheetDocument xSheetDoc = null;
93 /**
94 * Creates a spreadsheet document.
96 protected void initialize( TestParameters tParam, PrintWriter log ) {
97 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() );
98 try {
99 log.println( "creating a Spreadsheet document" );
100 xSheetDoc = SOF.createCalcDoc(null);
101 } catch ( com.sun.star.uno.Exception e ) {
102 // Some exception occures.FAILED
103 e.printStackTrace( log );
104 throw new StatusException( "Couldn't create document", e );
109 * Disposes a spreadsheet document.
111 protected void cleanup( TestParameters tParam, PrintWriter log ) {
112 log.println( " disposing xSheetDoc " );
113 XComponent oComp = (XComponent)UnoRuntime.queryInterface
114 (XComponent.class, xSheetDoc);
115 util.DesktopTools.closeDoc(oComp);
120 * Creating a Testenvironment for the interfaces to be tested.
121 * Obtains the accessible object for a one of cell in preview mode.
123 protected synchronized TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) {
125 XInterface oObj = null;
126 XCell xCell = null;
128 try {
129 log.println("Getting spreadsheet") ;
130 XSpreadsheets oSheets = xSheetDoc.getSheets() ;
131 XIndexAccess oIndexSheets = (XIndexAccess)
132 UnoRuntime.queryInterface(XIndexAccess.class, oSheets);
133 XSpreadsheet oSheet = (XSpreadsheet) AnyConverter.toObject(
134 new Type(XSpreadsheet.class),oIndexSheets.getByIndex(0));
136 log.println("Getting a cell from sheet") ;
137 xCell = oSheet.getCellByPosition(0, 0);
138 } catch (com.sun.star.lang.WrappedTargetException e) {
139 e.printStackTrace(log);
140 throw new StatusException(
141 "Error getting cell object from spreadsheet document", e);
142 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
143 e.printStackTrace(log);
144 throw new StatusException(
145 "Error getting cell object from spreadsheet document", e);
146 } catch (com.sun.star.lang.IllegalArgumentException e) {
147 e.printStackTrace(log);
148 throw new StatusException(
149 "Error getting cell object from spreadsheet document", e);
152 xCell.setFormula("Value");
154 XModel xModel = (XModel)
155 UnoRuntime.queryInterface(XModel.class, xSheetDoc);
157 XController xController = xModel.getCurrentController();
159 //switch to 'Print Preview' mode
160 try {
161 XDispatchProvider xDispProv = (XDispatchProvider)
162 UnoRuntime.queryInterface(XDispatchProvider.class, xController);
163 XURLTransformer xParser = (com.sun.star.util.XURLTransformer)
164 UnoRuntime.queryInterface(XURLTransformer.class,
165 ((XMultiServiceFactory)Param.getMSF()).createInstance("com.sun.star.util.URLTransformer"));
166 URL[] aParseURL = new URL[1];
167 aParseURL[0] = new URL();
168 aParseURL[0].Complete = ".uno:PrintPreview";
169 xParser.parseStrict(aParseURL);
170 URL aURL = aParseURL[0];
171 XDispatch xDispatcher = xDispProv.queryDispatch(aURL, "", 0);
172 if(xDispatcher != null)
173 xDispatcher.dispatch( aURL, null );
174 } catch (com.sun.star.uno.Exception e) {
175 log.println("Couldn't change mode");
176 throw new StatusException(Status.failed("Couldn't change mode"));
179 shortWait();
181 AccessibilityTools at = new AccessibilityTools();
183 XWindow xWindow = at.getCurrentWindow((XMultiServiceFactory)Param.getMSF(), xModel);
184 XAccessible xRoot = at.getAccessibleObject(xWindow);
186 at.getAccessibleObjectForRole(xRoot, AccessibleRole.TABLE_CELL, true);
188 oObj = AccessibilityTools.SearchedContext;
190 log.println("ImplementationName " + utils.getImplName(oObj));
192 TestEnvironment tEnv = new TestEnvironment( oObj );
194 tEnv.addObjRelation("EventProducer",
195 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer(){
196 public void fireEvent() {
197 System.out.println("Fire Event");
201 return tEnv;
204 protected void shortWait() {
205 try {
206 Thread.sleep(1000) ;
207 } catch (InterruptedException e) {
208 System.out.println("While waiting :" + e);