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
) throws Exception
{
76 SOfficeFactory SOF
= SOfficeFactory
.getFactory( tParam
.getMSF() );
77 log
.println( "creating a Spreadsheet document" );
78 xSheetDoc
= SOF
.createCalcDoc(null);
82 * Disposes a spreadsheet document.
85 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
86 log
.println( " disposing xSheetDoc " );
87 XComponent oComp
= UnoRuntime
.queryInterface
88 (XComponent
.class, xSheetDoc
);
89 util
.DesktopTools
.closeDoc(oComp
);
94 * Creating a TestEnvironment for the interfaces to be tested.
95 * Obtains the accessible object for the spreadsheet.
98 public TestEnvironment createTestEnvironment
99 ( TestParameters Param
, PrintWriter log
)
100 throws StatusException
{
102 XInterface oObj
= null;
104 XModel xModel
= UnoRuntime
.queryInterface(XModel
.class, xSheetDoc
);
106 XWindow xWindow
= AccessibilityTools
.getCurrentWindow(xModel
);
107 XAccessible xRoot
= AccessibilityTools
.getAccessibleObject(xWindow
);
109 oObj
= AccessibilityTools
.getAccessibleObjectForRole(xRoot
, AccessibleRole
.TABLE
);
111 log
.println("ImplementationName " + utils
.getImplName(oObj
));
113 TestEnvironment tEnv
= new TestEnvironment( oObj
);
115 // relation for XAccessibleEventBroadcaster
117 final String text
= "Text for testing of the interface XAccessibleText";
119 XSpreadsheets oSheets
= xSheetDoc
.getSheets() ;
120 XIndexAccess oIndexSheets
= UnoRuntime
.queryInterface(XIndexAccess
.class, oSheets
);
121 XSpreadsheet oSheet
= (XSpreadsheet
) AnyConverter
.toObject(
122 new Type(XSpreadsheet
.class),oIndexSheets
.getByIndex(0));
123 xCell
= oSheet
.getCellByPosition(5, 5) ;
124 xCell
.setFormula(text
);
125 } catch(com
.sun
.star
.lang
.WrappedTargetException e
) {
126 log
.println("Exception creating accessible text :");
127 e
.printStackTrace(log
);
128 } catch(com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
129 log
.println("Exception creating accessible text :");
130 e
.printStackTrace(log
);
131 } catch(com
.sun
.star
.lang
.IllegalArgumentException e
) {
132 log
.println("Exception creating accessible text :");
133 e
.printStackTrace(log
);
136 final XCell fCell
= xCell
;
138 tEnv
.addObjRelation("EventProducer",
139 new ifc
.accessibility
._XAccessibleEventBroadcaster
.EventProducer(){
140 public void fireEvent() {
141 fCell
.setFormula("firing event");
142 fCell
.setFormula(text
);