/************************************************************************* * * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * Copyright 2000, 2010 Oracle and/or its affiliates. * * OpenOffice.org - a multi-platform office productivity suite * * This file is part of OpenOffice.org. * * OpenOffice.org is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License version 3 * only, as published by the Free Software Foundation. * * OpenOffice.org 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 version 3 for more details * (a copy is included in the LICENSE file that accompanied this code). * * You should have received a copy of the GNU Lesser General Public License * version 3 along with OpenOffice.org. If not, see * * for a copy of the LGPLv3 License. * ************************************************************************/ 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 : *

* @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 : *

* @see com.sun.star.script.ScriptEventDescriptor */ public void _registerScriptEvent() { requiredMethod("insertEntry()"); desc = new ScriptEventDescriptor( "XEventListener1", "disposing", "", "Basic", ""); try { oObj.registerScriptEvent(index, desc); tRes.tested("registerScriptEvent()", true); } catch (com.sun.star.lang.IllegalArgumentException e) { log.println("registerScriptEvent() throws unexpected exception " + e.getMessage()); e.printStackTrace(log); tRes.tested("registerScriptEvent()", false); } } ScriptEventDescriptor descs[]; /** * Test creates array of ScriptEventDescriptor, 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 : *

* @see com.sun.star.script.ScriptEventDescriptor */ public void _registerScriptEvents() { requiredMethod("insertEntry()"); descs = new ScriptEventDescriptor[] { new ScriptEventDescriptor( "XEventListener2", "disposing", "", "Basic", ""), new ScriptEventDescriptor( "XEventListener3", "disposing", "", "Basic", "") }; try { oObj.registerScriptEvents(index, descs); tRes.tested("registerScriptEvents()", true); } catch (com.sun.star.lang.IllegalArgumentException e) { log.println("registerScriptEvents() throws unexpected exception " + e.getMessage()); e.printStackTrace(log); tRes.tested("registerScriptEvents()", false); } } /** * Test calls the method and checks returned value.

* 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 : *

*/ public void _getScriptEvents() { requiredMethod("registerScriptEvent()"); requiredMethod("registerScriptEvents()"); ScriptEventDescriptor[] res; try { res = oObj.getScriptEvents(index); } catch (com.sun.star.lang.IllegalArgumentException e) { log.println("registerScriptEvents() throws unexpected exception " + e.getMessage()); e.printStackTrace(log); tRes.tested("registerScriptEvents()", false); return; } // checking the desc and descs are in script events tRes.tested("getScriptEvents()", contains(res, desc) && containsArray(res, descs)); log.println("Script events :") ; printEvents(res) ; } /** * Method checks that array of descriptors contains the concrete desciptor. * @param container the array of descriptors * @param evt the descriptor which presence in the array is checked * @return true if the descriptor presence in the array */ boolean contains(ScriptEventDescriptor[] container, ScriptEventDescriptor evt) { for (int i = 0; i < container.length; i++) { if (equal(container[i], evt)) { return true; } } return false; } /** * Method checks that one array of descriptors contains * another array of descriptors. * @param container the array of descriptors * @param events the array of descriptors which presence * in array 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 : *