bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / ifc / form / _XLoadable.java
blobf9f81b069a0b2db415c35fae7b171c78fa4a94c6
1 /*
2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 package ifc.form;
22 import lib.MultiMethodTest;
24 import com.sun.star.form.XLoadable;
26 /**
27 * Testing <code>com.sun.star.form.XLoadable</code>
28 * interface methods :
29 * <ul>
30 * <li><code> load()</code></li>
31 * <li><code> unload()</code></li>
32 * <li><code> reload()</code></li>
33 * <li><code> isLoaded()</code></li>
34 * <li><code> addLoadListener()</code></li>
35 * <li><code> removeLoadListener()</code></li>
36 * </ul> <p>
37 * Test is <b> NOT </b> multithread compilant. <p>
38 * @see com.sun.star.form.XLoadable
40 public class _XLoadable extends MultiMethodTest {
42 public XLoadable oObj = null;
44 /**
45 * Listener implementation which sets flags on appropriate method calls
47 protected class TestLoadListener implements com.sun.star.form.XLoadListener {
48 public boolean disposingCalled = false ;
49 public boolean loadedCalled = false ;
50 public boolean reloadedCalled = false ;
51 public boolean reloadingCalled = false ;
52 public boolean unloadedCalled = false ;
53 public boolean unloadingCalled = false ;
54 private java.io.PrintWriter log = null ;
56 public TestLoadListener(java.io.PrintWriter log) {
57 this.log = log ;
60 public void disposing(com.sun.star.lang.EventObject e) {
61 disposingCalled = true ;
62 log.println(" disposing was called.") ;
65 public void loaded(com.sun.star.lang.EventObject e) {
66 loadedCalled = true ;
67 log.println(" loaded was called.") ;
70 public void reloaded(com.sun.star.lang.EventObject e) {
71 reloadedCalled = true ;
72 log.println(" reloaded was called.") ;
75 public void reloading(com.sun.star.lang.EventObject e) {
76 reloadingCalled = true ;
77 log.println(" reloading was called.") ;
80 public void unloaded(com.sun.star.lang.EventObject e) {
81 unloadedCalled = true ;
82 log.println(" unloaded was called.") ;
85 public void unloading(com.sun.star.lang.EventObject e) {
86 unloadingCalled = true ;
87 log.println(" unloading was called.") ;
91 TestLoadListener loadListener = null ;
93 /**
94 * Creates new listener.
96 public void before() {
97 loadListener = new TestLoadListener(log) ;
101 * Waits for 0.1 second. Used to get time for load completion.
103 private void shortWait() {
104 try {
105 Thread.sleep(100);
106 } catch (InterruptedException e) {}
110 * Loads the form. <p>
111 * Has <b> OK </b> status if <code>isLoaded()</code> returns
112 * <code>true</code> and listener method <code>loaded()</code>
113 * is called.
114 * The following method tests are to be completed successfully before :
115 * <ul>
116 * <li> <code> isLoaded() </code> : to be sure form is not loaded </li>
117 * <li> <code> addLoadListener() </code> : to check if this listener method
118 * is called. </li>
119 * </ul>
121 public void _load() {
122 requiredMethod("isLoaded()") ;
123 requiredMethod("addLoadListener()") ;
125 boolean result = true ;
126 oObj.load() ;
128 shortWait() ;
129 result = oObj.isLoaded() && loadListener.loadedCalled ;
131 tRes.tested("load()", result) ;
135 * Unloads the form. <p>
136 * Has <b> OK </b> status if <code>isLoaded()</code> returns
137 * <code>false</code> and listener method <code>unloaded()</code>
138 * is called.
139 * The following method tests are to be completed successfully before :
140 * <ul>
141 * <li> <code> reload() </code> : to be sure the form is loaded </li>
142 * <li> <code> addLoadListener() </code> : to check if this listener method
143 * is called. </li>
144 * </ul>
146 public void _unload() {
147 requiredMethod("reload()") ;
148 requiredMethod("addLoadListener()") ;
150 boolean result = true ;
151 oObj.unload() ;
153 shortWait() ;
154 result = !oObj.isLoaded() && loadListener.unloadedCalled ;
156 tRes.tested("unload()", result) ;
160 * Reloads the form. <p>
161 * Has <b> OK </b> status if <code>isLoaded()</code> returns
162 * <code>true</code> and listener method <code>reloaded()</code>
163 * is called.
164 * The following method tests are to be completed successfully before :
165 * <ul>
166 * <li> <code> load() </code> : to be sure form is loaded </li>
167 * <li> <code> addLoadListener() </code> : to check if this listener method
168 * is called. </li>
169 * </ul>
171 public void _reload() {
172 requiredMethod("load()") ;
173 requiredMethod("addLoadListener()") ;
175 boolean result = true ;
176 oObj.reload() ;
178 shortWait() ;
179 result = oObj.isLoaded() && loadListener.reloadedCalled;
181 tRes.tested("reload()", result) ;
185 * Checks if the component is already loaded. If yes it unloads
186 * it <p>
187 * Has <b> OK </b> status if finally <code>isLoaded()</code> method
188 * returns <code>false</code>.
190 public void _isLoaded() {
192 boolean isLoaded = oObj.isLoaded() ;
193 if (isLoaded) oObj.unload();
194 isLoaded = oObj.isLoaded() ;
196 tRes.tested("isLoaded()", !isLoaded) ;
200 * Adds a listener. If its methods are called or not is checked
201 * in other object methods. <p>
202 * Has <b> OK </b> status if no runtime exceptions occurred.
204 public void _addLoadListener() {
206 boolean result = true ;
207 oObj.addLoadListener(loadListener) ;
209 tRes.tested("addLoadListener()", result) ;
213 * Removes the listener added before. <p>
214 * Has <b> OK </b> status if after <code>load()</code> call no
215 * listener methods were called. <p>
216 * The following method tests are to be completed successfully before :
217 * <ul>
218 * <li> <code> unload() </code> : to make this test run finally.</li>
219 * </ul>
221 public void _removeLoadListener() {
222 requiredMethod("unload()") ;
224 boolean result = true ;
225 oObj.removeLoadListener(loadListener) ;
226 loadListener.loadedCalled = false ;
227 oObj.load();
229 result = ! loadListener.loadedCalled ;
231 tRes.tested("removeLoadListener()", result) ;
234 protected void after() {
235 disposeEnvironment();