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.form;
25 
26 
27 import lib.MultiMethodTest;
28 
29 import com.sun.star.form.XLoadable;
30 
31 /**
32 * Testing <code>com.sun.star.form.XLoadable</code>
33 * interface methods :
34 * <ul>
35 *  <li><code> load()</code></li>
36 *  <li><code> unload()</code></li>
37 *  <li><code> reload()</code></li>
38 *  <li><code> isLoaded()</code></li>
39 *  <li><code> addLoadListener()</code></li>
40 *  <li><code> removeLoadListener()</code></li>
41 * </ul> <p>
42 * Test is <b> NOT </b> multithread compilant. <p>
43 * @see com.sun.star.form.XLoadable
44 */
45 public class _XLoadable extends MultiMethodTest {
46 
47     public XLoadable oObj = null;
48 
49     /**
50     * Listener implementation which sets flags on appropriate method calls
51     */
52     protected class TestLoadListener implements com.sun.star.form.XLoadListener {
53         public boolean disposingCalled = false ;
54         public boolean loadedCalled = false ;
55         public boolean reloadedCalled = false ;
56         public boolean reloadingCalled = false ;
57         public boolean unloadedCalled = false ;
58         public boolean unloadingCalled = false ;
59         private java.io.PrintWriter log = null ;
60 
TestLoadListener(java.io.PrintWriter log)61         public TestLoadListener(java.io.PrintWriter log) {
62             this.log = log ;
63         }
64 
disposing(com.sun.star.lang.EventObject e)65         public void disposing(com.sun.star.lang.EventObject e) {
66             disposingCalled = true ;
67             log.println(" disposing was called.") ;
68         }
69 
loaded(com.sun.star.lang.EventObject e)70         public void loaded(com.sun.star.lang.EventObject e) {
71             loadedCalled = true ;
72             log.println(" loaded was called.") ;
73         }
74 
reloaded(com.sun.star.lang.EventObject e)75         public void reloaded(com.sun.star.lang.EventObject e) {
76             reloadedCalled = true ;
77             log.println(" reloaded was called.") ;
78         }
79 
reloading(com.sun.star.lang.EventObject e)80         public void reloading(com.sun.star.lang.EventObject e) {
81             reloadingCalled = true ;
82             log.println(" reloading was called.") ;
83         }
84 
unloaded(com.sun.star.lang.EventObject e)85         public void unloaded(com.sun.star.lang.EventObject e) {
86             unloadedCalled = true ;
87             log.println(" unloaded was called.") ;
88         }
89 
unloading(com.sun.star.lang.EventObject e)90         public void unloading(com.sun.star.lang.EventObject e) {
91             unloadingCalled = true ;
92             log.println(" unloading was called.") ;
93         }
94     }
95 
96     TestLoadListener loadListener = null ;
97 
98     /**
99     * Creates new listener.
100     */
before()101     public void before() {
102         loadListener = new TestLoadListener(log) ;
103     }
104 
105     /**
106      * Waits for 0.1 second. Used to get time for load completion.
107      */
shortWait()108     private void shortWait() {
109         try {
110             Thread.sleep(100);
111         } catch (InterruptedException e) {}
112     }
113 
114     /**
115     * Loads the form. <p>
116     * Has <b> OK </b> status if <code>isLoaded()</code> returns
117     * <code>true</code> and listener method <code>loaded()</code>
118     * is called.
119     * The following method tests are to be completed successfully before :
120     * <ul>
121     *  <li> <code> isLoaded() </code> : to be sure form is not loaded </li>
122     *  <li> <code> addLoadListener() </code> : to check if this listener method
123     *  is called. </li>
124     * </ul>
125     */
_load()126     public void _load() {
127         requiredMethod("isLoaded()") ;
128         requiredMethod("addLoadListener()") ;
129 
130         boolean result = true ;
131         oObj.load() ;
132 
133         shortWait() ;
134         result = oObj.isLoaded() && loadListener.loadedCalled ;
135 
136         tRes.tested("load()", result) ;
137     }
138 
139     /**
140     * Unloads the form. <p>
141     * Has <b> OK </b> status if <code>isLoaded()</code> returns
142     * <code>false</code> and listener method <code>unloaded()</code>
143     * is called.
144     * The following method tests are to be completed successfully before :
145     * <ul>
146     *  <li> <code> reload() </code> : to be sure the form is loaded </li>
147     *  <li> <code> addLoadListener() </code> : to check if this listener method
148     *  is called. </li>
149     * </ul>
150     */
_unload()151     public void _unload() {
152         requiredMethod("reload()") ;
153         requiredMethod("addLoadListener()") ;
154 
155         boolean result = true ;
156         oObj.unload() ;
157 
158         shortWait() ;
159         result = !oObj.isLoaded() && loadListener.unloadedCalled ;
160 
161         tRes.tested("unload()", result) ;
162     }
163 
164     /**
165     * Reloads the form. <p>
166     * Has <b> OK </b> status if <code>isLoaded()</code> returns
167     * <code>true</code> and listener method <code>reloaded()</code>
168     * is called.
169     * The following method tests are to be completed successfully before :
170     * <ul>
171     *  <li> <code> load() </code> : to be sure form is loaded </li>
172     *  <li> <code> addLoadListener() </code> : to check if this listener method
173     *  is called. </li>
174     * </ul>
175     */
_reload()176     public void _reload() {
177         requiredMethod("load()") ;
178         requiredMethod("addLoadListener()") ;
179 
180         boolean result = true ;
181         oObj.reload() ;
182 
183         shortWait() ;
184         result = oObj.isLoaded() && loadListener.reloadedCalled;
185 
186         tRes.tested("reload()", result) ;
187     }
188 
189     /**
190     * Checks if the component is already loaded. If yes it unloads
191     * it <p>
192     * Has <b> OK </b> status if finally <code>isLoaded()</code> method
193     * returns <code>false</code>.
194     */
_isLoaded()195     public void _isLoaded() {
196 
197         boolean isLoaded = oObj.isLoaded() ;
198         if (isLoaded) oObj.unload();
199         isLoaded = oObj.isLoaded() ;
200 
201         tRes.tested("isLoaded()", !isLoaded) ;
202     }
203 
204     /**
205     * Adds a listener. If its methods are called or not is checked
206     * in other object methods. <p>
207     * Has <b> OK </b> status if no runtime exceptions occured.
208     */
_addLoadListener()209     public void _addLoadListener() {
210 
211         boolean result = true ;
212         oObj.addLoadListener(loadListener) ;
213 
214         tRes.tested("addLoadListener()", result) ;
215     }
216 
217     /**
218     * Removes the listener added before. <p>
219     * Has <b> OK </b> status if after <code>load()</code> call no
220     * listener methods were called. <p>
221     * The following method tests are to be completed successfully before :
222     * <ul>
223     *  <li> <code> unload() </code> : to make this test run finally.</li>
224     * </ul>
225     */
_removeLoadListener()226     public void _removeLoadListener() {
227         requiredMethod("unload()") ;
228 
229         boolean result = true ;
230         oObj.removeLoadListener(loadListener) ;
231         loadListener.loadedCalled = false ;
232         oObj.load();
233 
234         result = ! loadListener.loadedCalled ;
235 
236         tRes.tested("removeLoadListener()", result) ;
237     }
238 
after()239     protected void after() {
240         disposeEnvironment();
241     }
242 }
243 
244