1*ef39d40dSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*ef39d40dSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*ef39d40dSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*ef39d40dSAndrew Rist * distributed with this work for additional information 6*ef39d40dSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*ef39d40dSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*ef39d40dSAndrew Rist * "License"); you may not use this file except in compliance 9*ef39d40dSAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*ef39d40dSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*ef39d40dSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*ef39d40dSAndrew Rist * software distributed under the License is distributed on an 15*ef39d40dSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*ef39d40dSAndrew Rist * KIND, either express or implied. See the License for the 17*ef39d40dSAndrew Rist * specific language governing permissions and limitations 18*ef39d40dSAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*ef39d40dSAndrew Rist *************************************************************/ 21*ef39d40dSAndrew Rist 22*ef39d40dSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir package ifc.ui.dialogs; 25cdf0e10cSrcweir 26cdf0e10cSrcweir import lib.MultiMethodTest; 27cdf0e10cSrcweir 28cdf0e10cSrcweir import com.sun.star.ui.dialogs.XExecutableDialog; 29cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime; 30cdf0e10cSrcweir import com.sun.star.util.XCancellable; 31cdf0e10cSrcweir 32cdf0e10cSrcweir /** 33cdf0e10cSrcweir * Testing <code>com.sun.star.ui.dialogs.XExecutableDialog</code> 34cdf0e10cSrcweir * interface methods : 35cdf0e10cSrcweir * <ul> 36cdf0e10cSrcweir * <li><code> setTitle()</code></li> 37cdf0e10cSrcweir * <li><code> execute()</code></li> 38cdf0e10cSrcweir * </ul> <p> 39cdf0e10cSrcweir * 40cdf0e10cSrcweir * This interface methods cann't be checked, thereby methods 41cdf0e10cSrcweir * are just called. <code>execute</code> method is not called 42cdf0e10cSrcweir * at all as the dialog shown cann't be disposed. <p> 43cdf0e10cSrcweir * 44cdf0e10cSrcweir * Test is <b> NOT </b> multithread compilant. <p> 45cdf0e10cSrcweir * @see com.sun.star.ui.dialogs.XExecutableDialog 46cdf0e10cSrcweir */ 47cdf0e10cSrcweir public class _XExecutableDialog extends MultiMethodTest { 48cdf0e10cSrcweir 49cdf0e10cSrcweir public XExecutableDialog oObj = null; 50cdf0e10cSrcweir private ExecThread eThread = null; 51cdf0e10cSrcweir 52cdf0e10cSrcweir /** 53cdf0e10cSrcweir * Test calls the method. <p> 54cdf0e10cSrcweir * Has <b> OK </b> status if the method successfully returns 55cdf0e10cSrcweir * and no exceptions were thrown. <p> 56cdf0e10cSrcweir */ _setTitle()57cdf0e10cSrcweir public void _setTitle() { 58cdf0e10cSrcweir oObj.setTitle("The Title"); 59cdf0e10cSrcweir tRes.tested("setTitle()",true); 60cdf0e10cSrcweir } 61cdf0e10cSrcweir 62cdf0e10cSrcweir /** 63cdf0e10cSrcweir * This method is excluded from automated test since 64cdf0e10cSrcweir * we can't close the dialog. <p> 65cdf0e10cSrcweir * Always has <b>OK</b> status. 66cdf0e10cSrcweir */ _execute()67cdf0e10cSrcweir public void _execute() { 68cdf0e10cSrcweir String aName = tEnv.getTestCase().getObjectName(); 69cdf0e10cSrcweir boolean result = false; 70cdf0e10cSrcweir if (aName.startsWith("OData") || aName.startsWith("OSQL")) { 71cdf0e10cSrcweir log.println("dbaccess dialogs can't be closed via API"); 72cdf0e10cSrcweir log.println("therefore they aren't executed"); 73cdf0e10cSrcweir log.println("and the result is set to true"); 74cdf0e10cSrcweir result = true; 75cdf0e10cSrcweir } else { 76cdf0e10cSrcweir eThread = new ExecThread(oObj); 77cdf0e10cSrcweir log.println("Starting Dialog"); 78cdf0e10cSrcweir eThread.start(); 79cdf0e10cSrcweir XCancellable canc = (XCancellable)UnoRuntime.queryInterface 80cdf0e10cSrcweir (XCancellable.class, tEnv.getTestObject()); 81cdf0e10cSrcweir shortWait(); 82cdf0e10cSrcweir if (canc != null) { 83cdf0e10cSrcweir closeDialog(); 84cdf0e10cSrcweir short res = eThread.execRes; 85cdf0e10cSrcweir log.println("result: "+res); 86cdf0e10cSrcweir result = (res == 0); 87cdf0e10cSrcweir } else { 88cdf0e10cSrcweir this.disposeEnvironment(); 89cdf0e10cSrcweir result=true; 90cdf0e10cSrcweir log.println("XCancellable isn't supported and the "+ 91cdf0e10cSrcweir "environment is killed hard"); 92cdf0e10cSrcweir } 93cdf0e10cSrcweir 94cdf0e10cSrcweir 95cdf0e10cSrcweir } 96cdf0e10cSrcweir tRes.tested("execute()",result); 97cdf0e10cSrcweir } 98cdf0e10cSrcweir 99cdf0e10cSrcweir /** 100cdf0e10cSrcweir * Calls <code>execute()</code> method in a separate thread. 101cdf0e10cSrcweir * Necessary to check if this method works 102cdf0e10cSrcweir */ 103cdf0e10cSrcweir protected class ExecThread extends Thread { 104cdf0e10cSrcweir 105cdf0e10cSrcweir public short execRes = (short) 17 ; 106cdf0e10cSrcweir private XExecutableDialog Diag = null ; 107cdf0e10cSrcweir ExecThread(XExecutableDialog Diag)108cdf0e10cSrcweir public ExecThread(XExecutableDialog Diag) { 109cdf0e10cSrcweir this.Diag = Diag ; 110cdf0e10cSrcweir } 111cdf0e10cSrcweir run()112cdf0e10cSrcweir public void run() { 113cdf0e10cSrcweir try { 114cdf0e10cSrcweir execRes = Diag.execute(); 115cdf0e10cSrcweir System.out.println("HERE: "+execRes); 116cdf0e10cSrcweir } catch(Exception e) { 117cdf0e10cSrcweir log.println("Thread has been interrupted ... "); 118cdf0e10cSrcweir } 119cdf0e10cSrcweir } 120cdf0e10cSrcweir } 121cdf0e10cSrcweir 122cdf0e10cSrcweir /** 123cdf0e10cSrcweir * Sleeps for 5 sec. to allow StarOffice to react on <code> 124cdf0e10cSrcweir * reset</code> call. 125cdf0e10cSrcweir */ shortWait()126cdf0e10cSrcweir private void shortWait() { 127cdf0e10cSrcweir try { 128cdf0e10cSrcweir Thread.sleep(2000) ; 129cdf0e10cSrcweir } catch (InterruptedException e) { 130cdf0e10cSrcweir log.println("While waiting :" + e) ; 131cdf0e10cSrcweir } 132cdf0e10cSrcweir } 133cdf0e10cSrcweir after()134cdf0e10cSrcweir public void after() { 135cdf0e10cSrcweir if (eThread.isAlive()) { 136cdf0e10cSrcweir log.println("Thread didn't die ... cleaning up"); 137cdf0e10cSrcweir disposeEnvironment(); 138cdf0e10cSrcweir } 139cdf0e10cSrcweir } 140cdf0e10cSrcweir closeDialog()141cdf0e10cSrcweir private void closeDialog() { 142cdf0e10cSrcweir XCancellable canc = (XCancellable) UnoRuntime.queryInterface( 143cdf0e10cSrcweir XCancellable.class, tEnv.getTestObject()); 144cdf0e10cSrcweir if (canc != null) { 145cdf0e10cSrcweir log.println("Cancelling Dialog"); 146cdf0e10cSrcweir canc.cancel(); 147cdf0e10cSrcweir } else { 148cdf0e10cSrcweir this.disposeEnvironment(); 149cdf0e10cSrcweir } 150cdf0e10cSrcweir 151cdf0e10cSrcweir long st = System.currentTimeMillis(); 152cdf0e10cSrcweir boolean toLong = false; 153cdf0e10cSrcweir 154cdf0e10cSrcweir log.println("waiting for dialog to close"); 155cdf0e10cSrcweir 156cdf0e10cSrcweir while (eThread.isAlive() && !toLong) { 157cdf0e10cSrcweir //wait for dialog to close 158cdf0e10cSrcweir toLong = (System.currentTimeMillis()-st > 10000); 159cdf0e10cSrcweir } 160cdf0e10cSrcweir 161cdf0e10cSrcweir log.println("done"); 162cdf0e10cSrcweir 163cdf0e10cSrcweir try { 164cdf0e10cSrcweir if (eThread.isAlive()) { 165cdf0e10cSrcweir log.println("Interrupting Thread"); 166cdf0e10cSrcweir eThread.interrupt(); 167cdf0e10cSrcweir eThread.yield(); 168cdf0e10cSrcweir } 169cdf0e10cSrcweir } catch (Exception e) { 170cdf0e10cSrcweir // who cares ;-) 171cdf0e10cSrcweir } 172cdf0e10cSrcweir 173cdf0e10cSrcweir st = System.currentTimeMillis(); 174cdf0e10cSrcweir toLong = false; 175cdf0e10cSrcweir 176cdf0e10cSrcweir log.println("waiting for interruption to work"); 177cdf0e10cSrcweir 178cdf0e10cSrcweir while (eThread.isAlive() && !toLong) { 179cdf0e10cSrcweir //wait for dialog to close 180cdf0e10cSrcweir toLong = (System.currentTimeMillis()-st > 10000); 181cdf0e10cSrcweir } 182cdf0e10cSrcweir 183cdf0e10cSrcweir log.println("DialogThread alive: "+eThread.isAlive()); 184cdf0e10cSrcweir 185cdf0e10cSrcweir log.println("done"); 186cdf0e10cSrcweir 187cdf0e10cSrcweir } 188cdf0e10cSrcweir 189cdf0e10cSrcweir } 190cdf0e10cSrcweir 191cdf0e10cSrcweir 192