bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _sc / ScAccessibleCsvRuler.java
blobc43c8762ed53515f4f491a450ab4a92cfe6c06f3
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.accessibility.XAccessibleText;
36 import com.sun.star.awt.XExtendedToolkit;
37 import com.sun.star.awt.XWindow;
38 import com.sun.star.beans.PropertyValue;
39 import com.sun.star.lang.XComponent;
40 import com.sun.star.lang.XMultiServiceFactory;
41 import com.sun.star.uno.UnoRuntime;
42 import com.sun.star.uno.XInterface;
44 public class ScAccessibleCsvRuler extends TestCase {
46 Thread lThread = null;
47 static XAccessibleAction accAction = null;
49 /**
50 * Called to create an instance of <code>TestEnvironment</code> with an
51 * object to test and related objects. Subclasses should implement this
52 * method to provide the implementation and related objects. The method is
53 * called from <code>getTestEnvironment()</code>.
55 * @param Param test parameters
56 * @param log writer to log information while testing
58 * @see TestEnvironment
59 * @see #getTestEnvironment
61 protected TestEnvironment createTestEnvironment(TestParameters Param,
62 PrintWriter log) {
63 XInterface oObj = null;
65 shortWait();
67 XMultiServiceFactory msf = (XMultiServiceFactory) Param.getMSF();
69 try {
70 oObj = (XInterface) msf.createInstance("com.sun.star.awt.Toolkit");
71 } catch (com.sun.star.uno.Exception e) {
72 log.println("Couldn't get toolkit");
73 e.printStackTrace(log);
74 throw new StatusException("Couldn't get toolkit", e);
77 XExtendedToolkit tk = UnoRuntime.queryInterface(
78 XExtendedToolkit.class, oObj);
80 XWindow xWindow = UnoRuntime.queryInterface(XWindow.class,
81 tk.getActiveTopWindow());
83 XAccessible xRoot = AccessibilityTools.getAccessibleObject(xWindow);
85 oObj = AccessibilityTools.getAccessibleObjectForRole(xRoot, AccessibleRole.PUSH_BUTTON,
86 "Cancel");
88 accAction = UnoRuntime.queryInterface(
89 XAccessibleAction.class, oObj);
91 XAccessibleContext acc = AccessibilityTools.getAccessibleObjectForRole(xRoot,
92 AccessibleRole.RADIO_BUTTON);
94 log.println("Click on: " + acc.getAccessibleName());
96 XAccessibleAction accAction2 = UnoRuntime.queryInterface(
97 XAccessibleAction.class, acc);
99 try {
100 accAction2.doAccessibleAction(0);
101 } catch (com.sun.star.lang.IndexOutOfBoundsException iae) {
105 //util.dbg.printInterfaces(oObj);
106 AccessibilityTools.printAccessibleTree(log, xRoot);
107 oObj = AccessibilityTools.getAccessibleObjectForRole(xRoot, AccessibleRole.TEXT,
108 "Ruler", true);
110 log.println("ImplementationName " + utils.getImplName(oObj));
112 TestEnvironment tEnv = new TestEnvironment(oObj);
114 tEnv.addObjRelation("EditOnly",
115 "This method isn't supported in this dialog");
117 XAccessibleText text = UnoRuntime.queryInterface(
118 XAccessibleText.class, oObj);
120 int lastone = 100;
122 for (int i = 0; i < 1000; i++) {
123 try {
124 text.getCharacterBounds(i);
125 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
126 lastone = i - 1;
128 break;
132 tEnv.addObjRelation("LimitedBounds", new Integer(lastone));
133 tEnv.addObjRelation("PreviousUsed",new int[]{11,22,33,44,55,66,77,88,99});
135 return tEnv;
139 * Called while disposing a <code>TestEnvironment</code>.
140 * Disposes calc document.
141 * @param Param test parameters
142 * @param log writer to log information while testing
144 protected void cleanup( TestParameters Param, PrintWriter log) {
145 /* log.println( " closing Dialog " );
146 try {
147 accAction.doAccessibleAction(0);
148 } catch (com.sun.star.lang.IndexOutOfBoundsException iae) {
149 log.println("Couldn't close dialog");
150 } */
154 * Called while the <code>TestCase</code> initialization. In the
155 * implementation does nothing. Subclasses can override to initialize
156 * objects shared among all <code>TestEnvironment</code>s.
158 * @param Param test parameters
159 * @param log writer to log information while testing
161 * @see #initializeTestCase
163 protected void initialize(TestParameters Param, PrintWriter log) {
164 // get a soffice factory object
165 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)Param.getMSF());
167 log.println("opening dialog");
169 PropertyValue[] args = new PropertyValue[1];
170 try {
171 args[0] = new PropertyValue();
172 args[0].Name = "InteractionHandler";
173 args[0].Value = ((XMultiServiceFactory)Param.getMSF()).createInstance(
174 "com.sun.star.comp.uui.UUIInteractionHandler");
175 } catch(com.sun.star.uno.Exception e) {
178 lThread = new loadThread(SOF, args);
179 lThread.start();
180 shortWait();
185 * Sleeps for 2 sec. to allow StarOffice to react on <code>
186 * reset</code> call.
188 private void shortWait() {
189 try {
190 Thread.sleep(2000) ;
191 } catch (InterruptedException e) {
192 log.println("While waiting :" + e) ;
196 public class loadThread extends Thread {
198 private SOfficeFactory SOF = null ;
199 private PropertyValue[] args = null;
200 public XComponent xSpreadSheedDoc = null;
202 public loadThread(SOfficeFactory SOF, PropertyValue[] Args) {
203 this.SOF = SOF;
204 this.args = Args;
207 public void run() {
208 try {
209 String url= utils.getFullTestURL("10test.csv");
210 log.println("loading "+url);
211 SOF.loadDocument(url,args);
212 } catch (com.sun.star.uno.Exception e) {
213 e.printStackTrace();
214 throw new StatusException( "Couldn't create document ", e );