1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir package ifc.awt; 29*cdf0e10cSrcweir 30*cdf0e10cSrcweir import lib.MultiMethodTest; 31*cdf0e10cSrcweir 32*cdf0e10cSrcweir import com.sun.star.awt.XDialog; 33*cdf0e10cSrcweir 34*cdf0e10cSrcweir /** 35*cdf0e10cSrcweir * Testing <code>com.sun.star.awt.XDialog</code> 36*cdf0e10cSrcweir * interface methods : 37*cdf0e10cSrcweir * <ul> 38*cdf0e10cSrcweir * <li><code> setTitle()</code></li> 39*cdf0e10cSrcweir * <li><code> getTitle()</code></li> 40*cdf0e10cSrcweir * <li><code> execute()</code></li> 41*cdf0e10cSrcweir * <li><code> endExecute()</code></li> 42*cdf0e10cSrcweir * </ul> <p> 43*cdf0e10cSrcweir * Test is <b> NOT </b> multithread compilant. <p> 44*cdf0e10cSrcweir * After test completion object environment has to be recreated. 45*cdf0e10cSrcweir * @see com.sun.star.awt.XDialog 46*cdf0e10cSrcweir */ 47*cdf0e10cSrcweir public class _XDialog extends MultiMethodTest { 48*cdf0e10cSrcweir 49*cdf0e10cSrcweir public XDialog oObj = null; 50*cdf0e10cSrcweir 51*cdf0e10cSrcweir /** 52*cdf0e10cSrcweir * As <code>execute()</code> method is a blocking call, 53*cdf0e10cSrcweir * then it must be executed in a separate thread. This 54*cdf0e10cSrcweir * thread class just call <code>execute</code> method 55*cdf0e10cSrcweir * of tested object. 56*cdf0e10cSrcweir */ 57*cdf0e10cSrcweir protected Thread execThread = new Thread( 58*cdf0e10cSrcweir new Runnable() { 59*cdf0e10cSrcweir public void run() { 60*cdf0e10cSrcweir oObj.execute() ; 61*cdf0e10cSrcweir } 62*cdf0e10cSrcweir }) ; 63*cdf0e10cSrcweir 64*cdf0e10cSrcweir /** 65*cdf0e10cSrcweir * Sets the title to some string. <p> 66*cdf0e10cSrcweir * Has <b>OK</b> status if no runtime exceptions occurs. 67*cdf0e10cSrcweir */ 68*cdf0e10cSrcweir public void _setTitle() { 69*cdf0e10cSrcweir 70*cdf0e10cSrcweir oObj.setTitle("XDialog test") ; 71*cdf0e10cSrcweir 72*cdf0e10cSrcweir tRes.tested("setTitle()", true) ; 73*cdf0e10cSrcweir } 74*cdf0e10cSrcweir 75*cdf0e10cSrcweir /** 76*cdf0e10cSrcweir * Gets the title and compares it to the value set in 77*cdf0e10cSrcweir * <code>setTitle</code> method test. <p> 78*cdf0e10cSrcweir * Has <b>OK</b> status is set/get values are equal. 79*cdf0e10cSrcweir * The following method tests are to be completed successfully before : 80*cdf0e10cSrcweir * <ul> 81*cdf0e10cSrcweir * <li> <code> setTitle </code> </li> 82*cdf0e10cSrcweir * </ul> 83*cdf0e10cSrcweir */ 84*cdf0e10cSrcweir public void _getTitle() { 85*cdf0e10cSrcweir requiredMethod("setTitle()") ; 86*cdf0e10cSrcweir 87*cdf0e10cSrcweir tRes.tested("getTitle()", 88*cdf0e10cSrcweir "XDialog test".equals(oObj.getTitle())) ; 89*cdf0e10cSrcweir } 90*cdf0e10cSrcweir 91*cdf0e10cSrcweir /** 92*cdf0e10cSrcweir * Starts the execution of dialog in a separate thread. 93*cdf0e10cSrcweir * As this call is blocking then the thread execution 94*cdf0e10cSrcweir * must not be finished. <p> 95*cdf0e10cSrcweir * Has <b>OK</b> status if thread wasn't finished and 96*cdf0e10cSrcweir * no exceptions occured. 97*cdf0e10cSrcweir */ 98*cdf0e10cSrcweir public void _execute() { 99*cdf0e10cSrcweir boolean result = true ; 100*cdf0e10cSrcweir 101*cdf0e10cSrcweir log.println("Starting execute() thread ...") ; 102*cdf0e10cSrcweir execThread.start() ; 103*cdf0e10cSrcweir 104*cdf0e10cSrcweir try { 105*cdf0e10cSrcweir execThread.join(200) ; 106*cdf0e10cSrcweir } catch (InterruptedException e) { 107*cdf0e10cSrcweir log.println("execute() thread was interrupted") ; 108*cdf0e10cSrcweir result = false ; 109*cdf0e10cSrcweir } 110*cdf0e10cSrcweir result &= execThread.isAlive() ; 111*cdf0e10cSrcweir 112*cdf0e10cSrcweir tRes.tested("execute()", result) ; 113*cdf0e10cSrcweir } 114*cdf0e10cSrcweir 115*cdf0e10cSrcweir /** 116*cdf0e10cSrcweir * Calls the method and checks if the execution thread 117*cdf0e10cSrcweir * where <code>execute()</code> method is running was 118*cdf0e10cSrcweir * finished. If <code>execute</code> method didn't return 119*cdf0e10cSrcweir * and still running then thread interrupted. <p> 120*cdf0e10cSrcweir * Has <b>OK</b> status if <code>execute</code> method 121*cdf0e10cSrcweir * call successfully retured. 122*cdf0e10cSrcweir * The following method tests are to be completed successfully before : 123*cdf0e10cSrcweir * <ul> 124*cdf0e10cSrcweir * <li> <code> execute </code> </li> 125*cdf0e10cSrcweir * </ul> 126*cdf0e10cSrcweir */ 127*cdf0e10cSrcweir public void _endExecute() { 128*cdf0e10cSrcweir requiredMethod("execute()") ; 129*cdf0e10cSrcweir 130*cdf0e10cSrcweir boolean result = true ; 131*cdf0e10cSrcweir 132*cdf0e10cSrcweir oObj.endExecute() ; 133*cdf0e10cSrcweir 134*cdf0e10cSrcweir try { 135*cdf0e10cSrcweir execThread.join(200) ; 136*cdf0e10cSrcweir } catch (InterruptedException e) { 137*cdf0e10cSrcweir log.println("execute() thread was interrupted") ; 138*cdf0e10cSrcweir result = false ; 139*cdf0e10cSrcweir } 140*cdf0e10cSrcweir 141*cdf0e10cSrcweir if (execThread.isAlive()) { 142*cdf0e10cSrcweir execThread.interrupt() ; 143*cdf0e10cSrcweir } 144*cdf0e10cSrcweir 145*cdf0e10cSrcweir result &= !execThread.isAlive() ; 146*cdf0e10cSrcweir 147*cdf0e10cSrcweir tRes.tested("endExecute()", result) ; 148*cdf0e10cSrcweir } 149*cdf0e10cSrcweir 150*cdf0e10cSrcweir /** 151*cdf0e10cSrcweir * Disposes object environment. 152*cdf0e10cSrcweir */ 153*cdf0e10cSrcweir public void after() { 154*cdf0e10cSrcweir disposeEnvironment() ; 155*cdf0e10cSrcweir } 156*cdf0e10cSrcweir } 157*cdf0e10cSrcweir 158*cdf0e10cSrcweir 159