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 com
.sun
.star
.ui
.dialogs
.XExecutableDialog
;
33 import com
.sun
.star
.uno
.UnoRuntime
;
34 import com
.sun
.star
.util
.XCancellable
;
37 * Testing <code>com.sun.star.ui.dialogs.XExecutableDialog</code>
40 * <li><code> setTitle()</code></li>
41 * <li><code> execute()</code></li>
44 * This interface methods cann't be checked, thereby methods
45 * are just called. <code>execute</code> method is not called
46 * at all as the dialog shown cann't be disposed. <p>
48 * Test is <b> NOT </b> multithread compilant. <p>
49 * @see com.sun.star.ui.dialogs.XExecutableDialog
51 public class _XExecutableDialog
extends MultiMethodTest
{
53 public XExecutableDialog oObj
= null;
54 private ExecThread eThread
= null;
57 * Test calls the method. <p>
58 * Has <b> OK </b> status if the method successfully returns
59 * and no exceptions were thrown. <p>
61 public void _setTitle() {
62 oObj
.setTitle("The Title");
63 tRes
.tested("setTitle()",true);
67 * This method is excluded from automated test since
68 * we can't close the dialog. <p>
69 * Always has <b>OK</b> status.
71 public void _execute() {
72 String aName
= tEnv
.getTestCase().getObjectName();
73 boolean result
= false;
74 if (aName
.startsWith("OData") || aName
.startsWith("OSQL")) {
75 log
.println("dbaccess dialogs can't be closed via API");
76 log
.println("therefore they aren't executed");
77 log
.println("and the result is set to true");
80 eThread
= new ExecThread(oObj
);
81 log
.println("Starting Dialog");
83 XCancellable canc
= (XCancellable
)UnoRuntime
.queryInterface
84 (XCancellable
.class, tEnv
.getTestObject());
88 short res
= eThread
.execRes
;
89 log
.println("result: "+res
);
92 this.disposeEnvironment();
94 log
.println("XCancellable isn't supported and the "+
95 "environment is killed hard");
100 tRes
.tested("execute()",result
);
104 * Calls <code>execute()</code> method in a separate thread.
105 * Necessary to check if this method works
107 protected class ExecThread
extends Thread
{
109 public short execRes
= (short) 17 ;
110 private XExecutableDialog Diag
= null ;
112 public ExecThread(XExecutableDialog Diag
) {
118 execRes
= Diag
.execute();
119 System
.out
.println("HERE: "+execRes
);
120 } catch(Exception e
) {
121 log
.println("Thread has been interrupted ... ");
127 * Sleeps for 5 sec. to allow StarOffice to react on <code>
130 private void shortWait() {
133 } catch (InterruptedException e
) {
134 log
.println("While waiting :" + e
) ;
138 public void after() {
139 if (eThread
.isAlive()) {
140 log
.println("Thread didn't die ... cleaning up");
141 disposeEnvironment();
145 private void closeDialog() {
146 XCancellable canc
= (XCancellable
) UnoRuntime
.queryInterface(
147 XCancellable
.class, tEnv
.getTestObject());
149 log
.println("Cancelling Dialog");
152 this.disposeEnvironment();
155 long st
= System
.currentTimeMillis();
156 boolean toLong
= false;
158 log
.println("waiting for dialog to close");
160 while (eThread
.isAlive() && !toLong
) {
161 //wait for dialog to close
162 toLong
= (System
.currentTimeMillis()-st
> 10000);
168 if (eThread
.isAlive()) {
169 log
.println("Interrupting Thread");
173 } catch (Exception e
) {
177 st
= System
.currentTimeMillis();
180 log
.println("waiting for interruption to work");
182 while (eThread
.isAlive() && !toLong
) {
183 //wait for dialog to close
184 toLong
= (System
.currentTimeMillis()-st
> 10000);
187 log
.println("DialogThread alive: "+eThread
.isAlive());