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
;
28 * Testing <code>com.sun.star.ui.dialogs.XExecutableDialog</code>
31 * <li><code> setTitle()</code></li>
32 * <li><code> execute()</code></li>
35 * These interface methods can't be checked, thereby methods
36 * are just called. <code>execute</code> method is not called
37 * at all as the dialog shown can'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;
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);
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");
71 eThread
= new ExecThread(oObj
);
72 log
.println("Starting Dialog");
74 XCancellable canc
= UnoRuntime
.queryInterface
75 (XCancellable
.class, tEnv
.getTestObject());
79 short res
= eThread
.execRes
;
80 log
.println("result: "+res
);
83 this.disposeEnvironment();
85 log
.println("XCancellable isn't supported and the "+
86 "environment is killed hard");
91 tRes
.tested("execute()",result
);
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
) {
110 execRes
= Diag
.execute();
111 System
.out
.println("HERE: "+execRes
);
112 } catch(Exception e
) {
113 log
.println("Thread has been interrupted ... ");
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());
130 log
.println("Cancelling Dialog");
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);
149 if (eThread
.isAlive()) {
150 log
.println("Interrupting Thread");
154 } catch (Exception e
) {
158 st
= System
.currentTimeMillis();
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());