tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / qadevOOo / tests / java / ifc / ui / dialogs / _XFilePickerNotifier.java
blob54858bfcf1066211aa1eb43a0135aad0db21a354
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 ifc.ui.dialogs;
21 import lib.MultiMethodTest;
22 import lib.Status;
23 import lib.StatusException;
25 import com.sun.star.lang.EventObject;
26 import com.sun.star.ui.dialogs.FilePickerEvent;
27 import com.sun.star.ui.dialogs.XExecutableDialog;
28 import com.sun.star.ui.dialogs.XFilePicker;
29 import com.sun.star.ui.dialogs.XFilePickerListener;
30 import com.sun.star.ui.dialogs.XFilePickerNotifier;
31 import com.sun.star.uno.UnoRuntime;
32 import com.sun.star.util.XCancellable;
35 /**
36 * Testing <code>com.sun.star.ui.XFilePickerNotifier</code>
37 * interface methods :
38 * <ul>
39 * <li><code> addFilePickerListener()</code></li>
40 * <li><code> removeFilePickerListener()</code></li>
41 * </ul> <p>
42 * The object must implement <code>XFilePicker</code>
43 * interface to check if a listener was called. <p>
44 * Test is <b> NOT </b> multithread compliant. <p>
45 * @see com.sun.star.ui.XFilePickerNotifier
47 public class _XFilePickerNotifier extends MultiMethodTest {
49 public XFilePickerNotifier oObj = null;
50 private XFilePicker fps = null ;
51 private String dir1 = null,
52 dir2 = null ;
53 ExecThread eThread = null;
56 /**
57 * Listener implementation which sets a flag if some of its
58 * methods was called.
60 protected class TestListener implements XFilePickerListener {
61 public boolean called = false ;
63 public void dialogSizeChanged() {
64 called = true;
67 public void fileSelectionChanged(FilePickerEvent e) {
68 called = true;
71 public void directoryChanged(FilePickerEvent e) {
72 log.println("***** Directory Changed *****");
73 called = true;
76 public String helpRequested(FilePickerEvent e) {
77 called = true;
78 return "help";
81 public void controlStateChanged(FilePickerEvent e) {
82 called = true;
85 public void disposing(EventObject e) {}
88 TestListener listener = new TestListener() ;
90 /**
91 * Tries to query object for <code>XFilePicker</code> interface, and
92 * initializes two different URLs for changing file picker directory. <p>
93 * @throw StatusException If object doesn't support <code>XFilePicker</code>
94 * interface.
96 @Override
97 public void before() {
98 fps = UnoRuntime.queryInterface
99 (XFilePicker.class, oObj) ;
101 if (fps == null) {
102 log.println("The object doesn't implement XFilePicker") ;
103 throw new StatusException(Status.failed
104 ("The object doesn't implement XFilePicker"));
107 XExecutableDialog exD = UnoRuntime.queryInterface(
108 XExecutableDialog.class, tEnv.getTestObject());
110 dir1 = util.utils.getOfficeTemp(tParam.getMSF());
111 dir2 = util.utils.getFullTestURL("");
112 eThread = new ExecThread(exD);
116 * Adds a listener, then tries to change display directory and
117 * checks if the listener was called. <p>
118 * Has <b>OK</b> status if a listener method was called.
120 public void _addFilePickerListener() {
121 oObj.addFilePickerListener(listener) ;
123 try {
124 log.println("***** Setting DisplayDirectory to " + dir1);
125 fps.setDisplayDirectory(dir1) ;
126 log.println("***** Getting: " + fps.getDisplayDirectory());
127 openDialog();
128 log.println("***** Setting DisplayDirectory to " + dir2);
129 fps.setDisplayDirectory(dir2) ;
130 log.println("***** Getting: " + fps.getDisplayDirectory());
132 } catch(com.sun.star.lang.IllegalArgumentException e) {
133 log.println("!!! Exception changing dir !!!") ;
134 e.printStackTrace(log) ;
137 waitForEventIdle();
139 if (!listener.called) {
140 log.println("Listener wasn't called :-(");
143 closeDialog();
145 tRes.tested("addFilePickerListener()", listener.called) ;
149 * Removes the listener and changes display directory. <p>
150 * Has <b>OK</b> status if the listener wasn't called. <p>
151 * The following method tests are to be completed successfully before :
152 * <ul>
153 * <li> <code> addFilePickerListener </code> </li>
154 * </ul>
156 public void _removeFilePickerListener() {
157 requiredMethod("addFilePickerListener()") ;
159 oObj.removeFilePickerListener(listener) ;
161 listener.called = false ;
163 try {
164 fps.setDisplayDirectory(dir1) ;
165 openDialog();
166 fps.setDisplayDirectory(dir2) ;
167 } catch(com.sun.star.lang.IllegalArgumentException e) {
168 log.println("!!! Exception changing dir !!!") ;
169 e.printStackTrace(log) ;
172 waitForEventIdle();
174 closeDialog();
176 tRes.tested("removeFilePickerListener()", !listener.called) ;
180 * Calls <code>execute()</code> method in a separate thread.
181 * Necessary to check if this method works
183 protected class ExecThread extends Thread {
185 public short execRes = (short) 17 ;
186 private final XExecutableDialog Diag;
188 public ExecThread(XExecutableDialog Diag) {
189 this.Diag = Diag ;
192 @Override
193 public void run() {
194 try {
195 execRes = Diag.execute();
196 System.out.println("HERE: "+execRes);
197 } catch (Exception e) {
198 log.println("Thread has been interrupted ...");
203 private void closeDialog() {
204 XCancellable canc = UnoRuntime.queryInterface(
205 XCancellable.class, tEnv.getTestObject());
206 if (canc != null) {
207 log.println("Cancelling Dialog");
208 canc.cancel();
209 } else {
210 this.disposeEnvironment();
213 long st = System.currentTimeMillis();
214 boolean toLong = false;
216 log.println("waiting for dialog to close");
218 while (eThread.isAlive() && !toLong) {
219 //wait for dialog to close
220 toLong = (System.currentTimeMillis()-st > 10000);
223 log.println("done");
225 try {
226 if (eThread.isAlive()) {
227 log.println("Interrupting Thread");
228 eThread.interrupt();
229 Thread.yield();
231 } catch (Exception e) {
232 // who cares ;-)
235 st = System.currentTimeMillis();
236 toLong = false;
238 log.println("waiting for interruption to work");
240 while (eThread.isAlive() && !toLong) {
241 //wait for dialog to close
242 toLong = (System.currentTimeMillis()-st > 10000);
245 log.println("DialogThread alive: "+eThread.isAlive());
247 log.println("done");
251 private void openDialog() {
252 log.println("Starting Dialog");
253 if (eThread.isAlive()) {
254 log.println("second interrupt");
255 eThread.interrupt();
256 Thread.yield();
259 XExecutableDialog exD = UnoRuntime.queryInterface(
260 XExecutableDialog.class, tEnv.getTestObject());
262 dir1 = util.utils.getOfficeTemp(tParam.getMSF());
263 dir2 = util.utils.getFullTestURL("");
264 eThread = new ExecThread(exD);
266 eThread.start();