Branch libreoffice-5-0-4
[LibreOffice.git] / qadevOOo / tests / java / mod / _sc / ScAccessibleCsvGrid.java
blob8fa3f4c458f868f80354fdb30d4264cdcc672cd5
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.uno.UnoRuntime;
38 import com.sun.star.uno.XInterface;
40 public class ScAccessibleCsvGrid extends TestCase {
42 Thread lThread = null;
43 static XAccessibleAction accAction = null;
45 /**
46 * Called to create an instance of <code>TestEnvironment</code> with an
47 * object to test and related objects. Subclasses should implement this
48 * method to provide the implementation and related objects. The method is
49 * called from <code>getTestEnvironment()</code>.
51 * @param Param test parameters
52 * @param log writer to log information while testing
54 * @see TestEnvironment
55 * @see #getTestEnvironment
57 @Override
58 protected TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) {
60 XInterface oObj = null;
62 util.utils.pause(2000);
64 try {
65 oObj = (XInterface) Param.getMSF().createInstance
66 ("com.sun.star.awt.Toolkit") ;
67 } catch (com.sun.star.uno.Exception e) {
68 log.println("Couldn't get toolkit");
69 e.printStackTrace(log);
70 throw new StatusException("Couldn't get toolkit", e );
74 XExtendedToolkit tk = UnoRuntime.queryInterface(XExtendedToolkit.class,oObj);
77 XWindow xWindow = UnoRuntime.queryInterface(XWindow.class,tk.getActiveTopWindow());
79 XAccessible xRoot = AccessibilityTools.getAccessibleObject(xWindow);
81 oObj = AccessibilityTools.getAccessibleObjectForRole
82 (xRoot, AccessibleRole.PUSH_BUTTON, "Cancel");
84 accAction = UnoRuntime.queryInterface(XAccessibleAction.class, oObj);
86 oObj = AccessibilityTools.getAccessibleObjectForRole
87 (xRoot, AccessibleRole.TABLE, true);
89 log.println("ImplementationName " + utils.getImplName(oObj));
91 TestEnvironment tEnv = new TestEnvironment(oObj);
93 return tEnv;
96 /**
97 * Called while disposing a <code>TestEnvironment</code>.
98 * Disposes calc document.
99 * @param Param test parameters
100 * @param log writer to log information while testing
102 @Override
103 protected void cleanup( TestParameters Param, PrintWriter log) {
104 log.println( " closing Dialog " );
105 try {
106 accAction.doAccessibleAction(0);
107 } catch (com.sun.star.lang.IndexOutOfBoundsException iae) {
108 log.println("Couldn't close dialog");
113 * Called while the <code>TestCase</code> initialization. In the
114 * implementation does nothing. Subclasses can override to initialize
115 * objects shared among all <code>TestEnvironment</code>s.
117 * @param Param test parameters
118 * @param log writer to log information while testing
120 * @see #initializeTestCase
122 @Override
123 protected void initialize(TestParameters Param, PrintWriter log) {
124 // get a soffice factory object
125 SOfficeFactory SOF = SOfficeFactory.getFactory( Param.getMSF());
127 log.println("opening dialog");
129 PropertyValue[] args = new PropertyValue[1];
130 try {
131 args[0] = new PropertyValue();
132 args[0].Name = "InteractionHandler";
133 args[0].Value = Param.getMSF().createInstance(
134 "com.sun.star.comp.uui.UUIInteractionHandler");
135 } catch(com.sun.star.uno.Exception e) {
138 lThread = new loadThread(SOF, args);
139 lThread.start();
140 util.utils.pause(2000);
144 private class loadThread extends Thread {
146 private final SOfficeFactory SOF;
147 private final PropertyValue[] args;
149 private loadThread(SOfficeFactory SOF, PropertyValue[] Args) {
150 this.SOF = SOF;
151 this.args = Args;
154 @Override
155 public void run() {
156 try {
157 String url= utils.getFullTestURL("10test.csv");
158 log.println("loading "+url);
159 SOF.loadDocument(url,args);
160 } catch (com.sun.star.uno.Exception e) {
161 e.printStackTrace();
162 throw new StatusException( "Couldn't create document ", e );