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