Branch libreoffice-5-0-4
[LibreOffice.git] / qadevOOo / tests / java / ifc / ui / dialogs / _XExecutableDialog.java
blobbb10c5abd9cd2209bb0cda7e860e52c593a7e241
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 compliant. <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 util.utils.pause(2000);
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 final XExecutableDialog Diag;
103 public ExecThread(XExecutableDialog Diag) {
104 this.Diag = Diag ;
107 @Override
108 public void run() {
109 try {
110 execRes = Diag.execute();
111 System.out.println("HERE: "+execRes);
112 } catch(Exception e) {
113 log.println("Thread has been interrupted ... ");
118 @Override
119 public void after() {
120 if (eThread.isAlive()) {
121 log.println("Thread didn't die ... cleaning up");
122 disposeEnvironment();
126 private void closeDialog() {
127 XCancellable canc = UnoRuntime.queryInterface(
128 XCancellable.class, tEnv.getTestObject());
129 if (canc != null) {
130 log.println("Cancelling Dialog");
131 canc.cancel();
132 } else {
133 this.disposeEnvironment();
136 long st = System.currentTimeMillis();
137 boolean toLong = false;
139 log.println("waiting for dialog to close");
141 while (eThread.isAlive() && !toLong) {
142 //wait for dialog to close
143 toLong = (System.currentTimeMillis()-st > 10000);
146 log.println("done");
148 try {
149 if (eThread.isAlive()) {
150 log.println("Interrupting Thread");
151 eThread.interrupt();
152 Thread.yield();
154 } catch (Exception e) {
155 // who cares ;-)
158 st = System.currentTimeMillis();
159 toLong = false;
161 log.println("waiting for interruption to work");
163 while (eThread.isAlive() && !toLong) {
164 //wait for dialog to close
165 toLong = (System.currentTimeMillis()-st > 10000);
168 log.println("DialogThread alive: "+eThread.isAlive());
170 log.println("done");