From 267c6f2ac71f92999e969232431ba04678e7437e Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Mon, 15 Apr 2024 07:54:39 +0200 Subject: Adding upstream version 4:24.2.0. Signed-off-by: Daniel Baumann --- extensions/qa/bibliography/bibliography.cxx | 50 +++++ .../integration/extensions/ComponentFactory.java | 93 +++++++++ .../qa/integration/extensions/ConsoleWait.java | 120 ++++++++++++ extensions/qa/integration/extensions/Frame.java | 215 ++++++++++++++++++++ .../integration/extensions/HelpTextProvider.java | 58 ++++++ .../qa/integration/extensions/MethodHandler.java | 217 +++++++++++++++++++++ .../qa/integration/extensions/ObjectInspector.java | 159 +++++++++++++++ .../qa/integration/extensions/ServicesHandler.java | 212 ++++++++++++++++++++ .../integration/extensions/extensions_complex.sce | 1 + extensions/qa/integration/extensions/makefile.mk | 74 +++++++ extensions/qa/ole/automationtest.vbs | 132 +++++++++++++ extensions/qa/unoapi/extensions.sce | 5 + extensions/qa/update/simple.xml | 18 ++ extensions/qa/update/test_update.cxx | 152 +++++++++++++++ 14 files changed, 1506 insertions(+) create mode 100644 extensions/qa/bibliography/bibliography.cxx create mode 100644 extensions/qa/integration/extensions/ComponentFactory.java create mode 100644 extensions/qa/integration/extensions/ConsoleWait.java create mode 100644 extensions/qa/integration/extensions/Frame.java create mode 100644 extensions/qa/integration/extensions/HelpTextProvider.java create mode 100644 extensions/qa/integration/extensions/MethodHandler.java create mode 100644 extensions/qa/integration/extensions/ObjectInspector.java create mode 100644 extensions/qa/integration/extensions/ServicesHandler.java create mode 100644 extensions/qa/integration/extensions/extensions_complex.sce create mode 100644 extensions/qa/integration/extensions/makefile.mk create mode 100644 extensions/qa/ole/automationtest.vbs create mode 100644 extensions/qa/unoapi/extensions.sce create mode 100644 extensions/qa/update/simple.xml create mode 100644 extensions/qa/update/test_update.cxx (limited to 'extensions/qa') diff --git a/extensions/qa/bibliography/bibliography.cxx b/extensions/qa/bibliography/bibliography.cxx new file mode 100644 index 0000000000..af68ee95eb --- /dev/null +++ b/extensions/qa/bibliography/bibliography.cxx @@ -0,0 +1,50 @@ +/* -*- 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/. + */ + +#include +#include + +#include +#include + +using namespace ::com::sun::star; + +namespace +{ +/// Covers extensions/source/bibliography/ fixes. +class Test : public test::BootstrapFixture, public unotest::MacrosTest +{ +}; +} + +CPPUNIT_TEST_FIXTURE(Test, testBibliographyLoader) +{ + // Given a bibliography provider: + uno::Reference xBibAccess + = frame::Bibliography::create(mxComponentContext); + uno::Reference xPropSet(xBibAccess, uno::UNO_QUERY); + uno::Sequence aSeq; + + // When getting the column names: + xPropSet->getPropertyValue("BibliographyDataFieldNames") >>= aSeq; + + // Then make sure we have columns and all have non-empty names: + CPPUNIT_ASSERT(aSeq.hasElements()); + + // Without the accompanying fix in place, this test would have failed, as the last column + // (LOCAL_URL) had an empty field name: + for (const auto& rPair : std::as_const(aSeq)) + { + CPPUNIT_ASSERT(!rPair.Name.isEmpty()); + } +} + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/extensions/qa/integration/extensions/ComponentFactory.java b/extensions/qa/integration/extensions/ComponentFactory.java new file mode 100644 index 0000000000..ec848c4dfb --- /dev/null +++ b/extensions/qa/integration/extensions/ComponentFactory.java @@ -0,0 +1,93 @@ +/* + * 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 integration.extensions; + +import com.sun.star.uno.XComponentContext; +import com.sun.star.lang.XSingleComponentFactory; +import java.lang.reflect.Constructor; + +public class ComponentFactory implements XSingleComponentFactory +{ + private final Class m_handlerClass; + private Constructor m_defaultConstructor; + private Constructor m_initConstructor; + + public ComponentFactory( Class _handlerClass ) + { + m_handlerClass = _handlerClass; + + Class objectArrayClass = null; + try + { + objectArrayClass = Class.forName("[Ljava.lang.Object;"); + } + catch ( java.lang.ClassNotFoundException e ) { } + + Constructor ctors[] = _handlerClass.getConstructors(); + for ( int i = 0; i < ctors.length; ++i) + { + Class ctorParams[] = ctors[i].getParameterTypes(); + if ( ( ctorParams.length == 1 ) && ( ctorParams[0].equals( XComponentContext.class ) ) ) + m_defaultConstructor = ctors[i]; + if ( ( ctorParams.length == 2 ) + && ( ctorParams[0].equals( XComponentContext.class ) ) + && ( ctorParams[1].equals( objectArrayClass ) ) + ) + m_initConstructor = ctors[i]; + } + if ( m_defaultConstructor == null ) + throw new java.lang.IllegalArgumentException(); + } + + private Object ipml_createInstance( Constructor _ctor, Object[] _arguments ) + { + Object newInstance = null; + try + { + newInstance = _ctor.newInstance( _arguments ); + } + catch( InstantiationException e ) + { + System.err.println( "InstantiationException: Could not instantiate an instance of " + m_handlerClass.getName() ); + } + catch( IllegalAccessException e ) + { + System.err.println( "IllegalAccessException: Could not instantiate an instance of " + m_handlerClass.getName() ); + } + catch( java.lang.reflect.InvocationTargetException e ) + { + System.err.println( "InvocationTargetException: Could not instantiate an instance of " + m_handlerClass.getName() ); + } + return newInstance; + } + + public Object createInstanceWithArgumentsAndContext(Object[] _arguments, XComponentContext _componentContext) throws com.sun.star.uno.Exception + { + if ( m_initConstructor != null ) + return ipml_createInstance( m_initConstructor, new Object[] { _componentContext, _arguments } ); + else + return createInstanceWithContext( _componentContext ); + } + + public Object createInstanceWithContext(XComponentContext _componentContext) throws com.sun.star.uno.Exception + { + return ipml_createInstance( m_defaultConstructor, new Object[] { _componentContext } ); + } +} + diff --git a/extensions/qa/integration/extensions/ConsoleWait.java b/extensions/qa/integration/extensions/ConsoleWait.java new file mode 100644 index 0000000000..34fdaa7c06 --- /dev/null +++ b/extensions/qa/integration/extensions/ConsoleWait.java @@ -0,0 +1,120 @@ +/* + * 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 integration.extensions; + +import com.sun.star.uno.*; +import com.sun.star.lang.XComponent; + +public class ConsoleWait implements com.sun.star.lang.XEventListener +{ + private final Object m_disposable; + + /** a helper class which waits for a console ENTER key event in a dedicated thread, + and notifies a ConsoleWait object if this event happened + */ + private class WaitForEnter extends java.lang.Thread + { + private final ConsoleWait m_toNotify; + private boolean m_done; + + public WaitForEnter( ConsoleWait _toNotify ) + { + m_toNotify = _toNotify; + m_done = false; + } + + public boolean isDone() + { + return m_done; + } + + @Override + public void run() + { + try + { + System.out.println( "\npress enter to exit" ); + System.in.read(); + + m_done = true; + // notify that the user pressed the key + synchronized ( m_toNotify ) + { + m_toNotify.notify(); + } + } + catch( java.lang.Exception e ) + { + // not really interested in + System.err.println( e ); + } + } + } + + /** creates a ConsoleWait instance + * @param _disposable + * a component whose disposal should be monitored. When this component dies, + * the ConsoleWait also returns from a waitForConsole call, even if the user + * did not yet press the enter key + */ + public ConsoleWait( Object _disposable ) + { + m_disposable = _disposable; + XComponent component = UnoRuntime.queryInterface( XComponent.class, _disposable ); + if ( component != null ) + component.addEventListener( this ); + } + + /** waits for the user to press the ENTER key (on the console where she started the java program) + or the disposable component to be closed by the user. + @return + TRUE if the user pressed a key on the console, FALSE if she closed the document + */ + public boolean waitForUserInput() throws java.lang.Exception + { + synchronized (this) + { + WaitForEnter keyWaiter = new WaitForEnter( this ); + keyWaiter.start(); + wait(); + + // if the waiter thread is done, the user pressed enter + boolean bKeyPressed = keyWaiter.isDone(); + if ( !bKeyPressed ) + keyWaiter.interrupt(); + + return bKeyPressed; + } + } + + /* ------------------------------------------------------------------ */ + /* XEventListener overridables */ + /* ------------------------------------------------------------------ */ + public void disposing( com.sun.star.lang.EventObject eventObject ) + { + if ( eventObject.Source.equals( m_disposable ) ) + { + // notify ourself that we can stop waiting for user input + synchronized (this) + { + notify(); + } + } + } +} diff --git a/extensions/qa/integration/extensions/Frame.java b/extensions/qa/integration/extensions/Frame.java new file mode 100644 index 0000000000..15f26de744 --- /dev/null +++ b/extensions/qa/integration/extensions/Frame.java @@ -0,0 +1,215 @@ +/* + * 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 integration.extensions; + +import com.sun.star.uno.*; +import com.sun.star.frame.*; +import com.sun.star.task.XStatusIndicatorFactory; +import com.sun.star.util.XCloseable; + +/** + * wraps the com.sun.star.frame.Frame service + */ +public class Frame implements XDispatchProvider, + XDispatchProviderInterception, + XFramesSupplier, + XStatusIndicatorFactory, + XCloseable +{ + private XFrame m_frame; + private XDispatchProvider m_dispatchProvider; + private XDispatchProviderInterception m_dispatchProviderInterception; + private XFramesSupplier m_framesSupplier; + private XStatusIndicatorFactory m_statusIndicatorFactory; + private XCloseable m_closeable; + + /** Creates a new instance of Frame */ + public Frame( Object _frameComponent ) + { + if ( _frameComponent != null ) + { + m_frame = UnoRuntime.queryInterface( XFrame.class, _frameComponent ); + m_dispatchProvider = UnoRuntime.queryInterface( XDispatchProvider.class, _frameComponent ); + m_dispatchProviderInterception = UnoRuntime.queryInterface( XDispatchProviderInterception.class, _frameComponent ); + m_framesSupplier = UnoRuntime.queryInterface( XFramesSupplier.class, _frameComponent ); + m_statusIndicatorFactory = UnoRuntime.queryInterface( XStatusIndicatorFactory.class, _frameComponent ); + m_closeable = UnoRuntime.queryInterface( XCloseable.class, _frameComponent ); + } + } + + public XFrame getXFrame() + { + return m_frame; + } + + public void activate() + { + m_frame.activate(); + } + + public void addEventListener(com.sun.star.lang.XEventListener _eventListener) + { + m_frame.addEventListener( _eventListener ); + } + + public void addFrameActionListener(XFrameActionListener _frameActionListener) + { + m_frame.addFrameActionListener( _frameActionListener ); + } + + public void contextChanged() + { + m_frame.contextChanged(); + } + + public com.sun.star.task.XStatusIndicator createStatusIndicator() + { + return m_statusIndicatorFactory.createStatusIndicator(); + } + + public void deactivate() + { + m_frame.deactivate(); + } + + public void dispose() + { + m_frame.dispose(); + } + + public XFrame findFrame(String str, int param) + { + return m_frame.findFrame( str, param ); + } + + public XFrame getActiveFrame() + { + return m_framesSupplier.getActiveFrame(); + } + + public com.sun.star.awt.XWindow getComponentWindow() + { + return m_frame.getComponentWindow(); + } + + public com.sun.star.awt.XWindow getContainerWindow() + { + return m_frame.getContainerWindow(); + } + + public XController getController() + { + return m_frame.getController(); + } + + public XFramesSupplier getCreator() + { + return m_frame.getCreator(); + } + + public XFrames getFrames() + { + return m_framesSupplier.getFrames(); + } + + public String getName() + { + return m_frame.getName(); + } + + public void initialize(com.sun.star.awt.XWindow _window) + { + m_frame.initialize( _window ); + } + + public boolean isActive() + { + return m_frame.isActive(); + } + + public boolean isTop() + { + return m_frame.isTop(); + } + + public XDispatch queryDispatch(com.sun.star.util.URL _url, String _str, int _param) + { + return m_dispatchProvider.queryDispatch( _url, _str, _param ); + } + + public XDispatch[] queryDispatches(DispatchDescriptor[] dispatchDescriptor) + { + return m_dispatchProvider.queryDispatches( dispatchDescriptor ); + } + + public void registerDispatchProviderInterceptor(XDispatchProviderInterceptor _dispatchProviderInterceptor) + { + m_dispatchProviderInterception.registerDispatchProviderInterceptor( _dispatchProviderInterceptor ); + } + + public void releaseDispatchProviderInterceptor(XDispatchProviderInterceptor _dispatchProviderInterceptor) + { + m_dispatchProviderInterception.releaseDispatchProviderInterceptor( _dispatchProviderInterceptor ); + } + + public void removeEventListener(com.sun.star.lang.XEventListener _eventListener) + { + m_frame.removeEventListener( _eventListener ); + } + + public void removeFrameActionListener(XFrameActionListener _frameActionListener) + { + m_frame.removeFrameActionListener( _frameActionListener ); + } + + public void setActiveFrame(XFrame _frame) + { + m_framesSupplier.setActiveFrame( _frame ); + } + + public boolean setComponent(com.sun.star.awt.XWindow _window, XController _controller) + { + return m_frame.setComponent( _window, _controller ); + } + + public void setCreator(XFramesSupplier _framesSupplier) + { + m_frame.setCreator( _framesSupplier ); + } + + public void setName(String str) + { + m_frame.setName( str ); + } + + public void close(boolean _deliverOwnership) throws com.sun.star.util.CloseVetoException + { + m_closeable.close( _deliverOwnership ); + } + + public void removeCloseListener(com.sun.star.util.XCloseListener _closeListener) + { + m_closeable.removeCloseListener( _closeListener ); + } + + public void addCloseListener(com.sun.star.util.XCloseListener _closeListener) + { + m_closeable.addCloseListener( _closeListener ); + } +} diff --git a/extensions/qa/integration/extensions/HelpTextProvider.java b/extensions/qa/integration/extensions/HelpTextProvider.java new file mode 100644 index 0000000000..8bd6596bc9 --- /dev/null +++ b/extensions/qa/integration/extensions/HelpTextProvider.java @@ -0,0 +1,58 @@ +/* + * 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 integration.extensions; + +import com.sun.star.inspection.XObjectInspectorUI; +import com.sun.star.inspection.XPropertyControl; +import com.sun.star.inspection.XPropertyControlObserver; +import com.sun.star.lang.NoSupportException; + +/** displays help text for the currently selected method + */ +public class HelpTextProvider implements XPropertyControlObserver +{ + private final XObjectInspectorUI m_inspectorUI; + + /** + * Creates a new instance of HelpTextProvider + */ + public HelpTextProvider( XObjectInspectorUI _inspectorUI ) + { + m_inspectorUI = _inspectorUI; + m_inspectorUI.registerControlObserver( this ); + } + + public void focusGained( XPropertyControl _propertyControl ) + { + try + { + String helpText = "here could be the help for:\n"; + helpText += _propertyControl.getValue().toString(); + m_inspectorUI.setHelpSectionText( helpText ); + } + catch (NoSupportException ex) + { + ex.printStackTrace(); + } + } + + public void valueChanged( XPropertyControl _propertyControl ) + { + // not interested in + } +} diff --git a/extensions/qa/integration/extensions/MethodHandler.java b/extensions/qa/integration/extensions/MethodHandler.java new file mode 100644 index 0000000000..ffc81c5f56 --- /dev/null +++ b/extensions/qa/integration/extensions/MethodHandler.java @@ -0,0 +1,217 @@ +/* + * 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 integration.extensions; + +import com.sun.star.uno.*; +import com.sun.star.beans.*; +import com.sun.star.reflection.*; +import com.sun.star.inspection.*; + +public class MethodHandler implements XPropertyHandler +{ + private XIntrospection m_introspection; + private XIdlMethod[] m_methods; + private java.util.HashMap m_methodsHash; + + /** Creates a new instance of MethodHandler */ + public MethodHandler( XComponentContext _context ) + { + m_methodsHash = new java.util.HashMap(); + + try + { + m_introspection = UnoRuntime.queryInterface( XIntrospection.class, + _context.getServiceManager().createInstanceWithContext( "com.sun.star.beans.Introspection", _context ) + ); + } + catch( com.sun.star.uno.Exception e ) + { + System.err.println( "MethodHandler: could not create an Introspection service, not much functionality will be available." ); + } + } + + + + public void actuatingPropertyChanged(String _propertyName, Object _newValue, Object _oldValue, com.sun.star.inspection.XObjectInspectorUI _objectInspectorUI, boolean _firstTimeInit) throws com.sun.star.lang.NullPointerException + { + // not interested in + } + + public void addEventListener(com.sun.star.lang.XEventListener _eventListener) + { + // ignoring this + } + + public void addPropertyChangeListener(com.sun.star.beans.XPropertyChangeListener _propertyChangeListener) throws com.sun.star.lang.NullPointerException + { + // ignoring this + } + + public Object convertToControlValue(String _propertyName, Object _propertyValue, com.sun.star.uno.Type type) throws com.sun.star.beans.UnknownPropertyException + { + return _propertyValue; + } + + public Object convertToPropertyValue(String _propertyName, Object _controlValue) throws com.sun.star.beans.UnknownPropertyException + { + return _controlValue; + } + + public com.sun.star.inspection.LineDescriptor describePropertyLine(String _propertyName, com.sun.star.inspection.XPropertyControlFactory _propertyControlFactory) throws com.sun.star.beans.UnknownPropertyException, com.sun.star.lang.NullPointerException + { + com.sun.star.inspection.LineDescriptor descriptor = new com.sun.star.inspection.LineDescriptor(); + + descriptor = new LineDescriptor(); + descriptor.Category = "Methods"; + descriptor.DisplayName = "has method"; + descriptor.HasPrimaryButton = descriptor.HasSecondaryButton = false; + descriptor.IndentLevel = 0; + try + { + XPropertyControl control = UnoRuntime.queryInterface( + XPropertyControl.class, _propertyControlFactory.createPropertyControl( + PropertyControlType.TextField, true ) ); + + descriptor.Control = control; + } + catch( com.sun.star.lang.IllegalArgumentException e ) + { + } + return descriptor; + } + + public void dispose() + { + // nothing to do + } + + public String[] getActuatingProperties() + { + // none + return new String[] { }; + } + + public com.sun.star.beans.PropertyState getPropertyState(String _propertyName) throws com.sun.star.beans.UnknownPropertyException + { + return com.sun.star.beans.PropertyState.DIRECT_VALUE; + } + + public Object getPropertyValue(String _propertyName) throws com.sun.star.beans.UnknownPropertyException + { + XIdlMethod method = impl_getMethod( _propertyName ); + + String signature = ""; + signature += method.getReturnType().getName(); + signature += " "; + signature += method.getName(); + + signature += "("; + + XIdlClass[] parameterTypes = method.getParameterTypes(); + for ( int param = 0; param(); + + XIntrospectionAccess introspectionAccess = m_introspection.inspect( _component ); + if ( introspectionAccess == null ) + return; + + m_methods = introspectionAccess.getMethods( MethodConcept.ALL ); + } + + public boolean isComposable(String _propertyName) throws com.sun.star.beans.UnknownPropertyException + { + return true; + } + + public com.sun.star.inspection.InteractiveSelectionResult onInteractivePropertySelection(String str, boolean param, Object[] obj, com.sun.star.inspection.XObjectInspectorUI xObjectInspectorUI) throws com.sun.star.beans.UnknownPropertyException, com.sun.star.lang.NullPointerException + { + return InteractiveSelectionResult.Cancelled; + } + + public void removeEventListener(com.sun.star.lang.XEventListener _eventListener) + { + // ignoring this + } + + public void removePropertyChangeListener(com.sun.star.beans.XPropertyChangeListener _propertyChangeListener) + { + // ignoring this + } + + public void setPropertyValue(String str, Object obj) throws com.sun.star.beans.UnknownPropertyException + { + // we declared our properties as readonly + throw new java.lang.RuntimeException(); + } + + public boolean suspend(boolean param) + { + return true; + } + + /** returns the descriptor for the method with the given name + * @param _propertyName + * the name of the method whose descriptor should be obtained + * @throws com.sun.star.beans.UnknownPropertyException + * if we don't have a method hash, or the given property name does not denote a method of our inspectee + */ + private XIdlMethod impl_getMethod( String _methodName ) throws UnknownPropertyException + { + XIdlMethod method = m_methodsHash.get( _methodName ); + if ( method == null ) + throw new com.sun.star.beans.UnknownPropertyException(); + + return method; + } +} diff --git a/extensions/qa/integration/extensions/ObjectInspector.java b/extensions/qa/integration/extensions/ObjectInspector.java new file mode 100644 index 0000000000..2b2fa4e0a9 --- /dev/null +++ b/extensions/qa/integration/extensions/ObjectInspector.java @@ -0,0 +1,159 @@ +/* + * 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 integration.extensions; + +import com.sun.star.uno.XComponentContext; +import com.sun.star.uno.UnoRuntime; +import com.sun.star.lang.XMultiServiceFactory; + +import com.sun.star.frame.*; +import com.sun.star.inspection.*; +import com.sun.star.beans.*; + +public class ObjectInspector extends complexlib.ComplexTestCase +{ + private XComponentContext m_context; + private XMultiServiceFactory m_orb; + private Frame m_desktop; + + static final private String m_inspectorFrameName = "ObjectInspector"; + + /* ------------------------------------------------------------------ */ + @Override + public String[] getTestMethodNames() + { + return new String[] { + "interactiveObjectInspector" + }; + } + + /* ------------------------------------------------------------------ */ + @Override + public String getTestObjectName() + { + return "Test Skeleton"; + } + + /* ------------------------------------------------------------------ */ + public void before() throws com.sun.star.uno.Exception, java.lang.Exception + { + m_orb = param.getMSF(); + m_context = UnoRuntime.queryInterface( XComponentContext.class, + UnoRuntime.queryInterface( XPropertySet.class, m_orb ).getPropertyValue( "DefaultContext" ) ); + m_desktop = new Frame( m_orb.createInstance( "com.sun.star.frame.Desktop" ) ); + } + + /* ------------------------------------------------------------------ */ + public void after() throws java.lang.Exception + { + closeExistentInspector(); + } + + /* ------------------------------------------------------------------ */ + public void interactiveObjectInspector() throws com.sun.star.uno.Exception, java.lang.Exception + { + closeExistentInspector(); + + // the to-be-inspected object + XFrame inspectee = m_desktop.getActiveFrame(); + + // the inspector + XObjectInspector inspector = createObjectInspector(); + + // do inspect + inspector.inspect( new Object[] { inspectee } ); + + ConsoleWait keyWaiter = new ConsoleWait( inspector ); + keyWaiter.waitForUserInput(); + } + + /* ------------------------------------------------------------------ */ + private XObjectInspector createObjectInspector() throws com.sun.star.uno.Exception + { + com.sun.star.awt.XWindow floatingWindow = createFloatingWindow(); + + Frame inspectorFrame = new Frame( m_orb.createInstance( "com.sun.star.frame.Frame" ) ); + inspectorFrame.setName( m_inspectorFrameName ); + inspectorFrame.initialize( floatingWindow ); + m_desktop.getFrames().append( inspectorFrame.getXFrame() ); + + // handler factories: + Object[] handlerFactories = new Object[] { + "com.sun.star.inspection.GenericPropertyHandler", + new ComponentFactory( ServicesHandler.class ), + new ComponentFactory( MethodHandler.class ) + }; + // a model + XObjectInspectorModel model = ObjectInspectorModel.createWithHandlerFactoriesAndHelpSection( + m_context, handlerFactories, 4, 4 ); + + // create the ObjectInspector + XObjectInspector inspector = com.sun.star.inspection.ObjectInspector.createWithModel( + m_context, model ); + + // add an observer which will emit help texts + new HelpTextProvider( inspector.getInspectorUI() ); + + // plug it into the frame + inspector.attachFrame( inspectorFrame.getXFrame() ); + + // make the window visible + floatingWindow.setVisible( true ); + + // outta here + return inspector; + } + + /* ------------------------------------------------------------------ */ + private void closeExistentInspector() + { + Frame existentInspectorFrame = new Frame( m_desktop.findFrame( m_inspectorFrameName, 255 ) ); + try + { + existentInspectorFrame.close( true ); + } + catch( com.sun.star.util.CloseVetoException e ) + { + failed( "could not close the existent inspector frame" ); + } + } + + /* ------------------------------------------------------------------ */ + private com.sun.star.awt.XWindow createFloatingWindow() throws com.sun.star.uno.Exception + { + com.sun.star.awt.XToolkit toolkit = UnoRuntime.queryInterface( + com.sun.star.awt.XToolkit.class, m_orb.createInstance( "com.sun.star.awt.Toolkit" ) ); + + com.sun.star.awt.WindowDescriptor windowDescriptor = new com.sun.star.awt.WindowDescriptor(); + windowDescriptor.Type = com.sun.star.awt.WindowClass.TOP; + windowDescriptor.WindowServiceName = "modelessdialog"; // "floatingwindow" would need a parent + windowDescriptor.ParentIndex = -1; + //windowDescriptor.Parent = null; + + windowDescriptor.Bounds = new com.sun.star.awt.Rectangle( 500, 100, 400, 600 ); + windowDescriptor.WindowAttributes = com.sun.star.awt.WindowAttribute.BORDER + + com.sun.star.awt.WindowAttribute.MOVEABLE + + com.sun.star.awt.WindowAttribute.SIZEABLE + + com.sun.star.awt.WindowAttribute.CLOSEABLE + + com.sun.star.awt.VclWindowPeerAttribute.CLIPCHILDREN; + + return UnoRuntime.queryInterface( com.sun.star.awt.XWindow.class, + toolkit.createWindow( windowDescriptor ) ); + } +} diff --git a/extensions/qa/integration/extensions/ServicesHandler.java b/extensions/qa/integration/extensions/ServicesHandler.java new file mode 100644 index 0000000000..c84e128e88 --- /dev/null +++ b/extensions/qa/integration/extensions/ServicesHandler.java @@ -0,0 +1,212 @@ +/* + * 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 integration.extensions; + +import com.sun.star.uno.*; +import com.sun.star.beans.*; +import com.sun.star.inspection.*; +import com.sun.star.frame.*; +import com.sun.star.lang.XServiceInfo; + +public class ServicesHandler implements XPropertyHandler +{ + private final XComponentContext m_context; + private String[] m_supportedServices; + + private static class ClickHandler implements com.sun.star.awt.XActionListener + { + XComponentContext m_context; + private final String m_serviceName; + + public ClickHandler( XComponentContext _context, String _serviceName ) + { + m_context = _context; + m_serviceName = _serviceName; + } + + public void disposing(com.sun.star.lang.EventObject eventObject) + { + // not interested in + } + + public void actionPerformed(com.sun.star.awt.ActionEvent actionEvent) + { + try + { + // translate the service name into a URL to dispatch + String documentationURL = "https://api.libreoffice.org/docs/common/ref/" + m_serviceName.replace('.','/') + ".html"; + System.out.println( documentationURL ); + + // the OpenHyperlink command, to be dispatched to the Desktop + com.sun.star.util.URL dispatchURL[] = { new com.sun.star.util.URL() }; + dispatchURL[0].Complete = ".uno:OpenHyperlink"; + com.sun.star.util.XURLTransformer transformer = UnoRuntime.queryInterface( + com.sun.star.util.XURLTransformer.class, + m_context.getServiceManager().createInstanceWithContext( "com.sun.star.util.URLTransformer", m_context ) ); + transformer.parseStrict( dispatchURL ); + + // the dispatcher for the OpenHyperlink command + Frame desktop = new Frame( + m_context.getServiceManager().createInstanceWithContext( "com.sun.star.frame.Desktop", m_context ) ); + XDispatch dispatcher = desktop.queryDispatch(dispatchURL[0],"",0); + + // the arguments for the OpenHyperlink command + PropertyValue dispatchArgs[] = new PropertyValue[] { new PropertyValue() }; + dispatchArgs[0].Name = "URL"; + dispatchArgs[0].Value = documentationURL; + + dispatcher.dispatch(dispatchURL[0], dispatchArgs ); + } + catch( com.sun.star.uno.Exception e ) + { + e.printStackTrace( System.err ); + } + } + } + + /** Creates a new instance of ServicesHandler */ + public ServicesHandler( XComponentContext _context ) + { + m_context = _context; + m_supportedServices = new String[] { }; + } + + public void actuatingPropertyChanged(String _propertyName, Object _newValue, Object _oldValue, com.sun.star.inspection.XObjectInspectorUI _objectInspectorUI, boolean _firstTimeInit) throws com.sun.star.lang.NullPointerException + { + // not interested in + } + + public void addEventListener(com.sun.star.lang.XEventListener _eventListener) + { + // ignoring this + } + + public void addPropertyChangeListener(com.sun.star.beans.XPropertyChangeListener _propertyChangeListener) throws com.sun.star.lang.NullPointerException + { + // ignoring this + } + + public Object convertToControlValue(String _propertyName, Object _propertyValue, com.sun.star.uno.Type type) throws com.sun.star.beans.UnknownPropertyException + { + return _propertyValue; + } + + public Object convertToPropertyValue(String _propertyName, Object _controlValue) throws com.sun.star.beans.UnknownPropertyException + { + return _controlValue; + } + + public com.sun.star.inspection.LineDescriptor describePropertyLine(String _propertyName, com.sun.star.inspection.XPropertyControlFactory _propertyControlFactory) throws com.sun.star.beans.UnknownPropertyException, com.sun.star.lang.NullPointerException + { + com.sun.star.inspection.LineDescriptor descriptor = new com.sun.star.inspection.LineDescriptor(); + + descriptor = new LineDescriptor(); + descriptor.Category = "Services"; + descriptor.DisplayName = "supports service"; + descriptor.HasPrimaryButton = descriptor.HasSecondaryButton = false; + descriptor.IndentLevel = 0; + try + { + XHyperlinkControl hyperlinkControl = UnoRuntime.queryInterface( + XHyperlinkControl.class, _propertyControlFactory.createPropertyControl( PropertyControlType.HyperlinkField, true ) ); + hyperlinkControl.addActionListener( new ClickHandler( m_context, _propertyName ) ); + + descriptor.Control = hyperlinkControl; + } + catch( com.sun.star.lang.IllegalArgumentException e ) + { + } + return descriptor; + } + + public void dispose() + { + // nothing to do + } + + public String[] getActuatingProperties() + { + // none + return new String[] { }; + } + + public com.sun.star.beans.PropertyState getPropertyState(String _propertyName) throws com.sun.star.beans.UnknownPropertyException + { + return com.sun.star.beans.PropertyState.DIRECT_VALUE; + } + + public Object getPropertyValue(String _propertyName) throws com.sun.star.beans.UnknownPropertyException + { + return _propertyName; + } + + public String[] getSupersededProperties() + { + return new String[] { "SupportedServiceNames" }; + // we're used in conjunction with a GenericPropertyHandler, which (via inspection) finds + // a property SupportedServiceNames, resulting from the XServiceInfo.getSupportedServiceNames + // method. Since we handle those ourself, we supersede them. + } + + public com.sun.star.beans.Property[] getSupportedProperties() + { + Property[] properties = new Property[ m_supportedServices.length ]; + for ( int i=0; i 1 Then + WScript.Echo "Pass $(SRCDIR) as parameter" + WScript.Quit(1) +End If + +srcdir = WScript.Arguments.Item(0) + +exitStatus = 0 + +testCounter = 0 +okCounter = 0 + +Sub ExitWithReport + If okCounter <> testCounter Then + exitStatus = 1 + End If + WScript.Echo "OK (" + CStr(okCounter) + ")" + WScript.Quit(exitstatus) +End Sub + +Sub CheckFatal(expr) + testCounter = testCounter + 1 + If Not Eval(expr) Then + WScript.Echo "FAIL: " & expr + ExitWithReport + Else + WScript.Echo "PASS: " & expr + okCounter = okCounter + 1 + End If +End Sub + +Sub Check(expr) + testCounter = testCounter + 1 + If Not Eval(expr) Then + WScript.Echo "FAIL: " & expr + Else + WScript.Echo "PASS: " & expr + okCounter = okCounter + 1 + End If +End Sub + +Sub CheckIfExpected(expr, expected) + testCounter = testCounter + 1 + actual = Eval(expr) + If actual <> expected Then + WScript.Echo "FAIL: Value of '" & expr & "' was expected to be '" & CStr(expected) & "', but was " & CStr(actual) + Else + WScript.Echo "PASS: " & expr & " == " & CStr(expected) + okCounter = okCounter + 1 + End If +End Sub + +Sub CheckErrorFatal(test) + testCounter = testCounter + 1 + Execute(test) + If Err.Number <> 0 Then + WScript.Echo "FAIL: " & test + WScript.Echo "ERROR: " & Err.Description + ExitWithReport + Else + WScript.Echo "PASS: " & test + okCounter = okCounter + 1 + End If +End Sub + +Sub CheckError(test) + testCounter = testCounter + 1 + Execute(test) + If Err.Number <> 0 Then + WScript.Echo "FAIL: " & test + WScript.Echo "ERROR: " & Err.Description + Else + WScript.Echo "PASS: " & test + okCounter = okCounter + 1 + End If +End Sub + +WScript.Echo "Running Automation client tests" + +On Error Resume Next + +' FIXME: How can we ever make this work specifically with the +' LibreOffice in instdir, when WScript.CreateObject() wants the +' symbolic name that it then looks up from the Registry to find the +' CLSID of the class? + +CheckErrorFatal "Set writer = WScript.CreateObject(""Writer.Application"")" +CheckErrorFatal "writer.Visible = True" +CheckErrorFatal "writer.Caption = ""=== This is Writer ===""" +CheckErrorFatal "writer.ShowMe" + +CheckErrorFatal "Set documents = writer.Documents" + +' Open two randomly chosen documents +CheckErrorFatal "Set d1 = documents.Open(""" & srcdir & "/sw/qa/extras/ww8export/data/n325936.doc"")" +CheckErrorFatal "Set d2 = documents.Open(""" & srcdir & "/sw/qa/extras/ww8export/data/bnc636128.doc"")" + +CheckErrorFatal "n1 = d1.FullName" +CheckErrorFatal "n2 = d2.FullName" + +CheckIfExpected "n1", "n325936.doc" +CheckIfExpected "n2", "bnc636128.doc" + +CheckErrorFatal "Set c1 = d1.Content" +CheckErrorFatal "Set c2 = d2.Content" + +' The range of characters in these documents +CheckIfExpected "c1.Start", 0 +CheckIfExpected "c1.End", 4 +CheckIfExpected "c2.Start", 0 +CheckIfExpected "c2.End", 42 + +' Check number of paragraphs in each document +CheckErrorFatal "Set p1 = d1.Paragraphs" +nparas = 0 +For Each i in p1 + nparas = nparas + 1 +Next +CheckIfExpected "nparas", 1 + +CheckErrorFatal "Set p2 = d2.Paragraphs" +nparas = 0 +For Each i in p2 + nparas = nparas + 1 +Next +CheckIfExpected "nparas", 1 + +CheckErrorFatal "writer.Quit" + +ExitWithReport diff --git a/extensions/qa/unoapi/extensions.sce b/extensions/qa/unoapi/extensions.sce new file mode 100644 index 0000000000..b63a954b76 --- /dev/null +++ b/extensions/qa/unoapi/extensions.sce @@ -0,0 +1,5 @@ +-o pcr.ObjectInspector +# this object must be tested twice, because it is the only one in this module +# The runner only prints "[0-9]+? of [0-9]+? tests failed" +# if more than one tests is executed. This is needed by cwscheckapi. +-o pcr.ObjectInspector diff --git a/extensions/qa/update/simple.xml b/extensions/qa/update/simple.xml new file mode 100644 index 0000000000..f2694700ad --- /dev/null +++ b/extensions/qa/update/simple.xml @@ -0,0 +1,18 @@ + + + + LibreOffice 3.5.0 Beta2 + 3.5.0 Beta2 + 123456-abcdef-1a2b3c-4d5e6f + Linux + x86 + + + diff --git a/extensions/qa/update/test_update.cxx b/extensions/qa/update/test_update.cxx new file mode 100644 index 0000000000..27d634b3b3 --- /dev/null +++ b/extensions/qa/update/test_update.cxx @@ -0,0 +1,152 @@ +/* + * 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/. + */ + +#include + +#include + +#include + +#include +#include +#include + +#include "../../source/update/check/updatecheck.hxx" +#include "../../source/update/check/updateprotocol.hxx" + +using namespace com::sun::star; +using namespace com::sun::star::xml; + +namespace testupdate { + +class Test : public test::BootstrapFixture +{ +public: + virtual void setUp() override + { + // so that comphelper::getProcessServiceFactory() works, m_xContext is + // set up, etc. + test::BootstrapFixture::setUp(); + + if ( !m_xProvider.is() ) + m_xProvider = deployment::UpdateInformationProvider::create( m_xContext ); + + // repositories that we will be checking + m_aRepositoryList = { m_directories.getURLFromSrc( u"/extensions/qa/update/simple.xml" ) }; + } + + virtual void tearDown() override + { + m_xProvider.clear(); + m_aRepositoryList.realloc( 0 ); + test::BootstrapFixture::tearDown(); + } + +protected: + // test the getUpdateInformationEnumeration() method + void testGetUpdateInformationEnumeration() + { + uno::Reference< container::XEnumeration > aUpdateInfoEnumeration = + m_xProvider->getUpdateInformationEnumeration( + m_aRepositoryList, + "TODO" ); // unused when we do not have a 'feed' + + if ( !aUpdateInfoEnumeration.is() ) + CPPUNIT_FAIL( "Calling getUpdateInformationEnumeration() with TODO failed." ); + + if ( !aUpdateInfoEnumeration->hasMoreElements() ) + CPPUNIT_FAIL( "Should have more elements (this one is 1st)." ); + + deployment::UpdateInformationEntry aEntry; + if ( aUpdateInfoEnumeration->nextElement() >>= aEntry ) + { + CPPUNIT_ASSERT_EQUAL( OUString("description"), aEntry.UpdateDocument->getNodeName() ); + + uno::Reference< dom::XNodeList> xChildNodes = aEntry.UpdateDocument->getChildNodes(); + CPPUNIT_ASSERT( xChildNodes.is() ); +#if 0 + for ( int i = 0; i < xChildNodes->getLength(); ++i ) + { + fprintf( stderr, "node == %d\n", i ); + uno::Reference< dom::XElement > xChildId( xChildNodes->item( i ), uno::UNO_QUERY ); + if ( xChildId.is() ) + { + fprintf( stderr, "Name == %s\n", OUStringToOString( xChildId->getNodeName(), RTL_TEXTENCODING_UTF8 ).getStr() ); + fprintf( stderr, "Value == %s\n", OUStringToOString( xChildId->getNodeValue(), RTL_TEXTENCODING_UTF8 ).getStr() ); + } + } +#endif + CPPUNIT_ASSERT_EQUAL( sal_Int32(13), xChildNodes->getLength() ); + + //uno::Reference< dom::XElement > xChildId( xChildNodes->item( 0 ), uno::UNO_QUERY ); + //CPPUNIT_ASSERT( xChildId.is() ); + //CPPUNIT_ASSERT( xChildId->getNodeValue() == "LibreOffice_3.4" ); + //fprintf( stderr, "Attribute == %s\n", OUStringToOString( aEntry.UpdateDocument->getAttribute( OUString( "test" ) ), RTL_TEXTENCODING_UTF8 ).getStr() ); + //fprintf( stderr, "Value == %s\n", OUStringToOString( xChildId->getNodeValue(), RTL_TEXTENCODING_UTF8 ).getStr() ); + // TODO check more deeply + } + else + CPPUNIT_FAIL( "Wrong type of the entry." ); + } + + // test the checkForUpdates() method - update is available + void testCheckUpdateAvailable() + { + UpdateInfo aInfo; + rtl::Reference< UpdateCheck > aController( UpdateCheck::get() ); + + if ( checkForUpdates( aInfo, m_xContext, aController->getInteractionHandler(), m_xProvider, + u"Linux", + u"x86", + m_aRepositoryList, + u"111111-222222-333333-444444", + "InstallSetID" ) ) + { + CPPUNIT_ASSERT_EQUAL( std::size_t(1), aInfo.Sources.size() ); + CPPUNIT_ASSERT_EQUAL( OUString("http://www.libreoffice.org/download/"), aInfo.Sources[0].URL ); + } + else + CPPUNIT_FAIL( "Calling checkForUpdates() failed." ); + } + + // test the checkForUpdates() method - we are up-to-date + void testCheckUpToDate() + { + UpdateInfo aInfo; + rtl::Reference< UpdateCheck > aController( UpdateCheck::get() ); + + if ( checkForUpdates( aInfo, m_xContext, aController->getInteractionHandler(), m_xProvider, + u"Linux", + u"x86", + m_aRepositoryList, + u"123456-abcdef-1a2b3c-4d5e6f", + "InstallSetID" ) ) + { + CPPUNIT_ASSERT( aInfo.Sources.empty() ); + } + else + CPPUNIT_FAIL( "Calling checkForUpdates() failed." ); + } + + CPPUNIT_TEST_SUITE(Test); + CPPUNIT_TEST(testGetUpdateInformationEnumeration); + CPPUNIT_TEST(testCheckUpdateAvailable); + CPPUNIT_TEST(testCheckUpToDate); + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Reference< deployment::XUpdateInformationProvider > m_xProvider; + uno::Sequence< OUString > m_aRepositoryList; +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(testupdate::Test); +} // namespace testupdate + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ -- cgit v1.2.3