Update ooo320-m1
[ooovba.git] / qadevOOo / tests / java / ifc / form / _XLoadable.java
blob6cb66b7c492b51769907851353aa9338d7ff25cd
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: _XLoadable.java,v $
10 * $Revision: 1.5 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 package ifc.form;
34 import lib.MultiMethodTest;
36 import com.sun.star.form.XLoadable;
38 /**
39 * Testing <code>com.sun.star.form.XLoadable</code>
40 * interface methods :
41 * <ul>
42 * <li><code> load()</code></li>
43 * <li><code> unload()</code></li>
44 * <li><code> reload()</code></li>
45 * <li><code> isLoaded()</code></li>
46 * <li><code> addLoadListener()</code></li>
47 * <li><code> removeLoadListener()</code></li>
48 * </ul> <p>
49 * Test is <b> NOT </b> multithread compilant. <p>
50 * @see com.sun.star.form.XLoadable
52 public class _XLoadable extends MultiMethodTest {
54 public XLoadable oObj = null;
56 /**
57 * Listener implementation which sets flags on appropriate method calls
59 protected class TestLoadListener implements com.sun.star.form.XLoadListener {
60 public boolean disposingCalled = false ;
61 public boolean loadedCalled = false ;
62 public boolean reloadedCalled = false ;
63 public boolean reloadingCalled = false ;
64 public boolean unloadedCalled = false ;
65 public boolean unloadingCalled = false ;
66 private java.io.PrintWriter log = null ;
68 public TestLoadListener(java.io.PrintWriter log) {
69 this.log = log ;
72 public void disposing(com.sun.star.lang.EventObject e) {
73 disposingCalled = true ;
74 log.println(" disposing was called.") ;
77 public void loaded(com.sun.star.lang.EventObject e) {
78 loadedCalled = true ;
79 log.println(" loaded was called.") ;
82 public void reloaded(com.sun.star.lang.EventObject e) {
83 reloadedCalled = true ;
84 log.println(" reloaded was called.") ;
87 public void reloading(com.sun.star.lang.EventObject e) {
88 reloadingCalled = true ;
89 log.println(" reloading was called.") ;
92 public void unloaded(com.sun.star.lang.EventObject e) {
93 unloadedCalled = true ;
94 log.println(" unloaded was called.") ;
97 public void unloading(com.sun.star.lang.EventObject e) {
98 unloadingCalled = true ;
99 log.println(" unloading was called.") ;
103 TestLoadListener loadListener = null ;
106 * Creates new listener.
108 public void before() {
109 loadListener = new TestLoadListener(log) ;
113 * Waits for 0.1 second. Used to get time for load completion.
115 private void shortWait() {
116 try {
117 Thread.sleep(100);
118 } catch (InterruptedException e) {}
122 * Loads the form. <p>
123 * Has <b> OK </b> status if <code>isLoaded()</code> returns
124 * <code>true</code> and listener method <code>loaded()</code>
125 * is called.
126 * The following method tests are to be completed successfully before :
127 * <ul>
128 * <li> <code> isLoaded() </code> : to be sure form is not loaded </li>
129 * <li> <code> addLoadListener() </code> : to check if this listener method
130 * is called. </li>
131 * </ul>
133 public void _load() {
134 requiredMethod("isLoaded()") ;
135 requiredMethod("addLoadListener()") ;
137 boolean result = true ;
138 oObj.load() ;
140 shortWait() ;
141 result = oObj.isLoaded() && loadListener.loadedCalled ;
143 tRes.tested("load()", result) ;
147 * Unloads the form. <p>
148 * Has <b> OK </b> status if <code>isLoaded()</code> returns
149 * <code>false</code> and listener method <code>unloaded()</code>
150 * is called.
151 * The following method tests are to be completed successfully before :
152 * <ul>
153 * <li> <code> reload() </code> : to be sure the form is loaded </li>
154 * <li> <code> addLoadListener() </code> : to check if this listener method
155 * is called. </li>
156 * </ul>
158 public void _unload() {
159 requiredMethod("reload()") ;
160 requiredMethod("addLoadListener()") ;
162 boolean result = true ;
163 oObj.unload() ;
165 shortWait() ;
166 result = !oObj.isLoaded() && loadListener.unloadedCalled ;
168 tRes.tested("unload()", result) ;
172 * Reloads the form. <p>
173 * Has <b> OK </b> status if <code>isLoaded()</code> returns
174 * <code>true</code> and listener method <code>reloaded()</code>
175 * is called.
176 * The following method tests are to be completed successfully before :
177 * <ul>
178 * <li> <code> load() </code> : to be sure form is loaded </li>
179 * <li> <code> addLoadListener() </code> : to check if this listener method
180 * is called. </li>
181 * </ul>
183 public void _reload() {
184 requiredMethod("load()") ;
185 requiredMethod("addLoadListener()") ;
187 boolean result = true ;
188 oObj.reload() ;
190 shortWait() ;
191 result = oObj.isLoaded() && loadListener.reloadedCalled;
193 tRes.tested("reload()", result) ;
197 * Checks if the component is already loaded. If yes it unloads
198 * it <p>
199 * Has <b> OK </b> status if finally <code>isLoaded()</code> method
200 * returns <code>false</code>.
202 public void _isLoaded() {
204 boolean isLoaded = oObj.isLoaded() ;
205 if (isLoaded) oObj.unload();
206 isLoaded = oObj.isLoaded() ;
208 tRes.tested("isLoaded()", !isLoaded) ;
212 * Adds a listener. If its methods are called or not is checked
213 * in other object methods. <p>
214 * Has <b> OK </b> status if no runtime exceptions occured.
216 public void _addLoadListener() {
218 boolean result = true ;
219 oObj.addLoadListener(loadListener) ;
221 tRes.tested("addLoadListener()", result) ;
225 * Removes the listener added before. <p>
226 * Has <b> OK </b> status if after <code>load()</code> call no
227 * listener methods were called. <p>
228 * The following method tests are to be completed successfully before :
229 * <ul>
230 * <li> <code> unload() </code> : to make this test run finally.</li>
231 * </ul>
233 public void _removeLoadListener() {
234 requiredMethod("unload()") ;
236 boolean result = true ;
237 oObj.removeLoadListener(loadListener) ;
238 loadListener.loadedCalled = false ;
239 oObj.load();
241 result = ! loadListener.loadedCalled ;
243 tRes.tested("removeLoadListener()", result) ;
246 protected void after() {
247 disposeEnvironment();