From 940b4d1848e8c70ab7642901a68594e8016caffc Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 27 Apr 2024 18:51:28 +0200 Subject: Adding upstream version 1:7.0.4. Signed-off-by: Daniel Baumann --- .../java/ifc/script/_XEventAttacherManager.java | 492 +++++++++++++++++++++ .../ifc/script/_XInvocationAdapterFactory.java | 103 +++++ .../ifc/script/_XInvocationAdapterFactory2.java | 105 +++++ .../tests/java/ifc/script/_XTypeConverter.java | 122 +++++ 4 files changed, 822 insertions(+) create mode 100644 qadevOOo/tests/java/ifc/script/_XEventAttacherManager.java create mode 100644 qadevOOo/tests/java/ifc/script/_XInvocationAdapterFactory.java create mode 100644 qadevOOo/tests/java/ifc/script/_XInvocationAdapterFactory2.java create mode 100644 qadevOOo/tests/java/ifc/script/_XTypeConverter.java (limited to 'qadevOOo/tests/java/ifc/script') diff --git a/qadevOOo/tests/java/ifc/script/_XEventAttacherManager.java b/qadevOOo/tests/java/ifc/script/_XEventAttacherManager.java new file mode 100644 index 000000000..b0375c257 --- /dev/null +++ b/qadevOOo/tests/java/ifc/script/_XEventAttacherManager.java @@ -0,0 +1,492 @@ +/* + * 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 : +*

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

+ * @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 descriptor. + * @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 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 : + *