1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: _XFilePickerNotifier.java,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 package ifc
.ui
.dialogs
;
33 import lib
.MultiMethodTest
;
35 import lib
.StatusException
;
37 import com
.sun
.star
.lang
.EventObject
;
38 import com
.sun
.star
.lang
.XMultiServiceFactory
;
39 import com
.sun
.star
.ui
.dialogs
.FilePickerEvent
;
40 import com
.sun
.star
.ui
.dialogs
.XExecutableDialog
;
41 import com
.sun
.star
.ui
.dialogs
.XFilePicker
;
42 import com
.sun
.star
.ui
.dialogs
.XFilePickerListener
;
43 import com
.sun
.star
.ui
.dialogs
.XFilePickerNotifier
;
44 import com
.sun
.star
.uno
.UnoRuntime
;
45 import com
.sun
.star
.util
.XCancellable
;
49 * Testing <code>com.sun.star.ui.XFilePickerNotifier</code>
52 * <li><code> addFilePickerListener()</code></li>
53 * <li><code> removeFilePickerListener()</code></li>
55 * The object must implement <code>XFilePicker</code>
56 * interface to check if a listener was called. <p>
57 * Test is <b> NOT </b> multithread compilant. <p>
58 * @see com.sun.star.ui.XFilePickerNotifier
60 public class _XFilePickerNotifier
extends MultiMethodTest
{
62 public XFilePickerNotifier oObj
= null;
63 private XFilePicker fps
= null ;
64 private String dir1
= null,
66 ExecThread eThread
= null;
70 * Listener implementation which sets a flag if some of its
73 protected class TestListener
implements XFilePickerListener
{
74 public boolean called
= false ;
76 public void dialogSizeChanged() {
80 public void fileSelectionChanged(FilePickerEvent e
) {
84 public void directoryChanged(FilePickerEvent e
) {
85 log
.println("***** Directory Changed *****");
89 public String
helpRequested(FilePickerEvent e
) {
94 public void controlStateChanged(FilePickerEvent e
) {
98 public void disposing(EventObject e
) {}
101 TestListener listener
= new TestListener() ;
104 * Tries to query object for <code>XFilePicker</code> interface, and
105 * initializes two different URLs for changing file picker directory. <p>
106 * @throw StatusException If object doesn't support <code>XFilePicker</code>
109 public void before() {
110 fps
= (XFilePicker
) UnoRuntime
.queryInterface
111 (XFilePicker
.class, oObj
) ;
114 log
.println("The object doesnt implement XFilePicker") ;
115 throw new StatusException(Status
.failed
116 ("The object doesnt implement XFilePicker"));
119 XExecutableDialog exD
= (XExecutableDialog
) UnoRuntime
.queryInterface(
120 XExecutableDialog
.class, tEnv
.getTestObject());
122 dir1
= util
.utils
.getOfficeTemp((XMultiServiceFactory
)tParam
.getMSF());
123 dir2
= util
.utils
.getFullTestURL("");
124 eThread
= new ExecThread(exD
);
128 * Adds a listener, then tries to change display directory and
129 * checks if the listener was called. <p>
130 * Has <b>OK</b> status if a listener method was called.
132 public void _addFilePickerListener() {
133 oObj
.addFilePickerListener(listener
) ;
136 log
.println("***** Setting DisplayDirectory to " + dir1
);
137 fps
.setDisplayDirectory(dir1
) ;
138 log
.println("***** Getting: " + fps
.getDisplayDirectory());
140 log
.println("***** Setting DisplayDirectory to " + dir2
);
141 fps
.setDisplayDirectory(dir2
) ;
142 log
.println("***** Getting: " + fps
.getDisplayDirectory());
144 } catch(com
.sun
.star
.lang
.IllegalArgumentException e
) {
145 log
.println("!!! Exception changing dir !!!") ;
146 e
.printStackTrace(log
) ;
151 if (!listener
.called
) {
152 log
.println("Listener wasn't called :-(");
157 tRes
.tested("addFilePickerListener()", listener
.called
) ;
161 * Removes the listener and changes display directory. <p>
162 * Has <b>OK</b> status if the listener wasn't called. <p>
163 * The following method tests are to be completed successfully before :
165 * <li> <code> addFilePickerListener </code> </li>
168 public void _removeFilePickerListener() {
169 requiredMethod("addFilePickerListener()") ;
171 oObj
.removeFilePickerListener(listener
) ;
173 listener
.called
= false ;
176 fps
.setDisplayDirectory(dir1
) ;
178 fps
.setDisplayDirectory(dir2
) ;
179 } catch(com
.sun
.star
.lang
.IllegalArgumentException e
) {
180 log
.println("!!! Exception changing dir !!!") ;
181 e
.printStackTrace(log
) ;
188 tRes
.tested("removeFilePickerListener()", !listener
.called
) ;
192 * Calls <code>execute()</code> method in a separate thread.
193 * Necessary to check if this method works
195 protected class ExecThread
extends Thread
{
197 public short execRes
= (short) 17 ;
198 private XExecutableDialog Diag
= null ;
200 public ExecThread(XExecutableDialog Diag
) {
206 execRes
= Diag
.execute();
207 System
.out
.println("HERE: "+execRes
);
208 } catch (Exception e
) {
209 log
.println("Thread has been interrupted ...");
215 * Sleeps for 0.5 sec. to allow StarOffice to react on <code>
218 private void shortWait() {
221 } catch (InterruptedException e
) {
222 log
.println("While waiting :" + e
) ;
226 private void closeDialog() {
227 XCancellable canc
= (XCancellable
) UnoRuntime
.queryInterface(
228 XCancellable
.class, tEnv
.getTestObject());
230 log
.println("Cancelling Dialog");
233 this.disposeEnvironment();
236 long st
= System
.currentTimeMillis();
237 boolean toLong
= false;
239 log
.println("waiting for dialog to close");
241 while (eThread
.isAlive() && !toLong
) {
242 //wait for dialog to close
243 toLong
= (System
.currentTimeMillis()-st
> 10000);
249 if (eThread
.isAlive()) {
250 log
.println("Interrupting Thread");
254 } catch (Exception e
) {
258 st
= System
.currentTimeMillis();
261 log
.println("waiting for interruption to work");
263 while (eThread
.isAlive() && !toLong
) {
264 //wait for dialog to close
265 toLong
= (System
.currentTimeMillis()-st
> 10000);
268 log
.println("DialogThread alive: "+eThread
.isAlive());
274 private void openDialog() {
275 log
.println("Starting Dialog");
276 if (eThread
.isAlive()) {
277 log
.println("second interrupt");
282 XExecutableDialog exD
= (XExecutableDialog
) UnoRuntime
.queryInterface(
283 XExecutableDialog
.class, tEnv
.getTestObject());
285 dir1
= util
.utils
.getOfficeTemp((XMultiServiceFactory
)tParam
.getMSF());
286 dir2
= util
.utils
.getFullTestURL("");
287 eThread
= new ExecThread(exD
);