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 --- .../qa/complex/imageManager/CheckImageManager.java | 201 +++++++++++++++++++++ framework/qa/complex/imageManager/_XComponent.java | 167 +++++++++++++++++ .../qa/complex/imageManager/_XImageManager.java | 105 +++++++++++ .../qa/complex/imageManager/_XInitialization.java | 78 ++++++++ .../qa/complex/imageManager/_XTypeProvider.java | 89 +++++++++ .../qa/complex/imageManager/_XUIConfiguration.java | 66 +++++++ .../imageManager/_XUIConfigurationPersistence.java | 84 +++++++++ 7 files changed, 790 insertions(+) create mode 100644 framework/qa/complex/imageManager/CheckImageManager.java create mode 100644 framework/qa/complex/imageManager/_XComponent.java create mode 100644 framework/qa/complex/imageManager/_XImageManager.java create mode 100644 framework/qa/complex/imageManager/_XInitialization.java create mode 100644 framework/qa/complex/imageManager/_XTypeProvider.java create mode 100644 framework/qa/complex/imageManager/_XUIConfiguration.java create mode 100644 framework/qa/complex/imageManager/_XUIConfigurationPersistence.java (limited to 'framework/qa/complex/imageManager') diff --git a/framework/qa/complex/imageManager/CheckImageManager.java b/framework/qa/complex/imageManager/CheckImageManager.java new file mode 100644 index 000000000..a88a96d30 --- /dev/null +++ b/framework/qa/complex/imageManager/CheckImageManager.java @@ -0,0 +1,201 @@ +/* + * 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 complex.imageManager; + +import com.sun.star.lang.XComponent; +import com.sun.star.lang.XInitialization; +import com.sun.star.lang.XMultiServiceFactory; +import com.sun.star.lang.XTypeProvider; +import com.sun.star.uno.UnoRuntime; +import com.sun.star.ui.XImageManager; +import com.sun.star.ui.XModuleUIConfigurationManagerSupplier; +import com.sun.star.ui.XUIConfiguration; +import com.sun.star.ui.XUIConfigurationManager; +import com.sun.star.ui.XUIConfigurationPersistence; + + +// ---------- junit imports ----------------- +import lib.TestParameters; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.openoffice.test.OfficeConnection; +import static org.junit.Assert.*; + + +/** + * + */ +public class CheckImageManager { + boolean checkUIConfigManager = false; + XMultiServiceFactory xMSF = null; + /** + * The test parameters + */ + private TestParameters param = null; + + @Before public void before() + { + xMSF = getMSF(); + param = new TestParameters(); + param.put("ServiceFactory", xMSF); // some qadevOOo functions need the ServiceFactory + } + + + @Test public void checkImageManagerFromModule() + { + System.out.println(" **** ImageManager from ModuleUIConfigurationManager *** "); + XUIConfigurationManager xManager = null; + try { + Object o = xMSF.createInstance( + "com.sun.star.ui.ModuleUIConfigurationManagerSupplier"); + XModuleUIConfigurationManagerSupplier xMUICMS = + UnoRuntime.queryInterface(XModuleUIConfigurationManagerSupplier.class, o); + xManager = xMUICMS.getUIConfigurationManager( + "com.sun.star.text.TextDocument"); + } + catch(com.sun.star.uno.Exception e) { + fail("Exception. " + e.getMessage()); + } + XImageManager xImageManager = UnoRuntime.queryInterface(XImageManager.class, xManager.getImageManager()); + performChecks(xImageManager, "ModuleUIConfig"); + } + + public void checkImageManager() { + System.out.println(" **** ImageManager from UIConfigurationManager *** "); + XUIConfigurationManager xManager = null; + try { + xManager = UnoRuntime.queryInterface(XUIConfigurationManager.class, xMSF.createInstance("com.sun.star.comp.framework.UIConfigurationManager")); + } + catch(com.sun.star.uno.Exception e) { + fail("Exception. " + e.getMessage()); + } + + XImageManager xImageManager = UnoRuntime.queryInterface(XImageManager.class, xManager.getImageManager()); + performChecks(xImageManager, "UIConfig"); + } + + private void performChecks(XImageManager xImageManager, String testObjectName) { + util.dbg.printInterfaces(xImageManager); + + OXUIConfigurationListenerImpl configListener = new OXUIConfigurationListenerImpl(); + param.put("XUIConfiguration.XUIConfigurationListenerImpl", configListener); + + XInitialization xInit = UnoRuntime.queryInterface(XInitialization.class, xImageManager); + _XInitialization _xInit = new _XInitialization(param, xInit); + assertTrue(testObjectName + "::XInitialization.initialize", _xInit._initialize()); + + // xImageManager is already there, just write a test ;-) + _XImageManager _xImage = new _XImageManager(xImageManager); + assertTrue(testObjectName + "::XImageManager.getAllImageNames", _xImage._getAllImageNames()); + assertTrue(testObjectName + "::XImageManager.getImages", _xImage._getImages()); + assertTrue(testObjectName + "::XImageManager.hasImage", _xImage._hasImage()); + assertTrue(testObjectName + "::XImageManager.insertImages", _xImage._insertImages()); + assertTrue(testObjectName + "::XImageManager.removeImages", _xImage._removeImages()); + assertTrue(testObjectName + "::XImageManager.replaceImages", _xImage._replaceImages()); + assertTrue(testObjectName + "::XImageManager.reset", _xImage._reset()); + + XTypeProvider xType = UnoRuntime.queryInterface(XTypeProvider.class, xImageManager); + _XTypeProvider _xType = new _XTypeProvider(xType); + assertTrue(testObjectName + "::XTypeProvider.getImplementationId", _xType._getImplementationId()); + assertTrue(testObjectName + "::XTypeProvider.getTypes", _xType._getTypes()); + + XUIConfiguration xUIConfig = UnoRuntime.queryInterface(XUIConfiguration.class, xImageManager); + _XUIConfiguration _xUIConfig = new _XUIConfiguration(param, xUIConfig); + _xUIConfig.before(); + assertTrue(testObjectName + "::XUIConfig.addConfigurationListener", _xUIConfig._addConfigurationListener()); + assertTrue(testObjectName + "::XUIConfig.removeConfigurationListener", _xUIConfig._removeConfigurationListener()); + + XUIConfigurationPersistence xUIConfigPersistence = (XUIConfigurationPersistence)UnoRuntime.queryInterface(XUIConfiguration.class, xImageManager); + _XUIConfigurationPersistence _xUIConfigPersistence = new _XUIConfigurationPersistence(param, xUIConfigPersistence); + _xUIConfigPersistence.before(); + assertTrue(testObjectName + "::XUIConfigPersistence.isModified", _xUIConfigPersistence._isModified()); + assertTrue(testObjectName + "::XUIConfigPersistence.isReadOnly", _xUIConfigPersistence._isReadOnly()); + assertTrue(testObjectName + "::XUIConfigPersistence.reload", _xUIConfigPersistence._reload()); + assertTrue(testObjectName + "::XUIConfigPersistence.store", _xUIConfigPersistence._store()); + assertTrue(testObjectName + "::XUIConfigPersistence.storeToStorage", _xUIConfigPersistence._storeToStorage()); + + XComponent xComp = UnoRuntime.queryInterface(XComponent.class, xImageManager); + _XComponent _xComp = new _XComponent(param, xComp); + _xComp.before(); + assertTrue(testObjectName + "::XComponent.addEventListener", _xComp._addEventListener()); + assertTrue(testObjectName + "::XComponent.removeEventListener", _xComp._removeEventListener()); + assertTrue(testObjectName + "::XComponent.dispose", _xComp._dispose()); + } + + + private static class OXUIConfigurationListenerImpl implements _XUIConfiguration.XUIConfigurationListenerImpl { + private boolean triggered = false; + + public boolean actionWasTriggered() { + return triggered; + } + + public void disposing(com.sun.star.lang.EventObject eventObject) { + triggered = true; + } + + public void elementInserted(com.sun.star.ui.ConfigurationEvent configurationEvent) { + triggered = true; + } + + public void elementRemoved(com.sun.star.ui.ConfigurationEvent configurationEvent) { + triggered = true; + } + + public void elementReplaced(com.sun.star.ui.ConfigurationEvent configurationEvent) { + triggered = true; + } + + public void fireEvent() { + // remove for real action: + triggered = !triggered; + } + + public void reset() { + // remove comment for real function + //triggered = false; + } + + } + + private XMultiServiceFactory getMSF() + { + return UnoRuntime.queryInterface(XMultiServiceFactory.class, connection.getComponentContext().getServiceManager()); + } + + // setup and close connections + @BeforeClass + public static void setUpConnection() throws Exception + { + System.out.println("setUpConnection()"); + connection.setUp(); + } + + @AfterClass + public static void tearDownConnection() + throws InterruptedException, com.sun.star.uno.Exception + { + System.out.println("tearDownConnection()"); + connection.tearDown(); + } + private static final OfficeConnection connection = new OfficeConnection(); + +} diff --git a/framework/qa/complex/imageManager/_XComponent.java b/framework/qa/complex/imageManager/_XComponent.java new file mode 100644 index 000000000..0d0a997b7 --- /dev/null +++ b/framework/qa/complex/imageManager/_XComponent.java @@ -0,0 +1,167 @@ +/* + * 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 complex.imageManager; + +import com.sun.star.frame.XDesktop; +import com.sun.star.lang.EventObject; +import com.sun.star.lang.XComponent; +import com.sun.star.lang.XEventListener; +import lib.TestParameters; + +/** +* Testing com.sun.star.lang.XComponent +* interface methods : +* +* After this interface test object must be recreated.

+* Multithreaded test ability not implemented yet. +* @see com.sun.star.lang.XComponent +*/ +public class _XComponent { + + private XComponent oObj = null; + private XComponent altDispose = null; + private final TestParameters tEnv; + private boolean listenerDisposed[] = new boolean[2]; + private String[] Loutput = new String[2]; + + /** + * Listener which added but not removed, and its method must be called + * on dispose call. + */ + private class MyEventListener implements XEventListener { + private final int number; + private final String message; + private MyEventListener(int number, String message) { + this.message = message; + this.number = number; + } + public void disposing ( EventObject oEvent ) { + Loutput[number] = Thread.currentThread() + " is DISPOSING " + message + this; + listenerDisposed[number] = true; + } + } + + private final XEventListener listener1 = new MyEventListener(0, "EV1"); + private final XEventListener listener2 = new MyEventListener(1, "EV2"); + + public _XComponent(TestParameters tEnv, XComponent oObj) { + this.tEnv = tEnv; + this.oObj = oObj; + } + + /** + * For the cfgmgr2.OSetElement tests: dispose the owner element. + */ + public void before() { + // do not dispose this component, but parent instead + altDispose = (XComponent)tEnv.get("XComponent.DisposeThis"); + + } + + /** + * Adds two listeners.

+ * Has OK status if then the first listener will receive an event + * on dispose method call. + */ + public boolean _addEventListener() { + + listenerDisposed[0] = false; + listenerDisposed[1] = false; + + oObj.addEventListener( listener1 ); + oObj.addEventListener( listener2 ); + + return true; + } // finished _addEventListener() + + /** + * Removes the second of two added listeners.

+ * Method tests to be completed successfully : + *

+ * Has OK status if no events will be sent to the second listener on + * dispose method call. + */ + public boolean _removeEventListener() { + if (disposed) + { + System.out.println("Hint: already disposed."); + return false; + } + // the second listener should not be called + oObj.removeEventListener( listener2 ); + System.out.println(Thread.currentThread() + " is removing EL " + listener2); + return true; + } // finished _removeEventListener() + + private boolean disposed = false; + + /** + * Disposes the object and then check appropriate listeners were + * called or not.

+ * Method tests to be completed successfully : + *

+ * Has OK status if liseter removed wasn't called and other listener + * was. + */ + public boolean _dispose() { + disposed = false; + + System.out.println( "begin dispose" + Thread.currentThread()); + XDesktop oDesk = (XDesktop) tEnv.get("Desktop"); + if (oDesk !=null) { + oDesk.terminate(); + } + else { + if (altDispose == null) + { + oObj.dispose(); + } + else + { + altDispose.dispose(); + } + } + + util.utils.shortWait(); + if (Loutput[0]!=null){ + System.out.println(Loutput[0]); + } + if (Loutput[1]!=null) { + System.out.println(Loutput[1]); + } + System.out.println( "end dispose" + Thread.currentThread()); + disposed = true; + + // check that dispose() works OK. + return listenerDisposed[0] && !listenerDisposed[1]; + + } // finished _dispose() + +} // finished class _XComponent + + diff --git a/framework/qa/complex/imageManager/_XImageManager.java b/framework/qa/complex/imageManager/_XImageManager.java new file mode 100644 index 000000000..c077bbf26 --- /dev/null +++ b/framework/qa/complex/imageManager/_XImageManager.java @@ -0,0 +1,105 @@ +/* + * 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 complex.imageManager; + +import com.sun.star.graphic.XGraphic; +import com.sun.star.ui.ImageType; +import com.sun.star.ui.XImageManager; + + +/** + * + */ +public class _XImageManager { + + + private String[]imageNames = null; + private XGraphic[] xGraphicArray = null; + private final XImageManager oObj; + + public _XImageManager( XImageManager oObj) { + this.oObj = oObj; + } + + public boolean _getAllImageNames() { + short s = ImageType.COLOR_NORMAL + ImageType.SIZE_DEFAULT; + imageNames = oObj.getAllImageNames(s); + for (int i=0; i<(imageNames.length>10?10:imageNames.length); i++) + { + System.out.println("###### Image: " + imageNames[i]); + } + return imageNames != null; + } + + public boolean _getImages() { + short s = ImageType.COLOR_NORMAL + ImageType.SIZE_DEFAULT; + try { + xGraphicArray = oObj.getImages(s, imageNames); + } + catch(com.sun.star.lang.IllegalArgumentException e) { + } + return xGraphicArray != null; + } + + public boolean _hasImage() { + boolean result = true; + short s = ImageType.COLOR_NORMAL + ImageType.SIZE_DEFAULT; + try { // check the first image names, 10 at max + for (int i=0; i<(imageNames.length>10?10:imageNames.length); i++) + { + result &= oObj.hasImage(s, imageNames[i]); + } + } + catch(com.sun.star.lang.IllegalArgumentException e) { + result = false; + } + return result; + } + + public boolean _insertImages() { + try { + oObj.insertImages((short)imageNames.length, imageNames, xGraphicArray); + } + catch(com.sun.star.container.ElementExistException e) { + } + catch(com.sun.star.lang.IllegalArgumentException e) { + } + catch(com.sun.star.lang.IllegalAccessException e) { + } + return true; + } + + public boolean _removeImages() { + try { + oObj.removeImages((short)(imageNames.length-1), imageNames); + } + catch(com.sun.star.lang.IllegalArgumentException e) { + } + catch(com.sun.star.lang.IllegalAccessException e) { + } + return true; + } + + public boolean _replaceImages() { + return true; + } + + public boolean _reset() { + return true; + } +} diff --git a/framework/qa/complex/imageManager/_XInitialization.java b/framework/qa/complex/imageManager/_XInitialization.java new file mode 100644 index 000000000..07508ef3f --- /dev/null +++ b/framework/qa/complex/imageManager/_XInitialization.java @@ -0,0 +1,78 @@ +/* + * 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 complex.imageManager; + + + + +import com.sun.star.lang.XInitialization; +import lib.TestParameters; + +/** +* Testing com.sun.star.lang.XInitialization +* interface methods.

+* This test needs the following object relations : +*