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
.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
.uno
.AnyConverter
;
42 import com
.sun
.star
.uno
.Type
;
43 import com
.sun
.star
.uno
.UnoRuntime
;
44 import com
.sun
.star
.uno
.XInterface
;
47 * Test for accessible object of spreadsheet document.<p>
48 * Object implements the following interfaces:
50 * <li> <code>::com::sun::star::accessibility::XAccessibleComponent</code>
52 * <li> <code>::com::sun::star::accessibility::XAccessibleContext</code>
54 * <li> <code>::com::sun::star::accessibility::XAccessibleSelection
56 * <li><code>::com::sun::star::accessibility::XAccessibleTable</code>
59 * @see com.sun.star.accessibility.XAccessibleComponent
60 * @see com.sun.star.accessibility.XAccessibleContext
61 * @see com.sun.star.accessibility.XAccessibleSelection
62 * @see com.sun.star.accessibility.XAccessibleTable
63 * @see ifc.accessibility._XAccessibleComponent
64 * @see ifc.accessibility._XAccessibleContext
65 * @see ifc.accessibility._XAccessibleSelection
66 * @see ifc.accessibility._XAccessibleTable
68 public class ScAccessibleSpreadsheet
extends TestCase
{
69 private XSpreadsheetDocument xSheetDoc
= null;
72 * Creates a spreadsheet document.
75 protected void initialize( TestParameters tParam
, PrintWriter log
) {
76 SOfficeFactory SOF
= SOfficeFactory
.getFactory( tParam
.getMSF() );
78 log
.println( "creating a Spreadsheet document" );
79 xSheetDoc
= SOF
.createCalcDoc(null);
80 } catch ( com
.sun
.star
.uno
.Exception e
) {
81 // Some exception occurs.FAILED
82 e
.printStackTrace( log
);
83 throw new StatusException( "Couldn't create document", e
);
88 * Disposes a spreadsheet document.
91 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
92 log
.println( " disposing xSheetDoc " );
93 XComponent oComp
= UnoRuntime
.queryInterface
94 (XComponent
.class, xSheetDoc
);
95 util
.DesktopTools
.closeDoc(oComp
);
100 * Creating a Testenvironment for the interfaces to be tested.
101 * Obtains the accessible object for the spreadsheet.
104 public synchronized TestEnvironment createTestEnvironment
105 ( TestParameters Param
, PrintWriter log
)
106 throws StatusException
{
108 XInterface oObj
= null;
110 XModel xModel
= UnoRuntime
.queryInterface(XModel
.class, xSheetDoc
);
112 XWindow xWindow
= AccessibilityTools
.getCurrentWindow(xModel
);
113 XAccessible xRoot
= AccessibilityTools
.getAccessibleObject(xWindow
);
115 oObj
= AccessibilityTools
.getAccessibleObjectForRole(xRoot
, AccessibleRole
.TABLE
);
117 log
.println("ImplementationName " + utils
.getImplName(oObj
));
119 TestEnvironment tEnv
= new TestEnvironment( oObj
);
121 // relation for XAccessibleEventBroadcaster
123 final String text
= "Text for testing of the interface XAccessibleText";
125 XSpreadsheets oSheets
= xSheetDoc
.getSheets() ;
126 XIndexAccess oIndexSheets
= UnoRuntime
.queryInterface(XIndexAccess
.class, oSheets
);
127 XSpreadsheet oSheet
= (XSpreadsheet
) AnyConverter
.toObject(
128 new Type(XSpreadsheet
.class),oIndexSheets
.getByIndex(0));
129 xCell
= oSheet
.getCellByPosition(5, 5) ;
130 xCell
.setFormula(text
);
131 } catch(com
.sun
.star
.lang
.WrappedTargetException e
) {
132 log
.println("Exception creating accessible text :");
133 e
.printStackTrace(log
);
134 } catch(com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
135 log
.println("Exception creating accessible text :");
136 e
.printStackTrace(log
);
137 } catch(com
.sun
.star
.lang
.IllegalArgumentException e
) {
138 log
.println("Exception creating accessible text :");
139 e
.printStackTrace(log
);
142 final XCell fCell
= xCell
;
144 tEnv
.addObjRelation("EventProducer",
145 new ifc
.accessibility
._XAccessibleEventBroadcaster
.EventProducer(){
146 public void fireEvent() {
147 fCell
.setFormula("firing event");
148 fCell
.setFormula(text
);