1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 package ifc.awt;
25 
26 import lib.MultiMethodTest;
27 
28 import com.sun.star.awt.SpinEvent;
29 import com.sun.star.awt.XSpinField;
30 import com.sun.star.awt.XSpinListener;
31 import com.sun.star.lang.EventObject;
32 
33 /**
34 * Testing <code>com.sun.star.awt.XSpinField</code>
35 * interface methods :
36 * <ul>
37 *  <li><code> addSpinListener()</code></li>
38 *  <li><code> removeSpinListener()</code></li>
39 *  <li><code> up()</code></li>
40 *  <li><code> down()</code></li>
41 *  <li><code> first()</code></li>
42 *  <li><code> last()</code></li>
43 *  <li><code> enableRepeat()</code></li>
44 * </ul> <p>
45 * Test is <b> NOT </b> multithread compilant. <p>
46 * @see com.sun.star.awt.XSpinField
47 */
48 public class _XSpinField extends MultiMethodTest {
49 
50     public XSpinField oObj = null;
51 
52     /**
53     * Listener implementation which set flags on appropriate
54     * listener methods calls.
55     */
56     protected class TestListener implements XSpinListener {
57         public boolean upFl = false ;
58         public boolean downFl = false ;
59         public boolean firstFl = false ;
60         public boolean lastFl = false ;
61 
up(SpinEvent e)62         public void up(SpinEvent e) {
63             upFl = true ;
64         }
down(SpinEvent e)65         public void down(SpinEvent e) {
66             downFl = true ;
67         }
first(SpinEvent e)68         public void first(SpinEvent e) {
69             firstFl = true ;
70         }
last(SpinEvent e)71         public void last(SpinEvent e) {
72             lastFl = true ;
73         }
disposing(EventObject e)74         public void disposing(EventObject e) {}
75     }
76 
77     private TestListener listener = new TestListener() ;
78 
79     /**
80     * Just adds a listener. <p>
81     * Has <b>OK</b> status if no runtime exceptions occured.
82     */
_addSpinListener()83     public void _addSpinListener() {
84         oObj.addSpinListener(listener) ;
85 
86         tRes.tested("addSpinListener()", true) ;
87     }
88 
89     /**
90     * Calls the method. <p>
91     * Has <b>OK</b> status if the appropriate listener method
92     * was called. <p>
93     * The following method tests are to be completed successfully before :
94     * <ul>
95     *  <li> <code> addSpinListener </code> </li>
96     * </ul>
97     */
_up()98     public void _up() {
99         requiredMethod("addSpinListener()") ;
100 
101         oObj.up() ;
102         shortWait();
103 
104         tRes.tested("up()", listener.upFl) ;
105     }
106 
107     /**
108     * Calls the method. <p>
109     * Has <b>OK</b> status if the appropriate listener method
110     * was called. <p>
111     * The following method tests are to be completed successfully before :
112     * <ul>
113     *  <li> <code> addSpinListener </code> </li>
114     * </ul>
115     */
_down()116     public void _down() {
117         requiredMethod("addSpinListener()") ;
118 
119         oObj.down() ;
120         shortWait();
121 
122         tRes.tested("down()", listener.downFl) ;
123     }
124 
125     /**
126     * Calls the method. <p>
127     * Has <b>OK</b> status if the appropriate listener method
128     * was called.<p>
129     * The following method tests are to be completed successfully before :
130     * <ul>
131     *  <li> <code> addSpinListener </code> </li>
132     * </ul>
133     */
_first()134     public void _first() {
135         requiredMethod("addSpinListener()") ;
136 
137         oObj.first() ;
138         shortWait();
139 
140         tRes.tested("first()", listener.firstFl) ;
141     }
142 
143     /**
144     * Calls the method. <p>
145     * Has <b>OK</b> status if the appropriate listener method
146     * was called.<p>
147     * The following method tests are to be completed successfully before :
148     * <ul>
149     *  <li> <code> addSpinListener </code> </li>
150     * </ul>
151     */
_last()152     public void _last() {
153         requiredMethod("addSpinListener()") ;
154 
155         oObj.last() ;
156         shortWait();
157 
158         tRes.tested("last()", listener.lastFl) ;
159     }
160 
161     /**
162     * Removes the listener, then calls <code>up</code> method and
163     * checks if te listener wasn't called. <p>
164     * Has <b>OK</b> status if listener wasn't called. <p>
165     * The following method tests are to be completed successfully before :
166     * <ul>
167     *  <li> <code> addSpinListener </code> </li>
168     *  <li> <code> up </code> </li>
169     *  <li> <code> down </code> </li>
170     *  <li> <code> first </code> </li>
171     *  <li> <code> last </code> </li>
172     * </ul>
173     */
_removeSpinListener()174     public void _removeSpinListener() {
175         requiredMethod("addSpinListener()") ;
176         executeMethod("up()") ;
177         executeMethod("down()") ;
178         executeMethod("first()") ;
179         executeMethod("last()") ;
180 
181         listener.upFl = false ;
182 
183         oObj.removeSpinListener(listener) ;
184 
185         oObj.up() ;
186 
187         tRes.tested("removeSpinListener()", !listener.upFl) ;
188     }
189 
190     /**
191     * Enables then disables repeating. <p>
192     * Has <b>OK</b> status if no runtime exceptions occured.
193     */
_enableRepeat()194     public void _enableRepeat() {
195         oObj.enableRepeat(true) ;
196         oObj.enableRepeat(false) ;
197 
198         tRes.tested("enableRepeat()", true) ;
199     }
200 
201     /**
202      * Waits for 0.5 sec to allow listener to be called.
203      */
shortWait()204     private void shortWait() {
205         try {
206             Thread.sleep(500);
207         }
208         catch (InterruptedException ex) {
209         }
210 
211     }
212 }
213