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.SpinEvent; 33*cdf0e10cSrcweir import com.sun.star.awt.XSpinField; 34*cdf0e10cSrcweir import com.sun.star.awt.XSpinListener; 35*cdf0e10cSrcweir import com.sun.star.lang.EventObject; 36*cdf0e10cSrcweir 37*cdf0e10cSrcweir /** 38*cdf0e10cSrcweir * Testing <code>com.sun.star.awt.XSpinField</code> 39*cdf0e10cSrcweir * interface methods : 40*cdf0e10cSrcweir * <ul> 41*cdf0e10cSrcweir * <li><code> addSpinListener()</code></li> 42*cdf0e10cSrcweir * <li><code> removeSpinListener()</code></li> 43*cdf0e10cSrcweir * <li><code> up()</code></li> 44*cdf0e10cSrcweir * <li><code> down()</code></li> 45*cdf0e10cSrcweir * <li><code> first()</code></li> 46*cdf0e10cSrcweir * <li><code> last()</code></li> 47*cdf0e10cSrcweir * <li><code> enableRepeat()</code></li> 48*cdf0e10cSrcweir * </ul> <p> 49*cdf0e10cSrcweir * Test is <b> NOT </b> multithread compilant. <p> 50*cdf0e10cSrcweir * @see com.sun.star.awt.XSpinField 51*cdf0e10cSrcweir */ 52*cdf0e10cSrcweir public class _XSpinField extends MultiMethodTest { 53*cdf0e10cSrcweir 54*cdf0e10cSrcweir public XSpinField oObj = null; 55*cdf0e10cSrcweir 56*cdf0e10cSrcweir /** 57*cdf0e10cSrcweir * Listener implementation which set flags on appropriate 58*cdf0e10cSrcweir * listener methods calls. 59*cdf0e10cSrcweir */ 60*cdf0e10cSrcweir protected class TestListener implements XSpinListener { 61*cdf0e10cSrcweir public boolean upFl = false ; 62*cdf0e10cSrcweir public boolean downFl = false ; 63*cdf0e10cSrcweir public boolean firstFl = false ; 64*cdf0e10cSrcweir public boolean lastFl = false ; 65*cdf0e10cSrcweir 66*cdf0e10cSrcweir public void up(SpinEvent e) { 67*cdf0e10cSrcweir upFl = true ; 68*cdf0e10cSrcweir } 69*cdf0e10cSrcweir public void down(SpinEvent e) { 70*cdf0e10cSrcweir downFl = true ; 71*cdf0e10cSrcweir } 72*cdf0e10cSrcweir public void first(SpinEvent e) { 73*cdf0e10cSrcweir firstFl = true ; 74*cdf0e10cSrcweir } 75*cdf0e10cSrcweir public void last(SpinEvent e) { 76*cdf0e10cSrcweir lastFl = true ; 77*cdf0e10cSrcweir } 78*cdf0e10cSrcweir public void disposing(EventObject e) {} 79*cdf0e10cSrcweir } 80*cdf0e10cSrcweir 81*cdf0e10cSrcweir private TestListener listener = new TestListener() ; 82*cdf0e10cSrcweir 83*cdf0e10cSrcweir /** 84*cdf0e10cSrcweir * Just adds a listener. <p> 85*cdf0e10cSrcweir * Has <b>OK</b> status if no runtime exceptions occured. 86*cdf0e10cSrcweir */ 87*cdf0e10cSrcweir public void _addSpinListener() { 88*cdf0e10cSrcweir oObj.addSpinListener(listener) ; 89*cdf0e10cSrcweir 90*cdf0e10cSrcweir tRes.tested("addSpinListener()", true) ; 91*cdf0e10cSrcweir } 92*cdf0e10cSrcweir 93*cdf0e10cSrcweir /** 94*cdf0e10cSrcweir * Calls the method. <p> 95*cdf0e10cSrcweir * Has <b>OK</b> status if the appropriate listener method 96*cdf0e10cSrcweir * was called. <p> 97*cdf0e10cSrcweir * The following method tests are to be completed successfully before : 98*cdf0e10cSrcweir * <ul> 99*cdf0e10cSrcweir * <li> <code> addSpinListener </code> </li> 100*cdf0e10cSrcweir * </ul> 101*cdf0e10cSrcweir */ 102*cdf0e10cSrcweir public void _up() { 103*cdf0e10cSrcweir requiredMethod("addSpinListener()") ; 104*cdf0e10cSrcweir 105*cdf0e10cSrcweir oObj.up() ; 106*cdf0e10cSrcweir shortWait(); 107*cdf0e10cSrcweir 108*cdf0e10cSrcweir tRes.tested("up()", listener.upFl) ; 109*cdf0e10cSrcweir } 110*cdf0e10cSrcweir 111*cdf0e10cSrcweir /** 112*cdf0e10cSrcweir * Calls the method. <p> 113*cdf0e10cSrcweir * Has <b>OK</b> status if the appropriate listener method 114*cdf0e10cSrcweir * was called. <p> 115*cdf0e10cSrcweir * The following method tests are to be completed successfully before : 116*cdf0e10cSrcweir * <ul> 117*cdf0e10cSrcweir * <li> <code> addSpinListener </code> </li> 118*cdf0e10cSrcweir * </ul> 119*cdf0e10cSrcweir */ 120*cdf0e10cSrcweir public void _down() { 121*cdf0e10cSrcweir requiredMethod("addSpinListener()") ; 122*cdf0e10cSrcweir 123*cdf0e10cSrcweir oObj.down() ; 124*cdf0e10cSrcweir shortWait(); 125*cdf0e10cSrcweir 126*cdf0e10cSrcweir tRes.tested("down()", listener.downFl) ; 127*cdf0e10cSrcweir } 128*cdf0e10cSrcweir 129*cdf0e10cSrcweir /** 130*cdf0e10cSrcweir * Calls the method. <p> 131*cdf0e10cSrcweir * Has <b>OK</b> status if the appropriate listener method 132*cdf0e10cSrcweir * was called.<p> 133*cdf0e10cSrcweir * The following method tests are to be completed successfully before : 134*cdf0e10cSrcweir * <ul> 135*cdf0e10cSrcweir * <li> <code> addSpinListener </code> </li> 136*cdf0e10cSrcweir * </ul> 137*cdf0e10cSrcweir */ 138*cdf0e10cSrcweir public void _first() { 139*cdf0e10cSrcweir requiredMethod("addSpinListener()") ; 140*cdf0e10cSrcweir 141*cdf0e10cSrcweir oObj.first() ; 142*cdf0e10cSrcweir shortWait(); 143*cdf0e10cSrcweir 144*cdf0e10cSrcweir tRes.tested("first()", listener.firstFl) ; 145*cdf0e10cSrcweir } 146*cdf0e10cSrcweir 147*cdf0e10cSrcweir /** 148*cdf0e10cSrcweir * Calls the method. <p> 149*cdf0e10cSrcweir * Has <b>OK</b> status if the appropriate listener method 150*cdf0e10cSrcweir * was called.<p> 151*cdf0e10cSrcweir * The following method tests are to be completed successfully before : 152*cdf0e10cSrcweir * <ul> 153*cdf0e10cSrcweir * <li> <code> addSpinListener </code> </li> 154*cdf0e10cSrcweir * </ul> 155*cdf0e10cSrcweir */ 156*cdf0e10cSrcweir public void _last() { 157*cdf0e10cSrcweir requiredMethod("addSpinListener()") ; 158*cdf0e10cSrcweir 159*cdf0e10cSrcweir oObj.last() ; 160*cdf0e10cSrcweir shortWait(); 161*cdf0e10cSrcweir 162*cdf0e10cSrcweir tRes.tested("last()", listener.lastFl) ; 163*cdf0e10cSrcweir } 164*cdf0e10cSrcweir 165*cdf0e10cSrcweir /** 166*cdf0e10cSrcweir * Removes the listener, then calls <code>up</code> method and 167*cdf0e10cSrcweir * checks if te listener wasn't called. <p> 168*cdf0e10cSrcweir * Has <b>OK</b> status if listener wasn't called. <p> 169*cdf0e10cSrcweir * The following method tests are to be completed successfully before : 170*cdf0e10cSrcweir * <ul> 171*cdf0e10cSrcweir * <li> <code> addSpinListener </code> </li> 172*cdf0e10cSrcweir * <li> <code> up </code> </li> 173*cdf0e10cSrcweir * <li> <code> down </code> </li> 174*cdf0e10cSrcweir * <li> <code> first </code> </li> 175*cdf0e10cSrcweir * <li> <code> last </code> </li> 176*cdf0e10cSrcweir * </ul> 177*cdf0e10cSrcweir */ 178*cdf0e10cSrcweir public void _removeSpinListener() { 179*cdf0e10cSrcweir requiredMethod("addSpinListener()") ; 180*cdf0e10cSrcweir executeMethod("up()") ; 181*cdf0e10cSrcweir executeMethod("down()") ; 182*cdf0e10cSrcweir executeMethod("first()") ; 183*cdf0e10cSrcweir executeMethod("last()") ; 184*cdf0e10cSrcweir 185*cdf0e10cSrcweir listener.upFl = false ; 186*cdf0e10cSrcweir 187*cdf0e10cSrcweir oObj.removeSpinListener(listener) ; 188*cdf0e10cSrcweir 189*cdf0e10cSrcweir oObj.up() ; 190*cdf0e10cSrcweir 191*cdf0e10cSrcweir tRes.tested("removeSpinListener()", !listener.upFl) ; 192*cdf0e10cSrcweir } 193*cdf0e10cSrcweir 194*cdf0e10cSrcweir /** 195*cdf0e10cSrcweir * Enables then disables repeating. <p> 196*cdf0e10cSrcweir * Has <b>OK</b> status if no runtime exceptions occured. 197*cdf0e10cSrcweir */ 198*cdf0e10cSrcweir public void _enableRepeat() { 199*cdf0e10cSrcweir oObj.enableRepeat(true) ; 200*cdf0e10cSrcweir oObj.enableRepeat(false) ; 201*cdf0e10cSrcweir 202*cdf0e10cSrcweir tRes.tested("enableRepeat()", true) ; 203*cdf0e10cSrcweir } 204*cdf0e10cSrcweir 205*cdf0e10cSrcweir /** 206*cdf0e10cSrcweir * Waits for 0.5 sec to allow listener to be called. 207*cdf0e10cSrcweir */ 208*cdf0e10cSrcweir private void shortWait() { 209*cdf0e10cSrcweir try { 210*cdf0e10cSrcweir Thread.sleep(500); 211*cdf0e10cSrcweir } 212*cdf0e10cSrcweir catch (InterruptedException ex) { 213*cdf0e10cSrcweir } 214*cdf0e10cSrcweir 215*cdf0e10cSrcweir } 216*cdf0e10cSrcweir } 217