merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / mod / _sc / ScAccessibleSpreadsheet.java
blobefc487b0507516d1ac3bc3358cf2d888a6125863
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: ScAccessibleSpreadsheet.java,v $
10 * $Revision: 1.10 $
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.container.XIndexAccess;
47 import com.sun.star.frame.XModel;
48 import com.sun.star.lang.XComponent;
49 import com.sun.star.lang.XMultiServiceFactory;
50 import com.sun.star.sheet.XSpreadsheet;
51 import com.sun.star.sheet.XSpreadsheetDocument;
52 import com.sun.star.sheet.XSpreadsheets;
53 import com.sun.star.table.XCell;
54 import com.sun.star.uno.AnyConverter;
55 import com.sun.star.uno.Type;
56 import com.sun.star.uno.UnoRuntime;
57 import com.sun.star.uno.XInterface;
59 /**
60 * Test for accessible object of spreadsheet document.<p>
61 * Object implements the following interfaces:
62 * <ul>
63 * <li> <code>::com::sun::star::accessibility::XAccessibleComponent</code>
64 * </li>
65 * <li> <code>::com::sun::star::accessibility::XAccessibleContext</code>
66 * </li>
67 * <li> <code>::com::sun::star::accessibility::XAccessibleSelection
68 * </code></li>
69 * <li><code>::com::sun::star::accessibility::XAccessibleTable</code>
70 * </li>
71 * </ul>
72 * @see com.sun.star.accessibility.XAccessibleComponent
73 * @see com.sun.star.accessibility.XAccessibleContext
74 * @see com.sun.star.accessibility.XAccessibleSelection
75 * @see com.sun.star.accessibility.XAccessibleTable
76 * @see ifc.accessibility._XAccessibleComponent
77 * @see ifc.accessibility._XAccessibleContext
78 * @see ifc.accessibility._XAccessibleSelection
79 * @see ifc.accessibility._XAccessibleTable
81 public class ScAccessibleSpreadsheet extends TestCase {
82 static XSpreadsheetDocument xSheetDoc = null;
84 /**
85 * Creates a spreadsheet document.
87 protected void initialize( TestParameters tParam, PrintWriter log ) {
88 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() );
89 try {
90 log.println( "creating a Spreadsheet document" );
91 xSheetDoc = SOF.createCalcDoc(null);
92 } catch ( com.sun.star.uno.Exception e ) {
93 // Some exception occures.FAILED
94 e.printStackTrace( log );
95 throw new StatusException( "Couldn't create document", e );
99 /**
100 * Disposes a spreadsheet document.
102 protected void cleanup( TestParameters tParam, PrintWriter log ) {
103 log.println( " disposing xSheetDoc " );
104 XComponent oComp = (XComponent)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 the spreadsheet.
114 public synchronized TestEnvironment createTestEnvironment
115 ( TestParameters Param, PrintWriter log )
116 throws StatusException {
118 XInterface oObj = null;
120 XModel xModel = (XModel)
121 UnoRuntime.queryInterface(XModel.class, xSheetDoc);
123 AccessibilityTools at = new AccessibilityTools();
125 XWindow xWindow = at.getCurrentWindow((XMultiServiceFactory)Param.getMSF(), xModel);
126 XAccessible xRoot = at.getAccessibleObject(xWindow);
128 at.getAccessibleObjectForRole(xRoot, AccessibleRole.TABLE );
130 oObj = AccessibilityTools.SearchedContext;
132 log.println("ImplementationName " + utils.getImplName(oObj));
134 TestEnvironment tEnv = new TestEnvironment( oObj );
136 // relation for XAccessibleEventBroadcaster
137 XCell xCell = null;
138 final String text = "Text for testing of the interface XAccessibleText";
139 try {
140 XSpreadsheets oSheets = xSheetDoc.getSheets() ;
141 XIndexAccess oIndexSheets = (XIndexAccess)
142 UnoRuntime.queryInterface(XIndexAccess.class, oSheets);
143 XSpreadsheet oSheet = (XSpreadsheet) AnyConverter.toObject(
144 new Type(XSpreadsheet.class),oIndexSheets.getByIndex(0));
145 xCell = oSheet.getCellByPosition(5, 5) ;
146 xCell.setFormula(text);
147 } catch(com.sun.star.lang.WrappedTargetException e) {
148 log.println("Exception ceating relation :");
149 e.printStackTrace(log);
150 } catch(com.sun.star.lang.IndexOutOfBoundsException e) {
151 log.println("Exception ceating relation :");
152 e.printStackTrace(log);
153 } catch(com.sun.star.lang.IllegalArgumentException e) {
154 log.println("Exception ceating relation :");
155 e.printStackTrace(log);
158 final XCell fCell = xCell ;
160 tEnv.addObjRelation("EventProducer",
161 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer(){
162 public void fireEvent() {
163 fCell.setFormula("firing event");
164 fCell.setFormula(text);
168 return tEnv;