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
;
24 import lib
.TestEnvironment
;
25 import lib
.TestParameters
;
26 import util
.AccessibilityTools
;
27 import util
.SOfficeFactory
;
30 import com
.sun
.star
.accessibility
.AccessibleRole
;
31 import com
.sun
.star
.accessibility
.XAccessible
;
32 import com
.sun
.star
.awt
.XWindow
;
33 import com
.sun
.star
.beans
.XPropertySet
;
34 import com
.sun
.star
.container
.XIndexAccess
;
35 import com
.sun
.star
.frame
.XModel
;
36 import com
.sun
.star
.lang
.XComponent
;
37 import com
.sun
.star
.sheet
.XSpreadsheet
;
38 import com
.sun
.star
.sheet
.XSpreadsheetDocument
;
39 import com
.sun
.star
.sheet
.XSpreadsheets
;
40 import com
.sun
.star
.table
.XCell
;
41 import com
.sun
.star
.table
.XColumnRowRange
;
42 import com
.sun
.star
.table
.XTableColumns
;
43 import com
.sun
.star
.uno
.AnyConverter
;
44 import com
.sun
.star
.uno
.Type
;
45 import com
.sun
.star
.uno
.UnoRuntime
;
46 import com
.sun
.star
.uno
.XInterface
;
49 * Test for object which is represented by accessible component of
50 * a cell in the spreadsheet. <p>
51 * Object implements the following interfaces :
53 * <li> <code>::com::sun::star::accessibility::XAccessibleSelection</code></li>
54 * <li> <code>::com::sun::star::accessibility::XAccessibleEventBroadcaster</code></li>
55 * <li> <code>::com::sun::star::accessibility::XAccessibleComponent</code></li>
56 * <li> <code>::com::sun::star::accessibility::XAccessibleTable</code></li>
57 * <li> <code>::com::sun::star::accessibility::XAccessibleContext</code></li>
60 * @see com.sun.star.accessibility.XAccessibleSelection
61 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
62 * @see com.sun.star.accessibility.XAccessibleComponent
63 * @see com.sun.star.accessibility.XAccessibleTable
64 * @see com.sun.star.accessibility.XAccessibleContext
65 * @see ifc.accessibility._XAccessibleSelection
66 * @see ifc.accessibility._XAccessibleEventBroadcaster
67 * @see ifc.accessibility._XAccessibleComponent
68 * @see ifc.accessibility._XAccessibleTable
69 * @see ifc.accessibility._XAccessibleContext
71 public class ScAccessibleCell
extends TestCase
{
73 private XSpreadsheetDocument xSpreadsheetDoc
= null;
76 * Called to create an instance of <code>TestEnvironment</code>
77 * with an object to test and related objects.
78 * Switches the document to Print Preview mode.
79 * Obtains accessible object for the page view.
81 * @param Param test parameters
82 * @param log writer to log information while testing
84 * @see TestEnvironment
85 * @see #getTestEnvironment
88 protected TestEnvironment
createTestEnvironment(
89 TestParameters Param
, PrintWriter log
) throws Exception
{
91 // get a soffice factory object
92 SOfficeFactory SOF
= SOfficeFactory
.getFactory( Param
.getMSF());
94 log
.println("creating a spreadsheetdocument");
95 xSpreadsheetDoc
= SOF
.createCalcDoc(null);
97 XInterface oObj
= null;
99 XModel aModel
= UnoRuntime
.queryInterface(XModel
.class, xSpreadsheetDoc
);
101 XWindow xWindow
= AccessibilityTools
.getCurrentWindow(aModel
);
102 XAccessible xRoot
= AccessibilityTools
.getAccessibleObject(xWindow
);
104 oObj
= AccessibilityTools
.getAccessibleObjectForRole
105 (xRoot
, AccessibleRole
.TABLE_CELL
, "B1");
107 log
.println("ImplementationName " + utils
.getImplName(oObj
));
109 TestEnvironment tEnv
= new TestEnvironment(oObj
);
111 // relation for XAccessibleEventBroadcaster
113 final String text
= "XAccessibleText";
115 XSpreadsheets oSheets
= xSpreadsheetDoc
.getSheets() ;
116 XIndexAccess oIndexSheets
= UnoRuntime
.queryInterface(XIndexAccess
.class, oSheets
);
117 XSpreadsheet oSheet
= (XSpreadsheet
) AnyConverter
.toObject(
118 new Type(XSpreadsheet
.class),oIndexSheets
.getByIndex(0));
119 xCell
= oSheet
.getCellByPosition(1, 0) ;
120 xCell
.setFormula(text
);
121 XColumnRowRange oColumnRowRange
= UnoRuntime
.queryInterface(XColumnRowRange
.class, oSheet
);
122 XTableColumns oColumns
= oColumnRowRange
.getColumns();
123 XIndexAccess oIndexAccess
= UnoRuntime
.queryInterface(XIndexAccess
.class, oColumns
);
124 XPropertySet column
= UnoRuntime
.queryInterface(
125 XPropertySet
.class,oIndexAccess
.getByIndex(1));
126 column
.setPropertyValue("OptimalWidth", Boolean
.TRUE
);
127 } catch(com
.sun
.star
.lang
.WrappedTargetException e
) {
128 log
.println("Exception creating relation :");
129 e
.printStackTrace(log
);
130 } catch(com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
131 log
.println("Exception creating relation :");
132 e
.printStackTrace(log
);
133 } catch(com
.sun
.star
.beans
.UnknownPropertyException e
) {
134 log
.println("Exception creating relation :");
135 e
.printStackTrace(log
);
136 } catch(com
.sun
.star
.beans
.PropertyVetoException e
) {
137 log
.println("Exception creating relation :");
138 e
.printStackTrace(log
);
139 } catch(com
.sun
.star
.lang
.IllegalArgumentException e
) {
140 log
.println("Exception creating relation :");
141 e
.printStackTrace(log
);
144 tEnv
.addObjRelation("EditOnly",
145 "This method is only supported if the Cell is in edit mode");
147 final XCell fCell
= xCell
;
149 tEnv
.addObjRelation("EventProducer",
150 new ifc
.accessibility
._XAccessibleEventBroadcaster
.EventProducer(){
151 public void fireEvent() {
152 fCell
.setFormula("firing event");
153 fCell
.setFormula(text
);
157 tEnv
.addObjRelation("XAccessibleText.Text", text
);
164 * Called while disposing a <code>TestEnvironment</code>.
165 * Disposes calc document.
166 * @param Param test parameters
167 * @param log writer to log information while testing
170 protected void cleanup( TestParameters Param
, PrintWriter log
) {
171 log
.println( " disposing xSheetDoc " );
172 XComponent oComp
= UnoRuntime
.queryInterface (XComponent
.class, xSpreadsheetDoc
) ;
173 util
.DesktopTools
.closeDoc(oComp
);