bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _sc / ScAccessibleCsvGrid.java
blobd8f12e4938465c060c1a7be48e3d155d293d140f
1 /*
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 .
19 package mod._sc;
21 import java.io.PrintWriter;
23 import lib.StatusException;
24 import lib.TestCase;
25 import lib.TestEnvironment;
26 import lib.TestParameters;
27 import util.AccessibilityTools;
28 import util.SOfficeFactory;
29 import util.utils;
31 import com.sun.star.accessibility.AccessibleRole;
32 import com.sun.star.accessibility.XAccessible;
33 import com.sun.star.accessibility.XAccessibleAction;
34 import com.sun.star.awt.XExtendedToolkit;
35 import com.sun.star.awt.XWindow;
36 import com.sun.star.beans.PropertyValue;
37 import com.sun.star.lang.XComponent;
38 import com.sun.star.lang.XMultiServiceFactory;
39 import com.sun.star.uno.UnoRuntime;
40 import com.sun.star.uno.XInterface;
42 public class ScAccessibleCsvGrid extends TestCase {
44 Thread lThread = null;
45 static XAccessibleAction accAction = null;
47 /**
48 * Called to create an instance of <code>TestEnvironment</code> with an
49 * object to test and related objects. Subclasses should implement this
50 * method to provide the implementation and related objects. The method is
51 * called from <code>getTestEnvironment()</code>.
53 * @param Param test parameters
54 * @param log writer to log information while testing
56 * @see TestEnvironment
57 * @see #getTestEnvironment
59 protected TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) {
61 XInterface oObj = null;
63 shortWait();
65 try {
66 oObj = (XInterface) ((XMultiServiceFactory)Param.getMSF()).createInstance
67 ("com.sun.star.awt.Toolkit") ;
68 } catch (com.sun.star.uno.Exception e) {
69 log.println("Couldn't get toolkit");
70 e.printStackTrace(log);
71 throw new StatusException("Couldn't get toolkit", e );
75 XExtendedToolkit tk = UnoRuntime.queryInterface(XExtendedToolkit.class,oObj);
78 XWindow xWindow = UnoRuntime.queryInterface(XWindow.class,tk.getActiveTopWindow());
80 XAccessible xRoot = AccessibilityTools.getAccessibleObject(xWindow);
82 oObj = AccessibilityTools.getAccessibleObjectForRole
83 (xRoot, AccessibleRole.PUSH_BUTTON, "Cancel");
85 accAction = UnoRuntime.queryInterface(XAccessibleAction.class, oObj);
87 /*int count = accAction.getAccessibleActionCount();
89 for (int i = 0; i<count; i++) {
90 try {
91 System.out.println(i+": "+accAction.getAccessibleActionDescription(i));
92 } catch (com.sun.star.lang.IndexOutOfBoundsException iae) {}
93 }*/
95 //util.dbg.printInterfaces(oObj);
97 //AccessibilityTools.printAccessibleTree(log, xRoot);
99 oObj = AccessibilityTools.getAccessibleObjectForRole
100 (xRoot, AccessibleRole.TABLE, true);
102 log.println("ImplementationName " + utils.getImplName(oObj));
104 TestEnvironment tEnv = new TestEnvironment(oObj);
106 return tEnv;
110 * Called while disposing a <code>TestEnvironment</code>.
111 * Disposes calc document.
112 * @param Param test parameters
113 * @param log writer to log information while testing
115 protected void cleanup( TestParameters Param, PrintWriter log) {
116 log.println( " closing Dialog " );
117 try {
118 accAction.doAccessibleAction(0);
119 } catch (com.sun.star.lang.IndexOutOfBoundsException iae) {
120 log.println("Couldn't close dialog");
125 * Called while the <code>TestCase</code> initialization. In the
126 * implementation does nothing. Subclasses can override to initialize
127 * objects shared among all <code>TestEnvironment</code>s.
129 * @param Param test parameters
130 * @param log writer to log information while testing
132 * @see #initializeTestCase
134 protected void initialize(TestParameters Param, PrintWriter log) {
135 // get a soffice factory object
136 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)Param.getMSF());
138 log.println("opening dialog");
140 PropertyValue[] args = new PropertyValue[1];
141 try {
142 args[0] = new PropertyValue();
143 args[0].Name = "InteractionHandler";
144 args[0].Value = ((XMultiServiceFactory)Param.getMSF()).createInstance(
145 "com.sun.star.comp.uui.UUIInteractionHandler");
146 } catch(com.sun.star.uno.Exception e) {
149 lThread = new loadThread(SOF, args);
150 lThread.start();
151 shortWait();
156 * Sleeps for 2 sec. to allow StarOffice to react on <code>
157 * reset</code> call.
159 private void shortWait() {
160 try {
161 Thread.sleep(2000) ;
162 } catch (InterruptedException e) {
163 log.println("While waiting :" + e) ;
167 public class loadThread extends Thread {
169 private SOfficeFactory SOF = null ;
170 private PropertyValue[] args = null;
171 public XComponent xSpreadSheedDoc = null;
173 public loadThread(SOfficeFactory SOF, PropertyValue[] Args) {
174 this.SOF = SOF;
175 this.args = Args;
178 public void run() {
179 try {
180 String url= utils.getFullTestURL("10test.csv");
181 log.println("loading "+url);
182 SOF.loadDocument(url,args);
183 } catch (com.sun.star.uno.Exception e) {
184 e.printStackTrace();
185 throw new StatusException( "Couldn't create document ", e );