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 .
21 import java
.io
.PrintWriter
;
23 import lib
.StatusException
;
25 import lib
.TestEnvironment
;
26 import lib
.TestParameters
;
27 import util
.AccessibilityTools
;
28 import util
.SOfficeFactory
;
31 import com
.sun
.star
.accessibility
.AccessibleRole
;
32 import com
.sun
.star
.accessibility
.XAccessible
;
33 import com
.sun
.star
.awt
.XWindow
;
34 import com
.sun
.star
.beans
.XPropertySet
;
35 import com
.sun
.star
.container
.XIndexAccess
;
36 import com
.sun
.star
.frame
.XModel
;
37 import com
.sun
.star
.lang
.XComponent
;
38 import com
.sun
.star
.sheet
.XSpreadsheet
;
39 import com
.sun
.star
.sheet
.XSpreadsheetDocument
;
40 import com
.sun
.star
.sheet
.XSpreadsheets
;
41 import com
.sun
.star
.table
.XCell
;
42 import com
.sun
.star
.table
.XColumnRowRange
;
43 import com
.sun
.star
.table
.XTableColumns
;
44 import com
.sun
.star
.uno
.AnyConverter
;
45 import com
.sun
.star
.uno
.Type
;
46 import com
.sun
.star
.uno
.UnoRuntime
;
47 import com
.sun
.star
.uno
.XInterface
;
50 * Test for object which is represented by accessible component of
51 * a cell in the spreadsheet. <p>
52 * Object implements the following interfaces :
54 * <li> <code>::com::sun::star::accessibility::XAccessibleSelection</code></li>
55 * <li> <code>::com::sun::star::accessibility::XAccessibleEventBroadcaster</code></li>
56 * <li> <code>::com::sun::star::accessibility::XAccessibleComponent</code></li>
57 * <li> <code>::com::sun::star::accessibility::XAccessibleTable</code></li>
58 * <li> <code>::com::sun::star::accessibility::XAccessibleContext</code></li>
61 * @see com.sun.star.accessibility.XAccessibleSelection
62 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
63 * @see com.sun.star.accessibility.XAccessibleComponent
64 * @see com.sun.star.accessibility.XAccessibleTable
65 * @see com.sun.star.accessibility.XAccessibleContext
66 * @see ifc.accessibility._XAccessibleSelection
67 * @see ifc.accessibility._XAccessibleEventBroadcaster
68 * @see ifc.accessibility._XAccessibleComponent
69 * @see ifc.accessibility._XAccessibleTable
70 * @see ifc.accessibility._XAccessibleContext
72 public class ScAccessibleCell
extends TestCase
{
74 private XSpreadsheetDocument xSpreadsheetDoc
= null;
77 * Called to create an instance of <code>TestEnvironment</code>
78 * with an object to test and related objects.
79 * Switches the document to Print Preview mode.
80 * Obtains accessible object for the page view.
82 * @param Param test parameters
83 * @param log writer to log information while testing
85 * @see TestEnvironment
86 * @see #getTestEnvironment
89 protected TestEnvironment
createTestEnvironment(
90 TestParameters Param
, PrintWriter log
) {
92 // get a soffice factory object
93 SOfficeFactory SOF
= SOfficeFactory
.getFactory( Param
.getMSF());
96 log
.println("creating a spreadsheetdocument");
97 xSpreadsheetDoc
= SOF
.createCalcDoc(null);
98 } catch (com
.sun
.star
.uno
.Exception e
) {
99 e
.printStackTrace( log
);
100 throw new StatusException( "Couldn't create document ", e
);
103 XInterface oObj
= null;
105 XModel aModel
= UnoRuntime
.queryInterface(XModel
.class, xSpreadsheetDoc
);
107 XWindow xWindow
= AccessibilityTools
.getCurrentWindow(aModel
);
108 XAccessible xRoot
= AccessibilityTools
.getAccessibleObject(xWindow
);
110 oObj
= AccessibilityTools
.getAccessibleObjectForRole
111 (xRoot
, AccessibleRole
.TABLE_CELL
, "B1");
113 log
.println("ImplementationName " + utils
.getImplName(oObj
));
115 TestEnvironment tEnv
= new TestEnvironment(oObj
);
117 // relation for XAccessibleEventBroadcaster
119 final String text
= "XAccessibleText";
121 XSpreadsheets oSheets
= xSpreadsheetDoc
.getSheets() ;
122 XIndexAccess oIndexSheets
= UnoRuntime
.queryInterface(XIndexAccess
.class, oSheets
);
123 XSpreadsheet oSheet
= null;
125 oSheet
= (XSpreadsheet
) AnyConverter
.toObject(
126 new Type(XSpreadsheet
.class),oIndexSheets
.getByIndex(0));
127 } catch (com
.sun
.star
.lang
.IllegalArgumentException iae
) {
128 throw new StatusException("couldn't get sheet",iae
);
130 xCell
= oSheet
.getCellByPosition(1, 0) ;
131 xCell
.setFormula(text
);
132 XColumnRowRange oColumnRowRange
= UnoRuntime
.queryInterface(XColumnRowRange
.class, oSheet
);
133 XTableColumns oColumns
= oColumnRowRange
.getColumns();
134 XIndexAccess oIndexAccess
= UnoRuntime
.queryInterface(XIndexAccess
.class, oColumns
);
135 XPropertySet column
= UnoRuntime
.queryInterface(
136 XPropertySet
.class,oIndexAccess
.getByIndex(1));
137 column
.setPropertyValue("OptimalWidth", Boolean
.TRUE
);
138 } catch(com
.sun
.star
.lang
.WrappedTargetException e
) {
139 log
.println("Exception creating relation :");
140 e
.printStackTrace(log
);
141 } catch(com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
142 log
.println("Exception creating relation :");
143 e
.printStackTrace(log
);
144 } catch(com
.sun
.star
.beans
.UnknownPropertyException e
) {
145 log
.println("Exception creating relation :");
146 e
.printStackTrace(log
);
147 } catch(com
.sun
.star
.beans
.PropertyVetoException e
) {
148 log
.println("Exception creating relation :");
149 e
.printStackTrace(log
);
150 } catch(com
.sun
.star
.lang
.IllegalArgumentException e
) {
151 log
.println("Exception creating relation :");
152 e
.printStackTrace(log
);
155 tEnv
.addObjRelation("EditOnly",
156 "This method is only supported if the Cell is in edit mode");
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 tEnv
.addObjRelation("XAccessibleText.Text", text
);
175 * Called while disposing a <code>TestEnvironment</code>.
176 * Disposes calc document.
177 * @param Param test parameters
178 * @param log writer to log information while testing
181 protected void cleanup( TestParameters Param
, PrintWriter log
) {
182 log
.println( " disposing xSheetDoc " );
183 XComponent oComp
= UnoRuntime
.queryInterface (XComponent
.class, xSpreadsheetDoc
) ;
184 util
.DesktopTools
.closeDoc(oComp
);