1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 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. 14 * 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). 20 * 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. 25 * 26 ************************************************************************/ 27 28 package ifc.ui.dialogs; 29 30 import lib.MultiMethodTest; 31 32 import com.sun.star.ui.dialogs.XExecutableDialog; 33 import com.sun.star.uno.UnoRuntime; 34 import com.sun.star.util.XCancellable; 35 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> 43 * 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> 47 * 48 * Test is <b> NOT </b> multithread compilant. <p> 49 * @see com.sun.star.ui.dialogs.XExecutableDialog 50 */ 51 public class _XExecutableDialog extends MultiMethodTest { 52 53 public XExecutableDialog oObj = null; 54 private ExecThread eThread = null; 55 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> 60 */ 61 public void _setTitle() { 62 oObj.setTitle("The Title"); 63 tRes.tested("setTitle()",true); 64 } 65 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. 70 */ 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"); 96 } 97 98 99 } 100 tRes.tested("execute()",result); 101 } 102 103 /** 104 * Calls <code>execute()</code> method in a separate thread. 105 * Necessary to check if this method works 106 */ 107 protected class ExecThread extends Thread { 108 109 public short execRes = (short) 17 ; 110 private XExecutableDialog Diag = null ; 111 112 public ExecThread(XExecutableDialog Diag) { 113 this.Diag = Diag ; 114 } 115 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 ... "); 122 } 123 } 124 } 125 126 /** 127 * Sleeps for 5 sec. to allow StarOffice to react on <code> 128 * reset</code> call. 129 */ 130 private void shortWait() { 131 try { 132 Thread.sleep(2000) ; 133 } catch (InterruptedException e) { 134 log.println("While waiting :" + e) ; 135 } 136 } 137 138 public void after() { 139 if (eThread.isAlive()) { 140 log.println("Thread didn't die ... cleaning up"); 141 disposeEnvironment(); 142 } 143 } 144 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(); 153 } 154 155 long st = System.currentTimeMillis(); 156 boolean toLong = false; 157 158 log.println("waiting for dialog to close"); 159 160 while (eThread.isAlive() && !toLong) { 161 //wait for dialog to close 162 toLong = (System.currentTimeMillis()-st > 10000); 163 } 164 165 log.println("done"); 166 167 try { 168 if (eThread.isAlive()) { 169 log.println("Interrupting Thread"); 170 eThread.interrupt(); 171 eThread.yield(); 172 } 173 } catch (Exception e) { 174 // who cares ;-) 175 } 176 177 st = System.currentTimeMillis(); 178 toLong = false; 179 180 log.println("waiting for interruption to work"); 181 182 while (eThread.isAlive() && !toLong) { 183 //wait for dialog to close 184 toLong = (System.currentTimeMillis()-st > 10000); 185 } 186 187 log.println("DialogThread alive: "+eThread.isAlive()); 188 189 log.println("done"); 190 191 } 192 193 } 194 195 196