diff options
-rw-r--r-- | testtools/com/sun/star/comp/bridge/TestComponent.java | 782 | ||||
-rw-r--r-- | testtools/com/sun/star/comp/bridge/makefile.mk | 94 | ||||
-rw-r--r-- | testtools/com/sun/star/comp/bridge/manifest | 2 | ||||
-rw-r--r-- | testtools/prj/build.lst | 4 | ||||
-rw-r--r-- | testtools/prj/d.lst | 2 | ||||
-rw-r--r-- | testtools/source/bridgetest/bridgetest.cxx | 669 | ||||
-rw-r--r-- | testtools/source/bridgetest/cppobj.cxx | 535 | ||||
-rw-r--r-- | testtools/source/bridgetest/makefile.mk | 80 | ||||
-rw-r--r-- | testtools/source/performance/exports.dxp | 3 | ||||
-rw-r--r-- | testtools/source/performance/makefile.mk | 97 | ||||
-rw-r--r-- | testtools/source/performance/pseudo.cxx | 288 | ||||
-rw-r--r-- | testtools/source/performance/ubobject.cxx | 307 | ||||
-rw-r--r-- | testtools/source/performance/ubtest.cxx | 1371 |
13 files changed, 4234 insertions, 0 deletions
diff --git a/testtools/com/sun/star/comp/bridge/TestComponent.java b/testtools/com/sun/star/comp/bridge/TestComponent.java new file mode 100644 index 000000000000..12edef2d8e83 --- /dev/null +++ b/testtools/com/sun/star/comp/bridge/TestComponent.java @@ -0,0 +1,782 @@ +/************************************************************************* + * + * $RCSfile: TestComponent.java,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: kr $ $Date: 2001-05-04 07:05:17 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRUNTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRUNTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc.. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +package com.sun.star.comp.bridge; + + +import com.sun.star.comp.loader.FactoryHelper; + +import com.sun.star.lang.XServiceInfo; +import com.sun.star.lang.XTypeProvider; + +import com.sun.star.test.performance.ComplexTypes; +import com.sun.star.test.performance.XPerformanceTest; + +import com.sun.star.test.bridge.TestDataElements; +import com.sun.star.test.bridge.TestElement; +import com.sun.star.test.bridge.TestEnum; +import com.sun.star.test.bridge.XBridgeTest; +import com.sun.star.test.bridge.XRecursiveCall; + +import com.sun.star.lang.XMultiServiceFactory; +import com.sun.star.lang.XSingleServiceFactory; + +import com.sun.star.registry.XRegistryKey; + +import com.sun.star.uno.Type; + + +public class TestComponent { + static public final boolean DEBUG = false; + + static public class _PerformancTestObject implements XPerformanceTest, XServiceInfo, XTypeProvider { + static private final String __serviceName = "com.sun.star.comp.benchmark.JavaTestObject"; + + private boolean _bool; + private char _char; + private byte _byte; + private short _short; + private int _long; + private int _ulong; + private long _hyper; + private float _float; + private double _double; + private String _string = ""; + private Object _xInterface; + private Object _any; + private Object _interface_sequence[] = new Object[0]; + private ComplexTypes _complexTypes = new ComplexTypes(); + + // Attributes + public int getLong_attr() throws com.sun.star.uno.RuntimeException { + return _long; + } + + public void setLong_attr( int _long_attr ) throws com.sun.star.uno.RuntimeException { + _long = _long_attr; + } + + public long getHyper_attr() throws com.sun.star.uno.RuntimeException { + return _hyper; + } + + public void setHyper_attr( long _hyper_attr ) throws com.sun.star.uno.RuntimeException { + _hyper = _hyper_attr; + } + + public float getFloat_attr() throws com.sun.star.uno.RuntimeException { + return _float; + } + + public void setFloat_attr( float _float_attr ) throws com.sun.star.uno.RuntimeException { + _float = _float; + } + + public double getDouble_attr() throws com.sun.star.uno.RuntimeException { + return _double; + } + + public void setDouble_attr( double _double_attr ) throws com.sun.star.uno.RuntimeException { + _double = _double_attr; + } + + public String getString_attr() throws com.sun.star.uno.RuntimeException { + return _string; + } + + public void setString_attr( String _string_attr ) throws com.sun.star.uno.RuntimeException { + _string = _string_attr; + } + + public Object getInterface_attr() throws com.sun.star.uno.RuntimeException { + return _xInterface; + } + + public void setInterface_attr( java.lang.Object _interface_attr ) throws com.sun.star.uno.RuntimeException { + _xInterface = _interface_attr; + } + + public Object getAny_attr() throws com.sun.star.uno.RuntimeException { + return _any; + } + + public void setAny_attr(Object _any_attr ) throws com.sun.star.uno.RuntimeException { + _any = _any_attr; + } + + public Object[] getSequence_attr() throws com.sun.star.uno.RuntimeException { + return _interface_sequence; + } + + public void setSequence_attr(Object[] _sequence_attr ) throws com.sun.star.uno.RuntimeException { + _interface_sequence = _sequence_attr; + } + + public ComplexTypes getStruct_attr() throws com.sun.star.uno.RuntimeException { + return _complexTypes; + } + + public void setStruct_attr( ComplexTypes _struct_attr ) throws com.sun.star.uno.RuntimeException { + _complexTypes = _struct_attr; + } + + + // Methods + public void async() throws com.sun.star.uno.RuntimeException { + } + + public void sync( ) throws com.sun.star.uno.RuntimeException { + } + + public ComplexTypes complex_in( /*IN*/ComplexTypes aVal ) throws com.sun.star.uno.RuntimeException { + return aVal; + } + + public ComplexTypes complex_inout( /*INOUT*/ComplexTypes[] aVal ) throws com.sun.star.uno.RuntimeException { + return aVal[0]; + } + + public void complex_oneway( /*IN*/ComplexTypes aVal ) throws com.sun.star.uno.RuntimeException { + } + + public void complex_noreturn( /*IN*/ComplexTypes aVal ) throws com.sun.star.uno.RuntimeException { + } + + public XPerformanceTest createObject( ) throws com.sun.star.uno.RuntimeException { + return new _PerformancTestObject(); + } + + public int getLong() throws com.sun.star.uno.RuntimeException { + return _long; + } + + public void setLong(/*IN*/int n) throws com.sun.star.uno.RuntimeException { + _long = n; + } + + public long getHyper() throws com.sun.star.uno.RuntimeException { + return _hyper; + } + + public void setHyper(/*IN*/long n) throws com.sun.star.uno.RuntimeException { + _hyper = n; + } + + public float getFloat() throws com.sun.star.uno.RuntimeException { + return _float; + } + + public void setFloat( /*IN*/float f ) throws com.sun.star.uno.RuntimeException { + _float = f; + } + + public double getDouble( ) throws com.sun.star.uno.RuntimeException { + return _double; + } + + public void setDouble( /*IN*/double f ) throws com.sun.star.uno.RuntimeException { + _double = f; + } + + public String getString( ) throws com.sun.star.uno.RuntimeException { + return _string; + } + + public void setString( /*IN*/String s ) throws com.sun.star.uno.RuntimeException { + _string = s; + } + + public Object getInterface( ) throws com.sun.star.uno.RuntimeException { + return _xInterface; + } + + public void setInterface( /*IN*/Object x ) throws com.sun.star.uno.RuntimeException { + _xInterface = x; + } + + public Object getAny( ) throws com.sun.star.uno.RuntimeException { + return _any; + } + + public void setAny( /*IN*/java.lang.Object a ) throws com.sun.star.uno.RuntimeException { + _any = a; + } + + public Object[] getSequence( ) throws com.sun.star.uno.RuntimeException { + return _interface_sequence; + } + + public void setSequence( /*IN*/Object[] seq ) throws com.sun.star.uno.RuntimeException { + if(DEBUG) System.err.println("#### " + getClass().getName() + ".setSequence:" + seq); + + _interface_sequence = seq; + } + + public ComplexTypes getStruct( ) throws com.sun.star.uno.RuntimeException { + return _complexTypes; + } + + public void setStruct( /*IN*/ComplexTypes c ) throws com.sun.star.uno.RuntimeException { + _complexTypes = c; + } + + public void raiseRuntimeException( ) throws com.sun.star.uno.RuntimeException { + throw new com.sun.star.uno.RuntimeException(); + } + + // XServiceInfo + public String getImplementationName() throws com.sun.star.uno.RuntimeException { + return __serviceName; + } + + public boolean supportsService(String rServiceName) throws com.sun.star.uno.RuntimeException { + String rSNL[] = getSupportedServiceNames(); + + for(int nPos = rSNL.length; (nPos--) != 0;) { + if (rSNL[nPos].equals(rServiceName)) + return true; + } + + return false; + } + + public String [] getSupportedServiceNames() throws com.sun.star.uno.RuntimeException { + return new String[]{__serviceName}; + } + + // XTypeProvider + public Type[] getTypes() throws com.sun.star.uno.RuntimeException { + try { + return new Type[]{new Type(XPerformanceTest.class), new Type(XServiceInfo.class), new Type(XTypeProvider.class)}; + } + catch(Exception exception) { + throw new com.sun.star.uno.RuntimeException(exception.getMessage()); + } + } + + public byte[] getImplementationId() throws com.sun.star.uno.RuntimeException { + return toString().getBytes(); + } + } + + static public class _TestObject implements XBridgeTest, XRecursiveCall, XServiceInfo, XTypeProvider { + static private final String __serviceName = "com.sun.star.test.bridge.JavaTestObject"; + + private boolean _bool; + private char _char; + private byte _byte; + private short _short; + private short _ushort; + private int _long; + private int _ulong; + private long _hyper; + private long _uhyper; + private float _float; + private double _double; + private String _string; + private Object _xInterface; + private Object _any; + private TestEnum _testEnum = TestEnum.TEST; + private TestElement _testElements[] = new TestElement[0]; + private TestDataElements _testDataElements = new TestDataElements(); + + private int _nLastCallId; + private boolean _bFirstCall; + private boolean _bSequenceOfCallTestPassed; + + public _TestObject(XMultiServiceFactory xMultiServiceFactory) { + if(DEBUG) System.err.println("##### " + getClass().getName() + ".<init> " + xMultiServiceFactory); + + _nLastCallId = 0; + _bFirstCall = true; + _bSequenceOfCallTestPassed = true; + } + + + public void setValues(boolean bBool, + char cChar, + byte nByte, + short nShort, + short nUShort, + int nLong, + int nULong, + long nHyper, + long nUHyper, + float fFloat, + double fDouble, + TestEnum testEnum, + String string, + Object xInterface, + Object any, + TestElement testElements[], + TestDataElements testDataElements) throws com.sun.star.uno.RuntimeException + { + if(DEBUG) System.err.println("##### " + getClass().getName() + ".setValues:" + any); + + _bool = bBool; + _char = cChar; + _byte = nByte; + _short = nShort; + _ushort = nUShort; + _long = nLong; + _ulong = nULong; + _hyper = nHyper; + _uhyper = nUHyper; + _float = fFloat; + _double = fDouble; + _testEnum = testEnum; + _string = string; + _xInterface = xInterface; + _any = any; + _testElements = testElements; + _testDataElements = testDataElements; + } + + + + public TestDataElements setValues2(/*INOUT*/boolean[] io_bool, + /*INOUT*/char[] io_char, + /*INOUT*/byte[] io_byte, + /*INOUT*/short[] io_short, + /*INOUT*/short[] io_ushort, + /*INOUT*/int[] io_long, + /*INOUT*/int[] io_ulong, + /*INOUT*/long[] io_hyper, + /*INOUT*/long[] io_uhyper, + /*INOUT*/float[] io_float, + /*INOUT*/double[] io_double, + /*INOUT*/TestEnum[] io_testEnum, + /*INOUT*/String[] io_string, + /*INOUT*/Object[] io_xInterface, + /*INOUT*/Object[] io_any, + /*INOUT*/TestElement[][] io_testElements, + /*INOUT*/TestDataElements[] io_testDataElements) throws com.sun.star.uno.RuntimeException + { + if(DEBUG) System.err.println("##### " + getClass().getName() + ".setValues2:" + io_any[0]); + + _bool = io_bool[0]; + _char = io_char[0]; + _byte = io_byte[0]; + _short = io_short[0]; + _ushort = io_ushort[0]; + _long = io_long[0]; + _ulong = io_ulong[0]; + _hyper = io_hyper[0]; + _uhyper = io_uhyper[0]; + _float = io_float[0]; + _double = io_double[0]; + _testEnum = io_testEnum[0]; + _string = io_string[0]; + _xInterface = io_xInterface[0]; + _any = io_any[0]; + _testElements = io_testElements[0]; + _testDataElements = io_testDataElements[0]; + + return _testDataElements; + } + + public TestDataElements getValues(/*OUT*/boolean[] o_bool, + /*OUT*/char[] o_char, + /*OUT*/byte[] o_byte, + /*OUT*/short[] o_short, + /*OUT*/short[] o_ushort, + /*OUT*/int[] o_long, + /*OUT*/int[] o_ulong, + /*OUT*/long[] o_hyper, + /*OUT*/long[] o_uhyper, + /*OUT*/float[] o_float, + /*OUT*/double[] o_double, + /*OUT*/TestEnum[] o_testEnum, + /*OUT*/String[] o_string, + /*OUT*/Object[] o_xInterface, + /*OUT*/Object[] o_any, + /*OUT*/TestElement[][] o_testElements, + /*OUT*/TestDataElements[] o_testDataElements) throws com.sun.star.uno.RuntimeException + { + if(DEBUG) System.err.println("##### " + getClass().getName() + ".getValues:" + _any); + + o_bool[0] = _bool; + o_char[0] = _char; + o_byte[0] = _byte; + o_short[0] = _short; + o_ushort[0] = _ushort; + o_long[0] = _long; + o_ulong[0] = _ulong; + o_hyper[0] = _hyper; + o_uhyper[0] = _uhyper; + o_float[0] = _float; + o_double[0] = _double; + o_testEnum[0] = _testEnum; + o_string[0] = _string; + o_xInterface[0] = _xInterface; + o_any[0] = _any; + o_testElements[0] = _testElements; + o_testDataElements[0] = _testDataElements; + + return _testDataElements; + } + + // Attributes + public boolean getBool() throws com.sun.star.uno.RuntimeException { + return _bool; + } + + public void setBool(boolean bool) throws com.sun.star.uno.RuntimeException { + _bool = bool; + } + + public byte getByte() throws com.sun.star.uno.RuntimeException { + return _byte; + } + + public void setByte(byte zbyte) throws com.sun.star.uno.RuntimeException { + _byte = zbyte; + } + + public char getChar() throws com.sun.star.uno.RuntimeException { + return _char; + } + + public void setChar(char zchar) throws com.sun.star.uno.RuntimeException { + _char = zchar; + } + + public short getShort() throws com.sun.star.uno.RuntimeException { + return _short; + } + + public void setShort(short zshort) throws com.sun.star.uno.RuntimeException { + _short = zshort; + } + + public short getUShort() throws com.sun.star.uno.RuntimeException { + return _ushort; + } + + public void setUShort(short ushort) throws com.sun.star.uno.RuntimeException { + _ushort = ushort; + } + + public int getLong() throws com.sun.star.uno.RuntimeException { + return _long; + } + + public void setLong(int zint) throws com.sun.star.uno.RuntimeException { + _long = zint; + } + + public int getULong() throws com.sun.star.uno.RuntimeException { + return _ulong; + } + + public void setULong(int uint) throws com.sun.star.uno.RuntimeException { + _ulong = uint; + } + + public long getHyper() throws com.sun.star.uno.RuntimeException { + return _hyper; + } + + public void setHyper(long hyper) throws com.sun.star.uno.RuntimeException { + _hyper = hyper; + } + + public long getUHyper() throws com.sun.star.uno.RuntimeException { + return _uhyper; + } + + public void setUHyper(long uhyper) throws com.sun.star.uno.RuntimeException { + _uhyper = uhyper; + } + + public float getFloat() throws com.sun.star.uno.RuntimeException { + return _float; + } + + public void setFloat(float zfloat) throws com.sun.star.uno.RuntimeException { + _float = zfloat; + } + + public double getDouble() throws com.sun.star.uno.RuntimeException { + return _double; + } + + public void setDouble(double zdouble) throws com.sun.star.uno.RuntimeException { + _double = zdouble; + } + + public TestEnum getEnum() throws com.sun.star.uno.RuntimeException { + return _testEnum; + } + + public void setEnum(TestEnum testEnum) throws com.sun.star.uno.RuntimeException { + _testEnum = testEnum; + } + + public String getString() throws com.sun.star.uno.RuntimeException { + return _string; + } + + public void setString(String string) throws com.sun.star.uno.RuntimeException { + _string = string; + } + + public Object getInterface() throws com.sun.star.uno.RuntimeException { + return _xInterface; + } + + public void setInterface(Object zinterface) throws com.sun.star.uno.RuntimeException { + _xInterface = zinterface; + } + + public Object getAny() throws com.sun.star.uno.RuntimeException { + if(DEBUG) System.err.println("##### " + getClass().getName() + ".setAny:" + _any); + + return _any; + } + + public void setAny(Object any) throws com.sun.star.uno.RuntimeException { + if(DEBUG) System.err.println("##### " + getClass().getName() + ".setAny:" + any); + + _any = any; + } + + public TestElement[] getSequence() throws com.sun.star.uno.RuntimeException { + return _testElements; + } + + public void setSequence(TestElement testElements[]) throws com.sun.star.uno.RuntimeException { + _testElements = testElements; + } + + public TestDataElements getStruct() throws com.sun.star.uno.RuntimeException { + return _testDataElements; + } + + public void setStruct(TestDataElements testDataElements) throws com.sun.star.uno.RuntimeException { + _testDataElements = testDataElements; + } + + public Object transportAny(Object value) throws com.sun.star.uno.RuntimeException { + return value; + } + + public void call(int nCallId , int nWaitMUSEC) throws com.sun.star.uno.RuntimeException { +// TimeValue value = { nWaitMUSEC / 1000000 , nWaitMUSEC * 1000 }; +// osl_waitThread( &value ); + try { + Thread.sleep(nWaitMUSEC / 10000); + } + catch(InterruptedException interruptedException) { + throw new com.sun.star.uno.RuntimeException(interruptedException.getMessage()); + } + + if(_bFirstCall) + _bFirstCall = false; + + else + _bSequenceOfCallTestPassed = _bSequenceOfCallTestPassed && (nCallId > _nLastCallId); + + _nLastCallId = nCallId; + } + + public void callOneway( int nCallId , int nWaitMUSEC ) throws com.sun.star.uno.RuntimeException { +// TimeValue value = { nWaitMUSEC / 1000000 , nWaitMUSEC * 1000 }; +// osl_waitThread( &value ); + try { + Thread.sleep(nWaitMUSEC / 10000); + } + catch(InterruptedException interruptedException) { + throw new com.sun.star.uno.RuntimeException(interruptedException.getMessage()); + } + + _bSequenceOfCallTestPassed = _bSequenceOfCallTestPassed && (nCallId > _nLastCallId); + _nLastCallId = nCallId; + } + + public boolean sequenceOfCallTestPassed() throws com.sun.star.uno.RuntimeException { + return _bSequenceOfCallTestPassed; + } + + public synchronized void callRecursivly(com.sun.star.test.bridge.XRecursiveCall xCall, int nToCall) throws com.sun.star.uno.RuntimeException { + if(nToCall != 0) + { + nToCall --; + xCall.callRecursivly(this , nToCall); + } + } + + public synchronized void startRecursiveCall(com.sun.star.test.bridge.XRecursiveCall xCall, int nToCall) throws com.sun.star.uno.RuntimeException { + if(nToCall != 0) + { + nToCall --; + xCall.callRecursivly( this , nToCall ); + } + } + + + // XBridgeTest + public TestDataElements raiseException(short nArgumentPos, String rMsg, Object xContext) + throws com.sun.star.lang.IllegalArgumentException, + com.sun.star.uno.RuntimeException + { + throw new com.sun.star.lang.IllegalArgumentException(rMsg, xContext, nArgumentPos); + } + + public void raiseRuntimeExceptionOneway(String rMsg, Object xContext) throws com.sun.star.uno.RuntimeException { + throw new com.sun.star.uno.RuntimeException(rMsg, xContext); + } + + public int getRuntimeException() throws com.sun.star.uno.RuntimeException { + throw new com.sun.star.uno.RuntimeException(_string, _xInterface); + } + + public void setRuntimeException(int _runtimeexception) throws com.sun.star.uno.RuntimeException { + throw new com.sun.star.uno.RuntimeException(_string, _xInterface); + } + + + + // XServiceInfo + public String getImplementationName() throws com.sun.star.uno.RuntimeException { + return __serviceName; + } + + public boolean supportsService(String rServiceName) throws com.sun.star.uno.RuntimeException { + String rSNL[] = getSupportedServiceNames(); + + for(int nPos = rSNL.length; (nPos--) != 0;) { + if (rSNL[nPos].equals(rServiceName)) + return true; + } + + return false; + } + + public String [] getSupportedServiceNames() throws com.sun.star.uno.RuntimeException { + return new String[]{__serviceName}; + } + + // XTypeProvider + public Type[] getTypes() throws com.sun.star.uno.RuntimeException { + try { + return new Type[]{new Type(XBridgeTest.class), new Type(XRecursiveCall.class), new Type(XServiceInfo.class), new Type(XTypeProvider.class)}; + } + catch(Exception exception) { + throw new com.sun.star.uno.RuntimeException(exception.getMessage()); + } + } + + public byte[] getImplementationId() throws com.sun.star.uno.RuntimeException { + return toString().getBytes(); + } + } + + /** + * Gives a factory for creating the service. + * This method is called by the <code>JavaLoader</code> + * <p> + * @return returns a <code>XSingleServiceFactory</code> for creating the component + * @param implName the name of the implementation for which a service is desired + * @param multiFactory the service manager to be uses if needed + * @param regKey the registryKey + * @see com.sun.star.comp.loader.JavaLoader + */ + public static XSingleServiceFactory __getServiceFactory(String implName, + XMultiServiceFactory multiFactory, + XRegistryKey regKey) + { + XSingleServiceFactory xSingleServiceFactory = null; + + if(implName.equals(_TestObject.class.getName())) + xSingleServiceFactory = FactoryHelper.getServiceFactory(_TestObject.class, + _TestObject.__serviceName, + multiFactory, + regKey); + + else if(implName.equals(_PerformancTestObject.class.getName())) + xSingleServiceFactory = FactoryHelper.getServiceFactory(_PerformancTestObject.class, + _PerformancTestObject.__serviceName, + multiFactory, + regKey); + + return xSingleServiceFactory; + } + + /** + * Writes the service information into the given registry key. + * This method is called by the <code>JavaLoader</code> + * <p> + * @return returns true if the operation succeeded + * @param regKey the registryKey + * @see com.sun.star.comp.loader.JavaLoader + */ + public static boolean __writeRegistryServiceInfo(XRegistryKey regKey) { + boolean result = true; + + result = result & FactoryHelper.writeRegistryServiceInfo(_TestObject.class.getName(), _TestObject.__serviceName, regKey); + result = result & FactoryHelper.writeRegistryServiceInfo(_PerformancTestObject.class.getName(), + _PerformancTestObject.__serviceName, regKey); + + return result; + } + +} diff --git a/testtools/com/sun/star/comp/bridge/makefile.mk b/testtools/com/sun/star/comp/bridge/makefile.mk new file mode 100644 index 000000000000..e767cb64aa93 --- /dev/null +++ b/testtools/com/sun/star/comp/bridge/makefile.mk @@ -0,0 +1,94 @@ +#************************************************************************* +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.1 $ +# +# last change: $Author: kr $ $Date: 2001-05-04 07:05:17 $ +# +# The Contents of this file are made available subject to the terms of +# either of the following licenses +# +# - GNU Lesser General Public License Version 2.1 +# - Sun Industry Standards Source License Version 1.1 +# +# Sun Microsystems Inc., October, 2000 +# +# GNU Lesser General Public License Version 2.1 +# ============================================= +# Copyright 2000 by Sun Microsystems, Inc. +# 901 San Antonio Road, Palo Alto, CA 94303, USA +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License version 2.1, as published by the Free Software Foundation. +# +# This library 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 for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, +# MA 02111-1307 USA +# +# +# Sun Industry Standards Source License Version 1.1 +# ================================================= +# The contents of this file are subject to the Sun Industry Standards +# Source License Version 1.1 (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.openoffice.org/license.html. +# +# Software provided under this License is provided on an "AS IS" basis, +# WITHOUT WARRUNTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, +# WITHOUT LIMITATION, WARRUNTIES THAT THE SOFTWARE IS FREE OF DEFECTS, +# MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. +# See the License for the specific provisions governing your rights and +# obligations concerning the Software. +# +# The Initial Developer of the Original Code is: Sun Microsystems, Inc.. +# +# Copyright: 2000 by Sun Microsystems, Inc. +# +# All Rights Reserved. +# +# Contributor(s): _______________________________________ +# +# +# +#************************************************************************* + +PRJ=..$/..$/..$/..$/.. +PRJNAME=testtools +PACKAGE=com$/sun$/star$/comp$/bridge +TARGET=com_sun_star_comp_bridge + + +# --- Settings ----------------------------------------------------- + +.INCLUDE : settings.mk + +# ------------------------------------------------------------------ + + +JARFILES = sandbox.jar ridl.jar jurt.jar + + +JAVACLASSFILES= \ + $(CLASSDIR)$/$(PACKAGE)$/TestComponent.class + +JAVAFILES = $(subst,$(CLASSDIR)$/$(PACKAGE)$/, $(subst,.class,.java $(JAVACLASSFILES))) + + +JARCLASSDIRS = $(PACKAGE) +JARTARGET = testComponent.jar +JARCOMPRESS = TRUE +CUSTOMMANIFESTFILE = manifest + +# --- Targets ------------------------------------------------------ + +.INCLUDE : target.mk + + diff --git a/testtools/com/sun/star/comp/bridge/manifest b/testtools/com/sun/star/comp/bridge/manifest new file mode 100644 index 000000000000..15c109825aef --- /dev/null +++ b/testtools/com/sun/star/comp/bridge/manifest @@ -0,0 +1,2 @@ +RegistrationClassName: com.sun.star.comp.bridge.TestComponent + diff --git a/testtools/prj/build.lst b/testtools/prj/build.lst new file mode 100644 index 000000000000..66ba3010f30a --- /dev/null +++ b/testtools/prj/build.lst @@ -0,0 +1,4 @@ +tt testtools : cppuhelper NULL +tt testtools usr1 - all tt_mkout NULL +tt testtools\source\bridgetest nmake - all tt_bridgetest NULL +tt testtools\com\sun\star\comp\bridge nmake - all tt_javaTestObjs NULL diff --git a/testtools/prj/d.lst b/testtools/prj/d.lst new file mode 100644 index 000000000000..a787c3a4c3c0 --- /dev/null +++ b/testtools/prj/d.lst @@ -0,0 +1,2 @@ +..\%__SRC%\bin\*.dll %_DEST%\bin%_EXT%\* +..\%__SRC%\lib\*.so %_DEST%\lib%_EXT%\* diff --git a/testtools/source/bridgetest/bridgetest.cxx b/testtools/source/bridgetest/bridgetest.cxx new file mode 100644 index 000000000000..a9814a693e37 --- /dev/null +++ b/testtools/source/bridgetest/bridgetest.cxx @@ -0,0 +1,669 @@ +/************************************************************************** +#* +#* last change $Author: kr $ $Date: 2001-05-04 07:05:17 $ +#* $Revision: 1.1 $ +#* +#* $Logfile: $ +#* +#* Copyright (c) 1989 - 2000, Star Office GmbH +#* +#************************************************************************/ + +#include <stdio.h> +#include <osl/diagnose.h> + +#include <uno/dispatcher.h> +#include <uno/mapping.hxx> +#include <uno/data.h> +#include <uno/environment.h> + +#include <cppuhelper/factory.hxx> +#include <cppuhelper/implbase2.hxx> +#include <cppuhelper/implbase1.hxx> + +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/lang/XMain.hpp> +#include <com/sun/star/registry/XRegistryKey.hpp> +#include <com/sun/star/bridge/XUnoUrlResolver.hpp> + +#include <com/sun/star/test/bridge/XBridgeTest.hpp> + +using namespace rtl; +using namespace osl; +using namespace cppu; +using namespace com::sun::star::uno; +using namespace com::sun::star::lang; +using namespace com::sun::star::registry; +using namespace com::sun::star::bridge; +using namespace com::sun::star::test::bridge; + +#define SERVICENAME "com.sun.star.test.bridge.BridgeTest" +#define IMPLNAME "com.sun.star.comp.bridge.BridgeTest" + +namespace bridge_test +{ + +//-------------------------------------------------------------------------------------------------- +inline static Sequence< OUString > getSupportedServiceNames() +{ + OUString aName( RTL_CONSTASCII_USTRINGPARAM(SERVICENAME) ); + return Sequence< OUString >( &aName, 1 ); +} + +//================================================================================================== +class TestBridgeImpl : public WeakImplHelper2< XMain, XServiceInfo > +{ + Reference< XMultiServiceFactory > _xMgr; + +public: + TestBridgeImpl( const Reference< XMultiServiceFactory > & xMgr_ ) + : _xMgr( xMgr_ ) + {} + + // XServiceInfo + virtual OUString SAL_CALL getImplementationName() throw (RuntimeException); + virtual sal_Bool SAL_CALL supportsService( const OUString & rServiceName ) throw (RuntimeException); + virtual Sequence< OUString > SAL_CALL getSupportedServiceNames() throw (RuntimeException); + + // XMain + virtual sal_Int32 SAL_CALL run( const Sequence< OUString > & rArgs ) throw (RuntimeException); +}; + +//================================================================================================== +static sal_Bool equals( const TestElement & rData1, const TestElement & rData2 ) +{ + OSL_ENSURE( rData1.Bool == rData2.Bool, "### bool does not match!" ); + OSL_ENSURE( rData1.Char == rData2.Char, "### char does not match!" ); + OSL_ENSURE( rData1.Byte == rData2.Byte, "### byte does not match!" ); + OSL_ENSURE( rData1.Short == rData2.Short, "### short does not match!" ); + OSL_ENSURE( rData1.UShort == rData2.UShort, "### unsigned short does not match!" ); + OSL_ENSURE( rData1.Long == rData2.Long, "### long does not match!" ); + OSL_ENSURE( rData1.ULong == rData2.ULong, "### unsigned long does not match!" ); + OSL_ENSURE( rData1.Hyper == rData2.Hyper, "### hyper does not match!" ); + OSL_ENSURE( rData1.UHyper == rData2.UHyper, "### unsigned hyper does not match!" ); + OSL_ENSURE( rData1.Float == rData2.Float, "### float does not match!" ); + OSL_ENSURE( rData1.Double == rData2.Double, "### double does not match!" ); + OSL_ENSURE( rData1.Enum == rData2.Enum, "### enum does not match!" ); + OSL_ENSURE( rData1.String == rData2.String, "### string does not match!" ); + OSL_ENSURE( rData1.Interface == rData2.Interface, "### interface does not match!" ); + OSL_ENSURE( rData1.Any == rData2.Any, "### any does not match!" ); + + return (rData1.Bool == rData2.Bool && + rData1.Char == rData2.Char && + rData1.Byte == rData2.Byte && + rData1.Short == rData2.Short && + rData1.UShort == rData2.UShort && + rData1.Long == rData2.Long && + rData1.ULong == rData2.ULong && + rData1.Hyper == rData2.Hyper && + rData1.UHyper == rData2.UHyper && + rData1.Float == rData2.Float && + rData1.Double == rData2.Double && + rData1.Enum == rData2.Enum && + rData1.String == rData2.String && + rData1.Interface == rData2.Interface && + rData1.Any == rData2.Any); +} +//================================================================================================== +static sal_Bool equals( const TestData & rData1, const TestData & rData2 ) +{ + sal_Int32 nLen; + + if ((rData1.Sequence == rData2.Sequence) && + equals( (const TestElement &)rData1, (const TestElement &)rData2 ) && + (nLen = rData1.Sequence.getLength()) == rData2.Sequence.getLength()) + { + // once again by hand sequence == + const TestElement * pElements1 = rData1.Sequence.getConstArray(); + const TestElement * pElements2 = rData2.Sequence.getConstArray(); + for ( ; nLen--; ) + { + if (! equals( pElements1[nLen], pElements2[nLen] )) + { + OSL_ENSURE( sal_False, "### sequence element did not match!" ); + return sal_False; + } + } + return sal_True; + } + return sal_False; +} +//================================================================================================== +static void assign( TestElement & rData, + sal_Bool bBool, sal_Unicode cChar, sal_Int8 nByte, + sal_Int16 nShort, sal_uInt16 nUShort, + sal_Int32 nLong, sal_uInt32 nULong, + sal_Int64 nHyper, sal_uInt64 nUHyper, + float fFloat, double fDouble, + TestEnum eEnum, const ::rtl::OUString& rStr, + const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& xTest, + const ::com::sun::star::uno::Any& rAny ) +{ + rData.Bool = bBool; + rData.Char = cChar; + rData.Byte = nByte; + rData.Short = nShort; + rData.UShort = nUShort; + rData.Long = nLong; + rData.ULong = nULong; + rData.Hyper = nHyper; + rData.UHyper = nUHyper; + rData.Float = fFloat; + rData.Double = fDouble; + rData.Enum = eEnum; + rData.String = rStr; + rData.Interface = xTest; + rData.Any = rAny; +} +//================================================================================================== +static void assign( TestData & rData, + sal_Bool bBool, sal_Unicode cChar, sal_Int8 nByte, + sal_Int16 nShort, sal_uInt16 nUShort, + sal_Int32 nLong, sal_uInt32 nULong, + sal_Int64 nHyper, sal_uInt64 nUHyper, + float fFloat, double fDouble, + TestEnum eEnum, const ::rtl::OUString& rStr, + const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& xTest, + const ::com::sun::star::uno::Any& rAny, + const com::sun::star::uno::Sequence< TestElement >& rSequence ) +{ + assign( (TestElement &)rData, + bBool, cChar, nByte, nShort, nUShort, nLong, nULong, nHyper, nUHyper, fFloat, fDouble, + eEnum, rStr, xTest, rAny ); + rData.Sequence = rSequence; +} + +template < class type > +static sal_Bool testAny( const type & value , const Reference< XBridgeTest > &xLBT ) +{ + Any any; + any <<= value; + + Any any2 = xLBT->transportAny( any ); + + OSL_ASSERT( any == any2 ); + return any == any2; +} + + + +static sal_Bool performAnyTest( const Reference< XBridgeTest > &xLBT, const TestData &data) +{ + sal_Bool bReturn = sal_True; + bReturn = testAny( data.Byte ,xLBT ) && bReturn; + bReturn = testAny( data.Short,xLBT ) && bReturn; + bReturn = testAny( data.UShort,xLBT ) && bReturn; + bReturn = testAny( data.Long,xLBT ) && bReturn; + bReturn = testAny( data.Hyper,xLBT ) && bReturn; + bReturn = testAny( data.UHyper,xLBT ) && bReturn; + bReturn = testAny( data.Float,xLBT ) && bReturn; + bReturn = testAny( data.Double,xLBT ) && bReturn; + bReturn = testAny( data.Enum,xLBT ) && bReturn; + bReturn = testAny( data.String,xLBT ) && bReturn; + bReturn = testAny( data.Interface,xLBT ) && bReturn; + bReturn = testAny( data, xLBT ) && bReturn; + + Any a; + { + a.setValue( &(data.Bool) , getCppuBooleanType() ); + Any a2 = xLBT->transportAny( a ); + OSL_ASSERT( a2 == a ); + } + + { + a.setValue( &(data.Char) , getCppuCharType() ); + Any a2 = xLBT->transportAny( a ); + OSL_ASSERT( a2 == a ); + } + + return bReturn; +} + +//_______________________________________________________________________________________ +static sal_Bool performSequenceOfCallTest( const Reference < XBridgeTest > &xLBT ) +{ + sal_Int32 i,nRounds; + sal_Int32 nGlobalIndex = 0; + const sal_Int32 nWaitTimeSpanMUSec = 10000; + for( nRounds = 0 ; nRounds < 10 ; nRounds ++ ) + { + for( i = 0 ; i < nRounds ; i ++ ) + { + // fire oneways + xLBT->callOneway( nGlobalIndex , nWaitTimeSpanMUSec ); + nGlobalIndex ++; + } + + // call synchron + xLBT->call( nGlobalIndex , nWaitTimeSpanMUSec ); + nGlobalIndex ++; + } + + return xLBT->sequenceOfCallTestPassed(); +} + +class ORecursiveCall : public WeakImplHelper1< XRecursiveCall > +{ +private: + Mutex m_mutex; + +public: + void SAL_CALL callRecursivly( + const ::com::sun::star::uno::Reference< ::com::sun::star::test::bridge::XRecursiveCall >& xCall, + sal_Int32 nToCall ) + throw(::com::sun::star::uno::RuntimeException) + { + MutexGuard guard( m_mutex ); + if( nToCall ) + { + nToCall --; + xCall->callRecursivly( this , nToCall ); + } + + } +}; + + +//_______________________________________________________________________________________ +static sal_Bool performRecursiveCallTest( const Reference < XBridgeTest > & xLBT ) +{ + xLBT->startRecursiveCall( new ORecursiveCall , 50 ); + // on failure, the test would lock up or crash + return sal_True; +} + + +//================================================================================================== +static sal_Bool performTest( const Reference<XBridgeTest > & xLBT ) +{ + OSL_ENSURE( xLBT.is(), "### no test interface!" ); + if (xLBT.is()) + { + // this data is never ever granted access to by calls other than equals(), assign()! + TestData aData; // test against this data + + Reference<XInterface > xI( *new OWeakObject() ); + + assign( (TestElement &)aData, + sal_True, '@', 17, 0x1234, 0xfedc, 0x12345678, 0xfedcba98, + 0x123456789abcdef0, 0xfedcba9876543210, + (float)17.0815, 3.1415926359, TestEnum_LOLA, + OUString::createFromAscii("dum dum dum ich tanz im kreis herum..."), xI, + Any( &xI, ::getCppuType( (const Reference<XInterface > *)0 ) ) ); + + OSL_ENSURE( aData.Any == xI, "### unexpected any!" ); + OSL_ENSURE( !(aData.Any != xI), "### unexpected any!" ); + + aData.Sequence = Sequence<TestElement >( (const TestElement *)&aData, 1 ); + // aData complete + //================================================================================ + + // this is a manually copy of aData for first setting... + TestData aSetData; + + assign( (TestElement &)aSetData, + aData.Bool, aData.Char, aData.Byte, aData.Short, aData.UShort, + aData.Long, aData.ULong, aData.Hyper, aData.UHyper, aData.Float, aData.Double, + aData.Enum, aData.String, xI, + Any( &xI, ::getCppuType( (const Reference<XInterface > *)0 ) ) ); + + aSetData.Sequence = Sequence<TestElement >( (const TestElement *)&aSetData, 1 ); + + xLBT->setValues( + aSetData.Bool, aSetData.Char, aSetData.Byte, aSetData.Short, aSetData.UShort, + aSetData.Long, aSetData.ULong, aSetData.Hyper, aSetData.UHyper, aSetData.Float, aSetData.Double, + aSetData.Enum, aSetData.String, aSetData.Interface, aSetData.Any, aSetData.Sequence, aSetData ); + + { + TestData aRet, aRet2; + xLBT->getValues( + aRet.Bool, aRet.Char, aRet.Byte, aRet.Short, aRet.UShort, + aRet.Long, aRet.ULong, aRet.Hyper, aRet.UHyper, aRet.Float, aRet.Double, + aRet.Enum, aRet.String, aRet.Interface, aRet.Any, aRet.Sequence, aRet2 ); + + OSL_ASSERT( equals( aData, aRet ) && equals( aData, aRet2 ) ); + + // set last retrieved values + TestData aSV2ret = xLBT->setValues2( + aRet.Bool, aRet.Char, aRet.Byte, aRet.Short, aRet.UShort, + aRet.Long, aRet.ULong, aRet.Hyper, aRet.UHyper, aRet.Float, aRet.Double, + aRet.Enum, aRet.String, aRet.Interface, aRet.Any, aRet.Sequence, aRet2 ); + + OSL_ASSERT( equals( aData, aSV2ret ) && equals( aData, aRet2 ) ); + } + { + TestData aRet, aRet2; + TestData aGVret = xLBT->getValues( + aRet.Bool, aRet.Char, aRet.Byte, aRet.Short, aRet.UShort, + aRet.Long, aRet.ULong, aRet.Hyper, aRet.UHyper, aRet.Float, aRet.Double, + aRet.Enum, aRet.String, aRet.Interface, aRet.Any, aRet.Sequence, aRet2 ); + + OSL_ASSERT( equals( aData, aRet ) && equals( aData, aRet2 ) && equals( aData, aGVret ) ); + + // set last retrieved values + xLBT->setBool( aRet.Bool ); + xLBT->setChar( aRet.Char ); + xLBT->setByte( aRet.Byte ); + xLBT->setShort( aRet.Short ); + xLBT->setUShort( aRet.UShort ); + xLBT->setLong( aRet.Long ); + xLBT->setULong( aRet.ULong ); + xLBT->setHyper( aRet.Hyper ); + xLBT->setUHyper( aRet.UHyper ); + xLBT->setFloat( aRet.Float ); + xLBT->setDouble( aRet.Double ); + xLBT->setEnum( aRet.Enum ); + xLBT->setString( aRet.String ); + xLBT->setInterface( aRet.Interface ); + xLBT->setAny( aRet.Any ); + xLBT->setSequence( aRet.Sequence ); + xLBT->setStruct( aRet2 ); + } + { + TestData aRet, aRet2; + aRet.Hyper = xLBT->getHyper(); + aRet.UHyper = xLBT->getUHyper(); + aRet.Float = xLBT->getFloat(); + aRet.Double = xLBT->getDouble(); + aRet.Byte = xLBT->getByte(); + aRet.Char = xLBT->getChar(); + aRet.Bool = xLBT->getBool(); + aRet.Short = xLBT->getShort(); + aRet.UShort = xLBT->getUShort(); + aRet.Long = xLBT->getLong(); + aRet.ULong = xLBT->getULong(); + aRet.Enum = xLBT->getEnum(); + aRet.String = xLBT->getString(); + aRet.Interface = xLBT->getInterface(); + aRet.Any = xLBT->getAny(); + aRet.Sequence = xLBT->getSequence(); + aRet2 = xLBT->getStruct(); + + OSL_ASSERT( equals( aData, aRet ) && equals( aData, aRet2 ) ); + + // any test + OSL_ASSERT( performAnyTest( xLBT , aData ) ); + + // sequence of call test + OSL_ASSERT( performSequenceOfCallTest( xLBT ) ); + + // recursive call test + OSL_ASSERT( performRecursiveCallTest( xLBT ) ); + + return (equals( aData, aRet ) && equals( aData, aRet2 )); + } + } + return sal_False; +} +static sal_Bool raiseOnewayException( const Reference < XBridgeTest > & xLBT ) +{ + sal_Bool bReturn = sal_True; + OUString sCompare = OUString( RTL_CONSTASCII_USTRINGPARAM("dum dum dum ich tanz im kreis herum...") ); + try + { + // Note : the exception may fly or not (e.g. remote scenario). + // When it flies, it must contain the correct elements. + xLBT->raiseRuntimeExceptionOneway( sCompare, xLBT->getInterface() ); + } + catch( RuntimeException & e ) + { + bReturn = ( e.Message == sCompare && xLBT->getInterface() == e.Context ); + } + return bReturn; +} + +//================================================================================================== +static sal_Bool raiseException( const Reference< XBridgeTest > & xLBT ) +{ + sal_Int32 nCount = 0; + try + { + try + { + try + { + TestData aRet, aRet2; + xLBT->raiseException( + 5, OUString( RTL_CONSTASCII_USTRINGPARAM("dum dum dum ich tanz im kreis herum...") ), + xLBT->getInterface() ); + } + catch (IllegalArgumentException aExc) + { + if (aExc.ArgumentPosition == 5 && + aExc.Context == xLBT->getInterface() && + aExc.Message.compareToAscii( "dum dum dum ich tanz im kreis herum..." ) == 0) + { + ++nCount; + } + else + { + OSL_ENSURE( sal_False, "### unexpected exception content!" ); + } + + /** it is certain, that the RuntimeException testing will fail, if no */ + xLBT->getRuntimeException(); + } + } + catch (const RuntimeException & rExc) + { + if (rExc.Context == xLBT->getInterface() && + rExc.Message.compareToAscii( "dum dum dum ich tanz im kreis herum..." ) == 0) + { + ++nCount; + } + else + { + OSL_ENSURE( sal_False, "### unexpected exception content!" ); + } + + /** it is certain, that the RuntimeException testing will fail, if no */ + xLBT->setRuntimeException( 0xcafebabe ); + } + } + catch (Exception & rExc) + { + if (rExc.Context == xLBT->getInterface() && + rExc.Message.compareToAscii( "dum dum dum ich tanz im kreis herum..." ) == 0) + { + ++nCount; + } + else + { + OSL_ENSURE( sal_False, "### unexpected exception content!" ); + } + return (nCount == 3); + } + return sal_False; +} + +template< class T > +static inline sal_Bool makeSurrogate( com::sun::star::uno::Reference< T > & rOut, + const com::sun::star::uno::Reference< T > & rOriginal ) +{ + rOut.clear(); + + typelib_TypeDescription * pTD = 0; + const com::sun::star::uno::Type & rType = ::getCppuType( &rOriginal ); + TYPELIB_DANGER_GET( &pTD, rType.getTypeLibType() ); + OSL_ENSURE( pTD, "### cannot get typedescription!" ); + if (pTD) + { + uno_Environment * pCppEnv1 = 0; + uno_Environment * pCppEnv2 = 0; + + OUString aCppEnvTypeName( RTL_CONSTASCII_USTRINGPARAM(CPPU_CURRENT_LANGUAGE_BINDING_NAME) ); + uno_getEnvironment( &pCppEnv1, aCppEnvTypeName.pData, 0 ); + uno_createEnvironment( &pCppEnv2, aCppEnvTypeName.pData, 0 ); // anonymous + + ::com::sun::star::uno::Mapping aMapping( pCppEnv1, pCppEnv2, OUString::createFromAscii("prot") ); + T * p = (T *)aMapping.mapInterface( rOriginal.get(), (typelib_InterfaceTypeDescription *)pTD ); + if (p) + { + rOut = p; + p->release(); + } + + (*pCppEnv2->release)( pCppEnv2 ); + (*pCppEnv1->release)( pCppEnv1 ); + + TYPELIB_DANGER_RELEASE( pTD ); + } + return rOut.is(); +} + +//================================================================================================== +sal_Int32 TestBridgeImpl::run( const Sequence< OUString > & rArgs ) + throw (RuntimeException) +{ + if (! rArgs.getLength()) + { + throw RuntimeException( OUString( RTL_CONSTASCII_USTRINGPARAM( + "no test object specified!\n" + "usage : ServiceName of test object | -u unourl of test object\n" ) ), + Reference< XInterface >() ); + } + + Reference<XBridgeTest > xOriginal; + if( rArgs.getLength() > 1 && 0 == rArgs[0].compareToAscii( "-u" ) ) + { + Reference <XInterface > r = _xMgr->createInstance( + OUString::createFromAscii( "com.sun.star.bridge.UnoUrlResolver" ) ); + Reference <XUnoUrlResolver> rResolver( r , UNO_QUERY ); + r = rResolver->resolve( rArgs[1] ); + xOriginal = Reference < XBridgeTest > ( r , UNO_QUERY ); + } + else + { + // local test + xOriginal = Reference<XBridgeTest > ( _xMgr->createInstance( rArgs[0] ), UNO_QUERY ); + } + + if (! xOriginal.is()) + { + throw RuntimeException( OUString( RTL_CONSTASCII_USTRINGPARAM("cannot instantiate object!") ), + Reference< XInterface >() ); + } + + Reference<XBridgeTest > xLBT; + if (makeSurrogate( xLBT, xOriginal ) && + performTest( xLBT ) && + raiseException( xLBT ) && + raiseOnewayException( xLBT ) ) + { + printf( "> dynamic invocation test succeeded!\n" ); + } + else + { + printf( "> dynamic invocation test failed!\n" ); + } + + return 0; +} + +// XServiceInfo +//__________________________________________________________________________________________________ +OUString TestBridgeImpl::getImplementationName() + throw (RuntimeException) +{ + return OUString( RTL_CONSTASCII_USTRINGPARAM(IMPLNAME) ); +} +//__________________________________________________________________________________________________ +sal_Bool TestBridgeImpl::supportsService( const OUString & rServiceName ) + throw (RuntimeException) +{ + const Sequence< OUString > & rSNL = getSupportedServiceNames(); + const OUString * pArray = rSNL.getConstArray(); + for ( sal_Int32 nPos = rSNL.getLength(); nPos--; ) + { + if (pArray[nPos] == rServiceName) + return sal_True; + } + return sal_False; +} +//__________________________________________________________________________________________________ +Sequence< OUString > TestBridgeImpl::getSupportedServiceNames() + throw (RuntimeException) +{ + return bridge_test::getSupportedServiceNames(); +} + +// ... + +//================================================================================================== +static Reference< XInterface > SAL_CALL TestBridgeImpl_create( + const Reference< XMultiServiceFactory > & xSMgr ) +{ + return Reference< XInterface >( (XBridgeTest *)new TestBridgeImpl( xSMgr ) ); +} + +} + +extern "C" +{ +//================================================================================================== +void SAL_CALL component_getImplementationEnvironment( + const sal_Char ** ppEnvTypeName, uno_Environment ** ppEnv ) +{ + *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME; +} +//================================================================================================== +sal_Bool SAL_CALL component_writeInfo( + void * pServiceManager, void * pRegistryKey ) +{ + if (pRegistryKey) + { + try + { + Reference< XRegistryKey > xNewKey( + reinterpret_cast< XRegistryKey * >( pRegistryKey )->createKey( + OUString( RTL_CONSTASCII_USTRINGPARAM("/" IMPLNAME "/UNO/SERVICES") ) ) ); + xNewKey->createKey( OUString( RTL_CONSTASCII_USTRINGPARAM(SERVICENAME) ) ); + + return sal_True; + } + catch (InvalidRegistryException &) + { + OSL_ENSURE( sal_False, "### InvalidRegistryException!" ); + } + } + return sal_False; +} +//================================================================================================== +void * SAL_CALL component_getFactory( + const sal_Char * pImplName, void * pServiceManager, void * pRegistryKey ) +{ + void * pRet = 0; + + if (pServiceManager && rtl_str_compare( pImplName, IMPLNAME ) == 0) + { + Reference< XSingleServiceFactory > xFactory( createSingleFactory( + reinterpret_cast< XMultiServiceFactory * >( pServiceManager ), + OUString( RTL_CONSTASCII_USTRINGPARAM(IMPLNAME) ), + bridge_test::TestBridgeImpl_create, + bridge_test::getSupportedServiceNames() ) ); + + if (xFactory.is()) + { + xFactory->acquire(); + pRet = xFactory.get(); + } + } + + return pRet; +} +} + +/************************************************************************** + $Log: not supported by cvs2svn $ + Revision 1.3 2001/03/12 16:22:44 jl + OSL_ENSHURE replaced by OSL_ENSURE + + Revision 1.2 2000/08/14 07:12:50 jbu + added remote tests + + Revision 1.1 2000/05/26 14:20:26 dbo + new + + +**************************************************************************/ diff --git a/testtools/source/bridgetest/cppobj.cxx b/testtools/source/bridgetest/cppobj.cxx new file mode 100644 index 000000000000..bcb06069ac18 --- /dev/null +++ b/testtools/source/bridgetest/cppobj.cxx @@ -0,0 +1,535 @@ +/************************************************************************** +#* +#* last change $Author: kr $ $Date: 2001-05-04 07:05:17 $ +#* $Revision: 1.1 $ +#* +#* $Logfile: $ +#* +#* Copyright (c) 1989 - 2000, Star Office GmbH +#* +#************************************************************************/ +#include <stdio.h> + +#include <osl/diagnose.h> +#include <osl/thread.h> +#include <osl/mutex.hxx> +#ifndef _OSL_TIME_H_ +#include <osl/time.h> +#endif + +#include <cppuhelper/implbase3.hxx> +#include <cppuhelper/factory.hxx> + +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/registry/XRegistryKey.hpp> + +#include <com/sun/star/test/bridge/XBridgeTest.hpp> + +using namespace rtl; +using namespace osl; +using namespace cppu; +using namespace com::sun::star::uno; +using namespace com::sun::star::lang; +using namespace com::sun::star::registry; +using namespace com::sun::star::test::bridge; + +#define SERVICENAME "com.sun.star.test.bridge.CppTestObject" +#define IMPLNAME "com.sun.star.comp.bridge.CppTestObject" + +namespace bridge_object +{ + +//-------------------------------------------------------------------------------------------------- +inline static Sequence< OUString > getSupportedServiceNames() +{ + OUString aName( RTL_CONSTASCII_USTRINGPARAM(SERVICENAME) ); + return Sequence< OUString >( &aName, 1 ); +} + +//================================================================================================== +static void assign( TestElement & rData, + sal_Bool bBool, sal_Unicode cChar, sal_Int8 nByte, + sal_Int16 nShort, sal_uInt16 nUShort, + sal_Int32 nLong, sal_uInt32 nULong, + sal_Int64 nHyper, sal_uInt64 nUHyper, + float fFloat, double fDouble, + TestEnum eEnum, const ::rtl::OUString& rStr, + const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& xTest, + const ::com::sun::star::uno::Any& rAny ) +{ + rData.Bool = bBool; + rData.Char = cChar; + rData.Byte = nByte; + rData.Short = nShort; + rData.UShort = nUShort; + rData.Long = nLong; + rData.ULong = nULong; + rData.Hyper = nHyper; + rData.UHyper = nUHyper; + rData.Float = fFloat; + rData.Double = fDouble; + rData.Enum = eEnum; + rData.String = rStr; + rData.Interface = xTest; + rData.Any = rAny; +} +//================================================================================================== +static void assign( TestData & rData, + sal_Bool bBool, sal_Unicode cChar, sal_Int8 nByte, + sal_Int16 nShort, sal_uInt16 nUShort, + sal_Int32 nLong, sal_uInt32 nULong, + sal_Int64 nHyper, sal_uInt64 nUHyper, + float fFloat, double fDouble, + TestEnum eEnum, const ::rtl::OUString& rStr, + const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& xTest, + const ::com::sun::star::uno::Any& rAny, + const com::sun::star::uno::Sequence< TestElement >& rSequence ) +{ + assign( (TestElement &)rData, + bBool, cChar, nByte, nShort, nUShort, nLong, nULong, nHyper, nUHyper, fFloat, fDouble, + eEnum, rStr, xTest, rAny ); + rData.Sequence = rSequence; +} + +//================================================================================================== +class Test_Impl : public WeakImplHelper3< XBridgeTest, XServiceInfo , XRecursiveCall > +{ + TestData _aData, _aStructData; + sal_Int32 m_nLastCallId; + sal_Bool m_bFirstCall; + sal_Bool m_bSequenceOfCallTestPassed; + Mutex m_mutex; + +public: + Test_Impl() : m_nLastCallId( 0 ), + m_bFirstCall( sal_True ), + m_bSequenceOfCallTestPassed( sal_True ) + {} + virtual ~Test_Impl() + { OSL_TRACE( "> scalar Test_Impl dtor <\n" ); } + + // XServiceInfo + virtual OUString SAL_CALL getImplementationName() throw (RuntimeException); + virtual sal_Bool SAL_CALL supportsService( const OUString & rServiceName ) throw (RuntimeException); + virtual Sequence< OUString > SAL_CALL getSupportedServiceNames() throw (RuntimeException); + + // XLBTestBase + virtual void SAL_CALL setValues( sal_Bool bBool, sal_Unicode cChar, sal_Int8 nByte, + sal_Int16 nShort, sal_uInt16 nUShort, + sal_Int32 nLong, sal_uInt32 nULong, + sal_Int64 nHyper, sal_uInt64 nUHyper, + float fFloat, double fDouble, + TestEnum eEnum, const ::rtl::OUString& rStr, + const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& xTest, + const ::com::sun::star::uno::Any& rAny, + const ::com::sun::star::uno::Sequence<TestElement >& rSequence, + const TestData& rStruct ) + throw(com::sun::star::uno::RuntimeException); + + virtual TestData SAL_CALL setValues2( sal_Bool& bBool, sal_Unicode& cChar, sal_Int8& nByte, + sal_Int16& nShort, sal_uInt16& nUShort, + sal_Int32& nLong, sal_uInt32& nULong, + sal_Int64& nHyper, sal_uInt64& nUHyper, + float& fFloat, double& fDouble, + TestEnum& eEnum, rtl::OUString& rStr, + ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& xTest, + ::com::sun::star::uno::Any& rAny, + ::com::sun::star::uno::Sequence<TestElement >& rSequence, + TestData& rStruct ) + throw(com::sun::star::uno::RuntimeException); + + virtual TestData SAL_CALL getValues( sal_Bool& bBool, sal_Unicode& cChar, sal_Int8& nByte, + sal_Int16& nShort, sal_uInt16& nUShort, + sal_Int32& nLong, sal_uInt32& nULong, + sal_Int64& nHyper, sal_uInt64& nUHyper, + float& fFloat, double& fDouble, + TestEnum& eEnum, rtl::OUString& rStr, + ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& xTest, + ::com::sun::star::uno::Any& rAny, + ::com::sun::star::uno::Sequence< TestElement >& rSequence, + TestData& rStruct ) + throw(com::sun::star::uno::RuntimeException); + + virtual sal_Bool SAL_CALL getBool() throw(com::sun::star::uno::RuntimeException) + { return _aData.Bool; } + virtual sal_Int8 SAL_CALL getByte() throw(com::sun::star::uno::RuntimeException) + { return _aData.Byte; } + virtual sal_Unicode SAL_CALL getChar() throw(com::sun::star::uno::RuntimeException) + { return _aData.Char; } + virtual sal_Int16 SAL_CALL getShort() throw(com::sun::star::uno::RuntimeException) + { return _aData.Short; } + virtual sal_uInt16 SAL_CALL getUShort() throw(com::sun::star::uno::RuntimeException) + { return _aData.UShort; } + virtual sal_Int32 SAL_CALL getLong() throw(com::sun::star::uno::RuntimeException) + { return _aData.Long; } + virtual sal_uInt32 SAL_CALL getULong() throw(com::sun::star::uno::RuntimeException) + { return _aData.ULong; } + virtual sal_Int64 SAL_CALL getHyper() throw(com::sun::star::uno::RuntimeException) + { return _aData.Hyper; } + virtual sal_uInt64 SAL_CALL getUHyper() throw(com::sun::star::uno::RuntimeException) + { return _aData.UHyper; } + virtual float SAL_CALL getFloat() throw(com::sun::star::uno::RuntimeException) + { return _aData.Float; } + virtual double SAL_CALL getDouble() throw(com::sun::star::uno::RuntimeException) + { return _aData.Double; } + virtual TestEnum SAL_CALL getEnum() throw(com::sun::star::uno::RuntimeException) + { return _aData.Enum; } + virtual rtl::OUString SAL_CALL getString() throw(com::sun::star::uno::RuntimeException) + { return _aData.String; } + virtual com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL getInterface( ) throw(com::sun::star::uno::RuntimeException) + { return _aData.Interface; } + virtual com::sun::star::uno::Any SAL_CALL getAny() throw(com::sun::star::uno::RuntimeException) + { return _aData.Any; } + virtual com::sun::star::uno::Sequence< TestElement > SAL_CALL getSequence() throw(com::sun::star::uno::RuntimeException) + { return _aData.Sequence; } + virtual TestData SAL_CALL getStruct() throw(com::sun::star::uno::RuntimeException) + { return _aStructData; } + + virtual void SAL_CALL setBool( sal_Bool _bool ) throw(::com::sun::star::uno::RuntimeException) + { _aData.Bool = _bool; } + virtual void SAL_CALL setByte( sal_Int8 _byte ) throw(::com::sun::star::uno::RuntimeException) + { _aData.Byte = _byte; } + virtual void SAL_CALL setChar( sal_Unicode _char ) throw(::com::sun::star::uno::RuntimeException) + { _aData.Char = _char; } + virtual void SAL_CALL setShort( sal_Int16 _short ) throw(::com::sun::star::uno::RuntimeException) + { _aData.Short = _short; } + virtual void SAL_CALL setUShort( sal_uInt16 _ushort ) throw(::com::sun::star::uno::RuntimeException) + { _aData.UShort = _ushort; } + virtual void SAL_CALL setLong( sal_Int32 _long ) throw(::com::sun::star::uno::RuntimeException) + { _aData.Long = _long; } + virtual void SAL_CALL setULong( sal_uInt32 _ulong ) throw(::com::sun::star::uno::RuntimeException) + { _aData.ULong = _ulong; } + virtual void SAL_CALL setHyper( sal_Int64 _hyper ) throw(::com::sun::star::uno::RuntimeException) + { _aData.Hyper = _hyper; } + virtual void SAL_CALL setUHyper( sal_uInt64 _uhyper ) throw(::com::sun::star::uno::RuntimeException) + { _aData.UHyper = _uhyper; } + virtual void SAL_CALL setFloat( float _float ) throw(::com::sun::star::uno::RuntimeException) + { _aData.Float = _float; } + virtual void SAL_CALL setDouble( double _double ) throw(::com::sun::star::uno::RuntimeException) + { _aData.Double = _double; } + virtual void SAL_CALL setEnum( TestEnum _enum ) throw(::com::sun::star::uno::RuntimeException) + { _aData.Enum = _enum; } + virtual void SAL_CALL setString( const ::rtl::OUString& _string ) throw(::com::sun::star::uno::RuntimeException) + { _aData.String = _string; } + virtual void SAL_CALL setInterface( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _interface ) throw(::com::sun::star::uno::RuntimeException) + { _aData.Interface = _interface; } + virtual void SAL_CALL setAny( const ::com::sun::star::uno::Any& _any ) throw(::com::sun::star::uno::RuntimeException) + { _aData.Any = _any; } + virtual void SAL_CALL setSequence( const ::com::sun::star::uno::Sequence<TestElement >& _sequence ) throw(::com::sun::star::uno::RuntimeException) + { _aData.Sequence = _sequence; } + virtual void SAL_CALL setStruct( const TestData& _struct ) throw(::com::sun::star::uno::RuntimeException) + { _aStructData = _struct; } + + virtual ::com::sun::star::uno::Any SAL_CALL transportAny( + const ::com::sun::star::uno::Any& value ) + throw(::com::sun::star::uno::RuntimeException); + + virtual void SAL_CALL call( sal_Int32 nCallId, sal_Int32 nWaitMUSEC ) + throw(::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL callOneway( sal_Int32 nCallId, sal_Int32 nWaitMUSEC ) + throw(::com::sun::star::uno::RuntimeException); + virtual sal_Bool SAL_CALL sequenceOfCallTestPassed( ) + throw(::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL startRecursiveCall( + const ::com::sun::star::uno::Reference< ::com::sun::star::test::bridge::XRecursiveCall >& xCall, sal_Int32 nToCall ) + throw(::com::sun::star::uno::RuntimeException); + +public: // XBridgeTest + virtual TestData SAL_CALL raiseException( sal_Int16 nArgumentPos, const OUString & rMsg, const Reference< XInterface > & xCOntext ) + throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); + + virtual void SAL_CALL raiseRuntimeExceptionOneway( + const ::rtl::OUString& Message, const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& Context ) + throw(::com::sun::star::uno::RuntimeException); + + virtual sal_Int32 SAL_CALL getRuntimeException() throw(::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setRuntimeException( sal_Int32 _runtimeexception ) throw(::com::sun::star::uno::RuntimeException); + +public: + virtual void SAL_CALL callRecursivly( const ::com::sun::star::uno::Reference< ::com::sun::star::test::bridge::XRecursiveCall >& xCall, sal_Int32 nToCall ) throw(::com::sun::star::uno::RuntimeException); +}; + +//__________________________________________________________________________________________________ +Any Test_Impl::transportAny( const Any & value ) throw ( ::com::sun::star::uno::RuntimeException) +{ + return value; +} + +//__________________________________________________________________________________________________ +void Test_Impl::call( sal_Int32 nCallId , sal_Int32 nWaitMUSEC ) throw(::com::sun::star::uno::RuntimeException) +{ + TimeValue value = { nWaitMUSEC / 1000000 , nWaitMUSEC * 1000 }; + osl_waitThread( &value ); + if( m_bFirstCall ) + { + m_bFirstCall = sal_False; + } + else + { + m_bSequenceOfCallTestPassed = m_bSequenceOfCallTestPassed && (nCallId > m_nLastCallId); + } + m_nLastCallId = nCallId; +} + +//__________________________________________________________________________________________________ +void Test_Impl::callOneway( sal_Int32 nCallId , sal_Int32 nWaitMUSEC ) throw (::com::sun::star::uno::RuntimeException) +{ + TimeValue value = { nWaitMUSEC / 1000000 , nWaitMUSEC * 1000 }; + osl_waitThread( &value ); + m_bSequenceOfCallTestPassed = m_bSequenceOfCallTestPassed && (nCallId > m_nLastCallId); + m_nLastCallId = nCallId; +} + +//__________________________________________________________________________________________________ +sal_Bool Test_Impl::sequenceOfCallTestPassed() throw (::com::sun::star::uno::RuntimeException) +{ + return m_bSequenceOfCallTestPassed; +} + +//__________________________________________________________________________________________________ +void SAL_CALL Test_Impl::startRecursiveCall( + const ::com::sun::star::uno::Reference< ::com::sun::star::test::bridge::XRecursiveCall >& xCall, sal_Int32 nToCall ) + throw(::com::sun::star::uno::RuntimeException) +{ + MutexGuard guard( m_mutex ); + if( nToCall ) + { + nToCall --; + xCall->callRecursivly( this , nToCall ); + } +} + + +void SAL_CALL Test_Impl::callRecursivly( + const ::com::sun::star::uno::Reference< ::com::sun::star::test::bridge::XRecursiveCall >& xCall, + sal_Int32 nToCall ) + throw(::com::sun::star::uno::RuntimeException) +{ + MutexGuard guard( m_mutex ); + if( nToCall ) + { + nToCall --; + xCall->callRecursivly( this , nToCall ); + } +} + +//__________________________________________________________________________________________________ +void Test_Impl::setValues( sal_Bool bBool, sal_Unicode cChar, sal_Int8 nByte, + sal_Int16 nShort, sal_uInt16 nUShort, + sal_Int32 nLong, sal_uInt32 nULong, + sal_Int64 nHyper, sal_uInt64 nUHyper, + float fFloat, double fDouble, + TestEnum eEnum, const ::rtl::OUString& rStr, + const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& xTest, + const ::com::sun::star::uno::Any& rAny, + const ::com::sun::star::uno::Sequence<TestElement >& rSequence, + const TestData& rStruct ) + throw(com::sun::star::uno::RuntimeException) +{ + assign( _aData, + bBool, cChar, nByte, nShort, nUShort, nLong, nULong, nHyper, nUHyper, fFloat, fDouble, + eEnum, rStr, xTest, rAny, rSequence ); + _aStructData = rStruct; +} +//__________________________________________________________________________________________________ +TestData Test_Impl::setValues2( sal_Bool& bBool, sal_Unicode& cChar, sal_Int8& nByte, + sal_Int16& nShort, sal_uInt16& nUShort, + sal_Int32& nLong, sal_uInt32& nULong, + sal_Int64& nHyper, sal_uInt64& nUHyper, + float& fFloat, double& fDouble, + TestEnum& eEnum, rtl::OUString& rStr, + ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& xTest, + ::com::sun::star::uno::Any& rAny, + ::com::sun::star::uno::Sequence<TestElement >& rSequence, + TestData& rStruct ) + throw(com::sun::star::uno::RuntimeException) +{ + assign( _aData, + bBool, cChar, nByte, nShort, nUShort, nLong, nULong, nHyper, nUHyper, fFloat, fDouble, + eEnum, rStr, xTest, rAny, rSequence ); + _aStructData = rStruct; + return _aStructData; +} +//__________________________________________________________________________________________________ +TestData Test_Impl::getValues( sal_Bool& bBool, sal_Unicode& cChar, sal_Int8& nByte, + sal_Int16& nShort, sal_uInt16& nUShort, + sal_Int32& nLong, sal_uInt32& nULong, + sal_Int64& nHyper, sal_uInt64& nUHyper, + float& fFloat, double& fDouble, + TestEnum& eEnum, rtl::OUString& rStr, + ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& xTest, + ::com::sun::star::uno::Any& rAny, + ::com::sun::star::uno::Sequence<TestElement >& rSequence, + TestData& rStruct ) + throw(com::sun::star::uno::RuntimeException) +{ + bBool = _aData.Bool; + cChar = _aData.Char; + nByte = _aData.Byte; + nShort = _aData.Short; + nUShort = _aData.UShort; + nLong = _aData.Long; + nULong = _aData.ULong; + nHyper = _aData.Hyper; + nUHyper = _aData.UHyper; + fFloat = _aData.Float; + fDouble = _aData.Double; + eEnum = _aData.Enum; + rStr = _aData.String; + xTest = _aData.Interface; + rAny = _aData.Any; + rSequence = _aData.Sequence; + rStruct = _aStructData; + return _aStructData; +} +//__________________________________________________________________________________________________ +TestData Test_Impl::raiseException( sal_Int16 nArgumentPos, const OUString & rMsg, const Reference< XInterface > & xContext ) + throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException) +{ + IllegalArgumentException aExc; + aExc.ArgumentPosition = nArgumentPos; + aExc.Message = _aData.String = rMsg; + aExc.Context = _aData.Interface = xContext; + throw aExc; + return TestData(); // for dummy +} + +void Test_Impl::raiseRuntimeExceptionOneway( const OUString & rMsg, const Reference< XInterface > & xContext ) + throw(::com::sun::star::uno::RuntimeException) +{ + RuntimeException aExc; + aExc.Message = _aData.String = rMsg; + aExc.Context = _aData.Interface = xContext; + throw aExc; +} + +//__________________________________________________________________________________________________ +sal_Int32 Test_Impl::getRuntimeException() throw(::com::sun::star::uno::RuntimeException) +{ + RuntimeException aExc; + aExc.Message = _aData.String; + aExc.Context = _aData.Interface; + throw aExc; + return 0; // for dummy +} +//__________________________________________________________________________________________________ +void Test_Impl::setRuntimeException( sal_Int32 _runtimeexception ) throw(::com::sun::star::uno::RuntimeException) +{ + RuntimeException aExc; + aExc.Message = _aData.String; + aExc.Context = _aData.Interface; + throw aExc; +} + +// XServiceInfo +//__________________________________________________________________________________________________ +OUString Test_Impl::getImplementationName() + throw (RuntimeException) +{ + return OUString( RTL_CONSTASCII_USTRINGPARAM(IMPLNAME) ); +} +//__________________________________________________________________________________________________ +sal_Bool Test_Impl::supportsService( const OUString & rServiceName ) + throw (RuntimeException) +{ + const Sequence< OUString > & rSNL = getSupportedServiceNames(); + const OUString * pArray = rSNL.getConstArray(); + for ( sal_Int32 nPos = rSNL.getLength(); nPos--; ) + { + if (pArray[nPos] == rServiceName) + return sal_True; + } + return sal_False; +} +//__________________________________________________________________________________________________ +Sequence< OUString > Test_Impl::getSupportedServiceNames() + throw (RuntimeException) +{ + return bridge_object::getSupportedServiceNames(); +} + +// ... + +//================================================================================================== +static Reference< XInterface > SAL_CALL Test_Impl_create( const Reference< XMultiServiceFactory > & xSMgr ) +{ + return Reference< XInterface >( (XBridgeTest *)new Test_Impl() ); +} + +} + +extern "C" +{ +//================================================================================================== +void SAL_CALL component_getImplementationEnvironment( + const sal_Char ** ppEnvTypeName, uno_Environment ** ppEnv ) +{ + *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME; +} +//================================================================================================== +sal_Bool SAL_CALL component_writeInfo( + void * pServiceManager, void * pRegistryKey ) +{ + if (pRegistryKey) + { + try + { + Reference< XRegistryKey > xNewKey( + reinterpret_cast< XRegistryKey * >( pRegistryKey )->createKey( + OUString( RTL_CONSTASCII_USTRINGPARAM("/" IMPLNAME "/UNO/SERVICES") ) ) ); + xNewKey->createKey( OUString( RTL_CONSTASCII_USTRINGPARAM(SERVICENAME) ) ); + + return sal_True; + } + catch (InvalidRegistryException &) + { + OSL_ENSURE( sal_False, "### InvalidRegistryException!" ); + } + } + return sal_False; +} +//================================================================================================== +void * SAL_CALL component_getFactory( + const sal_Char * pImplName, void * pServiceManager, void * pRegistryKey ) +{ + void * pRet = 0; + + if (pServiceManager && rtl_str_compare( pImplName, IMPLNAME ) == 0) + { + Reference< XSingleServiceFactory > xFactory( createSingleFactory( + reinterpret_cast< XMultiServiceFactory * >( pServiceManager ), + OUString( RTL_CONSTASCII_USTRINGPARAM(IMPLNAME) ), + bridge_object::Test_Impl_create, + bridge_object::getSupportedServiceNames() ) ); + + if (xFactory.is()) + { + xFactory->acquire(); + pRet = xFactory.get(); + } + } + + return pRet; +} +} + +/************************************************************************** + $Log: not supported by cvs2svn $ + Revision 1.5 2001/03/14 09:55:11 jl + #include <osl/time.h> added + + Revision 1.4 2001/03/12 16:22:44 jl + OSL_ENSHURE replaced by OSL_ENSURE + + Revision 1.3 2000/08/30 13:13:59 jbu + now passes cc50 compiler + + Revision 1.2 2000/08/14 07:12:50 jbu + added remote tests + + Revision 1.1 2000/05/26 14:20:35 dbo + new + + +**************************************************************************/ diff --git a/testtools/source/bridgetest/makefile.mk b/testtools/source/bridgetest/makefile.mk new file mode 100644 index 000000000000..b5555a67c03e --- /dev/null +++ b/testtools/source/bridgetest/makefile.mk @@ -0,0 +1,80 @@ +PRJ=..$/.. + +PRJNAME=testtools +TARGET=bridgetest +USE_DEFFILE=TRUE +NO_BSYMBOLIC=TRUE +ENABLE_EXCEPTIONS=TRUE +LIBTARGET=NO + +# --- Settings ----------------------------------------------------- + +.INCLUDE : svpre.mk +.INCLUDE : settings.mk +.INCLUDE : sv.mk + +# ------------------------------------------------------------------ + +UNOUCRDEP=$(SOLARBINDIR)$/udkapi.rdb +UNOUCRRDB=$(SOLARBINDIR)$/udkapi.rdb + +UNOUCROUT=$(OUT)$/inc +INCPRE+=$(OUT)$/inc + +UNOTYPES= \ + com.sun.star.uno.TypeClass \ + com.sun.star.uno.XAggregation \ + com.sun.star.uno.XWeak \ + com.sun.star.lang.XTypeProvider \ + com.sun.star.lang.XServiceInfo \ + com.sun.star.lang.XSingleServiceFactory \ + com.sun.star.lang.XMultiServiceFactory \ + com.sun.star.lang.XComponent \ + com.sun.star.lang.XMain \ + com.sun.star.loader.XImplementationLoader \ + com.sun.star.registry.XRegistryKey \ + com.sun.star.container.XSet \ + com.sun.star.test.bridge.XBridgeTest \ + com.sun.star.bridge.XUnoUrlResolver + +SLOFILES= \ + $(SLO)$/cppobj.obj \ + $(SLO)$/bridgetest.obj + +# ---- test ---- + +LIB1TARGET=$(SLB)$/cppobj.lib +LIB1OBJFILES= \ + $(SLO)$/cppobj.obj + +SHL1TARGET=cppobj +SHL1STDLIBS= \ + $(CPPULIB) \ + $(CPPUHELPERLIB) \ + $(SALLIB) + +SHL1LIBS= $(LIB1TARGET) +SHL1DEF= $(MISC)$/$(SHL1TARGET).def +DEF1NAME= $(SHL1TARGET) +DEF1EXPORTFILE= exports.dxp + +# ---- test object ---- + +LIB2TARGET=$(SLB)$/bridgetest.lib +LIB2OBJFILES= \ + $(SLO)$/bridgetest.obj + +SHL2TARGET=bridgetest +SHL2STDLIBS= \ + $(CPPULIB) \ + $(CPPUHELPERLIB) \ + $(SALLIB) + +SHL2LIBS= $(LIB2TARGET) +SHL2DEF= $(MISC)$/$(SHL2TARGET).def +DEF2NAME= $(SHL2TARGET) +DEF2EXPORTFILE= exports.dxp + +# --- Targets ------------------------------------------------------ + +.INCLUDE : target.mk diff --git a/testtools/source/performance/exports.dxp b/testtools/source/performance/exports.dxp new file mode 100644 index 000000000000..9630d7e06768 --- /dev/null +++ b/testtools/source/performance/exports.dxp @@ -0,0 +1,3 @@ +component_getImplementationEnvironment +component_writeInfo +component_getFactory diff --git a/testtools/source/performance/makefile.mk b/testtools/source/performance/makefile.mk new file mode 100644 index 000000000000..b295a3905d11 --- /dev/null +++ b/testtools/source/performance/makefile.mk @@ -0,0 +1,97 @@ +PRJ=..$/.. + +PRJNAME=testtools +TARGET=performancetest +USE_DEFFILE=TRUE +NO_BSYMBOLIC=TRUE +ENABLE_EXCEPTIONS=TRUE +LIBTARGET=NO + +# --- Settings ----------------------------------------------------- + +.INCLUDE : svpre.mk +.INCLUDE : settings.mk +.INCLUDE : sv.mk + +# ------------------------------------------------------------------ + +UNOUCRDEP=$(SOLARBINDIR)$/udkapi.rdb +UNOUCRRDB=$(SOLARBINDIR)$/udkapi.rdb + +UNOUCROUT=$(OUT)$/inc +INCPRE+=$(OUT)$/inc + +UNOTYPES= \ + com.sun.star.uno.TypeClass \ + com.sun.star.uno.XAggregation \ + com.sun.star.uno.XWeak \ + com.sun.star.lang.XInitialization \ + com.sun.star.lang.XTypeProvider \ + com.sun.star.lang.XServiceInfo \ + com.sun.star.lang.XSingleServiceFactory \ + com.sun.star.lang.XMultiServiceFactory \ + com.sun.star.lang.XComponent \ + com.sun.star.lang.XMain \ + com.sun.star.loader.XImplementationLoader \ + com.sun.star.registry.XRegistryKey \ + com.sun.star.bridge.XUnoUrlResolver \ + com.sun.star.container.XSet \ + com.sun.star.test.performance.XPerformanceTest + +SLOFILES= \ + $(SLO)$/ubtest.obj \ + $(SLO)$/ubobject.obj + +# ---- test ---- + +LIB1TARGET=$(SLB)$/perftest.lib +LIB1OBJFILES= \ + $(SLO)$/ubtest.obj + +SHL1TARGET=perftest +SHL1STDLIBS= \ + $(CPPULIB) \ + $(CPPUHELPERLIB) \ + $(SALLIB) + +SHL1LIBS= $(LIB1TARGET) +SHL1DEF= $(MISC)$/$(SHL1TARGET).def +DEF1NAME= $(SHL1TARGET) +DEF1EXPORTFILE= exports.dxp + +# ---- test object ---- + +LIB2TARGET=$(SLB)$/perfobj.lib +LIB2OBJFILES= \ + $(SLO)$/ubobject.obj + +SHL2TARGET=perfobj +SHL2STDLIBS= \ + $(CPPULIB) \ + $(CPPUHELPERLIB) \ + $(SALLIB) + +SHL2LIBS= $(LIB2TARGET) +SHL2DEF= $(MISC)$/$(SHL2TARGET).def +DEF2NAME= $(SHL2TARGET) +DEF2EXPORTFILE= exports.dxp + +# ---- pseudo uno bridge ---- + +LIB3TARGET=$(SLB)$/pseudo.lib +LIB3OBJFILES= \ + $(SLO)$/pseudo.obj + +SHL3TARGET=pseudo_uno_uno +SHL3STDLIBS= \ + $(CPPULIB) \ + $(SALLIB) + +SHL3LIBS= $(LIB3TARGET) +SHL3DEF= $(MISC)$/$(SHL3TARGET).def +DEF3NAME= $(SHL3TARGET) +DEF3EXPORTFILE= pseudo.dxp + +# --- Targets ------------------------------------------------------ + +.INCLUDE : target.mk diff --git a/testtools/source/performance/pseudo.cxx b/testtools/source/performance/pseudo.cxx new file mode 100644 index 000000000000..fdc62bb811ca --- /dev/null +++ b/testtools/source/performance/pseudo.cxx @@ -0,0 +1,288 @@ +/************************************************************************** +#* +#* last change $Author: kr $ $Date: 2001-05-04 07:05:18 $ +#* $Revision: 1.1 $ +#* +#* $Logfile: $ +#* +#* Copyright (c) 1989 - 2000, Star Office GmbH +#* +#************************************************************************/ + +#ifndef _OSL_DIAGNOSE_H_ +#include <osl/diagnose.h> +#endif +#ifndef _OSL_INTERLOCK_H_ +#include <osl/interlck.h> +#endif +#ifndef _RTL_USTRING_HXX_ +#include <rtl/ustring.hxx> +#endif + +#ifndef _TYPELIB_TYPEDESCRIPTION_H_ +#include <typelib/typedescription.h> +#endif +#ifndef _UNO_DISPATCHER_H_ +#include <uno/dispatcher.h> +#endif +#ifndef _UNO_ENVIRONMENT_H_ +#include <uno/environment.h> +#endif +#ifndef _UNO_MAPPING_H_ +#include <uno/mapping.h> +#endif +#ifndef _UNO_LBNAMES_H_ +#include <uno/lbnames.h> +#endif + +using namespace rtl; + + +namespace pseudo_uno +{ + +//================================================================================================== +struct pseudo_Mapping : public uno_Mapping +{ + oslInterlockedCount nRef; + + uno_ExtEnvironment * pFrom; + uno_ExtEnvironment * pTo; + + pseudo_Mapping( uno_ExtEnvironment * pFrom_, uno_ExtEnvironment * pTo_ ); + ~pseudo_Mapping(); +}; + +//==== a uno pseudo proxy ============================================================================= +struct pseudo_unoInterfaceProxy : public uno_Interface +{ + oslInterlockedCount nRef; + pseudo_Mapping * pPseudoMapping; + + // mapping information + uno_Interface * pUnoI; // wrapped interface + typelib_InterfaceTypeDescription * pTypeDescr; + OUString oid; + + // ctor + inline pseudo_unoInterfaceProxy( pseudo_Mapping * pPseudoMapping_, + uno_Interface * pUnoI_, + typelib_InterfaceTypeDescription * pTypeDescr_, + const OUString & rOId_ ); +}; +//-------------------------------------------------------------------------------------------------- +static void SAL_CALL pseudo_unoInterfaceProxy_dispatch( + uno_Interface * pUnoI, + const typelib_TypeDescription * pMemberType, + void * pReturn, + void * pArgs[], + uno_Any ** ppException ) +{ + pseudo_unoInterfaceProxy * pThis = static_cast< pseudo_unoInterfaceProxy * >( pUnoI ); + (*pThis->pUnoI->pDispatcher)( pThis->pUnoI, pMemberType, pReturn, pArgs, ppException ); +} + +//-------------------------------------------------------------------------------------------------- +static void SAL_CALL pseudo_unoInterfaceProxy_free( uno_ExtEnvironment * pEnv, void * pProxy ) +{ + pseudo_unoInterfaceProxy * pThis = + static_cast< pseudo_unoInterfaceProxy * >( + reinterpret_cast< uno_Interface * >( pProxy ) ); + OSL_ASSERT( pEnv == pThis->pPseudoMapping->pTo ); + + (*pThis->pPseudoMapping->pFrom->revokeInterface)( pThis->pPseudoMapping->pFrom, pThis->pUnoI ); + (*pThis->pUnoI->release)( pThis->pUnoI ); + typelib_typedescription_release( (typelib_TypeDescription *)pThis->pTypeDescr ); + (*pThis->pPseudoMapping->release)( pThis->pPseudoMapping ); + +#ifdef DEBUG + *(int *)pProxy = 0xdeadbabe; +#endif + delete pThis; +} +//-------------------------------------------------------------------------------------------------- +static void SAL_CALL pseudo_unoInterfaceProxy_acquire( uno_Interface * pUnoI ) +{ + if (1 == osl_incrementInterlockedCount( &static_cast< pseudo_unoInterfaceProxy * >( pUnoI )->nRef )) + { + // rebirth of proxy zombie + // register at uno env + void * pThis = static_cast< uno_Interface * >( pUnoI ); + (*static_cast< pseudo_unoInterfaceProxy * >( pUnoI )->pPseudoMapping->pTo->registerProxyInterface)( + static_cast< pseudo_unoInterfaceProxy * >( pUnoI )->pPseudoMapping->pTo, + &pThis, pseudo_unoInterfaceProxy_free, + static_cast< pseudo_unoInterfaceProxy * >( pUnoI )->oid.pData, + static_cast< pseudo_unoInterfaceProxy * >( pUnoI )->pTypeDescr ); + OSL_ASSERT( pThis == static_cast< uno_Interface * >( pUnoI ) ); + } +} +//-------------------------------------------------------------------------------------------------- +static void SAL_CALL pseudo_unoInterfaceProxy_release( uno_Interface * pUnoI ) +{ + if (! osl_decrementInterlockedCount( & static_cast< pseudo_unoInterfaceProxy * >( pUnoI )->nRef )) + { + // revoke from uno env on last release + (*static_cast< pseudo_unoInterfaceProxy * >( pUnoI )->pPseudoMapping->pTo->revokeInterface)( + static_cast< pseudo_unoInterfaceProxy * >( pUnoI )->pPseudoMapping->pTo, pUnoI ); + } +} +//__________________________________________________________________________________________________ +inline pseudo_unoInterfaceProxy::pseudo_unoInterfaceProxy( + pseudo_Mapping * pPseudoMapping_, uno_Interface * pUnoI_, + typelib_InterfaceTypeDescription * pTypeDescr_, const OUString & rOId_ ) + : nRef( 1 ) + , pPseudoMapping( pPseudoMapping_ ) + , pUnoI( pUnoI_ ) + , pTypeDescr( pTypeDescr_ ) + , oid( rOId_ ) +{ + (*pPseudoMapping->acquire)( pPseudoMapping ); + typelib_typedescription_acquire( (typelib_TypeDescription *)pTypeDescr ); + (*pPseudoMapping->pFrom->registerInterface)( + pPseudoMapping->pFrom, reinterpret_cast< void ** >( &pUnoI ), oid.pData, pTypeDescr ); + (*pUnoI->acquire)( pUnoI ); + + // uno_Interface + uno_Interface::acquire = pseudo_unoInterfaceProxy_acquire; + uno_Interface::release = pseudo_unoInterfaceProxy_release; + uno_Interface::pDispatcher = pseudo_unoInterfaceProxy_dispatch; +} + +//-------------------------------------------------------------------------------------------------- +static void SAL_CALL pseudo_Mapping_mapInterface( + uno_Mapping * pMapping, void ** ppOut, + void * pUnoI, typelib_InterfaceTypeDescription * pTypeDescr ) +{ + OSL_ASSERT( ppOut && pTypeDescr ); + if (*ppOut) + { + (*reinterpret_cast< uno_Interface * >( *ppOut )->release)( + reinterpret_cast< uno_Interface * >( *ppOut ) ); + *ppOut = 0; + } + if (pUnoI && pTypeDescr) + { + // get object id of uno interface to be wrapped + rtl_uString * pOId = 0; + (*static_cast< pseudo_Mapping * >( pMapping )->pFrom->getObjectIdentifier)( + static_cast< pseudo_Mapping * >( pMapping )->pFrom, &pOId, pUnoI ); + OSL_ASSERT( pOId ); + + if (pOId) + { + // try to get any known interface from target environment + (*static_cast< pseudo_Mapping * >( pMapping )->pTo->getRegisteredInterface)( + static_cast< pseudo_Mapping * >( pMapping )->pTo, ppOut, pOId, pTypeDescr ); + if (! *ppOut) // no existing interface, register new proxy interface + { + // try to publish a new proxy (ref count initially 1) + void * pProxy = new pseudo_unoInterfaceProxy( + static_cast< pseudo_Mapping * >( pMapping ), + reinterpret_cast< uno_Interface * >( pUnoI ), pTypeDescr, pOId ); + + // proxy may be exchanged during registration + (*static_cast< pseudo_Mapping * >( pMapping )->pTo->registerProxyInterface)( + static_cast< pseudo_Mapping * >( pMapping )->pTo, + &pProxy, pseudo_unoInterfaceProxy_free, pOId, pTypeDescr ); + + *ppOut = pProxy; + } + rtl_uString_release( pOId ); + } + } +} +//-------------------------------------------------------------------------------------------------- +static void SAL_CALL pseudo_Mapping_free( uno_Mapping * pMapping ) +{ + delete static_cast< pseudo_Mapping * >( pMapping ); +} +//-------------------------------------------------------------------------------------------------- +static void SAL_CALL pseudo_Mapping_acquire( uno_Mapping * pMapping ) +{ + if (1 == osl_incrementInterlockedCount( & static_cast< pseudo_Mapping * >( pMapping )->nRef )) + { + OUString aMappingPurpose( RTL_CONSTASCII_USTRINGPARAM("pseudo") ); + uno_registerMapping( &pMapping, + pseudo_Mapping_free, + (uno_Environment *)((pseudo_Mapping *)pMapping)->pFrom, + (uno_Environment *)((pseudo_Mapping *)pMapping)->pTo, + aMappingPurpose.pData ); + } +} +//-------------------------------------------------------------------------------------------------- +static void SAL_CALL pseudo_Mapping_release( uno_Mapping * pMapping ) +{ + if (! osl_decrementInterlockedCount( & static_cast< pseudo_Mapping * >( pMapping )->nRef )) + { + uno_revokeMapping( pMapping ); + } +} + +//__________________________________________________________________________________________________ +pseudo_Mapping::pseudo_Mapping( uno_ExtEnvironment * pFrom_, uno_ExtEnvironment * pTo_ ) + : nRef( 1 ) + , pFrom( pFrom_ ) + , pTo( pTo_ ) +{ + (*((uno_Environment *)pFrom)->acquire)( (uno_Environment *)pFrom ); + (*((uno_Environment *)pTo)->acquire)( (uno_Environment *)pTo ); + // + uno_Mapping::acquire = pseudo_Mapping_acquire; + uno_Mapping::release = pseudo_Mapping_release; + uno_Mapping::mapInterface = pseudo_Mapping_mapInterface; +} +//__________________________________________________________________________________________________ +pseudo_Mapping::~pseudo_Mapping() +{ + (*((uno_Environment *)pTo)->release)( (uno_Environment *)pTo ); + (*((uno_Environment *)pFrom)->release)( (uno_Environment *)pFrom ); +} + +} + +//################################################################################################## +extern "C" SAL_DLLEXPORT void SAL_CALL uno_initEnvironment( uno_Environment * pUnoEnv ) +{ + OSL_ENSURE( sal_False, "### no impl: unexpected call!" ); +} +//################################################################################################## +extern "C" SAL_DLLEXPORT void SAL_CALL uno_ext_getMapping( + uno_Mapping ** ppMapping, uno_Environment * pFrom, uno_Environment * pTo ) +{ + OSL_ASSERT( ppMapping && pFrom && pTo ); + if (ppMapping && pFrom && pTo && pFrom->pExtEnv && pTo->pExtEnv) + { + uno_Mapping * pMapping = 0; + + if (0 == rtl_ustr_ascii_compare( pFrom->pTypeName->buffer, UNO_LB_UNO ) && + 0 == rtl_ustr_ascii_compare( pTo->pTypeName->buffer, UNO_LB_UNO )) + { + OUString aMappingPurpose( RTL_CONSTASCII_USTRINGPARAM("pseudo") ); + // ref count is initially 1 + pMapping = new pseudo_uno::pseudo_Mapping( pFrom->pExtEnv, pTo->pExtEnv ); + uno_registerMapping( &pMapping, pseudo_uno::pseudo_Mapping_free, + (uno_Environment *)pFrom->pExtEnv, + (uno_Environment *)pTo->pExtEnv, + aMappingPurpose.pData ); + } + + if (*ppMapping) + (*(*ppMapping)->release)( *ppMapping ); + *ppMapping = pMapping; + } +} + + +/************************************************************************** + $Log: not supported by cvs2svn $ + Revision 1.3 2001/03/12 16:22:44 jl + OSL_ENSHURE replaced by OSL_ENSURE + + Revision 1.2 2000/06/15 08:58:08 dbo + runtime changes + + Revision 1.1 2000/05/22 12:50:36 dbo + new + + +**************************************************************************/ diff --git a/testtools/source/performance/ubobject.cxx b/testtools/source/performance/ubobject.cxx new file mode 100644 index 000000000000..1a4d82655197 --- /dev/null +++ b/testtools/source/performance/ubobject.cxx @@ -0,0 +1,307 @@ +/************************************************************************** +#* +#* last change $Author: kr $ $Date: 2001-05-04 07:05:18 $ +#* $Revision: 1.1 $ +#* +#* $Logfile: $ +#* +#* Copyright (c) 1989 - 2000, Star Office GmbH +#* +#************************************************************************/ + +#include <osl/diagnose.h> +#include <osl/interlck.h> + +#include <cppuhelper/factory.hxx> + +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/registry/XRegistryKey.hpp> + +#include <com/sun/star/test/performance/XPerformanceTest.hpp> + +using namespace rtl; +using namespace osl; +using namespace cppu; +using namespace com::sun::star::uno; +using namespace com::sun::star::lang; +using namespace com::sun::star::registry; +using namespace com::sun::star::test::performance; + +#define SERVICENAME "com.sun.star.test.performance.PerformanceTestObject" +#define IMPLNAME "com.sun.star.comp.performance.PerformanceTestObject" + +namespace benchmark_object +{ + +//-------------------------------------------------------------------------------------------------- +inline static Sequence< OUString > getSupportedServiceNames() +{ + OUString aName( RTL_CONSTASCII_USTRINGPARAM(SERVICENAME) ); + return Sequence< OUString >( &aName, 1 ); +} + +//================================================================================================== +class ServiceImpl + : public XServiceInfo + , public XPerformanceTest +{ + OUString _aDummyString; + Any _aDummyAny; + Sequence< Reference< XInterface > > _aDummySequence; + ComplexTypes _aDummyStruct; + RuntimeException _aDummyRE; + + sal_Int32 _nRef; + +public: + ServiceImpl() + : _nRef( 0 ) + {} + ServiceImpl( const Reference< XMultiServiceFactory > & xMgr ) + : _nRef( 0 ) + {} + + // XInterface + virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type& aType ) throw(::com::sun::star::uno::RuntimeException) + { + // execution time remains appr. constant any time + Any aRet; + if (aType == ::getCppuType( (const Reference< XInterface > *)0 )) + { + void * p = (XInterface *)(XPerformanceTest *)this; + aRet.setValue( &p, ::getCppuType( (const Reference< XInterface > *)0 ) ); + } + if (aType == ::getCppuType( (const Reference< XPerformanceTest > *)0 )) + { + void * p = (XPerformanceTest *)this; + aRet.setValue( &p, ::getCppuType( (const Reference< XPerformanceTest > *)0 ) ); + } + if (! aRet.hasValue()) + { + void * p = (XPerformanceTest *)this; + Any aDummy( &p, ::getCppuType( (const Reference< XPerformanceTest > *)0 ) ); + } + return aRet; + } + virtual void SAL_CALL acquire() throw(::com::sun::star::uno::RuntimeException) + { osl_incrementInterlockedCount( &_nRef ); } + virtual void SAL_CALL release() throw(::com::sun::star::uno::RuntimeException) + { if (! osl_decrementInterlockedCount( &_nRef )) delete this; } + + // XServiceInfo + virtual OUString SAL_CALL getImplementationName() throw (RuntimeException); + virtual sal_Bool SAL_CALL supportsService( const OUString & rServiceName ) throw (RuntimeException); + virtual Sequence< OUString > SAL_CALL getSupportedServiceNames() throw (RuntimeException); + + // Attributes + virtual sal_Int32 SAL_CALL getLong_attr() throw(::com::sun::star::uno::RuntimeException) + { return 0; } + virtual void SAL_CALL setLong_attr( sal_Int32 _attributelong ) throw(::com::sun::star::uno::RuntimeException) + {} + virtual sal_Int64 SAL_CALL getHyper_attr() throw(::com::sun::star::uno::RuntimeException) + { return 0; } + virtual void SAL_CALL setHyper_attr( sal_Int64 _attributehyper ) throw(::com::sun::star::uno::RuntimeException) + {} + virtual float SAL_CALL getFloat_attr() throw(::com::sun::star::uno::RuntimeException) + { return 0.0; } + virtual void SAL_CALL setFloat_attr( float _attributefloat ) throw(::com::sun::star::uno::RuntimeException) + {} + virtual double SAL_CALL getDouble_attr() throw(::com::sun::star::uno::RuntimeException) + { return 0.0; } + virtual void SAL_CALL setDouble_attr( double _attributedouble ) throw(::com::sun::star::uno::RuntimeException) + {} + virtual OUString SAL_CALL getString_attr() throw(::com::sun::star::uno::RuntimeException) + { return _aDummyString; } + virtual void SAL_CALL setString_attr( const ::rtl::OUString& _attributestring ) throw(::com::sun::star::uno::RuntimeException) + {} + virtual Reference< XInterface > SAL_CALL getInterface_attr() throw(::com::sun::star::uno::RuntimeException) + { return Reference< XInterface >(); } + virtual void SAL_CALL setInterface_attr( const Reference< XInterface >& _attributeinterface ) throw(::com::sun::star::uno::RuntimeException) + {} + virtual Any SAL_CALL getAny_attr() throw(::com::sun::star::uno::RuntimeException) + { return _aDummyAny; } + virtual void SAL_CALL setAny_attr( const Any& _attributeany ) throw(::com::sun::star::uno::RuntimeException) + {} + virtual Sequence< Reference< XInterface > > SAL_CALL getSequence_attr() throw(::com::sun::star::uno::RuntimeException) + { return _aDummySequence; } + virtual void SAL_CALL setSequence_attr( const Sequence< Reference< XInterface > >& _attributesequence ) throw(::com::sun::star::uno::RuntimeException) + {} + virtual ComplexTypes SAL_CALL getStruct_attr() throw(::com::sun::star::uno::RuntimeException) + { return _aDummyStruct; } + virtual void SAL_CALL setStruct_attr( const ::com::sun::star::test::performance::ComplexTypes& _attributestruct ) throw(::com::sun::star::uno::RuntimeException) + {} + + // Methods + virtual sal_Int32 SAL_CALL getLong() throw(::com::sun::star::uno::RuntimeException) + { return 0; } + virtual void SAL_CALL setLong( sal_Int32 _long ) throw(::com::sun::star::uno::RuntimeException) + {} + virtual sal_Int64 SAL_CALL getHyper() throw(::com::sun::star::uno::RuntimeException) + { return 0; } + virtual void SAL_CALL setHyper( sal_Int64 _hyper ) throw(::com::sun::star::uno::RuntimeException) + {} + virtual float SAL_CALL getFloat() throw(::com::sun::star::uno::RuntimeException) + { return 0; } + virtual void SAL_CALL setFloat( float _float ) throw(::com::sun::star::uno::RuntimeException) + {} + virtual double SAL_CALL getDouble() throw(::com::sun::star::uno::RuntimeException) + { return 0; } + virtual void SAL_CALL setDouble( double _double ) throw(::com::sun::star::uno::RuntimeException) + {} + virtual OUString SAL_CALL getString() throw(::com::sun::star::uno::RuntimeException) + { return _aDummyString; } + virtual void SAL_CALL setString( const ::rtl::OUString& _string ) throw(::com::sun::star::uno::RuntimeException) + {} + virtual Reference< XInterface > SAL_CALL getInterface() throw(::com::sun::star::uno::RuntimeException) + { return Reference< XInterface >(); } + virtual void SAL_CALL setInterface( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _interface ) throw(::com::sun::star::uno::RuntimeException) + {} + virtual Any SAL_CALL getAny() throw(::com::sun::star::uno::RuntimeException) + { return _aDummyAny; } + virtual void SAL_CALL setAny( const ::com::sun::star::uno::Any& _any ) throw(::com::sun::star::uno::RuntimeException) + {} + virtual Sequence< Reference< XInterface > > SAL_CALL getSequence() throw(::com::sun::star::uno::RuntimeException) + { return _aDummySequence; } + virtual void SAL_CALL setSequence( const Sequence< Reference< XInterface > >& _sequence ) throw(::com::sun::star::uno::RuntimeException) + {} + virtual ComplexTypes SAL_CALL getStruct() throw(::com::sun::star::uno::RuntimeException) + { return _aDummyStruct; } + virtual void SAL_CALL setStruct( const ::com::sun::star::test::performance::ComplexTypes& c ) throw(::com::sun::star::uno::RuntimeException) + {} + + virtual void SAL_CALL async() throw(::com::sun::star::uno::RuntimeException) + {} + virtual void SAL_CALL sync() throw(::com::sun::star::uno::RuntimeException) + {} + virtual ComplexTypes SAL_CALL complex_in( const ::com::sun::star::test::performance::ComplexTypes& aVal ) throw(::com::sun::star::uno::RuntimeException) + { return aVal; } + virtual ComplexTypes SAL_CALL complex_inout( ::com::sun::star::test::performance::ComplexTypes& aVal ) throw(::com::sun::star::uno::RuntimeException) + { return aVal; } + virtual void SAL_CALL complex_oneway( const ::com::sun::star::test::performance::ComplexTypes& aVal ) throw(::com::sun::star::uno::RuntimeException) + {} + virtual void SAL_CALL complex_noreturn( const ::com::sun::star::test::performance::ComplexTypes& aVal ) throw(::com::sun::star::uno::RuntimeException) + {} + virtual Reference< XPerformanceTest > SAL_CALL createObject() throw(::com::sun::star::uno::RuntimeException) + { return new ServiceImpl(); } + virtual void SAL_CALL raiseRuntimeException( ) throw(::com::sun::star::uno::RuntimeException) + { throw _aDummyRE; } +}; + +//################################################################################################## + +// XServiceInfo +//__________________________________________________________________________________________________ +OUString ServiceImpl::getImplementationName() + throw (RuntimeException) +{ + return OUString( RTL_CONSTASCII_USTRINGPARAM(IMPLNAME) ); +} +//__________________________________________________________________________________________________ +sal_Bool ServiceImpl::supportsService( const OUString & rServiceName ) + throw (RuntimeException) +{ + const Sequence< OUString > & rSNL = getSupportedServiceNames(); + const OUString * pArray = rSNL.getConstArray(); + for ( sal_Int32 nPos = rSNL.getLength(); nPos--; ) + { + if (pArray[nPos] == rServiceName) + return sal_True; + } + return sal_False; +} +//__________________________________________________________________________________________________ +Sequence< OUString > ServiceImpl::getSupportedServiceNames() + throw (RuntimeException) +{ + return benchmark_object::getSupportedServiceNames(); +} + +// ... + +//================================================================================================== +static Reference< XInterface > SAL_CALL ServiceImpl_create( const Reference< XMultiServiceFactory > & xSMgr ) +{ + return Reference< XInterface >( (XPerformanceTest *)new ServiceImpl( xSMgr ) ); +} + +} + + +//################################################################################################## +//################################################################################################## +//################################################################################################## + + +extern "C" +{ +//================================================================================================== +void SAL_CALL component_getImplementationEnvironment( + const sal_Char ** ppEnvTypeName, uno_Environment ** ppEnv ) +{ + *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME; +} +//================================================================================================== +sal_Bool SAL_CALL component_writeInfo( + void * pServiceManager, void * pRegistryKey ) +{ + if (pRegistryKey) + { + try + { + Reference< XRegistryKey > xNewKey( + reinterpret_cast< XRegistryKey * >( pRegistryKey )->createKey( + OUString( RTL_CONSTASCII_USTRINGPARAM("/" IMPLNAME "/UNO/SERVICES") ) ) ); + xNewKey->createKey( OUString( RTL_CONSTASCII_USTRINGPARAM(SERVICENAME) ) ); + + return sal_True; + } + catch (InvalidRegistryException &) + { + OSL_ENSURE( sal_False, "### InvalidRegistryException!" ); + } + } + return sal_False; +} +//================================================================================================== +void * SAL_CALL component_getFactory( + const sal_Char * pImplName, void * pServiceManager, void * pRegistryKey ) +{ + void * pRet = 0; + + if (pServiceManager && rtl_str_compare( pImplName, IMPLNAME ) == 0) + { + Reference< XSingleServiceFactory > xFactory( createSingleFactory( + reinterpret_cast< XMultiServiceFactory * >( pServiceManager ), + OUString( RTL_CONSTASCII_USTRINGPARAM(IMPLNAME) ), + benchmark_object::ServiceImpl_create, + benchmark_object::getSupportedServiceNames() ) ); + + if (xFactory.is()) + { + xFactory->acquire(); + pRet = xFactory.get(); + } + } + + return pRet; +} +} + + +/************************************************************************** + $Log: not supported by cvs2svn $ + Revision 1.4 2001/03/12 16:22:44 jl + OSL_ENSHURE replaced by OSL_ENSURE + + Revision 1.3 2000/05/26 14:15:34 dbo + misc + + Revision 1.2 2000/05/25 16:45:00 dbo + shifted XPerformanceTest to api + + Revision 1.1 2000/05/22 12:50:36 dbo + new + + +**************************************************************************/ diff --git a/testtools/source/performance/ubtest.cxx b/testtools/source/performance/ubtest.cxx new file mode 100644 index 000000000000..610e8b535fb8 --- /dev/null +++ b/testtools/source/performance/ubtest.cxx @@ -0,0 +1,1371 @@ +/************************************************************************** +#* +#* last change $Author: kr $ $Date: 2001-05-04 07:05:18 $ +#* $Revision: 1.1 $ +#* +#* $Logfile: $ +#* +#* Copyright (c) 1989 - 2000, Star Office GmbH +#* +#************************************************************************/ + +#include <stdio.h> +#include <math.h> +#include <string> +#include <stl/hash_map> +#include <stl/map> + +#include <osl/diagnose.h> +#include <osl/mutex.hxx> +#include <osl/module.h> +#include <osl/process.h> +#include <osl/thread.h> +#include <osl/conditn.hxx> + +#ifndef _OSL_TIME_H_ +#include <osl/time.h> +#endif + +#ifdef SAL_W32 +#include <windows.h> +#else +#include <sys/times.h> +#endif + +#include <rtl/string.hxx> +#include <rtl/strbuf.hxx> +#include <rtl/ustrbuf.hxx> + +#include <uno/environment.hxx> +#include <uno/mapping.hxx> + +#include <cppuhelper/factory.hxx> +#include <cppuhelper/implbase2.hxx> + +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/lang/XMain.hpp> +#include <com/sun/star/lang/XInitialization.hpp> +#include <com/sun/star/loader/XImplementationLoader.hpp> +#include <com/sun/star/registry/XRegistryKey.hpp> +#include <com/sun/star/bridge/XUnoUrlResolver.hpp> +#include <com/sun/star/container/XSet.hpp> +#include <com/sun/star/test/performance/XPerformanceTest.hpp> + +#define NLOOP 200000000 + +using namespace rtl; +using namespace osl; +using namespace cppu; +using namespace com::sun::star::uno; +using namespace com::sun::star::lang; +using namespace com::sun::star::loader; +using namespace com::sun::star::registry; +using namespace com::sun::star::bridge; +using namespace com::sun::star::container; +using namespace com::sun::star::test::performance; + +#define SERVICENAME "com.sun.star.test.performance.PerformanceTest" +#define IMPLNAME "com.sun.star.comp.performance.PerformanceTest" + +namespace benchmark_test +{ + +static inline sal_uInt32 getSystemTicks() +{ +#ifdef SAL_W32 + return (sal_uInt32)GetTickCount(); +#else // only UNX supported for now + static sal_uInt32 nImplTicksPerSecond = 0; + static double dImplTicksPerSecond; + static double dImplTicksULONGMAX; + + struct tms aTms; + sal_uInt32 nTicks = (sal_uInt32)times( &aTms ); + + if ( !nImplTicksPerSecond ) + { + nImplTicksPerSecond = CLK_TCK; + dImplTicksPerSecond = nImplTicksPerSecond; + dImplTicksULONGMAX = (double)(sal_uInt32)ULONG_MAX; + } + + double fTicks = nTicks; + fTicks *= 1000; + fTicks /= dImplTicksPerSecond; + fTicks = fmod (fTicks, dImplTicksULONGMAX); + + return (sal_uInt32)fTicks; +#endif +} + +//-------------------------------------------------------------------------------------------------- +static void out( const sal_Char * pText, FILE * stream = stderr, + sal_Int32 nStart = -1, sal_Char cFillchar = ' ' ) +{ + static sal_Int32 s_nPos = 0; + + sal_Char ar[2] = { cFillchar, 0 }; + while (s_nPos < nStart) + { + ::fprintf( stream, ar ); + ++s_nPos; + } + + ::fprintf( stream, pText ); + + for ( const sal_Char * p = pText; *p; ++p ) + { + if (*p == '\n') + s_nPos = 0; + else + ++s_nPos; + } +} +//-------------------------------------------------------------------------------------------------- +static inline void out( const OUString & rText, FILE * stream = stderr, + sal_Int32 nStart = -1, sal_Char cFillchar = ' ' ) +{ + OString aText( OUStringToOString( rText, RTL_TEXTENCODING_ASCII_US ) ); + out( aText.getStr(), stream, nStart, cFillchar ); +} +//-------------------------------------------------------------------------------------------------- +static inline void out( double fVal, FILE * stream = stderr, + sal_Int32 nStart = -1, sal_Char cFillchar = ' ' ) +{ + sal_Char ar[128]; + ::sprintf( ar, (fVal < 0.000001 ? "%g" : "%f"), fVal ); + out( ar, stream, nStart, cFillchar ); +} +//-------------------------------------------------------------------------------------------------- +static inline void out( sal_Int64 nVal, FILE * stream = stderr, + sal_Int32 nStart = -1, sal_Char cFillchar = ' ' ) +{ + sal_Char ar[128]; + ::sprintf( ar, "%ld", nVal ); + out( ar, stream, nStart, cFillchar ); +} + +//================================================================================================== +Reference< XSingleServiceFactory > loadLibComponentFactory( + const OUString & rLibName, const OUString & rImplName, + const Reference< XMultiServiceFactory > & xSF, const Reference< XRegistryKey > & xKey ) +{ + Reference< XSingleServiceFactory > xRet; + + OUStringBuffer aLibNameBuf( 32 ); +#ifdef SAL_UNX + aLibNameBuf.appendAscii( RTL_CONSTASCII_STRINGPARAM("lib") ); + aLibNameBuf.append( rLibName ); + aLibNameBuf.appendAscii( RTL_CONSTASCII_STRINGPARAM(".so") ); +#else + aLibNameBuf.append( rLibName ); + aLibNameBuf.appendAscii( RTL_CONSTASCII_STRINGPARAM(".dll") ); +#endif + OUString aLibName( aLibNameBuf.makeStringAndClear() ); + oslModule lib = osl_loadModule( aLibName.pData, SAL_LOADMODULE_LAZY | SAL_LOADMODULE_GLOBAL ); + + if (lib) + { + void * pSym; + + // ========================= LATEST VERSION ========================= + OUString aGetEnvName( RTL_CONSTASCII_USTRINGPARAM(COMPONENT_GETENV) ); + if (pSym = osl_getSymbol( lib, aGetEnvName.pData )) + { + uno_Environment * pCurrentEnv = 0; + uno_Environment * pEnv = 0; + const sal_Char * pEnvTypeName = 0; + (*((component_getImplementationEnvironmentFunc)pSym))( &pEnvTypeName, &pEnv ); + + sal_Bool bNeedsMapping = + (pEnv || 0 != rtl_str_compare( pEnvTypeName, CPPU_CURRENT_LANGUAGE_BINDING_NAME )); + + OUString aEnvTypeName( OUString::createFromAscii( pEnvTypeName ) ); + + if (bNeedsMapping) + { + if (! pEnv) + uno_getEnvironment( &pEnv, aEnvTypeName.pData, 0 ); + if (pEnv) + { + OUString aCppEnvTypeName( RTL_CONSTASCII_USTRINGPARAM(CPPU_CURRENT_LANGUAGE_BINDING_NAME) ); + uno_getEnvironment( &pCurrentEnv, aCppEnvTypeName.pData, 0 ); + if (pCurrentEnv) + bNeedsMapping = (pEnv != pCurrentEnv); + } + } + + OUString aGetFactoryName( RTL_CONSTASCII_USTRINGPARAM(COMPONENT_GETFACTORY) ); + if (pSym = osl_getSymbol( lib, aGetFactoryName.pData )) + { + OString aImplName( OUStringToOString( rImplName, RTL_TEXTENCODING_ASCII_US ) ); + + if (bNeedsMapping) + { + if (pEnv && pCurrentEnv) + { + Mapping aCurrent2Env( pCurrentEnv, pEnv ); + Mapping aEnv2Current( pEnv, pCurrentEnv ); + + if (aCurrent2Env.is() && aEnv2Current.is()) + { + void * pSMgr = aCurrent2Env.mapInterface( + xSF.get(), ::getCppuType( (const Reference< XMultiServiceFactory > *)0 ) ); + void * pKey = aCurrent2Env.mapInterface( + xKey.get(), ::getCppuType( (const Reference< XRegistryKey > *)0 ) ); + + void * pSSF = (*((component_getFactoryFunc)pSym))( + aImplName.getStr(), pSMgr, pKey ); + + if (pKey) + (*pEnv->pExtEnv->releaseInterface)( pEnv->pExtEnv, pKey ); + if (pSMgr) + (*pEnv->pExtEnv->releaseInterface)( pEnv->pExtEnv, pSMgr ); + + if (pSSF) + { + aEnv2Current.mapInterface( + reinterpret_cast< void ** >( &xRet ), + pSSF, ::getCppuType( (const Reference< XSingleServiceFactory > *)0 ) ); + (*pEnv->pExtEnv->releaseInterface)( pEnv->pExtEnv, pSSF ); + } + } + } + } + else + { + XSingleServiceFactory * pRet = (XSingleServiceFactory *) + (*((component_getFactoryFunc)pSym))( + aImplName.getStr(), xSF.get(), xKey.get() ); + if (pRet) + { + xRet = pRet; + pRet->release(); + } + } + } + + if (pEnv) + (*pEnv->release)( pEnv ); + if (pCurrentEnv) + (*pCurrentEnv->release)( pCurrentEnv ); + } + + // ========================= PREVIOUS VERSION ========================= + else + { + OUString aGetFactoryName( RTL_CONSTASCII_USTRINGPARAM(CREATE_COMPONENT_FACTORY_FUNCTION) ); + if (pSym = osl_getSymbol( lib, aGetFactoryName.pData )) + { + OUString aCppEnvTypeName( RTL_CONSTASCII_USTRINGPARAM(CPPU_CURRENT_LANGUAGE_BINDING_NAME) ); + OUString aUnoEnvTypeName( RTL_CONSTASCII_USTRINGPARAM(UNO_LB_UNO) ); + Mapping aUno2Cpp( aUnoEnvTypeName, aCppEnvTypeName ); + Mapping aCpp2Uno( aCppEnvTypeName, aUnoEnvTypeName ); + OSL_ENSURE( aUno2Cpp.is() && aCpp2Uno.is(), "### cannot get uno mappings!" ); + + if (aUno2Cpp.is() && aCpp2Uno.is()) + { + uno_Interface * pUComponentFactory = 0; + + uno_Interface * pUSFactory = (uno_Interface *)aCpp2Uno.mapInterface( + xSF.get(), ::getCppuType( (const Reference< XMultiServiceFactory > *)0 ) ); + uno_Interface * pUKey = (uno_Interface *)aCpp2Uno.mapInterface( + xKey.get(), ::getCppuType( (const Reference< XRegistryKey > *)0 ) ); + + pUComponentFactory = (*((CreateComponentFactoryFunc)pSym))( + rImplName.getStr(), pUSFactory, pUKey ); + + if (pUKey) + (*pUKey->release)( pUKey ); + if (pUSFactory) + (*pUSFactory->release)( pUSFactory ); + + if (pUComponentFactory) + { + XSingleServiceFactory * pXFactory = + (XSingleServiceFactory *)aUno2Cpp.mapInterface( + pUComponentFactory, ::getCppuType( (const Reference< XSingleServiceFactory > *)0 ) ); + (*pUComponentFactory->release)( pUComponentFactory ); + + if (pXFactory) + { + xRet = pXFactory; + pXFactory->release(); + } + } + } + } + } + + if (! xRet.is()) + osl_unloadModule( lib ); + } + + return xRet; +} +//-------------------------------------------------------------------------------------------------- +template< class T > +static void createInstance( Reference< T > & rxOut, + const Reference< XMultiServiceFactory > & xMgr, + const OUString & rServiceName ) + throw (RuntimeException) +{ + Reference< XInterface > x( xMgr->createInstance( rServiceName ), UNO_QUERY ); + + if (! x.is()) + { + static sal_Bool s_bSet = sal_False; + if (! s_bSet) + { + MutexGuard aGuard( Mutex::getGlobalMutex() ); + if (! s_bSet) + { + Reference< XSet > xSet( xMgr, UNO_QUERY ); + if (xSet.is()) + { + // acceptor + xSet->insert( makeAny( loadLibComponentFactory( + OUString( RTL_CONSTASCII_USTRINGPARAM("acceptor") ), + OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.stoc.Acceptor") ), + xMgr, Reference< XRegistryKey >() ) ) ); + // connector + xSet->insert( makeAny( loadLibComponentFactory( + OUString( RTL_CONSTASCII_USTRINGPARAM("connectr") ), + OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.stoc.Connector") ), + xMgr, Reference< XRegistryKey >() ) ) ); + // iiop bridge + xSet->insert( makeAny( loadLibComponentFactory( + OUString( RTL_CONSTASCII_USTRINGPARAM("remotebridge") ), + OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.bridge.Bridge.various") ), + xMgr, Reference< XRegistryKey >() ) ) ); + // bridge factory + xSet->insert( makeAny( loadLibComponentFactory( + OUString( RTL_CONSTASCII_USTRINGPARAM("brdgfctr") ), + OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.stoc.BridgeFactory") ), + xMgr, Reference< XRegistryKey >() ) ) ); + // uno url resolver + xSet->insert( makeAny( loadLibComponentFactory( + OUString( RTL_CONSTASCII_USTRINGPARAM("uuresolver") ), + OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.bridge.UnoUrlResolver") ), + xMgr, Reference< XRegistryKey >() ) ) ); + // java loader +// xSet->insert( makeAny( loadLibComponentFactory( +// OUString( RTL_CONSTASCII_USTRINGPARAM("javaloader") ), +// OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.stoc.JavaComponentLoader") ), +// xMgr, Reference< XRegistryKey >() ) ) ); + } + s_bSet = sal_True; + } + } + x = xMgr->createInstance( rServiceName ); + } + + if (! x.is()) + { + OUStringBuffer buf( 64 ); + buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("cannot get service instance \"") ); + buf.append( rServiceName ); + buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("\"!") ); + throw RuntimeException( buf.makeStringAndClear(), Reference< XInterface >() ); + } + + rxOut = Reference< T >::query( x ); + if (! rxOut.is()) + { + OUStringBuffer buf( 64 ); + buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("service instance \"") ); + buf.append( rServiceName ); + buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("\" does not support demanded interface \"") ); + const Type & rType = ::getCppuType( (const Reference< T > *)0 ); + buf.append( rType.getTypeName() ); + buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("\"!") ); + throw RuntimeException( buf.makeStringAndClear(), Reference< XInterface >() ); + } +} + +//-------------------------------------------------------------------------------------------------- +inline static Sequence< OUString > getSupportedServiceNames() +{ + OUString aName( RTL_CONSTASCII_USTRINGPARAM(SERVICENAME) ); + return Sequence< OUString >( &aName, 1 ); +} + +//================================================================================================== +class TestImpl : public WeakImplHelper2< XServiceInfo, XMain > +{ + Reference< XMultiServiceFactory > _xSMgr; + + Reference< XInterface > _xDirect; + Reference< XInterface > getDirect() throw (Exception); + Reference< XInterface > resolveObject( const OUString & rUnoUrl ) throw (Exception); + +public: + TestImpl( const Reference< XMultiServiceFactory > & xSMgr ); + virtual ~TestImpl(); + + // XServiceInfo + virtual OUString SAL_CALL getImplementationName() throw (RuntimeException); + virtual sal_Bool SAL_CALL supportsService( const OUString & rServiceName ) throw (RuntimeException); + virtual Sequence< OUString > SAL_CALL getSupportedServiceNames() throw (RuntimeException); + + // XMain + virtual sal_Int32 SAL_CALL run( const Sequence< OUString > & rArgs ) throw (RuntimeException); +}; + +//################################################################################################## + +//__________________________________________________________________________________________________ +TestImpl::TestImpl( const Reference< XMultiServiceFactory > & xSMgr ) + : _xSMgr( xSMgr ) +{ +} +//__________________________________________________________________________________________________ +TestImpl::~TestImpl() +{ +} + +//================================================================================================== +static Reference< XInterface > SAL_CALL TestImpl_create( const Reference< XMultiServiceFactory > & xSMgr ) +{ + return Reference< XInterface >( *new TestImpl( xSMgr ) ); +} + +// XServiceInfo +//__________________________________________________________________________________________________ +OUString TestImpl::getImplementationName() + throw (RuntimeException) +{ + return OUString( RTL_CONSTASCII_USTRINGPARAM(IMPLNAME) ); +} +//__________________________________________________________________________________________________ +sal_Bool TestImpl::supportsService( const OUString & rServiceName ) + throw (RuntimeException) +{ + const Sequence< OUString > & rSNL = getSupportedServiceNames(); + const OUString * pArray = rSNL.getConstArray(); + for ( sal_Int32 nPos = rSNL.getLength(); nPos--; ) + { + if (pArray[nPos] == rServiceName) + return sal_True; + } + return sal_False; +} +//__________________________________________________________________________________________________ +Sequence< OUString > TestImpl::getSupportedServiceNames() + throw (RuntimeException) +{ + return benchmark_test::getSupportedServiceNames(); +} + +//__________________________________________________________________________________________________ +Reference< XInterface > TestImpl::getDirect() + throw (Exception) +{ + if (! _xDirect.is()) + { + MutexGuard aGuard( Mutex::getGlobalMutex() ); + if (! _xDirect.is()) + { + Reference< XSingleServiceFactory > xFac( loadLibComponentFactory( + OUString( RTL_CONSTASCII_USTRINGPARAM("perfobj") ), + OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.performance.PerformanceTestObject") ), + _xSMgr, Reference< XRegistryKey >() ) ); + if (! xFac.is()) + throw RuntimeException( OUString( RTL_CONSTASCII_USTRINGPARAM("no test object available!") ), Reference< XInterface >() ); + _xDirect = xFac->createInstance(); + } + } + return _xDirect; +} +//-------------------------------------------------------------------------------------------------- +Reference< XInterface > TestImpl::resolveObject( const OUString & rUnoUrl ) + throw (Exception) +{ + Reference< XUnoUrlResolver > xResolver; + createInstance( + xResolver, _xSMgr, + OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.bridge.UnoUrlResolver") ) ); + + Reference< XInterface > xResolvedObject( xResolver->resolve( rUnoUrl ) ); + + if (! xResolvedObject.is()) + { + OUStringBuffer buf( 32 ); + buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("cannot resolve object \"") ); + buf.append( rUnoUrl ); + buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("\"!") ); + throw RuntimeException( buf.makeStringAndClear(), Reference< XInterface >() ); + } + + return xResolvedObject; +} + +//================================================================================================== +class TimeEntry +{ + sal_Int64 nLoop; + sal_uInt32 nTicks; + +public: + TimeEntry() + {} + TimeEntry( sal_Int64 nLoop_, sal_uInt32 nTicks_ ) + : nLoop( nLoop_ ) + , nTicks( nTicks_ ) + {} + + inline double secPerCall() const + { return (((double)nTicks) / (nLoop * 1000)); } + + double ratio( const TimeEntry & rEntry ) const; +}; +//__________________________________________________________________________________________________ +double TimeEntry::ratio( const TimeEntry & rEntry ) const +{ + double f = rEntry.nTicks * nLoop; + if (f == 0.0) + { + return 0.0; + } + else + { + return (((double)(nTicks * rEntry.nLoop)) / f); + } +} + +//================================================================================================== +typedef std::map< std::string, TimeEntry > t_TimeEntryMap; + +//================================================================================================== +struct TimingSheet +{ + t_TimeEntryMap _entries; + void insert( const sal_Char * pText, sal_Int64 nLoop, sal_uInt32 nTicks ); +}; +//__________________________________________________________________________________________________ +void TimingSheet::insert( const sal_Char * pText, sal_Int64 nLoop, sal_uInt32 nTicks ) +{ + _entries[ pText ] = TimeEntry( nLoop, nTicks ); +} + +//================================================================================================== +typedef std::hash_map< std::string, TimingSheet > t_TimingSheetMap; + +//-------------------------------------------------------------------------------------------------- +static void benchmark( + TimingSheet & rSheet, const Reference< XInterface > & xInstance, sal_Int64 nLoop ) + throw (Exception) +{ + Reference< XPerformanceTest > xBench( xInstance, UNO_QUERY ); + if (! xBench.is()) + throw RuntimeException( OUString( RTL_CONSTASCII_USTRINGPARAM("illegal test object!") ), Reference< XInterface >() ); + + sal_Int64 i; + sal_uInt32 tStart, tEnd; + + const Type & rKnownType = ::getCppuType( (const Reference< XPerformanceTest > *)0 ); + const Type & rUnKnownType = ::getCppuType( (const Reference< XSet > *)0 ); + + ComplexTypes aDummyStruct; + + //------------------------------------ + // oneway calls + i = nLoop; + tStart = getSystemTicks(); + while (i--) + xBench->async(); + sal_uInt32 tEndSend = getSystemTicks(); + xBench->sync(); + tEnd = getSystemTicks(); + rSheet.insert( "1a: sending simple oneway calls (no params, no return)", nLoop, tEndSend - tStart ); + rSheet.insert( "1b: simple oneway calls (no params, no return)", nLoop, tEnd - tStart ); + // synchron calls + i = nLoop; + tStart = getSystemTicks(); + while (i--) + xBench->sync(); + xBench->sync(); + tEnd = getSystemTicks(); + rSheet.insert( "1c: simple synchron calls (no params no return)", nLoop+1, tEnd - tStart ); + + // acquire + i = nLoop; + tStart = getSystemTicks(); + while (i--) + xBench->acquire(); + tEnd = getSystemTicks(); + rSheet.insert( "2a: interface acquire() calls", nLoop, tEnd - tStart ); + // release + i = nLoop; + tStart = getSystemTicks(); + while (i--) + xBench->release(); + tEnd = getSystemTicks(); + rSheet.insert( "2b: interface release() calls", nLoop, tEnd - tStart ); + + // queryInterface() for known type + i = nLoop; + tStart = getSystemTicks(); + while (i--) + xBench->queryInterface( rKnownType ); + tEnd = getSystemTicks(); + rSheet.insert( "2c: interface query for implemented type", nLoop, tEnd - tStart ); + // queryInterface() for unknown type + i = nLoop; + tStart = getSystemTicks(); + while (i--) + xBench->queryInterface( rUnKnownType ); + tEnd = getSystemTicks(); + rSheet.insert( "2d: interface query for unknown type", nLoop, tEnd - tStart ); + + // create and forget objects + Reference< XPerformanceTest > xBench2( xBench ); + i = nLoop; + tStart = getSystemTicks(); + while (i--) + xBench2 = xBench2->createObject(); + tEnd = getSystemTicks(); + rSheet.insert( "3a: create and release test objects", nLoop, tEnd - tStart ); + + // hold new objects + Sequence< Reference< XInterface > > aSeq( nLoop / 100 ); + Reference< XInterface > * pSeq = aSeq.getArray(); + xBench2 = xBench; + i = aSeq.getLength(); + tStart = getSystemTicks(); + while (i--) + pSeq[i] = xBench2 = xBench2->createObject(); + tEnd = getSystemTicks(); + rSheet.insert( "3b: create and hold test objects", nLoop, tEnd - tStart ); + + // structs + i = nLoop; + tStart = getSystemTicks(); + while (i--) + xBench->complex_in( aDummyStruct ); + tEnd = getSystemTicks(); + rSheet.insert( "4a: complex_in() calls (in struct; return struct)", nLoop, tEnd - tStart ); + i = nLoop; + tStart = getSystemTicks(); + while (i--) + xBench->complex_inout( aDummyStruct ); + tEnd = getSystemTicks(); + rSheet.insert( "4b: complex_inout() calls (inout struct; return struct)", nLoop, tEnd - tStart ); + + i = nLoop; + tStart = getSystemTicks(); + while (i--) + xBench->complex_oneway( aDummyStruct ); + tEnd = getSystemTicks(); + rSheet.insert( "4c: complex_oneway() oneway calls (in struct)", nLoop, tEnd - tStart ); + i = nLoop; + tStart = getSystemTicks(); + while (i--) + xBench->complex_noreturn( aDummyStruct ); + tEnd = getSystemTicks(); + rSheet.insert( "4d: complex_noreturn() calls (in struct)", nLoop, tEnd - tStart ); + + // attributes, get() methods + i = nLoop; + tStart = getSystemTicks(); + while (i--) + xBench->getLong(); + tEnd = getSystemTicks(); + rSheet.insert( "5a: getLong() call", nLoop, tEnd - tStart ); + i = nLoop; + tStart = getSystemTicks(); + while (i--) + xBench->getLong_attr(); + tEnd = getSystemTicks(); + rSheet.insert( "5b: get long attribute", nLoop, tEnd - tStart ); + + i = nLoop; + tStart = getSystemTicks(); + while (i--) + xBench->setLong( 0 ); + tEnd = getSystemTicks(); + rSheet.insert( "5c: setLong() call", nLoop, tEnd - tStart ); + i = nLoop; + tStart = getSystemTicks(); + while (i--) + xBench->setLong_attr( 0 ); + tEnd = getSystemTicks(); + rSheet.insert( "5d: set long attribute", nLoop, tEnd - tStart ); + + i = nLoop; + tStart = getSystemTicks(); + while (i--) + xBench->getHyper(); + tEnd = getSystemTicks(); + rSheet.insert( "5e: getHyper() call", nLoop, tEnd - tStart ); + i = nLoop; + tStart = getSystemTicks(); + while (i--) + xBench->getHyper_attr(); + tEnd = getSystemTicks(); + rSheet.insert( "5f: get hyper attribute", nLoop, tEnd - tStart ); + + i = nLoop; + tStart = getSystemTicks(); + while (i--) + xBench->setHyper( 0 ); + tEnd = getSystemTicks(); + rSheet.insert( "5g: setHyper() call", nLoop, tEnd - tStart ); + i = nLoop; + tStart = getSystemTicks(); + while (i--) + xBench->setHyper_attr( 0 ); + tEnd = getSystemTicks(); + rSheet.insert( "5h: set hyper attribute", nLoop, tEnd - tStart ); + + i = nLoop; + tStart = getSystemTicks(); + while (i--) + xBench->getFloat(); + tEnd = getSystemTicks(); + rSheet.insert( "5i: getFloat() call", nLoop, tEnd - tStart ); + i = nLoop; + tStart = getSystemTicks(); + while (i--) + xBench->getFloat_attr(); + tEnd = getSystemTicks(); + rSheet.insert( "5j: get float attribute",nLoop, tEnd - tStart ); + + i = nLoop; + tStart = getSystemTicks(); + while (i--) + xBench->setFloat( 0.0 ); + tEnd = getSystemTicks(); + rSheet.insert( "5k: setFloat() call", nLoop, tEnd - tStart ); + i = nLoop; + tStart = getSystemTicks(); + while (i--) + xBench->setFloat_attr( 0.0 ); + tEnd = getSystemTicks(); + rSheet.insert( "5l: set float attribute", nLoop, tEnd - tStart ); + + i = nLoop; + tStart = getSystemTicks(); + while (i--) + xBench->getDouble(); + tEnd = getSystemTicks(); + rSheet.insert( "5m: getDouble() call", nLoop, tEnd - tStart ); + i = nLoop; + tStart = getSystemTicks(); + while (i--) + xBench->getDouble_attr(); + tEnd = getSystemTicks(); + rSheet.insert( "5n: get double attribute", nLoop, tEnd - tStart ); + i = nLoop; + tStart = getSystemTicks(); + while (i--) + xBench->setDouble( 0.0 ); + tEnd = getSystemTicks(); + rSheet.insert( "5o: setDouble() call", nLoop, tEnd - tStart ); + i = nLoop; + tStart = getSystemTicks(); + while (i--) + xBench->setDouble_attr( 0.0 ); + tEnd = getSystemTicks(); + rSheet.insert( "5p: set double attribute", nLoop, tEnd - tStart ); + + i = nLoop; + tStart = getSystemTicks(); + while (i--) + xBench->getString(); + tEnd = getSystemTicks(); + rSheet.insert( "6a: getString() call (empty)", nLoop, tEnd - tStart ); + i = nLoop; + tStart = getSystemTicks(); + while (i--) + xBench->getString_attr(); + tEnd = getSystemTicks(); + rSheet.insert( "6b: get empty string attribute", nLoop, tEnd - tStart ); + + i = nLoop; + OUString aDummyString; + tStart = getSystemTicks(); + while (i--) + xBench->setString( aDummyString ); + tEnd = getSystemTicks(); + rSheet.insert( "6c: setString() call (emtpy)", nLoop, tEnd - tStart ); + i = nLoop; + tStart = getSystemTicks(); + while (i--) + xBench->setString_attr( aDummyString ); + tEnd = getSystemTicks(); + rSheet.insert( "6d: set empty string attribute", nLoop, tEnd - tStart ); + + i = nLoop; + tStart = getSystemTicks(); + while (i--) + xBench->getInterface(); + tEnd = getSystemTicks(); + rSheet.insert( "7a: getInterface() call (null)", nLoop, tEnd - tStart ); + i = nLoop; + tStart = getSystemTicks(); + while (i--) + xBench->getInterface_attr(); + tEnd = getSystemTicks(); + rSheet.insert( "7b: get interface attribute", nLoop, tEnd - tStart ); + + i = nLoop; + Reference< XInterface > aDummyInterface; + tStart = getSystemTicks(); + while (i--) + xBench->setInterface( aDummyInterface ); + tEnd = getSystemTicks(); + rSheet.insert( "7c: setInterface() call (null)", nLoop, tEnd - tStart ); + i = nLoop; + tStart = getSystemTicks(); + while (i--) + xBench->setInterface_attr( Reference< XInterface >() ); + tEnd = getSystemTicks(); + rSheet.insert( "7d: set interface attribute", nLoop, tEnd - tStart ); + + i = nLoop; + tStart = getSystemTicks(); + while (i--) + xBench->getAny(); + tEnd = getSystemTicks(); + rSheet.insert( "8a: getAny() call (empty)", nLoop, tEnd - tStart ); + i = nLoop; + tStart = getSystemTicks(); + while (i--) + xBench->getAny_attr(); + tEnd = getSystemTicks(); + rSheet.insert( "8b: get empty any attribute", nLoop, tEnd - tStart ); + + i = nLoop; + Any aDummyAny; + tStart = getSystemTicks(); + while (i--) + xBench->setAny( aDummyAny ); + tEnd = getSystemTicks(); + rSheet.insert( "8c: setAny() call (empty)", nLoop, tEnd - tStart ); + i = nLoop; + tStart = getSystemTicks(); + while (i--) + xBench->setAny_attr( aDummyAny ); + tEnd = getSystemTicks(); + rSheet.insert( "8d: set empty any attribute", nLoop, tEnd - tStart ); + + i = nLoop; + tStart = getSystemTicks(); + while (i--) + xBench->getSequence(); + tEnd = getSystemTicks(); + rSheet.insert( "9a: getSequence() call (empty)", nLoop, tEnd - tStart ); + i = nLoop; + tStart = getSystemTicks(); + while (i--) + xBench->getSequence_attr(); + tEnd = getSystemTicks(); + rSheet.insert( "9b: get empty sequence attribute", nLoop, tEnd - tStart ); + i = nLoop; + Sequence< Reference< XInterface > > aDummySeq; + tStart = getSystemTicks(); + while (i--) + xBench->setSequence( aDummySeq ); + tEnd = getSystemTicks(); + rSheet.insert( "9c: setSequence() call (empty)", nLoop, tEnd - tStart ); + i = nLoop; + tStart = getSystemTicks(); + while (i--) + xBench->setSequence_attr( aDummySeq ); + tEnd = getSystemTicks(); + rSheet.insert( "9d: set empty sequence attribute", nLoop, tEnd - tStart ); + + i = nLoop; + tStart = getSystemTicks(); + while (i--) + xBench->getStruct(); + tEnd = getSystemTicks(); + rSheet.insert( "Aa: getStruct() call", nLoop, tEnd - tStart ); + i = nLoop; + tStart = getSystemTicks(); + while (i--) + xBench->getStruct_attr(); + tEnd = getSystemTicks(); + rSheet.insert( "Ab: get struct attribute", nLoop, tEnd - tStart ); + + i = nLoop; + tStart = getSystemTicks(); + while (i--) + xBench->setStruct( aDummyStruct ); + tEnd = getSystemTicks(); + rSheet.insert( "Ac: setStruct() call", nLoop, tEnd - tStart ); + i = nLoop; + tStart = getSystemTicks(); + while (i--) + xBench->setStruct_attr( aDummyStruct ); + tEnd = getSystemTicks(); + rSheet.insert( "Ad: set struct attribute", nLoop, tEnd - tStart ); + + // load +// i = nLoop; +// tStart = getSystemTicks(); +// while (i--) +// xBench->setSequence( aSeq ); +// tEnd = getSystemTicks(); +// rSheet.insert( "transfer of exisiting objects", nLoop, tEnd - tStart ); + + // exceptions + i = nLoop; + tStart = getSystemTicks(); + while (i--) + { + try + { + xBench->raiseRuntimeException(); + } + catch (RuntimeException &) + { + } + } + tEnd = getSystemTicks(); + rSheet.insert( "Ba: raising RuntimeException", nLoop, tEnd - tStart ); + + //------------------------------------ +} + +//-------------------------------------------------------------------------------------------------- +static OUString extractParam( const Sequence< OUString > & rArgs, const OUString & rParam ) +{ + const OUString * pArgs = rArgs.getConstArray(); + for ( sal_Int32 nPos = rArgs.getLength(); nPos--; ) + { + if (pArgs[nPos].indexOf( rParam ) == 0 && + pArgs[nPos].getLength() > (rParam.getLength()+1)) + { + return pArgs[nPos].copy( rParam.getLength() +1 ); // XXX=bla + } + } + return OUString(); +} + +const sal_Int32 nMagicNumberDirect = 34000; + +//XMain +//__________________________________________________________________________________________________ +sal_Int32 TestImpl::run( const Sequence< OUString > & rArgs ) + throw (RuntimeException) +{ + // defaults + FILE * stream = stderr; + sal_Int64 nLoop = NLOOP; + OUString aArg( RTL_CONSTASCII_USTRINGPARAM("dms") ); + + try + { + OUString aLoopStr( extractParam( rArgs, OUString( RTL_CONSTASCII_USTRINGPARAM("loop") ) ) ); + if (aLoopStr.getLength()) + { + sal_Int64 n = aLoopStr.toInt64(); + if (n > 0) + nLoop = n; + } + + OUString aDurationStr( extractParam( rArgs , OUString( RTL_CONSTASCII_USTRINGPARAM("duration" ) ) ) ); + if( aDurationStr.getLength() ) + { + sal_Int64 n = aDurationStr.toInt64(); + if( n >0 ) + nLoop = nMagicNumberDirect * n; + } + + OUString aLogStr( extractParam( rArgs, OUString( RTL_CONSTASCII_USTRINGPARAM("log") ) ) ); + if (aLogStr.getLength()) + { + if (aLogStr.compareToAscii( "stderr" ) == 0) + { + stream = stderr; + } + else if (aLogStr.compareToAscii( "stdout" ) == 0) + { + stream = stdout; + } + else + { + OString aFileName( OUStringToOString( aLogStr, RTL_TEXTENCODING_ASCII_US ) ); + stream = ::fopen( aFileName.getStr(), "w" ); + if (! stream) + { + OUStringBuffer buf( 32 ); + buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("cannot open file for writing: \"") ); + buf.append( aLogStr ); + buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("\"!") ); + throw RuntimeException( buf.makeStringAndClear(), Reference< XInterface >() ); + } + } + } + + OUString aArgStr( extractParam( rArgs, OUString( RTL_CONSTASCII_USTRINGPARAM("opt") ) ) ); + if (aArgStr.getLength()) + { + aArg = aArgStr; + } + + if (! rArgs.getLength()) + out( "\n> no options given, using defaults" ); + + // params + out( "\n> opt=" ); + out( aArg ); + out( " log=" ); + if (stream == stderr) + out( "stderr" ); + else if (stream == stderr) + out( "stdout loop=" ); + else + out( aLogStr ); + out( " loop=" ); + out( nLoop ); + out( "\n" ); + t_TimingSheetMap aSheets; + TimingSheet aDirect; + + //------------------------------------------------------------------------------------------ + + if (aArg.indexOf( 'd' ) >= 0) + { + // in process direct test + sal_uInt32 nStart = getSystemTicks(); + benchmark( aDirect, getDirect(), nLoop ); + sal_uInt32 nEnd = getSystemTicks(); + fprintf( stderr, "Duration (direct in process): %g s\n", (nEnd - nStart)/1000. ); + } + + //------------------------------------------------------------------------------------------ + + if (aArg.indexOf( 'm' ) >= 0) + { + // in process uno dispatch + Environment aCppEnv, aAnoCppEnv; + OUString aCurrentLanguageBindingName( RTL_CONSTASCII_USTRINGPARAM(CPPU_CURRENT_LANGUAGE_BINDING_NAME) ); + uno_getEnvironment( reinterpret_cast< uno_Environment ** >( &aCppEnv ), + aCurrentLanguageBindingName.pData, 0 ); + // anonymous + uno_createEnvironment( reinterpret_cast< uno_Environment ** >( &aAnoCppEnv ), + aCurrentLanguageBindingName.pData, 0 ); + + // pseudo mapping uno<->uno: does nothing! + Mapping aMapping( aCppEnv.get(), aAnoCppEnv.get(), OUString( RTL_CONSTASCII_USTRINGPARAM("pseudo") ) ); + if (! aMapping.is()) + throw RuntimeException( OUString( RTL_CONSTASCII_USTRINGPARAM("no pseudo mapping available!") ), Reference< XInterface >() ); + + Reference< XInterface > xMapped; + Reference< XInterface > xDirect( getDirect() ); + aMapping.mapInterface( reinterpret_cast< void ** >( &xMapped ), xDirect.get(), + ::getCppuType( &xDirect ) ); + if (! xMapped.is()) + throw RuntimeException( OUString( RTL_CONSTASCII_USTRINGPARAM("mapping object failed!") ), Reference< XInterface >() ); + + sal_uInt32 nStart = getSystemTicks(); + benchmark( aSheets[ "mapped in process" ], xMapped, nLoop / 100 ); + sal_uInt32 nEnd = getSystemTicks(); + fprintf( stderr, "Duration (mapped in process): %g s\n", (nStart - nEnd)/1000. ); + } + + //------------------------------------------------------------------------------------------ + + if (aArg.indexOf( 's' ) >= 0) + { + // start server process + oslSecurity hSecurity = osl_getCurrentSecurity(); + if (! hSecurity) + throw RuntimeException( OUString( RTL_CONSTASCII_USTRINGPARAM("cannot get current security handle!") ), Reference< XInterface >() ); + + OUString aArgs[] = { + OUString( RTL_CONSTASCII_USTRINGPARAM("-c") ), + OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.performance.PerformanceTestObject") ), + OUString( RTL_CONSTASCII_USTRINGPARAM("-l") ), +#ifdef SAL_UNX + OUString( RTL_CONSTASCII_USTRINGPARAM("libperfobj.so") ), +#else + OUString( RTL_CONSTASCII_USTRINGPARAM("perfobj.dll") ), +#endif + OUString( RTL_CONSTASCII_USTRINGPARAM("-r") ), + OUString( RTL_CONSTASCII_USTRINGPARAM("applicat.rdb") ), + OUString( RTL_CONSTASCII_USTRINGPARAM("-u") ), + OUString( RTL_CONSTASCII_USTRINGPARAM("uno:socket,host=localhost,port=6000;iiop;TestRemoteObject") ), + OUString( RTL_CONSTASCII_USTRINGPARAM("--singleaccept") ) + }; + rtl_uString * pArgs[] = { + aArgs[0].pData, + aArgs[1].pData, + aArgs[2].pData, + aArgs[3].pData, + aArgs[4].pData, + aArgs[5].pData, + aArgs[6].pData, + aArgs[7].pData, + aArgs[8].pData, + aArgs[9].pData, + }; + + out( "\n> executing: \"uno" ); + for ( sal_Int32 nPos = 0; nPos < (sizeof(aArgs) / sizeof(OUString)); ++nPos ) + { + out( " " ); + out( aArgs[nPos] ); + } + out( "\" ..." ); + + oslProcess hProcess = 0; + OUString aUnoExe( RTL_CONSTASCII_USTRINGPARAM("uno") ); + OUString aWorkingDir( RTL_CONSTASCII_USTRINGPARAM(".") ); + osl_executeProcess( + aUnoExe.pData, pArgs, sizeof(aArgs) / sizeof(OUString), + osl_Process_SEARCHPATH | osl_Process_DETACHED | osl_Process_NORMAL, + hSecurity, aWorkingDir.pData, 0, 0, 0, &hProcess ); + + osl_freeSecurityHandle( hSecurity ); + if (! hProcess) + throw RuntimeException( OUString( RTL_CONSTASCII_USTRINGPARAM("cannot start server process!") ), Reference< XInterface >() ); + osl_freeProcessHandle( hProcess ); + + // wait three seconds + TimeValue threeSeconds; + threeSeconds.Seconds = 3; + osl_waitThread( &threeSeconds ); + + // connect and resolve outer process object + Reference< XInterface > xResolvedObject( resolveObject( OUString( + RTL_CONSTASCII_USTRINGPARAM("uno:socket,host=localhost,port=6000;iiop;TestRemoteObject") ) ) ); + + benchmark( aSheets[ "remote same host" ], xResolvedObject, nLoop / 300 ); + } + + //------------------------------------------------------------------------------------------ + + if (aArg.indexOf( 'r' ) >= 0) + { + // remote + OUString aUnoUrl( extractParam( rArgs, OUString( RTL_CONSTASCII_USTRINGPARAM("url") ) ) ); + if (! aUnoUrl.getLength()) + throw RuntimeException( OUString( RTL_CONSTASCII_USTRINGPARAM("performance test r(emote) needs additional uno url!") ), Reference< XInterface >() ); + + // connect and resolve outer process object + Reference< XInterface > xResolvedObject( resolveObject( aUnoUrl ) ); + + sal_Int32 t1 = getSystemTicks(); + OString o = OUStringToOString( aUnoUrl, RTL_TEXTENCODING_ASCII_US ); + benchmark( aSheets[ o.getStr() ], xResolvedObject, nLoop / 900 ); + sal_Int32 t2 = getSystemTicks(); + fprintf( stderr, "Duration (%s): %g s\n", o.getStr(),(t2 - t1)/1000. ); + } + + //------------------------------------------------------------------------------------------ + + if (aArg.indexOf( 'j' ) >= 0) + { + // java + benchmark( aSheets[ "java in process" ], + _xSMgr->createInstance(OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.benchmark.JavaTestObject"))), + nLoop / 1000 ); + } + + //------------------------------------------------------------------------------------------ + // dump out tables + + out( "\nTimes( ratio to direct in process )", stream ); +#ifdef DEBUG + out ("; compiled with DEBUG", stream ); +#endif + out( ":", stream ); + + sal_Int32 nPos = 60; + out( "[direct in process]", stream, nPos ); + t_TimingSheetMap::const_iterator iSheets( aSheets.begin() ); + for ( ; iSheets != aSheets.end(); ++iSheets ) + { + nPos += 40; + out( "[", stream, nPos ); + out( (*iSheets).first.c_str(), stream ); + out( "]", stream ); + } + for ( t_TimeEntryMap::const_iterator iTopics( aDirect._entries.begin() ); + iTopics != aDirect._entries.end(); ++iTopics ) + { + const std::string & rTopic = (*iTopics).first; + + out( "\n", stream ); + out( rTopic.c_str(), stream ); + + out( ":", stream, 58, '.' ); + + sal_Int32 nPos = 60; + + double secs = (*iTopics).second.secPerCall(); + if (secs > 0.0) + { + out( secs * 1000, stream, nPos ); + out( "ms", stream ); + } + else + { + out( "NA", stream, nPos ); + } + + iSheets = aSheets.begin(); + for ( ; iSheets != aSheets.end(); ++iSheets ) + { + const t_TimeEntryMap::const_iterator iFind( (*iSheets).second._entries.find( rTopic ) ); + OSL_ENSURE( iFind != (*iSheets).second._entries.end(), "####" ); + + nPos += 40; + + double secs = (*iFind).second.secPerCall(); + if (secs != 0.0) + { + out( secs * 1000, stream, nPos ); + out( "ms", stream ); + + out( " (", stream ); + double ratio = (*iFind).second.ratio( (*iTopics).second ); + if (ratio != 0.0) + { + out( ratio, stream ); + out( " x)", stream ); + } + else + { + out( "NA)", stream ); + } + } + else + { + out( "NA", stream, nPos ); + } + } + } + } + catch (Exception & rExc) + { + if (stream != stderr && stream != stdout) + ::fclose( stream ); + throw RuntimeException( rExc.Message, rExc.Context ); + } + + if (stream != stderr && stream != stdout) + ::fclose( stream ); + + out( "\n> done.\n" ); + return 0; +} + +} + + +//################################################################################################## +//################################################################################################## +//################################################################################################## + + +extern "C" +{ +//================================================================================================== +void SAL_CALL component_getImplementationEnvironment( + const sal_Char ** ppEnvTypeName, uno_Environment ** ppEnv ) +{ + *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME; +} +//================================================================================================== +sal_Bool SAL_CALL component_writeInfo( + void * pServiceManager, void * pRegistryKey ) +{ + if (pRegistryKey) + { + try + { + Reference< XRegistryKey > xNewKey( + reinterpret_cast< XRegistryKey * >( pRegistryKey )->createKey( + OUString( RTL_CONSTASCII_USTRINGPARAM("/" IMPLNAME "/UNO/SERVICES") ) ) ); + xNewKey->createKey( OUString( RTL_CONSTASCII_USTRINGPARAM(SERVICENAME) ) ); + + return sal_True; + } + catch (InvalidRegistryException &) + { + OSL_ENSURE( sal_False, "### InvalidRegistryException!" ); + } + } + return sal_False; +} +//================================================================================================== +void * SAL_CALL component_getFactory( + const sal_Char * pImplName, void * pServiceManager, void * pRegistryKey ) +{ + void * pRet = 0; + + if (pServiceManager && rtl_str_compare( pImplName, IMPLNAME ) == 0) + { + Reference< XSingleServiceFactory > xFactory( createSingleFactory( + reinterpret_cast< XMultiServiceFactory * >( pServiceManager ), + OUString( RTL_CONSTASCII_USTRINGPARAM(IMPLNAME) ), + benchmark_test::TestImpl_create, + benchmark_test::getSupportedServiceNames() ) ); + + if (xFactory.is()) + { + xFactory->acquire(); + pRet = xFactory.get(); + } + } + + return pRet; +} +} + + +/************************************************************************** + $Log: not supported by cvs2svn $ + Revision 1.16 2001/04/19 12:53:47 kr + java in process test now works + + Revision 1.15 2001/03/14 09:55:11 jl + #include <osl/time.h> added + + Revision 1.14 2001/03/12 16:23:18 jl + OSL_ENSHURE replaced by OSL_ENSURE + + Revision 1.13 2001/01/17 12:38:33 kr + include <string> + + Revision 1.12 2000/09/28 10:38:47 jbu + iiopbrdg renaming + + Revision 1.11 2000/09/15 13:23:24 jbu + now passes unix compiler + + Revision 1.10 2000/09/12 15:41:07 jbu + added duration parameter + + Revision 1.8 2000/07/10 09:41:28 dbo + *** empty log message *** + + Revision 1.7 2000/06/23 13:52:58 dbo + *** empty log message *** + + Revision 1.6 2000/06/15 08:58:08 dbo + runtime changes + + Revision 1.5 2000/05/26 15:23:52 dbo + misc + + Revision 1.4 2000/05/26 14:15:34 dbo + misc + + Revision 1.3 2000/05/25 16:45:00 dbo + shifted XPerformanceTest to api + + Revision 1.2 2000/05/23 14:38:45 dbo + *** empty log message *** + + Revision 1.1 2000/05/22 12:50:36 dbo + new + + +**************************************************************************/ |