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: _XExecutableDialog.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 com
.sun
.star
.ui
.dialogs
.XExecutableDialog
;
36 import com
.sun
.star
.uno
.UnoRuntime
;
37 import com
.sun
.star
.util
.XCancellable
;
40 * Testing <code>com.sun.star.ui.dialogs.XExecutableDialog</code>
43 * <li><code> setTitle()</code></li>
44 * <li><code> execute()</code></li>
47 * This interface methods cann't be checked, thereby methods
48 * are just called. <code>execute</code> method is not called
49 * at all as the dialog shown cann't be disposed. <p>
51 * Test is <b> NOT </b> multithread compilant. <p>
52 * @see com.sun.star.ui.dialogs.XExecutableDialog
54 public class _XExecutableDialog
extends MultiMethodTest
{
56 public XExecutableDialog oObj
= null;
57 private ExecThread eThread
= null;
60 * Test calls the method. <p>
61 * Has <b> OK </b> status if the method successfully returns
62 * and no exceptions were thrown. <p>
64 public void _setTitle() {
65 oObj
.setTitle("The Title");
66 tRes
.tested("setTitle()",true);
70 * This method is excluded from automated test since
71 * we can't close the dialog. <p>
72 * Always has <b>OK</b> status.
74 public void _execute() {
75 String aName
= tEnv
.getTestCase().getObjectName();
76 boolean result
= false;
77 if (aName
.startsWith("OData") || aName
.startsWith("OSQL")) {
78 log
.println("dbaccess dialogs can't be closed via API");
79 log
.println("therefore they aren't executed");
80 log
.println("and the result is set to true");
83 eThread
= new ExecThread(oObj
);
84 log
.println("Starting Dialog");
86 XCancellable canc
= (XCancellable
)UnoRuntime
.queryInterface
87 (XCancellable
.class, tEnv
.getTestObject());
91 short res
= eThread
.execRes
;
92 log
.println("result: "+res
);
95 this.disposeEnvironment();
97 log
.println("XCancellable isn't supported and the "+
98 "environment is killed hard");
103 tRes
.tested("execute()",result
);
107 * Calls <code>execute()</code> method in a separate thread.
108 * Necessary to check if this method works
110 protected class ExecThread
extends Thread
{
112 public short execRes
= (short) 17 ;
113 private XExecutableDialog Diag
= null ;
115 public ExecThread(XExecutableDialog Diag
) {
121 execRes
= Diag
.execute();
122 System
.out
.println("HERE: "+execRes
);
123 } catch(Exception e
) {
124 log
.println("Thread has been interrupted ... ");
130 * Sleeps for 5 sec. to allow StarOffice to react on <code>
133 private void shortWait() {
136 } catch (InterruptedException e
) {
137 log
.println("While waiting :" + e
) ;
141 public void after() {
142 if (eThread
.isAlive()) {
143 log
.println("Thread didn't die ... cleaning up");
144 disposeEnvironment();
148 private void closeDialog() {
149 XCancellable canc
= (XCancellable
) UnoRuntime
.queryInterface(
150 XCancellable
.class, tEnv
.getTestObject());
152 log
.println("Cancelling Dialog");
155 this.disposeEnvironment();
158 long st
= System
.currentTimeMillis();
159 boolean toLong
= false;
161 log
.println("waiting for dialog to close");
163 while (eThread
.isAlive() && !toLong
) {
164 //wait for dialog to close
165 toLong
= (System
.currentTimeMillis()-st
> 10000);
171 if (eThread
.isAlive()) {
172 log
.println("Interrupting Thread");
176 } catch (Exception e
) {
180 st
= System
.currentTimeMillis();
183 log
.println("waiting for interruption to work");
185 while (eThread
.isAlive() && !toLong
) {
186 //wait for dialog to close
187 toLong
= (System
.currentTimeMillis()-st
> 10000);
190 log
.println("DialogThread alive: "+eThread
.isAlive());