merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / ifc / ui / dialogs / _XExecutableDialog.java
blobf76634af50221183a5e47b0ee1f4b32dc46073e2
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: _XExecutableDialog.java,v $
10 * $Revision: 1.7 $
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;
39 /**
40 * Testing <code>com.sun.star.ui.dialogs.XExecutableDialog</code>
41 * interface methods :
42 * <ul>
43 * <li><code> setTitle()</code></li>
44 * <li><code> execute()</code></li>
45 * </ul> <p>
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;
59 /**
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);
69 /**
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");
81 result = true;
82 } else {
83 eThread = new ExecThread(oObj);
84 log.println("Starting Dialog");
85 eThread.start();
86 XCancellable canc = (XCancellable)UnoRuntime.queryInterface
87 (XCancellable.class, tEnv.getTestObject());
88 shortWait();
89 if (canc != null) {
90 closeDialog();
91 short res = eThread.execRes;
92 log.println("result: "+res);
93 result = (res == 0);
94 } else {
95 this.disposeEnvironment();
96 result=true;
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) {
116 this.Diag = Diag ;
119 public void run() {
120 try {
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>
131 * reset</code> call.
133 private void shortWait() {
134 try {
135 Thread.sleep(2000) ;
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());
151 if (canc != null) {
152 log.println("Cancelling Dialog");
153 canc.cancel();
154 } else {
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);
168 log.println("done");
170 try {
171 if (eThread.isAlive()) {
172 log.println("Interrupting Thread");
173 eThread.interrupt();
174 eThread.yield();
176 } catch (Exception e) {
177 // who cares ;-)
180 st = System.currentTimeMillis();
181 toLong = false;
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());
192 log.println("done");