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
;
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
;
36 * Testing <code>com.sun.star.ui.XFilePickerNotifier</code>
39 * <li><code> addFilePickerListener()</code></li>
40 * <li><code> removeFilePickerListener()</code></li>
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,
53 ExecThread eThread
= null;
57 * Listener implementation which sets a flag if some of its
60 protected class TestListener
implements XFilePickerListener
{
61 public boolean called
= false ;
63 public void dialogSizeChanged() {
67 public void fileSelectionChanged(FilePickerEvent e
) {
71 public void directoryChanged(FilePickerEvent e
) {
72 log
.println("***** Directory Changed *****");
76 public String
helpRequested(FilePickerEvent e
) {
81 public void controlStateChanged(FilePickerEvent e
) {
85 public void disposing(EventObject e
) {}
88 TestListener listener
= new TestListener() ;
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>
97 public void before() {
98 fps
= UnoRuntime
.queryInterface
99 (XFilePicker
.class, oObj
) ;
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
) ;
124 log
.println("***** Setting DisplayDirectory to " + dir1
);
125 fps
.setDisplayDirectory(dir1
) ;
126 log
.println("***** Getting: " + fps
.getDisplayDirectory());
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
) ;
139 if (!listener
.called
) {
140 log
.println("Listener wasn't called :-(");
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 :
153 * <li> <code> addFilePickerListener </code> </li>
156 public void _removeFilePickerListener() {
157 requiredMethod("addFilePickerListener()") ;
159 oObj
.removeFilePickerListener(listener
) ;
161 listener
.called
= false ;
164 fps
.setDisplayDirectory(dir1
) ;
166 fps
.setDisplayDirectory(dir2
) ;
167 } catch(com
.sun
.star
.lang
.IllegalArgumentException e
) {
168 log
.println("!!! Exception changing dir !!!") ;
169 e
.printStackTrace(log
) ;
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
) {
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());
207 log
.println("Cancelling Dialog");
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);
226 if (eThread
.isAlive()) {
227 log
.println("Interrupting Thread");
231 } catch (Exception e
) {
235 st
= System
.currentTimeMillis();
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());
251 private void openDialog() {
252 log
.println("Starting Dialog");
253 if (eThread
.isAlive()) {
254 log
.println("second interrupt");
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
);