bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _sc / ScAccessibleCsvCell.java
blob72199eef0bf1d526f52b5b86ab2a03fba6151dbe
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.accessibility.XAccessibleContext;
35 import com.sun.star.awt.XExtendedToolkit;
36 import com.sun.star.awt.XWindow;
37 import com.sun.star.beans.PropertyValue;
38 import com.sun.star.lang.XComponent;
39 import com.sun.star.lang.XMultiServiceFactory;
40 import com.sun.star.uno.UnoRuntime;
41 import com.sun.star.uno.XInterface;
43 public class ScAccessibleCsvCell extends TestCase {
45 Thread lThread = null;
46 static XAccessibleAction accAction = null;
48 /**
49 * Called to create an instance of <code>TestEnvironment</code> with an
50 * object to test and related objects. Subclasses should implement this
51 * method to provide the implementation and related objects. The method is
52 * called from <code>getTestEnvironment()</code>.
54 * @param tParam test parameters
55 * @param log writer to log information while testing
57 * @see TestEnvironment
58 * @see #getTestEnvironment
60 protected TestEnvironment createTestEnvironment(TestParameters tParam, PrintWriter log) {
61 XInterface oObj = null;
63 shortWait();
65 try {
66 oObj = (XInterface) ((XMultiServiceFactory)tParam.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);
77 XWindow xWindow = UnoRuntime.queryInterface(XWindow.class,tk.getActiveTopWindow());
79 XAccessible xRoot = AccessibilityTools.getAccessibleObject(xWindow);
81 AccessibilityTools.printAccessibleTree(log, xRoot, tParam.getBool(util.PropertyName.DEBUG_IS_ACTIVE));
82 oObj = AccessibilityTools.getAccessibleObjectForRole
83 (xRoot, AccessibleRole.PUSH_BUTTON, "Cancel");
85 accAction = UnoRuntime.queryInterface(XAccessibleAction.class, oObj);
87 oObj = AccessibilityTools.getAccessibleObjectForRole
88 (xRoot, AccessibleRole.TABLE, true);
90 //util.dbg.printInterfaces(oObj);
92 XAccessibleContext cont = UnoRuntime.queryInterface(XAccessibleContext.class, oObj);
94 String name = "";
95 try {
96 XAccessible acc = cont.getAccessibleChild(3);
97 name = acc.getAccessibleContext().getAccessibleName();
98 log.println("Child: "+ name);
99 log.println("ImplementationName " + utils.getImplName(acc));
100 oObj = acc;
102 catch(com.sun.star.lang.IndexOutOfBoundsException e) {}
104 TestEnvironment tEnv = new TestEnvironment(oObj);
106 tEnv.addObjRelation("EditOnly",
107 "This method isn't supported in this dialog");
109 tEnv.addObjRelation("XAccessibleText.Text", name);
111 return tEnv;
115 * Called while disposing a <code>TestEnvironment</code>.
116 * Disposes calc document.
117 * @param Param test parameters
118 * @param log writer to log information while testing
120 protected void cleanup( TestParameters Param, PrintWriter log) {
121 log.println( " closing Dialog " );
122 try {
123 accAction.doAccessibleAction(0);
124 } catch (com.sun.star.lang.IndexOutOfBoundsException iae) {
125 log.println("Couldn't close dialog");
130 * Called while the <code>TestCase</code> initialization. In the
131 * implementation does nothing. Subclasses can override to initialize
132 * objects shared among all <code>TestEnvironment</code>s.
134 * @param Param test parameters
135 * @param log writer to log information while testing
137 * @see #initializeTestCase
139 protected void initialize(TestParameters Param, PrintWriter log) {
140 // get a soffice factory object
141 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)Param.getMSF());
143 log.println("opening dialog");
145 PropertyValue[] args = new PropertyValue[1];
146 try {
147 args[0] = new PropertyValue();
148 args[0].Name = "InteractionHandler";
149 args[0].Value = ((XMultiServiceFactory)Param.getMSF()).createInstance(
150 "com.sun.star.comp.uui.UUIInteractionHandler");
151 } catch(com.sun.star.uno.Exception e) {
154 lThread = new loadThread(SOF, args);
155 lThread.start();
156 shortWait();
160 * Sleeps for 2 sec. to allow StarOffice to react on <code>
161 * reset</code> call.
163 private void shortWait() {
164 try {
165 Thread.sleep(2000) ;
166 } catch (InterruptedException e) {
167 log.println("While waiting :" + e) ;
171 public class loadThread extends Thread {
173 private SOfficeFactory SOF = null ;
174 private PropertyValue[] args = null;
175 public XComponent xSpreadSheedDoc = null;
177 public loadThread(SOfficeFactory SOF, PropertyValue[] Args) {
178 this.SOF = SOF;
179 this.args = Args;
182 public void run() {
183 try {
184 String url= utils.getFullTestURL("10test.csv");
185 log.println("loading "+url);
186 SOF.loadDocument(url,args);
187 } catch (com.sun.star.uno.Exception e) {
188 e.printStackTrace();
189 throw new StatusException( "Couldn't create document ", e );