1*ef39d40dSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*ef39d40dSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*ef39d40dSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*ef39d40dSAndrew Rist  * distributed with this work for additional information
6*ef39d40dSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*ef39d40dSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*ef39d40dSAndrew Rist  * "License"); you may not use this file except in compliance
9*ef39d40dSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*ef39d40dSAndrew Rist  *
11*ef39d40dSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*ef39d40dSAndrew Rist  *
13*ef39d40dSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*ef39d40dSAndrew Rist  * software distributed under the License is distributed on an
15*ef39d40dSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*ef39d40dSAndrew Rist  * KIND, either express or implied.  See the License for the
17*ef39d40dSAndrew Rist  * specific language governing permissions and limitations
18*ef39d40dSAndrew Rist  * under the License.
19*ef39d40dSAndrew Rist  *
20*ef39d40dSAndrew Rist  *************************************************************/
21*ef39d40dSAndrew Rist 
22*ef39d40dSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir package ifc.script;
25cdf0e10cSrcweir 
26cdf0e10cSrcweir import lib.MultiMethodTest;
27cdf0e10cSrcweir 
28cdf0e10cSrcweir import com.sun.star.lang.EventObject;
29cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory;
30cdf0e10cSrcweir import com.sun.star.script.ScriptEvent;
31cdf0e10cSrcweir import com.sun.star.script.ScriptEventDescriptor;
32cdf0e10cSrcweir import com.sun.star.script.XEventAttacherManager;
33cdf0e10cSrcweir import com.sun.star.script.XScriptListener;
34cdf0e10cSrcweir 
35cdf0e10cSrcweir /**
36cdf0e10cSrcweir * Testing <code>com.sun.star.script.XEventAttacherManager</code>
37cdf0e10cSrcweir * interface methods :
38cdf0e10cSrcweir * <ul>
39cdf0e10cSrcweir *  <li><code> registerScriptEvent()</code></li>
40cdf0e10cSrcweir *  <li><code> registerScriptEvents()</code></li>
41cdf0e10cSrcweir *  <li><code> revokeScriptEvent()</code></li>
42cdf0e10cSrcweir *  <li><code> revokeScriptEvents()</code></li>
43cdf0e10cSrcweir *  <li><code> insertEntry()</code></li>
44cdf0e10cSrcweir *  <li><code> removeEntry()</code></li>
45cdf0e10cSrcweir *  <li><code> getScriptEvents()</code></li>
46cdf0e10cSrcweir *  <li><code> attach()</code></li>
47cdf0e10cSrcweir *  <li><code> detach()</code></li>
48cdf0e10cSrcweir *  <li><code> addScriptListener()</code></li>
49cdf0e10cSrcweir *  <li><code> removeScriptListener()</code></li>
50cdf0e10cSrcweir * </ul> <p>
51cdf0e10cSrcweir * @see com.sun.star.script.XEventAttacherManager
52cdf0e10cSrcweir */
53cdf0e10cSrcweir public class _XEventAttacherManager extends MultiMethodTest {
54cdf0e10cSrcweir 
55cdf0e10cSrcweir     /**
56cdf0e10cSrcweir      * oObj filled by MultiMethodTest
57cdf0e10cSrcweir      */
58cdf0e10cSrcweir     public XEventAttacherManager oObj = null;
59cdf0e10cSrcweir 
60cdf0e10cSrcweir     int index;
61cdf0e10cSrcweir 
62cdf0e10cSrcweir     /**
63cdf0e10cSrcweir     * Test calls the method and stores index of new entry. <p>
64cdf0e10cSrcweir     * Has <b> OK </b> status if the method successfully returns
65cdf0e10cSrcweir     * and no exceptions were thrown. <p>
66cdf0e10cSrcweir     */
_insertEntry()67cdf0e10cSrcweir     public void _insertEntry() {
68cdf0e10cSrcweir         index = 0;
69cdf0e10cSrcweir         try {
70cdf0e10cSrcweir             oObj.insertEntry(index);
71cdf0e10cSrcweir             tRes.tested("insertEntry()", true);
72cdf0e10cSrcweir         } catch (com.sun.star.lang.IllegalArgumentException e) {
73cdf0e10cSrcweir             log.println("insertEntry(" + index
74cdf0e10cSrcweir                     + ") throws unexpected exception "
75cdf0e10cSrcweir                     + e.getMessage());
76cdf0e10cSrcweir             e.printStackTrace(log);
77cdf0e10cSrcweir             tRes.tested("insertEntry()", false);
78cdf0e10cSrcweir         }
79cdf0e10cSrcweir     }
80cdf0e10cSrcweir 
81cdf0e10cSrcweir     ScriptEventDescriptor desc;
82cdf0e10cSrcweir 
83cdf0e10cSrcweir     /**
84cdf0e10cSrcweir     * Test creates <code>ScriptEventDescriptor</code>, registers
85cdf0e10cSrcweir     * the script event and stores the descriptor. <p>
86cdf0e10cSrcweir     * Has <b> OK </b> status if the method successfully returns
87cdf0e10cSrcweir     * and no exceptions were thrown. <p>
88cdf0e10cSrcweir     * The following method tests are to be completed successfully before :
89cdf0e10cSrcweir     * <ul>
90cdf0e10cSrcweir     *  <li> <code> insertEntry() </code> : to have entry's index</li>
91cdf0e10cSrcweir     * </ul>
92cdf0e10cSrcweir     * @see com.sun.star.script.ScriptEventDescriptor
93cdf0e10cSrcweir     */
_registerScriptEvent()94cdf0e10cSrcweir     public void _registerScriptEvent() {
95cdf0e10cSrcweir         requiredMethod("insertEntry()");
96cdf0e10cSrcweir         desc = new ScriptEventDescriptor(
97cdf0e10cSrcweir                     "XEventListener1",
98cdf0e10cSrcweir                     "disposing", "", "Basic", "");
99cdf0e10cSrcweir 
100cdf0e10cSrcweir         try {
101cdf0e10cSrcweir             oObj.registerScriptEvent(index, desc);
102cdf0e10cSrcweir             tRes.tested("registerScriptEvent()", true);
103cdf0e10cSrcweir         } catch (com.sun.star.lang.IllegalArgumentException e) {
104cdf0e10cSrcweir             log.println("registerScriptEvent() throws unexpected exception "
105cdf0e10cSrcweir                     + e.getMessage());
106cdf0e10cSrcweir             e.printStackTrace(log);
107cdf0e10cSrcweir             tRes.tested("registerScriptEvent()", false);
108cdf0e10cSrcweir         }
109cdf0e10cSrcweir     }
110cdf0e10cSrcweir 
111cdf0e10cSrcweir     ScriptEventDescriptor descs[];
112cdf0e10cSrcweir 
113cdf0e10cSrcweir     /**
114cdf0e10cSrcweir     * Test creates array of <code>ScriptEventDescriptor</code>, registers
115cdf0e10cSrcweir     * this script events and stores the descriptors. <p>
116cdf0e10cSrcweir     * Has <b> OK </b> status if the method successfully returns
117cdf0e10cSrcweir     * and no exceptions were thrown. <p>
118cdf0e10cSrcweir     * The following method tests are to be completed successfully before :
119cdf0e10cSrcweir     * <ul>
120cdf0e10cSrcweir     *  <li> <code> insertEntry() </code> : to have entry's index</li>
121cdf0e10cSrcweir     * </ul>
122cdf0e10cSrcweir     * @see com.sun.star.script.ScriptEventDescriptor
123cdf0e10cSrcweir     */
_registerScriptEvents()124cdf0e10cSrcweir     public void _registerScriptEvents() {
125cdf0e10cSrcweir         requiredMethod("insertEntry()");
126cdf0e10cSrcweir         descs = new ScriptEventDescriptor[] {
127cdf0e10cSrcweir             new ScriptEventDescriptor(
128cdf0e10cSrcweir                     "XEventListener2",
129cdf0e10cSrcweir                     "disposing", "", "Basic", ""),
130cdf0e10cSrcweir             new ScriptEventDescriptor(
131cdf0e10cSrcweir                     "XEventListener3",
132cdf0e10cSrcweir                     "disposing", "", "Basic", "")
133cdf0e10cSrcweir         };
134cdf0e10cSrcweir 
135cdf0e10cSrcweir         try {
136cdf0e10cSrcweir             oObj.registerScriptEvents(index, descs);
137cdf0e10cSrcweir             tRes.tested("registerScriptEvents()", true);
138cdf0e10cSrcweir         } catch (com.sun.star.lang.IllegalArgumentException e) {
139cdf0e10cSrcweir             log.println("registerScriptEvents() throws unexpected exception "
140cdf0e10cSrcweir                     + e.getMessage());
141cdf0e10cSrcweir             e.printStackTrace(log);
142cdf0e10cSrcweir             tRes.tested("registerScriptEvents()", false);
143cdf0e10cSrcweir         }
144cdf0e10cSrcweir     }
145cdf0e10cSrcweir 
146cdf0e10cSrcweir     /**
147cdf0e10cSrcweir     * Test calls the method and checks returned value. <p>
148cdf0e10cSrcweir     * Has <b> OK </b> status if returned array of descriptors contains
149cdf0e10cSrcweir     * array of descriptors registered by methods <code>registerScriptEvents</code>
150cdf0e10cSrcweir     * and <code>registerScriptEvent</code> and no exceptions were thrown. <p>
151cdf0e10cSrcweir     * The following method tests are to be completed successfully before :
152cdf0e10cSrcweir     * <ul>
153cdf0e10cSrcweir     *  <li> <code> registerScriptEvent() </code> :
154cdf0e10cSrcweir     *   to have registered descriptor </li>
155cdf0e10cSrcweir     *  <li> <code> registerScriptEvents() </code> :
156cdf0e10cSrcweir     *   to have registered descriptors </li>
157cdf0e10cSrcweir     * </ul>
158cdf0e10cSrcweir     */
_getScriptEvents()159cdf0e10cSrcweir     public void _getScriptEvents() {
160cdf0e10cSrcweir         requiredMethod("registerScriptEvent()");
161cdf0e10cSrcweir         requiredMethod("registerScriptEvents()");
162cdf0e10cSrcweir 
163cdf0e10cSrcweir         ScriptEventDescriptor[] res;
164cdf0e10cSrcweir 
165cdf0e10cSrcweir         try {
166cdf0e10cSrcweir             res = oObj.getScriptEvents(index);
167cdf0e10cSrcweir         } catch (com.sun.star.lang.IllegalArgumentException e) {
168cdf0e10cSrcweir             log.println("registerScriptEvents() throws unexpected exception "
169cdf0e10cSrcweir                     + e.getMessage());
170cdf0e10cSrcweir             e.printStackTrace(log);
171cdf0e10cSrcweir             tRes.tested("registerScriptEvents()", false);
172cdf0e10cSrcweir             return;
173cdf0e10cSrcweir         }
174cdf0e10cSrcweir 
175cdf0e10cSrcweir         // checking the desc and descs are in script events
176cdf0e10cSrcweir         tRes.tested("getScriptEvents()",
177cdf0e10cSrcweir                 contains(res, desc) && containsArray(res, descs));
178cdf0e10cSrcweir 
179cdf0e10cSrcweir         log.println("Script events :") ;
180cdf0e10cSrcweir         printEvents(res) ;
181cdf0e10cSrcweir     }
182cdf0e10cSrcweir 
183cdf0e10cSrcweir     /**
184cdf0e10cSrcweir      * Method checks that array of descriptors contains the concrete desciptor.
185cdf0e10cSrcweir      * @param container the array of descriptors
186cdf0e10cSrcweir      * @param evt the descriptor which presence in the array is checked
187cdf0e10cSrcweir      * @return true if the descriptor presence in the array
188cdf0e10cSrcweir      */
contains(ScriptEventDescriptor[] container, ScriptEventDescriptor evt)189cdf0e10cSrcweir     boolean contains(ScriptEventDescriptor[] container,
190cdf0e10cSrcweir             ScriptEventDescriptor evt) {
191cdf0e10cSrcweir         for (int i = 0; i < container.length; i++) {
192cdf0e10cSrcweir             if (equal(container[i], evt)) {
193cdf0e10cSrcweir                 return true;
194cdf0e10cSrcweir             }
195cdf0e10cSrcweir         }
196cdf0e10cSrcweir 
197cdf0e10cSrcweir         return false;
198cdf0e10cSrcweir     }
199cdf0e10cSrcweir 
200cdf0e10cSrcweir     /**
201cdf0e10cSrcweir      * Method checks that one array of descriptors contains
202cdf0e10cSrcweir      * another array of descriptors.
203cdf0e10cSrcweir      * @param container the array of descriptors
204cdf0e10cSrcweir      * @param events the array of descriptors which presence
205cdf0e10cSrcweir      * in array <code>container</code> is checked
206cdf0e10cSrcweir      * @return true if the array <code>events</code> contains in the array
207cdf0e10cSrcweir      * <code>container</code>
208cdf0e10cSrcweir      */
containsArray(ScriptEventDescriptor[] container, ScriptEventDescriptor[] events)209cdf0e10cSrcweir     boolean containsArray(ScriptEventDescriptor[] container,
210cdf0e10cSrcweir             ScriptEventDescriptor[] events) {
211cdf0e10cSrcweir         for (int i = 0; i < events.length; i++) {
212cdf0e10cSrcweir             if (!contains(container, events[i])) {
213cdf0e10cSrcweir                 return false;
214cdf0e10cSrcweir             }
215cdf0e10cSrcweir         }
216cdf0e10cSrcweir 
217cdf0e10cSrcweir         return true;
218cdf0e10cSrcweir     }
219cdf0e10cSrcweir 
220cdf0e10cSrcweir     /**
221cdf0e10cSrcweir      * Compares descriptor <code>evt1</code> to descriptor <code>evt2</code>.
222cdf0e10cSrcweir      * Two descriptors are considered equal if all their fields are equal.
223cdf0e10cSrcweir      * @return true if the argument is not <code>null</code> and
224cdf0e10cSrcweir      * the descriptors are equal; false otherwise
225cdf0e10cSrcweir      */
equal(ScriptEventDescriptor evt1, ScriptEventDescriptor evt2)226cdf0e10cSrcweir     boolean equal(ScriptEventDescriptor evt1,
227cdf0e10cSrcweir             ScriptEventDescriptor evt2) {
228cdf0e10cSrcweir         return evt1.ListenerType.equals(evt2.ListenerType)
229cdf0e10cSrcweir             && evt1.EventMethod.equals(evt2.EventMethod)
230cdf0e10cSrcweir             && evt1.ScriptType.equals(evt2.ScriptType)
231cdf0e10cSrcweir             && evt1.ScriptCode.equals(evt2.ScriptCode)
232cdf0e10cSrcweir             && evt1.AddListenerParam.equals(evt2.AddListenerParam);
233cdf0e10cSrcweir     }
234cdf0e10cSrcweir 
235cdf0e10cSrcweir     /**
236cdf0e10cSrcweir      * Prints fields of descriptor <code>evt</code> to log.
237cdf0e10cSrcweir      * @param evt the descriptor that needs to be printed to log
238cdf0e10cSrcweir      */
printEvent(ScriptEventDescriptor evt)239cdf0e10cSrcweir     void printEvent(ScriptEventDescriptor evt) {
240cdf0e10cSrcweir         if (evt == null) {
241cdf0e10cSrcweir             log.println("null");
242cdf0e10cSrcweir         } else {
243cdf0e10cSrcweir             log.println("\"" + evt.ListenerType + "\",\""
244cdf0e10cSrcweir                      + evt.EventMethod + "\",\""
245cdf0e10cSrcweir                      + evt.ScriptType + "\",\""
246cdf0e10cSrcweir                      + evt.ScriptCode + "\",\""
247cdf0e10cSrcweir                      + evt.AddListenerParam + "\"");
248cdf0e10cSrcweir         }
249cdf0e10cSrcweir     }
250cdf0e10cSrcweir 
251cdf0e10cSrcweir     /**
252cdf0e10cSrcweir      * Prints the descriptors to log.
253cdf0e10cSrcweir      * @param events the array of descriptors that need to be printed to log
254cdf0e10cSrcweir      */
printEvents(ScriptEventDescriptor events[])255cdf0e10cSrcweir     void printEvents(ScriptEventDescriptor events[]) {
256cdf0e10cSrcweir         if (events == null) {
257cdf0e10cSrcweir             log.println("null");
258cdf0e10cSrcweir         } else {
259cdf0e10cSrcweir             for (int i = 0; i < events.length; i++) {
260cdf0e10cSrcweir                 printEvent(events[i]);
261cdf0e10cSrcweir             }
262cdf0e10cSrcweir         }
263cdf0e10cSrcweir     }
264cdf0e10cSrcweir 
265cdf0e10cSrcweir     Object attachedObject;
266cdf0e10cSrcweir 
267cdf0e10cSrcweir     /**
268cdf0e10cSrcweir     * Test creates instance of <code>TypeDescriptionProvider</code>,
269cdf0e10cSrcweir     * stores it and attaches it to the entry with index stored in the method
270cdf0e10cSrcweir     * <code>insertEntry()</code>. <p>
271cdf0e10cSrcweir     * Has <b> OK </b> status if the method successfully returns
272cdf0e10cSrcweir     * and no exceptions were thrown. <p>
273cdf0e10cSrcweir     * The following method tests are to be completed successfully before :
274cdf0e10cSrcweir     * <ul>
275cdf0e10cSrcweir     *  <li> <code> insertEntry() </code> : to have entry's index for attach</li>
276cdf0e10cSrcweir     * @see com.sun.star.reflection.TypeDescriptionProvider
277cdf0e10cSrcweir     */
_attach()278cdf0e10cSrcweir     public void _attach() {
279cdf0e10cSrcweir         requiredMethod("insertEntry()");
280cdf0e10cSrcweir 
281cdf0e10cSrcweir         try {
282cdf0e10cSrcweir             XMultiServiceFactory xMSF = (XMultiServiceFactory)tParam.getMSF();
283cdf0e10cSrcweir             attachedObject = xMSF.createInstance
284cdf0e10cSrcweir                 ( "com.sun.star.reflection.TypeDescriptionProvider" );
285cdf0e10cSrcweir         } catch( com.sun.star.uno.Exception e ) {
286cdf0e10cSrcweir             log.println("Service not available" );
287cdf0e10cSrcweir             e.printStackTrace(log);
288cdf0e10cSrcweir             tRes.tested("attach()", false);
289cdf0e10cSrcweir             return;
290cdf0e10cSrcweir         }
291cdf0e10cSrcweir 
292cdf0e10cSrcweir         try {
293cdf0e10cSrcweir             oObj.attach(index, attachedObject, "param");
294cdf0e10cSrcweir             tRes.tested("attach()", true);
295cdf0e10cSrcweir         } catch (com.sun.star.lang.IllegalArgumentException e) {
296cdf0e10cSrcweir             log.println("attach() throws exception "
297cdf0e10cSrcweir                     + e.getMessage());
298cdf0e10cSrcweir             e.printStackTrace(log);
299cdf0e10cSrcweir             tRes.tested("attach()", false);
300cdf0e10cSrcweir         } catch (com.sun.star.lang.ServiceNotRegisteredException e) {
301cdf0e10cSrcweir             log.println("attach() throws exception "
302cdf0e10cSrcweir                     + e.getMessage());
303cdf0e10cSrcweir             e.printStackTrace(log);
304cdf0e10cSrcweir             tRes.tested("attach()", false);
305cdf0e10cSrcweir         }
306cdf0e10cSrcweir     }
307cdf0e10cSrcweir 
308cdf0e10cSrcweir     /**
309cdf0e10cSrcweir     * Test calls the method for the object that was stored in the method
310cdf0e10cSrcweir     * <code>attach()</code>. <p>
311cdf0e10cSrcweir     * Has <b> OK </b> status if the method successfully returns
312cdf0e10cSrcweir     * and no exceptions were thrown. <p>
313cdf0e10cSrcweir     * The following method tests are to be completed successfully before :
314cdf0e10cSrcweir     * <ul>
315cdf0e10cSrcweir     *  <li> <code> attach() </code> : to have attached object </li>
316cdf0e10cSrcweir     * </ul>
317cdf0e10cSrcweir     */
_detach()318cdf0e10cSrcweir     public void _detach() {
319cdf0e10cSrcweir         requiredMethod("attach()");
320cdf0e10cSrcweir 
321cdf0e10cSrcweir         try {
322cdf0e10cSrcweir             oObj.detach(index, attachedObject);
323cdf0e10cSrcweir             tRes.tested("detach()", true);
324cdf0e10cSrcweir         } catch (com.sun.star.lang.IllegalArgumentException e) {
325cdf0e10cSrcweir             log.println("detach() throws unexpected exception "
326cdf0e10cSrcweir                     + e.getMessage());
327cdf0e10cSrcweir             e.printStackTrace(log);
328cdf0e10cSrcweir             tRes.tested("detach()", false);
329cdf0e10cSrcweir         }
330cdf0e10cSrcweir     }
331cdf0e10cSrcweir 
332cdf0e10cSrcweir     /**
333cdf0e10cSrcweir     * Test revokes script event that was registered by method
334cdf0e10cSrcweir     * <code>registerScriptEvent()</code> and checks that the description
335cdf0e10cSrcweir     * was removed. <p>
336cdf0e10cSrcweir     * Has <b> OK </b> status if description was successfully removed. <p>
337cdf0e10cSrcweir     * The following method tests are to be completed successfully before :
338cdf0e10cSrcweir     * <ul>
339cdf0e10cSrcweir     *  <li> <code> registerScriptEvent() </code> :
340cdf0e10cSrcweir     *   to have registered descriptor </li>
341cdf0e10cSrcweir     * </ul>
342cdf0e10cSrcweir     * The following method tests are to be executed before :
343cdf0e10cSrcweir     * <ul>
344cdf0e10cSrcweir     *  <li> <code> getScriptEvents() </code> :
345cdf0e10cSrcweir     *   this method must be executed first </li>
346cdf0e10cSrcweir     * </ul>
347cdf0e10cSrcweir     */
_revokeScriptEvent()348cdf0e10cSrcweir     public void _revokeScriptEvent() {
349cdf0e10cSrcweir         requiredMethod("registerScriptEvent()");
350cdf0e10cSrcweir         executeMethod("getScriptEvents()") ;
351cdf0e10cSrcweir 
352cdf0e10cSrcweir         try {
353cdf0e10cSrcweir             oObj.revokeScriptEvent(index, desc.ListenerType,
354cdf0e10cSrcweir                     desc.EventMethod, "");
355cdf0e10cSrcweir 
356cdf0e10cSrcweir             ScriptEventDescriptor[] res = oObj.getScriptEvents(index);
357cdf0e10cSrcweir             // checking that the desc has been removed
358cdf0e10cSrcweir             tRes.tested("revokeScriptEvent()", !contains(res, desc));
359cdf0e10cSrcweir             printEvents(res) ;
360cdf0e10cSrcweir         } catch (com.sun.star.lang.IllegalArgumentException e) {
361cdf0e10cSrcweir             log.println("revokeScriptEvent() throws unexpected exception "
362cdf0e10cSrcweir                     + e.getMessage());
363cdf0e10cSrcweir             e.printStackTrace(log);
364cdf0e10cSrcweir             tRes.tested("revokeScriptEvent()", false);
365cdf0e10cSrcweir         }
366cdf0e10cSrcweir     }
367cdf0e10cSrcweir 
368cdf0e10cSrcweir     /**
369cdf0e10cSrcweir     * Test revokes script events that was registered by method
370cdf0e10cSrcweir     * <code>registerScriptEvents()</code> and checks that the descriptions
371cdf0e10cSrcweir     * were removed. <p>
372cdf0e10cSrcweir     * Has <b> OK </b> status if descriptions were successfully removed. <p>
373cdf0e10cSrcweir     * The following method tests are to be completed successfully before :
374cdf0e10cSrcweir     * <ul>
375cdf0e10cSrcweir     *  <li> <code> revokeScriptEvent() </code> :
376cdf0e10cSrcweir     *   this method must be executed first </li>
377cdf0e10cSrcweir     * </ul>
378cdf0e10cSrcweir     * The following method tests are to be executed before :
379cdf0e10cSrcweir     * <ul>
380cdf0e10cSrcweir     *  <li> <code> getScriptEvents() </code> :
381cdf0e10cSrcweir     *   this method must be executed first </li>
382cdf0e10cSrcweir     * </ul>
383cdf0e10cSrcweir     */
_revokeScriptEvents()384cdf0e10cSrcweir     public void _revokeScriptEvents() {
385cdf0e10cSrcweir         requiredMethod("revokeScriptEvent()");
386cdf0e10cSrcweir         executeMethod("getScriptEvents()") ;
387cdf0e10cSrcweir 
388cdf0e10cSrcweir         try {
389cdf0e10cSrcweir             oObj.revokeScriptEvents(index);
390cdf0e10cSrcweir 
391cdf0e10cSrcweir             ScriptEventDescriptor[] res = oObj.getScriptEvents(index);
392cdf0e10cSrcweir             // checking that all events have been removed
393cdf0e10cSrcweir             tRes.tested("revokeScriptEvents()",
394cdf0e10cSrcweir                     res == null || res.length == 0);
395cdf0e10cSrcweir         } catch (com.sun.star.lang.IllegalArgumentException e) {
396cdf0e10cSrcweir             log.println("revokeScriptEvents() throws unexpected exception "
397cdf0e10cSrcweir                     + e.getMessage());
398cdf0e10cSrcweir             e.printStackTrace(log);
399cdf0e10cSrcweir             tRes.tested("revokeScriptEvents()", false);
400cdf0e10cSrcweir         }
401cdf0e10cSrcweir     }
402cdf0e10cSrcweir 
403cdf0e10cSrcweir     /**
404cdf0e10cSrcweir     * Test calls the method with entry's index that was stored in method
405cdf0e10cSrcweir     * <code>insertEntry()</code>. <p>
406cdf0e10cSrcweir     * Has <b> OK </b> status if the method successfully returns
407cdf0e10cSrcweir     * and no exceptions were thrown. <p>
408cdf0e10cSrcweir     * The following method tests are to be completed successfully before :
409cdf0e10cSrcweir     * <ul>
410cdf0e10cSrcweir     *  <li> <code> insertEntry() </code> :
411cdf0e10cSrcweir     *  to have entry's index </li>
412cdf0e10cSrcweir     */
_removeEntry()413cdf0e10cSrcweir     public void _removeEntry() {
414cdf0e10cSrcweir         requiredMethod("insertEntry()");
415cdf0e10cSrcweir         try {
416cdf0e10cSrcweir             oObj.removeEntry(index);
417cdf0e10cSrcweir             tRes.tested("removeEntry()", true);
418cdf0e10cSrcweir         } catch (com.sun.star.lang.IllegalArgumentException e) {
419cdf0e10cSrcweir             log.println("removeEntry(" + index
420cdf0e10cSrcweir                     + ") throws unexpected exception "
421cdf0e10cSrcweir                     + e.getMessage());
422cdf0e10cSrcweir             e.printStackTrace(log);
423cdf0e10cSrcweir             tRes.tested("removeEntry()", false);
424cdf0e10cSrcweir         }
425cdf0e10cSrcweir     }
426cdf0e10cSrcweir 
427cdf0e10cSrcweir     XScriptListener listener;
428cdf0e10cSrcweir 
429cdf0e10cSrcweir     /**
430cdf0e10cSrcweir     * Test creates object that supports interface <code>XScriptListener</code>,
431cdf0e10cSrcweir     * stores it and addes this scripts listener. <p>
432cdf0e10cSrcweir     * Has <b> OK </b> status if the method successfully returns
433cdf0e10cSrcweir     * and no exceptions were thrown. <p>
434cdf0e10cSrcweir     * @see com.sun.star.script.XScriptListener
435cdf0e10cSrcweir     */
_addScriptListener()436cdf0e10cSrcweir     public void _addScriptListener() {
437cdf0e10cSrcweir         listener = new MyScriptListener();
438cdf0e10cSrcweir 
439cdf0e10cSrcweir         try {
440cdf0e10cSrcweir             oObj.addScriptListener(listener);
441cdf0e10cSrcweir             tRes.tested("addScriptListener()", true);
442cdf0e10cSrcweir         } catch (com.sun.star.lang.IllegalArgumentException e) {
443cdf0e10cSrcweir             log.println("addScriptListener() throws unexpected exception "
444cdf0e10cSrcweir                     + e.getMessage());
445cdf0e10cSrcweir             e.printStackTrace(log);
446cdf0e10cSrcweir             tRes.tested("addScriptListener()", false);
447cdf0e10cSrcweir         }
448cdf0e10cSrcweir     }
449cdf0e10cSrcweir 
450cdf0e10cSrcweir     /**
451cdf0e10cSrcweir     * Test removes script listener that was stored in method
452cdf0e10cSrcweir     * <code>addScriptListener()</code>. <p>
453cdf0e10cSrcweir     * Has <b> OK </b> status if the method successfully returns
454cdf0e10cSrcweir     * and no exceptions were thrown. <p>
455cdf0e10cSrcweir     * The following method tests are to be completed successfully before :
456cdf0e10cSrcweir     * <ul>
457cdf0e10cSrcweir     *  <li> <code> addScriptListener() </code> :
458cdf0e10cSrcweir     *  to have script listener </li>
459cdf0e10cSrcweir     * </ul>
460cdf0e10cSrcweir     */
_removeScriptListener()461cdf0e10cSrcweir     public void _removeScriptListener() {
462cdf0e10cSrcweir         requiredMethod("addScriptListener()");
463cdf0e10cSrcweir 
464cdf0e10cSrcweir         try {
465cdf0e10cSrcweir             oObj.removeScriptListener(listener);
466cdf0e10cSrcweir             tRes.tested("removeScriptListener()", true);
467cdf0e10cSrcweir         } catch (com.sun.star.lang.IllegalArgumentException e) {
468cdf0e10cSrcweir             log.println("removeScriptListener() throws unexpected exception "
469cdf0e10cSrcweir                     + e.getMessage());
470cdf0e10cSrcweir             e.printStackTrace(log);
471cdf0e10cSrcweir             tRes.tested("removeScriptListener()", false);
472cdf0e10cSrcweir         }
473cdf0e10cSrcweir     }
474cdf0e10cSrcweir 
475cdf0e10cSrcweir     /**
476cdf0e10cSrcweir      * Class implement interface <code>XScriptListener</code>
477cdf0e10cSrcweir      * for test of the method <code>addScriptListener()</code>.
478cdf0e10cSrcweir      * No functionality implemented.
479cdf0e10cSrcweir      * @see com.sun.star.script.XScriptListener
480cdf0e10cSrcweir      */
481cdf0e10cSrcweir     class MyScriptListener implements XScriptListener {
firing(ScriptEvent evt)482cdf0e10cSrcweir         public void firing(ScriptEvent evt) {
483cdf0e10cSrcweir         }
484cdf0e10cSrcweir 
approveFiring(ScriptEvent evt)485cdf0e10cSrcweir         public Object approveFiring(ScriptEvent evt) {
486cdf0e10cSrcweir             return evt.Helper;
487cdf0e10cSrcweir         }
488cdf0e10cSrcweir 
disposing(EventObject evt)489cdf0e10cSrcweir         public void disposing(EventObject evt) {
490cdf0e10cSrcweir         }
491cdf0e10cSrcweir     }
492cdf0e10cSrcweir 
493cdf0e10cSrcweir }
494cdf0e10cSrcweir 
495