1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ScAccessibleCsvRuler.java,v $
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 ************************************************************************/
33 import java
.io
.PrintWriter
;
35 import lib
.StatusException
;
37 import lib
.TestEnvironment
;
38 import lib
.TestParameters
;
39 import util
.AccessibilityTools
;
40 import util
.SOfficeFactory
;
43 import com
.sun
.star
.accessibility
.AccessibleRole
;
44 import com
.sun
.star
.accessibility
.XAccessible
;
45 import com
.sun
.star
.accessibility
.XAccessibleAction
;
46 import com
.sun
.star
.accessibility
.XAccessibleContext
;
47 import com
.sun
.star
.accessibility
.XAccessibleText
;
48 import com
.sun
.star
.awt
.XExtendedToolkit
;
49 import com
.sun
.star
.awt
.XWindow
;
50 import com
.sun
.star
.beans
.PropertyValue
;
51 import com
.sun
.star
.lang
.XComponent
;
52 import com
.sun
.star
.lang
.XMultiServiceFactory
;
53 import com
.sun
.star
.uno
.UnoRuntime
;
54 import com
.sun
.star
.uno
.XInterface
;
56 public class ScAccessibleCsvRuler
extends TestCase
{
58 Thread lThread
= null;
59 static XAccessibleAction accAction
= null;
62 * Called to create an instance of <code>TestEnvironment</code> with an
63 * object to test and related objects. Subclasses should implement this
64 * method to provide the implementation and related objects. The method is
65 * called from <code>getTestEnvironment()</code>.
67 * @param tParam test parameters
68 * @param log writer to log information while testing
70 * @see TestEnvironment
71 * @see #getTestEnvironment()
73 protected TestEnvironment
createTestEnvironment(TestParameters Param
,
75 XInterface oObj
= null;
79 XMultiServiceFactory msf
= (XMultiServiceFactory
) Param
.getMSF();
82 oObj
= (XInterface
) msf
.createInstance("com.sun.star.awt.Toolkit");
83 } catch (com
.sun
.star
.uno
.Exception e
) {
84 log
.println("Couldn't get toolkit");
85 e
.printStackTrace(log
);
86 throw new StatusException("Couldn't get toolkit", e
);
89 XExtendedToolkit tk
= (XExtendedToolkit
) UnoRuntime
.queryInterface(
90 XExtendedToolkit
.class, oObj
);
92 XWindow xWindow
= (XWindow
) UnoRuntime
.queryInterface(XWindow
.class,
93 tk
.getActiveTopWindow());
95 XAccessible xRoot
= AccessibilityTools
.getAccessibleObject(xWindow
);
97 oObj
= AccessibilityTools
.getAccessibleObjectForRole(xRoot
, AccessibleRole
.PUSH_BUTTON
,
100 accAction
= (XAccessibleAction
) UnoRuntime
.queryInterface(
101 XAccessibleAction
.class, oObj
);
103 XAccessibleContext acc
= AccessibilityTools
.getAccessibleObjectForRole(xRoot
,
104 AccessibleRole
.RADIO_BUTTON
);
106 log
.println("Click on: " + acc
.getAccessibleName());
108 XAccessibleAction accAction2
= (XAccessibleAction
) UnoRuntime
.queryInterface(
109 XAccessibleAction
.class, acc
);
112 accAction2
.doAccessibleAction(0);
113 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException iae
) {
117 //util.dbg.printInterfaces(oObj);
118 AccessibilityTools
.printAccessibleTree(log
, xRoot
);
119 oObj
= AccessibilityTools
.getAccessibleObjectForRole(xRoot
, AccessibleRole
.TEXT
,
122 log
.println("ImplementationName " + utils
.getImplName(oObj
));
124 TestEnvironment tEnv
= new TestEnvironment(oObj
);
126 tEnv
.addObjRelation("EditOnly",
127 "This method isn't supported in this dialog");
129 XAccessibleText text
= (XAccessibleText
) UnoRuntime
.queryInterface(
130 XAccessibleText
.class, oObj
);
134 for (int i
= 0; i
< 1000; i
++) {
136 text
.getCharacterBounds(i
);
137 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
144 tEnv
.addObjRelation("LimitedBounds", new Integer(lastone
));
145 tEnv
.addObjRelation("PreviousUsed",new int[]{11,22,33,44,55,66,77,88,99});
151 * Called while disposing a <code>TestEnvironment</code>.
152 * Disposes calc document.
153 * @param tParam test parameters
154 * @param tEnv the environment to cleanup
155 * @param log writer to log information while testing
157 protected void cleanup( TestParameters Param
, PrintWriter log
) {
158 /* log.println( " closing Dialog " );
160 accAction.doAccessibleAction(0);
161 } catch (com.sun.star.lang.IndexOutOfBoundsException iae) {
162 log.println("Couldn't close dialog");
167 * Called while the <code>TestCase</code> initialization. In the
168 * implementation does nothing. Subclasses can override to initialize
169 * objects shared among all <code>TestEnvironment</code>s.
171 * @param tParam test parameters
172 * @param log writer to log information while testing
174 * @see #initializeTestCase()
176 protected void initialize(TestParameters Param
, PrintWriter log
) {
177 // get a soffice factory object
178 SOfficeFactory SOF
= SOfficeFactory
.getFactory( (XMultiServiceFactory
)Param
.getMSF());
180 log
.println("opening dialog");
182 PropertyValue
[] args
= new PropertyValue
[1];
184 args
[0] = new PropertyValue();
185 args
[0].Name
= "InteractionHandler";
186 args
[0].Value
= ((XMultiServiceFactory
)Param
.getMSF()).createInstance(
187 "com.sun.star.comp.uui.UUIInteractionHandler");
188 } catch(com
.sun
.star
.uno
.Exception e
) {
191 lThread
= new loadThread(SOF
, args
);
198 * Sleeps for 2 sec. to allow StarOffice to react on <code>
201 private void shortWait() {
204 } catch (InterruptedException e
) {
205 log
.println("While waiting :" + e
) ;
209 public class loadThread
extends Thread
{
211 private SOfficeFactory SOF
= null ;
212 private PropertyValue
[] args
= null;
213 public XComponent xSpreadSheedDoc
= null;
215 public loadThread(SOfficeFactory SOF
, PropertyValue
[] Args
) {
222 String url
= utils
.getFullTestURL("10test.csv");
223 log
.println("loading "+url
);
224 SOF
.loadDocument(url
,args
);
225 } catch (com
.sun
.star
.uno
.Exception e
) {
227 throw new StatusException( "Couldn't create document ", e
);