/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 .
*/
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; private static final int index = 0; /** * 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() {
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 NamingService
(arbitrarily),
* 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 adds 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
*/
static class MyScriptListener implements XScriptListener {
public void firing(ScriptEvent evt) {
}
public Object approveFiring(ScriptEvent evt) {
return evt.Helper;
}
public void disposing(EventObject evt) {
}
}
}