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 --- framework/qa/complex/dispatches/Interceptor.java | 338 +++++++++++++++++ .../qa/complex/dispatches/checkdispatchapi.java | 401 +++++++++++++++++++++ 2 files changed, 739 insertions(+) create mode 100644 framework/qa/complex/dispatches/Interceptor.java create mode 100644 framework/qa/complex/dispatches/checkdispatchapi.java (limited to 'framework/qa/complex/dispatches') diff --git a/framework/qa/complex/dispatches/Interceptor.java b/framework/qa/complex/dispatches/Interceptor.java new file mode 100644 index 000000000..ecbac4421 --- /dev/null +++ b/framework/qa/complex/dispatches/Interceptor.java @@ -0,0 +1,338 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-/* + * 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.dispatches; + +// __________ Imports __________ + +// structs, const, ... +import com.sun.star.beans.PropertyValue; + +// exceptions +import com.sun.star.frame.DispatchDescriptor; +import com.sun.star.frame.XDispatch; +import com.sun.star.frame.XDispatchProvider; +import com.sun.star.frame.XDispatchProviderInterceptor; +import com.sun.star.frame.XInterceptorInfo; +import com.sun.star.frame.XStatusListener; + +import com.sun.star.lang.XMultiServiceFactory; +import com.sun.star.awt.XDataTransferProviderAccess; + +// helper +import com.sun.star.util.URL; +import com.sun.star.uno.UnoRuntime; + +// __________ Implementation __________ + +/** + * implements a configurable interceptor for dispatch events. + */ +public class Interceptor implements XDispatch, + XDispatchProviderInterceptor, + XInterceptorInfo +{ + /** contains the list of interception URL schema's (wildcards are allowed there!) + supported by this interceptor. It can be set from outside. + If no external URLs are set, the default "*" is used instead. + That would have the same effect as if this implementation would not support the + interface XInterceptorInfo ! + */ + private String[] m_lURLs4InterceptionInfo = null; + + + + /** These URL's will be blocked by this interceptor. + Can be set from outside. Every queryDispatch() for these + set of URL's will be answered with an empty dispatch object! + If no external URLs are set the default "*" is used instead. + So every incoming URL will be blocked .-) + */ + private String[] m_lURLs4Blocking = null; + + + + /** Every dispatch interceptor knows it's master and slave interceptor + of the dispatch chain. These values must be stupid handled .-) + They have to be set and reset in case the right interface methods are called. + Nothing more. It's not allowed to dispose() it. + The slave can be used inside queryDispatch() to forward requests, + which are not handled by this interceptor instance. + */ + private XDispatchProvider m_xSlave = null; + private XDispatchProvider m_xMaster = null; + + + + /** counts calls of setSlave...(). + So the outside API test can use this value to know if this interceptor + was really added to the interceptor chain of OOo. + */ + private int m_nRegistrationCount = 0; + + + + /** indicates if this interceptor object is currently part of the interceptor + chain of OOo. Only true if a valid slave or master dispatch is set on this + instance. + */ + private boolean m_bIsRegistered = false; + + /** points to the global uno service manager. */ + private XMultiServiceFactory m_xMSF = null; + + public Interceptor(XMultiServiceFactory xMSF) + { + m_xMSF = xMSF; + } + + + /** XInterceptorInfo */ + public synchronized String[] getInterceptedURLs() + { + return impl_getURLs4InterceptionInfo(); + } + + + + /** XDispatchProviderInterceptor */ + public synchronized XDispatchProvider getSlaveDispatchProvider() + { + System.out.println("Interceptor.getSlaveDispatchProvider() called"); + return m_xSlave; + } + + + + /** XDispatchProviderInterceptor */ + public synchronized XDispatchProvider getMasterDispatchProvider() + { + System.out.println("Interceptor.getMasterDispatchProvider() called"); + return m_xMaster; + } + + + + /** XDispatchProviderInterceptor */ + public synchronized void setSlaveDispatchProvider(XDispatchProvider xSlave) + { + System.out.println("Interceptor.setSlaveDispatchProvider("+xSlave+") called"); + + if (xSlave != null) + { + ++m_nRegistrationCount; + m_bIsRegistered = true; + } + else + { + m_bIsRegistered = false; + } + + m_xSlave = xSlave; + } + + /** XDispatchProviderInterceptor */ + public synchronized void setMasterDispatchProvider(XDispatchProvider xMaster) + { + System.out.println("Interceptor.setMasterDispatchProvider("+xMaster+") called"); + m_xMaster = xMaster; + } + + private XDataTransferProviderAccess m_xToolkit = null; + + /** A beautiful method whose only purpose is to take and release a + * solar mutex. If this hangs - you can see a beautiful deadlock + * when you attach your debugger to the main process. + */ + private void checkNoSolarMutexHeld() + { + try + { + if (m_xToolkit == null) + m_xToolkit = UnoRuntime.queryInterface( + XDataTransferProviderAccess.class, + m_xMSF.createInstance("com.sun.star.awt.Toolkit")); + + // A Method notable only for taking the solar mutex. + System.out.println("Check solarmutex not held - if so deadlock"); + m_xToolkit.getDragSource( null ); + System.out.println("Solarmutex not held."); + } catch (java.lang.Throwable ex) { + System.out.println("Failed to create and invoke toolkit method " + ex.toString()); + } + } + + /** XDispatchProvider + */ + public synchronized XDispatch queryDispatch(URL aURL, + String sTargetFrameName, + int nSearchFlags) + { + System.out.println("Interceptor.queryDispatch('"+aURL.Complete+"', '"+sTargetFrameName+"', "+nSearchFlags+") called"); + + checkNoSolarMutexHeld(); + + if (impl_isBlockedURL(aURL.Complete)) + { + System.out.println("Interceptor.queryDispatch(): URL blocked => returns NULL"); + return null; + } + + if (m_xSlave != null) + { + System.out.println("Interceptor.queryDispatch(): ask slave ..."); + return m_xSlave.queryDispatch(aURL, sTargetFrameName, nSearchFlags); + } + + System.out.println("Interceptor.queryDispatch(): no idea => returns this"); + return this; + } + + + + /** XDispatchProvider + */ + public XDispatch[] queryDispatches(DispatchDescriptor[] lRequests) + { + int i = 0; + int c = lRequests.length; + + XDispatch[] lResults = new XDispatch[c]; + for (i=0; i aCheckMap = new HashMap(c2); + for (i2 = 0; i2 < c2; ++i2) + { + DispatchInformation aInfo = lInfos[i2]; + if (aInfo.GroupId != nGroup) + { + // Error + fail("At least one DispatchInformation item does not match the requested group.\n\trequested group=[" + nGroup + + "] returned group=[" + aInfo.GroupId + "] command=\"" + aInfo.Command + "\""); // true => don't break this test + continue; + } + + if (aCheckMap.containsKey(aInfo.Command)) + { + // Error + fail("Found a duplicate item: group=[" + aInfo.GroupId + "] command=\"" + aInfo.Command + "\""); // true => don't break this test + continue; + } + + aCheckMap.put(aInfo.Command, aInfo.Command); + System.out.println("\t[" + aInfo.GroupId + "] \"" + aInfo.Command + "\""); + } + } + } + + private synchronized XFrame impl_createNewFrame() + { + XFrame xFrame = m_xDesktop.findFrame("_blank", 0); + xFrame.getContainerWindow().setVisible(true); + return xFrame; + } + + private synchronized void impl_closeFrame(XFrame xFrame) throws Exception + { + XCloseable xClose = UnoRuntime.queryInterface(XCloseable.class, xFrame); + xClose.close(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(); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ -- cgit v1.2.3