1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 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. 14 * 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). 20 * 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. 25 * 26 ************************************************************************/ 27 28 package ifc.form; 29 30 import lib.MultiMethodTest; 31 32 import com.sun.star.form.XReset; 33 import com.sun.star.form.XResetListener; 34 import com.sun.star.lang.EventObject; 35 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 46 */ 47 public class _XReset extends MultiMethodTest { 48 49 public static XReset oObj = null; 50 51 /** 52 * Indicates if listeners must approve restes requests or not. 53 */ 54 protected boolean approve = true; 55 /** 56 * Array of two elements, each of them indicates <code>resetted</code> 57 * call of appropriate listener. 58 */ 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. 63 */ 64 protected boolean approveReset[] = new boolean[2]; 65 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. 71 */ 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; 78 } 79 public void resetted ( EventObject oEvent ) { 80 resetted[0] = true; 81 } 82 } 83 84 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. 90 */ 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; 97 } 98 public void resetted ( EventObject oEvent ) { 99 resetted[1] = true; 100 } 101 } 102 103 /** 104 * Listener which is added in test 105 */ 106 protected XResetListener listener1 = new MyResetListener(); 107 /** 108 * Listener which is added in test 109 */ 110 protected XResetListener listener2 = new MyResetListener2(); 111 112 /** 113 * Just adds two reset listeners. <p> 114 * Status for it is set later in <code>reset</code> method test. 115 */ 116 public void _addResetListener() { 117 118 log.println("Testing addResetListener ..."); 119 oObj.addResetListener( listener2 ); 120 oObj.addResetListener( listener1 ); 121 122 } // finished _addResetListener() 123 124 /** 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> 139 */ 140 public void _reset() { 141 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])); 152 153 } // finished _reset 154 155 /** 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> 164 */ 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 174 175 return; 176 177 } // finished _removeResetListener() 178 179 /** 180 * Sleeps for 0.5 sec. to allow StarOffice to react on <code> 181 * reset</code> call. 182 */ 183 private void shortWait() { 184 try { 185 Thread.sleep(500) ; 186 } catch (InterruptedException e) { 187 log.println("While waiting :" + e) ; 188 } 189 } 190 191 192 } // finished class _XRefresh 193 194 195