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 .
21 import lib
.MultiMethodTest
;
23 import com
.sun
.star
.form
.XReset
;
24 import com
.sun
.star
.form
.XResetListener
;
25 import com
.sun
.star
.lang
.EventObject
;
28 * Testing <code>com.sun.star.form.XReset</code>
31 * <li><code> reset()</code></li>
32 * <li><code> addResetListener()</code></li>
33 * <li><code> removeResetListener()</code></li>
35 * Test is <b> NOT </b> multithread compliant. <p>
36 * @see com.sun.star.form.XReset
38 public class _XReset
extends MultiMethodTest
{
40 public static XReset oObj
= null;
43 * Indicates if listeners must approve reset requests or not.
45 protected boolean approve
= true;
47 * Array of two elements, each of them indicates <code>reset</code>
48 * call of appropriate listener.
50 protected boolean resetted
[] = new boolean[2];
52 * Array of two elements, each of them indicates
53 * <code>approveReset</code> call of appropriate listener.
55 protected boolean approveReset
[] = new boolean[2];
58 * The listener which sets flags (in array elements with index 0)
59 * on <code>reset</code> and
60 * <code>approveReset</code> events. It approves reset request
61 * depending on <code>approve</code> field.
63 protected class MyResetListener
implements XResetListener
{
64 public void disposing ( EventObject oEvent
) {}
65 public boolean approveReset ( EventObject oEvent
) {
66 approveReset
[0] = true;
67 //cancel the reset action
70 public void resetted ( EventObject oEvent
) {
77 * The listener which sets flags (in array elements with index 1)
78 * on <code>reset</code> and
79 * <code>approveReset</code> events. It approves reset request
80 * depending on <code>approve</code> field.
82 protected class MyResetListener2
implements XResetListener
{
83 public void disposing ( EventObject oEvent
) {}
84 public boolean approveReset ( EventObject oEvent
) {
85 approveReset
[1] = true;
86 //don't cancel the reset action
89 public void resetted ( EventObject oEvent
) {
95 * Listener which is added in test
97 protected XResetListener listener1
= new MyResetListener();
99 * Listener which is added in test
101 protected XResetListener listener2
= new MyResetListener2();
104 * Just adds two reset listeners. <p>
105 * Status for it is set later in <code>reset</code> method test.
107 public void _addResetListener() {
109 log
.println("Testing addResetListener ...");
110 oObj
.addResetListener( listener2
);
111 oObj
.addResetListener( listener1
);
113 } // finished _addResetListener()
116 * First calls <code>reset</code> method without approving
117 * the request, in this case only <code>approveReset</code>
118 * event must be called. Second calls <code>reset</code> with
119 * approving the request. In this case both listener's events
120 * must be called. <p>
121 * Has <b>OK</b> status for <code>reset</code> method if in
122 * the first case only <code>approveReset</code> method was
124 * Has <b>OK</b> status for <code>addResetListener</code> method
125 * if in the second case both listener's methods were called.<p>
126 * The following method tests are to be completed successfully before :
128 * <li> <code> addResetListener </code> : to have listeners added.</li>
131 public void _reset() {
133 executeMethod("addResetListener()");
134 log
.println("Testing reset() ...");
138 tRes
.tested("reset()", (approveReset
[0] && (! resetted
[0])));
142 tRes
.tested("addResetListener()", (approveReset
[1] && resetted
[1]));
147 * Removes the first listener, clears it's call flags, and
148 * calls <code>reset</code> method.<p>
149 * Has <b> OK </b> status if no methods of the listener removed
151 * The following method tests are to be completed successfully before :
153 * <li> <code> reset </code> : to test this method last. </li>
156 public void _removeResetListener() {
157 requiredMethod("reset()");
158 log
.println("Testing removeResetListener ...");
159 approveReset
[0] = resetted
[0] = false;
160 oObj
.removeResetListener(listener1
);
163 tRes
.tested("removeResetListener()", !approveReset
[0] && !resetted
[0]);
164 //removing the second listener here may avoid crashing the office
165 } // finished _removeResetListener()
168 } // finished class _XRefresh