Version 3.6.0.4, tag libreoffice-3.6.0.4
[LibreOffice.git] / qadevOOo / tests / java / ifc / form / _XReset.java
blob324df29e99768c75e629d4bcc6a6909c58d29dd8
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
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.
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).
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.
26 ************************************************************************/
28 package ifc.form;
30 import lib.MultiMethodTest;
32 import com.sun.star.form.XReset;
33 import com.sun.star.form.XResetListener;
34 import com.sun.star.lang.EventObject;
36 /**
37 * Testing <code>com.sun.star.form.XReset</code>
38 * interface methods :
39 * <ul>
40 * <li><code> reset()</code></li>
41 * <li><code> addResetListener()</code></li>
42 * <li><code> removeResetListener()</code></li>
43 * </ul>
44 * Test is <b> NOT </b> multithread compilant. <p>
45 * @see com.sun.star.form.XReset
47 public class _XReset extends MultiMethodTest {
49 public static XReset oObj = null;
51 /**
52 * Indicates if listeners must approve restes requests or not.
54 protected boolean approve = true;
55 /**
56 * Array of two elements, each of them indicates <code>resetted</code>
57 * call of appropriate listener.
59 protected boolean resetted[] = new boolean[2];
60 /**
61 * Array of two elements, each of them indicates
62 * <code>approveReset</code> call of appropriate listener.
64 protected boolean approveReset[] = new boolean[2];
66 /**
67 * The listener which sets flags (in array elements with index 0)
68 * on <code>resetted</code> and
69 * <code>approveReset</code> events. It approves reset request
70 * depending on <code>approve</code> field.
72 protected class MyResetListener implements XResetListener {
73 public void disposing ( EventObject oEvent ) {}
74 public boolean approveReset ( EventObject oEvent ) {
75 approveReset[0] = true;
76 //cancel the reset action
77 return approve;
79 public void resetted ( EventObject oEvent ) {
80 resetted[0] = true;
85 /**
86 * The listener which sets flags (in array elements with index 1)
87 * on <code>resetted</code> and
88 * <code>approveReset</code> events. It approves reset request
89 * depending on <code>approve</code> field.
91 protected class MyResetListener2 implements XResetListener {
92 public void disposing ( EventObject oEvent ) {}
93 public boolean approveReset ( EventObject oEvent ) {
94 approveReset[1] = true;
95 //don't cancel the reset action
96 return true;
98 public void resetted ( EventObject oEvent ) {
99 resetted[1] = true;
104 * Listener which is added in test
106 protected XResetListener listener1 = new MyResetListener();
108 * Listener which is added in test
110 protected XResetListener listener2 = new MyResetListener2();
113 * Just adds two reset listeners. <p>
114 * Status for it is set later in <code>reset</code> method test.
116 public void _addResetListener() {
118 log.println("Testing addResetListener ...");
119 oObj.addResetListener( listener2 );
120 oObj.addResetListener( listener1 );
122 } // finished _addResetListener()
125 * First calls <code>reset</code> method without approving
126 * the request, in this case only <code>approveReset</code>
127 * event must be called. Second calls <code>reset</code> with
128 * approving the request. In this case both listener's events
129 * must be called. <p>
130 * Has <b>OK</b> status for <code>reset</code> method if in
131 * the first case only <code>approveReset</code> method was
132 * called. <p>
133 * Has <b>OK</b> status for <code>addResetListener</code> method
134 * if in the second case both listener's methods were called.<p>
135 * The following method tests are to be completed successfully before :
136 * <ul>
137 * <li> <code> addResetListener </code> : to have listeners added.</li>
138 * </ul>
140 public void _reset() {
142 executeMethod("addResetListener()");
143 log.println("Testing reset() ...");
144 approve = false;
145 oObj.reset();
146 shortWait();
147 tRes.tested("reset()", (approveReset[0] && (! resetted[0])));
148 approve = true;
149 oObj.reset();
150 shortWait();
151 tRes.tested("addResetListener()", (approveReset[1] && resetted[1]));
153 } // finished _reset
156 * Removes the first listener, clears it's call flags, and
157 * calls <code>reset</code> method.<p>
158 * Has <b> OK </b> status if no methods of the listener removed
159 * were called. <p>
160 * The following method tests are to be completed successfully before :
161 * <ul>
162 * <li> <code> reset </code> : to test this method last. </li>
163 * </ul>
165 public void _removeResetListener() {
166 requiredMethod("reset()");
167 log.println("Testing removeResetListener ...");
168 approveReset[0] = resetted[0] = false;
169 oObj.removeResetListener(listener1);
170 oObj.reset();
171 shortWait();
172 tRes.tested("removeResetListener()", !approveReset[0] && !resetted[0]);
173 //removing the second listener here may avoid crashing the office
175 return;
177 } // finished _removeResetListener()
180 * Sleeps for 0.5 sec. to allow StarOffice to react on <code>
181 * reset</code> call.
183 private void shortWait() {
184 try {
185 Thread.sleep(500) ;
186 } catch (InterruptedException e) {
187 log.println("While waiting :" + e) ;
192 } // finished class _XRefresh