bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / ifc / ui / dialogs / _XExecutableDialog.java
blobe87b407115bfe3d2f9f5bf35fa48f8fea3b051ba
1 /*
2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 package ifc.ui.dialogs;
21 import lib.MultiMethodTest;
23 import com.sun.star.ui.dialogs.XExecutableDialog;
24 import com.sun.star.uno.UnoRuntime;
25 import com.sun.star.util.XCancellable;
27 /**
28 * Testing <code>com.sun.star.ui.dialogs.XExecutableDialog</code>
29 * interface methods :
30 * <ul>
31 * <li><code> setTitle()</code></li>
32 * <li><code> execute()</code></li>
33 * </ul> <p>
35 * This interface methods cann't be checked, thereby methods
36 * are just called. <code>execute</code> method is not called
37 * at all as the dialog shown cann't be disposed. <p>
39 * Test is <b> NOT </b> multithread compilant. <p>
40 * @see com.sun.star.ui.dialogs.XExecutableDialog
42 public class _XExecutableDialog extends MultiMethodTest {
44 public XExecutableDialog oObj = null;
45 private ExecThread eThread = null;
47 /**
48 * Test calls the method. <p>
49 * Has <b> OK </b> status if the method successfully returns
50 * and no exceptions were thrown. <p>
52 public void _setTitle() {
53 oObj.setTitle("The Title");
54 tRes.tested("setTitle()",true);
57 /**
58 * This method is excluded from automated test since
59 * we can't close the dialog. <p>
60 * Always has <b>OK</b> status.
62 public void _execute() {
63 String aName = tEnv.getTestCase().getObjectName();
64 boolean result = false;
65 if (aName.startsWith("OData") || aName.startsWith("OSQL")) {
66 log.println("dbaccess dialogs can't be closed via API");
67 log.println("therefore they aren't executed");
68 log.println("and the result is set to true");
69 result = true;
70 } else {
71 eThread = new ExecThread(oObj);
72 log.println("Starting Dialog");
73 eThread.start();
74 XCancellable canc = UnoRuntime.queryInterface
75 (XCancellable.class, tEnv.getTestObject());
76 shortWait();
77 if (canc != null) {
78 closeDialog();
79 short res = eThread.execRes;
80 log.println("result: "+res);
81 result = (res == 0);
82 } else {
83 this.disposeEnvironment();
84 result=true;
85 log.println("XCancellable isn't supported and the "+
86 "environment is killed hard");
91 tRes.tested("execute()",result);
94 /**
95 * Calls <code>execute()</code> method in a separate thread.
96 * Necessary to check if this method works
98 protected class ExecThread extends Thread {
100 public short execRes = (short) 17 ;
101 private XExecutableDialog Diag = null ;
103 public ExecThread(XExecutableDialog Diag) {
104 this.Diag = Diag ;
107 public void run() {
108 try {
109 execRes = Diag.execute();
110 System.out.println("HERE: "+execRes);
111 } catch(Exception e) {
112 log.println("Thread has been interrupted ... ");
118 * Sleeps for 5 sec. to allow StarOffice to react on <code>
119 * reset</code> call.
121 private void shortWait() {
122 try {
123 Thread.sleep(2000) ;
124 } catch (InterruptedException e) {
125 log.println("While waiting :" + e) ;
129 public void after() {
130 if (eThread.isAlive()) {
131 log.println("Thread didn't die ... cleaning up");
132 disposeEnvironment();
136 private void closeDialog() {
137 XCancellable canc = UnoRuntime.queryInterface(
138 XCancellable.class, tEnv.getTestObject());
139 if (canc != null) {
140 log.println("Cancelling Dialog");
141 canc.cancel();
142 } else {
143 this.disposeEnvironment();
146 long st = System.currentTimeMillis();
147 boolean toLong = false;
149 log.println("waiting for dialog to close");
151 while (eThread.isAlive() && !toLong) {
152 //wait for dialog to close
153 toLong = (System.currentTimeMillis()-st > 10000);
156 log.println("done");
158 try {
159 if (eThread.isAlive()) {
160 log.println("Interrupting Thread");
161 eThread.interrupt();
162 Thread.yield();
164 } catch (Exception e) {
165 // who cares ;-)
168 st = System.currentTimeMillis();
169 toLong = false;
171 log.println("waiting for interruption to work");
173 while (eThread.isAlive() && !toLong) {
174 //wait for dialog to close
175 toLong = (System.currentTimeMillis()-st > 10000);
178 log.println("DialogThread alive: "+eThread.isAlive());
180 log.println("done");