/*************************************************************************
*
* $RCSfile: _XEventAttacherManager.java,v $
*
* $Revision: 1.3 $
*
* last change:$Date: 2003-09-08 10:49:57 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
*
* - GNU Lesser General Public License Version 2.1
* - Sun Industry Standards Source License Version 1.1
*
* Sun Microsystems Inc., October, 2000
*
* GNU Lesser General Public License Version 2.1
* =============================================
* Copyright 2000 by Sun Microsystems, Inc.
* 901 San Antonio Road, Palo Alto, CA 94303, USA
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1, as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*
*
* Sun Industry Standards Source License Version 1.1
* =================================================
* The contents of this file are subject to the Sun Industry Standards
* Source License Version 1.1 (the "License"); You may not use this file
* except in compliance with the License. You may obtain a copy of the
* License at http://www.openoffice.org/license.html.
*
* Software provided under this License is provided on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
* WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
* MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
* See the License for the specific provisions governing your rights and
* obligations concerning the Software.
*
* The Initial Developer of the Original Code is: Sun Microsystems, Inc.
*
* Copyright: 2000 by Sun Microsystems, Inc.
*
* All Rights Reserved.
*
* Contributor(s): _______________________________________
*
*
************************************************************************/
package ifc.script;
import lib.MultiMethodTest;
import com.sun.star.lang.EventObject;
import com.sun.star.lang.XMultiServiceFactory;
import com.sun.star.script.ScriptEvent;
import com.sun.star.script.ScriptEventDescriptor;
import com.sun.star.script.XEventAttacherManager;
import com.sun.star.script.XScriptListener;
/**
* Testing com.sun.star.script.XEventAttacherManager
* interface methods :
*
registerScriptEvent() registerScriptEvents() revokeScriptEvent() revokeScriptEvents() insertEntry() removeEntry() getScriptEvents() attach() detach() addScriptListener() removeScriptListener()* @see com.sun.star.script.XEventAttacherManager */ public class _XEventAttacherManager extends MultiMethodTest { /** * oObj filled by MultiMethodTest */ public XEventAttacherManager oObj = null; int index; /** * Test calls the method and stores index of new entry.
* Has OK status if the method successfully returns * and no exceptions were thrown.
*/
public void _insertEntry() {
index = 0;
try {
oObj.insertEntry(index);
tRes.tested("insertEntry()", true);
} catch (com.sun.star.lang.IllegalArgumentException e) {
log.println("insertEntry(" + index
+ ") throws unexpected exception "
+ e.getMessage());
e.printStackTrace(log);
tRes.tested("insertEntry()", false);
}
}
ScriptEventDescriptor desc;
/**
* Test creates ScriptEventDescriptor, registers
* the script event and stores the descriptor.
* Has OK status if the method successfully returns * and no exceptions were thrown.
* The following method tests are to be completed successfully before : *
insertEntry() : to have entry's indexScriptEventDescriptor, registers
* this script events and stores the descriptors. * Has OK status if the method successfully returns * and no exceptions were thrown.
* The following method tests are to be completed successfully before : *
insertEntry() : to have entry's index
* Has OK status if returned array of descriptors contains
* array of descriptors registered by methods registerScriptEvents
* and registerScriptEvent and no exceptions were thrown.
* The following method tests are to be completed successfully before : *
registerScriptEvent() :
* to have registered descriptor registerScriptEvents() :
* to have registered descriptors container is checked
* @return true if the array events contains in the array
* container
*/
boolean containsArray(ScriptEventDescriptor[] container,
ScriptEventDescriptor[] events) {
for (int i = 0; i < events.length; i++) {
if (!contains(container, events[i])) {
return false;
}
}
return true;
}
/**
* Compares descriptor evt1 to descriptor evt2.
* Two descriptors are considered equal if all their fields are equal.
* @return true if the argument is not null and
* the descriptors are equal; false otherwise
*/
boolean equal(ScriptEventDescriptor evt1,
ScriptEventDescriptor evt2) {
return evt1.ListenerType.equals(evt2.ListenerType)
&& evt1.EventMethod.equals(evt2.EventMethod)
&& evt1.ScriptType.equals(evt2.ScriptType)
&& evt1.ScriptCode.equals(evt2.ScriptCode)
&& evt1.AddListenerParam.equals(evt2.AddListenerParam);
}
/**
* Prints fields of descriptor evt to log.
* @param evt the descriptor that needs to be printed to log
*/
void printEvent(ScriptEventDescriptor evt) {
if (evt == null) {
log.println("null");
} else {
log.println("\"" + evt.ListenerType + "\",\""
+ evt.EventMethod + "\",\""
+ evt.ScriptType + "\",\""
+ evt.ScriptCode + "\",\""
+ evt.AddListenerParam + "\"");
}
}
/**
* Prints the descriptors to log.
* @param events the array of descriptors that need to be printed to log
*/
void printEvents(ScriptEventDescriptor events[]) {
if (events == null) {
log.println("null");
} else {
for (int i = 0; i < events.length; i++) {
printEvent(events[i]);
}
}
}
Object attachedObject;
/**
* Test creates instance of TypeDescriptionProvider,
* stores it and attaches it to the entry with index stored in the method
* insertEntry(). * Has OK status if the method successfully returns * and no exceptions were thrown.
* The following method tests are to be completed successfully before : *
insertEntry() : to have entry's index for attachattach(). * Has OK status if the method successfully returns * and no exceptions were thrown.
* The following method tests are to be completed successfully before : *
attach() : to have attached object registerScriptEvent() and checks that the description
* was removed. * Has OK status if description was successfully removed.
* The following method tests are to be completed successfully before : *
registerScriptEvent() :
* to have registered descriptor getScriptEvents() :
* this method must be executed first registerScriptEvents() and checks that the descriptions
* were removed. * Has OK status if descriptions were successfully removed.
* The following method tests are to be completed successfully before : *
revokeScriptEvent() :
* this method must be executed first getScriptEvents() :
* this method must be executed first insertEntry(). * Has OK status if the method successfully returns * and no exceptions were thrown.
* The following method tests are to be completed successfully before : *
insertEntry() :
* to have entry's index XScriptListener,
* stores it and addes this scripts listener. * Has OK status if the method successfully returns * and no exceptions were thrown.
* @see com.sun.star.script.XScriptListener
*/
public void _addScriptListener() {
listener = new MyScriptListener();
try {
oObj.addScriptListener(listener);
tRes.tested("addScriptListener()", true);
} catch (com.sun.star.lang.IllegalArgumentException e) {
log.println("addScriptListener() throws unexpected exception "
+ e.getMessage());
e.printStackTrace(log);
tRes.tested("addScriptListener()", false);
}
}
/**
* Test removes script listener that was stored in method
* addScriptListener().
* Has OK status if the method successfully returns * and no exceptions were thrown.
* The following method tests are to be completed successfully before : *
addScriptListener() :
* to have script listener XScriptListener
* for test of the method addScriptListener().
* No functionality implemented.
* @see com.sun.star.script.XScriptListener
*/
class MyScriptListener implements XScriptListener {
public void firing(ScriptEvent evt) {
}
public Object approveFiring(ScriptEvent evt) {
return evt.Helper;
}
public void disposing(EventObject evt) {
}
}
}