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