1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 package ifc
.ui
.dialogs
;
30 import lib
.MultiMethodTest
;
32 import lib
.StatusException
;
34 import com
.sun
.star
.lang
.EventObject
;
35 import com
.sun
.star
.lang
.XMultiServiceFactory
;
36 import com
.sun
.star
.ui
.dialogs
.FilePickerEvent
;
37 import com
.sun
.star
.ui
.dialogs
.XExecutableDialog
;
38 import com
.sun
.star
.ui
.dialogs
.XFilePicker
;
39 import com
.sun
.star
.ui
.dialogs
.XFilePickerListener
;
40 import com
.sun
.star
.ui
.dialogs
.XFilePickerNotifier
;
41 import com
.sun
.star
.uno
.UnoRuntime
;
42 import com
.sun
.star
.util
.XCancellable
;
46 * Testing <code>com.sun.star.ui.XFilePickerNotifier</code>
49 * <li><code> addFilePickerListener()</code></li>
50 * <li><code> removeFilePickerListener()</code></li>
52 * The object must implement <code>XFilePicker</code>
53 * interface to check if a listener was called. <p>
54 * Test is <b> NOT </b> multithread compilant. <p>
55 * @see com.sun.star.ui.XFilePickerNotifier
57 public class _XFilePickerNotifier
extends MultiMethodTest
{
59 public XFilePickerNotifier oObj
= null;
60 private XFilePicker fps
= null ;
61 private String dir1
= null,
63 ExecThread eThread
= null;
67 * Listener implementation which sets a flag if some of its
70 protected class TestListener
implements XFilePickerListener
{
71 public boolean called
= false ;
73 public void dialogSizeChanged() {
77 public void fileSelectionChanged(FilePickerEvent e
) {
81 public void directoryChanged(FilePickerEvent e
) {
82 log
.println("***** Directory Changed *****");
86 public String
helpRequested(FilePickerEvent e
) {
91 public void controlStateChanged(FilePickerEvent e
) {
95 public void disposing(EventObject e
) {}
98 TestListener listener
= new TestListener() ;
101 * Tries to query object for <code>XFilePicker</code> interface, and
102 * initializes two different URLs for changing file picker directory. <p>
103 * @throw StatusException If object doesn't support <code>XFilePicker</code>
106 public void before() {
107 fps
= (XFilePicker
) UnoRuntime
.queryInterface
108 (XFilePicker
.class, oObj
) ;
111 log
.println("The object doesnt implement XFilePicker") ;
112 throw new StatusException(Status
.failed
113 ("The object doesnt implement XFilePicker"));
116 XExecutableDialog exD
= (XExecutableDialog
) UnoRuntime
.queryInterface(
117 XExecutableDialog
.class, tEnv
.getTestObject());
119 dir1
= util
.utils
.getOfficeTemp((XMultiServiceFactory
)tParam
.getMSF());
120 dir2
= util
.utils
.getFullTestURL("");
121 eThread
= new ExecThread(exD
);
125 * Adds a listener, then tries to change display directory and
126 * checks if the listener was called. <p>
127 * Has <b>OK</b> status if a listener method was called.
129 public void _addFilePickerListener() {
130 oObj
.addFilePickerListener(listener
) ;
133 log
.println("***** Setting DisplayDirectory to " + dir1
);
134 fps
.setDisplayDirectory(dir1
) ;
135 log
.println("***** Getting: " + fps
.getDisplayDirectory());
137 log
.println("***** Setting DisplayDirectory to " + dir2
);
138 fps
.setDisplayDirectory(dir2
) ;
139 log
.println("***** Getting: " + fps
.getDisplayDirectory());
141 } catch(com
.sun
.star
.lang
.IllegalArgumentException e
) {
142 log
.println("!!! Exception changing dir !!!") ;
143 e
.printStackTrace(log
) ;
148 if (!listener
.called
) {
149 log
.println("Listener wasn't called :-(");
154 tRes
.tested("addFilePickerListener()", listener
.called
) ;
158 * Removes the listener and changes display directory. <p>
159 * Has <b>OK</b> status if the listener wasn't called. <p>
160 * The following method tests are to be completed successfully before :
162 * <li> <code> addFilePickerListener </code> </li>
165 public void _removeFilePickerListener() {
166 requiredMethod("addFilePickerListener()") ;
168 oObj
.removeFilePickerListener(listener
) ;
170 listener
.called
= false ;
173 fps
.setDisplayDirectory(dir1
) ;
175 fps
.setDisplayDirectory(dir2
) ;
176 } catch(com
.sun
.star
.lang
.IllegalArgumentException e
) {
177 log
.println("!!! Exception changing dir !!!") ;
178 e
.printStackTrace(log
) ;
185 tRes
.tested("removeFilePickerListener()", !listener
.called
) ;
189 * Calls <code>execute()</code> method in a separate thread.
190 * Necessary to check if this method works
192 protected class ExecThread
extends Thread
{
194 public short execRes
= (short) 17 ;
195 private XExecutableDialog Diag
= null ;
197 public ExecThread(XExecutableDialog Diag
) {
203 execRes
= Diag
.execute();
204 System
.out
.println("HERE: "+execRes
);
205 } catch (Exception e
) {
206 log
.println("Thread has been interrupted ...");
212 * Sleeps for 0.5 sec. to allow StarOffice to react on <code>
215 private void shortWait() {
218 } catch (InterruptedException e
) {
219 log
.println("While waiting :" + e
) ;
223 private void closeDialog() {
224 XCancellable canc
= (XCancellable
) UnoRuntime
.queryInterface(
225 XCancellable
.class, tEnv
.getTestObject());
227 log
.println("Cancelling Dialog");
230 this.disposeEnvironment();
233 long st
= System
.currentTimeMillis();
234 boolean toLong
= false;
236 log
.println("waiting for dialog to close");
238 while (eThread
.isAlive() && !toLong
) {
239 //wait for dialog to close
240 toLong
= (System
.currentTimeMillis()-st
> 10000);
246 if (eThread
.isAlive()) {
247 log
.println("Interrupting Thread");
251 } catch (Exception e
) {
255 st
= System
.currentTimeMillis();
258 log
.println("waiting for interruption to work");
260 while (eThread
.isAlive() && !toLong
) {
261 //wait for dialog to close
262 toLong
= (System
.currentTimeMillis()-st
> 10000);
265 log
.println("DialogThread alive: "+eThread
.isAlive());
271 private void openDialog() {
272 log
.println("Starting Dialog");
273 if (eThread
.isAlive()) {
274 log
.println("second interrupt");
279 XExecutableDialog exD
= (XExecutableDialog
) UnoRuntime
.queryInterface(
280 XExecutableDialog
.class, tEnv
.getTestObject());
282 dir1
= util
.utils
.getOfficeTemp((XMultiServiceFactory
)tParam
.getMSF());
283 dir2
= util
.utils
.getFullTestURL("");
284 eThread
= new ExecThread(exD
);