Branch libreoffice-5-0-4
[LibreOffice.git] / qadevOOo / tests / java / mod / _sc / ScAccessibleCsvRuler.java
blobd41103abad15d0418b834cec9a96f1c7e6c0c657
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.XMultiServiceFactory;
40 import com.sun.star.uno.UnoRuntime;
41 import com.sun.star.uno.XInterface;
43 public class ScAccessibleCsvRuler 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 Param test parameters
55 * @param log writer to log information while testing
57 * @see TestEnvironment
58 * @see #getTestEnvironment
60 @Override
61 protected TestEnvironment createTestEnvironment(TestParameters Param,
62 PrintWriter log) {
63 XInterface oObj = null;
65 util.utils.pause(2000);
67 XMultiServiceFactory msf = 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 AccessibilityTools.printAccessibleTree(log, xRoot);
106 oObj = AccessibilityTools.getAccessibleObjectForRole(xRoot, AccessibleRole.TEXT,
107 "Ruler", true);
109 log.println("ImplementationName " + utils.getImplName(oObj));
111 TestEnvironment tEnv = new TestEnvironment(oObj);
113 tEnv.addObjRelation("EditOnly",
114 "This method isn't supported in this dialog");
116 XAccessibleText text = UnoRuntime.queryInterface(
117 XAccessibleText.class, oObj);
119 int lastone = 100;
121 for (int i = 0; i < 1000; i++) {
122 try {
123 text.getCharacterBounds(i);
124 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
125 lastone = i - 1;
127 break;
131 tEnv.addObjRelation("LimitedBounds", Integer.valueOf(lastone));
132 tEnv.addObjRelation("PreviousUsed",new int[]{11,22,33,44,55,66,77,88,99});
134 return tEnv;
138 * Called while disposing a <code>TestEnvironment</code>.
139 * Disposes calc document.
140 * @param Param test parameters
141 * @param log writer to log information while testing
143 @Override
144 protected void cleanup( TestParameters Param, PrintWriter log) {
148 * Called while the <code>TestCase</code> initialization. In the
149 * implementation does nothing. Subclasses can override to initialize
150 * objects shared among all <code>TestEnvironment</code>s.
152 * @param Param test parameters
153 * @param log writer to log information while testing
155 * @see #initializeTestCase
157 @Override
158 protected void initialize(TestParameters Param, PrintWriter log) {
159 // get a soffice factory object
160 SOfficeFactory SOF = SOfficeFactory.getFactory( Param.getMSF());
162 log.println("opening dialog");
164 PropertyValue[] args = new PropertyValue[1];
165 try {
166 args[0] = new PropertyValue();
167 args[0].Name = "InteractionHandler";
168 args[0].Value = Param.getMSF().createInstance(
169 "com.sun.star.comp.uui.UUIInteractionHandler");
170 } catch(com.sun.star.uno.Exception e) {
173 lThread = new loadThread(SOF, args);
174 lThread.start();
175 util.utils.pause(2000);
179 private class loadThread extends Thread {
181 private final SOfficeFactory SOF;
182 private final PropertyValue[] args;
184 private loadThread(SOfficeFactory SOF, PropertyValue[] Args) {
185 this.SOF = SOF;
186 this.args = Args;
189 @Override
190 public void run() {
191 try {
192 String url= utils.getFullTestURL("10test.csv");
193 log.println("loading "+url);
194 SOF.loadDocument(url,args);
195 } catch (com.sun.star.uno.Exception e) {
196 e.printStackTrace();
197 throw new StatusException( "Couldn't create document ", e );