Version 3.6.0.4, tag libreoffice-3.6.0.4
[LibreOffice.git] / qadevOOo / tests / java / ifc / ui / dialogs / _XExecutableDialog.java
blob95e2c27d98959d85e880cb7cda046339679081b6
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;
36 /**
37 * Testing <code>com.sun.star.ui.dialogs.XExecutableDialog</code>
38 * interface methods :
39 * <ul>
40 * <li><code> setTitle()</code></li>
41 * <li><code> execute()</code></li>
42 * </ul> <p>
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;
56 /**
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);
66 /**
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");
78 result = true;
79 } else {
80 eThread = new ExecThread(oObj);
81 log.println("Starting Dialog");
82 eThread.start();
83 XCancellable canc = (XCancellable)UnoRuntime.queryInterface
84 (XCancellable.class, tEnv.getTestObject());
85 shortWait();
86 if (canc != null) {
87 closeDialog();
88 short res = eThread.execRes;
89 log.println("result: "+res);
90 result = (res == 0);
91 } else {
92 this.disposeEnvironment();
93 result=true;
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) {
113 this.Diag = Diag ;
116 public void run() {
117 try {
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>
128 * reset</code> call.
130 private void shortWait() {
131 try {
132 Thread.sleep(2000) ;
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());
148 if (canc != null) {
149 log.println("Cancelling Dialog");
150 canc.cancel();
151 } else {
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);
165 log.println("done");
167 try {
168 if (eThread.isAlive()) {
169 log.println("Interrupting Thread");
170 eThread.interrupt();
171 eThread.yield();
173 } catch (Exception e) {
174 // who cares ;-)
177 st = System.currentTimeMillis();
178 toLong = false;
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());
189 log.println("done");