merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / mod / _sc / ScAccessibleCell.java
blobceec23004225b3e65024d32f42669d947537c761
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: ScAccessibleCell.java,v $
10 * $Revision: 1.12 $
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.StatusException;
36 import lib.TestCase;
37 import lib.TestEnvironment;
38 import lib.TestParameters;
39 import util.AccessibilityTools;
40 import util.SOfficeFactory;
41 import util.utils;
43 import com.sun.star.accessibility.AccessibleRole;
44 import com.sun.star.accessibility.XAccessible;
45 import com.sun.star.awt.XWindow;
46 import com.sun.star.beans.XPropertySet;
47 import com.sun.star.container.XIndexAccess;
48 import com.sun.star.frame.XModel;
49 import com.sun.star.lang.XComponent;
50 import com.sun.star.lang.XMultiServiceFactory;
51 import com.sun.star.sheet.XSpreadsheet;
52 import com.sun.star.sheet.XSpreadsheetDocument;
53 import com.sun.star.sheet.XSpreadsheets;
54 import com.sun.star.table.XCell;
55 import com.sun.star.table.XColumnRowRange;
56 import com.sun.star.table.XTableColumns;
57 import com.sun.star.uno.AnyConverter;
58 import com.sun.star.uno.Type;
59 import com.sun.star.uno.UnoRuntime;
60 import com.sun.star.uno.XInterface;
62 /**
63 * Test for object which is represented by accessible component of
64 * a cell in the spreadsheet. <p>
65 * Object implements the following interfaces :
66 * <ul>
67 * <li> <code>::com::sun::star::accessibility::XAccessibleSelection</code></li>
68 * <li> <code>::com::sun::star::accessibility::XAccessibleEventBroadcaster</code></li>
69 * <li> <code>::com::sun::star::accessibility::XAccessibleComponent</code></li>
70 * <li> <code>::com::sun::star::accessibility::XAccessibleTable</code></li>
71 * <li> <code>::com::sun::star::accessibility::XAccessibleContext</code></li>
72 * </ul> <p>
74 * @see com.sun.star.accessibility.XAccessibleSelection
75 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
76 * @see com.sun.star.accessibility.XAccessibleComponent
77 * @see com.sun.star.accessibility.XAccessibleTable
78 * @see com.sun.star.accessibility.XAccessibleContext
79 * @see ifc.n.star.accessibility._XAccessibleSelection
80 * @see ifc.n.star.accessibility._XAccessibleEventBroadcaster
81 * @see ifc.n.star.accessibility._XAccessibleComponent
82 * @see ifc.n.star.accessibility._XAccessibleTable
83 * @see ifc.n.star.accessibility._XAccessibleContext
85 public class ScAccessibleCell extends TestCase {
87 static XSpreadsheetDocument xSpreadsheetDoc = null;
89 /**
90 * Called to create an instance of <code>TestEnvironment</code>
91 * with an object to test and related objects.
92 * Switchs the document to Print Preview mode.
93 * Obtains accissible object for the page view.
95 * @param tParam test parameters
96 * @param log writer to log information while testing
98 * @see TestEnvironment
99 * @see #getTestEnvironment()
101 protected TestEnvironment createTestEnvironment(
102 TestParameters Param, PrintWriter log) {
104 // get a soffice factory object
105 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory) Param.getMSF());
107 try {
108 log.println("creating a spreadsheetdocument");
109 xSpreadsheetDoc = SOF.createCalcDoc(null);
110 } catch (com.sun.star.uno.Exception e) {
111 e.printStackTrace( log );
112 throw new StatusException( "Couldn't create document ", e );
115 XInterface oObj = null;
117 XModel aModel = (XModel)
118 UnoRuntime.queryInterface(XModel.class, xSpreadsheetDoc);
120 XWindow xWindow = AccessibilityTools.getCurrentWindow( (XMultiServiceFactory) Param.getMSF(), aModel);
121 XAccessible xRoot = AccessibilityTools.getAccessibleObject(xWindow);
123 oObj = AccessibilityTools.getAccessibleObjectForRole
124 (xRoot, AccessibleRole.TABLE_CELL, "B1");
126 log.println("ImplementationName " + utils.getImplName(oObj));
128 TestEnvironment tEnv = new TestEnvironment(oObj);
130 // relation for XAccessibleEventBroadcaster
131 XCell xCell = null;
132 final String text = "XAccessibleText";
133 try {
134 XSpreadsheets oSheets = xSpreadsheetDoc.getSheets() ;
135 XIndexAccess oIndexSheets = (XIndexAccess)
136 UnoRuntime.queryInterface(XIndexAccess.class, oSheets);
137 XSpreadsheet oSheet = null;
138 try {
139 oSheet = (XSpreadsheet) AnyConverter.toObject(
140 new Type(XSpreadsheet.class),oIndexSheets.getByIndex(0));
141 } catch (com.sun.star.lang.IllegalArgumentException iae) {
142 throw new StatusException("couldn't get sheet",iae);
144 xCell = oSheet.getCellByPosition(1, 0) ;
145 xCell.setFormula(text);
146 XColumnRowRange oColumnRowRange = (XColumnRowRange)
147 UnoRuntime.queryInterface(XColumnRowRange.class, oSheet);
148 XTableColumns oColumns = (XTableColumns) oColumnRowRange.getColumns();
149 XIndexAccess oIndexAccess = (XIndexAccess)
150 UnoRuntime.queryInterface(XIndexAccess.class, oColumns);
151 XPropertySet column = (XPropertySet) UnoRuntime.queryInterface(
152 XPropertySet.class,oIndexAccess.getByIndex(1));
153 column.setPropertyValue("OptimalWidth", new Boolean(true));
154 } catch(com.sun.star.lang.WrappedTargetException e) {
155 log.println("Exception ceating relation :");
156 e.printStackTrace(log);
157 } catch(com.sun.star.lang.IndexOutOfBoundsException e) {
158 log.println("Exception ceating relation :");
159 e.printStackTrace(log);
160 } catch(com.sun.star.beans.UnknownPropertyException e) {
161 log.println("Exception ceating relation :");
162 e.printStackTrace(log);
163 } catch(com.sun.star.beans.PropertyVetoException e) {
164 log.println("Exception ceating relation :");
165 e.printStackTrace(log);
166 } catch(com.sun.star.lang.IllegalArgumentException e) {
167 log.println("Exception ceating relation :");
168 e.printStackTrace(log);
171 tEnv.addObjRelation("EditOnly",
172 "This method is only supported if the Cell is in edit mode");
174 final XCell fCell = xCell ;
176 tEnv.addObjRelation("EventProducer",
177 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer(){
178 public void fireEvent() {
179 fCell.setFormula("firing event");
180 fCell.setFormula(text);
184 tEnv.addObjRelation("XAccessibleText.Text", text);
186 return tEnv;
191 * Called while disposing a <code>TestEnvironment</code>.
192 * Disposes calc document.
193 * @param tParam test parameters
194 * @param tEnv the environment to cleanup
195 * @param log writer to log information while testing
197 protected void cleanup( TestParameters Param, PrintWriter log) {
198 log.println( " disposing xSheetDoc " );
199 XComponent oComp = (XComponent)
200 UnoRuntime.queryInterface (XComponent.class, xSpreadsheetDoc) ;
201 util.DesktopTools.closeDoc(oComp);