diff options
Diffstat (limited to 'testtools')
87 files changed, 16709 insertions, 0 deletions
diff --git a/testtools/com/sun/star/comp/bridge/CurrentContextChecker.java b/testtools/com/sun/star/comp/bridge/CurrentContextChecker.java new file mode 100644 index 000000000000..6d8022cd47fd --- /dev/null +++ b/testtools/com/sun/star/comp/bridge/CurrentContextChecker.java @@ -0,0 +1,81 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +package com.sun.star.comp.bridge; + +import com.sun.star.uno.Any; +import com.sun.star.uno.Type; +import com.sun.star.uno.UnoRuntime; +import com.sun.star.uno.XCurrentContext; +import test.testtools.bridgetest.XCurrentContextChecker; + +final class CurrentContextChecker implements XCurrentContextChecker { + public CurrentContextChecker() {} + + public boolean perform( + XCurrentContextChecker other, int setSteps, int checkSteps) + { + if (setSteps == 0) { + XCurrentContext old = UnoRuntime.getCurrentContext(); + UnoRuntime.setCurrentContext( + new XCurrentContext() { + public Object getValueByName(String Name) { + return Name.equals(KEY) + ? (Object) VALUE : (Object) Any.VOID; + } + }); + try { + return performCheck(other, setSteps, checkSteps); + } finally { + UnoRuntime.setCurrentContext(old); + } + } else { + return performCheck(other, setSteps, checkSteps); + } + } + + private boolean performCheck( + XCurrentContextChecker other, int setSteps, int checkSteps) + { + // assert other != null && checkSteps >= 0; + if (checkSteps == 0) { + XCurrentContext context = UnoRuntime.getCurrentContext(); + if (context == null) { + return false; + } + Any a = Any.complete(context.getValueByName(KEY)); + return + a.getType().equals(Type.STRING) && a.getObject().equals(VALUE); + } else { + return other.perform( + this, setSteps >= 0 ? setSteps - 1 : -1, checkSteps - 1); + } + } + + private static final String KEY = "testtools.bridgetest.Key"; + private static final String VALUE = "good"; +} 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..a399595f0164 --- /dev/null +++ b/testtools/com/sun/star/comp/bridge/TestComponent.java @@ -0,0 +1,1332 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +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 test.testtools.bridgetest.BadConstructorArguments; +import test.testtools.bridgetest.Constructors; +import test.testtools.bridgetest.Constructors2; +import test.testtools.bridgetest.TestDataElements; +import test.testtools.bridgetest.TestElement; +import test.testtools.bridgetest.TestEnum; +import test.testtools.bridgetest.TestPolyStruct; +import test.testtools.bridgetest.TestPolyStruct2; +import test.testtools.bridgetest.TestStruct; +import test.testtools.bridgetest.SmallStruct; +import test.testtools.bridgetest.MediumStruct; +import test.testtools.bridgetest.BigStruct; +import test.testtools.bridgetest.AllFloats; +import test.testtools.bridgetest.XBridgeTest; +import test.testtools.bridgetest.XBridgeTest2; +import test.testtools.bridgetest.XCurrentContextChecker; +import test.testtools.bridgetest.XMulti; +import test.testtools.bridgetest.XRecursiveCall; + + +import com.sun.star.lang.IllegalArgumentException; +import com.sun.star.lang.XMultiServiceFactory; +import com.sun.star.lang.XSingleServiceFactory; + +import com.sun.star.registry.XRegistryKey; + +import com.sun.star.uno.Any; +import com.sun.star.uno.Type; +import com.sun.star.uno.XComponentContext; +import com.sun.star.uno.XInterface; + +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 XBridgeTest2, 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; + + private boolean[] arBool; + private char[] arChar; + private byte[] arByte; + private short[] arShort; + private short[] arUShort; + private int[] arLong; + private int[] arULong; + private long[] arHyper; + private long[] arUHyper; + private float[] arFloat; + private double[] arDouble; + private String[] arString; + private Object[] arObject; + private Object[] arAny; + private TestEnum[] arEnum; + private int[][] arLong2; + private int[][][] arLong3; + 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]; + + io_testElements[ 0 ] = + new TestElement [] { io_testElements[ 0 ][ 1 ], io_testElements[ 0 ][ 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; + } + + public SmallStruct echoSmallStruct( SmallStruct i_Struct) throws com.sun.star.uno.RuntimeException { + return i_Struct; + } + + public MediumStruct echoMediumStruct( MediumStruct i_Struct) throws com.sun.star.uno.RuntimeException { + return i_Struct; + } + + public BigStruct echoBigStruct( BigStruct i_Struct) throws com.sun.star.uno.RuntimeException { + return i_Struct; + } + + public AllFloats echoAllFloats( AllFloats i_Struct) throws com.sun.star.uno.RuntimeException { + return i_Struct; + } + + public int testPPCAlignment( long l1, long l2, int i1, long l3, int i2 ) throws com.sun.star.uno.RuntimeException { + return i2; + } + + // 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 int getRaiseAttr1() { + throw new com.sun.star.uno.RuntimeException(); + } + + public void setRaiseAttr1(int n) throws IllegalArgumentException { + throw new IllegalArgumentException(); + } + + public int getRaiseAttr2() throws IllegalArgumentException { + throw new IllegalArgumentException(); + } + + public TestPolyStruct transportPolyBoolean(TestPolyStruct arg) { + Boolean dummy = (Boolean) arg.member; + return arg; + } + + public void transportPolyHyper(TestPolyStruct[] arg) { + Long dummy = (Long) arg[0].member; + } + + public void transportPolySequence( + TestPolyStruct arg1, TestPolyStruct[] arg2) + { + Object[] dummy = (Object[]) arg1.member; + arg2[0] = arg1; + } + + public TestPolyStruct getNullPolyLong() { + return new TestPolyStruct(); + } + + public TestPolyStruct getNullPolyString() { + return new TestPolyStruct(); + } + + public TestPolyStruct getNullPolyType() { + return new TestPolyStruct(); + } + + public TestPolyStruct getNullPolyAny() { + return new TestPolyStruct(); + } + + public TestPolyStruct getNullPolySequence() { + return new TestPolyStruct(); + } + + public TestPolyStruct getNullPolyEnum() { + return new TestPolyStruct(); + } + + public TestPolyStruct getNullPolyBadEnum() { + return new TestPolyStruct(); + } + + public TestPolyStruct getNullPolyStruct() { + return new TestPolyStruct(); + } + + public TestPolyStruct getNullPolyInterface() { + return new TestPolyStruct(); + } + + 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(XRecursiveCall xCall, int nToCall) throws com.sun.star.uno.RuntimeException { + if(nToCall != 0) + { + nToCall --; + xCall.callRecursivly(this , nToCall); + } + } + + public synchronized void startRecursiveCall(XRecursiveCall xCall, int nToCall) throws com.sun.star.uno.RuntimeException { + if(nToCall != 0) + { + nToCall --; + xCall.callRecursivly( this , nToCall ); + } + } + + public XMulti getMulti() { + return new XMulti() { + public double getatt1() { + return attribute1; + } + + public void setatt1(double value) { + attribute1 = value; + } + + public int fn11(int arg) { + return 11 * arg; + } + + public String fn12(String arg) { + return "12" + arg; + } + + public int fn21(int arg) { + return 21 * arg; + } + + public String fn22(String arg) { + return "22" + arg; + } + + public double getatt3() { + return attribute3; + } + + public void setatt3(double value) { + attribute3 = value; + } + + public int fn31(int arg) { + return 31 * arg; + } + + public String fn32(String arg) { + return "32" + arg; + } + + public int fn33() { + return 33; + } + + public int fn41(int arg) { + return 41 * arg; + } + + public int fn61(int arg) { + return 61 * arg; + } + + public String fn62(String arg) { + return "62" + arg; + } + + public int fn71(int arg) { + return 71 * arg; + } + + public String fn72(String arg) { + return "72" + arg; + } + + public int fn73() { + return 73; + } + + private double attribute1 = 0.0; + private double attribute3 = 0.0; + }; + } + + private static final class CheckFailed extends Exception { + CheckFailed(String message) { + super(message); + } + } + + private static void checkEqual(int value, int argument) + throws CheckFailed + { + if (argument != value) { + throw new CheckFailed(value + " != " + argument); + } + } + + private static void checkEqual(double value, double argument) + throws CheckFailed + { + if (argument != value) { + throw new CheckFailed(value + " != " + argument); + } + } + + private static void checkEqual(String value, String argument) + throws CheckFailed + { + if (!argument.equals(value)) { + throw new CheckFailed(value + " != " + argument); + } + } + + public String testMulti(XMulti multi) { + try { + checkEqual(0.0, multi.getatt1()); + multi.setatt1(0.1); + checkEqual(0.1, multi.getatt1()); + checkEqual(11 * 1, multi.fn11(1)); + checkEqual("12" + "abc", multi.fn12("abc")); + checkEqual(21 * 2, multi.fn21(2)); + checkEqual("22" + "de", multi.fn22("de")); + checkEqual(0.0, multi.getatt3()); + multi.setatt3(0.3); + checkEqual(0.3, multi.getatt3()); + checkEqual(31 * 3, multi.fn31(3)); + checkEqual("32" + "f", multi.fn32("f")); + checkEqual(33, multi.fn33()); + checkEqual(41 * 4, multi.fn41(4)); + checkEqual(61 * 6, multi.fn61(6)); + checkEqual("62" + "", multi.fn62("")); + checkEqual(71 * 7, multi.fn71(7)); + checkEqual("72" + "g", multi.fn72("g")); + checkEqual(73, multi.fn73()); + } catch (CheckFailed f) { + return f.getMessage(); + } + return ""; + } + + // 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); + } + + private void dothrow( com.sun.star.uno.RuntimeException t ) + throws com.sun.star.uno.RuntimeException + { + throw t; + } + public int getRuntimeException() + throws com.sun.star.uno.RuntimeException + { + try + { + dothrow( new com.sun.star.uno.RuntimeException( + _string, _xInterface ) ); + return 0; // dummy + } + catch (com.sun.star.uno.RuntimeException t) + { + throw t; + } + } + + 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(); + } + + //XBridgeTest2 + public boolean[] setSequenceBool( /*IN*/boolean[] aSeq ) + { + arBool = aSeq; + return aSeq; + } + public char[] setSequenceChar( /*IN*/char[] aSeq ) + { + arChar = aSeq; + return aSeq; + } + public byte[] setSequenceByte( /*IN*/byte[] aSeq ) + { + arByte = aSeq; + return aSeq; + } + public short[] setSequenceShort( /*IN*/short[] aSeq ) + { + arShort = aSeq; + return aSeq; + } + public short[] setSequenceUShort( /*IN*/short[] aSeq ) + { + arUShort = aSeq; + return aSeq; + } + public int[] setSequenceLong( /*IN*/int[] aSeq ) + { + arLong = aSeq; + return aSeq; + } + public int[] setSequenceULong( /*IN*/int[] aSeq ) + { + arULong = aSeq; + return aSeq; + } + public long[] setSequenceHyper( /*IN*/long[] aSeq ) + { + arHyper = aSeq; + return aSeq; + } + public long[] setSequenceUHyper( /*IN*/long[] aSeq ) + { + arUHyper = aSeq; + return aSeq; + } + public float[] setSequenceFloat( /*IN*/float[] aSeq ) + { + arFloat = aSeq; + return aSeq; + } + public double[] setSequenceDouble( /*IN*/double[] aSeq ) + { + arDouble = aSeq; + return aSeq; + } + public TestEnum[] setSequenceEnum( /*IN*/TestEnum[] aSeq ) + { + arEnum = aSeq; + return aSeq; + } + public String[] setSequenceString( /*IN*/String[] aSeq ) + { + arString = aSeq; + return aSeq; + } + public java.lang.Object[] setSequenceXInterface( /*IN*/java.lang.Object[] aSeq ) + { + arObject = aSeq; + return aSeq; + } + public java.lang.Object[] setSequenceAny( /*IN*/java.lang.Object[] aSeq ) + { + arAny = aSeq; + return aSeq; + } + public TestElement[] setSequenceStruct( /*IN*/TestElement[] aSeq ) + { + _testElements = aSeq; + return aSeq; + } + public int[][] setDim2( /*IN*/int[][] aSeq ) + { + arLong2 = aSeq; + return aSeq; + } + public int[][][] setDim3( /*IN*/int[][][] aSeq ) + { + arLong3 = aSeq; + return aSeq; + } + public void setSequencesInOut( /*INOUT*/boolean[][] aSeqBoolean, + /*INOUT*/char[][] aSeqChar, /*INOUT*/byte[][] aSeqByte, + /*INOUT*/short[][] aSeqShort, /*INOUT*/short[][] aSeqUShort, + /*INOUT*/int[][] aSeqLong, /*INOUT*/int[][] aSeqULong, + /*INOUT*/long[][] aSeqHyper, /*INOUT*/long[][] aSeqUHyper, + /*INOUT*/float[][] aSeqFloat, /*INOUT*/double[][] aSeqDouble, + /*INOUT*/TestEnum[][] aSeqEnum, /*INOUT*/String[][] aSeqString, + /*INOUT*/java.lang.Object[][] aSeqXInterface, + /*INOUT*/java.lang.Object[][] aSeqAny, + /*INOUT*/int[][][] aSeqDim2, /*INOUT*/int[][][][] aSeqDim3 ) + { + arBool = aSeqBoolean[0]; + arChar = aSeqChar[0]; + arByte = aSeqByte[0]; + arShort = aSeqShort[0]; + arUShort = aSeqUShort[0]; + arLong = aSeqLong[0]; + arULong = aSeqULong[0]; + arFloat = aSeqFloat[0]; + arDouble = aSeqDouble[0]; + arEnum = aSeqEnum[0]; + arString = aSeqString[0]; + arObject = aSeqXInterface[0]; + arAny = aSeqAny[0]; + arLong2 = aSeqDim2[0]; + arLong3 = aSeqDim3[0]; + } + public void setSequencesOut( /*OUT*/boolean[][] aSeqBoolean, /*OUT*/char[][] aSeqChar, + /*OUT*/byte[][] aSeqByte, /*OUT*/short[][] aSeqShort, + /*OUT*/short[][] aSeqUShort, /*OUT*/int[][] aSeqLong, + /*OUT*/int[][] aSeqULong, /*OUT*/long[][] aSeqHyper, + /*OUT*/long[][] aSeqUHyper, /*OUT*/float[][] aSeqFloat, + /*OUT*/double[][] aSeqDouble, /*OUT*/TestEnum[][] aSeqEnum, + /*OUT*/String[][] aSeqString, + /*OUT*/java.lang.Object[][] aSeqXInterface, + /*OUT*/java.lang.Object[][] aSeqAny, /*OUT*/int[][][] aSeqDim2, + /*OUT*/int[][][][] aSeqDim3 ) + { + aSeqBoolean[0] = arBool; + aSeqChar[0] = arChar; + aSeqByte[0] = arByte; + aSeqShort[0] = arShort; + aSeqUShort[0] = arUShort; + aSeqLong[0] = arLong; + aSeqULong[0] = arULong; + aSeqHyper[0] = arHyper; + aSeqUHyper[0] = arUHyper; + aSeqFloat[0] = arFloat; + aSeqDouble[0] = arDouble; + aSeqEnum[0] = arEnum; + aSeqString[0] = arString; + aSeqXInterface[0] = arObject; + aSeqAny[0] = arAny; + aSeqDim2[0] = arLong2; + aSeqDim3[0] = arLong3; + } + + public void testConstructorsService(XComponentContext context) + throws BadConstructorArguments + { + Constructors.create1(context, + true, + Byte.MIN_VALUE, + Short.MIN_VALUE, + (short) -1, + Integer.MIN_VALUE, + -1, + Long.MIN_VALUE, + -1L, + 0.123f, + 0.456, + 'X', + "test", + Type.ANY, + new Any(Type.BOOLEAN, Boolean.TRUE), + new boolean[] { true }, + new byte[] { Byte.MIN_VALUE }, + new short[] { Short.MIN_VALUE }, + new short[] { (short) -1 }, + new int[] { Integer.MIN_VALUE }, + new int[] { -1 }, + new long[] { Long.MIN_VALUE }, + new long[] { -1L }, + new float[] { 0.123f }, + new double[] { 0.456 }, + new char[] { 'X' }, + new String[] { "test" }, + new Type[] { Type.ANY }, + new Boolean[] { Boolean.TRUE }, + new boolean[][] { new boolean[] { true } }, + new Object[][] { + new Object[] { new Any(Type.BOOLEAN, Boolean.TRUE) } }, + new TestEnum[] { TestEnum.TWO }, + new TestStruct[] { new TestStruct(10) }, + new TestPolyStruct[] { new TestPolyStruct(Boolean.TRUE) }, + new TestPolyStruct[] { + new TestPolyStruct(new Any(Type.BOOLEAN, Boolean.TRUE)) }, + new Object[] { null }, + TestEnum.TWO, + new TestStruct(10), + new TestPolyStruct(Boolean.TRUE), + new TestPolyStruct(new Any(Type.BOOLEAN, Boolean.TRUE)), + null); + Constructors.create2(context, new Object[] { + Boolean.TRUE, + new Byte(Byte.MIN_VALUE), + new Short(Short.MIN_VALUE), + new Any(Type.UNSIGNED_SHORT, new Short((short) -1)), + new Integer(Integer.MIN_VALUE), + new Any(Type.UNSIGNED_LONG, new Integer(-1)), + new Long(Long.MIN_VALUE), + new Any(Type.UNSIGNED_HYPER, new Long(-1L)), + new Float(0.123f), + new Double(0.456), + new Character('X'), + "test", + Type.ANY, + new Any(Type.BOOLEAN, Boolean.TRUE), + new boolean[] { true }, + new byte[] { Byte.MIN_VALUE }, + new short[] { Short.MIN_VALUE }, + new Any( + new Type("[]unsigned short"), new short[] { (short) -1 }), + new int[] { Integer.MIN_VALUE }, + new Any(new Type("[]unsigned long"), new int[] { -1 }), + new long[] { Long.MIN_VALUE }, + new Any(new Type("[]unsigned hyper"), new long[] { -1L }), + new float[] { 0.123f }, + new double[] { 0.456 }, + new char[] { 'X' }, + new String[] { "test" }, + new Type[] { Type.ANY }, + new Any(new Type("[]any"), new Boolean[] { Boolean.TRUE }), + new boolean[][] { new boolean[] { true } }, + new Object[][] { + new Object[] { new Any(Type.BOOLEAN, Boolean.TRUE) } }, + new TestEnum[] { TestEnum.TWO }, + new TestStruct[] { new TestStruct(10) }, + new Any( + new Type( + "[]test.testtools.bridgetest.TestPolyStruct<boolean>"), + new TestPolyStruct[] { new TestPolyStruct(Boolean.TRUE) }), + new Any( + new Type("[]test.testtools.bridgetest.TestPolyStruct<any>"), + new TestPolyStruct[] { + new TestPolyStruct(new Any(Type.BOOLEAN, Boolean.TRUE)) + }), + new XInterface[] { null }, + TestEnum.TWO, + new TestStruct(10), + new Any( + new Type( + "test.testtools.bridgetest.TestPolyStruct<boolean>"), + new TestPolyStruct(Boolean.TRUE)), + new Any( + new Type("test.testtools.bridgetest.TestPolyStruct<any>"), + new TestPolyStruct(new Any(Type.BOOLEAN, Boolean.TRUE))), + null }); + Constructors2.create1( + context, + new TestPolyStruct(Type.LONG), + new TestPolyStruct(new Any(Type.BOOLEAN, Boolean.TRUE)), + new TestPolyStruct(new Boolean(true)), + new TestPolyStruct(new Byte(Byte.MIN_VALUE)), + new TestPolyStruct(new Short(Short.MIN_VALUE)), + new TestPolyStruct(new Integer(Integer.MIN_VALUE)), + new TestPolyStruct(new Long(Long.MIN_VALUE)), + new TestPolyStruct(new Character('X')), + new TestPolyStruct("test"), + new TestPolyStruct(new Float(0.123f)), + new TestPolyStruct(new Double(0.456)), + new TestPolyStruct(new com.sun.star.lib.uno.helper.ComponentBase()), + new TestPolyStruct(new com.sun.star.lib.uno.helper.ComponentBase()), + new TestPolyStruct(TestEnum.TWO), + new TestPolyStruct(new TestPolyStruct2(new Character('X'), + new Any(Type.BOOLEAN, Boolean.TRUE))), + new TestPolyStruct(new TestPolyStruct2(new TestPolyStruct2( + new Character('X'), new Any(Type.BOOLEAN, Boolean.TRUE)), "test")), + new TestPolyStruct2("test", new TestPolyStruct2(new Character('X'), + new TestPolyStruct(new Any(Type.BOOLEAN, Boolean.TRUE)))), + new TestPolyStruct2( new TestPolyStruct2(new Character('X'), + new Any(Type.BOOLEAN, Boolean.TRUE)), new TestPolyStruct(new Character('X'))), + new TestPolyStruct(new Type[] { Type.LONG}), + new TestPolyStruct(new Any[] { new Any(Type.BOOLEAN, Boolean.TRUE) }), + new TestPolyStruct(new boolean[] {true}), + new TestPolyStruct(new byte[] {Byte.MIN_VALUE}), + new TestPolyStruct(new short[] {Short.MIN_VALUE}), + new TestPolyStruct(new int[] {Integer.MIN_VALUE}), + new TestPolyStruct(new long[] {Long.MIN_VALUE}), + new TestPolyStruct(new char[] {'X'}), + new TestPolyStruct(new String[] {"test"}), + new TestPolyStruct(new float[] {0.123f}), + new TestPolyStruct(new double[] {0.456d}), + new TestPolyStruct(new Object[] {new com.sun.star.lib.uno.helper.ComponentBase()}), + new TestPolyStruct(new com.sun.star.lang.XComponent[] {new com.sun.star.lib.uno.helper.ComponentBase()}), + new TestPolyStruct(new TestEnum[] {TestEnum.TWO}), + new TestPolyStruct(new TestPolyStruct2[] {new TestPolyStruct2( + new Character('X'), new Any[] {new Any(Type.BOOLEAN, Boolean.TRUE)})}), + new TestPolyStruct(new TestPolyStruct2[] {new TestPolyStruct2( + new TestPolyStruct(new Character('X')), new Any[] {new Any(Type.BOOLEAN, Boolean.TRUE)})}), + new TestPolyStruct(new int[][] { new int[] {Integer.MIN_VALUE} }), + new TestPolyStruct[]{ new TestPolyStruct(new Integer(Integer.MIN_VALUE))}, + new TestPolyStruct[]{new TestPolyStruct(new TestPolyStruct2( + new Character('X'), new Any(Type.BOOLEAN, Boolean.TRUE)))}, + new TestPolyStruct[]{new TestPolyStruct(new TestPolyStruct2( + new TestPolyStruct2(new Character('X'), new Any(Type.BOOLEAN, Boolean.TRUE)), "test"))}, + new TestPolyStruct2[]{new TestPolyStruct2("test", new TestPolyStruct2( + new Character('X'), new TestPolyStruct(new Any(Type.BOOLEAN, Boolean.TRUE))))}, + new TestPolyStruct2[]{new TestPolyStruct2(new TestPolyStruct2(new Character('X'), new Any( + Type.BOOLEAN, Boolean.TRUE)),new TestPolyStruct(new Character('X')))}, + new TestPolyStruct[][]{new TestPolyStruct[]{new TestPolyStruct(new Character('X'))}}, + new TestPolyStruct[][]{new TestPolyStruct[]{ + new TestPolyStruct(new TestPolyStruct2(new Character('X'), new Any(Type.BOOLEAN, Boolean.TRUE)))}}, + new TestPolyStruct[][]{new TestPolyStruct[] {new TestPolyStruct(new TestPolyStruct2( + new TestPolyStruct2(new Character('X'),new Any(Type.BOOLEAN, Boolean.TRUE)), "test"))}}, + new TestPolyStruct2[][]{new TestPolyStruct2[]{new TestPolyStruct2( + "test", new TestPolyStruct2(new Character('X'),new TestPolyStruct(new Any(Type.BOOLEAN, Boolean.TRUE))))}}, + new TestPolyStruct2[][]{new TestPolyStruct2[]{new TestPolyStruct2( + new TestPolyStruct2(new Character('X'),new Any(Type.BOOLEAN, Boolean.TRUE)), + new TestPolyStruct(new Character('X')))}}); + } + + public XCurrentContextChecker getCurrentContextChecker() { + return new CurrentContextChecker(); + } + } + + /** + * 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/TestComponentMain.java b/testtools/com/sun/star/comp/bridge/TestComponentMain.java new file mode 100644 index 000000000000..805bb1b68281 --- /dev/null +++ b/testtools/com/sun/star/comp/bridge/TestComponentMain.java @@ -0,0 +1,158 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +package com.sun.star.comp.bridge; + +import com.sun.star.bridge.XBridge; +import com.sun.star.bridge.XBridgeFactory; +import com.sun.star.bridge.XInstanceProvider; + +import com.sun.star.uno.XComponentContext; +import com.sun.star.lang.EventObject; +import com.sun.star.lang.XComponent; +import com.sun.star.lang.XEventListener; +import com.sun.star.lang.XMultiComponentFactory; +import com.sun.star.lang.XMultiServiceFactory; +import com.sun.star.container.XSet; + +import com.sun.star.connection.Acceptor; +import com.sun.star.connection.XAcceptor; +import com.sun.star.connection.XConnection; + +import com.sun.star.uno.UnoRuntime; + +public class TestComponentMain +{ + + static class InstanceProvider implements XInstanceProvider { + XComponentContext ctx; + + public InstanceProvider( XComponentContext ctx ) + { + this.ctx = ctx; + } + + public Object getInstance( /*IN*/String sInstanceName ) + throws com.sun.star.container.NoSuchElementException, com.sun.star.uno.RuntimeException + { + Object o =null; + try + { + o = ctx.getServiceManager().createInstanceWithContext( + "com.sun.star.comp.bridge.TestComponent$_TestObject" , ctx ); + } + catch( com.sun.star.uno.Exception e ) + { + System.out.println( "error during instantiation" + e ); + } + return o; + } + } + + static public void main(String args[]) throws Exception, com.sun.star.uno.Exception { + if(args.length != 2) { + System.err.println("usage : com.sun.star.comp.bridge.TestComponentMain uno:connection;protocol;objectName singleaccept"); + System.exit(-1); + } + + String conDcp = null; + String protDcp = null; + String rootOid = null; + + String dcp = args[0]; + boolean singleaccept = args[1].equals("singleaccept"); + + int index = dcp.indexOf(':'); + String url = dcp.substring(0, index).trim(); + dcp = dcp.substring(index + 1).trim(); + + index = dcp.indexOf(';'); + conDcp = dcp.substring(0, index).trim(); + dcp = dcp.substring(index + 1).trim(); + + index = dcp.indexOf(';'); + protDcp = dcp.substring(0, index).trim(); + dcp = dcp.substring(index + 1).trim(); + + rootOid = dcp.trim().trim(); + + XComponentContext ctx = com.sun.star.comp.helper.Bootstrap.createInitialComponentContext( null ); + XMultiComponentFactory smgr = ctx.getServiceManager(); + XMultiServiceFactory oldsmgr = + UnoRuntime.queryInterface( XMultiServiceFactory.class, smgr ); + + // prepare servicemanager + XSet set = UnoRuntime.queryInterface(XSet.class, smgr); + Object o = com.sun.star.comp.bridge.TestComponent.__getServiceFactory( + "com.sun.star.comp.bridge.TestComponent$_TestObject", oldsmgr,null ); + set.insert(o); + + XAcceptor xAcceptor = Acceptor.create(ctx); + + while( true ) + { + System.err.println("waiting for connect..."); + + XConnection xConnection = xAcceptor.accept(conDcp); + + XBridgeFactory xBridgeFactory = UnoRuntime.queryInterface( + XBridgeFactory.class, + smgr.createInstanceWithContext("com.sun.star.bridge.BridgeFactory",ctx)); + + XBridge xBridge = xBridgeFactory.createBridge( + "", protDcp, xConnection, new InstanceProvider(ctx)); + + if (singleaccept) { + Listener listener = new Listener(); + UnoRuntime.queryInterface(XComponent.class, xBridge). + addEventListener(listener); + listener.await(); + break; + } + } + + } + + private static final class Listener implements XEventListener { + public synchronized void disposing(EventObject source) { + done = true; + notifyAll(); + } + + public synchronized void await() { + while (!done) { + try { + wait(); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + throw new RuntimeException(e); + } + } + } + + private boolean done = false; + } +} 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..6f0129ac7b48 --- /dev/null +++ b/testtools/com/sun/star/comp/bridge/makefile.mk @@ -0,0 +1,61 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2000, 2010 Oracle and/or its affiliates. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org 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 version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* + +PRJ=..$/..$/..$/..$/.. +PRJNAME=testtools +PACKAGE=com$/sun$/star$/comp$/bridge +TARGET=com_sun_star_comp_bridge + + +# --- Settings ----------------------------------------------------- + +.INCLUDE : settings.mk + +# ------------------------------------------------------------------ + + +JARFILES = ridl.jar jurt.jar juh.jar + + +JAVACLASSFILES= \ + $(CLASSDIR)$/$(PACKAGE)$/CurrentContextChecker.class \ + $(CLASSDIR)$/$(PACKAGE)$/TestComponent.class \ + $(CLASSDIR)$/$(PACKAGE)$/TestComponentMain.class + +JAVAFILES = $(subst,$(CLASSDIR)$/$(PACKAGE)$/, $(subst,.class,.java $(JAVACLASSFILES))) + + +JARCLASSDIRS = $(PACKAGE) test$/testtools$/bridgetest +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/inc/makefile.mk b/testtools/inc/makefile.mk new file mode 100644 index 000000000000..636cf5288618 --- /dev/null +++ b/testtools/inc/makefile.mk @@ -0,0 +1,47 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2000, 2010 Oracle and/or its affiliates. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org 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 version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* +PRJ=.. + +PRJNAME=testtools +TARGET=inc + +# --- Settings ----------------------------------------------------- + +.INCLUDE : settings.mk + +# --- Files -------------------------------------------------------- +# --- Targets ------------------------------------------------------- + +.INCLUDE : target.mk + +.IF "$(ENABLE_PCH)"!="" +ALLTAR : \ + $(SLO)$/precompiled.pch \ + $(SLO)$/precompiled_ex.pch + +.ENDIF # "$(ENABLE_PCH)"!="" + diff --git a/testtools/inc/pch/precompiled_testtools.cxx b/testtools/inc/pch/precompiled_testtools.cxx new file mode 100644 index 000000000000..53af728534a9 --- /dev/null +++ b/testtools/inc/pch/precompiled_testtools.cxx @@ -0,0 +1,29 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include "precompiled_testtools.hxx" + diff --git a/testtools/inc/pch/precompiled_testtools.hxx b/testtools/inc/pch/precompiled_testtools.hxx new file mode 100644 index 000000000000..a6ac8b6591b7 --- /dev/null +++ b/testtools/inc/pch/precompiled_testtools.hxx @@ -0,0 +1,32 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): Generated on 2006-09-01 17:50:13.873382 + +#ifdef PRECOMPILED_HEADERS +#endif + diff --git a/testtools/prj/build.lst b/testtools/prj/build.lst new file mode 100644 index 000000000000..24dce4119821 --- /dev/null +++ b/testtools/prj/build.lst @@ -0,0 +1,8 @@ +tt testtools : cpputools io remotebridges stoc javaunohelper pyuno cli_ure offapi NULL +tt testtools\inc nmake - all tt_inc NULL +tt testtools\source\bridgetest nmake - all tt_bridgetest tt_bridgetest_idl tt_javaTestObjs tt_inc NULL +tt testtools\source\bridgetest\cli nmake - w,vc7 tt_cli tt_bridgetest tt_bridgetest_idl tt_inc NULL +tt testtools\source\bridgetest\idl nmake - all tt_bridgetest_idl tt_inc NULL +tt testtools\com\sun\star\comp\bridge nmake - all tt_javaTestObjs tt_bridgetest_idl tt_inc NULL +tt testtools\source\bridgetest\pyuno nmake - all tt_pyuno tt_bridgetest tt_inc NULL +tt testtools\source\cliversioning nmake - all tt_cliver NULL diff --git a/testtools/prj/d.lst b/testtools/prj/d.lst new file mode 100644 index 000000000000..e69de29bb2d1 --- /dev/null +++ b/testtools/prj/d.lst diff --git a/testtools/qa/cli/CLITest.java b/testtools/qa/cli/CLITest.java new file mode 100644 index 000000000000..68cc5dbd40fb --- /dev/null +++ b/testtools/qa/cli/CLITest.java @@ -0,0 +1,111 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +package clitest; + + +import complexlib.ComplexTestCase; +import java.io.*; + +public class CLITest extends ComplexTestCase +{ + public String[] getTestMethodNames() + { + // TODO think about trigger of sub-tests from outside + return new String[] + { + "runCLITests" + }; + } + + public void runCLITests() + { + try + { + String testProgram = System.getProperty("cli_test", ""); + if (testProgram.length() == 0) + failed("Check the make file. Java must be called with -Dcli_test=pathtoexe"); + + String arg1 = System.getProperty("cli_test_arg", ""); + if (arg1.length() == 0) + failed("Check the make file. Java must be called with " + + "-Dcli_test_arg=path_to_bootstrap_ini"); + String[] cmdarray = new String[] {testProgram, arg1}; + + Process proc = null; + Reader outReader; + Reader errReader; + try{ + + proc = Runtime.getRuntime().exec(cmdarray); + outReader = new Reader(proc.getInputStream()); + errReader = new Reader(proc.getErrorStream()); + + + } + catch(Exception e) + { + System.out.println("\n ###" + e.getMessage() + "\n"); + + } +// System.out.println("### waiting for " + testProgram); + proc.waitFor(); +// System.out.println("### " + testProgram + " finished"); + int retVal = proc.exitValue(); + if (retVal != 0) + failed("CLI test failed."); + } catch( java.lang.Exception e) + { + failed("Unexpected exception."); + } + + } +} + + +/* This reads reads from an InputStream and discards the data. + */ +class Reader extends Thread +{ + InputStream is; + public Reader(InputStream stream) + { + is = stream; + start(); + } + + public void run() + { + try + { + byte[] buf = new byte[1024]; + while (-1 != is.read(buf)); + } + catch (java.io.IOException exc) + { + } + } +} diff --git a/testtools/qa/cli/makefile.mk b/testtools/qa/cli/makefile.mk new file mode 100644 index 000000000000..7813b9b321fe --- /dev/null +++ b/testtools/qa/cli/makefile.mk @@ -0,0 +1,82 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2000, 2010 Oracle and/or its affiliates. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org 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 version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* + +PRJ := ..$/.. +PRJNAME := testtools +TARGET := test_cli +PACKAGE = clitest + +.INCLUDE: settings.mk + +#----- compile .java files ----------------------------------------- + +JARFILES = ridl.jar unoil.jar jurt.jar juh.jar java_uno.jar OOoRunner.jar +JAVAFILES = CLITest.java +JAVACLASSFILES = $(foreach,i,$(JAVAFILES) $(CLASSDIR)$/$(PACKAGE)$/$(i:b).class) + +#----- make a jar from compiled files ------------------------------ + +MAXLINELENGTH = 100000 + +JARCLASSDIRS = $(PACKAGE) +JARTARGET = $(TARGET).jar +JARCOMPRESS = TRUE + +ALLTAR: + +EXETARGET = $(BIN)$/cli_bridgetest_inprocess.exe +EXEARG_WIN= $(BIN)$/cli_bridgetest_inprocess.ini + +EXEARG= $(strip $(subst,$/,/ $(EXEARG_WIN))) + +.IF "$(depend)" == "" +ALL: ALLTAR +.ELSE +ALL: ALLDEP +.ENDIF + +.INCLUDE: target.mk + +# --- Parameters for the test -------------------------------------- + +# test base is java complex +CT_TESTBASE = -TestBase java_complex + +# test looks something like the.full.package.TestName +CT_TEST = -o $(PACKAGE:s\$/\.\).$(JAVAFILES:b) + +# start the runner application +CT_APP = org.openoffice.Runner + +CT_NOOFFICE = -NoOffice +# --- Targets ------------------------------------------------------ + +RUN: +.IF "$(GUI)"=="WNT" + java -cp $(CLASSPATH) -Dcli_test=$(EXETARGET) -Dcli_test_arg=$(EXEARG) $(CT_APP) $(CT_NOOFFICE) $(CT_TESTBASE) $(CT_TEST) +.ENDIF +run: RUN diff --git a/testtools/qa/cli/readme.txt b/testtools/qa/cli/readme.txt new file mode 100644 index 000000000000..d0a55beae98b --- /dev/null +++ b/testtools/qa/cli/readme.txt @@ -0,0 +1,26 @@ +This test is for Windows only! + +The cli test uses .NET assemblies: +cli_types.dll, +cli_basetypes.dll, +cli_ure.dll, +cli_cppuhelper.dll. + + +When an office is properly installed then these assemblies can be found in the +global assebly cache (GAC), for example in c:\windows\assembly. + +When the test is run then the assemblies are used from the GAC. That is +one has to make sure that one has the respective office installed. + +The test can also be run without an installed office. Then the assemblies are used +which reside next to the executable. The testtools project copies the assemblies from +the build environment into the wntmscixx\bin folder. + +However, if for some reason an assembly remains in the GAC than it is used no matter +what. + + +The qa test simply executes the cli_bridgetest_inprocess.exe. All console output is decarded. +When the test fails one should directly run that executable. Then one may see the cause +of the failure in the console. diff --git a/testtools/qa/cliversioning/VersionTestCase.java b/testtools/qa/cliversioning/VersionTestCase.java new file mode 100644 index 000000000000..bb897bbff1df --- /dev/null +++ b/testtools/qa/cliversioning/VersionTestCase.java @@ -0,0 +1,106 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +package cliversion; + + +import complexlib.ComplexTestCase; + + +public class VersionTestCase extends ComplexTestCase +{ + public String[] getTestMethodNames() + { + return new String[] + { + "checkVersion" + }; + } + + public void checkVersion() + { + int retVal = 0; + try + { + String testProgram = System.getProperty("cli_test_program"); + if (testProgram == null || testProgram.length() == 0) + failed("Check the make file. Java must be called with -Dcli_ure_test=pathtoexe"); + String unoPath = System.getProperty("path"); + if (unoPath == null || unoPath.length() == 0) + failed("Check the make file. Java must be called with -Duno_path=path_to_ure_bin_folder"); + String sSystemRoot = System.getProperty("SystemRoot"); + if (sSystemRoot == null || sSystemRoot.length() == 0) + failed("Check the make file. Java must be called with -DSystemRoot=%SystemRoot%."); + +// System.out.println("UNO_PATH="+unoPath); + //We need to set the PATH because otherwise it appears that runtests inherits the PATH + //from build environment. Then the bootstrapping fails because the libraries + //are not used from the office. + //.NET 2 requires SystemRoot being set. + String[] arEnv = new String[] { + "PATH=" + unoPath, "SystemRoot=" + sSystemRoot}; + Process proc = null; + + proc = Runtime.getRuntime().exec(testProgram, arEnv); + Reader outReader = new Reader(proc.getInputStream()); + Reader errReader = new Reader(proc.getErrorStream()); + proc.waitFor(); + retVal = proc.exitValue(); + } catch(Exception e) + { + e.printStackTrace(); + System.out.println(e.getMessage()); + failed("Unexpected exception."); + } + if (retVal != 0) + failed("Tests for library versioning failed."); + } +} + + +/* This reads reads from an InputStream and discards the data. + */ +class Reader extends Thread +{ + java.io.InputStream is; + public Reader(java.io.InputStream stream) + { + is = stream; + start(); + } + + public void run() + { + try + { + byte[] buf = new byte[1024]; + while (-1 != is.read(buf)); + } + catch (java.io.IOException exc) + { + } + } +} diff --git a/testtools/qa/cliversioning/makefile.mk b/testtools/qa/cliversioning/makefile.mk new file mode 100644 index 000000000000..c4708f2d8337 --- /dev/null +++ b/testtools/qa/cliversioning/makefile.mk @@ -0,0 +1,93 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2000, 2010 Oracle and/or its affiliates. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org 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 version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* + + +# Builds the SpreadSheet examples of the Developers Guide. + +PRJ = ..$/.. +PRJNAME = cli_ure +TARGET := qa_test_climaker +PACKAGE = cliversion + +.INCLUDE: settings.mk + +#----- compile .java files ----------------------------------------- + +JARFILES = ridl.jar unoil.jar jurt.jar juh.jar java_uno.jar OOoRunner.jar +JAVAFILES = VersionTestCase.java +JAVACLASSFILES = $(foreach,i,$(JAVAFILES) $(CLASSDIR)$/$(PACKAGE)$/$(i:b).class) + +#----- make a jar from compiled files ------------------------------ + +MAXLINELENGTH = 100000 + +JARCLASSDIRS = $(PACKAGE) +JARTARGET = $(TARGET).jar +JARCOMPRESS = TRUE + + +.INCLUDE: target.mk + +ALLTAR : \ + echo + +echo : + @echo . + @echo ########################### N O T E ###################################### + @echo . + @echo To run the test you have to provide the path to the office location. It must + @echo contain the ure (d:\myOffice\OpenOffice.org\URE). + @echo Also an office must be installed with full system integration. + @echo Example: + @echo dmake run office="d:\myOffice" + @echo . + @echo To build a test library with a particular name run. The names must start with "version". + @echo For example: + @echo "dmake name=version_10_10_10.dll" + @echo ########################### N O T E ###################################### + @echo . + @echo . + +# --- Parameters for the test -------------------------------------- + +# test base is java complex +CT_TESTBASE = -TestBase java_complex + +# test looks something like the.full.package.TestName +CT_TEST = -o $(PACKAGE:s\$/\.\).$(JAVAFILES:b) + +# start the runner application +CT_APP = org.openoffice.Runner + +CT_NOOFFICE = -NoOffice +# --- Targets ------------------------------------------------------ + +RUN: $(MISC)$/copyassemblies.done + java -cp $(CLASSPATH) -DSystemRoot=$(SystemRoot) -Dcli_test_program=$(BIN)$/runtests.exe -Dpath="$(office)"\OpenOffice.org\URE\bin $(CT_APP) $(CT_NOOFFICE) $(CT_TESTBASE) $(CT_TEST) + +run: RUN + diff --git a/testtools/readme.txt b/testtools/readme.txt new file mode 100644 index 000000000000..d418da006603 --- /dev/null +++ b/testtools/readme.txt @@ -0,0 +1,34 @@ +How to check compatibility between compilers +============================================ + +Since the interfaces used in the cpp bridgetest are not changed often +one can just build the cppobj.uno.dll and the constructors.uno.dll +(testtools/source/bridgetest) in an +old environment and then use them in the new environment. That is the files +are copied into the testtools/wntmsciXX.pro folder which corresponds to the +new environment. + +On Windows this test will typically fail because the tests use the +cppu::getCaughtException function, which only works when all libs are build +using the same runtime. + +This part of the test can switched off. To do this go into the +testtools/source/bridgetest folder and call +dmake compcheck=1 + +This will add a new compiler define (-DCOMPCHECK) and will be used in the +bridgetest.cxx to switch off the code which uses the getCaughtException function. +However, there is still a test which causes the test component to throw +and IllegalArgumentException. This still works. + + +Using source/bridgetest for stress testing +========================================== + +Start a modified bridgetest_server (with the final "--singleaccept" argument +removed from the uno executable call) or a modified bridgetest_javaserver (with +the final "singleaccept" argument replaced with "multi" in the java executable +call), then start a modified bridgetest_client (with a final "stress" argument +added to the uno executable call). The client will continuously establish +connections to the server which are immediately destroyed again. The test will +run forever, unless an error occurs. diff --git a/testtools/source/bridgetest/bridgetest.cxx b/testtools/source/bridgetest/bridgetest.cxx new file mode 100644 index 000000000000..46204319966d --- /dev/null +++ b/testtools/source/bridgetest/bridgetest.cxx @@ -0,0 +1,1369 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_testtools.hxx" + +#include <stdio.h> +#include <string.h> +#include <osl/diagnose.h> +#include "osl/diagnose.hxx" +#include <osl/time.h> +#include <sal/types.h> +#include "typelib/typedescription.hxx" +#include <uno/dispatcher.hxx> +#include "uno/mapping.hxx" +#include <uno/data.h> +#include "uno/environment.hxx" + +#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/UnoUrlResolver.hpp> +#include <com/sun/star/bridge/XUnoUrlResolver.hpp> +#include "com/sun/star/uno/RuntimeException.hpp" +#include "com/sun/star/uno/Type.hxx" + +#include "test/testtools/bridgetest/BadConstructorArguments.hpp" +#include "test/testtools/bridgetest/TestPolyStruct.hpp" +#include "test/testtools/bridgetest/XBridgeTest.hpp" +#include "test/testtools/bridgetest/XBridgeTest2.hpp" +#include "test/testtools/bridgetest/XMulti.hpp" + +#include "currentcontextchecker.hxx" +#include "multi.hxx" + +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 test::testtools::bridgetest; + +#define SERVICENAME "com.sun.star.test.bridge.BridgeTest" +#define IMPLNAME "com.sun.star.comp.bridge.BridgeTest" + +#define OUSTR(x) ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(x) ) +#define STRING_TEST_CONSTANT "\" paco\' chorizo\\\' \"\'" + +namespace bridge_test +{ +template< class T> +Sequence<T> cloneSequence(const Sequence<T>& val); + +//-------------------------------------------------------------------------------------------------- +inline static Sequence< OUString > getSupportedServiceNames() +{ + OUString aName( RTL_CONSTASCII_USTRINGPARAM(SERVICENAME) ); + return Sequence< OUString >( &aName, 1 ); +} + +static bool check( bool b , char const * message ) +{ + if ( ! b ) + fprintf( stderr, "%s failed\n" , message ); + return b; +} + +namespace { + +bool checkEmpty(rtl::OUString const & string, char const * message) { + bool ok = string.getLength() == 0; + if (!ok) { + fprintf( + stderr, "%s failed: %s\n", message, + rtl::OUStringToOString(string, RTL_TEXTENCODING_UTF8).getStr()); + } + return ok; +} + +} + +//================================================================================================== +class TestBridgeImpl : protected osl::DebugBase<TestBridgeImpl>, + public WeakImplHelper2< XMain, XServiceInfo > +{ + Reference< XComponentContext > m_xContext; + +public: + TestBridgeImpl( const Reference< XComponentContext > & xContext ) + : m_xContext( xContext ) + {} + virtual ~TestBridgeImpl() + { + } + + // 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 ) +{ + check( rData1.Bool == rData2.Bool, "### bool does not match!" ); + check( rData1.Char == rData2.Char, "### char does not match!" ); + check( rData1.Byte == rData2.Byte, "### byte does not match!" ); + check( rData1.Short == rData2.Short, "### short does not match!" ); + check( rData1.UShort == rData2.UShort, "### unsigned short does not match!" ); + check( rData1.Long == rData2.Long, "### long does not match!" ); + check( rData1.ULong == rData2.ULong, "### unsigned long does not match!" ); + check( rData1.Hyper == rData2.Hyper, "### hyper does not match!" ); + check( rData1.UHyper == rData2.UHyper, "### unsigned hyper does not match!" ); + check( rData1.Float == rData2.Float, "### float does not match!" ); + check( rData1.Double == rData2.Double, "### double does not match!" ); + check( rData1.Enum == rData2.Enum, "### enum does not match!" ); + check( rData1.String == rData2.String, "### string does not match!" ); + check( rData1.Interface == rData2.Interface, "### interface does not match!" ); + check( 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] )) + { + check( 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; +} + +namespace { + +template < typename T > +bool testAny( + T const & value, Reference< XBridgeTest > const & xLBT, + char const * typeName = 0) +{ + Any any; + any <<= value; + Any any2 = xLBT->transportAny(any); + bool success = true; + if (any != any2) { + fprintf( + stderr, "any is different after roundtrip: in %s, out %s\n", + OUStringToOString( + any.getValueType().getTypeName(), + RTL_TEXTENCODING_ASCII_US).getStr(), + OUStringToOString( + any2.getValueType().getTypeName(), + RTL_TEXTENCODING_ASCII_US).getStr()); + success = false; + } + if (typeName != 0 + && !any2.getValueType().getTypeName().equalsAscii(typeName)) + { + fprintf( + stderr, "any has wrong type after roundtrip: %s instead of %s\n", + OUStringToOString( + any2.getValueType().getTypeName(), + RTL_TEXTENCODING_ASCII_US).getStr(), + typeName); + success = false; + } + return success; +} + +} + +static sal_Bool performAnyTest( const Reference< XBridgeTest > &xLBT, const TestData &data) +{ + bool bReturn = 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.ULong,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; + bReturn &= testAny( + TestPolyStruct< sal_Unicode >(' '), xLBT, + "test.testtools.bridgetest.TestPolyStruct<char>"); + + 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< 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 performQueryForUnknownType( const Reference< XBridgeTest > & xLBT ) +{ + sal_Bool bRet = sal_True; + // use this when you want to test querying for unknown types + // currently (not supported by the java remote bridge ) + { + // test queryInterface for an unknown type + typelib_TypeDescriptionReference *pTypeRef = 0; + OUString aName( RTL_CONSTASCII_USTRINGPARAM( "foo.MyInterface" ) ); + typelib_typedescriptionreference_new( + &pTypeRef, typelib_TypeClass_INTERFACE, aName.pData); + try + { + Any a = xLBT->queryInterface( Type( pTypeRef ) ); + bRet = check( a == Any( ), "got an foo.MyInterface, but didn't expect to get one" ); + } + catch( com::sun::star::uno::RuntimeException & ) + { + fprintf( + stderr, + "tried to query for an interface reference of an unknown type " + "but got a runtime exception. This should work for native bridges " + "but isn't implemented for Java remote bridge\n" + "Note: All subsequent tests may fail now as the remote bridge is broken\n" + "QueryForUnknownType" ); + } + typelib_typedescriptionreference_release( pTypeRef ); + } + return bRet; +} + +class MyClass : public osl::DebugBase<MyClass>, public OWeakObject +{ +public: + MyClass(); + virtual ~MyClass(); + virtual void SAL_CALL acquire() throw (); + virtual void SAL_CALL release() throw (); +}; + +//______________________________________________________________________________ +MyClass::MyClass() +{ +} +//______________________________________________________________________________ +MyClass::~MyClass() +{ +} +//______________________________________________________________________________ +void MyClass::acquire() throw () +{ + OWeakObject::acquire(); +} +//______________________________________________________________________________ +void MyClass::release() throw () +{ + OWeakObject::release(); +} + +//================================================================================================== +static sal_Bool performTest( + const Reference<XComponentContext> & xContext, + const Reference<XBridgeTest > & xLBT, + bool noCurrentContext ) +{ + check( xLBT.is(), "### no test interface!" ); + bool bRet = true; + 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 MyClass ); + + assign( (TestElement &)aData, + sal_True, '@', 17, 0x1234, 0xfedc, 0x12345678, 0xfedcba98, + SAL_CONST_INT64(0x123456789abcdef0), + SAL_CONST_UINT64(0xfedcba9876543210), + (float)17.0815, 3.1415926359, TestEnum_LOLA, + OUSTR(STRING_TEST_CONSTANT), xI, + Any( &xI, ::getCppuType( (const Reference<XInterface > *)0 ) ) ); + + bRet = check( aData.Any == xI, "### unexpected any!" ) && bRet; + bRet = check( !(aData.Any != xI), "### unexpected any!" ) && bRet; + + aData.Sequence.realloc( 2 ); + aData.Sequence[ 0 ] = *(const TestElement *)&aData; + // aData.Sequence[ 1 ] is empty + + // 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.realloc( 2 ); + aSetData.Sequence[ 0 ] = *(const TestElement *)&aSetData; + // aSetData.Sequence[ 1 ] is empty + + 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 ); + + bRet = check( equals( aData, aRet ) && equals( aData, aRet2 ) , "getValues test") && bRet; + + // 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 ); + // check inout sequence order + // => inout sequence parameter was switched by test objects + TestElement temp = aRet.Sequence[ 0 ]; + aRet.Sequence[ 0 ] = aRet.Sequence[ 1 ]; + aRet.Sequence[ 1 ] = temp; + + bRet = check( + equals( aData, aSV2ret ) && equals( aData, aRet2 ), + "getValues2 test") && bRet; + } + { + 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 ); + + bRet = check( equals( aData, aRet ) && equals( aData, aRet2 ) && equals( aData, aGVret ), "getValues test" ) && bRet; + + // 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(); + + bRet = check( equals( aData, aRet ) && equals( aData, aRet2 ) , "struct comparison test") && bRet; + + { + SmallStruct aIn(1, 2); + SmallStruct aOut = xLBT->echoSmallStruct(aIn); + bRet = check( memcmp(&aIn, &aOut, sizeof(SmallStruct)) == 0, "small struct test" ) && bRet; + } + { + MediumStruct aIn(1, 2, 3, 4); + MediumStruct aOut = xLBT->echoMediumStruct(aIn); + bRet = check( memcmp(&aIn, &aOut, sizeof(MediumStruct)) == 0, "medium struct test" ) && bRet; + } + { + BigStruct aIn(1, 2, 3, 4, 5, 6, 7, 8); + BigStruct aOut = xLBT->echoBigStruct(aIn); + bRet = check( memcmp(&aIn, &aOut, sizeof(BigStruct)) == 0, "big struct test" ) && bRet; + } + { + AllFloats aIn(1.1f, 2.2f, 3.3f, 4.4f); + AllFloats aOut = xLBT->echoAllFloats(aIn); + bRet = check( memcmp(&aIn, &aOut, sizeof(AllFloats)) == 0, "all floats struct test" ) && bRet; + } + { + sal_Int32 i2 = xLBT->testPPCAlignment( 0, 0, 0, 0, 0xbeaf ); + bRet = check( i2 == 0xbeaf, "ppc-style alignment test" ) && bRet; + } + + // Test extended attributes that raise exceptions: + try { + xLBT->getRaiseAttr1(); + bRet &= check(false, "getRaiseAttr1 did not throw"); + } catch (RuntimeException &) { + } catch (...) { + bRet &= check(false, "getRaiseAttr1 threw wrong type"); + } + try { + xLBT->setRaiseAttr1(0); + bRet &= check(false, "setRaiseAttr1 did not throw"); + } catch (IllegalArgumentException &) { + } catch (...) { + bRet &= check(false, "setRaiseAttr1 threw wrong type"); + } + try { + xLBT->getRaiseAttr2(); + bRet &= check(false, "getRaiseAttr2 did not throw"); + } catch (IllegalArgumentException &) { + } catch (...) { + bRet &= check(false, "getRaiseAttr2 threw wrong type"); + } + + // Test instantiated polymorphic struct types: + { + bRet &= check( + xLBT->transportPolyBoolean(TestPolyStruct< sal_Bool >(true)).member, + "transportPolyBoolean"); + TestPolyStruct< sal_Int64 > tps1(12345); + xLBT->transportPolyHyper(tps1); + bRet &= check(tps1.member == 12345, "transportPolyHyper"); + Sequence< Any > seq(2); + seq[0] <<= static_cast< sal_uInt32 >(33); + seq[1] <<= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ABC")); + TestPolyStruct< Sequence< Any > > tps2(seq); + TestPolyStruct< Sequence< Any > > tps3; + xLBT->transportPolySequence(tps2, tps3); + bRet &= check( + tps3.member.getLength() == 2, "transportPolySequence, length"); + sal_uInt32 v0 = sal_uInt32(); + tps3.member[0] >>= v0; + bRet &= check(v0 == 33, "transportPolySequence, element 0"); + rtl::OUString v1; + tps3.member[1] >>= v1; + bRet &= check( + v1.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("ABC")), + "transportPolySequence, element 1"); + bRet &= check(xLBT->getNullPolyLong().member == 0, "getNullPolyLong"); + bRet &= check( + xLBT->getNullPolyString().member.getLength() == 0, + "getNullPolyString"); + bRet &= check( + xLBT->getNullPolyType().member == Type(), "getNullPolyType"); + Any nullAny(xLBT->getNullPolyAny().member); + bRet &= check( + (((nullAny.getValueTypeName() + == rtl::OUString( + RTL_CONSTASCII_USTRINGPARAM("com.sun.star.uno.XInterface"))) + && !static_cast< Reference< XInterface > const * >( + nullAny.getValue())->is()) + || nullAny == Any()), + "getNullPolyAny"); + bRet &= check( + xLBT->getNullPolySequence().member.getLength() == 0, + "getNullPolySequence"); + bRet &= check( + xLBT->getNullPolyEnum().member == TestEnum_TEST, "getNullPolyEnum"); + bRet &= check( + xLBT->getNullPolyBadEnum().member == TestBadEnum_M, + "getNullPolyBadEnum"); + bRet &= check( + xLBT->getNullPolyStruct().member.member == 0, "getNullPolyStruct"); + bRet &= check( + !xLBT->getNullPolyInterface().member.is(), "getNullPolyInterface"); + } + + // any test + bRet = check( performAnyTest( xLBT , aData ) , "any test" ) && bRet; + + // sequence of call test + bRet = check( performSequenceOfCallTest( xLBT ) , "sequence of call test" ) && bRet; + + // recursive call test + bRet = check( performRecursiveCallTest( xLBT ) , "recursive test" ) && bRet; + + bRet = (equals( aData, aRet ) && equals( aData, aRet2 )) && bRet ; + + // multiple inheritance test + bRet &= checkEmpty( + testtools::bridgetest::testMulti(xLBT->getMulti()), "remote multi"); + bRet &= checkEmpty( + xLBT->testMulti(new testtools::bridgetest::Multi), "local multi"); + } + + } + { + Reference<XBridgeTest2> xBT2(xLBT, UNO_QUERY); + if ( ! xBT2.is()) + return bRet; + + // perform sequence tests (XBridgeTest2) + // create the sequence which are compared with the results + sal_Bool _arBool[] = {sal_True, sal_False, sal_True}; + sal_Unicode _arChar[] = {0x0065, 0x0066, 0x0067}; + sal_Int8 _arByte[] = { 1, 2, -1 }; + sal_Int16 _arShort[] = { -0x8000, 1, 0x7fff }; + sal_uInt16 _arUShort[] = {0 , 1, 0xffff}; + sal_Int32 _arLong[] = {0x80000000, 1, 0x7fffffff}; + sal_uInt32 _arULong[] = {0, 1, 0xffffffff}; + sal_Int64 _arHyper[] = { + SAL_CONST_INT64(0x8000000000000000), 1, + SAL_CONST_INT64(0x7fffffffffffffff)}; + sal_uInt64 _arUHyper[] = {0, 1, SAL_CONST_UINT64(0xffffffffffffffff)}; + float _arFloat[] = {1.1f, 2.2f, 3.3f}; + double _arDouble[] = {1.11, 2.22, 3.33}; + OUString _arString[] = { + OUString(RTL_CONSTASCII_USTRINGPARAM("String 1")), + OUString(RTL_CONSTASCII_USTRINGPARAM("String 2")), + OUString(RTL_CONSTASCII_USTRINGPARAM("String 3")) + }; + + sal_Bool _aBool = sal_True; + sal_Int32 _aInt = 0xbabebabe; + float _aFloat = 3.14f; + Any _any1(&_aBool, getCppuBooleanType()); + Any _any2(&_aInt, getCppuType((sal_Int32*) 0)); + Any _any3(&_aFloat, getCppuType((float*) 0)); + Any _arAny[] = { _any1, _any2, _any3}; + + Reference<XInterface> _arObj[3]; + _arObj[0] = new OWeakObject(); + _arObj[1] = new OWeakObject(); + _arObj[2] = new OWeakObject(); + + TestEnum _arEnum[] = {TestEnum_ONE, TestEnum_TWO, TestEnum_CHECK}; + + TestElement _arStruct[3]; + assign( _arStruct[0], sal_True, '@', 17, 0x1234, 0xfedc, 0x12345678, 0xfedcba98, + SAL_CONST_INT64(0x123456789abcdef0), + SAL_CONST_UINT64(0xfedcba9876543210), + 17.0815f, 3.1415926359, + TestEnum_LOLA, OUSTR(STRING_TEST_CONSTANT), _arObj[0], + Any( &_arObj[0], ::getCppuType( (const Reference<XInterface > *)0 ) ) ); + assign( _arStruct[1], sal_True, 'A', 17, 0x1234, 0xfedc, 0x12345678, 0xfedcba98, + SAL_CONST_INT64(0x123456789abcdef0), + SAL_CONST_UINT64(0xfedcba9876543210), + 17.0815f, 3.1415926359, + TestEnum_TWO, OUSTR(STRING_TEST_CONSTANT), _arObj[1], + Any( &_arObj[1], ::getCppuType( (const Reference<XInterface > *)0 ) ) ); + assign( _arStruct[2], sal_True, 'B', 17, 0x1234, 0xfedc, 0x12345678, 0xfedcba98, + SAL_CONST_INT64(0x123456789abcdef0), + SAL_CONST_UINT64(0xfedcba9876543210), + 17.0815f, 3.1415926359, + TestEnum_CHECK, OUSTR(STRING_TEST_CONSTANT), _arObj[2], + Any( &_arObj[2], ::getCppuType( (const Reference<XInterface > *)0 ) ) ); + + { + Sequence<sal_Bool> arBool(_arBool, 3); + Sequence<sal_Unicode> arChar( _arChar, 3); + Sequence<sal_Int8> arByte(_arByte, 3); + Sequence<sal_Int16> arShort(_arShort, 3); + Sequence<sal_uInt16> arUShort(_arUShort, 3); + Sequence<sal_Int32> arLong(_arLong, 3); + Sequence<sal_uInt32> arULong(_arULong, 3); + Sequence<sal_Int64> arHyper(_arHyper, 3); + Sequence<sal_uInt64> arUHyper(_arUHyper, 3); + Sequence<float> arFloat(_arFloat, 3); + Sequence<double> arDouble(_arDouble, 3); + Sequence<OUString> arString(_arString, 3); + Sequence<Any> arAny(_arAny, 3); + Sequence<Reference<XInterface> > arObject(_arObj, 3); + Sequence<TestEnum> arEnum(_arEnum, 3); + Sequence<TestElement> arStruct(_arStruct, 3); + Sequence<Sequence<sal_Int32> > _arSeqLong2[3]; + for (int j = 0; j < 3; j++) + { + Sequence<sal_Int32> _arSeqLong[3]; + for (int i = 0; i < 3; i++) + { + _arSeqLong[i] = Sequence<sal_Int32>(_arLong, 3); + } + + _arSeqLong2[j] = Sequence< Sequence<sal_Int32> > (_arSeqLong, 3); + } + + Sequence<Sequence<Sequence<sal_Int32> > > arLong3( _arSeqLong2, 3); + Sequence<Sequence<sal_Int32> > seqSeqRet = xBT2->setDim2(arLong3[0]); + bRet = check( seqSeqRet == arLong3[0], "sequence test") && bRet; + Sequence<Sequence<Sequence<sal_Int32> > > seqSeqRet2 = xBT2->setDim3(arLong3); + bRet = check( seqSeqRet2 == arLong3, "sequence test") && bRet; + Sequence<Any> seqAnyRet = xBT2->setSequenceAny(arAny); + bRet = check( seqAnyRet == arAny, "sequence test") && bRet; + Sequence<sal_Bool> seqBoolRet = xBT2->setSequenceBool(arBool); + bRet = check( seqBoolRet == arBool, "sequence test") && bRet; + Sequence<sal_Int8> seqByteRet = xBT2->setSequenceByte(arByte); + bRet = check( seqByteRet == arByte, "sequence test") && bRet; + Sequence<sal_Unicode> seqCharRet = xBT2->setSequenceChar(arChar); + bRet = check( seqCharRet == arChar, "sequence test") && bRet; + Sequence<sal_Int16> seqShortRet = xBT2->setSequenceShort(arShort); + bRet = check( seqShortRet == arShort, "sequence test") && bRet; + Sequence<sal_Int32> seqLongRet = xBT2->setSequenceLong(arLong); + bRet = check( seqLongRet == arLong, "sequence test") && bRet; + Sequence<sal_Int64> seqHyperRet = xBT2->setSequenceHyper(arHyper); + bRet = check( seqHyperRet == arHyper, "sequence test") && bRet; + Sequence<float> seqFloatRet = xBT2->setSequenceFloat(arFloat); + bRet = check( seqFloatRet == arFloat, "sequence test") && bRet; + Sequence<double> seqDoubleRet = xBT2->setSequenceDouble(arDouble); + bRet = check( seqDoubleRet == arDouble, "sequence test") && bRet; + Sequence<TestEnum> seqEnumRet = xBT2->setSequenceEnum(arEnum); + bRet = check( seqEnumRet == arEnum, "sequence test") && bRet; + Sequence<sal_uInt16> seqUShortRet = xBT2->setSequenceUShort(arUShort); + bRet = check( seqUShortRet == arUShort, "sequence test") && bRet; + Sequence<sal_uInt32> seqULongRet = xBT2->setSequenceULong(arULong); + bRet = check( seqULongRet == arULong, "sequence test") && bRet; + Sequence<sal_uInt64> seqUHyperRet = xBT2->setSequenceUHyper(arUHyper); + bRet = check( seqUHyperRet == arUHyper, "sequence test") && bRet; + Sequence<Reference<XInterface> > seqObjectRet = xBT2->setSequenceXInterface(arObject); + bRet = check( seqObjectRet == arObject, "sequence test") && bRet; + Sequence<OUString> seqStringRet = xBT2->setSequenceString(arString); + bRet = check( seqStringRet == arString, "sequence test") && bRet; + Sequence<TestElement> seqStructRet = xBT2->setSequenceStruct(arStruct); + bRet = check( seqStructRet == arStruct, "sequence test") && bRet; + + Sequence<sal_Bool> arBoolTemp = cloneSequence(arBool); + Sequence<sal_Unicode> arCharTemp = cloneSequence(arChar); + Sequence<sal_Int8> arByteTemp = cloneSequence(arByte); + Sequence<sal_Int16> arShortTemp = cloneSequence(arShort); + Sequence<sal_uInt16> arUShortTemp = cloneSequence(arUShort); + Sequence<sal_Int32> arLongTemp = cloneSequence(arLong); + Sequence<sal_uInt32> arULongTemp = cloneSequence(arULong); + Sequence<sal_Int64> arHyperTemp = cloneSequence(arHyper); + Sequence<sal_uInt64> arUHyperTemp = cloneSequence(arUHyper); + Sequence<float> arFloatTemp = cloneSequence(arFloat); + Sequence<double> arDoubleTemp = cloneSequence(arDouble); + Sequence<TestEnum> arEnumTemp = cloneSequence(arEnum); + Sequence<OUString> arStringTemp = cloneSequence(arString); + Reference<XInterface> _xint; + Sequence<Reference<XInterface> > arObjectTemp = cloneSequence(arObject); + Sequence<Any> arAnyTemp = cloneSequence(arAny); + Sequence<Sequence<sal_Int32> > arLong2Temp(arLong3[0]); + Sequence<Sequence<Sequence<sal_Int32> > > arLong3Temp(arLong3); + + xBT2->setSequencesInOut(arBoolTemp, arCharTemp, arByteTemp, arShortTemp, + arUShortTemp, arLongTemp,arULongTemp, arHyperTemp, + arUHyperTemp, arFloatTemp, arDoubleTemp, + arEnumTemp, arStringTemp, arObjectTemp, arAnyTemp, + arLong2Temp, arLong3Temp); + bRet = check( + arBoolTemp == arBool && + arCharTemp == arChar && + arByteTemp == arByte && + arShortTemp == arShort && + arUShortTemp == arUShort && + arLongTemp == arLong && + arULongTemp == arULong && + arHyperTemp == arHyper && + arUHyperTemp == arUHyper && + arFloatTemp == arFloat && + arDoubleTemp == arDouble && + arEnumTemp == arEnum && + arStringTemp == arString && + arObjectTemp == arObject && + arAnyTemp == arAny && + arLong2Temp == arLong3[0] && + arLong3Temp == arLong3, "sequence test") && bRet; + + Sequence<sal_Bool> arBoolOut; + Sequence<sal_Unicode> arCharOut; + Sequence<sal_Int8> arByteOut; + Sequence<sal_Int16> arShortOut; + Sequence<sal_uInt16> arUShortOut; + Sequence<sal_Int32> arLongOut; + Sequence<sal_uInt32> arULongOut; + Sequence<sal_Int64> arHyperOut; + Sequence<sal_uInt64> arUHyperOut; + Sequence<float> arFloatOut; + Sequence<double> arDoubleOut; + Sequence<TestEnum> arEnumOut; + Sequence<OUString> arStringOut; + Sequence<Reference<XInterface> > arObjectOut; + Sequence<Any> arAnyOut; + Sequence<Sequence<sal_Int32> > arLong2Out; + Sequence<Sequence<Sequence<sal_Int32> > > arLong3Out; + xBT2->setSequencesOut(arBoolOut, arCharOut, arByteOut, arShortOut, + arUShortOut, arLongOut,arULongOut, arHyperOut, + arUHyperOut, arFloatOut, arDoubleOut, + arEnumOut, arStringOut, arObjectOut, arAnyOut, + arLong2Out, arLong3Out); + bRet = check( + arBoolOut == arBool && + arCharOut == arChar && + arByteOut == arByte && + arShortOut == arShort && + arUShortOut == arUShort && + arLongOut == arLong && + arULongOut == arULong && + arHyperOut == arHyper && + arUHyperOut == arUHyper && + arFloatOut == arFloat && + arDoubleOut == arDouble && + arEnumOut == arEnum && + arStringOut == arString && + arObjectOut == arObject && + arAnyOut == arAny && + arLong2Out == arLong3[0] && + arLong3Out == arLong3, "sequence test") && bRet; + } + { + //test with empty sequences + Sequence<Sequence<sal_Int32> > arLong2; + Sequence<Sequence<sal_Int32> > seqSeqRet = xBT2->setDim2(arLong2); + bRet = check( seqSeqRet == arLong2, "sequence test") && bRet; + Sequence<Sequence<Sequence<sal_Int32> > > arLong3; + Sequence<Sequence<Sequence<sal_Int32> > > seqSeqRet2 = xBT2->setDim3( + arLong3); + bRet = check( seqSeqRet2 == arLong3, "sequence test") && bRet; + Sequence<Any> arAny; + Sequence<Any> seqAnyRet = xBT2->setSequenceAny(arAny); + bRet = check( seqAnyRet == arAny, "sequence test") && bRet; + Sequence<sal_Bool> arBool; + Sequence<sal_Bool> seqBoolRet = xBT2->setSequenceBool(arBool); + bRet = check( seqBoolRet == arBool, "sequence test") && bRet; + Sequence<sal_Int8> arByte; + Sequence<sal_Int8> seqByteRet = xBT2->setSequenceByte(arByte); + bRet = check( seqByteRet == arByte, "sequence test") && bRet; + Sequence<sal_Unicode> arChar; + Sequence<sal_Unicode> seqCharRet = xBT2->setSequenceChar(arChar); + bRet = check( seqCharRet == arChar, "sequence test") && bRet; + Sequence<sal_Int16> arShort; + Sequence<sal_Int16> seqShortRet = xBT2->setSequenceShort(arShort); + bRet = check( seqShortRet == arShort, "sequence test") && bRet; + Sequence<sal_Int32> arLong; + Sequence<sal_Int32> seqLongRet = xBT2->setSequenceLong(arLong); + bRet = check( seqLongRet == arLong, "sequence test") && bRet; + Sequence<sal_Int64> arHyper; + Sequence<sal_Int64> seqHyperRet = xBT2->setSequenceHyper(arHyper); + bRet = check( seqHyperRet == arHyper, "sequence test") && bRet; + Sequence<float> arFloat; + Sequence<float> seqFloatRet = xBT2->setSequenceFloat(arFloat); + bRet = check( seqFloatRet == arFloat, "sequence test") && bRet; + Sequence<double> arDouble; + Sequence<double> seqDoubleRet = xBT2->setSequenceDouble(arDouble); + bRet = check( seqDoubleRet == arDouble, "sequence test") && bRet; + Sequence<TestEnum> arEnum; + Sequence<TestEnum> seqEnumRet = xBT2->setSequenceEnum(arEnum); + bRet = check( seqEnumRet == arEnum, "sequence test") && bRet; + Sequence<sal_uInt16> arUShort; + Sequence<sal_uInt16> seqUShortRet = xBT2->setSequenceUShort(arUShort); + bRet = check( seqUShortRet == arUShort, "sequence test") && bRet; + Sequence<sal_uInt32> arULong; + Sequence<sal_uInt32> seqULongRet = xBT2->setSequenceULong(arULong); + bRet = check( seqULongRet == arULong, "sequence test") && bRet; + Sequence<sal_uInt64> arUHyper; + Sequence<sal_uInt64> seqUHyperRet = xBT2->setSequenceUHyper(arUHyper); + bRet = check( seqUHyperRet == arUHyper, "sequence test") && bRet; + Sequence<Reference<XInterface> > arObject; + Sequence<Reference<XInterface> > seqObjectRet = + xBT2->setSequenceXInterface(arObject); + bRet = check( seqObjectRet == arObject, "sequence test") && bRet; + Sequence<OUString> arString; + Sequence<OUString> seqStringRet = xBT2->setSequenceString(arString); + bRet = check( seqStringRet == arString, "sequence test") && bRet; + Sequence<TestElement> arStruct; + Sequence<TestElement> seqStructRet = xBT2->setSequenceStruct(arStruct); + bRet = check( seqStructRet == arStruct, "sequence test") && bRet; + } + // Issue #i60341# shows that the most interesting case is were Java calls + // the constructors; however, since this client is currently not available + // in Java, while the server is, the logic is reversed here: + try { + xBT2->testConstructorsService(xContext); + } catch (BadConstructorArguments &) { + bRet = false; + } + if (!noCurrentContext) { + if (!(new testtools::bridgetest::CurrentContextChecker)->perform( + xBT2->getCurrentContextChecker(), 0, 1)) + { + bRet = false; + } + if (!(new testtools::bridgetest::CurrentContextChecker)->perform( + xBT2->getCurrentContextChecker(), 0, 2)) + { + bRet = false; + } + if (!(new testtools::bridgetest::CurrentContextChecker)->perform( + xBT2->getCurrentContextChecker(), 1, 2)) + { + bRet = false; + } + if (!(new testtools::bridgetest::CurrentContextChecker)->perform( + xBT2->getCurrentContextChecker(), 1, 3)) + { + bRet = false; + } + } + } + return bRet; +} +static sal_Bool raiseOnewayException( const Reference < XBridgeTest > & xLBT ) +{ + sal_Bool bReturn = sal_True; + OUString sCompare = OUSTR(STRING_TEST_CONSTANT); + Reference<XInterface> const x(xLBT->getInterface()); + try + { + // Note : the exception may fly or not (e.g. remote scenario). + // When it flies, it must contain the correct elements. + xLBT->raiseRuntimeExceptionOneway( sCompare, x ); + } + catch( RuntimeException & e ) + { + bReturn = ( +#if OSL_DEBUG_LEVEL == 0 + // java stack traces trash Message + e.Message == sCompare && +#endif + xLBT->getInterface() == e.Context && + x == 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, OUSTR(STRING_TEST_CONSTANT), + xLBT->getInterface() ); + } + catch (IllegalArgumentException aExc) + { + if (aExc.ArgumentPosition == 5 && +#if OSL_DEBUG_LEVEL == 0 + // java stack traces trash Message + aExc.Message.compareToAscii( STRING_TEST_CONSTANT ) == 0 && +#endif + aExc.Context == xLBT->getInterface()) + { +#ifdef COMPCHECK + //When we check if a new compiler still works then we must not call + //getRuntimeException because it uses cppu::getCaughtException which + //does only work if all libs are build with the same runtime. + return true; +#else + ++nCount; +#endif + } + else + { + check( 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() +#if OSL_DEBUG_LEVEL == 0 + // java stack traces trash Message + && rExc.Message.compareToAscii( STRING_TEST_CONSTANT ) == 0 +#endif + ) + { + ++nCount; + } + else + { + check( 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() +#if OSL_DEBUG_LEVEL == 0 + // java stack traces trash Message + && rExc.Message.compareToAscii( STRING_TEST_CONSTANT ) == 0 +#endif + ) + { + ++nCount; + } + else + { + check( sal_False, "### unexpected exception content!" ); + } + return (nCount == 3); + } + return sal_False; +} + +/* Returns an acquired sequence + */ +uno_Sequence* cloneSequence(const uno_Sequence* val, const Type& type) +{ + TypeDescription td(type); + td.makeComplete(); + typelib_TypeDescription* pTdRaw = td.get(); + typelib_IndirectTypeDescription* pIndirectTd = + (typelib_IndirectTypeDescription*) pTdRaw; + + typelib_TypeDescription* pTdElem = pIndirectTd->pType->pType; + sal_Int8* buf = new sal_Int8[pTdElem->nSize * val->nElements]; + sal_Int8* pBufCur = buf; + + uno_Sequence* retSeq = NULL; + switch (pTdElem->eTypeClass) + { + case TypeClass_SEQUENCE: + { + Type _tElem(pTdElem->pWeakRef); + for (int i = 0; i < val->nElements; i++) + { + uno_Sequence* seq = cloneSequence( + *(uno_Sequence**) (&val->elements + i * pTdElem->nSize), + _tElem); + *((uno_Sequence**) pBufCur) = seq; + pBufCur += pTdElem->nSize; + } + break; + } + default: + uno_type_sequence_construct( + &retSeq, type.getTypeLibType(), (void*) val->elements, + val->nElements, reinterpret_cast< uno_AcquireFunc >(cpp_acquire)); + break; + } + delete[] buf; + return retSeq; +} + +template< class T> +Sequence<T> cloneSequence(const Sequence<T>& val) +{ + Sequence<T> seq( cloneSequence(val.get(), getCppuType(&val)), SAL_NO_ACQUIRE); + return seq; +} + +template< class T > +inline bool makeSurrogate( + Reference< T > & rOut, Reference< T > const & rOriginal ) +{ + rOut.clear(); + if (! rOriginal.is()) + return false; + + Environment aCppEnv_official; + Environment aUnoEnv_ano; + Environment aCppEnv_ano; + + OUString aCppEnvTypeName( + RTL_CONSTASCII_USTRINGPARAM(CPPU_CURRENT_LANGUAGE_BINDING_NAME) ); + OUString aUnoEnvTypeName( + RTL_CONSTASCII_USTRINGPARAM(UNO_LB_UNO) ); + // official: + uno_getEnvironment( + reinterpret_cast< uno_Environment ** >( &aCppEnv_official ), + aCppEnvTypeName.pData, 0 ); + // anonymous: + uno_createEnvironment( + reinterpret_cast< uno_Environment ** >( &aCppEnv_ano ), + aCppEnvTypeName.pData, 0 ); + uno_createEnvironment( + reinterpret_cast< uno_Environment ** >( &aUnoEnv_ano ), + aUnoEnvTypeName.pData, 0 ); + + UnoInterfaceReference unoI; + Mapping cpp2uno( aCppEnv_official.get(), aUnoEnv_ano.get() ); + Mapping uno2cpp( aUnoEnv_ano.get(), aCppEnv_ano.get() ); + if (!cpp2uno.is() || !uno2cpp.is()) + { + throw RuntimeException( + OUSTR("cannot get C++-UNO mappings!"), + Reference< XInterface >() ); + } + cpp2uno.mapInterface( + reinterpret_cast< void ** >( &unoI.m_pUnoI ), + rOriginal.get(), ::getCppuType( &rOriginal ) ); + if (! unoI.is()) + { + throw RuntimeException( + OUSTR("mapping C++ to binary UNO failed!"), + Reference< XInterface >() ); + } + uno2cpp.mapInterface( + reinterpret_cast< void ** >( &rOut ), + unoI.get(), ::getCppuType( &rOriginal ) ); + if (! rOut.is()) + { + throw RuntimeException( + OUSTR("mapping binary UNO to C++ failed!"), + Reference< XInterface >() ); + } + + return rOut.is(); +} + +//================================================================================================== +sal_Int32 TestBridgeImpl::run( const Sequence< OUString > & rArgs ) + throw (RuntimeException) +{ + bool bRet = false; + try + { + 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< XInterface > xOriginal; + bool remote; + sal_Int32 i; + if( rArgs.getLength() > 1 && 0 == rArgs[0].compareToAscii( "-u" ) ) + { + remote = true; + i = 2; + } + else + { + remote = false; + i = 1; + } + bool noCurrentContext = false; + if (i < rArgs.getLength() + && rArgs[i].equalsAsciiL( + RTL_CONSTASCII_STRINGPARAM("noCurrentContext"))) + { + noCurrentContext = true; + ++i; + } + bool stress = false; + if (i < rArgs.getLength() + && rArgs[i].equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("stress"))) + { + stress = true; + ++i; + } + + for (;;) { + Reference< XInterface > o; + if (remote) { + o = UnoUrlResolver::create(m_xContext)->resolve(rArgs[1]); + } else { + o = m_xContext->getServiceManager()->createInstanceWithContext( + rArgs[0], m_xContext); + } + if (!stress) { + xOriginal = o; + break; + } + } + + if (! xOriginal.is()) + { + throw RuntimeException( + OUString( RTL_CONSTASCII_USTRINGPARAM( + "cannot get test object!") ), + Reference< XInterface >() ); + } + Reference< XBridgeTest > xTest( xOriginal, UNO_QUERY ); + if (! xTest.is()) + { + throw RuntimeException( + OUString( RTL_CONSTASCII_USTRINGPARAM("test object does not implement XBridgeTest!") ), + Reference< XInterface >() ); + } + + Reference<XBridgeTest > xLBT; + bRet = check( makeSurrogate( xLBT, xTest ), "makeSurrogate" ); + bRet = check( + performTest( m_xContext, xLBT, noCurrentContext ), "standard test" ) + && bRet; + bRet = check( raiseException( xLBT ) , "exception test" )&& bRet; + bRet = check( raiseOnewayException( xLBT ), + "oneway exception test" ) && bRet; + bRet = performQueryForUnknownType( xLBT ) && bRet; + if (! bRet) + { + throw RuntimeException( + OUString( RTL_CONSTASCII_USTRINGPARAM("error: test failed!") ), + Reference< XInterface >() ); + } + } + catch (Exception & exc) + { + OString cstr( OUStringToOString( exc.Message, RTL_TEXTENCODING_ASCII_US ) ); + fprintf( stderr, "exception occured: %s\n", cstr.getStr() ); + throw; + } + + if( bRet ) + { + printf( "\n\n ### test succeeded!\n" ); + } + else + { + printf( "\n> ### 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< XComponentContext > & xContext ) +{ + return Reference< XInterface >( + static_cast< OWeakObject * >( new TestBridgeImpl( xContext ) ) ); +} + +} + +extern "C" +{ +//================================================================================================== +void SAL_CALL component_getImplementationEnvironment( + const sal_Char ** ppEnvTypeName, uno_Environment ** ) +{ + *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME; +} +//================================================================================================== +sal_Bool SAL_CALL component_writeInfo( void *, 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 * ) +{ + void * pRet = 0; + + if (pServiceManager && rtl_str_compare( pImplName, IMPLNAME ) == 0) + { + Reference< XInterface > xFactory( + createSingleComponentFactory( + bridge_test::TestBridgeImpl_create, + OUString( RTL_CONSTASCII_USTRINGPARAM(IMPLNAME) ), + bridge_test::getSupportedServiceNames() ) ); + + if (xFactory.is()) + { + xFactory->acquire(); + pRet = xFactory.get(); + } + } + + return pRet; +} +} diff --git a/testtools/source/bridgetest/cli/cli_bridgetest_inprocess.cs b/testtools/source/bridgetest/cli/cli_bridgetest_inprocess.cs new file mode 100644 index 000000000000..c527946b633d --- /dev/null +++ b/testtools/source/bridgetest/cli/cli_bridgetest_inprocess.cs @@ -0,0 +1,260 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +using System; +using System.Collections; +using uno; +using uno.util; +using unoidl.com.sun.star.uno; +using unoidl.com.sun.star.lang; +using unoidl.com.sun.star.container; + + +//============================================================================== +internal class Factory : + WeakComponentBase, XSingleComponentFactory, XServiceInfo +{ + private String m_service; + private Type m_type; + private System.Reflection.ConstructorInfo m_ctor; + + public Factory( Type type, String service ) + { + m_service = service; + m_type = type; + m_ctor = type.GetConstructor( + new Type [] { typeof (XComponentContext) } ); + } + + public Object createInstanceWithContext( XComponentContext xContext ) + { + return m_ctor.Invoke( new Object [] { xContext } ); + } + + public Object createInstanceWithArgumentsAndContext( + uno.Any [] args, XComponentContext xContext ) + { + return m_ctor.Invoke( new Object [] { xContext } ); + } + + public bool supportsService( String name ) + { + return m_service.Equals( name ); + } + + public String [] getSupportedServiceNames() + { + return new String [] { m_service }; + } + + public String getImplementationName() + { + return m_type.ToString(); + } +} + + +/** This executable does the same as the batch file starting via uno.exe, + but via bootstrapping native UNO. +*/ +public class BridgeTest +{ + public static int Main( String [] args ) + { +// System.Diagnostics.Debugger.Launch(); + try + { + string bootstrap_ini = "cli_bridgetest_inprocess.ini"; + if (args.Length > 0) + { + if (args[0] == "/?") + { + Console.WriteLine( + "\n\ncli_bridgetest_inprocess [bootstrap file] \n\n" + + "bootstrap file \n" + + "\t contains the entries UNO_TYPES and UNO_SERVICES.\n" + + "\t If a file is not provided than it is assumed that a\n" + + "\t cli_bridgetest_inprocess.ini file can be found in the\n " + + "\t current working directory.\n" + ); + return 0; + } + else + { + bootstrap_ini = args[0]; + } + } + + // bootstrap native UNO + XComponentContext xContext = + Bootstrap.defaultBootstrap_InitialComponentContext( + bootstrap_ini, null ); + + using (new uno.util.DisposeGuard( (XComponent) xContext )) + { + XSet xSet = (XSet) xContext.getServiceManager(); + xSet.insert( + new uno.Any( + typeof (XSingleComponentFactory), + new Factory( + typeof (cs_testobj.BridgeTestObject), + "com.sun.star.test.bridge.cli_uno.CsTestObject" ) ) ); + xSet.insert( + new uno.Any( + typeof (XSingleComponentFactory), + new Factory( + typeof (vb_testobj.VBBridgeTestObject), + "com.sun.star.test.bridge.cli_uno.VbTestObject" ) ) ); + xSet.insert( + new uno.Any( + typeof (XSingleComponentFactory), + new Factory( + typeof (cpp_bridgetest.BridgeTest), + "com.sun.star.test.bridge.cli_uno.CppBridgeTest" ) ) ); + xSet.insert( + new uno.Any( + typeof (XSingleComponentFactory), + new Factory( + typeof (cs_testobj.BridgeTest), + "com.sun.star.test.bridge.cli_uno.CsBridgeTest" ) ) ); + xSet.insert( + new uno.Any( + typeof (XSingleComponentFactory), + new Factory( + typeof (vb_bridetest.BridgeTest), + "com.sun.star.test.bridge.cli_uno.VbBridgeTest" ) ) ); + + // I. + // direct unbridged test + // get client object via singleton entry + Object test_client; + XMain xClient; + test_client = new cs_testobj.BridgeTest( xContext ); + xClient = (XMain) test_client; + Console.WriteLine( + "\n[cli bridgetest] 1. C# client calls C# object"); + // run with CLI target object + xClient.run( + new String [] { + "com.sun.star.test.bridge.cli_uno.CsTestObject" } ); + + // II: + // uno -ro uno_services.rdb -ro uno_types.rdb + // -s com.sun.star.test.bridge.BridgeTest + // -- com.sun.star.test.bridge.cli_uno.TestObject + + // get native client + test_client = + xContext.getServiceManager().createInstanceWithContext( + "com.sun.star.test.bridge.BridgeTest", xContext ); + xClient = (XMain) test_client; + Console.WriteLine( + "\n[cli bridgetest] 2. C++ client (native) calls C# object"); + // run with CLI target object + xClient.run( + new String [] { + "com.sun.star.test.bridge.cli_uno.CsTestObject", + "noCurrentContext"} ); + + // III: + // uno -ro uno_services.rdb -ro uno_types.rdb + // -s com.sun.star.test.bridge.cli_uno.BridgeTest + // -- com.sun.star.test.bridge.CppTestObject + + // get CLI client + test_client = + xContext.getServiceManager().createInstanceWithContext( + "com.sun.star.test.bridge.cli_uno.CsBridgeTest", + xContext ); + xClient = (XMain) test_client; + Console.WriteLine( + "\n[cli bridgetest] 3. C# client calls C++ object (native)"); + // run with native target object + xClient.run( + new String [] { "com.sun.star.test.bridge.CppTestObject" } ); + + // IV: + // uno -ro uno_services.rdb -ro uno_types.rdb + // -s com.sun.star.test.bridge.cli_uno.VbBridgeTest + // -- com.sun.star.test.bridge.CppTestObject + // get CLI client + test_client = + xContext.getServiceManager().createInstanceWithContext( + "com.sun.star.test.bridge.cli_uno.VbBridgeTest", + xContext ); + xClient = (XMain) test_client; + Console.WriteLine( + "\n[cli bridgetest] 4. Visual Basic client calls C++ (native) object" ); + // run with native target object + xClient.run( + new String [] { "com.sun.star.test.bridge.CppTestObject" } ); + + // V: + // uno -ro uno_services.rdb -ro uno_types.rdb + // -s com.sun.star.test.bridge.BridgeTest + // -- com.sun.star.test.bridge.cli_uno.VbTestObject + // get CLI client +// test_client = +// xContext.getServiceManager().createInstanceWithContext( +// "com.sun.star.test.bridge.BridgeTest", xContext ); +// xClient = (XMain) test_client; +// Console.WriteLine( +// "[cli bridgetest] Visual Basic client: {0}", +// xClient.ToString() ); +// // run with native target object +// xClient.run( +// new String [] { +// "com.sun.star.test.bridge.cli_uno.VbTestObject" } ); + + // VI: + // uno -ro uno_services.rdb -ro uno_types.rdb + // -s com.sun.star.test.bridge.cli_uno.CppBridgeTest + // -- com.sun.star.test.bridge.CppTestObject + test_client = + xContext.getServiceManager().createInstanceWithContext( + "com.sun.star.test.bridge.cli_uno.CppBridgeTest", + xContext ); + xClient = (XMain) test_client; + Console.WriteLine( + "\n[cli bridgetest] 6. CLI C++ client calls C++ object (native)"); + // run with native target object + xClient.run( + new String [] { "com.sun.star.test.bridge.CppTestObject" } ); + } + } + catch (System.Exception exc) + { + GC.WaitForPendingFinalizers(); + System.Console.WriteLine( exc ); + return -1; + } + + GC.WaitForPendingFinalizers(); + System.Console.WriteLine( "====> all tests ok." ); + return 0; + } +} diff --git a/testtools/source/bridgetest/cli/cli_bridgetest_inprocess.ini b/testtools/source/bridgetest/cli/cli_bridgetest_inprocess.ini new file mode 100644 index 000000000000..bb7c56fcf0d8 --- /dev/null +++ b/testtools/source/bridgetest/cli/cli_bridgetest_inprocess.ini @@ -0,0 +1,3 @@ +[Bootstrap] +UNO_TYPES=$SYSBINDIR/uno_types.rdb +UNO_SERVICES=$SYSBINDIR/uno_services.rdb diff --git a/testtools/source/bridgetest/cli/cli_cpp_bridgetest.cxx b/testtools/source/bridgetest/cli/cli_cpp_bridgetest.cxx new file mode 100644 index 000000000000..dceb0aff5284 --- /dev/null +++ b/testtools/source/bridgetest/cli/cli_cpp_bridgetest.cxx @@ -0,0 +1,982 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_testtools.hxx" + +#using <mscorlib.dll> +#using <System.dll> +#using <cli_basetypes.dll> +#using <cli_uretypes.dll> +#using <cli_ure.dll> +#using <cli_types_bridgetest.dll> + +using namespace System; +using namespace System::Diagnostics; +using namespace System::Reflection; +using namespace System::Threading; +using namespace uno; +using namespace uno::util; +using namespace unoidl::com::sun::star::uno; +using namespace unoidl::com::sun::star::lang; +//using namespace unoidl::com::sun::star::test::bridge; +using namespace unoidl::test::testtools::bridgetest; +namespace foo +{ + public __gc __interface MyInterface + { + }; +} + +namespace cpp_bridgetest +{ + __gc class ORecursiveCall: public WeakBase, public XRecursiveCall + { + public: + void callRecursivly(XRecursiveCall * xCall, int nToCall) + { + Monitor::Enter(this); + try + { + { + if (nToCall > 0) + { + nToCall --; + xCall->callRecursivly(this, nToCall); + } + } + } + __finally + { + Monitor::Exit(this); + } + + } + }; + +public __gc class Constants +{ +public: + static String* STRING_TEST_CONSTANT = new String(S"\" paco\' chorizo\\\' \"\'"); +}; + +public __gc class BridgeTest : public WeakBase, public XMain +{ + static bool compareData(Object* val1, Object* val2) + { + if (val1 == 0 && val2 == 0 || val1 == val2) + return true; + if ((val1 == 0 && val2 != 0) || + (val1 != 0 && val2 == 0) || val1->GetType() != val2->GetType()) + return false; + + bool ret = false; + Type* t1 = val1->GetType(); + //Sequence + if (t1->IsArray) + { + ret = compareSequence(static_cast<Array*>(val1), + static_cast<Array*>(val2)); + } + //String + else if (t1 == __typeof(String)) + { + ret = val1->Equals(val2); + } + // Interface implementation + else if (t1->GetInterfaces()->Length > 0 && ! t1->IsValueType) + { + ret = val1 == val2; + } + // Struct + else if ( ! t1->IsValueType) + { + ret = compareStruct(val1, val2); + } + else if (t1 == __typeof(Any)) + { + Any a1 = (Any) val1; + Any a2 = (Any) val2; + ret = a1.Type == a2.Type && compareData(a1.Value, a2.Value); + } + else if (t1->IsValueType) + { + //Any, enum, int, bool char, float, double etc. + ret = val1->Equals(val2); + } + else + { + Debug::Assert(false); + } + return ret; + } + + // Arrays have only one dimension + static bool compareSequence(Array* ar1, Array* ar2) + { + Debug::Assert(ar1 != 0 && ar2 != 0); + Type* t1 = ar1->GetType(); + Type* t2 = ar2->GetType(); + + if (!(ar1->Rank == 1 && ar2->Rank == 1 + && ar1->Length == ar2->Length && t1->GetElementType() == t2->GetElementType())) + return false; + + //arrays have same rank and size and element type. + int len = ar1->Length; + bool ret = true; + for (int i = 0; i < len; i++) + { + if (compareData(ar1->GetValue(i), ar2->GetValue(i)) == false) + { + ret = false; + break; + } + } + return ret; + } + + static bool compareStruct(Object* val1, Object* val2) + { + Debug::Assert(val1 != 0 && val2 != 0); + Type* t1 = val1->GetType(); + Type* t2 = val2->GetType(); + if (t1 != t2) + return false; + FieldInfo* fields[] = t1->GetFields(); + int cFields = fields->Length; + bool ret = true; + for (int i = 0; i < cFields; i++) + { + Object* fieldVal1 = fields[i]->GetValue(val1); + Object* fieldVal2 = fields[i]->GetValue(val2); + if ( ! compareData(fieldVal1, fieldVal2)) + { + ret = false; + break; + } + } + return ret; + } + + static bool check( bool b , String* message ) + { + if ( ! b) + Console::WriteLine("{0} failed\n" , message); + return b; + } + + static bool equals(TestElement* rData1, TestElement* rData2) + { + check( rData1->Bool == rData2->Bool, "### bool does not match!" ); + check( rData1->Char == rData2->Char, "### char does not match!" ); + check( rData1->Byte == rData2->Byte, "### byte does not match!" ); + check( rData1->Short == rData2->Short, "### short does not match!" ); + check( rData1->UShort == rData2->UShort, "### unsigned short does not match!" ); + check( rData1->Long == rData2->Long, "### long does not match!" ); + check( rData1->ULong == rData2->ULong, "### unsigned long does not match!" ); + check( rData1->Hyper == rData2->Hyper, "### hyper does not match!" ); + check( rData1->UHyper == rData2->UHyper, "### unsigned hyper does not match!" ); + check( rData1->Float == rData2->Float, "### float does not match!" ); + check( rData1->Double == rData2->Double, "### double does not match!" ); + check( rData1->Enum == rData2->Enum, "### enum does not match!" ); + check( rData1->String == rData2->String, "### string does not match!" ); + check( rData1->Interface == rData2->Interface, "### interface does not match!" ); + check( compareData(__box(rData1->Any), __box(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 && + compareData(__box(rData1->Any), __box(rData2->Any))); + } + +static void assign( TestElement* rData, + bool bBool, Char cChar, Byte nByte, + Int16 nShort, UInt16 nUShort, + Int32 nLong, UInt32 nULong, + Int64 nHyper, UInt64 nUHyper, + float fFloat, double fDouble, + TestEnum eEnum, String* rStr, + Object* xTest, + 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( TestDataElements* rData, + bool bBool, Char cChar, Byte nByte, + Int16 nShort, UInt16 nUShort, + Int32 nLong, UInt32 nULong, + Int64 nHyper, UInt64 nUHyper, + float fFloat, double fDouble, + TestEnum eEnum, String* rStr, + Object* xTest, + Any rAny, + TestElement* rSequence[]) +{ + assign( static_cast<TestElement*>(rData), + bBool, cChar, nByte, nShort, nUShort, nLong, nULong, nHyper, nUHyper, fFloat, fDouble, + eEnum, rStr, xTest, rAny ); + rData->Sequence = rSequence; +} + +static bool testAny(Type* typ, Object* value, XBridgeTest* xLBT ) +{ + Any any; + if (typ == 0) + any = Any(value->GetType(), value); + else + any = Any(typ, value); + + Any any2 = xLBT->transportAny(any); + bool ret = compareData(__box(any), __box(any2)); + if (!ret) + { + Console::WriteLine("any is different after roundtrip: in {0}, out {1}\n", + any.Type->FullName, any2.Type->FullName); + } + return ret; +} + + + +static bool performAnyTest(XBridgeTest* xLBT, TestDataElements* data) +{ + bool bReturn = true; + bReturn = testAny( 0, __box(data->Byte), xLBT ) && bReturn; + bReturn = testAny( 0, __box(data->Short), xLBT ) && bReturn; + bReturn = testAny( 0, __box(data->UShort), xLBT ) && bReturn; + bReturn = testAny( 0, __box(data->Long), xLBT ) && bReturn; + bReturn = testAny( 0, __box(data->ULong), xLBT ) && bReturn; + bReturn = testAny( 0, __box(data->Hyper), xLBT ) && bReturn; + bReturn = testAny( 0, __box(data->UHyper), xLBT ) && bReturn; + bReturn = testAny( 0, __box(data->Float), xLBT ) && bReturn; + bReturn = testAny( 0, __box(data->Double),xLBT ) && bReturn; + bReturn = testAny( 0, __box(data->Enum), xLBT ) && bReturn; + bReturn = testAny( 0, data->String,xLBT ) && bReturn; + bReturn = testAny(__typeof(XWeak), data->Interface,xLBT ) && bReturn; + bReturn = testAny(0, data, xLBT ) && bReturn; + + { + Any a1(true); + Any a2 = xLBT->transportAny( a1 ); + bReturn = compareData(__box(a2), __box(a1)) && bReturn; + } + + { + Any a1('A'); + Any a2 = xLBT->transportAny(a1); + bReturn = compareData( __box(a2), __box(a1)) && bReturn; + } + return bReturn; +} + +static bool performSequenceOfCallTest(XBridgeTest* xLBT) +{ + int i,nRounds; + int nGlobalIndex = 0; + const int 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(); +} + + + + +static bool performRecursiveCallTest(XBridgeTest* xLBT) +{ + xLBT->startRecursiveCall(new ORecursiveCall(), 50); + // on failure, the test would lock up or crash + return true; +} + +static bool performQueryForUnknownType(XBridgeTest* xLBT) +{ + bool bRet = false; + // test queryInterface for an unknown type + try + { + __try_cast<foo::MyInterface*>(xLBT); + } + catch( System::InvalidCastException*) + { + bRet = true; + } + + return bRet; +} + +// //================================================================================================== +static bool performTest(XBridgeTest* xLBT) +{ + check( xLBT != 0, "### no test interface!" ); + bool bRet = true; + if (xLBT != 0) + { + // this data is never ever granted access to by calls other than equals(), assign()! + TestDataElements* aData = new TestDataElements(); // test against this data + + Object* xI= new WeakBase(); + + Any aAny( __typeof(Object), xI); + assign( static_cast<TestElement*>(aData), + true, '@', 17, 0x1234, 0xfedc, 0x12345678, 0xfedcba98, + 0x123456789abcdef0, 0xfedcba9876543210, + 17.0815f, 3.1415926359, TestEnum::LOLA, + Constants::STRING_TEST_CONSTANT, xI, + aAny); + + bRet = check( aData->Any.Value == xI, "### unexpected any!" ) && bRet; + bRet = check( !(aData->Any.Value != xI), "### unexpected any!" ) && bRet; + + aData->Sequence = new TestElement*[2]; + aData->Sequence[0] = new TestElement( + 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, + aData->Interface, aData->Any); //(TestElement) aData; + aData->Sequence[1] = new TestElement(); //is empty + + // aData complete + // + // this is a manually copy of aData for first setting... + TestDataElements* aSetData = new TestDataElements; + Any aAnySet(__typeof(Object), xI); + assign( static_cast<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, + aAnySet); + + aSetData->Sequence = new TestElement*[2]; + aSetData->Sequence[0] = new TestElement( + 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); //TestElement) aSetData; + aSetData->Sequence[1] = new TestElement(); // empty struct + + 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 ); + + { + TestDataElements* aRet = new TestDataElements(); + TestDataElements* aRet2 = new TestDataElements(); + 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 ); + + bRet = check( compareData( aData, aRet ) && compareData( aData, aRet2 ) , "getValues test") && bRet; + + // set last retrieved values + TestDataElements* 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 ); + + // check inout sequence order + // => inout sequence parameter was switched by test objects + TestElement* temp = aRet->Sequence[ 0 ]; + aRet->Sequence[ 0 ] = aRet->Sequence[ 1 ]; + aRet->Sequence[ 1 ] = temp; + + bRet = check( + compareData( aData, aSV2ret ) && compareData( aData, aRet2 ), + "getValues2 test") && bRet; + } + { + TestDataElements* aRet = new TestDataElements(); + TestDataElements* aRet2 = new TestDataElements(); + TestDataElements* 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 ); + + bRet = check( compareData( aData, aRet ) && compareData( aData, aRet2 ) && compareData( aData, aGVret ), "getValues test" ) && bRet; + + // set last retrieved values + xLBT->Bool = aRet->Bool; + xLBT->Char = aRet->Char; + xLBT->Byte = aRet->Byte; + xLBT->Short = aRet->Short; + xLBT->UShort = aRet->UShort; + xLBT->Long = aRet->Long; + xLBT->ULong = aRet->ULong; + xLBT->Hyper = aRet->Hyper; + xLBT->UHyper = aRet->UHyper; + xLBT->Float = aRet->Float; + xLBT->Double = aRet->Double; + xLBT->Enum = aRet->Enum; + xLBT->String = aRet->String; + xLBT->Interface = aRet->Interface; + xLBT->Any = aRet->Any; + xLBT->Sequence = aRet->Sequence; + xLBT->Struct = aRet2; + } + { + TestDataElements* aRet = new TestDataElements(); + TestDataElements* aRet2 = new TestDataElements(); + aRet->Hyper = xLBT->Hyper; + aRet->UHyper = xLBT->UHyper; + aRet->Float = xLBT->Float; + aRet->Double = xLBT->Double; + aRet->Byte = xLBT->Byte; + aRet->Char = xLBT->Char; + aRet->Bool = xLBT->Bool; + aRet->Short = xLBT->Short; + aRet->UShort = xLBT->UShort; + aRet->Long = xLBT->Long; + aRet->ULong = xLBT->ULong; + aRet->Enum = xLBT->Enum; + aRet->String = xLBT->String; + aRet->Interface = xLBT->Interface; + aRet->Any = xLBT->Any; + aRet->Sequence = xLBT->Sequence; + aRet2 = xLBT->Struct; + + bRet = check( compareData( aData, aRet ) && compareData( aData, aRet2 ) , "struct comparison test") && bRet; + + bRet = check(performSequenceTest(xLBT), "sequence test") && bRet; + + // any test + bRet = check( performAnyTest( xLBT , aData ) , "any test" ) && bRet; + + // sequence of call test + bRet = check( performSequenceOfCallTest( xLBT ) , "sequence of call test" ) && bRet; + + // recursive call test + bRet = check( performRecursiveCallTest( xLBT ) , "recursive test" ) && bRet; + + bRet = (compareData( aData, aRet ) && compareData( aData, aRet2 )) && bRet ; + + // check setting of null reference + xLBT->Interface = 0; + aRet->Interface = xLBT->Interface; + bRet = (aRet->Interface == 0) && bRet; + + } + + + } + return bRet; + } +static bool performSequenceTest(XBridgeTest* xBT) +{ + bool bRet = true; + XBridgeTest2* xBT2 = dynamic_cast<XBridgeTest2*>(xBT); + if ( xBT2 == 0) + return false; + + // perform sequence tests (XBridgeTest2) + // create the sequence which are compared with the results + bool arBool __gc[] = new bool __gc [3]; + arBool[0] = true; arBool[1] = false; arBool[2] = true; + Char arChar[] = new Char[3]; + arChar[0] = 'A'; arChar[1] = 'B'; arChar[2] = 'C'; + Byte arByte[] = new Byte[3]; + arByte[0] = 1; arByte[1] = 2; arByte[2] = 0xff; + Int16 arShort[] = new Int16[3]; + arShort[0] = Int16::MinValue; arShort[1] = 1; arShort[2] = Int16::MaxValue; + UInt16 arUShort[] = new UInt16[3]; + arUShort[0] = UInt16::MinValue; arUShort[1] = 1; arUShort[2] = UInt16::MaxValue; + Int32 arLong[] = new Int32[3]; + arLong[0] = Int32::MinValue; arLong[1] = 1; arLong[2] = Int32::MaxValue; + UInt32 arULong[] = new UInt32[3]; + arULong[0] = UInt32::MinValue; arULong[1] = 1; arULong[2] = UInt32::MaxValue; + Int64 arHyper[] = new Int64[3]; + arHyper[0] = Int64::MinValue; arHyper[1] = 1; arHyper[2] = Int64::MaxValue; + UInt64 arUHyper[] = new UInt64[3]; + arUHyper[0] = UInt64::MinValue; arUHyper[1] = 1; + arUHyper[2] = UInt64::MaxValue; + Single arFloat[] = new Single[3]; + arFloat[0] = 1.1f; arFloat[1] = 2.2f; arFloat[2] = 3.3f; + Double arDouble[] = new Double[3]; + arDouble[0] = 1.11; arDouble[1] = 2.22; arDouble[2] = 3.33; + String* arString[] = new String*[3]; + arString[0] = new String("String 1"); + arString[1] = new String("String 2"); + arString[2] = new String("String 3"); + + Any arAny[] = new Any[3]; + arAny[0] = Any(true); arAny[1] = Any(11111); arAny[2] = Any(3.14); + Object* arObject[] = new Object*[3]; + arObject[0] = new WeakBase(); arObject[1] = new WeakBase(); + arObject[1] = new WeakBase(); + + //TestEnum arEnum[] = new TestEnum[3]; + //arEnum[0] = TestEnum::ONE; arEnum[1] = TestEnum::TWO; + //arEnum[2] = TestEnum::CHECK; + Console::WriteLine(new String("cli_cpp_bridgetest: Workaround for C++ compiler bug:" + " using Array of Int32 instead of Array of enums w")); + Int32 arEnum[] = new Int32[3]; + arEnum[0] = static_cast<Int32>(TestEnum::ONE); + arEnum[1] = static_cast<Int32>(TestEnum::TWO); + arEnum[2] = static_cast<Int32>(TestEnum::CHECK); + + TestElement* arStruct[] = new TestElement*[3]; + arStruct[0] = new TestElement(); arStruct[1] = new TestElement(); + arStruct[2] = new TestElement(); + assign( arStruct[0], true, '@', 17, 0x1234, 0xfedc, 0x12345678, 0xfedcba98, + 0x123456789abcdef0, 0xfedcba9876543210, 17.0815f, 3.1415926359, + TestEnum::LOLA, Constants::STRING_TEST_CONSTANT, arObject[0], + Any( __typeof(Object), arObject[0]) ); + assign( arStruct[1], true, 'A', 17, 0x1234, 0xfedc, 0x12345678, 0xfedcba98, + 0x123456789abcdef0, 0xfedcba9876543210, 17.0815f, 3.1415926359, + TestEnum::TWO, Constants::STRING_TEST_CONSTANT, arObject[1], + Any( __typeof(Object), arObject[1]) ); + assign( arStruct[2], true, 'B', 17, 0x1234, 0xfedc, 0x12345678, 0xfedcba98, + 0x123456789abcdef0, 0xfedcba9876543210, 17.0815f, 3.1415926359, + TestEnum::CHECK, Constants::STRING_TEST_CONSTANT, arObject[2], + Any( __typeof(Object), arObject[2] ) ); + + +// int[][][] arLong3 = new int[][][]{ +// new int[][]{new int[]{1,2,3},new int[]{4,5,6}, new int[]{7,8,9} }, +// new int [][]{new int[]{1,2,3},new int[]{4,5,6}, new int[]{7,8,9}}, +// new int[][]{new int[]{1,2,3},new int[]{4,5,6}, new int[]{7,8,9}}}; + + { + +// Console::WriteLine(new String("cli_cpp_bridgetest: +// int[][] seqSeqRet = xBT2->setDim2(arLong3[0]); +// bRet = check( compareData(seqSeqRet, arLong3[0]), "sequence test") && bRet; +// int[][][] seqSeqRet2 = xBT2->setDim3(arLong3); +// bRet = check( compareData(seqSeqRet2, arLong3), "sequence test") && bRet; + + Any seqAnyRet[] = xBT2->setSequenceAny(arAny); + bRet = check( compareData(seqAnyRet, arAny), "sequence test") && bRet; + Boolean seqBoolRet[] = xBT2->setSequenceBool(arBool); + bRet = check( compareData(seqBoolRet, arBool), "sequence test") && bRet; + Byte seqByteRet[] = xBT2->setSequenceByte(arByte); + bRet = check( compareData(seqByteRet, arByte), "sequence test") && bRet; + Char seqCharRet[] = xBT2->setSequenceChar(arChar); + bRet = check( compareData(seqCharRet, arChar), "sequence test") && bRet; + Int16 seqShortRet[] = xBT2->setSequenceShort(arShort); + bRet = check( compareData(seqShortRet, arShort), "sequence test") && bRet; + Int32 seqLongRet[] = xBT2->setSequenceLong(arLong); + bRet = check( compareData(seqLongRet, arLong), "sequence test") && bRet; + Int64 seqHyperRet[] = xBT2->setSequenceHyper(arHyper); + bRet = check( compareData(seqHyperRet,arHyper), "sequence test") && bRet; + Single seqFloatRet[] = xBT2->setSequenceFloat(arFloat); + bRet = check( compareData(seqFloatRet, arFloat), "sequence test") && bRet; + Double seqDoubleRet[] = xBT2->setSequenceDouble(arDouble); + bRet = check( compareData(seqDoubleRet, arDouble), "sequence test") && bRet; + xBT2->setSequenceEnum(arEnum); + //comparing seqEnumRet with arEnum will fail since they are of different + //types because of workaround. arEnum is Int32[]. + Console::WriteLine(new String("cli_cpp_bridgetest: Test omitted because " + "of C++ compiler bug. XBridgeTest2::setSequenceEnum(sequence<TestEnum>)")); +// bRet = check( compareData(seqEnumRet, arEnum), "sequence test") && bRet; + UInt16 seqUShortRet[] = xBT2->setSequenceUShort(arUShort); + bRet = check( compareData(seqUShortRet, arUShort), "sequence test") && bRet; + UInt32 seqULongRet[] = xBT2->setSequenceULong(arULong); + bRet = check( compareData(seqULongRet, arULong), "sequence test") && bRet; + UInt64 seqUHyperRet[] = xBT2->setSequenceUHyper(arUHyper); + bRet = check( compareData(seqUHyperRet, arUHyper), "sequence test") && bRet; + Object* seqObjectRet[] = xBT2->setSequenceXInterface(arObject); + bRet = check( compareData(seqObjectRet, arObject), "sequence test") && bRet; + String* seqStringRet[] = xBT2->setSequenceString(arString); + bRet = check( compareData(seqStringRet, arString), "sequence test") && bRet; + TestElement* seqStructRet[] = xBT2->setSequenceStruct(arStruct); + bRet = check( compareData(seqStructRet, arStruct), "sequence test") && bRet; + } + { +// Boolean arBoolTemp[] = static_cast<Boolean[]>( arBool->Clone()); +// Char arCharTemp[] = static_cast<Char[]>(arChar->Clone()); +// Byte arByteTemp[] = static_cast<Byte[]>(arByte->Clone()); +// Int16 arShortTemp[] = static_cast<Int16[]>(arShort->Clone()); +// UInt16 arUShortTemp[] = static_cast<UInt16[]>(arUShort->Clone()); +// Int32 arLongTemp[] = static_cast<Int32[]>(arLong->Clone()); +// UInt32 arULongTemp[] = static_cast<UInt32[]>(arULong->Clone()); +// Int64 arHyperTemp[] = static_cast<Int64[]>(arHyper->Clone()); +// UInt64 arUHyperTemp[] = static_cast<UInt64[]>(arUHyper->Clone()); +// Single arFloatTemp[] = static_cast<Single[]>(arFloat->Clone()); +// Double arDoubleTemp[] = static_cast<Double[]>(arDouble->Clone()); +// TestEnum arEnumTemp[] = static_cast<TestEnum[]>(arEnum->Clone()); +// String* arStringTemp[] = static_cast<String*[]>(arString->Clone()); +// Object* arObjectTemp = static_cast<Object*[]>(arObject->Clone()); +// Any arAnyTemp[] = static_cast<Any[]>(arAny->Clone()); +// // make sure this are has the same contents as arLong3[0] +// int[][] arLong2Temp = new int[][]{new int[]{1,2,3},new int[]{4,5,6}, new int[]{7,8,9} }; +// // make sure this are has the same contents as arLong3 +// int[][][] arLong3Temp = new int[][][]{ +// new int[][]{new int[]{1,2,3},new int[]{4,5,6}, new int[]{7,8,9} }, +// new int [][]{new int[]{1,2,3},new int[]{4,5,6}, new int[]{7,8,9}}, +// new int[][]{new int[]{1,2,3},new int[]{4,5,6}, new int[]{7,8,9}}}; + Console::WriteLine(new String("cli_cpp_bridgetest: no test of " + "XBridgeTest2::setSequencesInOut and XBridgeTest2.setSequencesOut " + "because jagged arrays are not supported by C++ compiler")); +// xBT2->setSequencesInOut(& arBoolTemp, & arCharTemp, & arByteTemp, +// & arShortTemp, & arUShortTemp, & arLongTemp, +// & arULongTemp,& arHyperTemp, & arUHyperTemp, +// & arFloatTemp,& arDoubleTemp, & arEnumTemp, +// & arStringTemp, & arObjectTemp, +// & arAnyTemp, & arLong2Temp, & arLong3Temp); +// bRet = check( +// compareData(arBoolTemp, arBool) && +// compareData(arCharTemp , arChar) && +// compareData(arByteTemp , arByte) && +// compareData(arShortTemp , arShort) && +// compareData(arUShortTemp , arUShort) && +// compareData(arLongTemp , arLong) && +// compareData(arULongTemp , arULong) && +// compareData(arHyperTemp , arHyper) && +// compareData(arUHyperTemp , arUHyper) && +// compareData(arFloatTemp , arFloat) && +// compareData(arDoubleTemp , arDouble) && +// compareData(arEnumTemp , arEnum) && +// compareData(arStringTemp , arString) && +// compareData(arObjectTemp , arObject) && +// compareData(arAnyTemp , arAny) && +// compareData(arLong2Temp , arLong3[0]) && +// compareData(arLong3Temp , arLong3), "sequence test") && bRet; + + //Boolean arBoolOut[]; + //Char arCharOut[]; + //Byte arByteOut[]; + //Int16 arShortOut[]; + //UInt16 arUShortOut[]; + //Int32 arLongOut[]; + //UInt32 arULongOut[]; + //Int64 arHyperOut[]; + //UInt64 arUHyperOut[]; + //Single arFloatOut[]; + //Double arDoubleOut[]; + //TestEnum arEnumOut[]; + //String* arStringOut[]; + //Object* arObjectOut[]; + //Any arAnyOut[]; +// int[][] arLong2Out; +// int[][][] arLong3Out; + +// xBT2->setSequencesOut(out arBoolOut, out arCharOut, out arByteOut, +// out arShortOut, out arUShortOut, out arLongOut, +// out arULongOut, out arHyperOut, out arUHyperOut, +// out arFloatOut, out arDoubleOut, out arEnumOut, +// out arStringOut, out arObjectOut, out arAnyOut, +// out arLong2Out, out arLong3Out); +// bRet = check( +// compareData(arBoolOut, arBool) && +// compareData(arCharOut, arChar) && +// compareData(arByteOut, arByte) && +// compareData(arShortOut, arShort) && +// compareData(arUShortOut, arUShort) && +// compareData(arLongOut, arLong) && +// compareData(arULongOut, arULong) && +// compareData(arHyperOut, arHyper) && +// compareData(arUHyperOut, arUHyper) && +// compareData(arFloatOut, arFloat) && +// compareData(arDoubleOut, arDouble) && +// compareData(arEnumOut, arEnum) && +// compareData(arStringOut, arString) && +// compareData(arObjectOut, arObject) && +// compareData(arAnyOut, arAny) && +// compareData(arLong2Out, arLong3[0]) && +// compareData(arLong3Out, arLong3), "sequence test") && bRet; + } + { + //test with empty sequences + // int[][] _arLong2 = new int[0][]; +// int[][] seqSeqRet = xBT2->setDim2(_arLong2); +// bRet = check( compareData(seqSeqRet, _arLong2), "sequence test") && bRet; +// int[][][] _arLong3 = new int[0][][]; +// int[][][] seqSeqRet2 = xBT2->setDim3(_arLong3); +// bRet = check( compareData(seqSeqRet2, _arLong3), "sequence test") && bRet; + Any _arAny[] = new Any[0]; + Any seqAnyRet[] = xBT2->setSequenceAny(_arAny); + bRet = check( compareData(seqAnyRet, _arAny), "sequence test") && bRet; + Boolean _arBool[] = new Boolean[0]; + Boolean seqBoolRet[] = xBT2->setSequenceBool(_arBool); + bRet = check( compareData(seqBoolRet, _arBool), "sequence test") && bRet; + Byte _arByte[] = new Byte[0]; + Byte seqByteRet[] = xBT2->setSequenceByte(_arByte); + bRet = check( compareData(seqByteRet, _arByte), "sequence test") && bRet; + Char _arChar[] = new Char[0]; + Char seqCharRet[] = xBT2->setSequenceChar(_arChar); + bRet = check( compareData(seqCharRet, _arChar), "sequence test") && bRet; + Int16 _arShort[] = new Int16[0]; + Int16 seqShortRet[] = xBT2->setSequenceShort(_arShort); + bRet = check( compareData(seqShortRet, _arShort), "sequence test") && bRet; + Int32 _arLong[] = new Int32[0]; + Int32 seqLongRet[] = xBT2->setSequenceLong(_arLong); + bRet = check( compareData(seqLongRet, _arLong), "sequence test") && bRet; + Int64 _arHyper[] = new Int64[0]; + Int64 seqHyperRet[] = xBT2->setSequenceHyper(_arHyper); + bRet = check( compareData(seqHyperRet, _arHyper), "sequence test") && bRet; + Single _arFloat[] = new Single[0]; + Single seqFloatRet[] = xBT2->setSequenceFloat(_arFloat); + bRet = check( compareData(seqFloatRet, _arFloat), "sequence test") && bRet; + Double _arDouble[] = new Double[0]; + Double seqDoubleRet[] = xBT2->setSequenceDouble(_arDouble); + bRet = check( compareData(seqDoubleRet, _arDouble), "sequence test") && bRet; + TestEnum _arEnum[] = new TestEnum[0]; + xBT2->setSequenceEnum(_arEnum); +// compiler bug: _arEnum has type System.Enum and not TestEnum +// bRet = check( compareData(seqEnumRet, _arEnum), "sequence test") && bRet; + UInt16 _arUShort[] = new UInt16[0]; + UInt16 seqUShortRet[] = xBT2->setSequenceUShort(_arUShort); + bRet = check( compareData(seqUShortRet, _arUShort), "sequence test") && bRet; + UInt32 _arULong[] = new UInt32[0]; + UInt32 seqULongRet[] = xBT2->setSequenceULong(_arULong); + bRet = check( compareData(seqULongRet, _arULong), "sequence test") && bRet; + UInt64 _arUHyper[] = new UInt64[0]; + UInt64 seqUHyperRet[] = xBT2->setSequenceUHyper(_arUHyper); + bRet = check( compareData(seqUHyperRet, _arUHyper), "sequence test") && bRet; + Object* _arObject[] = new Object*[0]; + Object* seqObjectRet[] = xBT2->setSequenceXInterface(_arObject); + bRet = check( compareData(seqObjectRet, _arObject), "sequence test") && bRet; + String* _arString[] = new String*[0]; + String* seqStringRet[] = xBT2->setSequenceString(_arString); + bRet = check( compareData(seqStringRet, _arString), "sequence test") && bRet; + TestElement* _arStruct[] = new TestElement*[0]; + TestElement* seqStructRet[] = xBT2->setSequenceStruct(_arStruct); + bRet = check( compareData(seqStructRet, _arStruct), "sequence test") && bRet; + + } + return bRet; +} +/** Test the System::Object method on the proxy object + */ +static bool testObjectMethodsImplemention(XBridgeTest* xLBT) +{ + bool ret = false; + Object* obj = new Object(); + XBridgeTestBase* xBase = dynamic_cast<XBridgeTestBase*>(xLBT); + if (xBase == 0) + return false; + // Object.Equals + ret = xLBT->Equals(obj) == false; + ret = xLBT->Equals(xLBT) && ret; + ret = Object::Equals(obj, obj) && ret; + ret = Object::Equals(xLBT, xBase) && ret; + //Object.GetHashCode + // Don't know how to verify this. Currently it is not possible to get the object id from a proxy + int nHash = xLBT->GetHashCode(); + ret = nHash == xBase->GetHashCode() && ret; + + //Object.ToString + // Don't know how to verify this automatically. + String* s = xLBT->ToString(); + ret = (s->Length > 0) && ret; + return ret; +} + + +static bool raiseOnewayException(XBridgeTest* xLBT) +{ + bool bReturn = true; + String* sCompare = Constants::STRING_TEST_CONSTANT; + 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->Interface ); + } + catch (RuntimeException* e ) + { + bReturn = ( xLBT->Interface == e->Context ); + } + return bReturn; +} + +// //================================================================================================== +static bool raiseException(XBridgeTest* xLBT ) +{ + int nCount = 0; + try + { + try + { + try + { + xLBT->raiseException( + 5, Constants::STRING_TEST_CONSTANT, xLBT->Interface ); + } + catch (unoidl::com::sun::star::lang::IllegalArgumentException* aExc) + { + if (aExc->ArgumentPosition == 5 && + aExc->Context == xLBT->Interface) + { + ++nCount; + } + else + { + check( false, "### unexpected exception content!" ); + } + + /** it is certain, that the RuntimeException testing will fail, + if no */ + xLBT->RuntimeException = 0; + } + } + catch (unoidl::com::sun::star::uno::RuntimeException* rExc) + { + if (rExc->Context == xLBT->Interface ) + { + ++nCount; + } + else + { + check( false, "### unexpected exception content!" ); + } + + /** it is certain, that the RuntimeException testing will fail, if no */ + xLBT->RuntimeException = (int) 0xcafebabe; + } + } + catch (unoidl::com::sun::star::uno::Exception* rExc) + { + if (rExc->Context == xLBT->Interface) + { + ++nCount; + } + else + + { + check( false, "### unexpected exception content!" ); + } + return (nCount == 3); + } + return false; +} + + static private void perform_test( XBridgeTest* xLBT ) + { + bool bRet= true;; + bRet = check( performTest( xLBT ), "standard test" ) && bRet; + bRet = check( raiseException( xLBT ) , "exception test" )&& bRet; + bRet = check( raiseOnewayException( xLBT ), "oneway exception test" ) && bRet; + bRet = check( testObjectMethodsImplemention(xLBT), "object methods test") && bRet; + bRet = performQueryForUnknownType( xLBT ) && bRet; + if (! bRet) + { + throw new unoidl::com::sun::star::uno::RuntimeException( + new String("error: test failed!"), 0); + } + } + XComponentContext* m_xContext; + + public: + BridgeTest( XComponentContext* xContext ) + { + m_xContext = xContext; + } + + + + int run( String* args[] ) + { + try + { + if (args->Length < 1) + { + throw new RuntimeException( + "missing argument for bridgetest!", this ); + } + Object* test_obj = + m_xContext->getServiceManager()->createInstanceWithContext( + args[ 0 ], m_xContext ); + if (test_obj == 0) + test_obj = m_xContext->getValueByName( args[ 0 ] ).Value; + + Console::WriteLine( + "cli target bridgetest obj: {0}", test_obj->ToString() ); + XBridgeTest* xTest = __try_cast<XBridgeTest*>(test_obj) ; + perform_test( xTest ); + Console::WriteLine( "\n### cli_uno C++ bridgetest succeeded." ); + return 0; + } + catch (unoidl::com::sun::star::uno::RuntimeException* ) + { + throw; + } + catch (System::Exception* exc) + { + System::Text::StringBuilder* s = new System::Text::StringBuilder(); + s->Append(S"cli_cpp_bridgetest: unexpected exception occured in XMain::run. Original exception: "); + s->Append(exc->GetType()->Name); + s->Append(S"\n Message: "); + s->Append(exc->Message); + throw new unoidl::com::sun::star::uno::RuntimeException( + s->ToString(), 0); + } + } +}; + +} diff --git a/testtools/source/bridgetest/cli/cli_cs_bridgetest.cs b/testtools/source/bridgetest/cli/cli_cs_bridgetest.cs new file mode 100644 index 000000000000..8872968e1764 --- /dev/null +++ b/testtools/source/bridgetest/cli/cli_cs_bridgetest.cs @@ -0,0 +1,1033 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +using System; +using System.Diagnostics; +using System.Reflection; +using uno; +using uno.util; +using unoidl.com.sun.star.uno; +using unoidl.com.sun.star.lang; +//using unoidl.com.sun.star.test.bridge; +using unoidl.test.testtools.bridgetest; + +namespace foo +{ + public interface MyInterface + { + } +} + +namespace cs_testobj +{ + class ORecursiveCall: WeakBase, XRecursiveCall + { + public void callRecursivly(XRecursiveCall xCall, int nToCall) + { + lock (this) + { + if (nToCall > 0) + { + nToCall --; + xCall.callRecursivly(this, nToCall); + } + } + } + }; + +class Constants +{ + public const string STRING_TEST_CONSTANT = "\" paco\' chorizo\\\' \"\'"; +} + +public class BridgeTest : WeakBase, XMain +{ + static bool compareData(Object val1, Object val2) + { + if (val1 == null && val2 == null || val1 == val2) + return true; + if ((val1 == null && val2 != null) || + (val1 != null && val2 == null) || val1.GetType() != val2.GetType()) + return false; + + bool ret = false; + Type t1 = val1.GetType(); + //Sequence + if (t1.IsArray) + { + ret = compareSequence((Array) val1, (Array) val2); + } + //String + else if (t1 == typeof(string)) + { + ret = (string) val1 == (string) val2; + } + // Interface implementation + else if (t1.GetInterfaces().Length > 0 && ! t1.IsValueType) + { + ret = val1 == val2; + } + // Struct + else if ( ! t1.IsValueType) + { + ret = compareStruct(val1, val2); + } + else if (t1 == typeof(Any)) + { + Any a1 = (Any) val1; + Any a2 = (Any) val2; + ret = a1.Type == a2.Type && compareData(a1.Value, a2.Value); + } + else if (t1.IsValueType) + { + //Any, enum, int, bool char, float, double etc. + ret = val1.Equals(val2); + } + else + { + Debug.Assert(false); + } + return ret; + } + + // Arrays have only one dimension + static bool compareSequence(Array ar1, Array ar2) + { + Debug.Assert(ar1 != null && ar2 != null); + Type t1 = ar1.GetType(); + Type t2 = ar2.GetType(); + + if (!(ar1.Rank == 1 && ar2.Rank == 1 + && ar1.Length == ar2.Length && t1.GetElementType() == t2.GetElementType())) + return false; + + //arrays have same rank and size and element type. + int len = ar1.Length; + Type elemType = t1.GetElementType(); + bool ret = true; + for (int i = 0; i < len; i++) + { + if (compareData(ar1.GetValue(i), ar2.GetValue(i)) == false) + { + ret = false; + break; + } + } + return ret; + } + + static bool compareStruct(Object val1, Object val2) + { + Debug.Assert(val1 != null && val2 != null); + Type t1 = val1.GetType(); + Type t2 = val2.GetType(); + if (t1 != t2) + return false; + FieldInfo[] fields = t1.GetFields(); + int cFields = fields.Length; + bool ret = true; + for (int i = 0; i < cFields; i++) + { + Object fieldVal1 = fields[i].GetValue(val1); + Object fieldVal2 = fields[i].GetValue(val2); + if ( ! compareData(fieldVal1, fieldVal2)) + { + ret = false; + break; + } + } + return ret; + } + + static bool check( bool b , string message ) + { + if ( ! b) + Console.WriteLine("{0} failed\n" , message); + return b; + } + + static bool equals(TestElement rData1, TestElement rData2) + { + check( rData1.Bool == rData2.Bool, "### bool does not match!" ); + check( rData1.Char == rData2.Char, "### char does not match!" ); + check( rData1.Byte == rData2.Byte, "### byte does not match!" ); + check( rData1.Short == rData2.Short, "### short does not match!" ); + check( rData1.UShort == rData2.UShort, "### unsigned short does not match!" ); + check( rData1.Long == rData2.Long, "### long does not match!" ); + check( rData1.ULong == rData2.ULong, "### unsigned long does not match!" ); + check( rData1.Hyper == rData2.Hyper, "### hyper does not match!" ); + check( rData1.UHyper == rData2.UHyper, "### unsigned hyper does not match!" ); + check( rData1.Float == rData2.Float, "### float does not match!" ); + check( rData1.Double == rData2.Double, "### double does not match!" ); + check( rData1.Enum == rData2.Enum, "### enum does not match!" ); + check( rData1.String == rData2.String, "### string does not match!" ); + check( rData1.Interface == rData2.Interface, "### interface does not match!" ); + check( compareData(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 && + compareData(rData1.Any, rData2.Any)); + } + +static void assign( TestElement rData, + bool bBool, char cChar, byte nByte, + short nShort, ushort nUShort, + int nLong, uint nULong, + long nHyper, ulong nUHyper, + float fFloat, double fDouble, + TestEnum eEnum, string rStr, + Object xTest, + 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( TestDataElements rData, + bool bBool, char cChar, byte nByte, + short nShort, ushort nUShort, + int nLong, uint nULong, + long nHyper, ulong nUHyper, + float fFloat, double fDouble, + TestEnum eEnum, string rStr, + Object xTest, + Any rAny, + 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 bool testAny(Type typ, Object value, XBridgeTest xLBT ) +{ + Any any; + if (typ == null) + any = new Any(value.GetType(), value); + else + any = new Any(typ, value); + + Any any2 = xLBT.transportAny(any); + bool ret; + if( ! (ret= compareData(any, any2))) + { + Console.WriteLine("any is different after roundtrip: in {0}, out {1}\n", + any.Type.FullName, any2.Type.FullName); + } + return ret; +} + + + +static bool performAnyTest(XBridgeTest xLBT, TestDataElements data) +{ + bool bReturn = true; + bReturn = testAny( null, data.Byte ,xLBT ) && bReturn; + bReturn = testAny( null, data.Short,xLBT ) && bReturn; + bReturn = testAny( null, data.UShort,xLBT ) && bReturn; + bReturn = testAny( null, data.Long,xLBT ) && bReturn; + bReturn = testAny( null, data.ULong,xLBT ) && bReturn; + bReturn = testAny( null, data.Hyper,xLBT ) && bReturn; + bReturn = testAny( null,data.UHyper,xLBT ) && bReturn; + bReturn = testAny( null, data.Float,xLBT ) && bReturn; + bReturn = testAny( null, data.Double,xLBT ) && bReturn; + bReturn = testAny( null, data.Enum,xLBT ) && bReturn; + bReturn = testAny( null, data.String,xLBT ) && bReturn; + bReturn = testAny(typeof(XWeak), data.Interface,xLBT ) && bReturn; + bReturn = testAny(null, data, xLBT ) && bReturn; + + { + Any a1= new Any(true); + Any a2 = xLBT.transportAny( a1 ); + bReturn = compareData(a2, a1) && bReturn; + } + + { + Any a1= new Any('A'); + Any a2 = xLBT.transportAny(a1); + bReturn = compareData(a2, a1) && bReturn; + } + return bReturn; +} + +static bool performSequenceOfCallTest(XBridgeTest xLBT) +{ + int i,nRounds; + int nGlobalIndex = 0; + const int 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(); +} + + + + +static bool performRecursiveCallTest(XBridgeTest xLBT) +{ + xLBT.startRecursiveCall(new ORecursiveCall(), 50); + // on failure, the test would lock up or crash + return true; +} + +static bool performQueryForUnknownType(XBridgeTest xLBT) +{ + bool bRet = false; + // test queryInterface for an unknown type + try + { + foo.MyInterface a = (foo.MyInterface) xLBT; + } + catch( System.InvalidCastException) + { + bRet = true; + } + + return bRet; +} + +// //================================================================================================== +bool performTest(XBridgeTest xLBT) +{ + check( xLBT != null, "### no test interface!" ); + bool bRet = true; + if (xLBT == null) + return false; + + // this data is never ever granted access to by calls other than equals(), assign()! + TestDataElements aData = new TestDataElements(); // test against this data + + Object xI= new WeakBase(); + + Any aAny = new Any( typeof(Object), xI); + assign( (TestElement)aData, + true, '@', 17, 0x1234, 0xfedc, 0x12345678, 0xfedcba98, + 0x123456789abcdef0, 0xfedcba9876543210, + 17.0815f, 3.1415926359, TestEnum.LOLA, + Constants.STRING_TEST_CONSTANT, xI, + aAny); + + bRet = check( aData.Any.Value == xI, "### unexpected any!" ) && bRet; + bRet = check( !(aData.Any.Value != xI), "### unexpected any!" ) && bRet; + + aData.Sequence = new TestElement[2]; + aData.Sequence[0] = new TestElement( + 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, + aData.Interface, aData.Any); //(TestElement) aData; + aData.Sequence[1] = new TestElement(); //is empty + + // aData complete + // + // this is a manually copy of aData for first setting... + TestDataElements aSetData = new TestDataElements(); + Any aAnySet= new Any(typeof(Object), xI); + 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, + aAnySet); + + aSetData.Sequence = new TestElement[2]; + aSetData.Sequence[0] = new TestElement( + 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); //TestElement) aSetData; + aSetData.Sequence[1] = new TestElement(); // empty struct + + 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 ); + + { + TestDataElements aRet = new TestDataElements(); + TestDataElements aRet2 = new TestDataElements(); + xLBT.getValues( + out aRet.Bool, out aRet.Char, out aRet.Byte, out aRet.Short, out aRet.UShort, + out aRet.Long, out aRet.ULong, out aRet.Hyper, out aRet.UHyper, + out aRet.Float, out aRet.Double, out aRet.Enum, out aRet.String, + out aRet.Interface, out aRet.Any, out aRet.Sequence, out aRet2 ); + + bRet = check( compareData( aData, aRet ) && compareData( aData, aRet2 ) , "getValues test") && bRet; + + // set last retrieved values + TestDataElements aSV2ret = xLBT.setValues2( + ref aRet.Bool, ref aRet.Char, ref aRet.Byte, ref aRet.Short, ref aRet.UShort, + ref aRet.Long, ref aRet.ULong, ref aRet.Hyper, ref aRet.UHyper, ref aRet.Float, + ref aRet.Double, ref aRet.Enum, ref aRet.String, ref aRet.Interface, ref aRet.Any, + ref aRet.Sequence, ref aRet2 ); + + // check inout sequence order + // => inout sequence parameter was switched by test objects + TestElement temp = aRet.Sequence[ 0 ]; + aRet.Sequence[ 0 ] = aRet.Sequence[ 1 ]; + aRet.Sequence[ 1 ] = temp; + + bRet = check( + compareData( aData, aSV2ret ) && compareData( aData, aRet2 ), + "getValues2 test") && bRet; + } + { + TestDataElements aRet = new TestDataElements(); + TestDataElements aRet2 = new TestDataElements(); + TestDataElements aGVret = xLBT.getValues( + out aRet.Bool, out aRet.Char, out aRet.Byte, out aRet.Short, + out aRet.UShort, out aRet.Long, out aRet.ULong, out aRet.Hyper, + out aRet.UHyper, out aRet.Float, out aRet.Double, out aRet.Enum, + out aRet.String, out aRet.Interface, out aRet.Any, out aRet.Sequence, + out aRet2 ); + + bRet = check( compareData( aData, aRet ) && compareData( aData, aRet2 ) && compareData( aData, aGVret ), "getValues test" ) && bRet; + + // set last retrieved values + xLBT.Bool = aRet.Bool; + xLBT.Char = aRet.Char; + xLBT.Byte = aRet.Byte; + xLBT.Short = aRet.Short; + xLBT.UShort = aRet.UShort; + xLBT.Long = aRet.Long; + xLBT.ULong = aRet.ULong; + xLBT.Hyper = aRet.Hyper; + xLBT.UHyper = aRet.UHyper; + xLBT.Float = aRet.Float; + xLBT.Double = aRet.Double; + xLBT.Enum = aRet.Enum; + xLBT.String = aRet.String; + xLBT.Interface = aRet.Interface; + xLBT.Any = aRet.Any; + xLBT.Sequence = aRet.Sequence; + xLBT.Struct = aRet2; + } + { + TestDataElements aRet = new TestDataElements(); + TestDataElements aRet2 = new TestDataElements(); + aRet.Hyper = xLBT.Hyper; + aRet.UHyper = xLBT.UHyper; + aRet.Float = xLBT.Float; + aRet.Double = xLBT.Double; + aRet.Byte = xLBT.Byte; + aRet.Char = xLBT.Char; + aRet.Bool = xLBT.Bool; + aRet.Short = xLBT.Short; + aRet.UShort = xLBT.UShort; + aRet.Long = xLBT.Long; + aRet.ULong = xLBT.ULong; + aRet.Enum = xLBT.Enum; + aRet.String = xLBT.String; + aRet.Interface = xLBT.Interface; + aRet.Any = xLBT.Any; + aRet.Sequence = xLBT.Sequence; + aRet2 = xLBT.Struct; + + bRet = check( compareData( aData, aRet ) && compareData( aData, aRet2 ) , "struct comparison test") && bRet; + + bRet = check(performSequenceTest(xLBT), "sequence test") && bRet; + + // any test + bRet = check( performAnyTest( xLBT , aData ) , "any test" ) && bRet; + + // sequence of call test + bRet = check( performSequenceOfCallTest( xLBT ) , "sequence of call test" ) && bRet; + + // recursive call test + bRet = check( performRecursiveCallTest( xLBT ) , "recursive test" ) && bRet; + + bRet = (compareData( aData, aRet ) && compareData( aData, aRet2 )) && bRet ; + + // check setting of null reference + xLBT.Interface = null; + aRet.Interface = xLBT.Interface; + bRet = (aRet.Interface == null) && bRet; + + } + // Test extended attributes that raise exceptions: + try { + int i = xLBT.RaiseAttr1; + bRet &= check(false, "getRaiseAttr1 did not throw"); + } catch (RuntimeException ) + { + } + catch (System.Exception) { + bRet &= check(false, "getRaiseAttr1 threw wrong type"); + } + try { + xLBT.RaiseAttr1 = 0; + bRet &= check(false, "setRaiseAttr1 did not throw"); + } catch (IllegalArgumentException) { + } catch (System.Exception) { + bRet &= check(false, "setRaiseAttr1 threw wrong type"); + } + try { + int i = xLBT.RaiseAttr2; + bRet &= check(false, "getRaiseAttr2 did not throw"); + } catch (IllegalArgumentException ) { + } catch (System.Exception) { + bRet &= check(false, "getRaiseAttr2 threw wrong type"); + } + + // Test instantiated polymorphic struct types: + { + TestPolyStruct poly = new TestPolyStruct(true); + bRet &= check( + (bool) xLBT.transportPolyBoolean(poly).member, + "transportPolyBoolean"); + poly = new TestPolyStruct(12345L); + xLBT.transportPolyHyper(ref poly); + bRet &= check((long)poly.member == 12345L, "transportPolyUnsignedHyper"); + + Any[] seq = { new Any(33), new Any("ABC")}; + poly = new TestPolyStruct(seq); + TestPolyStruct poly2; + xLBT.transportPolySequence(poly, out poly2); + try { + Any[] ar = (Any[]) poly2.member; + bRet &= check( + ar.Length == 2, "transportPolySequence, length"); + + int v0; + v0 = (int) ar[0].Value; + bRet &= check(v0 == 33, "transportPolySequence, element 0"); + + string v1 = (string) ar[1].Value; + bRet &= check( + v1.Equals("ABC"), + "transportPolySequence, element 1"); + } catch (InvalidCastException ) + { + bRet &= check(false, "transportPolySequence"); + } + + try { + //When the test object is a cli object then them member is null + //otherwise the bridge has provided a default value. + TestPolyStruct s = xLBT.getNullPolyLong(); + if (s.member != null) + bRet &= check(((int) s.member) == 0, "getNullPolyLong"); + + s = xLBT.getNullPolyString(); + if (s.member != null) + bRet &= check(((string) s.member).Length == 0, + "getNullPolyString"); + s = xLBT.getNullPolyType(); + if (s.member != null) + bRet &= check(((Type) s.member) == typeof(void), + "getNullPolyType"); + s = xLBT.getNullPolyAny(); + if (s.member != null) + { + Any nullAny = (Any) s.member; + //??? + bRet &= check(nullAny.Type == typeof(void), + "getNullPolyAny"); + } + s = xLBT.getNullPolySequence(); + if (s.member != null) + bRet &= check(((bool[]) s.member).Length == 0, + "getNullPolySequence"); + s = xLBT.getNullPolyEnum(); + if (s.member != null) + bRet &= check(((TestEnum) s.member) == TestEnum.TEST, + "getNullPolyEnum"); + s = xLBT.getNullPolyStruct(); + if (s.member != null) + bRet &= check(((TestStruct) s.member).member == 0, + "getNullPolyStruct"); + s = xLBT.getNullPolyInterface(); + bRet &= check(s.member == null, "getNullPolyInterface"); + + s = xLBT.getNullPolyBadEnum(); + bRet &= check(((TestBadEnum)s.member) == TestBadEnum.M, "getNullPolyBadEnum"); + + } catch(InvalidCastException) + { + bRet &= check(false, "getNullPolyXXX, InvalidCastException"); + } + + } + + XBridgeTest2 xBT2 = xLBT as XBridgeTest2; + if (xBT2 != null) { + try { + xBT2.testConstructorsService(m_xContext); + } catch (BadConstructorArguments) { + bRet = false; + } + } + + return bRet; +} +static bool performSequenceTest(XBridgeTest xBT) +{ + bool bRet = true; + XBridgeTest2 xBT2 = xBT as XBridgeTest2; + if ( xBT2 == null) + return false; + + // perform sequence tests (XBridgeTest2) + // create the sequence which are compared with the results + bool[] arBool = {true, false, true}; + char[] arChar = {'A','B','C'}; + byte[] arByte = { 1, 2, 0xff}; + short[] arShort = {Int16.MinValue, 1, Int16.MaxValue}; + UInt16[] arUShort = {UInt16.MinValue , 1, UInt16.MaxValue}; + int[] arLong = {Int32.MinValue, 1, Int32.MaxValue}; + UInt32[] arULong = {UInt32.MinValue, 1, UInt32.MaxValue}; + long[] arHyper = {Int64.MinValue, 1, Int64.MaxValue}; + UInt64[] arUHyper = {UInt64.MinValue, 1, UInt64.MaxValue}; + float[] arFloat = {1.1f, 2.2f, 3.3f}; + double[] arDouble = {1.11, 2.22, 3.33}; + string[] arString = {"String 1", "String 2", "String 3"}; + + Any[] arAny = {new Any(true), new Any(11111), new Any(3.14)}; + Object[] arObject = {new WeakBase(), new WeakBase(), new WeakBase()}; + TestEnum[] arEnum = {TestEnum.ONE, TestEnum.TWO, TestEnum.CHECK}; + + TestElement[] arStruct = {new TestElement(), new TestElement(), + new TestElement()}; + assign( arStruct[0], true, '@', 17, 0x1234, 0xfedc, 0x12345678, 0xfedcba98, + 0x123456789abcdef0, 0xfedcba9876543210, 17.0815f, 3.1415926359, + TestEnum.LOLA, Constants.STRING_TEST_CONSTANT, arObject[0], + new Any( typeof(Object), arObject[0]) ); + assign( arStruct[1], true, 'A', 17, 0x1234, 0xfedc, 0x12345678, 0xfedcba98, + 0x123456789abcdef0, 0xfedcba9876543210, 17.0815f, 3.1415926359, + TestEnum.TWO, Constants.STRING_TEST_CONSTANT, arObject[1], + new Any( typeof(Object), arObject[1]) ); + assign( arStruct[2], true, 'B', 17, 0x1234, 0xfedc, 0x12345678, 0xfedcba98, + 0x123456789abcdef0, 0xfedcba9876543210, 17.0815f, 3.1415926359, + TestEnum.CHECK, Constants.STRING_TEST_CONSTANT, arObject[2], + new Any( typeof(Object), arObject[2] ) ); + + + int[][][] arLong3 = new int[][][]{ + new int[][]{new int[]{1,2,3},new int[]{4,5,6}, new int[]{7,8,9} }, + new int [][]{new int[]{1,2,3},new int[]{4,5,6}, new int[]{7,8,9}}, + new int[][]{new int[]{1,2,3},new int[]{4,5,6}, new int[]{7,8,9}}}; + + { + int[][] seqSeqRet = xBT2.setDim2(arLong3[0]); + bRet = check( compareData(seqSeqRet, arLong3[0]), "sequence test") && bRet; + int[][][] seqSeqRet2 = xBT2.setDim3(arLong3); + bRet = check( compareData(seqSeqRet2, arLong3), "sequence test") && bRet; + Any[] seqAnyRet = xBT2.setSequenceAny(arAny); + bRet = check( compareData(seqAnyRet, arAny), "sequence test") && bRet; + bool[] seqBoolRet = xBT2.setSequenceBool(arBool); + bRet = check( compareData(seqBoolRet, arBool), "sequence test") && bRet; + byte[] seqByteRet = xBT2.setSequenceByte(arByte); + bRet = check( compareData(seqByteRet, arByte), "sequence test") && bRet; + char[] seqCharRet = xBT2.setSequenceChar(arChar); + bRet = check( compareData(seqCharRet, arChar), "sequence test") && bRet; + short[] seqShortRet = xBT2.setSequenceShort(arShort); + bRet = check( compareData(seqShortRet, arShort), "sequence test") && bRet; + int[] seqLongRet = xBT2.setSequenceLong(arLong); + bRet = check( compareData(seqLongRet, arLong), "sequence test") && bRet; + long[] seqHyperRet = xBT2.setSequenceHyper(arHyper); + bRet = check( compareData(seqHyperRet,arHyper), "sequence test") && bRet; + float[] seqFloatRet = xBT2.setSequenceFloat(arFloat); + bRet = check( compareData(seqFloatRet, arFloat), "sequence test") && bRet; + double[] seqDoubleRet = xBT2.setSequenceDouble(arDouble); + bRet = check( compareData(seqDoubleRet, arDouble), "sequence test") && bRet; + TestEnum[] seqEnumRet = xBT2.setSequenceEnum(arEnum); + bRet = check( compareData(seqEnumRet, arEnum), "sequence test") && bRet; + UInt16[] seqUShortRet = xBT2.setSequenceUShort(arUShort); + bRet = check( compareData(seqUShortRet, arUShort), "sequence test") && bRet; + UInt32[] seqULongRet = xBT2.setSequenceULong(arULong); + bRet = check( compareData(seqULongRet, arULong), "sequence test") && bRet; + UInt64[] seqUHyperRet = xBT2.setSequenceUHyper(arUHyper); + bRet = check( compareData(seqUHyperRet, arUHyper), "sequence test") && bRet; + Object[] seqObjectRet = xBT2.setSequenceXInterface(arObject); + bRet = check( compareData(seqObjectRet, arObject), "sequence test") && bRet; + string[] seqStringRet = xBT2.setSequenceString(arString); + bRet = check( compareData(seqStringRet, arString), "sequence test") && bRet; + TestElement[] seqStructRet = xBT2.setSequenceStruct(arStruct); + bRet = check( compareData(seqStructRet, arStruct), "sequence test") && bRet; + } + { + bool[] arBoolTemp = (bool[]) arBool.Clone(); + char[] arCharTemp = (char[]) arChar.Clone(); + byte[] arByteTemp = (byte[]) arByte.Clone(); + short[] arShortTemp = (short[]) arShort.Clone(); + UInt16[] arUShortTemp = (UInt16[]) arUShort.Clone(); + int[] arLongTemp = (int[]) arLong.Clone(); + UInt32[] arULongTemp = (UInt32[]) arULong.Clone(); + long[] arHyperTemp = (long[]) arHyper.Clone(); + UInt64[] arUHyperTemp = (UInt64[]) arUHyper.Clone(); + float[] arFloatTemp = (float[]) arFloat.Clone(); + double[] arDoubleTemp = (double[]) arDouble.Clone(); + TestEnum[] arEnumTemp = (TestEnum[]) arEnum.Clone(); + string[] arStringTemp = (string[]) arString.Clone(); + Object[] arObjectTemp = (Object[]) arObject.Clone(); + Any[] arAnyTemp = (Any[]) arAny.Clone(); + // make sure this are has the same contents as arLong3[0] + int[][] arLong2Temp = new int[][]{new int[]{1,2,3},new int[]{4,5,6}, new int[]{7,8,9} }; + // make sure this are has the same contents as arLong3 + int[][][] arLong3Temp = new int[][][]{ + new int[][]{new int[]{1,2,3},new int[]{4,5,6}, new int[]{7,8,9} }, + new int [][]{new int[]{1,2,3},new int[]{4,5,6}, new int[]{7,8,9}}, + new int[][]{new int[]{1,2,3},new int[]{4,5,6}, new int[]{7,8,9}}}; + + xBT2.setSequencesInOut(ref arBoolTemp, ref arCharTemp, ref arByteTemp, + ref arShortTemp, ref arUShortTemp, ref arLongTemp, + ref arULongTemp,ref arHyperTemp, ref arUHyperTemp, + ref arFloatTemp,ref arDoubleTemp, ref arEnumTemp, + ref arStringTemp, ref arObjectTemp, + ref arAnyTemp, ref arLong2Temp, ref arLong3Temp); + bRet = check( + compareData(arBoolTemp, arBool) && + compareData(arCharTemp , arChar) && + compareData(arByteTemp , arByte) && + compareData(arShortTemp , arShort) && + compareData(arUShortTemp , arUShort) && + compareData(arLongTemp , arLong) && + compareData(arULongTemp , arULong) && + compareData(arHyperTemp , arHyper) && + compareData(arUHyperTemp , arUHyper) && + compareData(arFloatTemp , arFloat) && + compareData(arDoubleTemp , arDouble) && + compareData(arEnumTemp , arEnum) && + compareData(arStringTemp , arString) && + compareData(arObjectTemp , arObject) && + compareData(arAnyTemp , arAny) && + compareData(arLong2Temp , arLong3[0]) && + compareData(arLong3Temp , arLong3), "sequence test") && bRet; + + bool[] arBoolOut; + char[] arCharOut; + byte[] arByteOut; + short[] arShortOut; + UInt16[] arUShortOut; + int[] arLongOut; + UInt32[] arULongOut; + long[] arHyperOut; + UInt64[] arUHyperOut; + float[] arFloatOut; + double[] arDoubleOut; + TestEnum[] arEnumOut; + string[] arStringOut; + Object[] arObjectOut; + Any[] arAnyOut; + int[][] arLong2Out; + int[][][] arLong3Out; + + xBT2.setSequencesOut(out arBoolOut, out arCharOut, out arByteOut, + out arShortOut, out arUShortOut, out arLongOut, + out arULongOut, out arHyperOut, out arUHyperOut, + out arFloatOut, out arDoubleOut, out arEnumOut, + out arStringOut, out arObjectOut, out arAnyOut, + out arLong2Out, out arLong3Out); + bRet = check( + compareData(arBoolOut, arBool) && + compareData(arCharOut, arChar) && + compareData(arByteOut, arByte) && + compareData(arShortOut, arShort) && + compareData(arUShortOut, arUShort) && + compareData(arLongOut, arLong) && + compareData(arULongOut, arULong) && + compareData(arHyperOut, arHyper) && + compareData(arUHyperOut, arUHyper) && + compareData(arFloatOut, arFloat) && + compareData(arDoubleOut, arDouble) && + compareData(arEnumOut, arEnum) && + compareData(arStringOut, arString) && + compareData(arObjectOut, arObject) && + compareData(arAnyOut, arAny) && + compareData(arLong2Out, arLong3[0]) && + compareData(arLong3Out, arLong3), "sequence test") && bRet; + } + { + //test with empty sequences + int[][] _arLong2 = new int[0][]; + int[][] seqSeqRet = xBT2.setDim2(_arLong2); + bRet = check( compareData(seqSeqRet, _arLong2), "sequence test") && bRet; + int[][][] _arLong3 = new int[0][][]; + int[][][] seqSeqRet2 = xBT2.setDim3(_arLong3); + bRet = check( compareData(seqSeqRet2, _arLong3), "sequence test") && bRet; + Any[] _arAny = new Any[0]; + Any[] seqAnyRet = xBT2.setSequenceAny(_arAny); + bRet = check( compareData(seqAnyRet, _arAny), "sequence test") && bRet; + bool[] _arBool = new bool[0]; + bool[] seqBoolRet = xBT2.setSequenceBool(_arBool); + bRet = check( compareData(seqBoolRet, _arBool), "sequence test") && bRet; + byte[] _arByte = new byte[0]; + byte[] seqByteRet = xBT2.setSequenceByte(_arByte); + bRet = check( compareData(seqByteRet, _arByte), "sequence test") && bRet; + char[] _arChar = new char[0]; + char[] seqCharRet = xBT2.setSequenceChar(_arChar); + bRet = check( compareData(seqCharRet, _arChar), "sequence test") && bRet; + short[] _arShort = new short[0]; + short[] seqShortRet = xBT2.setSequenceShort(_arShort); + bRet = check( compareData(seqShortRet, _arShort), "sequence test") && bRet; + int[] _arLong = new int[0]; + int[] seqLongRet = xBT2.setSequenceLong(_arLong); + bRet = check( compareData(seqLongRet, _arLong), "sequence test") && bRet; + long[] _arHyper = new long[0]; + long[] seqHyperRet = xBT2.setSequenceHyper(_arHyper); + bRet = check( compareData(seqHyperRet, _arHyper), "sequence test") && bRet; + float[] _arFloat = new float[0]; + float[] seqFloatRet = xBT2.setSequenceFloat(_arFloat); + bRet = check( compareData(seqFloatRet, _arFloat), "sequence test") && bRet; + double[] _arDouble = new double[0]; + double[] seqDoubleRet = xBT2.setSequenceDouble(_arDouble); + bRet = check( compareData(seqDoubleRet, _arDouble), "sequence test") && bRet; + TestEnum[] _arEnum = new TestEnum[0]; + TestEnum[] seqEnumRet = xBT2.setSequenceEnum(_arEnum); + bRet = check( compareData(seqEnumRet, _arEnum), "sequence test") && bRet; + UInt16[] _arUShort = new UInt16[0]; + UInt16[] seqUShortRet = xBT2.setSequenceUShort(_arUShort); + bRet = check( compareData(seqUShortRet, _arUShort), "sequence test") && bRet; + UInt32[] _arULong = new UInt32[0]; + UInt32[] seqULongRet = xBT2.setSequenceULong(_arULong); + bRet = check( compareData(seqULongRet, _arULong), "sequence test") && bRet; + UInt64[] _arUHyper = new UInt64[0]; + UInt64[] seqUHyperRet = xBT2.setSequenceUHyper(_arUHyper); + bRet = check( compareData(seqUHyperRet, _arUHyper), "sequence test") && bRet; + Object[] _arObject = new Object[0]; + Object[] seqObjectRet = xBT2.setSequenceXInterface(_arObject); + bRet = check( compareData(seqObjectRet, _arObject), "sequence test") && bRet; + string[] _arString = new string[0]; + string[] seqStringRet = xBT2.setSequenceString(_arString); + bRet = check( compareData(seqStringRet, _arString), "sequence test") && bRet; + TestElement[] _arStruct = new TestElement[0]; + TestElement[] seqStructRet = xBT2.setSequenceStruct(_arStruct); + bRet = check( compareData(seqStructRet, _arStruct), "sequence test") && bRet; + + } + + + return bRet; +} +/** Test the System::Object method on the proxy object + */ +static bool testObjectMethodsImplemention(XBridgeTest xLBT) +{ + bool ret = false; + Object obj = new Object(); + Object xInt = (Object) xLBT; + XBridgeTestBase xBase = xLBT as XBridgeTestBase; + if (xBase == null) + return false; + // Object.Equals + ret = xLBT.Equals(obj) == false; + ret = xLBT.Equals(xLBT) && ret; + ret = Object.Equals(obj, obj) && ret; + ret = Object.Equals(xLBT, xBase) && ret; + //Object.GetHashCode + // Don't know how to verify this. Currently it is not possible to get the object id from a proxy + int nHash = xLBT.GetHashCode(); + ret = nHash == xBase.GetHashCode() && ret; + + //Object.ToString + // Don't know how to verify this automatically. + string s = xLBT.ToString(); + ret = (s.Length > 0) && ret; + return ret; +} + + +static bool raiseOnewayException(XBridgeTest xLBT) +{ + bool bReturn = true; + string sCompare = Constants.STRING_TEST_CONSTANT; + 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.Interface ); + } + catch (RuntimeException e ) + { + bReturn = ( xLBT.Interface == e.Context ); + } + return bReturn; +} + +// //================================================================================================== +static bool raiseException(XBridgeTest xLBT ) +{ + int nCount = 0; + try + { + try + { + try + { + TestDataElements aRet = new TestDataElements(); + TestDataElements aRet2 = new TestDataElements(); + xLBT.raiseException( + 5, Constants.STRING_TEST_CONSTANT, xLBT.Interface ); + } + catch (unoidl.com.sun.star.lang.IllegalArgumentException aExc) + { + if (aExc.ArgumentPosition == 5 && + aExc.Context == xLBT.Interface) + { + ++nCount; + } + else + { + check( false, "### unexpected exception content!" ); + } + + /** it is certain, that the RuntimeException testing will fail, + if no */ + xLBT.RuntimeException = 0; + } + } + catch (unoidl.com.sun.star.uno.RuntimeException rExc) + { + if (rExc.Context == xLBT.Interface ) + { + ++nCount; + } + else + { + check( false, "### unexpected exception content!" ); + } + + /** it is certain, that the RuntimeException testing will fail, if no */ + unchecked + { + xLBT.RuntimeException = (int) 0xcafebabe; + } + } + } + catch (unoidl.com.sun.star.uno.Exception rExc) + { + if (rExc.Context == xLBT.Interface) + { + ++nCount; + } + else + + { + check( false, "### unexpected exception content!" ); + } + return (nCount == 3); + } + return false; +} + + private void perform_test( XBridgeTest xLBT ) + { + bool bRet= true;; + bRet = check( performTest( xLBT ), "standard test" ) && bRet; + bRet = check( raiseException( xLBT ) , "exception test" )&& bRet; + bRet = check( raiseOnewayException( xLBT ), "oneway exception test" ) && bRet; + bRet = check( testObjectMethodsImplemention(xLBT), "object methods test") && bRet; + bRet = performQueryForUnknownType( xLBT ) && bRet; + if ( ! bRet) + { + throw new unoidl.com.sun.star.uno.RuntimeException( "error (cli_cs_bridgetest.cs): test failed!", null); + } + } + + public BridgeTest( XComponentContext xContext ) + { + m_xContext = xContext; + } + + private XComponentContext m_xContext; + + public int run( String [] args ) + { + Debug.AutoFlush = true; +// System.Diagnostics.Debugger.Launch(); + try + { + if (args.Length < 1) + { + throw new RuntimeException( + "missing argument for bridgetest!", this ); + } + Object test_obj = + m_xContext.getServiceManager().createInstanceWithContext( + args[ 0 ], m_xContext ); + + Debug.WriteLine( + "Calling object: {0}", test_obj.ToString() ); + + XBridgeTest xTest = (XBridgeTest) test_obj ; + perform_test( xTest ); + Console.WriteLine( "\n### cli_uno C# bridgetest succeeded." ); + return 0; + } + catch (unoidl.com.sun.star.uno.RuntimeException) + { + throw; + } + catch (System.Exception exc) + { + throw new unoidl.com.sun.star.uno.RuntimeException( + "cli_cs_bridgetest.cs: unexpected exception occured in XMain::run. Original exception: " + + exc.GetType().Name + "\n Message: " + exc.Message , null); + } + } +} + +} diff --git a/testtools/source/bridgetest/cli/cli_cs_multi.cs b/testtools/source/bridgetest/cli/cli_cs_multi.cs new file mode 100644 index 000000000000..398f60d278f7 --- /dev/null +++ b/testtools/source/bridgetest/cli/cli_cs_multi.cs @@ -0,0 +1,119 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +namespace testtools { namespace bridgetest { namespace cli_cs { + +public class Multi: unoidl.test.testtools.bridgetest.XMulti +{ + public Multi() + { + } + + public double att1 + { + get { return _att1; } + set { _att1 = value; } + } + + public int fn11(int arg) + { + return 11 * arg; + } + + public string fn12(string arg) + { + return "12" + arg; + } + + public int fn21(int arg) + { + return 21 * arg; + } + + public string fn22(string arg) + { + return "22" + arg; + } + + public double att3 + { + get { return _att3; } + set { _att3 = value; } + } + + public int fn31(int arg) + { + return 31 * arg; + } + + public string fn32(string arg) + { + return "32" + arg; + } + + public int fn33() + { + return 33; + } + + public int fn41(int arg) + { + return 41 * arg; + } + + public int fn61(int arg) + { + return 61 * arg; + } + + public string fn62(string arg) + { + return "62" + arg; + } + + public int fn71(int arg) + { + return 71 * arg; + } + + public string fn72(string arg) + { + return "72" + arg; + } + + public int fn73() + { + return 73; + } + + private double _att1; + private double _att3; +}; + +} } } + + diff --git a/testtools/source/bridgetest/cli/cli_cs_testobj.cs b/testtools/source/bridgetest/cli/cli_cs_testobj.cs new file mode 100644 index 000000000000..258445eea3ab --- /dev/null +++ b/testtools/source/bridgetest/cli/cli_cs_testobj.cs @@ -0,0 +1,909 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +using System; +using System.Diagnostics; +using System.Threading; +using System.Runtime.CompilerServices; +using uno; +using uno.util; +using unoidl.com.sun.star.uno; +using unoidl.com.sun.star.lang; +using unoidl.test.testtools.bridgetest; + +namespace cs_testobj +{ + +class CheckFailed: System.Exception { + public CheckFailed(string message): base(message) {} +} + +public class BridgeTestObject : WeakBase, XRecursiveCall, XBridgeTest2 +{ + private XComponentContext m_xContext; + + public BridgeTestObject( XComponentContext xContext ) + { + m_xContext = xContext; + } + public BridgeTestObject() + { + } + + private bool _bool; + private char _char; + private byte _byte; + private short _short; + private ushort _ushort; + private int _long; + private uint _ulong; + private long _hyper; + private ulong _uhyper; + private float _float; + private double _double; + private String _string; + private Object _xInterface; + private Any _any; + private TestEnum _testEnum = TestEnum.TEST; + private TestElement[] _testElements = new TestElement[0]; + private TestDataElements _testDataElements = new TestDataElements(); + private int _nLastCallId = 0; + private bool _bFirstCall = true; + private bool _bSequenceOfCallTestPassed = true; + + private bool[] _arBool; + private char[] _arChar; + private byte[] _arByte; + private short[]_arShort; + private int[] _arLong; + private long[] _arHyper; + private UInt16[] _arUShort; + private UInt32[] _arULong; + private UInt64[] _arUHyper; + private string[] _arString; + private float[] _arFloat; + private double[] _arDouble; + private TestEnum[] _arEnum; + private Object[] _arObject; + private int[][] _arLong2; + private int[][][] _arLong3; + private Any[] _arAny; + +// private int _raiseAttr1; + + + public void setValues( + bool bBool, + char cChar, + byte nByte, + short nShort, + ushort nUShort, + int nLong, + uint nULong, + long nHyper, + ulong nUHyper, + float fFloat, + double fDouble, + TestEnum testEnum, + String str, + Object xInterface, + Any any, + TestElement [] testElements, + TestDataElements testDataElements ) + { + Debug.WriteLine( "##### " + GetType().FullName + ".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 = str; + _xInterface = xInterface; + _any = any; + _testElements = testElements; + _testDataElements = testDataElements; + } + + public TestDataElements setValues2( + /*INOUT*/ref bool io_bool, + /*INOUT*/ref char io_char, + /*INOUT*/ref byte io_byte, + /*INOUT*/ref short io_short, + /*INOUT*/ref ushort io_ushort, + /*INOUT*/ref int io_long, + /*INOUT*/ref uint io_ulong, + /*INOUT*/ref long io_hyper, + /*INOUT*/ref ulong io_uhyper, + /*INOUT*/ref float io_float, + /*INOUT*/ref double io_double, + /*INOUT*/ref TestEnum io_testEnum, + /*INOUT*/ref String io_string, + /*INOUT*/ref Object io_xInterface, + /*INOUT*/ref Any io_any, + /*INOUT*/ref TestElement[] io_testElements, + /*INOUT*/ref TestDataElements io_testDataElements ) + { + Debug.WriteLine( "##### " + GetType().FullName + ".setValues2:" + io_any ); + + _bool = io_bool; + _char = io_char; + _byte = io_byte; + _short = io_short; + _ushort = io_ushort; + _long = io_long; + _ulong = io_ulong; + _hyper = io_hyper; + _uhyper = io_uhyper; + _float = io_float; + _double = io_double; + _testEnum = io_testEnum; + _string = io_string; + _xInterface = io_xInterface; + _any = io_any; + _testElements = (TestElement[]) io_testElements.Clone(); + _testDataElements = io_testDataElements; + + TestElement temp = io_testElements[ 0 ]; + io_testElements[ 0 ] = io_testElements[ 1 ]; + io_testElements[ 1 ] = temp; + + return _testDataElements; + } + + public TestDataElements getValues( + /*OUT*/out bool o_bool, + /*OUT*/out char o_char, + /*OUT*/out byte o_byte, + /*OUT*/out short o_short, + /*OUT*/out ushort o_ushort, + /*OUT*/out int o_long, + /*OUT*/out uint o_ulong, + /*OUT*/out long o_hyper, + /*OUT*/out ulong o_uhyper, + /*OUT*/out float o_float, + /*OUT*/out double o_double, + /*OUT*/out TestEnum o_testEnum, + /*OUT*/out String o_string, + /*OUT*/out Object o_xInterface, + /*OUT*/out Any o_any, + /*OUT*/out TestElement[] o_testElements, + /*OUT*/out TestDataElements o_testDataElements ) + { + Debug.WriteLine( "##### " + GetType().FullName + ".getValues" ); + + o_bool = _bool; + o_char = _char; + o_byte = _byte; + o_short = _short; + o_ushort = _ushort; + o_long = _long; + o_ulong = _ulong; + o_hyper = _hyper; + o_uhyper = _uhyper; + o_float = _float; + o_double = _double; + o_testEnum = _testEnum; + o_string = _string; + o_xInterface = _xInterface; + o_any = _any; + o_testElements = _testElements; + o_testDataElements = _testDataElements; + + return _testDataElements; + } + + public SmallStruct echoSmallStruct(/*[in]*/SmallStruct arg) + { + return arg; + } + + public MediumStruct echoMediumStruct(/*[in]*/MediumStruct arg) + { + return arg; + } + + public BigStruct echoBigStruct(/*[in]*/BigStruct arg) + { + return arg; + } + + public AllFloats echoAllFloats(/*[in]*/AllFloats arg) + { + return arg; + } + + public int testPPCAlignment( long l1, long l2, int i1, long l3, int i2 ) + { + return i2; + } + + // Attributes + public bool Bool + { + get { return _bool; } + set { _bool = value; } + } + public byte Byte + { + get { return _byte; } + set { _byte = value; } + } + public char Char + { + get { return _char; } + set { _char = value; } + } + public short Short + { + get { return _short; } + set { _short = value; } + } + public ushort UShort + { + get { return _ushort; } + set { _ushort = value; } + } + public int Long + { + get { return _long; } + set { _long = value; } + } + public uint ULong + { + get { return _ulong; } + set { _ulong = value; } + } + public long Hyper + { + get { return _hyper; } + set { _hyper = value; } + } + public ulong UHyper + { + get { return _uhyper; } + set { _uhyper = value; } + } + public float Float + { + get { return _float; } + set { _float = value; } + } + public double Double + { + get { return _double; } + set { _double = value; } + } + public TestEnum Enum + { + get { return _testEnum; } + set { _testEnum = value; } + } + public String String + { + get { return _string; } + set { _string = value; } + } + public Object Interface + { + get { return _xInterface; } + set { _xInterface = value; } + } + public uno.Any Any + { + get { + + Debug.WriteLine( "##### " + GetType().FullName + ".Any" ); + return _any; + } + set { + Debug.WriteLine( "##### " + GetType().FullName + ".Any:" + value ); + _any = value; + } + } + public TestElement [] Sequence + { + get { return _testElements; } + set { _testElements = value; } + } + public TestDataElements Struct + { + get { return _testDataElements; } + set { _testDataElements = value; } + } + public Any transportAny(Any value) + { + return value; + } + public void call(int nCallId , int nWaitMUSEC) + { + Thread.Sleep(nWaitMUSEC / 10000); + + if(_bFirstCall) + _bFirstCall = false; + + else + _bSequenceOfCallTestPassed = _bSequenceOfCallTestPassed && (nCallId > _nLastCallId); + + _nLastCallId = nCallId; + } + public void callOneway( int nCallId , int nWaitMUSEC ) + { + Thread.Sleep(nWaitMUSEC / 10000); + + _bSequenceOfCallTestPassed = _bSequenceOfCallTestPassed && (nCallId > _nLastCallId); + _nLastCallId = nCallId; + } + public bool sequenceOfCallTestPassed() + { + return _bSequenceOfCallTestPassed; + } + [MethodImpl( MethodImplOptions.Synchronized )] + public void callRecursivly( XRecursiveCall xCall, int nToCall ) + { + lock (this) + { + if(nToCall != 0) + { + nToCall --; + xCall.callRecursivly(this , nToCall); + } + } + } + [MethodImpl( MethodImplOptions.Synchronized )] + public void startRecursiveCall( XRecursiveCall xCall, int nToCall ) + { + lock (this) + { + if(nToCall != 0) + { + nToCall --; + xCall.callRecursivly( this , nToCall ); + } + } + } + + // XBridgeTest + public TestDataElements raiseException( + short nArgumentPos, String rMsg, Object xContext ) + { + throw new IllegalArgumentException(rMsg, xContext, nArgumentPos); + } + public void raiseRuntimeExceptionOneway( String rMsg, Object xContext ) + { + throw new RuntimeException(rMsg, xContext); + } + + private void dothrow( System.Exception e ) + { + throw e; + } + public int RuntimeException + { + get { + try + { + dothrow( new RuntimeException(_string, _xInterface) ); + return 0; // dummy + } + catch (System.Exception exc) + { + throw exc; + } + } + set { throw new RuntimeException(_string, _xInterface); } + } + + // XBridgeTest2 + public int[][] setDim2(int[][] val) + { + _arLong2 = val; + return val; + } + + public int[][][] setDim3(int[][][] val) + { + _arLong3 = val; + return val; + } + + public Any[] setSequenceAny(Any[] val) + { + _arAny = val; + return val; + } + + public bool[] setSequenceBool(bool[] val) + { + _arBool = val; + return val; + } + + public byte[] setSequenceByte(byte[] val) + { + _arByte = val; + return val; + } + + public char[] setSequenceChar(char[] val) + { + _arChar = val; + return val; + } + + public short[] setSequenceShort(short[] val) + { + _arShort = val; + return val; + } + + public int[] setSequenceLong(int[] val) + { + _arLong = val; + return val; + } + + public long[] setSequenceHyper(long[] val) + { + _arHyper = val; + return val; + } + + public float[] setSequenceFloat(float[] val) + { + _arFloat = val; + return val; + } + + public double[] setSequenceDouble(double[] val) + { + _arDouble = val; + return val; + } + + public TestEnum[] setSequenceEnum(TestEnum[] val) + { + _arEnum = val; + return val; + } + + public UInt16[] setSequenceUShort(UInt16[] val) + { + _arUShort = val; + return val; + } + + public UInt32[] setSequenceULong(UInt32[] val) + { + _arULong = val; + return val; + } + + public UInt64[] setSequenceUHyper(UInt64[] val) + { + _arUHyper = val; + return val; + } + + public Object[] setSequenceXInterface(Object[] val) + { + _arObject = val; + return val; + } + + public string[] setSequenceString(string[] val) + { + _arString = val; + return val; + } + + public TestElement[] setSequenceStruct(TestElement[] val) + { + _testElements = val; + return val; + } + + public void setSequencesInOut(ref bool[] aSeqBoolean, + ref char[] aSeqChar, + ref byte[] aSeqByte, + ref short[] aSeqShort, + ref UInt16[] aSeqUShort, + ref int[] aSeqLong, + ref UInt32[] aSeqULong, + ref long[] aSeqHyper, + ref UInt64[] aSeqUHyper, + ref float[] aSeqFloat, + ref double[] aSeqDouble, + ref TestEnum[] aSeqTestEnum, + ref string[] aSeqString, + ref object[] aSeqXInterface, + ref Any[] aSeqAny, + ref int[][] aSeqDim2, + ref int[][][] aSeqDim3) + { + _arBool = aSeqBoolean; + _arChar = aSeqChar; + _arByte = aSeqByte; + _arShort = aSeqShort; + _arUShort = aSeqUShort; + _arLong = aSeqLong; + _arULong = aSeqULong; + _arHyper = aSeqHyper; + _arUHyper = aSeqUHyper; + _arFloat = aSeqFloat; + _arDouble = aSeqDouble; + _arEnum = aSeqTestEnum; + _arString = aSeqString; + _arObject = aSeqXInterface; + _arAny = aSeqAny; + _arLong2 = aSeqDim2; + _arLong3 = aSeqDim3; + } + + public void setSequencesOut(out bool[] aSeqBoolean, + out char[] aSeqChar, + out byte[] aSeqByte, + out short[] aSeqShort, + out UInt16[] aSeqUShort, + out int[] aSeqLong, + out UInt32[] aSeqULong, + out long[] aSeqHyper, + out UInt64[] aSeqUHyper, + out float[] aSeqFloat, + out double[] aSeqDouble, + out TestEnum[] aSeqTestEnum, + out string[] aSeqString, + out object[] aSeqXInterface, + out Any[] aSeqAny, + out int[][] aSeqDim2, + out int[][][] aSeqDim3) + { + aSeqBoolean = _arBool; + aSeqChar = _arChar; + aSeqByte = _arByte; + aSeqShort = _arShort; + aSeqUShort = _arUShort; + aSeqLong = _arLong; + aSeqULong = _arULong; + aSeqHyper = _arHyper; + aSeqUHyper = _arUHyper; + aSeqFloat = _arFloat; + aSeqDouble = _arDouble; + aSeqTestEnum = _arEnum; + aSeqString = _arString; + aSeqXInterface = _arObject; + aSeqAny = _arAny; + aSeqDim2 = _arLong2; + aSeqDim3 = _arLong3; + + } + + /* Attention: Debugging this code (probably in mixed mode) may lead to exceptions + * which do not occur when running normally (Visual Studio 2003) + */ + public void testConstructorsService(XComponentContext context) + { + Constructors.create1(context, + true, + 0x80, // -128 in C++, + Int16.MinValue, + UInt16.MaxValue, + Int32.MinValue, + UInt32.MaxValue, + Int64.MinValue, + UInt64.MaxValue, + 0.123f, + 0.456, + 'X', + "test", + typeof(Any), + new Any(true), + new bool[] { true }, + new byte[] { 0x80}, // in C++ the value is compared with SAL_MIN_INT8 which is -128 + new short[] { Int16.MinValue }, + new UInt16[] { UInt16.MaxValue }, + new Int32[] {Int32.MinValue}, + new UInt32[] { UInt32.MaxValue }, + new long[] { Int64.MinValue }, + new UInt64[] { UInt64.MaxValue }, + new float[] { 0.123f }, + new double[] { 0.456 }, + new char[] { 'X' }, + new string[] { "test" }, + new Type[] { typeof(Any) }, + new Any[] { new Any(true) }, + new bool[][] { new bool[] { true } }, + new Any[][] { new Any[] { new Any(true) } }, + new TestEnum[] { TestEnum.TWO }, + new TestStruct[] { new TestStruct(10) }, + new TestPolyStruct[] { new TestPolyStruct(true) }, + new TestPolyStruct[] { new TestPolyStruct(new Any(true)) }, + new object[] { null }, + TestEnum.TWO, + new TestStruct(10), + new TestPolyStruct(true), + new TestPolyStruct(new Any(true)), + null + ); + + Constructors.create2(context, + new Any(true), + new Any((System.Byte) 0x80), + new Any(Int16.MinValue), + new Any(UInt16.MaxValue), + new Any(Int32.MinValue), + new Any(UInt32.MaxValue), + new Any(Int64.MinValue), + new Any(UInt64.MaxValue), + new Any(0.123f), + new Any(0.456), + new Any('X'), + new Any("test"), + new Any(typeof(Any)), + new Any(true), + new Any(typeof(bool[]), new bool[] { true }), + new Any(typeof(byte[]), new byte[] { (System.Byte) 0x80}), + new Any(typeof(short[]), new short[] { Int16.MinValue }), + new Any(typeof(UInt16[]), new UInt16[] { UInt16.MaxValue }), + new Any(typeof(int[]), new int[] { Int32.MinValue }), + new Any(typeof(UInt32[]), new UInt32[] { UInt32.MaxValue }), + new Any(typeof(long[]), new long[] { Int64.MinValue }), + new Any(typeof(UInt64[]), new UInt64[] { UInt64.MaxValue }), + new Any(typeof(float[]), new float[] { 0.123f }), + new Any(typeof(double[]), new double[] { 0.456 }), + new Any(typeof(char[]), new char[] { 'X' }), + new Any(typeof(string[]), new string[] { "test" }), + new Any(typeof(Type[]), new Type[] { typeof(Any) }), + new Any(typeof(Any[]), new Any[] { new Any(true) }), + new Any(typeof(bool[][]), new bool[][] { new bool[] { true } }), + new Any( + typeof(Any[][]), new Any[][] { new Any[] { new Any(true) } }), + new Any(typeof(TestEnum[]), new TestEnum[] { TestEnum.TWO }), + new Any( + typeof(TestStruct[]), new TestStruct[] { new TestStruct(10) }), + new Any( + PolymorphicType.GetType( + typeof(TestPolyStruct[]), + "unoidl.test.testtools.bridgetest.TestPolyStruct<System.Boolean>[]"), + new TestPolyStruct[] { new TestPolyStruct(true) }) , + new Any( + PolymorphicType.GetType( + typeof(TestPolyStruct[]), + "unoidl.test.testtools.bridgetest.TestPolyStruct<uno.Any>[]"), + new TestPolyStruct[] { new TestPolyStruct(new Any(true)) }), + new Any(typeof(object[])/*TODO*/, new object[] { null }), + new Any(typeof(TestEnum), TestEnum.TWO), + new Any(typeof(TestStruct), new TestStruct(10)), + new Any( + PolymorphicType.GetType( + typeof(TestPolyStruct), + "unoidl.test.testtools.bridgetest.TestPolyStruct<System.Boolean>"), + new TestPolyStruct(true)), + new Any( + PolymorphicType.GetType( + typeof(TestPolyStruct), + "unoidl.test.testtools.bridgetest.TestPolyStruct<uno.Any>"), + new TestPolyStruct(new Any(true))), + new Any(typeof(object), null) + ); + + + XMultiBase1 xMulti = Constructors2.create1( + context, + new TestPolyStruct(typeof(int)), + new TestPolyStruct(new Any(true)), + new TestPolyStruct(true), + new TestPolyStruct((Byte) 0x80), + new TestPolyStruct(Int16.MinValue), + new TestPolyStruct(Int32.MinValue), + new TestPolyStruct(Int64.MinValue), + new TestPolyStruct('X'), + new TestPolyStruct("test"), + new TestPolyStruct(0.123f), + new TestPolyStruct(0.456d), + new TestPolyStruct(new object()), + new TestPolyStruct(new uno.util.WeakComponentBase()), + new TestPolyStruct(TestEnum.TWO), + new TestPolyStruct(new TestPolyStruct2('X', new Any(true))), + new TestPolyStruct(new TestPolyStruct2(new TestPolyStruct2('X', new Any(true)), "test")), + new TestPolyStruct2("test", new TestPolyStruct2('X', new TestPolyStruct(new Any(true)))), + new TestPolyStruct2( new TestPolyStruct2('X', new Any(true)), new TestPolyStruct('X')), + new TestPolyStruct(new Type[] { typeof(int)}), + new TestPolyStruct(new Any[] { new Any(true) }), + new TestPolyStruct(new bool[] {true}), + new TestPolyStruct(new byte[] {0x80}), + new TestPolyStruct(new short[] {Int16.MinValue}), + new TestPolyStruct(new int[] {Int32.MinValue}), + new TestPolyStruct(new long[] {Int64.MinValue}), + new TestPolyStruct(new char[] {'X'}), + new TestPolyStruct(new string[] {"test"}), + new TestPolyStruct(new float[] {0.123f}), + new TestPolyStruct(new double[] {0.456d}), + new TestPolyStruct(new object[] {new object()}), + new TestPolyStruct(new unoidl.com.sun.star.lang.XComponent[] {new uno.util.WeakComponentBase()}), + new TestPolyStruct(new TestEnum[] {TestEnum.TWO}), + new TestPolyStruct(new TestPolyStruct2[] {new TestPolyStruct2('X', new Any[] {new Any(true)})}), + new TestPolyStruct(new TestPolyStruct2[] { + new TestPolyStruct2(new TestPolyStruct('X'), new Any[] {new Any(true)})}), + new TestPolyStruct(new int[][] { new int[] {Int32.MinValue} }), + new TestPolyStruct[]{ new TestPolyStruct(Int32.MinValue)}, + new TestPolyStruct[]{new TestPolyStruct(new TestPolyStruct2('X', new Any(true)))}, + new TestPolyStruct[]{new TestPolyStruct(new TestPolyStruct2(new TestPolyStruct2('X', new Any(true)), "test"))}, + new TestPolyStruct2[]{new TestPolyStruct2("test", new TestPolyStruct2('X', new TestPolyStruct(new Any(true))))}, + new TestPolyStruct2[]{new TestPolyStruct2(new TestPolyStruct2('X', new Any(true)),new TestPolyStruct('X'))}, + new TestPolyStruct[][]{new TestPolyStruct[]{new TestPolyStruct('X')}}, + new TestPolyStruct[][]{new TestPolyStruct[]{new TestPolyStruct(new TestPolyStruct2('X', new Any(true)))}}, + new TestPolyStruct[][]{new TestPolyStruct[] {new TestPolyStruct(new TestPolyStruct2(new TestPolyStruct2('X',new Any(true)), "test"))}}, + new TestPolyStruct2[][]{new TestPolyStruct2[]{new TestPolyStruct2("test", new TestPolyStruct2('X',new TestPolyStruct(new Any(true))))}}, + new TestPolyStruct2[][]{new TestPolyStruct2[]{new TestPolyStruct2(new TestPolyStruct2('X',new Any(true)),new TestPolyStruct('X'))}} + ); + + //test the returned interface + xMulti.fn11(1); + + + } + + public XCurrentContextChecker getCurrentContextChecker() + { + return null; //TODO: not yet tested in CLI UNO + } + + public TestPolyStruct transportPolyBoolean(/*[in]*/TestPolyStruct arg) + { + return arg; + } + + public void transportPolyHyper(/*[in][out]*/ ref TestPolyStruct arg) + { + } + + public void transportPolySequence(TestPolyStruct arg1, + out TestPolyStruct arg2) + { + arg2 = arg1; + } + + public TestPolyStruct getNullPolyBadEnum() + { + return new TestPolyStruct(unoidl.test.testtools.bridgetest.TestBadEnum.M); + } + + public TestPolyStruct getNullPolyLong() + { + return new TestPolyStruct(); + } + + public TestPolyStruct getNullPolyString() + { + return new TestPolyStruct(); + } + + public TestPolyStruct getNullPolyType() + { + return new TestPolyStruct(); + } + + public TestPolyStruct getNullPolyAny() + { + return new TestPolyStruct(); + } + + public TestPolyStruct getNullPolySequence() + { + return new TestPolyStruct(); + } + + public TestPolyStruct getNullPolyEnum() + { + return new TestPolyStruct(); + } + + public TestPolyStruct getNullPolyStruct() + { + return new TestPolyStruct(); + } + + public TestPolyStruct getNullPolyInterface() + { + return new TestPolyStruct(); + } + + public XMulti getMulti() + { + return new testtools.bridgetest.cli_cs.Multi(); + } + + private static void checkEqual(int value, int argument) { + if (argument != value) { + throw new CheckFailed(value + " != " + argument); + } + } + + private static void checkEqual(double value, double argument) { + if (argument != value) { + throw new CheckFailed(value + " != " + argument); + } + } + + private static void checkEqual(string value, string argument) { + if (argument != value) { + throw new CheckFailed(value + " != " + argument); + } + } + + public string testMulti(XMulti multi) + { + try { + checkEqual(0.0, multi.att1); + multi.att1 = 0.1; + checkEqual(0.1, multi.att1); + checkEqual(11 * 1, multi.fn11(1)); + checkEqual("12" + "abc", multi.fn12("abc")); + checkEqual(21 * 2, multi.fn21(2)); + checkEqual("22" + "de", multi.fn22("de")); + checkEqual(0.0, multi.att3); + multi.att3 = 0.3; + checkEqual(0.3, multi.att3); + checkEqual(31 * 3, multi.fn31(3)); + checkEqual("32" + "f", multi.fn32("f")); + checkEqual(33, multi.fn33()); + checkEqual(41 * 4, multi.fn41(4)); + checkEqual(61 * 6, multi.fn61(6)); + checkEqual("62" + "", multi.fn62("")); + checkEqual(71 * 7, multi.fn71(7)); + checkEqual("72" + "g", multi.fn72("g")); + checkEqual(73, multi.fn73()); + } catch (CheckFailed f) { + return f.Message; + } + return ""; + } + + public int RaiseAttr1 + { + get { throw new RuntimeException(); } + set { throw new IllegalArgumentException(); } + } + + public int RaiseAttr2 + { + get { throw new IllegalArgumentException(); } + set { throw new IllegalArgumentException(); } + } + + +} + +} diff --git a/testtools/source/bridgetest/cli/cli_vb_bridgetest.vb b/testtools/source/bridgetest/cli/cli_vb_bridgetest.vb new file mode 100644 index 000000000000..58e4521bac90 --- /dev/null +++ b/testtools/source/bridgetest/cli/cli_vb_bridgetest.vb @@ -0,0 +1,862 @@ +'************************************************************************* +' +' DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +' +' Copyright 2000, 2010 Oracle and/or its affiliates. +' +' OpenOffice.org - a multi-platform office productivity suite +' +' This file is part of OpenOffice.org. +' +' OpenOffice.org is free software: you can redistribute it and/or modify +' it under the terms of the GNU Lesser General Public License version 3 +' only, as published by the Free Software Foundation. +' +' OpenOffice.org 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 version 3 for more details +' (a copy is included in the LICENSE file that accompanied this code). +' +' You should have received a copy of the GNU Lesser General Public License +' version 3 along with OpenOffice.org. If not, see +' <http://www.openoffice.org/license.html> +' for a copy of the LGPLv3 License. +' +'************************************************************************* + + + +Option Explicit On +Option Strict On + +imports System +imports uno +imports uno.util +imports unoidl.com.sun.star.lang +imports unoidl.com.sun.star.uno +'imports unoidl.com.sun.star.test.bridge +imports unoidl.test.testtools.bridgetest +imports System.Windows.Forms +imports System.Diagnostics +imports System.Reflection + +Class CONSTANTS +Friend Shared STRING_TEST_CONSTANT As String = """ paco\' chorizo\\\' ""\'" +End Class + +Namespace foo + + Public Interface MyInterface + End Interface +End Namespace + +Namespace vb_bridetest +Class ORecursiveCall + Inherits WeakBase + Implements XRecursiveCall + + Overridable Sub callRecursivly(xCall As XRecursiveCall, nToCall As Integer) _ + Implements XRecursiveCall.callRecursivly + SyncLock Me + If nToCall > 0 + nToCall = nToCall - 1 + xCall.callRecursivly(Me, nToCall) + End If + End SyncLock + End Sub +End Class + + + + +Public Class BridgeTest + Inherits uno.util.WeakBase + Implements XMain + + Private m_xContext As XComponentContext + + Public Sub New( xContext As unoidl.com.sun.star.uno.XComponentContext ) + mybase.New() + m_xContext = xContext + End Sub + + Private Shared Function check( b As Boolean , message As String ) As Boolean + If Not b + Console.WriteLine("{0} failed\n" , message) + End If + Return b + End Function + + Private Shared Sub assign( rData As TestElement, bBool As Boolean, _ + aChar As Char, nByte As Byte, nShort As Short, nUShort As UInt16, _ + nLong As Integer, nULong As UInt32, nHyper As Long, _ + nUHyper As UInt64, fFloat As Single, fDouble As Double, _ + eEnum As TestEnum, rStr As String, xTest As Object, _ + rAny As Any) + + rData.Bool = bBool + rData.Char = aChar + 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 + End Sub + + Private Shared Sub assign( rData As TestDataElements, bBool As Boolean, _ + aChar As Char, nByte As Byte, nShort As Short, nUShort As UInt16, _ + nLong As Integer, nULong As UInt32, nHyper As Long, _ + nUHyper As UInt64, fFloat As Single, fDouble As Double, _ + eEnum As TestEnum, rStr As String, xTest As Object, _ + rAny As Any, rSequence() As TestElement) + + assign( DirectCast( rData,TestElement), _ + bBool, aChar, nByte, nShort, nUShort, nLong, nULong, nHyper, _ + nUHyper, fFloat, fDouble, eEnum, rStr, xTest, rAny ) + rData.Sequence = rSequence + End Sub + + Private Shared Function compareData(val1 As Object, val2 As Object) As Boolean + If val1 Is Nothing And val2 Is Nothing OrElse _ + val1 Is val2 + Return True + End If + If val1 Is Nothing And Not(val2 Is Nothing) OrElse _ + Not (val1 Is Nothing) And val2 Is Nothing OrElse _ + Not val1.GetType().Equals( val2.GetType()) + Return False + End If + + Dim ret As Boolean = False + Dim t1 As Type = val1.GetType() + 'Sequence + If t1.IsArray() + ret = compareSequence(DirectCast( val1, Array), _ + DirectCast( val2, Array)) + 'String + ElseIf TypeOf val1 Is String + ret = DirectCast( val1, string) = DirectCast( val2, string) + ' Interface implementation + ElseIf t1.GetInterfaces().Length > 0 And Not t1.IsValueType + ret = val1 Is val2 + ' Struct + ElseIf Not t1.IsValueType + ret = compareStruct(val1, val2) + ElseIf TypeOf val1 Is Any + Dim a1 As Any = DirectCast( val1, Any) + Dim a2 As Any = DirectCast( val2, Any) + ret = a1.Type.Equals( a2.Type ) And compareData( a1.Value, a2.Value ) + ElseIf t1.IsValueType + 'Any, enum, int, bool char, float, double etc. + ret = val1.Equals(val2) + Else + Debug.Assert(False) + End If + Return ret + End Function + + ' Arrays have only one dimension + Private Shared Function compareSequence( ar1 As Array, ar2 As Array) As Boolean + Debug.Assert( Not (ar1 Is Nothing) And Not (ar2 Is Nothing) ) + Dim t1 As Type = ar1.GetType() + Dim t2 As Type = ar2.GetType() + + if ( Not(ar1.Rank = 1 And ar2.Rank = 1 _ + And ar1.Length = ar2.Length And t1.GetElementType().Equals(t2.GetElementType()))) + return False + End If + 'arrays have same rank and size and element type. + Dim len As Integer = ar1.Length + Dim elemType As Type = t1.GetElementType() + Dim ret As Boolean = True + Dim i As Integer + For i = 0 To len - 1 + If (compareData(ar1.GetValue(i), ar2.GetValue(i)) = False) + ret = False + Exit For + End If + Next i + + Return ret + End Function + + Private Shared Function compareStruct( val1 As Object, val2 As Object) As Boolean + Debug.Assert( Not(val1 Is Nothing) And Not(val2 Is Nothing)) + Dim t1 As Type = val1.GetType() + Dim t2 As Type = val2.GetType() + If Not t1.Equals(t2) + Return False + End If + Dim fields() As FieldInfo = t1.GetFields() + Dim cFields As Integer = fields.Length + Dim ret As Boolean = True + Dim i As Integer + For i = 0 To cFields - 1 + Dim fieldVal1 As Object = fields(i).GetValue(val1) + Dim fieldVal2 As Object = fields(i).GetValue(val2) + If Not compareData(fieldVal1, fieldVal2) + ret = False + Exit For + End If + Next i + Return ret + End Function + + + Private Shared Function performSequenceTest(xBT As XBridgeTest) As Boolean + Dim bRet As Boolean = True + 'Automati cast ?? like with COM objects + Dim xBT2 As XBridgeTest2 + Try + xBT2 = DirectCast(xBT,XBridgeTest2) + Catch e As InvalidCastException + Return False + End Try + + ' perform sequence tests (XBridgeTest2) + 'create the sequence which are compared with the results + Dim arBool() As Boolean = {True, False, True} + Dim arChar() As Char = {"A"C,"B"C,"C"C} + Dim arByte() As Byte = { 1, 2, &Hff} + Dim arShort() As Short = {Int16.MinValue, 1, Int16.MaxValue} + Dim arUShort() As UInt16 = {Convert.ToUInt16(0), Convert.ToUInt16(1), _ + Convert.ToUInt16(&Hffff)} + Dim arLong() As Integer = {Int32.MinValue, 1, Int32.MaxValue} + Dim arULong() As UInt32 = {Convert.ToUInt32(0), Convert.ToUInt32(1), _ + Convert.ToUInt32(&HffffffffL)} + Dim arHyper() As Long = {Int64.MinValue, 1, Int64.MaxValue} + Dim arUHyper() As UInt64 = {Convert.ToUInt64(0), Convert.ToUInt64(1), _ + Convert.ToUInt64(&Hffffffff5L)} + Dim arFloat() As Single = {1.1f, 2.2f, 3.3f} + Dim arDouble() As Double = {1.11, 2.22, 3.33} + Dim arString() As String = {"String 1", "String 2", "String 3"} + + Dim arAny() As Any = {New Any(True), New Any(11111), New Any(3.14)} + Dim arObject() As Object = {New WeakBase(), New WeakBase(), New WeakBase()} + Dim arEnum() As TestEnum = {TestEnum.ONE, TestEnum.TWO, TestEnum.CHECK} + + Dim arStruct() As TestElement = {New TestElement(), New TestElement(), _ + New TestElement()} + assign( arStruct(0), True, "@"C, 17, &H1234, Convert.ToUInt16(&Hfedc), _ + &H12345678, Convert.ToUInt32(&H123456), &H123456789abcdef0, _ + Convert.ToUInt64(123456788), 17.0815F, 3.1415926359, _ + TestEnum.LOLA, CONSTANTS.STRING_TEST_CONSTANT, arObject(0), _ + New Any(GetType(System.Object), arObject(0))) + assign( arStruct(1), True, "A"C, 17, &H1234, Convert.ToUInt16(&Hfedc), _ + &H12345678, Convert.ToUInt32(&H123456), &H123456789abcdef0, _ + Convert.ToUInt64(12345678), 17.0815F, 3.1415926359, _ + TestEnum.TWO, CONSTANTS.STRING_TEST_CONSTANT, arObject(1), _ + New Any(GetType(System.Object), arObject(1)) ) + assign( arStruct(2), True, "B"C, 17, &H1234, Convert.ToUInt16(&Hfedc), _ + &H12345678, Convert.ToUInt32(654321), &H123456789abcdef0, _ + Convert.ToUInt64(87654321), 17.0815F, 3.1415926359, _ + TestEnum.CHECK, Constants.STRING_TEST_CONSTANT, arObject(2), _ + New Any(GetType(System.Object), arObject(2))) + + + Dim arLong3()()() As Integer = New Integer()()() { _ + New Integer()(){New Integer(){1,2,3},New Integer(){4,5,6}, New Integer(){7,8,9} }, _ + New Integer ()(){New Integer(){1,2,3},New Integer(){4,5,6}, New Integer(){7,8,9}}, _ + New Integer()(){New Integer(){1,2,3},New Integer(){4,5,6}, New Integer(){7,8,9}}} + + Dim seqSeqRet()() As Integer = xBT2.setDim2(arLong3(0)) + bRet = check( compareData(seqSeqRet, arLong3(0)), "sequence test") _ + And bRet + Dim seqSeqRet2()()() As Integer = xBT2.setDim3(arLong3) + bRet = check( compareData(seqSeqRet2, arLong3), "sequence test") _ + And bRet + Dim seqAnyRet() As Any = xBT2.setSequenceAny(arAny) + bRet = check( compareData(seqAnyRet, arAny), "sequence test") And bRet + Dim seqBoolRet() As Boolean = xBT2.setSequenceBool(arBool) + bRet = check( compareData(seqBoolRet, arBool), "sequence test") _ + And bRet + Dim seqByteRet() As Byte = xBT2.setSequenceByte(arByte) + bRet = check( compareData(seqByteRet, arByte), "sequence test") _ + And bRet + Dim seqCharRet() As Char = xBT2.setSequenceChar(arChar) + bRet = check( compareData(seqCharRet, arChar), "sequence test") _ + And bRet + Dim seqShortRet() As Short = xBT2.setSequenceShort(arShort) + bRet = check( compareData(seqShortRet, arShort), "sequence test") _ + And bRet + Dim seqLongRet() As Integer = xBT2.setSequenceLong(arLong) + bRet = check( compareData(seqLongRet, arLong), "sequence test") _ + And bRet + Dim seqHyperRet() As Long = xBT2.setSequenceHyper(arHyper) + bRet = check( compareData(seqHyperRet,arHyper), "sequence test") _ + And bRet + Dim seqFloatRet() As Single = xBT2.setSequenceFloat(arFloat) + bRet = check( compareData(seqFloatRet, arFloat), "sequence test") _ + And bRet + Dim seqDoubleRet() As Double= xBT2.setSequenceDouble(arDouble) + bRet = check( compareData(seqDoubleRet, arDouble), "sequence test") _ + And bRet + Dim seqEnumRet() As TestEnum = xBT2.setSequenceEnum(arEnum) + bRet = check( compareData(seqEnumRet, arEnum), "sequence test") _ + And bRet + Dim seqUShortRet() As UInt16 = xBT2.setSequenceUShort(arUShort) + bRet = check( compareData(seqUShortRet, arUShort), "sequence test") _ + And bRet + Dim seqULongRet() As UInt32 = xBT2.setSequenceULong(arULong) + bRet = check( compareData(seqULongRet, arULong), "sequence test") _ + And bRet + Dim seqUHyperRet() As UInt64 = xBT2.setSequenceUHyper(arUHyper) + bRet = check( compareData(seqUHyperRet, arUHyper), "sequence test") _ + And bRet + Dim seqObjectRet() As Object = xBT2.setSequenceXInterface(arObject) + bRet = check( compareData(seqObjectRet, arObject), "sequence test") _ + And bRet + Dim seqStringRet() As String = xBT2.setSequenceString(arString) + bRet = check( compareData(seqStringRet, arString), "sequence test") _ + And bRet + Dim seqStructRet() As TestElement = xBT2.setSequenceStruct(arStruct) + bRet = check( compareData(seqStructRet, arStruct), "sequence test") _ + And bRet + + + Dim arBoolTemp() As Boolean = DirectCast(arBool.Clone(), Boolean()) + Dim arCharTemp() As Char = DirectCast(arChar.Clone(), Char()) + Dim arByteTemp() As Byte = DirectCast(arByte.Clone(), Byte()) + Dim arShortTemp() As Short = DirectCast(arShort.Clone(), Short()) + Dim arUShortTemp() As UInt16 = DirectCast(arUShort.Clone(), UInt16()) + Dim arLongTemp() As Integer= DirectCast(arLong.Clone(), Integer()) + Dim arULongTemp() As UInt32 = DirectCast(arULong.Clone(), UInt32()) + Dim arHyperTemp() As Long = DirectCast(arHyper.Clone(), Long()) + Dim arUHyperTemp() As UInt64 = DirectCast(arUHyper.Clone(), UInt64()) + Dim arFloatTemp() As Single = DirectCast(arFloat.Clone(), Single()) + Dim arDoubleTemp() As Double = DirectCast(arDouble.Clone(), Double()) + Dim arEnumTemp() As TestEnum = DirectCast(arEnum.Clone(), TestEnum()) + Dim arStringTemp() As String = DirectCast(arString.Clone(), String()) + Dim arObjectTemp() As Object = DirectCast(arObject.Clone(), Object()) + Dim arAnyTemp() As Any = DirectCast(arAny.Clone(), Any()) + ' make sure this are has the same contents as arLong3(0) + Dim arLong2Temp()() As Integer = New Integer()(){New Integer(){1,2,3}, _ + New Integer(){4,5,6}, New Integer(){7,8,9} } + ' make sure this are has the same contents as arLong3 + Dim arLong3Temp()()() As Integer = New Integer()()(){ _ + New Integer()(){New Integer(){1,2,3},New Integer(){4,5,6}, New Integer(){7,8,9} }, _ + New Integer ()(){New Integer(){1,2,3},New Integer(){4,5,6}, New Integer(){7,8,9}}, _ + New Integer()(){New Integer(){1,2,3},New Integer(){4,5,6}, New Integer(){7,8,9}}} + + xBT2.setSequencesInOut( arBoolTemp, arCharTemp, arByteTemp, _ + arShortTemp, arUShortTemp, arLongTemp, _ + arULongTemp, arHyperTemp, arUHyperTemp, _ + arFloatTemp, arDoubleTemp, arEnumTemp, _ + arStringTemp, arObjectTemp, _ + arAnyTemp, arLong2Temp, arLong3Temp) + bRet = check( _ + compareData(arBoolTemp, arBool) And _ + compareData(arCharTemp , arChar) And _ + compareData(arByteTemp , arByte) And _ + compareData(arShortTemp , arShort) And _ + compareData(arUShortTemp , arUShort) And _ + compareData(arLongTemp , arLong) And _ + compareData(arULongTemp , arULong) And _ + compareData(arHyperTemp , arHyper) And _ + compareData(arUHyperTemp , arUHyper) And _ + compareData(arFloatTemp , arFloat) And _ + compareData(arDoubleTemp , arDouble) And _ + compareData(arEnumTemp , arEnum) And _ + compareData(arStringTemp , arString) And _ + compareData(arObjectTemp , arObject) And _ + compareData(arAnyTemp , arAny) And _ + compareData(arLong2Temp , arLong3(0)) And _ + compareData(arLong3Temp , arLong3), "sequence test") And bRet + + Dim arBoolOut() As Boolean + Dim arCharOut() As Char + Dim arByteOut() As Byte + Dim arShortOut() As Short + Dim arUShortOut() As UInt16 + Dim arLongOut() As Integer + Dim arULongOut() As UInt32 + Dim arHyperOut() As Long + Dim arUHyperOut() As UInt64 + Dim arFloatOut() As Single + Dim arDoubleOut() As Double + Dim arEnumOut() As TestEnum + Dim arStringOut() As String + Dim arObjectOut() As Object + Dim arAnyOut() As Any + Dim arLong2Out()() As Integer + Dim arLong3Out()()() As Integer + + xBT2.setSequencesOut( arBoolOut, arCharOut, arByteOut, _ + arShortOut, arUShortOut, arLongOut, _ + arULongOut, arHyperOut, arUHyperOut, _ + arFloatOut, arDoubleOut, arEnumOut, _ + arStringOut, arObjectOut, arAnyOut, _ + arLong2Out, arLong3Out) + bRet = check( _ + compareData(arBoolOut, arBool) And _ + compareData(arCharOut, arChar) And _ + compareData(arByteOut, arByte) And _ + compareData(arShortOut, arShort) And _ + compareData(arUShortOut, arUShort) And _ + compareData(arLongOut, arLong) And _ + compareData(arULongOut, arULong) And _ + compareData(arHyperOut, arHyper) And _ + compareData(arUHyperOut, arUHyper) And _ + compareData(arFloatOut, arFloat) And _ + compareData(arDoubleOut, arDouble) And _ + compareData(arEnumOut, arEnum) And _ + compareData(arStringOut, arString) And _ + compareData(arObjectOut, arObject) And _ + compareData(arAnyOut, arAny) And _ + compareData(arLong2Out, arLong3(0)) And _ + compareData(arLong3Out, arLong3), "sequence test") And bRet + + + 'test with empty sequences + Dim _arLong2()() As Integer = New Integer()(){} + seqSeqRet = xBT2.setDim2(_arLong2) + bRet = check( compareData(seqSeqRet, _arLong2), "sequence test") And bRet + Dim _arLong3()()() As Integer = New Integer()()(){} + seqSeqRet2 = xBT2.setDim3(_arLong3) + bRet = check( compareData(seqSeqRet2, _arLong3), "sequence test") And bRet + Dim _arAny() As Any = New Any(){} + seqAnyRet = xBT2.setSequenceAny(_arAny) + bRet = check( compareData(seqAnyRet, _arAny), "sequence test") And bRet + Dim _arBool() As Boolean = New Boolean() {} + seqBoolRet = xBT2.setSequenceBool(_arBool) + bRet = check( compareData(seqBoolRet, _arBool), "sequence test") And bRet + Dim _arByte() As Byte = New Byte() {} + seqByteRet = xBT2.setSequenceByte(_arByte) + bRet = check( compareData(seqByteRet, _arByte), "sequence test") And bRet + Dim _arChar() As Char = New Char() {} + seqCharRet = xBT2.setSequenceChar(_arChar) + bRet = check( compareData(seqCharRet, _arChar), "sequence test") And bRet + Dim _arShort() As Short = New Short() {} + seqShortRet = xBT2.setSequenceShort(_arShort) + bRet = check( compareData(seqShortRet, _arShort), "sequence test") And bRet + Dim _arLong() As Integer = New Integer() {} + seqLongRet = xBT2.setSequenceLong(_arLong) + bRet = check( compareData(seqLongRet, _arLong), "sequence test") And bRet + Dim _arHyper() As Long = New Long(){} + seqHyperRet = xBT2.setSequenceHyper(_arHyper) + bRet = check( compareData(seqHyperRet, _arHyper), "sequence test") And bRet + Dim _arFloat() As Single = New Single(){} + seqFloatRet = xBT2.setSequenceFloat(_arFloat) + bRet = check( compareData(seqFloatRet, _arFloat), "sequence test") And bRet + Dim _arDouble() As Double = New Double(){} + seqDoubleRet = xBT2.setSequenceDouble(_arDouble) + bRet = check( compareData(seqDoubleRet, _arDouble), "sequence test") And bRet + Dim _arEnum() As TestEnum = New TestEnum(){} + seqEnumRet = xBT2.setSequenceEnum(_arEnum) + bRet = check( compareData(seqEnumRet, _arEnum), "sequence test") And bRet + Dim _arUShort() As UInt16 = New UInt16(){} + seqUShortRet = xBT2.setSequenceUShort(_arUShort) + bRet = check( compareData(seqUShortRet, _arUShort), "sequence test") And bRet + Dim _arULong() As UInt32 = New UInt32(){} + seqULongRet = xBT2.setSequenceULong(_arULong) + bRet = check( compareData(seqULongRet, _arULong), "sequence test") And bRet + Dim _arUHyper() As UInt64 = New UInt64(){} + seqUHyperRet = xBT2.setSequenceUHyper(_arUHyper) + bRet = check( compareData(seqUHyperRet, _arUHyper), "sequence test") And bRet + Dim _arObject() As Object = New Object(){} + seqObjectRet = xBT2.setSequenceXInterface(_arObject) + bRet = check( compareData(seqObjectRet, _arObject), "sequence test") And bRet + Dim _arString() As String = New String(){} + seqStringRet = xBT2.setSequenceString(_arString) + bRet = check( compareData(seqStringRet, _arString), "sequence test") And bRet + Dim _arStruct() As TestElement = New TestElement(){} + seqStructRet = xBT2.setSequenceStruct(_arStruct) + bRet = check( compareData(seqStructRet, _arStruct), "sequence test") And bRet + Return bRet + End Function + + Private Shared Function testAny(typ As Type, value As Object, _ + xLBT As XBridgeTest ) As Boolean + + Dim any As Any + If (typ Is Nothing) + any = New Any(value.GetType(), value) + Else + any = New Any(typ, value) + End If + + Dim any2 As Any = xLBT.transportAny(any) + Dim ret As Boolean = compareData(any, any2) + If ret = False + Console.WriteLine("any is different after roundtrip: in {0}, " _ + & "out {1}\n", _ + any.Type.FullName, any2.Type.FullName) + End If + Return ret + End Function + + Private Shared Function performAnyTest(xLBT As XBridgeTest, _ + data As TestDataElements) As Boolean + Dim bReturn As Boolean = True + bReturn = testAny( Nothing, data.Byte ,xLBT ) And bReturn + bReturn = testAny( Nothing, data.Short,xLBT ) And bReturn + bReturn = testAny( Nothing, data.UShort,xLBT ) And bReturn + bReturn = testAny( Nothing, data.Long,xLBT ) And bReturn + bReturn = testAny( Nothing, data.ULong,xLBT ) And bReturn + bReturn = testAny( Nothing, data.Hyper,xLBT ) And bReturn + bReturn = testAny( Nothing,data.UHyper,xLBT ) And bReturn + bReturn = testAny( Nothing, data.Float,xLBT ) And bReturn + bReturn = testAny( Nothing, data.Double,xLBT ) And bReturn + bReturn = testAny( Nothing, data.Enum,xLBT ) And bReturn + bReturn = testAny( Nothing, data.String,xLBT ) And bReturn + bReturn = testAny(GetType(unoidl.com.sun.star.uno.XWeak), _ + data.Interface,xLBT ) And bReturn + bReturn = testAny(Nothing, data, xLBT ) And bReturn + + Dim a1 As Any = New Any(True) + Dim a2 As Any = xLBT.transportAny( a1 ) + bReturn = compareData(a2, a1) And bReturn + + Dim a3 As Any = New Any("A"C) + Dim a4 As Any = xLBT.transportAny(a3) + bReturn = compareData(a4, a3) And bReturn + + Return bReturn + End Function + + Private Shared Function performSequenceOfCallTest(xLBT As XBridgeTest) As Boolean + + Dim i, nRounds As Integer + Dim nGlobalIndex As Integer = 0 + const nWaitTimeSpanMUSec As Integer = 10000 + For nRounds = 0 To 9 + For i = 0 To nRounds - 1 + ' fire oneways + xLBT.callOneway(nGlobalIndex, nWaitTimeSpanMUSec) + nGlobalIndex = nGlobalIndex + 1 + Next + + ' call synchron + xLBT.call(nGlobalIndex, nWaitTimeSpanMUSec) + nGlobalIndex = nGlobalIndex + 1 + Next + Return xLBT.sequenceOfCallTestPassed() + End Function + + Private Shared Function performRecursiveCallTest(xLBT As XBridgeTest) As Boolean + xLBT.startRecursiveCall(new ORecursiveCall(), 50) + ' on failure, the test would lock up or crash + Return True + End Function + + + Private Shared Function performTest(xLBT As XBridgeTest) As Boolean + check( Not xLBT Is Nothing, "### no test interface!" ) + Dim bRet As Boolean = True + If xLBT Is Nothing + Return False + End If + 'this data is never ever granted access to by calls other than equals(), assign()! + Dim aData As New TestDataElements' test against this data + Dim xI As New WeakBase + + Dim aAny As New Any(GetType(System.Object), xI) + assign( DirectCast(aData, TestElement), _ + True, "@"C, 17, &H1234, Convert.ToUInt16(&HdcS), &H12345678, _ + Convert.ToUInt32(4294967294), _ + &H123456789abcdef0, Convert.ToUInt64(14294967294), _ + 17.0815f, 3.1415926359, TestEnum.LOLA, _ + CONSTANTS.STRING_TEST_CONSTANT, xI, _ + aAny) + + bRet = check( aData.Any.Value Is xI, "### unexpected any!" ) And bRet + + aData.Sequence = New TestElement(1){} + aData.Sequence(0) = New TestElement( _ + 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, _ + aData.Interface, aData.Any) + aData.Sequence(1) = New TestElement 'is empty + + ' aData complete + ' + ' this is a manually copy of aData for first setting... + Dim aSetData As New TestDataElements + Dim aAnySet As New Any(GetType(System.Object), xI) + assign( DirectCast(aSetData, TestElement), _ + 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, aAnySet) + + aSetData.Sequence = New TestElement(1){} + aSetData.Sequence(0) = New TestElement( _ + 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(1) = New TestElement ' empty struct + + 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 ) + + + Dim aRet As New TestDataElements + Dim aRet2 As New TestDataElements + 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 ) + + bRet = check( compareData( aData, aRet ) And _ + compareData( aData, aRet2 ) , "getValues test") And bRet + + ' set last retrieved values + Dim aSV2ret As TestDataElements= 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 ) + + ' check inout sequence order + ' => inout sequence parameter was switched by test objects + Dim temp As TestElement = aRet.Sequence( 0 ) + aRet.Sequence( 0 ) = aRet.Sequence( 1 ) + aRet.Sequence( 1 ) = temp + + bRet = check( _ + compareData( aData, aSV2ret ) And compareData( aData, aRet2 ), _ + "getValues2 test") And bRet + + + aRet = New TestDataElements + aRet2 = New TestDataElements + Dim aGVret As TestDataElements= 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 ) + + bRet = check( compareData( aData, aRet ) And _ + compareData( aData, aRet2 ) And _ + compareData( aData, aGVret ), "getValues test" ) And bRet + + ' set last retrieved values + xLBT.Bool = aRet.Bool + xLBT.Char = aRet.Char + xLBT.Byte = aRet.Byte + xLBT.Short = aRet.Short + xLBT.UShort = aRet.UShort + xLBT.Long = aRet.Long + xLBT.ULong = aRet.ULong + xLBT.Hyper = aRet.Hyper + xLBT.UHyper = aRet.UHyper + xLBT.Float = aRet.Float + xLBT.Double = aRet.Double + xLBT.Enum = aRet.Enum + xLBT.String = aRet.String + xLBT.Interface = aRet.Interface + xLBT.Any = aRet.Any + xLBT.Sequence = aRet.Sequence + xLBT.Struct = aRet2 + + + aRet = New TestDataElements + aRet2 = New TestDataElements + aRet.Hyper = xLBT.Hyper + aRet.UHyper = xLBT.UHyper + aRet.Float = xLBT.Float + aRet.Double = xLBT.Double + aRet.Byte = xLBT.Byte + aRet.Char = xLBT.Char + aRet.Bool = xLBT.Bool + aRet.Short = xLBT.Short + aRet.UShort = xLBT.UShort + aRet.Long = xLBT.Long + aRet.ULong = xLBT.ULong + aRet.Enum = xLBT.Enum + aRet.String = xLBT.String + aRet.Interface = xLBT.Interface + aRet.Any = xLBT.Any + aRet.Sequence = xLBT.Sequence + aRet2 = xLBT.Struct + + bRet = check( compareData( aData, aRet ) And _ + compareData( aData, aRet2 ) , "struct comparison test") _ + And bRet + + bRet = check(performSequenceTest(xLBT), "sequence test") And bRet + + ' any test + bRet = check( performAnyTest( xLBT , aData ) , "any test" ) And bRet + + 'sequence of call test + bRet = check( performSequenceOfCallTest( xLBT ) , _ + "sequence of call test" ) And bRet + + ' recursive call test + bRet = check( performRecursiveCallTest( xLBT ) , "recursive test" ) _ + And bRet + + bRet = (compareData( aData, aRet ) And compareData( aData, aRet2 )) _ + And bRet + + ' check setting of null reference + xLBT.Interface = Nothing + aRet.Interface = xLBT.Interface + bRet = (aRet.Interface Is Nothing) And bRet + + Return bRet + End Function + + Private Shared Function raiseException(xLBT As XBridgeTest) As Boolean + Dim nCount As Integer = 0 + Try + Try + Try + Dim aRet As TestDataElements = New TestDataElements + Dim aRet2 As TestDataElements = New TestDataElements + xLBT.raiseException( _ + 5, CONSTANTS.STRING_TEST_CONSTANT, xLBT.Interface ) + Catch rExc As unoidl.com.sun.star.lang.IllegalArgumentException + If rExc.ArgumentPosition = 5 And _ + rExc.Context Is xLBT.Interface + nCount = nCount + 1 + Else + check( False, "### unexpected exception content!" ) + End If + + 'it is certain, that the RuntimeException testing will fail, + ' if no + xLBT.RuntimeException = 0 + End Try + Catch rExc As unoidl.com.sun.star.uno.RuntimeException + If rExc.Context Is xLBT.Interface + nCount = nCount + 1 + Else + check( False, "### unexpected exception content!" ) + End If + xLBT.RuntimeException = CType(&Hcafebabe, Integer) + End Try + Catch rExc As unoidl.com.sun.star.uno.Exception + If rExc.Context Is xLBT.Interface + nCount = nCount + 1 + Else + check( False, "### unexpected exception content!" ) + End If + Return nCount = 3 + End Try + Return False + End Function + + Private Shared Function raiseOnewayException(xLBT As XBridgeTest) As Boolean + Dim bReturn As Boolean= True + Dim sCompare As String = CONSTANTS.STRING_TEST_CONSTANT + 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.Interface ) + Catch e As RuntimeException + bReturn = xLBT.Interface Is e.Context + End Try + Return bReturn + End Function + + 'Test the System::Object method on the proxy object + ' + Private Shared Function testObjectMethodsImplemention(xLBT As XBridgeTest) As Boolean + Dim ret As Boolean = False + Dim obj As Object = New Object + Dim xInt As Object = DirectCast(xLBT, Object) + Dim xBase As XBridgeTestBase = DirectCast(xLBT, XBridgeTestBase) + ' Object.Equals + ret = DirectCast(xLBT, Object).Equals(obj) = False + ret = DirectCast(xLBT, Object).Equals(xLBT) And ret + ret = Object.Equals(obj, obj) And ret + ret = Object.Equals(xLBT, xBase) And ret + 'Object.GetHashCode + ' Don't know how to verify this. Currently it is not possible to get the object id from a proxy + Dim nHash As Integer = DirectCast(xLBT, Object).GetHashCode() + ret = nHash = DirectCast(xBase, Object).GetHashCode() And ret + + 'Object.ToString + ' Don't know how to verify this automatically. + Dim s As String = DirectCast(xLBT, Object).ToString() + ret = (s.Length > 0) And ret + Return ret + End Function + + Private Shared Function performQueryForUnknownType(xLBT As XBridgeTest) As Boolean + Dim bRet As Boolean = False + ' test queryInterface for an unknown type + Try + Dim a As foo.MyInterface = DirectCast(xLBT, foo.MyInterface) + Catch e As System.InvalidCastException + bRet = True + End Try + + Return bRet + End Function + + + Private Shared Sub perform_test( xLBT As XBridgeTest) + Dim bRet As Boolean = True + bRet = check( performTest( xLBT ), "standard test" ) And bRet + bRet = check( raiseException( xLBT ) , "exception test" ) And bRet + bRet = check( raiseOnewayException( xLBT ), "oneway exception test" ) _ + And bRet + bRet = check( testObjectMethodsImplemention(xLBT), _ + "object methods test") And bRet + bRet = performQueryForUnknownType( xLBT ) And bRet + If Not bRet + Throw New unoidl.com.sun.star.uno.RuntimeException( "error: test failed!", Nothing) + End If + End Sub + + + + Public Overridable Function run(args() As String) As Integer _ + Implements XMain.run + Try + If (args.Length < 1) + Throw New RuntimeException( _ + "missing argument for bridgetest!", Me ) + End If + + Dim test_obj As Object = _ + m_xContext.getServiceManager().createInstanceWithContext( _ + args( 0 ), m_xContext ) + + Debug.WriteLine( _ + "cli target bridgetest obj: {0}", test_obj.ToString() ) + Dim xTest As XBridgeTest = DirectCast(test_obj, XBridgeTest) + perform_test( xTest ) + Console.WriteLine("### cli_uno VB bridgetest succeeded.") + return 0 + Catch e as unoidl.com.sun.star.uno.RuntimeException + Throw + Catch e as System.Exception + Throw New unoidl.com.sun.star.uno.RuntimeException( _ + "cli_vb_bridgetest.vb: unexpected exception occured in XMain::run. " _ + & "Original exception: " + e.GetType().Name + "\n Message: " _ + & e.Message , Nothing) + + End Try + End Function + +End Class + +End Namespace diff --git a/testtools/source/bridgetest/cli/cli_vb_testobj.vb b/testtools/source/bridgetest/cli/cli_vb_testobj.vb new file mode 100644 index 000000000000..8e7cfe6d0084 --- /dev/null +++ b/testtools/source/bridgetest/cli/cli_vb_testobj.vb @@ -0,0 +1,624 @@ +'************************************************************************* +' +' DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +' +' Copyright 2000, 2010 Oracle and/or its affiliates. +' +' OpenOffice.org - a multi-platform office productivity suite +' +' This file is part of OpenOffice.org. +' +' OpenOffice.org is free software: you can redistribute it and/or modify +' it under the terms of the GNU Lesser General Public License version 3 +' only, as published by the Free Software Foundation. +' +' OpenOffice.org 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 version 3 for more details +' (a copy is included in the LICENSE file that accompanied this code). +' +' You should have received a copy of the GNU Lesser General Public License +' version 3 along with OpenOffice.org. If not, see +' <http://www.openoffice.org/license.html> +' for a copy of the LGPLv3 License. +' +'************************************************************************* + +Option Explicit On +Option Strict On + +imports System +imports uno +imports uno.util +imports unoidl.com.sun.star.lang +imports unoidl.com.sun.star.uno +imports unoidl.com.sun.star.test.bridge +imports System.Windows.Forms +imports System.Diagnostics +imports System.Reflection + + +Namespace vb_testobj +Public Class VBBridgeTestObject + Inherits WeakBase + Implements XRecursiveCall, XBridgeTest2 + + Private m_xContext As XComponentContext + + Public Sub New (xContext As XComponentContext) + MyBase.New + m_xContext = xContext + End Sub + + Private m_bool As Boolean + Private m_char As Char + Private m_byte As Byte + Private m_short As Short + Private m_ushort As UInt16 + Private m_long As Integer + Private m_ulong As UInt32 + Private m_hyper As Long + Private m_uhyper As UInt64 + Private m_float As Single + Private m_double As Double + Private m_string As String + Private m_xInterface As Object + Private m_any As Any + Private m_testEnum As TestEnum = TestEnum.TEST + Private m_testElements() As TestElement = New TestElement(){} + Private m_testDataElements As TestDataElements = New TestDataElements + Private m_nLastCallId As Integer = 0 + Private m_bFirstCall As Boolean = True + Private m_bSequenceOfCallTestPassed As Boolean = True + + Private m_arBool() As Boolean + Private m_arChar() As Char + Private m_arByte() As Byte + Private m_arShort() As Short + Private m_arLong() As Integer + Private m_arHyper() As Long + Private m_arUShort() As UInt16 + Private m_arULong() As UInt32 + Private m_arUHyper() As UInt64 + Private m_arString() As String + Private m_arFloat() As Single + Private m_arDouble() As Double + Private m_arEnum() As TestEnum + Private m_arObject() As Object + Private m_arLong2()() As Integer + Private m_arLong3()()() As Integer + Private m_arAny() As Any + + Public Overridable Sub setValues( _ + bBool As Boolean, aChar As Char, nByte As Byte, nShort As Short, _ + nUShort As UInt16, nLong As Integer, nULong As UInt32, _ + nHyper As Long, nUHyper As UInt64, fFloat As Single, _ + fDouble As Double, testEnum As TestEnum, str As String, _ + xInterface As Object, any As Any, testElements() As TestElement, _ + testDataElements As TestDataElements) _ + Implements XBridgeTest2.setValues +#if DEBUG + ' Console.WriteLine( "##### " + GetType().FullName + ".setValues:" + any ) +#endif + m_bool = bBool + m_char = aChar + m_byte = nByte + m_short = nShort + m_ushort = nUShort + m_long = nLong + m_ulong = nULong + m_hyper = nHyper + m_uhyper = nUHyper + m_float = fFloat + m_double = fDouble + m_testEnum = testEnum + m_string = str + m_xInterface = xInterface + m_any = any + m_testElements = testElements + m_testDataElements = testDataElements + End Sub + + Public Overridable Function setValues2( _ + ByRef io_bool As Boolean, ByRef io_char As Char, _ + ByRef io_byte As Byte, ByRef io_short As Short, _ + ByRef io_ushort As UInt16, ByRef io_long As Integer, _ + ByRef io_ulong As UInt32, ByRef io_hyper As Long, _ + ByRef io_uhyper As UInt64, ByRef io_float As Single, _ + ByRef io_double As Double, ByRef io_testEnum As TestEnum, _ + ByRef io_string As String, ByRef io_xInterface As Object, _ + ByRef io_any As Any, ByRef io_testElements() As TestElement, _ + ByRef io_testDataElements As TestDataElements) As TestDataElements _ + Implements XBridgeTest2.setValues2 + +#if DEBUG + 'Console.WriteLine( "##### " + GetType().FullName + ".setValues2:" + io_any ) +#endif + + m_bool = io_bool + m_char = io_char + m_byte = io_byte + m_short = io_short + m_ushort = io_ushort + m_long = io_long + m_ulong = io_ulong + m_hyper = io_hyper + m_uhyper = io_uhyper + m_float = io_float + m_double = io_double + m_testEnum = io_testEnum + m_string = io_string + m_xInterface = io_xInterface + m_any = io_any + m_testElements = DirectCast(io_testElements.Clone(), TestElement()) + m_testDataElements = io_testDataElements + + Dim temp As TestElement = io_testElements(0) + io_testElements(0) = io_testElements(1) + io_testElements(1) = temp + + Return m_testDataElements + End Function + + Public Overridable Function getValues( _ + ByRef o_bool As Boolean, ByRef o_char As Char, _ + ByRef o_byte As Byte, ByRef o_short As Short, _ + ByRef o_ushort As UInt16, ByRef o_long As Integer, _ + ByRef o_ulong As UInt32, ByRef o_hyper As Long, _ + ByRef o_uhyper As UInt64, ByRef o_float As Single, _ + ByRef o_double As Double, ByRef o_testEnum As TestEnum, _ + ByRef o_string As String, ByRef o_xInterface As Object, _ + ByRef o_any As Any, ByRef o_testElements() As TestElement, _ + ByRef o_testDataElements As TestDataElements) As TestDataElements _ + Implements XBridgeTest2.getValues +#if DEBUG + 'Console.WriteLine( "##### " + GetType().FullName + ".getValues" ) +#endif + + o_bool = m_bool + o_char = m_char + o_byte = m_byte + o_short = m_short + o_ushort = m_ushort + o_long = m_long + o_ulong = m_ulong + o_hyper = m_hyper + o_uhyper = m_uhyper + o_float = m_float + o_double = m_double + o_testEnum = m_testEnum + o_string = m_string + o_xInterface = m_xInterface + o_any = m_any + o_testElements = m_testElements + o_testDataElements = m_testDataElements + + Return m_testDataElements + End Function + + ' Attributes --------------------------------------------------------- + Public Overridable Property Bool As Boolean _ + Implements XBridgeTest2.Bool + Get + Return m_bool + End Get + Set (Value As Boolean) + m_bool = value + End Set + End Property + + Public Overridable Property [Byte] As Byte _ + Implements XBridgeTest2.Byte + Get + Return m_byte + End Get + Set (Value As Byte) + m_byte = value + End Set + End Property + + Public Overridable Property [Char] As Char _ + Implements XBridgeTest2.Char + Get + Return m_char + End Get + Set (Value As Char) + m_char = value + End Set + End Property + + Public Overridable Property [Short] As Short _ + Implements XBridgeTest2.Short + Get + Return m_short + End Get + Set (Value As Short) + m_short = value + End Set + End Property + + Public Overridable Property [UShort] As UInt16 _ + Implements XBridgeTest2.UShort + Get + Return m_ushort + End Get + Set (Value As UInt16) + m_ushort = value + End Set + End Property + + Public Overridable Property [Long] As Integer _ + Implements XBridgeTest2.Long + Get + Return m_long + End Get + Set (Value As Integer) + m_long = value + End Set + End Property + + Public Overridable Property [ULong]() As UInt32 _ + Implements XBridgeTest2.ULong + Get + Return m_ulong + End Get + Set (Value As UInt32) + m_ulong = value + End Set + End Property + + Public Overridable Property Hyper As Long _ + Implements XBridgeTest2.Hyper + Get + Return m_hyper + End Get + Set (Value As Long) + m_hyper = value + End Set + End Property + + Public Overridable Property UHyper As UInt64 _ + Implements XBridgeTest2.UHyper + Get + Return m_uhyper + End Get + Set (Value As UInt64) + m_uhyper = value + End Set + End Property + + Public Overridable Property Float As Single _ + Implements XBridgeTest2.Float + Get + Return m_float + End Get + Set (Value As Single) + m_float = value + End Set + End Property + + Public Overridable Property [Double] As Double _ + Implements XBridgeTest2.Double + Get + Return m_double + End Get + Set (Value As Double) + m_double = value + End Set + End Property + + Public Overridable Property [Enum] As TestEnum _ + Implements XBridgeTest2.Enum + Get + Return m_testEnum + End Get + Set (Value As TestEnum) + m_testEnum = value + End Set + End Property + + Public Overridable Property [String] As String _ + Implements XBridgeTest2.String + Get + Return m_string + End Get + Set (Value As String) + m_string = value + End Set + End Property + + Public Overridable Property [Interface] As Object _ + Implements XBridgeTest2.Interface + Get + Return m_xInterface + End Get + Set (Value As Object) + m_xInterface = value + End Set + End Property + + Public Overridable Property Any As uno.Any _ + Implements XBridgeTest2.Any + Get +#if DEBUG +' Console.WriteLine( "##### " + GetType().FullName + ".Any" ) +#endif + Return m_any + End Get + Set (Value As Any) +#if DEBUG + 'Console.WriteLine( "##### " + GetType().FullName + ".Any:" + value ) +#endif + m_any = value + End Set + End Property + + Public Overridable Property Sequence As TestElement() _ + Implements XBridgeTest2.Sequence + Get + Return m_testElements + End Get + Set (Value() As TestElement) + m_testElements = value + End Set + End Property + + Public Overridable Property Struct As TestDataElements _ + Implements XBridgeTest2.Struct + Get + Return m_testDataElements + End Get + Set (Value As TestDataElements) + m_testDataElements = value + End Set + End Property + + Public Overridable Function transportAny(value As Any) As Any _ + Implements XBridgeTest2.transportAny + Return value + End Function + + Public Overridable Sub [call](nCallId As Integer, nWaitMUSEC As Integer) _ + Implements XBridgeTest2.call + + Threading.Thread.Sleep(CType(nWaitMUSEC / 10000, Integer)) + If m_bFirstCall = True + m_bFirstCall = False + Else + m_bSequenceOfCallTestPassed = m_bSequenceOfCallTestPassed And (nCallId > m_nLastCallId) + End If + m_nLastCallId = nCallId + End Sub + + Public Overridable Sub callOneway(nCallId As Integer, nWaitMUSEC As Integer) _ + Implements XBridgeTest2.callOneway + + Threading.Thread.Sleep(CType(nWaitMUSEC / 10000, Integer)) + m_bSequenceOfCallTestPassed = m_bSequenceOfCallTestPassed And (nCallId > m_nLastCallId) + m_nLastCallId = nCallId + End Sub + + Public Overridable Function sequenceOfCallTestPassed() As Boolean _ + Implements XBridgeTest2.sequenceOfCallTestPassed + Return m_bSequenceOfCallTestPassed + End Function + + Public Overridable Sub callRecursivly(xCall As XRecursiveCall, nToCall As Integer) _ + Implements XRecursiveCall.callRecursivly + SyncLock (Me) + If nToCall <> 0 + nToCall = nToCall - 1 + xCall.callRecursivly(Me , nToCall) + End If + End SyncLock + End Sub + + Public Overridable Sub startRecursiveCall(xCall As XRecursiveCall, nToCall As Integer) _ + Implements XBridgeTest2.startRecursiveCall + SyncLock (Me) + If nToCall <> 0 + nToCall = nToCall - 1 + xCall.callRecursivly(Me , nToCall ) + End If + End SyncLock + End Sub + + ' XBridgeTest + Public Overridable Function raiseException( _ + nArgumentPos As Short, rMsg As String, xContext As Object) As TestDataElements _ + Implements XBridgeTest2.raiseException + Throw New IllegalArgumentException(rMsg, xContext, nArgumentPos) + End Function + + Public Overridable Sub raiseRuntimeExceptionOneway(rMsg As String , xContext As Object) _ + Implements XBridgeTest2.raiseRuntimeExceptionOneway + Throw New RuntimeException(rMsg, xContext) + End Sub + + Public Overridable Property RuntimeException As Integer _ + Implements XBridgeTest2.RuntimeException + Get + Throw New RuntimeException(m_string, m_xInterface) + End Get + Set (Value As Integer) + Throw New RuntimeException(m_string, m_xInterface) + End Set + End Property + + ' XBridgeTest2 + Public Overridable Function setDim2(val()() As Integer) As Integer()() _ + Implements XBridgeTest2.setDim2 + m_arLong2 = val + Return val + End Function + + Public Overridable Function setDim3(val()()() As Integer) As Integer()()() _ + Implements XBridgeTest2.setDim3 + m_arLong3 = val + Return val + End Function + + Public Overridable Function setSequenceAny(val() As Any) As Any() _ + Implements XBridgeTest2.setSequenceAny + m_arAny = val + Return val + End Function + + Public Overridable Function setSequenceBool(val() As Boolean) As Boolean() _ + Implements XBridgeTest2.setSequenceBool + m_arBool = val + Return val + End Function + + Public Overridable Function setSequenceByte(val() As Byte) As Byte() _ + Implements XBridgeTest2.setSequenceByte + m_arByte = val + Return val + End Function + + Public Overridable Function setSequenceChar(val() As Char) As Char() _ + Implements XBridgeTest2.setSequenceChar + m_arChar = val + Return val + End Function + + Public Overridable Function setSequenceShort(val() As Short) As Short() _ + Implements XBridgeTest2.setSequenceShort + m_arShort = val + Return val + End Function + + Public Overridable Function setSequenceLong(val() As Integer) As Integer() _ + Implements XBridgeTest2.setSequenceLong + + m_arLong = val + Return val + End Function + + Public Overridable Function setSequenceHyper(val() As Long) As Long() _ + Implements XBridgeTest2.setSequenceHyper + m_arHyper = val + Return val + End Function + + Public Overridable Function setSequenceFloat(val() As Single) As Single() _ + Implements XBridgeTest2.setSequenceFloat + m_arFloat = val + Return val + End Function + + Public Overridable Function setSequenceDouble(val() As Double) As Double() _ + Implements XBridgeTest2.setSequenceDouble + m_arDouble = val + Return val + End Function + + Public Overridable Function setSequenceEnum(val() As TestEnum) As TestEnum() _ + Implements XBridgeTest2.setSequenceEnum + m_arEnum = val + Return val + End Function + + Public Overridable Function setSequenceUShort(val() As UInt16) As UInt16() _ + Implements XBridgeTest2.setSequenceUShort + m_arUShort = val + Return val + End Function + + Public Overridable Function setSequenceULong(val() As UInt32) As UInt32() _ + Implements XBridgeTest2.setSequenceULong + m_arULong = val + Return val + End Function + + Public Overridable Function setSequenceUHyper(val() As UInt64) As UInt64() _ + Implements XBridgeTest2.setSequenceUHyper + m_arUHyper = val + Return val + End Function + + Public Overridable Function setSequenceXInterface(val() As Object ) As Object() _ + Implements XBridgeTest2.setSequenceXInterface + m_arObject = val + Return val + End Function + + Public Overridable Function setSequenceString(val() As String) As String() _ + Implements XBridgeTest2.setSequenceString + m_arString = val + Return val + End Function + + Public Overridable Function setSequenceStruct(val() As TestElement) As TestElement() _ + Implements XBridgeTest2.setSequenceStruct + m_testElements = val + Return val + End Function + + Public Overridable Sub setSequencesInOut( _ + ByRef aSeqBoolean() As Boolean, ByRef aSeqChar() As Char, _ + ByRef aSeqByte() As Byte, ByRef aSeqShort() As Short, _ + ByRef aSeqUShort() As UInt16, ByRef aSeqLong() As Integer, _ + ByRef aSeqULong() As UInt32, ByRef aSeqHyper() As Long, _ + ByRef aSeqUHyper() As UInt64, ByRef aSeqFloat() As Single, _ + ByRef aSeqDouble() As Double, ByRef aSeqTestEnum() As TestEnum, _ + ByRef aSeqString() As String, ByRef aSeqXInterface() As Object, _ + ByRef aSeqAny() As Any, ByRef aSeqDim2()() As Integer, _ + ByRef aSeqDim3()()() As Integer) _ + Implements XBridgeTest2.setSequencesInOut + + m_arBool = aSeqBoolean + m_arChar = aSeqChar + m_arByte = aSeqByte + m_arShort = aSeqShort + m_arUShort = aSeqUShort + m_arLong = aSeqLong + m_arULong = aSeqULong + m_arHyper = aSeqHyper + m_arUHyper = aSeqUHyper + m_arFloat = aSeqFloat + m_arDouble = aSeqDouble + m_arEnum = aSeqTestEnum + m_arString = aSeqString + m_arObject = aSeqXInterface + m_arAny = aSeqAny + m_arLong2 = aSeqDim2 + m_arLong3 = aSeqDim3 + End Sub + + Public Overridable Sub setSequencesOut( _ + ByRef aSeqBoolean() As Boolean, ByRef aSeqChar() As Char, _ + ByRef aSeqByte() As Byte, ByRef aSeqShort() As Short, _ + ByRef aSeqUShort() As UInt16, ByRef aSeqLong() As Integer, _ + ByRef aSeqULong() As UInt32, ByRef aSeqHyper() As Long, _ + ByRef aSeqUHyper() As UInt64, ByRef aSeqFloat() As Single, _ + ByRef aSeqDouble() As Double, ByRef aSeqTestEnum() As TestEnum, _ + ByRef aSeqString() As String, ByRef aSeqXInterface() As Object, _ + ByRef aSeqAny() As Any, ByRef aSeqDim2()() As Integer, _ + ByRef aSeqDim3()()() As Integer) _ + Implements XBridgeTest2.setSequencesOut + + aSeqBoolean = m_arBool + aSeqChar = m_arChar + aSeqByte = m_arByte + aSeqShort = m_arShort + aSeqUShort = m_arUShort + aSeqLong = m_arLong + aSeqULong = m_arULong + aSeqHyper = m_arHyper + aSeqUHyper = m_arUHyper + aSeqFloat = m_arFloat + aSeqDouble = m_arDouble + aSeqTestEnum = m_arEnum + aSeqString = m_arString + aSeqXInterface = m_arObject + aSeqAny = m_arAny + aSeqDim2 = m_arLong2 + aSeqDim3 = m_arLong3 + + End Sub + +End Class + +End Namespace diff --git a/testtools/source/bridgetest/cli/makefile.mk b/testtools/source/bridgetest/cli/makefile.mk new file mode 100644 index 000000000000..3e5fd43df7d4 --- /dev/null +++ b/testtools/source/bridgetest/cli/makefile.mk @@ -0,0 +1,203 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2000, 2010 Oracle and/or its affiliates. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org 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 version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* + +PRJ=..$/..$/.. + +PRJNAME=testtools +TARGET=cli_cpp_bridgetest.uno +USE_DEFFILE=TRUE +NO_BSYMBOLIC=TRUE +ENABLE_EXCEPTIONS=TRUE +LIBTARGET=NO + +# disable caching to avoid stale objects +# on version changes +CCACHE_DISABLE=TRUE +.EXPORT : CCACHE_DISABLE + +# --- Settings ----------------------------------------------------- + +.INCLUDE : settings.mk +DLLPRE = +CFLAGSENABLESYMBOLS:=-Z7 +# ------------------------------------------------------------------ + +#These tests are for Windows only +.IF "$(COM)" == "MSC" && "$(GUI)" == "WNT" + +.IF "$(CCNUMVER)" >= "001399999999" +CFLAGSCXX += -clr:oldSyntax -AI $(OUT)$/bin -AI $(SOLARBINDIR) +SHL1STDLIBS = \ + mscoree.lib \ + msvcmrt.lib +.ELSE +CFLAGSCXX += -clr -AI $(OUT)$/bin -AI $(SOLARBINDIR) +SHL1STDLIBS = \ + mscoree.lib +.ENDIF +SLOFILES= \ + $(SLO)$/cli_cpp_bridgetest.obj + +SHL1OBJS = $(SLOFILES) + +SHL1TARGET = $(TARGET) + +SHL1DEF = $(MISC)$/$(SHL1TARGET).def +DEF1NAME = $(SHL1TARGET) + +.ENDIF + +# --- Targets ------------------------------------------------------ + +.INCLUDE : target.mk + +.IF "$(COM)" == "MSC" && "$(GUI)" == "WNT" + +ALLTAR : $(BIN)$/cli_bridgetest_inprocess.exe + +################################################################# + +CLI_URE = $(SOLARBINDIR)$/cli_ure.dll +CLI_URETYPES = $(SOLARBINDIR)$/cli_uretypes.dll +CLI_BASETYPES = $(SOLARBINDIR)$/cli_basetypes.dll +CLI_CPPUHELPER = $(SOLARBINDIR)$/cli_cppuhelper.dll +CLI_OOOTYPES = $(SOLARBINDIR)$/cli_oootypes.dll +CLI_TYPES_BRIDGETEST = $(BIN)$/cli_types_bridgetest.dll + +CSCFLAGS = -warnaserror+ +.IF "$(CCNUMVER)" <= "001399999999" +VBC_FLAGS = -warnaserror+ +.ELSE +VBC_FLAGS = -nowarn:42030 -warnaserror+ +.ENDIF +.IF "$(debug)" != "" +CSCFLAGS += -debug+ -checked+ -define:DEBUG -define:TRACE +VBC_FLAGS += -debug+ -define:DEBUG=TRUE -define:TRACE=TRUE +.ELSE +CSCFLAGS += -optimize +VBC_FLAGS += -optimize +.ENDIF + + +# C# ---------------------------------------------- +$(BIN)$/cli_cs_testobj.uno.dll : \ + cli_cs_testobj.cs \ + cli_cs_multi.cs \ + $(CLI_BASETYPES) \ + $(CLI_URETYPES) \ + $(CLI_URE) + $(CSC) $(CSCFLAGS) -target:library -out:$@ \ + -reference:$(CLI_TYPES_BRIDGETEST) \ + -reference:$(CLI_URE) \ + -reference:$(CLI_BASETYPES) \ + -reference:$(CLI_URETYPES) \ + cli_cs_testobj.cs cli_cs_multi.cs + +$(BIN)$/cli_cs_bridgetest.uno.dll : \ + cli_cs_bridgetest.cs \ + $(CLI_BASETYPES) \ + $(CLI_URETYPES) \ + $(CLI_URE) + $(CSC) $(CSCFLAGS) -target:library -out:$@ \ + -reference:$(CLI_TYPES_BRIDGETEST) \ + -reference:$(CLI_URETYPES) \ + -reference:$(CLI_BASETYPES) \ + -reference:$(CLI_URE) \ + -reference:System.dll \ + cli_cs_bridgetest.cs + +# Visual Basic ------------------------------------------ +$(BIN)$/cli_vb_bridgetest.uno.dll : \ + cli_vb_bridgetest.vb \ + $(CLI_BASETYPES) \ + $(CLI_URETYPES) \ + $(CLI_URE) + $(VBC) $(VBC_FLAGS) \ + -target:library \ + -out:$@ \ + -reference:$(CLI_URETYPES) \ + -reference:$(CLI_BASETYPES) \ + -reference:$(CLI_URE) \ + -reference:$(CLI_TYPES_BRIDGETEST) \ + -reference:System.dll \ + -reference:System.Drawing.dll \ + -reference:System.Windows.Forms.dll \ + cli_vb_bridgetest.vb + +$(BIN)$/cli_vb_testobj.uno.dll : \ + cli_vb_testobj.vb \ + $(CLI_BASETYPES) \ + $(CLI_URETYPES) \ + $(CLI_URE) + $(VBC) $(VBC_FLAGS) \ + -target:library \ + -out:$@ \ + -reference:$(CLI_BASETYPES) \ + -reference:$(CLI_URETYPES) \ + -reference:$(CLI_URE) \ + -reference:$(CLI_TYPES_BRIDGETEST) \ + -reference:System.dll \ + -reference:System.Drawing.dll \ + -reference:System.Windows.Forms.dll \ + cli_vb_testobj.vb + +$(MISC)$/copyassemblies.done .ERRREMOVE: + $(GNUCOPY) $(CLI_CPPUHELPER) $(BIN)$/$(CLI_CPPUHELPER:f) + $(GNUCOPY) $(CLI_BASETYPES) $(BIN)$/$(CLI_BASETYPES:f) + $(GNUCOPY) $(CLI_URETYPES) $(BIN)$/$(CLI_URETYPES:f) + $(GNUCOPY) $(CLI_URE) $(BIN)$/$(CLI_URE:f) + $(GNUCOPY) $(CLI_OOOTYPES) $(BIN)$/$(CLI_OOOTYPES:f) + $(TOUCH) $@ + +$(BIN)$/cli_bridgetest_inprocess.exe : \ + cli_bridgetest_inprocess.cs \ + $(BIN)$/cli_cs_bridgetest.uno.dll \ + $(BIN)$/cli_cs_testobj.uno.dll \ + $(BIN)$/cli_vb_bridgetest.uno.dll \ + $(BIN)$/cli_vb_testobj.uno.dll \ + $(BIN)$/cli_cpp_bridgetest.uno.dll \ + $(MISC)$/copyassemblies.done \ + $(CLI_BASETYPES) \ + $(CLI_URETYPES) \ + $(CLI_URE) \ + $(CLI_CPPUHELPER) + $(CSC) $(CSCFLAGS) -target:exe -out:$@ \ + -reference:$(CLI_TYPES_BRIDGETEST) \ + -reference:$(CLI_BASETYPES) \ + -reference:$(CLI_URETYPES) \ + -reference:$(CLI_URE) \ + -reference:$(CLI_CPPUHELPER) \ + -reference:$(BIN)$/cli_cs_bridgetest.uno.dll \ + -reference:$(BIN)$/cli_cs_testobj.uno.dll \ + -reference:$(BIN)$/cli_vb_bridgetest.uno.dll \ + -reference:$(BIN)$/cli_vb_testobj.uno.dll \ + -reference:$(BIN)$/cli_cpp_bridgetest.uno.dll \ + cli_bridgetest_inprocess.cs + $(GNUCOPY) cli_bridgetest_inprocess.ini $(BIN) + +.ENDIF + diff --git a/testtools/source/bridgetest/constructors.cxx b/testtools/source/bridgetest/constructors.cxx new file mode 100644 index 000000000000..feff9fef567d --- /dev/null +++ b/testtools/source/bridgetest/constructors.cxx @@ -0,0 +1,517 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_testtools.hxx" + +#include "sal/config.h" + +#include "com/sun/star/lang/XInitialization.hpp" +#include "com/sun/star/lang/XComponent.hpp" +#include "com/sun/star/uno/Any.hxx" +#include "com/sun/star/uno/Exception.hpp" +#include "com/sun/star/uno/Reference.hxx" +#include "com/sun/star/uno/Sequence.hxx" +#include "com/sun/star/uno/Type.hxx" +#include "com/sun/star/uno/XComponentContext.hpp" +#include "com/sun/star/uno/XInterface.hpp" +#include "cppu/unotype.hxx" +#include "cppuhelper/factory.hxx" +#include "cppuhelper/implbase1.hxx" +#include "cppuhelper/implbase2.hxx" +#include "cppuhelper/implementationentry.hxx" +#include "cppuhelper/weak.hxx" +#include "rtl/string.h" +#include "rtl/ustring.h" +#include "rtl/ustring.hxx" +#include "sal/types.h" +#include "test/testtools/bridgetest/BadConstructorArguments.hpp" +#include "test/testtools/bridgetest/TestEnum.hpp" +#include "test/testtools/bridgetest/TestStruct.hpp" +#include "test/testtools/bridgetest/TestPolyStruct.hpp" +#include "test/testtools/bridgetest/TestPolyStruct2.hpp" +#include "test/testtools/bridgetest/XMultiBase1.hpp" +#include "uno/lbnames.h" + +namespace { + +namespace css = ::com::sun::star; +namespace ttb = ::test::testtools::bridgetest; +class Impl: public ::cppu::WeakImplHelper1< css::lang::XInitialization > { +public: + Impl() {} + +private: + Impl(Impl &); // not defined + void operator =(Impl &); // not defined + + virtual ~Impl() {} + + virtual void SAL_CALL initialize( + css::uno::Sequence< css::uno::Any > const & arguments) + throw (css::uno::Exception); +}; + +void Impl::initialize(css::uno::Sequence< css::uno::Any > const & arguments) + throw (css::uno::Exception) +{ + ::sal_Bool arg0 = sal_Bool(); + ::sal_Int8 arg1 = sal_Int8(); + ::sal_Int16 arg2 = sal_Int16(); + ::sal_uInt16 arg3 = sal_uInt16(); + ::sal_Int32 arg4 = sal_Int32(); + ::sal_uInt32 arg5 = sal_uInt32(); + ::sal_Int64 arg6 = sal_Int64(); + ::sal_uInt64 arg7 = sal_uInt64(); + float arg8 = float(); + double arg9 = double(); + ::rtl::OUString arg11; + css::uno::Type arg12; + ::sal_Bool arg13 = sal_Bool(); + css::uno::Sequence< ::sal_Bool > arg14; + css::uno::Sequence< ::sal_Int8 > arg15; + css::uno::Sequence< ::sal_Int16 > arg16; + css::uno::Sequence< ::sal_uInt16 > arg17; + css::uno::Sequence< ::sal_Int32 > arg18; + css::uno::Sequence< ::sal_uInt32 > arg19; + css::uno::Sequence< ::sal_Int64 > arg20; + css::uno::Sequence< ::sal_uInt64 > arg21; + css::uno::Sequence< float > arg22; + css::uno::Sequence< double > arg23; + css::uno::Sequence< ::rtl::OUString > arg25; + css::uno::Sequence< css::uno::Type > arg26; + css::uno::Sequence< css::uno::Any > arg27; + ::sal_Bool arg27b = sal_Bool(); + css::uno::Sequence< css::uno::Sequence< ::sal_Bool > > arg28; + css::uno::Sequence< css::uno::Sequence< css::uno::Any > > arg29; + ::sal_Bool arg29b = sal_Bool(); + css::uno::Sequence< ::test::testtools::bridgetest::TestEnum > arg30; + css::uno::Sequence< ::test::testtools::bridgetest::TestStruct > arg31; + css::uno::Sequence< + ::test::testtools::bridgetest::TestPolyStruct< sal_Bool > > arg32; + css::uno::Sequence< + ::test::testtools::bridgetest::TestPolyStruct< css::uno::Any > > arg33; + ::sal_Bool arg33b = sal_Bool(); + css::uno::Sequence< css::uno::Reference< css::uno::XInterface > > arg34; + ::test::testtools::bridgetest::TestEnum arg35; + ::test::testtools::bridgetest::TestStruct arg36; + ::test::testtools::bridgetest::TestPolyStruct< ::sal_Bool > arg37; + ::test::testtools::bridgetest::TestPolyStruct< css::uno::Any > arg38; + ::sal_Bool arg38b = sal_Bool(); + css::uno::Reference< css::uno::XInterface > arg39; + if (!(arguments.getLength() == 40 + && (arguments[0] >>= arg0) && arg0 + && (arguments[1] >>= arg1) && arg1 == SAL_MIN_INT8 + && (arguments[2] >>= arg2) && arg2 == SAL_MIN_INT16 + && (arguments[3].getValueType() + == ::cppu::UnoType< ::cppu::UnoUnsignedShortType >::get()) + && (arguments[3] >>= arg3) && arg3 == SAL_MAX_UINT16 + && (arguments[4] >>= arg4) && arg4 == SAL_MIN_INT32 + && (arguments[5] >>= arg5) && arg5 == SAL_MAX_UINT32 + && (arguments[6] >>= arg6) && arg6 == SAL_MIN_INT64 + && (arguments[7] >>= arg7) && arg7 == SAL_MAX_UINT64 + && (arguments[8] >>= arg8) && arg8 == 0.123f + && (arguments[9] >>= arg9) && arg9 == 0.456 + && (arguments[10].getValueType() + == ::cppu::UnoType< ::cppu::UnoCharType >::get()) + && (*static_cast< ::sal_Unicode const * >(arguments[10].getValue()) + == 'X') + && (arguments[11] >>= arg11) + && arg11.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("test")) + && (arguments[12] >>= arg12) + && arg12 == ::cppu::UnoType< css::uno::Any >::get() + && (arguments[13] >>= arg13) && arg13 + && (arguments[14] >>= arg14) && arg14.getLength() == 1 && arg14[0] + && (arguments[15] >>= arg15) && arg15.getLength() == 1 + && arg15[0] == SAL_MIN_INT8 + && (arguments[16] >>= arg16) && arg16.getLength() == 1 + && arg16[0] == SAL_MIN_INT16 + && (arguments[17].getValueType() + == ::cppu::UnoType< + ::cppu::UnoSequenceType < + ::cppu::UnoUnsignedShortType > >::get()) + && (arguments[17] >>= arg17) && arg17.getLength() == 1 + && arg17[0] == SAL_MAX_UINT16 + && (arguments[18] >>= arg18) && arg18.getLength() == 1 + && arg18[0] == SAL_MIN_INT32 + && (arguments[19] >>= arg19) && arg19.getLength() == 1 + && arg19[0] == SAL_MAX_UINT32 + && (arguments[20] >>= arg20) && arg20.getLength() == 1 + && arg20[0] == SAL_MIN_INT64 + && (arguments[21] >>= arg21) && arg21.getLength() == 1 + && arg21[0] == SAL_MAX_UINT64 + && (arguments[22] >>= arg22) && arg22.getLength() == 1 + && arg22[0] == 0.123f + && (arguments[23] >>= arg23) && arg23.getLength() == 1 + && arg23[0] == 0.456 + && (arguments[24].getValueType() + == ::cppu::UnoType< + ::cppu::UnoSequenceType< ::cppu::UnoCharType > >::get()) + && (static_cast< css::uno::Sequence< ::sal_Unicode > const * >( + arguments[24].getValue())->getLength() + == 1) + && ((*static_cast< css::uno::Sequence< ::sal_Unicode > const * >( + arguments[24].getValue()))[0] + == 'X') + && (arguments[25] >>= arg25) && arg25.getLength() == 1 + && arg25[0].equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("test")) + && (arguments[26] >>= arg26) && arg26.getLength() == 1 + && arg26[0] == ::cppu::UnoType< css::uno::Any >::get() + && (arguments[27] >>= arg27) && arg27.getLength() == 1 + && (arg27[0] >>= arg27b) && arg27b + && (arguments[28] >>= arg28) && arg28.getLength() == 1 + && arg28[0].getLength() == 1 && arg28[0][0] + && (arguments[29] >>= arg29) && arg29.getLength() == 1 + && arg29[0].getLength() == 1 && (arg29[0][0] >>= arg29b) && arg29b + && (arguments[30] >>= arg30) && arg30.getLength() == 1 + && arg30[0] == ::test::testtools::bridgetest::TestEnum_TWO + && (arguments[31] >>= arg31) && arg31.getLength() == 1 + && arg31[0].member == 10 + && (arguments[32] >>= arg32) && arg32.getLength() == 1 + && arg32[0].member + && (arguments[33] >>= arg33) && arg33.getLength() == 1 + && (arg33[0].member >>= arg33b) && arg33b + && (arguments[34] >>= arg34) && arg34.getLength() == 1 + && !arg34[0].is() + && (arguments[35] >>= arg35) + && arg35 == ::test::testtools::bridgetest::TestEnum_TWO + && (arguments[36] >>= arg36) && arg36.member == 10 + && (arguments[37] >>= arg37) && arg37.member + && (arguments[38] >>= arg38) && (arg38.member >>= arg38b) && arg38b + && (arguments[39] >>= arg39) && !arg39.is())) + { + throw ::test::testtools::bridgetest::BadConstructorArguments(); + } +} + + +class Impl2: public ::cppu::WeakImplHelper2< + css::lang::XInitialization, ttb::XMultiBase1 > +{ +public: + Impl2(): m_attr1(0.0) {} + +private: + Impl2(Impl &); // not defined + void operator =(Impl &); // not defined + + virtual ~Impl2() {} + + virtual void SAL_CALL initialize( + css::uno::Sequence< css::uno::Any > const & arguments) + throw (css::uno::Exception); + + //XMultiBase1 + virtual double SAL_CALL getatt1() + throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setatt1( double _att1 ) + throw (::com::sun::star::uno::RuntimeException); + virtual ::sal_Int32 SAL_CALL fn11( ::sal_Int32 arg ) + throw (::com::sun::star::uno::RuntimeException); + virtual ::rtl::OUString SAL_CALL fn12( const ::rtl::OUString& arg ) + throw (::com::sun::star::uno::RuntimeException); + + + double m_attr1; +}; + +void Impl2::initialize(css::uno::Sequence< css::uno::Any > const & arguments) + throw (css::uno::Exception) +{ + ttb::TestPolyStruct< css::uno::Type > arg0; + ttb::TestPolyStruct< css::uno::Any > arg1; + css::uno::Any arg1b(sal_True); + ttb::TestPolyStruct< ::sal_Bool > arg2; + ttb::TestPolyStruct< ::sal_Int8 > arg3; + ttb::TestPolyStruct< ::sal_Int16 > arg4; + ttb::TestPolyStruct< ::sal_Int32 > arg5; + ttb::TestPolyStruct< ::sal_Int64 > arg6; + ttb::TestPolyStruct< ::sal_Unicode > arg7; + ttb::TestPolyStruct< ::rtl::OUString > arg8; + ttb::TestPolyStruct< float > arg9; + ttb::TestPolyStruct< double > arg10; + ttb::TestPolyStruct<css::uno::Reference<css::uno::XInterface> > arg11; + ttb::TestPolyStruct<css::uno::Reference< css::lang::XComponent> > arg12; + ttb::TestPolyStruct<ttb::TestEnum> arg13; + ttb::TestPolyStruct< + ttb::TestPolyStruct2<sal_Unicode, css::uno::Any> > arg14; + ttb::TestPolyStruct< ttb::TestPolyStruct2 < + ttb::TestPolyStruct2< sal_Unicode, css::uno::Any >, + ::rtl::OUString > > arg15; + ttb::TestPolyStruct2< ::rtl::OUString,ttb::TestPolyStruct2 < + ::sal_Unicode, ttb::TestPolyStruct < css::uno::Any > > > arg16; + ttb::TestPolyStruct2< ttb::TestPolyStruct2<sal_Unicode, css::uno::Any >, + ttb::TestPolyStruct<sal_Unicode> > arg17; + ttb::TestPolyStruct<css::uno::Sequence< css::uno::Type > > arg18; + ttb::TestPolyStruct<css::uno::Sequence<css::uno::Any> > arg19; + ttb::TestPolyStruct<css::uno::Sequence< ::sal_Bool > > arg20; + ttb::TestPolyStruct<css::uno::Sequence< ::sal_Int8 > > arg21; + ttb::TestPolyStruct<css::uno::Sequence< ::sal_Int16 > > arg22; + ttb::TestPolyStruct<css::uno::Sequence< ::sal_Int32 > > arg23; + ttb::TestPolyStruct<css::uno::Sequence< ::sal_Int64 > > arg24; +// ttb::TestPolyStruct<css::uno::Sequence<::sal_Unicode> > arg25; + ttb::TestPolyStruct<css::uno::Sequence< ::rtl::OUString > > arg26; + ttb::TestPolyStruct<css::uno::Sequence<float> > arg27; + ttb::TestPolyStruct<css::uno::Sequence<double> > arg28; + ttb::TestPolyStruct<css::uno::Sequence<css::uno::Reference<css::uno::XInterface> > > arg29; + ttb::TestPolyStruct<css::uno::Sequence<css::uno::Reference<css::lang::XComponent> > > arg30; + ttb::TestPolyStruct<css::uno::Sequence<ttb::TestEnum> > arg31; + ttb::TestPolyStruct<css::uno::Sequence<ttb::TestPolyStruct2< + ::sal_Unicode, css::uno::Sequence<css::uno::Any> > > > arg32; + bool arg32a = false; + ttb::TestPolyStruct<css::uno::Sequence<ttb::TestPolyStruct2< + ttb::TestPolyStruct< ::sal_Unicode>, css::uno::Sequence<css::uno::Any> > > > arg33; + ttb::TestPolyStruct<css::uno::Sequence<css::uno::Sequence< ::sal_Int32> > > arg34; + css::uno::Sequence<ttb::TestPolyStruct< ::sal_Int32> > arg35; + css::uno::Sequence<ttb::TestPolyStruct<ttb::TestPolyStruct2< ::sal_Unicode, css::uno::Any> > > arg36; + css::uno::Sequence<ttb::TestPolyStruct<ttb::TestPolyStruct2< + ttb::TestPolyStruct2< ::sal_Unicode,css::uno::Any >, ::rtl::OUString> > > arg37; + css::uno::Sequence<ttb::TestPolyStruct2< ::rtl::OUString, ttb::TestPolyStruct2< + ::sal_Unicode, ttb::TestPolyStruct<css::uno::Any> > > > arg38; + css::uno::Sequence<ttb::TestPolyStruct2<ttb::TestPolyStruct2< + ::sal_Unicode, css::uno::Any>, ttb::TestPolyStruct< ::sal_Unicode> > > arg39; + css::uno::Sequence<css::uno::Sequence<ttb::TestPolyStruct< ::sal_Unicode> > > arg40; + css::uno::Sequence<css::uno::Sequence<ttb::TestPolyStruct<ttb::TestPolyStruct2< ::sal_Unicode, css::uno::Any> > > >arg41; + css::uno::Sequence<css::uno::Sequence<ttb::TestPolyStruct< + ttb::TestPolyStruct2<ttb::TestPolyStruct2<sal_Unicode, css::uno::Any>, ::rtl::OUString> > > > arg42; + css::uno::Sequence<css::uno::Sequence<ttb::TestPolyStruct2< + ::rtl::OUString, ttb::TestPolyStruct2< ::sal_Unicode, ttb::TestPolyStruct<css::uno::Any> > > > > arg43; + css::uno::Sequence<css::uno::Sequence<ttb::TestPolyStruct2< + ttb::TestPolyStruct2< ::sal_Unicode, css::uno::Any>, ttb::TestPolyStruct< + ::sal_Unicode> > > > arg44; + + if (!(arguments.getLength() == 45 + && (arguments[0] >>= arg0) && arg0.member == cppu::UnoType<sal_Int32>::get() + && (arguments[1] >>= arg1) && arg1.member == arg1b + && (arguments[2] >>= arg2) && arg2.member == sal_True + && (arguments[3] >>= arg3) && arg3.member == SAL_MIN_INT8 + && (arguments[4] >>= arg4) && arg4.member == SAL_MIN_INT16 + && (arguments[5] >>= arg5) && arg5.member == SAL_MIN_INT32 + && (arguments[6] >>= arg6) && arg6.member == SAL_MIN_INT64 + && (arguments[7] >>= arg7) && arg7.member == 'X' + && (arguments[8] >>= arg8) && arg8.member.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("test")) + && (arguments[9] >>= arg9) && arg9.member == 0.123f + && (arguments[10] >>= arg10) && arg10.member == 0.456 + && (arguments[11] >>= arg11) + && (arguments[12] >>= arg12) + && (arguments[13] >>= arg13) && arg13.member == ttb::TestEnum_TWO + && (arguments[14] >>= arg14) && arg14.member.member1 == 'X' && arg14.member.member2 == arg1b + && (arguments[15] >>= arg15) && arg15.member.member1.member1 == 'X' + && arg15.member.member1.member2 == arg1b + && arg15.member.member2.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("test")) + && (arguments[16] >>= arg16) && arg16.member1.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("test")) + && arg16.member2.member1 == 'X' + && arg16.member2.member2.member == arg1b + && (arguments[17] >>= arg17) && arg17.member1.member1 == 'X' + && arg17.member1.member2 == arg1b + && arg17.member2.member == 'X' + && (arguments[18] >>= arg18) && arg18.member.getLength() == 1 + && arg18.member[0] == ::cppu::UnoType<sal_Int32>::get() + && (arguments[19] >>= arg19) && arg19.member.getLength() == 1 + && arg19.member[0] == arg1b + && (arguments[20] >>= arg20) && arg20.member.getLength() == 1 + && arg20.member[0] == sal_True + && (arguments[21] >>= arg21) && arg21.member.getLength() == 1 + && arg21.member[0] == SAL_MIN_INT8 + && (arguments[22] >>= arg22) && arg22.member.getLength() == 1 + && arg22.member[0] == SAL_MIN_INT16 + && (arguments[23] >>= arg23) && arg23.member.getLength() == 1 + && arg23.member[0] == SAL_MIN_INT32 + && (arguments[24] >>= arg24) && arg24.member.getLength() == 1 + && arg24.member[0] == SAL_MIN_INT64 + && (arguments[25].getValueType() + == ::cppu::UnoType< ttb::TestPolyStruct< ::cppu::UnoSequenceType< + ::cppu::UnoCharType> > >::get()) + && (static_cast< ttb::TestPolyStruct<css::uno::Sequence< + ::sal_Unicode> > const *>(arguments[25].getValue())->member[0]) == 'X' + && (arguments[26] >>= arg26) && arg26.member.getLength() == 1 + && arg26.member[0].equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("test")) + && (arguments[27] >>= arg27) && arg27.member.getLength() == 1 + && arg27.member[0] == 0.123f + && (arguments[28] >>= arg28) && arg28.member.getLength() == 1 + && arg28.member[0] == 0.456 + && (arguments[29] >>= arg29) && arg29.member.getLength() == 1 + && arg29.member[0] != NULL + && (arguments[30] >>= arg30) && arg30.member.getLength() == 1 + && arg30.member[0] != NULL + && (arguments[31] >>= arg31) && arg31.member.getLength() == 1 + && arg31.member[0] == ttb::TestEnum_TWO + && (arguments[32] >>= arg32) && arg32.member.getLength() == 1 + && arg32.member[0].member1 == 'X' + && arg32.member[0].member2.getLength() == 1 + && (arg32.member[0].member2[0] >>= arg32a) && arg32a == true + && (arguments[33] >>= arg33) && arg33.member.getLength() == 1 + && arg33.member[0].member1.member == 'X' + && arg33.member[0].member2.getLength() == 1 + && arg33.member[0].member2[0] == arg1b + && (arguments[34] >>= arg34) && arg34.member.getLength() == 1 + && arg34.member[0].getLength() == 1 && arg34.member[0][0] == SAL_MIN_INT32 + && (arguments[35] >>= arg35) && arg35.getLength() == 1 + && arg35[0].member == SAL_MIN_INT32 + && (arguments[36] >>= arg36) && arg36.getLength() == 1 + && arg36[0].member.member1 == 'X' + && arg36[0].member.member2 == arg1b + && (arguments[37] >>= arg37) && arg37.getLength() == 1 + && arg37[0].member.member1.member1 == 'X' + && arg37[0].member.member1.member2 == arg1b + && arg37[0].member.member2.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("test")) + && (arguments[38] >>= arg38) && arg38.getLength() == 1 + && arg38[0].member1.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("test")) + && arg38[0].member2.member1 == 'X' + && arg38[0].member2.member2.member == arg1b + && (arguments[39] >>= arg39) && arg39.getLength() == 1 + && arg39[0].member1.member1 == 'X' + && arg39[0].member1.member2 == arg1b + && arg39[0].member2.member == 'X' + && (arguments[40] >>= arg40) && arg40.getLength() == 1 + && arg40[0].getLength() == 1 + && arg40[0][0].member == 'X' + && (arguments[41] >>= arg41) && arg41.getLength() == 1 + && arg41[0].getLength() == 1 + && arg41[0][0].member.member1 == 'X' + && arg41[0][0].member.member2 == arg1b + && (arguments[42] >>= arg42) && arg42.getLength() == 1 + && arg42[0].getLength() == 1 + && arg42[0][0].member.member1.member1 == 'X' + && arg42[0][0].member.member1.member2 == arg1b + && arg42[0][0].member.member2.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("test")) + && (arguments[43] >>= arg43) && arg43.getLength() == 1 + && arg43[0].getLength() == 1 + && arg43[0][0].member1.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("test")) + && arg43[0][0].member2.member1 == 'X' + && arg43[0][0].member2.member2.member == arg1b + && (arguments[44] >>= arg44) && arg44.getLength() == 1 + && arg44[0].getLength() == 1 + && arg44[0][0].member1.member1 == 'X' + && arg44[0][0].member1.member2 == arg1b + && arg44[0][0].member2.member == 'X' + )) + { + throw ::test::testtools::bridgetest::BadConstructorArguments(); + } + + //check if interfaces work + arg11.member->acquire(); + arg11.member->release(); + arg12.member->acquire(); + arg12.member->release(); + arg29.member[0]->acquire(); + arg29.member[0]->release(); + +} + +//XMultiBase1 +double Impl2::getatt1() + throw (::com::sun::star::uno::RuntimeException) +{ + return m_attr1; +} + +void Impl2::setatt1( double _att1 )throw (::com::sun::star::uno::RuntimeException) +{ + m_attr1 = _att1; +} + +::sal_Int32 Impl2::fn11( ::sal_Int32 arg ) + throw (::com::sun::star::uno::RuntimeException) +{ + return 11 * arg; +} + +::rtl::OUString Impl2::fn12( const ::rtl::OUString& arg ) + throw (::com::sun::star::uno::RuntimeException) +{ + return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("12")) + arg; +} + +css::uno::Reference< css::uno::XInterface > SAL_CALL create( + css::uno::Reference< css::uno::XComponentContext > const &) + SAL_THROW((css::uno::Exception)) +{ + return static_cast< ::cppu::OWeakObject * >(new Impl); +} + +::rtl::OUString SAL_CALL getImplementationName() { + return ::rtl::OUString( + RTL_CONSTASCII_USTRINGPARAM( + "comp.test.testtools.bridgetest.Constructors")); +} + +css::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames() { + css::uno::Sequence< ::rtl::OUString > s(1); + s[0] = ::rtl::OUString( + RTL_CONSTASCII_USTRINGPARAM("test.testtools.bridgetest.Constructors")); + return s; +} + +css::uno::Reference< css::uno::XInterface > SAL_CALL create2( + css::uno::Reference< css::uno::XComponentContext > const &) + SAL_THROW((css::uno::Exception)) +{ + return static_cast< ::cppu::OWeakObject * >(new Impl2); +} + +::rtl::OUString SAL_CALL getImplementationName2() { + return ::rtl::OUString( + RTL_CONSTASCII_USTRINGPARAM( + "comp.test.testtools.bridgetest.Constructors2")); +} + +css::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames2() { + css::uno::Sequence< ::rtl::OUString > s(1); + s[0] = ::rtl::OUString( + RTL_CONSTASCII_USTRINGPARAM("test.testtools.bridgetest.Constructors2")); + return s; +} + +::cppu::ImplementationEntry entries[] = { + { &create, &getImplementationName, &getSupportedServiceNames, + &::cppu::createSingleComponentFactory, 0, 0 }, + { &create2, &getImplementationName2, &getSupportedServiceNames2, + &::cppu::createSingleComponentFactory, 0, 0 }, + { 0, 0, 0, 0, 0, 0 } }; +} + +extern "C" void * SAL_CALL component_getFactory( + char const * implName, void * serviceManager, void * registryKey) +{ + return ::cppu::component_getFactoryHelper( + implName, serviceManager, registryKey, entries); +} + +extern "C" void SAL_CALL component_getImplementationEnvironment( + char const ** envTypeName, uno_Environment **) +{ + *envTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME; +} + +extern "C" ::sal_Bool SAL_CALL component_writeInfo( + void * serviceManager, void * registryKey) +{ + return ::cppu::component_writeInfoHelper( + serviceManager, registryKey, entries); +} diff --git a/testtools/source/bridgetest/cppobj.cxx b/testtools/source/bridgetest/cppobj.cxx new file mode 100644 index 000000000000..68c725240971 --- /dev/null +++ b/testtools/source/bridgetest/cppobj.cxx @@ -0,0 +1,1229 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_testtools.hxx" +#include <stdio.h> + +#include "cppu/unotype.hxx" +#include <osl/diagnose.h> +#include "osl/diagnose.hxx" +#include <osl/thread.h> +#include <osl/mutex.hxx> +#include <osl/time.h> + +#include <cppuhelper/implbase3.hxx> +#include <cppuhelper/factory.hxx> +#include "cppuhelper/exc_hlp.hxx" +#include "cppuhelper/compbase_ex.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/uno/Any.hxx" +#include "com/sun/star/uno/RuntimeException.hpp" +#include "com/sun/star/uno/Sequence.hxx" + +#include "test/testtools/bridgetest/Constructors.hpp" +#include "test/testtools/bridgetest/Constructors2.hpp" +#include "test/testtools/bridgetest/TestPolyStruct.hpp" +#include "test/testtools/bridgetest/TestPolyStruct2.hpp" +#include "test/testtools/bridgetest/XBridgeTest2.hpp" +#include "test/testtools/bridgetest/XMulti.hpp" + +#include "currentcontextchecker.hxx" +#include "multi.hxx" + +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 test::testtools::bridgetest; + +#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 : + protected osl::DebugBase<Test_Impl>, + public WeakImplHelper3< XBridgeTest2, XServiceInfo , XRecursiveCall > +{ + TestData _aData, _aStructData; + sal_Int32 m_nLastCallId; + sal_Bool m_bFirstCall; + sal_Bool m_bSequenceOfCallTestPassed; + Mutex m_mutex; + + Sequence<sal_Bool> _arBool; + Sequence<sal_Unicode> _arChar; + Sequence<sal_Int8> _arByte; + Sequence<sal_Int16> _arShort; + Sequence<sal_uInt16> _arUShort; + Sequence<sal_Int32> _arLong; + Sequence<sal_uInt32> _arULong; + Sequence<sal_Int64> _arHyper; + Sequence<sal_uInt64> _arUHyper; + Sequence<OUString> _arString; + Sequence<float> _arFloat; + Sequence<double> _arDouble; + Sequence<TestEnum> _arEnum; + Sequence<Reference<XInterface> > _arObject; + Sequence<Sequence<sal_Int32> > _arLong2; + Sequence<Sequence<Sequence<sal_Int32> > > _arLong3; + Sequence<Any> _arAny; + Sequence<TestElement> _arStruct; + +public: + Test_Impl() : m_nLastCallId( 0 ), + m_bFirstCall( sal_True ), + m_bSequenceOfCallTestPassed( sal_True ) + {} + virtual ~Test_Impl() + { + OSL_TRACE( "> scalar Test_Impl dtor <\n" ); + } + + void SAL_CALL acquire() throw () + { + OWeakObject::acquire(); + } + void SAL_CALL release() throw () + { + OWeakObject::release(); + } + + // 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 SmallStruct SAL_CALL echoSmallStruct(const SmallStruct& rStruct) throw(com::sun::star::uno::RuntimeException) + { return rStruct; } + virtual MediumStruct SAL_CALL echoMediumStruct(const MediumStruct& rStruct) throw(com::sun::star::uno::RuntimeException) + { return rStruct; } + virtual BigStruct SAL_CALL echoBigStruct(const BigStruct& rStruct) throw(com::sun::star::uno::RuntimeException) + { return rStruct; } + virtual AllFloats SAL_CALL echoAllFloats(const AllFloats& rStruct) throw(com::sun::star::uno::RuntimeException) + { return rStruct; } + virtual sal_Int32 SAL_CALL testPPCAlignment( sal_Int64, sal_Int64, sal_Int32, sal_Int64, sal_Int32 i2 ) throw(com::sun::star::uno::RuntimeException) + { return i2; } + + 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 sal_Int32 SAL_CALL getRaiseAttr1() throw (RuntimeException) + { throw RuntimeException(); } + + virtual void SAL_CALL setRaiseAttr1(sal_Int32) + throw (IllegalArgumentException, RuntimeException) + { throw IllegalArgumentException(); } + + virtual sal_Int32 SAL_CALL getRaiseAttr2() + throw (IllegalArgumentException, RuntimeException) + { throw IllegalArgumentException(); } + + virtual TestPolyStruct< sal_Bool > SAL_CALL transportPolyBoolean( + TestPolyStruct< sal_Bool > const & arg) throw (RuntimeException) + { return arg; } + + virtual void SAL_CALL transportPolyHyper(TestPolyStruct< sal_Int64 > &) + throw (RuntimeException) {} + + virtual void SAL_CALL transportPolySequence( + TestPolyStruct< Sequence< Any > > const & arg1, + TestPolyStruct< Sequence< Any > > & arg2) throw (RuntimeException) + { arg2 = arg1; } + + virtual TestPolyStruct< sal_Int32 > SAL_CALL getNullPolyLong() + throw (RuntimeException) + { return TestPolyStruct< sal_Int32 >(0); /* work around MS compiler bug */ } + + virtual TestPolyStruct< rtl::OUString > SAL_CALL getNullPolyString() + throw (RuntimeException) + { return TestPolyStruct< rtl::OUString >(); } + + virtual TestPolyStruct< Type > SAL_CALL getNullPolyType() + throw (RuntimeException) + { return TestPolyStruct< Type >(); } + + virtual TestPolyStruct< Any > SAL_CALL getNullPolyAny() + throw (RuntimeException) + { return TestPolyStruct< Any >(); } + + virtual TestPolyStruct< Sequence< sal_Bool > > SAL_CALL + getNullPolySequence() throw (RuntimeException) + { return TestPolyStruct< Sequence< sal_Bool > >(); } + + virtual TestPolyStruct< TestEnum > SAL_CALL getNullPolyEnum() + throw (RuntimeException) + { return TestPolyStruct< TestEnum >( + test::testtools::bridgetest::TestEnum_TEST); + /* work around MS compiler bug */ } + + virtual TestPolyStruct< TestBadEnum > SAL_CALL getNullPolyBadEnum() + throw (RuntimeException) + { return TestPolyStruct< TestBadEnum >( + test::testtools::bridgetest::TestBadEnum_M); + /* explicitly instantiate with default enumerator */ } + + virtual TestPolyStruct< TestStruct > SAL_CALL getNullPolyStruct() + throw (RuntimeException) + { return TestPolyStruct< TestStruct >(); } + + virtual TestPolyStruct< Reference< XBridgeTestBase > > SAL_CALL + getNullPolyInterface() throw (RuntimeException) + { return TestPolyStruct< Reference< XBridgeTestBase > >(); } + + 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< XRecursiveCall >& xCall, sal_Int32 nToCall ) + throw(::com::sun::star::uno::RuntimeException); + + virtual Reference< XMulti > SAL_CALL getMulti() throw (RuntimeException); + + virtual rtl::OUString SAL_CALL testMulti(Reference< XMulti > const & multi) + throw (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); + + // XBridgeTest2 + virtual Sequence< sal_Bool > SAL_CALL setSequenceBool( + const Sequence< sal_Bool >& aSeq ) throw (RuntimeException); + virtual Sequence< sal_Unicode > SAL_CALL setSequenceChar( + const Sequence< sal_Unicode >& aSeq ) throw (RuntimeException); + virtual Sequence< sal_Int8 > SAL_CALL setSequenceByte( + const Sequence< sal_Int8 >& aSeq ) throw (RuntimeException); + virtual Sequence< sal_Int16 > SAL_CALL setSequenceShort( + const Sequence< sal_Int16 >& aSeq ) throw (RuntimeException); + virtual Sequence< sal_uInt16 > SAL_CALL setSequenceUShort( + const Sequence< sal_uInt16 >& aSeq ) throw (RuntimeException); + virtual Sequence< sal_Int32 > SAL_CALL setSequenceLong( + const Sequence< sal_Int32 >& aSeq ) throw (RuntimeException); + virtual Sequence< sal_uInt32 > SAL_CALL setSequenceULong( + const Sequence< sal_uInt32 >& aSeq ) throw (RuntimeException); + virtual Sequence< sal_Int64 > SAL_CALL setSequenceHyper( + const Sequence< sal_Int64 >& aSeq ) throw (RuntimeException); + virtual Sequence< sal_uInt64 > SAL_CALL setSequenceUHyper( + const Sequence< sal_uInt64 >& aSeq ) throw (RuntimeException); + virtual Sequence< float > SAL_CALL setSequenceFloat( + const Sequence< float >& aSeq ) throw (RuntimeException); + virtual Sequence< double > SAL_CALL setSequenceDouble( + const Sequence< double >& aSeq ) throw (RuntimeException); + virtual Sequence< TestEnum > SAL_CALL setSequenceEnum( + const Sequence< TestEnum >& aSeq ) throw (RuntimeException) ; + virtual Sequence< OUString > SAL_CALL setSequenceString( + const Sequence< OUString >& aString ) throw (RuntimeException); + virtual Sequence< Reference< XInterface > > SAL_CALL setSequenceXInterface( + const Sequence< Reference< XInterface > >& aSeq ) + throw (RuntimeException); + virtual Sequence<Any > SAL_CALL setSequenceAny( + const Sequence<Any >& aSeq ) throw (RuntimeException); + virtual Sequence<TestElement > SAL_CALL setSequenceStruct( + const Sequence< TestElement >& aSeq ) throw (RuntimeException); + virtual Sequence< Sequence< sal_Int32 > > SAL_CALL setDim2( + const Sequence<Sequence< sal_Int32 > >& aSeq ) throw (RuntimeException); + virtual Sequence< Sequence< Sequence< sal_Int32 > > > SAL_CALL setDim3( + const Sequence< Sequence< Sequence< sal_Int32 > > >& aSeq ) + throw (RuntimeException); + virtual void SAL_CALL setSequencesInOut(Sequence< sal_Bool >& aSeqBoolean, + Sequence< sal_Unicode >& aSeqChar, + Sequence< sal_Int8 >& aSeqByte, + Sequence< sal_Int16 >& aSeqShort, + Sequence< sal_uInt16 >& aSeqUShort, + Sequence< sal_Int32 >& aSeqLong, + Sequence< sal_uInt32 >& aSeqULong, + Sequence< sal_Int64 >& aSeqHyper, + Sequence< sal_uInt64 >& aSeqUHyper, + Sequence< float >& aSeqFloat, + Sequence< double >& aSeqDouble, + Sequence< TestEnum >& aSeqTestEnum, + Sequence< OUString >& aSeqString, + Sequence<Reference<XInterface > >& aSeqXInterface, + Sequence< Any >& aSeqAny, + Sequence< Sequence< sal_Int32 > >& aSeqDim2, + Sequence< Sequence< Sequence< sal_Int32 > > >& aSeqDim3 ) + throw (RuntimeException); + virtual void SAL_CALL setSequencesOut( Sequence< sal_Bool >& aSeqBoolean, + Sequence< sal_Unicode >& aSeqChar, + Sequence< sal_Int8 >& aSeqByte, + Sequence< sal_Int16 >& aSeqShort, + Sequence< sal_uInt16 >& aSeqUShort, + Sequence< sal_Int32 >& aSeqLong, + Sequence< sal_uInt32 >& aSeqULong, + Sequence< sal_Int64 >& aSeqHyper, + Sequence< sal_uInt64 >& aSeqUHyper, + Sequence< float >& aSeqFloat, + Sequence< double >& aSeqDouble, + Sequence< TestEnum >& aSeqEnum, + Sequence< OUString >& aSeqString, + Sequence< Reference< XInterface > >& aSeqXInterface, + Sequence< Any >& aSeqAny, + Sequence< Sequence< sal_Int32 > >& aSeqDim2, + Sequence< Sequence< Sequence< sal_Int32 > > >& aSeqDim3 ) + throw (RuntimeException); + virtual void SAL_CALL testConstructorsService( + Reference< XComponentContext > const & context) + throw (RuntimeException); + virtual Reference< XCurrentContextChecker > SAL_CALL + getCurrentContextChecker() + throw (RuntimeException); + +public: + virtual void SAL_CALL callRecursivly( const ::com::sun::star::uno::Reference< XRecursiveCall >& xCall, sal_Int32 nToCall ) throw(::com::sun::star::uno::RuntimeException); +}; + +//Dummy class for XComponent implementation +class Dummy : protected osl::DebugBase<Dummy>, + public WeakComponentImplHelperBase +{ +public: + Dummy(): WeakComponentImplHelperBase(*Mutex::getGlobalMutex()){} + +}; +//__________________________________________________________________________________________________ +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< 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< XRecursiveCall >& xCall, + sal_Int32 nToCall ) + throw(::com::sun::star::uno::RuntimeException) +{ + MutexGuard guard( m_mutex ); + if( nToCall ) + { + nToCall --; + xCall->callRecursivly( this , nToCall ); + } +} + +Reference< XMulti > Test_Impl::getMulti() throw (RuntimeException) { + return new testtools::bridgetest::Multi; +} + +rtl::OUString Test_Impl::testMulti(Reference< XMulti > const & multi) + throw (RuntimeException) +{ + return testtools::bridgetest::testMulti(multi); +} + +//__________________________________________________________________________________________________ +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; + + TestElement elem = rSequence[ 0 ]; + rSequence[ 0 ] = rSequence[ 1 ]; + rSequence[ 1 ] = elem; + + 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; +} + +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; +} + +void dothrow2( RuntimeException e ) +{ + throw e; +} +void dothrow( RuntimeException const & e ) +{ +#if defined _MSC_VER + // currently only for MSVC: + // just to test whether all bridges fall back to a RuntimeException + // in case of a thrown non-UNO exception: + try + { + throw ::std::bad_alloc(); + } + catch (...) + { + try + { + Any a( getCaughtException() ); + RuntimeException exc; + OSL_VERIFY( a >>= exc ); + OSL_TRACE( + OUStringToOString( + exc.Message, RTL_TEXTENCODING_UTF8 ).getStr() ); + } + catch (...) // never throws anything + { + fprintf( stderr, "\ngetCaughtException() failed!\n" ); + exit( 1 ); + } + } +#endif + dothrow2( e ); +} +//______________________________________________________________________________ +sal_Int32 Test_Impl::getRuntimeException() + throw (RuntimeException) +{ + try + { + dothrow( RuntimeException( _aData.String, _aData.Interface ) ); + } + catch (Exception &) + { + Any a( getCaughtException() ); + throwException( a ); + } + return 0; // for dummy +} +//__________________________________________________________________________________________________ +void Test_Impl::setRuntimeException( sal_Int32 ) throw(::com::sun::star::uno::RuntimeException) +{ + RuntimeException aExc; + aExc.Message = _aData.String; + aExc.Context = _aData.Interface; + throwException( makeAny( aExc ) ); +} + +// XBridgeTest2 ------------------------------------------------------------- +Sequence< sal_Bool > SAL_CALL Test_Impl::setSequenceBool( + const Sequence< sal_Bool >& aSeq ) throw (RuntimeException) +{ + _arBool = aSeq; + return aSeq; +} + +Sequence< sal_Unicode > SAL_CALL Test_Impl::setSequenceChar( + const Sequence< sal_Unicode >& aSeq ) throw (RuntimeException) +{ + _arChar = aSeq; + return aSeq; +} + +Sequence< sal_Int8 > SAL_CALL Test_Impl::setSequenceByte( + const Sequence< sal_Int8 >& aSeq ) throw (RuntimeException) +{ + _arByte = aSeq; + return aSeq; +} + +Sequence< sal_Int16 > SAL_CALL Test_Impl::setSequenceShort( + const Sequence< sal_Int16 >& aSeq ) throw (RuntimeException) +{ + _arShort = aSeq; + return aSeq; +} + +Sequence< sal_uInt16 > SAL_CALL Test_Impl::setSequenceUShort( + const Sequence< sal_uInt16 >& aSeq ) throw (RuntimeException) +{ + _arUShort = aSeq; + return aSeq; +} + +Sequence< sal_Int32 > SAL_CALL Test_Impl::setSequenceLong( + const Sequence< sal_Int32 >& aSeq ) throw (RuntimeException) +{ + _arLong = aSeq; + return aSeq; +} + +Sequence< sal_uInt32 > SAL_CALL Test_Impl::setSequenceULong( + const Sequence< sal_uInt32 >& aSeq ) throw (RuntimeException) +{ + _arULong = aSeq; + return aSeq; +} + +Sequence< sal_Int64 > SAL_CALL Test_Impl::setSequenceHyper( + const Sequence< sal_Int64 >& aSeq ) throw (RuntimeException) +{ + _arHyper = aSeq; + return aSeq; +} + +Sequence< sal_uInt64 > SAL_CALL Test_Impl::setSequenceUHyper( + const Sequence< sal_uInt64 >& aSeq ) throw (RuntimeException) +{ + _arUHyper = aSeq; + return aSeq; +} + +Sequence< float > SAL_CALL Test_Impl::setSequenceFloat( + const Sequence< float >& aSeq ) throw (RuntimeException) +{ + _arFloat = aSeq; + return aSeq; +} + +Sequence< double > SAL_CALL Test_Impl::setSequenceDouble( + const Sequence< double >& aSeq ) throw (RuntimeException) +{ + _arDouble = aSeq; + return aSeq; +} + +Sequence< TestEnum > SAL_CALL Test_Impl::setSequenceEnum( + const Sequence< TestEnum >& aSeq ) throw (RuntimeException) +{ + _arEnum = aSeq; + return aSeq; +} + +Sequence< OUString > SAL_CALL Test_Impl::setSequenceString( + const Sequence< OUString >& aSeq ) throw (RuntimeException) +{ + _arString = aSeq; + return aSeq; +} + +Sequence< Reference< XInterface > > SAL_CALL Test_Impl::setSequenceXInterface( + const Sequence< Reference< XInterface > >& aSeq ) + throw (RuntimeException) +{ + _arObject = aSeq; + return aSeq; +} + +Sequence<Any > SAL_CALL Test_Impl::setSequenceAny( + const Sequence<Any >& aSeq ) throw (RuntimeException) +{ + _arAny = aSeq; + return aSeq; +} + +Sequence<TestElement > SAL_CALL Test_Impl::setSequenceStruct( + const Sequence< TestElement >& aSeq ) throw (RuntimeException) +{ + _arStruct = aSeq; + return aSeq; +} + +Sequence< Sequence< sal_Int32 > > SAL_CALL Test_Impl::setDim2( + const Sequence<Sequence< sal_Int32 > >& aSeq ) throw (RuntimeException) +{ + _arLong2 = aSeq; + return aSeq; +} + +Sequence< Sequence< Sequence< sal_Int32 > > > SAL_CALL Test_Impl::setDim3( + const Sequence< Sequence< Sequence< sal_Int32 > > >& aSeq ) + throw (RuntimeException) +{ + _arLong3 = aSeq; + return aSeq; +} + +void SAL_CALL Test_Impl::setSequencesInOut(Sequence< sal_Bool >& aSeqBoolean, + Sequence< sal_Unicode >& aSeqChar, + Sequence< sal_Int8 >& aSeqByte, + Sequence< sal_Int16 >& aSeqShort, + Sequence< sal_uInt16 >& aSeqUShort, + Sequence< sal_Int32 >& aSeqLong, + Sequence< sal_uInt32 >& aSeqULong, + Sequence< sal_Int64 >& aSeqHyper, + Sequence< sal_uInt64 >& aSeqUHyper, + Sequence< float >& aSeqFloat, + Sequence< double >& aSeqDouble, + Sequence< TestEnum >& aSeqTestEnum, + Sequence< OUString >& aSeqString, + Sequence<Reference<XInterface > >& aSeqXInterface, + Sequence< Any >& aSeqAny, + Sequence< Sequence< sal_Int32 > >& aSeqDim2, + Sequence< Sequence< Sequence< sal_Int32 > > >& aSeqDim3 ) + throw (RuntimeException) +{ + _arBool = aSeqBoolean; + _arChar = aSeqChar; + _arByte = aSeqByte; + _arShort = aSeqShort; + _arUShort = aSeqUShort; + _arLong = aSeqLong; + _arULong = aSeqULong; + _arHyper = aSeqHyper; + _arUHyper = aSeqUHyper; + _arFloat = aSeqFloat; + _arDouble = aSeqDouble; + _arEnum = aSeqTestEnum; + _arString = aSeqString; + _arObject = aSeqXInterface; + _arAny = aSeqAny; + _arLong2 = aSeqDim2; + _arLong3 = aSeqDim3; +} + +void SAL_CALL Test_Impl::setSequencesOut( Sequence< sal_Bool >& aSeqBoolean, + Sequence< sal_Unicode >& aSeqChar, + Sequence< sal_Int8 >& aSeqByte, + Sequence< sal_Int16 >& aSeqShort, + Sequence< sal_uInt16 >& aSeqUShort, + Sequence< sal_Int32 >& aSeqLong, + Sequence< sal_uInt32 >& aSeqULong, + Sequence< sal_Int64 >& aSeqHyper, + Sequence< sal_uInt64 >& aSeqUHyper, + Sequence< float >& aSeqFloat, + Sequence< double >& aSeqDouble, + Sequence< TestEnum >& aSeqEnum, + Sequence< OUString >& aSeqString, + Sequence< Reference< XInterface > >& aSeqXInterface, + Sequence< Any >& aSeqAny, + Sequence< Sequence< sal_Int32 > >& aSeqDim2, + Sequence< Sequence< Sequence< sal_Int32 > > >& aSeqDim3 ) + throw (RuntimeException) +{ + aSeqBoolean = _arBool; + aSeqChar = _arChar; + aSeqByte = _arByte; + aSeqShort = _arShort; + aSeqUShort = _arUShort; + aSeqLong = _arLong; + aSeqULong = _arULong; + aSeqHyper = _arHyper; + aSeqUHyper = _arUHyper; + aSeqFloat = _arFloat; + aSeqDouble = _arDouble; + aSeqEnum = _arEnum; + aSeqString = _arString; + aSeqXInterface = _arObject; + aSeqAny = _arAny; + aSeqDim2 = _arLong2; + aSeqDim3 = _arLong3; +} + +void Test_Impl::testConstructorsService( + Reference< XComponentContext > const & context) throw (RuntimeException) +{ + Sequence< sal_Bool > arg14(1); arg14[0] = true; + Sequence< sal_Int8 > arg15(1); arg15[0] = SAL_MIN_INT8; + Sequence< sal_Int16 > arg16(1); arg16[0] = SAL_MIN_INT16; + Sequence< sal_uInt16 > arg17(1); arg17[0] = SAL_MAX_UINT16; + Sequence< sal_Int32 > arg18(1); arg18[0] = SAL_MIN_INT32; + Sequence< sal_uInt32 > arg19(1); arg19[0] = SAL_MAX_UINT32; + Sequence< sal_Int64 > arg20(1); arg20[0] = SAL_MIN_INT64; + Sequence< sal_uInt64 > arg21(1); arg21[0] = SAL_MAX_UINT64; + Sequence< float > arg22(1); arg22[0] = 0.123f; + Sequence< double > arg23(1); arg23[0] = 0.456; + Sequence< sal_Unicode > arg24(1); arg24[0] = 'X'; + Sequence< OUString > arg25(1); + arg25[0] = OUString(RTL_CONSTASCII_USTRINGPARAM("test")); + Sequence< Type > arg26(1); arg26[0] = UnoType< Any >::get(); + Sequence< Any > arg27(1); arg27[0] <<= true; + Sequence< Sequence< sal_Bool > > arg28(1); + arg28[0] = Sequence< sal_Bool >(1); arg28[0][0] = true; + Sequence< Sequence< Any > > arg29(1); arg29[0] = Sequence< Any >(1); + arg29[0][0] <<= true; + Sequence< TestEnum > arg30(1); arg30[0] = TestEnum_TWO; + Sequence< TestStruct > arg31(1); arg31[0].member = 10; + Sequence< TestPolyStruct< sal_Bool > > arg32(1); arg32[0].member = true; + Sequence< TestPolyStruct< Any > > arg33(1); arg33[0].member <<= true; + Sequence< Reference< XInterface > > arg34(1); + Constructors::create1(context, + true, + SAL_MIN_INT8, + SAL_MIN_INT16, + SAL_MAX_UINT16, + SAL_MIN_INT32, + SAL_MAX_UINT32, + SAL_MIN_INT64, + SAL_MAX_UINT64, + 0.123f, + 0.456, + 'X', + OUString(RTL_CONSTASCII_USTRINGPARAM("test")), + UnoType< Any >::get(), + makeAny(true), + arg14, + arg15, + arg16, + arg17, + arg18, + arg19, + arg20, + arg21, + arg22, + arg23, + arg24, + arg25, + arg26, + arg27, + arg28, + arg29, + arg30, + arg31, + arg32, + arg33, + arg34, + TestEnum_TWO, + TestStruct(10), + TestPolyStruct< sal_Bool >(true), + TestPolyStruct< Any >(makeAny(true)), + Reference< XInterface >(0)); + Sequence< Any > args(40); + args[0] <<= true; + args[1] <<= SAL_MIN_INT8; + args[2] <<= SAL_MIN_INT16; + args[3] <<= SAL_MAX_UINT16; + args[4] <<= SAL_MIN_INT32; + args[5] <<= SAL_MAX_UINT32; + args[6] <<= SAL_MIN_INT64; + args[7] <<= SAL_MAX_UINT64; + args[8] <<= 0.123f; + args[9] <<= 0.456; + sal_Unicode arg10c = 'X'; + args[10].setValue(&arg10c, UnoType< UnoCharType >::get()); + args[11] <<= OUString(RTL_CONSTASCII_USTRINGPARAM("test")); + args[12] <<= UnoType< Any >::get(); + args[13] <<= true; + args[14] <<= arg14; + args[15] <<= arg15; + args[16] <<= arg16; + args[17] <<= arg17; + args[18] <<= arg18; + args[19] <<= arg19; + args[20] <<= arg20; + args[21] <<= arg21; + args[22] <<= arg22; + args[23] <<= arg23; + args[24].setValue(&arg24, UnoType< UnoSequenceType< UnoCharType > >::get()); + args[25] <<= arg25; + args[26] <<= arg26; + args[27] <<= arg27; + args[28] <<= arg28; + args[29] <<= arg29; + args[30] <<= arg30; + args[31] <<= arg31; + args[32] <<= arg32; + args[33] <<= arg33; + args[34] <<= arg34; + args[35] <<= TestEnum_TWO; + args[36] <<= TestStruct(10); + args[37] <<= TestPolyStruct< sal_Bool >(true); + args[38] <<= TestPolyStruct< Any >(makeAny(true)); + args[39] <<= Reference< XInterface >(0); + Constructors::create2(context, args); + + Sequence<Type> argSeq1(1); argSeq1[0] = cppu::UnoType<sal_Int32>::get(); + Sequence<Reference<XInterface> > argSeq2(1); argSeq2[0] = static_cast<XComponent*>(new Dummy()); + Sequence<Reference<XComponent> > argSeq2a(1); argSeq2a[0] = static_cast<XComponent*>(new Dummy()); + + Sequence<TestPolyStruct2<sal_Unicode, Sequence<Any> > > argSeq3(1); + argSeq3[0] = TestPolyStruct2<sal_Unicode, Sequence<Any> >('X', arg27); + Sequence<TestPolyStruct2<TestPolyStruct<sal_Unicode>, Sequence<Any> > > argSeq4(1); + argSeq4[0] = TestPolyStruct2<TestPolyStruct<sal_Unicode>, Sequence<Any> >( + TestPolyStruct<sal_Unicode>('X'), arg27); + Sequence<Sequence<sal_Int32> > argSeq5(1); + argSeq5[0] = Sequence<sal_Int32>(1); argSeq5[0][0] = SAL_MIN_INT32; + Sequence<TestPolyStruct<sal_Int32> > argSeq6(1); + argSeq6[0] = TestPolyStruct<sal_Int32>(SAL_MIN_INT32); + Sequence<TestPolyStruct<TestPolyStruct2<sal_Unicode, Any> > > argSeq7(1); + argSeq7[0] = TestPolyStruct<TestPolyStruct2<sal_Unicode, Any> >( + TestPolyStruct2<sal_Unicode, Any>('X', Any(true))); + Sequence<TestPolyStruct<TestPolyStruct2<TestPolyStruct2<sal_Unicode, Any>,OUString> > > argSeq8(1); + argSeq8[0] = TestPolyStruct<TestPolyStruct2<TestPolyStruct2<sal_Unicode, Any>,OUString> > ( + TestPolyStruct2<TestPolyStruct2<sal_Unicode, Any>,OUString>( + TestPolyStruct2<sal_Unicode, Any>('X', Any(true)), OUString(RTL_CONSTASCII_USTRINGPARAM("test")))); + Sequence<TestPolyStruct2<OUString, TestPolyStruct2<sal_Unicode, TestPolyStruct<Any> > > > argSeq9(1); + argSeq9[0] = TestPolyStruct2<OUString, TestPolyStruct2<sal_Unicode, TestPolyStruct<Any> > >( + OUString(RTL_CONSTASCII_USTRINGPARAM("test")), TestPolyStruct2<sal_Unicode, TestPolyStruct<Any> >( + 'X', TestPolyStruct<Any>(Any(true)))); + Sequence<TestPolyStruct2<TestPolyStruct2<sal_Unicode, Any>, TestPolyStruct<sal_Unicode> > > argSeq10(1); + argSeq10[0] = TestPolyStruct2<TestPolyStruct2<sal_Unicode, Any>, TestPolyStruct<sal_Unicode> >( + TestPolyStruct2<sal_Unicode, Any>('X', Any(true)), TestPolyStruct<sal_Unicode>('X')); + Sequence<Sequence<TestPolyStruct<sal_Unicode > > > argSeq11(1); + argSeq11[0] = Sequence<TestPolyStruct<sal_Unicode > >(1); + argSeq11[0][0] = TestPolyStruct<sal_Unicode>('X'); + Sequence<Sequence<TestPolyStruct<TestPolyStruct2<sal_Unicode,Any> > > > argSeq12(1); + argSeq12[0] = Sequence<TestPolyStruct<TestPolyStruct2<sal_Unicode,Any> > >(1); + argSeq12[0][0] = TestPolyStruct<TestPolyStruct2<sal_Unicode,Any> >( + TestPolyStruct2<sal_Unicode,Any>('X', Any(true))); + Sequence<Sequence<TestPolyStruct<TestPolyStruct2<TestPolyStruct2<sal_Unicode,Any>,OUString> > > > argSeq13(1); + argSeq13[0] = Sequence<TestPolyStruct<TestPolyStruct2<TestPolyStruct2<sal_Unicode,Any>,OUString> > >(1); + argSeq13[0][0] = TestPolyStruct<TestPolyStruct2<TestPolyStruct2<sal_Unicode,Any>,OUString> >( + TestPolyStruct2<TestPolyStruct2<sal_Unicode,Any>,OUString>( + TestPolyStruct2<sal_Unicode,Any>('X', Any(true)), OUString(RTL_CONSTASCII_USTRINGPARAM("test")))); + Sequence<Sequence<TestPolyStruct2<OUString, TestPolyStruct2<sal_Unicode, TestPolyStruct<Any> > > > > argSeq14(1); + argSeq14[0] = Sequence<TestPolyStruct2<OUString, TestPolyStruct2<sal_Unicode, TestPolyStruct<Any> > > >(1); + argSeq14[0][0] = TestPolyStruct2<OUString, TestPolyStruct2<sal_Unicode, TestPolyStruct<Any> > >( + OUString(RTL_CONSTASCII_USTRINGPARAM("test")), TestPolyStruct2<sal_Unicode, TestPolyStruct<Any> >( + 'X', TestPolyStruct<Any>(Any(true)))); + Sequence<Sequence<TestPolyStruct2<TestPolyStruct2<sal_Unicode,Any>, TestPolyStruct<sal_Unicode> > > > argSeq15(1); + argSeq15[0] = Sequence<TestPolyStruct2<TestPolyStruct2<sal_Unicode,Any>, TestPolyStruct<sal_Unicode> > >(1); + argSeq15[0][0] = TestPolyStruct2<TestPolyStruct2<sal_Unicode,Any>, TestPolyStruct<sal_Unicode> >( + TestPolyStruct2<sal_Unicode,Any>('X',Any(true)), TestPolyStruct<sal_Unicode>('X')); + + Constructors2::create1( + context, + TestPolyStruct<Type>(cppu::UnoType<sal_Int32>::get()), + TestPolyStruct<Any>(Any(true)), + TestPolyStruct<sal_Bool>(true), + TestPolyStruct<sal_Int8>(SAL_MIN_INT8), + TestPolyStruct<sal_Int16>(SAL_MIN_INT16), + TestPolyStruct<sal_Int32>(SAL_MIN_INT32), + TestPolyStruct<sal_Int64>(SAL_MIN_INT64), + TestPolyStruct<sal_Unicode>('X'), + TestPolyStruct<OUString>(OUString(RTL_CONSTASCII_USTRINGPARAM("test"))), + TestPolyStruct<float>(0.123f), + TestPolyStruct<double>(0.456), + TestPolyStruct<Reference<XInterface> >(static_cast<XBridgeTest2*>(this)), + TestPolyStruct<Reference<XComponent> >(static_cast<XComponent*>(new Dummy())), + TestPolyStruct<TestEnum>(TestEnum_TWO), + TestPolyStruct<TestPolyStruct2<sal_Unicode, Any> >( + TestPolyStruct2<sal_Unicode, Any>('X', Any(true))), + TestPolyStruct<TestPolyStruct2<TestPolyStruct2<sal_Unicode, Any>,OUString> > ( + TestPolyStruct2<TestPolyStruct2<sal_Unicode, Any>,OUString>( + TestPolyStruct2<sal_Unicode, Any>('X', Any(true)), OUString(RTL_CONSTASCII_USTRINGPARAM("test")))), + TestPolyStruct2<OUString, TestPolyStruct2<sal_Unicode,TestPolyStruct<Any> > >( + OUString(RTL_CONSTASCII_USTRINGPARAM("test")), + TestPolyStruct2<sal_Unicode, TestPolyStruct<Any> >('X', TestPolyStruct<Any>(Any(true)))), + TestPolyStruct2<TestPolyStruct2<sal_Unicode, Any>, TestPolyStruct<sal_Unicode> >( + TestPolyStruct2<sal_Unicode, Any>('X', Any(true)), + TestPolyStruct<sal_Unicode>('X')), + TestPolyStruct<Sequence<Type> >(argSeq1), + TestPolyStruct<Sequence<Any> >(arg27), + TestPolyStruct<Sequence<sal_Bool> >(arg14), + TestPolyStruct<Sequence<sal_Int8> >(arg15), + TestPolyStruct<Sequence<sal_Int16> >(arg16), + TestPolyStruct<Sequence<sal_Int32> >(arg18), + TestPolyStruct<Sequence<sal_Int64> >(arg20), + TestPolyStruct<Sequence<sal_Unicode> >(arg24), + TestPolyStruct<Sequence<OUString> >(arg25), + TestPolyStruct<Sequence<float> >(arg22), + TestPolyStruct<Sequence<double> >(arg23), + TestPolyStruct<Sequence<Reference<XInterface> > >(argSeq2), + TestPolyStruct<Sequence<Reference<XComponent> > >(argSeq2a), + TestPolyStruct<Sequence<TestEnum> >(arg30), + TestPolyStruct<Sequence<TestPolyStruct2<sal_Unicode, Sequence<Any> > > >(argSeq3), + TestPolyStruct<Sequence<TestPolyStruct2<TestPolyStruct<sal_Unicode>, Sequence<Any> > > > (argSeq4), + TestPolyStruct<Sequence<Sequence<sal_Int32> > >(argSeq5), + argSeq6, + argSeq7, + argSeq8, + argSeq9, + argSeq10, + argSeq11, + argSeq12, + argSeq13, + argSeq14, + argSeq15); +} + +Reference< XCurrentContextChecker > Test_Impl::getCurrentContextChecker() + throw (RuntimeException) +{ + return new testtools::bridgetest::CurrentContextChecker; +} + +// 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 > & ) +{ + return Reference< XInterface >( (XBridgeTest *)new Test_Impl() ); +} + +} + +extern "C" +{ +//================================================================================================== +void SAL_CALL component_getImplementationEnvironment( + const sal_Char ** ppEnvTypeName, uno_Environment ** ) +{ + *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME; +} +//================================================================================================== +sal_Bool SAL_CALL component_writeInfo( void *, 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 * ) +{ + 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; +} +} + diff --git a/testtools/source/bridgetest/currentcontextchecker.cxx b/testtools/source/bridgetest/currentcontextchecker.cxx new file mode 100644 index 000000000000..3da2d74e9d2b --- /dev/null +++ b/testtools/source/bridgetest/currentcontextchecker.cxx @@ -0,0 +1,129 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_testtools.hxx" + +#include "sal/config.h" + +#include "currentcontextchecker.hxx" + +#include "com/sun/star/uno/Any.hxx" +#include "com/sun/star/uno/Reference.hxx" +#include "com/sun/star/uno/RuntimeException.hpp" +#include "com/sun/star/uno/XCurrentContext.hpp" +#include "cppu/unotype.hxx" +#include "cppuhelper/implbase1.hxx" +#include "osl/diagnose.h" +#include "osl/diagnose.hxx" +#include "rtl/string.h" +#include "rtl/ustring.hxx" +#include "sal/types.h" +#include "test/testtools/bridgetest/XCurrentContextChecker.hpp" +#include "uno/current_context.hxx" + +namespace { + +namespace css = ::com::sun::star; + +static char const key[] = "testtools.bridgetest.Key"; +static char const value[] = "good"; + +class CurrentContext: + public ::osl::DebugBase< CurrentContext >, + public ::cppu::WeakImplHelper1< css::uno::XCurrentContext > +{ +public: + CurrentContext(); + + virtual ~CurrentContext(); + + virtual css::uno::Any SAL_CALL getValueByName(::rtl::OUString const & Name) + throw (css::uno::RuntimeException); + +private: + CurrentContext(CurrentContext &); // not defined + void operator =(CurrentContext &); // not defined +}; + +CurrentContext::CurrentContext() {} + +CurrentContext::~CurrentContext() {} + +css::uno::Any CurrentContext::getValueByName(::rtl::OUString const & Name) + throw (css::uno::RuntimeException) +{ + return Name.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM(key)) + ? css::uno::makeAny(::rtl::OUString::createFromAscii(value)) + : css::uno::Any(); +} + +} + +testtools::bridgetest::CurrentContextChecker::CurrentContextChecker() {} + +testtools::bridgetest::CurrentContextChecker::~CurrentContextChecker() {} + +::sal_Bool testtools::bridgetest::CurrentContextChecker::perform( + css::uno::Reference< + ::test::testtools::bridgetest::XCurrentContextChecker > const & other, + ::sal_Int32 setSteps, ::sal_Int32 checkSteps) + throw (css::uno::RuntimeException) +{ + if (setSteps == 0) { + css::uno::ContextLayer layer(new CurrentContext); + return performCheck(other, setSteps, checkSteps); + } else { + return performCheck(other, setSteps, checkSteps); + } +} + +bool testtools::bridgetest::CurrentContextChecker::performCheck( + css::uno::Reference< + ::test::testtools::bridgetest::XCurrentContextChecker > const & other, + ::sal_Int32 setSteps, ::sal_Int32 checkSteps) +{ + OSL_ASSERT(other.is() && checkSteps >= 0); + if (checkSteps == 0) { + css::uno::Reference< css::uno::XCurrentContext > context( + css::uno::getCurrentContext()); + if (!context.is()) { + return false; + } + css::uno::Any a( + context->getValueByName(::rtl::OUString::createFromAscii(key))); + if (a.getValueType() != ::cppu::UnoType< ::rtl::OUString >::get()) { + return false; + } + ::rtl::OUString s; + OSL_VERIFY(a >>= s); + return s.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM(value)); + } else { + return other->perform( + this, setSteps >= 0 ? setSteps - 1 : -1, checkSteps - 1); + } +} diff --git a/testtools/source/bridgetest/currentcontextchecker.hxx b/testtools/source/bridgetest/currentcontextchecker.hxx new file mode 100644 index 000000000000..f38358a074a2 --- /dev/null +++ b/testtools/source/bridgetest/currentcontextchecker.hxx @@ -0,0 +1,73 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef INCLUDED_TESTTOOLS_SOURCE_BRIDGETEST_CURRENTCONTEXTCHECKER_HXX +#define INCLUDED_TESTTOOLS_SOURCE_BRIDGETEST_CURRENTCONTEXTCHECKER_HXX + +#include "sal/config.h" +#include "com/sun/star/uno/Reference.hxx" +#include "com/sun/star/uno/RuntimeException.hpp" +#include "cppuhelper/implbase1.hxx" +#ifndef OSL_DIAGNOSE_HXX_INCLUDED +#include "osl/diagnose.hxx" +#endif +#include "sal/types.h" +#include "test/testtools/bridgetest/XCurrentContextChecker.hpp" + +namespace testtools { namespace bridgetest { + +class CurrentContextChecker: + public ::osl::DebugBase< CurrentContextChecker >, + public ::cppu::WeakImplHelper1< + ::test::testtools::bridgetest::XCurrentContextChecker > +{ +public: + CurrentContextChecker(); + + virtual ~CurrentContextChecker(); + + virtual ::sal_Bool SAL_CALL perform( + ::com::sun::star::uno::Reference< + ::test::testtools::bridgetest::XCurrentContextChecker > const & + other, + ::sal_Int32 setSteps, ::sal_Int32 checkSteps) + throw (::com::sun::star::uno::RuntimeException); + +private: + CurrentContextChecker(CurrentContextChecker &); // not defined + void operator =(CurrentContextChecker &); // not defined + + bool performCheck( + ::com::sun::star::uno::Reference< + ::test::testtools::bridgetest::XCurrentContextChecker > const & + other, + ::sal_Int32 setSteps, ::sal_Int32 checkSteps); +}; + +} } + +#endif diff --git a/testtools/source/bridgetest/idl/bridgetest.idl b/testtools/source/bridgetest/idl/bridgetest.idl new file mode 100644 index 000000000000..40a0066211ab --- /dev/null +++ b/testtools/source/bridgetest/idl/bridgetest.idl @@ -0,0 +1,552 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include "com/sun/star/lang/IllegalArgumentException.idl" +#include "com/sun/star/lang/XComponent.idl" +#include "com/sun/star/uno/XComponentContext.idl" +#include "com/sun/star/uno/XInterface.idl" + +module test { module testtools { module bridgetest { + +enum TestEnum +{ + TEST, + ONE, + TWO, + CHECK, + LOLA, + PALOO, + ZA +}; + +enum TestBadEnum { M = 1 }; + +struct TestStruct +{ + long member; +}; + +/** + * simple types + */ +struct TestSimple +{ + boolean Bool; + char Char; + byte Byte; + short Short; + unsigned short UShort; + long Long; + unsigned long ULong; + hyper Hyper; + unsigned hyper UHyper; + float Float; + double Double; + TestEnum Enum; +}; +/** + * equal to max size returned in registers on x86_64 + */ +struct SmallStruct +{ + hyper a; + hyper b; +}; +/** + * equal to max size returned in registers on ia64 + */ +struct MediumStruct +{ + hyper a; + hyper b; + hyper c; + hyper d; +}; +/** + * bigger than max size returned in registers on ia64 + */ +struct BigStruct +{ + hyper a; + hyper b; + hyper c; + hyper d; + hyper e; + hyper f; + hyper g; + hyper h; +}; +/** + * all floats, ia64 handles them specially + */ +struct AllFloats +{ + float a; + float b; + float c; + float d; +}; +/** + * complex types adding string, inteface, any + */ +struct TestElement : TestSimple +{ + string String; + com::sun::star::uno::XInterface Interface; + any Any; +}; +/** + * adding even more complexity, sequence< TestElement > + */ +struct TestDataElements : TestElement +{ + sequence< TestElement > Sequence; +}; + +/** + * typedef used in interface + */ +typedef TestDataElements TestData; + +struct TestPolyStruct<T> { T member; }; +struct TestPolyStruct2<T,C> { + T member1; + C member2; +}; + +interface XRecursiveCall : com::sun::star::uno::XInterface +{ + /*** + * @param nToCall If nToCall is 0, the method returns immeadiatly. + * Otherwise, call the given interface with nToCall -1 + * + ***/ + void callRecursivly( [in] XRecursiveCall xCall , [in] long nToCall ); +}; + +interface XMultiBase1 { + [attribute] double att1; // initially 0.0 + long fn11([in] long arg); // return 11 * arg + string fn12([in] string arg); // return "12" + arg +}; + +interface XMultiBase2: XMultiBase1 { + long fn21([in] long arg); // return 21 * arg + string fn22([in] string arg); // return "22" + arg +}; + +interface XMultiBase3 { + [attribute] double att3; // initially 0.0 + long fn31([in] long arg); // return 31 * arg + string fn32([in] string arg); // return "32" + arg + long fn33(); // return 33 +}; + +interface XMultiBase3a: XMultiBase3 {}; + +interface XMultiBase4 { + long fn41([in] long arg); // return 41 * arg +}; + +interface XMultiBase5 { + interface XMultiBase3; + interface XMultiBase4; + interface XMultiBase1; +}; + +interface XMultiBase6 { + interface XMultiBase2; + interface XMultiBase3a; + interface XMultiBase5; + long fn61([in] long arg); // return 61 * arg + string fn62([in] string arg); // return "62" + arg +}; + +interface XMultiBase7 { + long fn71([in] long arg); // return 71 * arg + string fn72([in] string arg); // return "72" + arg + long fn73(); // return 73 +}; + +interface XMulti { + interface XMultiBase6; + interface XMultiBase7; +}; + +/** + * Monster test interface to test bridge calls. + * An implementation of this object has to store given values and return whenever there + * is an out param or return value. + */ +interface XBridgeTestBase : com::sun::star::uno::XInterface +{ + /** + * in parameter test, tests by calls reference also (complex types) + */ + [oneway] void setValues( [in] boolean bBool, [in] char cChar, [in] byte nByte, + [in] short nShort, [in] unsigned short nUShort, + [in] long nLong, [in] unsigned long nULong, + [in] hyper nHyper, [in] unsigned hyper nUHyper, + [in] float fFloat, [in] double fDouble, + [in] TestEnum eEnum, [in] string aString, + [in] com::sun::star::uno::XInterface xInterface, [in] any aAny, + [in] sequence< TestElement > aSequence, + [in] TestData aStruct ); + /** + * inout parameter test + * + * @return aStruct. The out parameter contain the values, that were previously set + * by setValues or (if not called before) default constructed values. + * + */ + TestData setValues2( [inout] boolean bBool, [inout] char cChar, [inout] byte nByte, + [inout] short nShort, [inout] unsigned short nUShort, + [inout] long nLong, [inout] unsigned long nULong, + [inout] hyper nHyper, [inout] unsigned hyper nUHyper, + [inout] float fFloat, [inout] double fDouble, + [inout] TestEnum eEnum, [inout] string aString, + [inout] com::sun::star::uno::XInterface xInterface, [inout] any aAny, + [inout] sequence< TestElement > aSequence, + [inout] TestData aStruct ); + + /** + * out parameter test + */ + TestData getValues( [out] boolean bBool, [out] char cChar, [out] byte nByte, + [out] short nShort, [out] unsigned short nUShort, + [out] long nLong, [out] unsigned long nULong, + [out] hyper nHyper, [out] unsigned hyper nUHyper, + [out] float fFloat, [out] double fDouble, + [out] TestEnum eEnum, [out] string aString, + [out] com::sun::star::uno::XInterface xInterface, [out] any aAny, + [out] sequence< TestElement > aSequence, + [out] TestData aStruct ); + + /** + * register return test 1 + */ + SmallStruct echoSmallStruct( [in] SmallStruct aStruct ); + + /** + * register return test 2 + */ + MediumStruct echoMediumStruct( [in] MediumStruct aStruct ); + + /** + * register return test 3 + */ + BigStruct echoBigStruct( [in] BigStruct aStruct ); + + /** + * register return test 4 + */ + AllFloats echoAllFloats( [in] AllFloats aStruct ); + + /** + * register return test 4 (i107182) + */ + long testPPCAlignment( [in] hyper l1, [in] hyper l2, [in] long i1, [in] hyper l3, [in] long i2 ); + + [attribute] boolean Bool; + [attribute] byte Byte; + [attribute] char Char; + [attribute] short Short; + [attribute] unsigned short UShort; + [attribute] long Long; + [attribute] unsigned long ULong; + [attribute] hyper Hyper; + [attribute] unsigned hyper UHyper; + [attribute] float Float; + [attribute] double Double; + [attribute] TestEnum Enum; + [attribute] string String; + [attribute] com::sun::star::uno::XInterface Interface; + [attribute] any Any; + [attribute] sequence< TestElement > Sequence; + [attribute] TestData Struct; + + [attribute] long RaiseAttr1 { + set raises (com::sun::star::lang::IllegalArgumentException); + }; + [attribute, readonly] long RaiseAttr2 { + get raises (com::sun::star::lang::IllegalArgumentException); + }; + + TestPolyStruct<boolean> transportPolyBoolean( + [in] TestPolyStruct<boolean> arg); + void transportPolyHyper([inout] TestPolyStruct<hyper> arg); + void transportPolySequence( + [in] TestPolyStruct<sequence<any> > arg1, + [out] TestPolyStruct<sequence<any> > arg2); + + TestPolyStruct<long> getNullPolyLong(); + TestPolyStruct<string> getNullPolyString(); + TestPolyStruct<type> getNullPolyType(); + TestPolyStruct<any> getNullPolyAny(); + TestPolyStruct<sequence<boolean> > getNullPolySequence(); + TestPolyStruct<TestEnum> getNullPolyEnum(); + TestPolyStruct<TestBadEnum> getNullPolyBadEnum(); + TestPolyStruct<TestStruct> getNullPolyStruct(); + TestPolyStruct<XBridgeTestBase> getNullPolyInterface(); + + /*** + * This method returns the parameter value. + * Method to extensivly test anys. + ****/ + any transportAny( [in] any value ); + + /*** + * methods to check sequence of calls. Call call() and callOneway + * in an arbitrary sequence. Increase the callId for every call. + * The testobject sets an error flag. + + @see testSequencePassed + ***/ + void call( [in] long nCallId, [in] long nWaitMUSEC ); + [oneway] void callOneway( [in] long nCallId, [in] long nWaitMUSEC ); + boolean sequenceOfCallTestPassed(); + + /**** + * methods to check, if threads thread identity is holded. + * + ***/ + void startRecursiveCall( [in] XRecursiveCall xCall , [in] long nToCall ); + + XMulti getMulti(); + string testMulti([in] XMulti multi); +}; + + +/** + * Inherting from monster; adds raiseException(), attribute raising RuntimeException. + */ +interface XBridgeTest : XBridgeTestBase +{ + /** + * the exception struct returned has to be filled with given arguments. + * return value is for dummy. + */ + TestData raiseException( [in] short ArgumentPosition, + [in] string Message, + [in] com::sun::star::uno::XInterface Context ) + raises( com::sun::star::lang::IllegalArgumentException ); + + + /** + * Throws runtime exception. + * check remote bridges handle exceptions during oneway calls properly. + * Note that on client side the execption may fly or not. When it flies, it should + * have the proper message and context. + ***/ + [oneway] void raiseRuntimeExceptionOneway( [in] string Message, + [in] com::sun::star::uno::XInterface Context ); + + /** + * raises runtime exception; + * the exception struct returned has to be filled with formerly set test data. + */ + [attribute] long RuntimeException; +}; + + +exception BadConstructorArguments: com::sun::star::uno::Exception {}; + +service Constructors: com::sun::star::uno::XInterface { + create1( + [in] boolean arg0, + [in] byte arg1, + [in] short arg2, + [in] unsigned short arg3, + [in] long arg4, + [in] unsigned long arg5, + [in] hyper arg6, + [in] unsigned hyper arg7, + [in] float arg8, + [in] double arg9, + [in] char arg10, + [in] string arg11, + [in] type arg12, + [in] any arg13, + [in] sequence< boolean > arg14, + [in] sequence< byte > arg15, + [in] sequence< short > arg16, + [in] sequence< unsigned short > arg17, + [in] sequence< long > arg18, + [in] sequence< unsigned long > arg19, + [in] sequence< hyper > arg20, + [in] sequence< unsigned hyper > arg21, + [in] sequence< float > arg22, + [in] sequence< double > arg23, + [in] sequence< char > arg24, + [in] sequence< string > arg25, + [in] sequence< type > arg26, + [in] sequence< any > arg27, + [in] sequence< sequence< boolean > > arg28, + [in] sequence< sequence< any > > arg29, + [in] sequence< TestEnum > arg30, + [in] sequence< TestStruct > arg31, + [in] sequence< TestPolyStruct< boolean > > arg32, + [in] sequence< TestPolyStruct< any > > arg33, + [in] sequence< com::sun::star::uno::XInterface > arg34, + [in] TestEnum arg35, + [in] TestStruct arg36, + [in] TestPolyStruct< boolean > arg37, + [in] TestPolyStruct< any > arg38, + [in] com::sun::star::uno::XInterface arg39) + raises (BadConstructorArguments); + + create2([in] any... args) raises (BadConstructorArguments); + +}; + +service Constructors2: XMultiBase1 { + + create1( + [in] TestPolyStruct<type> arg1, + [in] TestPolyStruct<any> arg2, + [in] TestPolyStruct<boolean> arg3, + [in] TestPolyStruct<byte> arg4, + [in] TestPolyStruct<short> arg5, + [in] TestPolyStruct<long> arg6, + [in] TestPolyStruct<hyper> arg7, + [in] TestPolyStruct<char> arg8, + [in] TestPolyStruct<string> arg9, + [in] TestPolyStruct<float> arg10, + [in] TestPolyStruct<double> arg11, + [in] TestPolyStruct<com::sun::star::uno::XInterface> arg12, + [in] TestPolyStruct<com::sun::star::lang::XComponent> arg13, + [in] TestPolyStruct<TestEnum> arg14, + [in] TestPolyStruct<TestPolyStruct2<char,any> > arg15, + [in] TestPolyStruct<TestPolyStruct2<TestPolyStruct2<char,any>,string> > arg16, + [in] TestPolyStruct2<string, TestPolyStruct2<char, TestPolyStruct<any> > > arg17, + [in] TestPolyStruct2<TestPolyStruct2<char,any>, TestPolyStruct<char> > arg18, + [in] TestPolyStruct<sequence<type> > arg19, + [in] TestPolyStruct<sequence<any> > arg20, + [in] TestPolyStruct<sequence<boolean> > arg21, + [in] TestPolyStruct<sequence<byte> > arg22, + [in] TestPolyStruct<sequence<short> > arg23, + [in] TestPolyStruct<sequence<long> > arg24, + [in] TestPolyStruct<sequence<hyper> > arg25, + [in] TestPolyStruct<sequence<char> > arg26, + [in] TestPolyStruct<sequence<string> > arg27, + [in] TestPolyStruct<sequence<float> > arg28, + [in] TestPolyStruct<sequence<double> > arg29, + [in] TestPolyStruct<sequence<com::sun::star::uno::XInterface> > arg30, + [in] TestPolyStruct<sequence<com::sun::star::lang::XComponent> > arg31, + [in] TestPolyStruct<sequence<TestEnum> > arg32, + [in] TestPolyStruct<sequence<TestPolyStruct2<char, sequence<any> > > > arg33, + [in] TestPolyStruct<sequence<TestPolyStruct2<TestPolyStruct<char>, sequence<any> > > > arg34, + [in] TestPolyStruct<sequence<sequence<long> > > arg35, + [in] sequence<TestPolyStruct<long > > arg36, + [in] sequence<TestPolyStruct<TestPolyStruct2<char,any> > > arg37, + [in] sequence<TestPolyStruct<TestPolyStruct2<TestPolyStruct2<char,any>,string> > > arg38, + [in] sequence<TestPolyStruct2<string, TestPolyStruct2<char, TestPolyStruct<any> > > > arg39, + [in] sequence<TestPolyStruct2<TestPolyStruct2<char,any>, TestPolyStruct<char> > > arg40, + [in] sequence<sequence<TestPolyStruct< char > > > arg41, + [in] sequence<sequence<TestPolyStruct<TestPolyStruct2<char,any> > > >arg42, + [in] sequence<sequence<TestPolyStruct<TestPolyStruct2<TestPolyStruct2<char,any>,string> > > > arg43, + [in] sequence<sequence<TestPolyStruct2<string, TestPolyStruct2<char, TestPolyStruct<any> > > > > arg44, + [in] sequence<sequence<TestPolyStruct2<TestPolyStruct2<char,any>, TestPolyStruct<char> > > > arg45 + ); +}; + +interface XCurrentContextChecker { + boolean perform( + [in] XCurrentContextChecker other, [in] long setSteps, + [in] long checkSteps); +}; + +/** Extended tests with sequences. + */ +interface XBridgeTest2 : XBridgeTest +{ + sequence< boolean > setSequenceBool( [in] sequence< boolean > aSeq); + sequence< char > setSequenceChar( [in] sequence< char > aSeq); + sequence< byte> setSequenceByte( [in] sequence< byte > aSeq); + sequence< short> setSequenceShort( [in] sequence< short > aSeq); + sequence< unsigned short > setSequenceUShort( [in] sequence< unsigned short > aSeq); + sequence< long > setSequenceLong( [in] sequence< long > aSeq); + sequence< unsigned long > setSequenceULong( [in] sequence< unsigned long > aSeq); + sequence< hyper > setSequenceHyper( [in] sequence< hyper > aSeq); + sequence< unsigned hyper > setSequenceUHyper( [in] sequence< unsigned hyper > aSeq); + sequence< float > setSequenceFloat( [in] sequence< float > aSeq); + sequence< double > setSequenceDouble( [in] sequence< double > aSeq); + sequence< TestEnum > setSequenceEnum( [in] sequence< TestEnum > aSeq); + sequence< string > setSequenceString( [in] sequence< string > aString); + sequence< com::sun::star::uno::XInterface > setSequenceXInterface( + [in] sequence< com::sun::star::uno::XInterface > aSeq); + sequence< any > setSequenceAny( [in] sequence< any > aSeq); + sequence< TestElement > setSequenceStruct( [in] sequence< TestElement > aSeq); + + sequence< sequence< long > > setDim2( [in] sequence< sequence< long > > aSeq); + sequence< sequence < sequence < long > > > setDim3( + [in] sequence< sequence < sequence < long > > > aSeq); + + void setSequencesInOut( [inout] sequence< boolean > aSeqBoolean, + [inout] sequence< char > aSeqChar, + [inout] sequence< byte > aSeqByte, + [inout] sequence< short > aSeqShort, + [inout] sequence< unsigned short> aSeqUShort, + [inout] sequence< long > aSeqLong, + [inout] sequence< unsigned long > aSeqULong, + [inout] sequence< hyper > aSeqHyper, + [inout] sequence< unsigned hyper > aSeqUHyper, + [inout] sequence< float > aSeqFloat, + [inout] sequence< double > aSeqDouble, + [inout] sequence< TestEnum > aSeqEnum, + [inout] sequence< string > aSeqString, + [inout] sequence< com::sun::star::uno::XInterface > aSeqXInterface, + [inout] sequence< any > aSeqAny, + [inout] sequence< sequence< long > > aSeqDim2, + [inout] sequence< sequence < sequence < long > > > aSeqDim3); + + void setSequencesOut( [out] sequence< boolean > aSeqBoolean, + [out] sequence< char > aSeqChar, + [out] sequence< byte > aSeqByte, + [out] sequence< short > aSeqShort, + [out] sequence< unsigned short> aSeqUShort, + [out] sequence< long > aSeqLong, + [out] sequence< unsigned long > aSeqULong, + [out] sequence< hyper > aSeqHyper, + [out] sequence< unsigned hyper > aSeqUHyper, + [out] sequence< float > aSeqFloat, + [out] sequence< double > aSeqDouble, + [out] sequence< TestEnum > aSeqEnum, + [out] sequence< string > aSeqString, + [out] sequence< com::sun::star::uno::XInterface > aSeqXInterface, + [out] sequence< any > aSeqAny, + [out] sequence< sequence< long > > aSeqDim2, + [out] sequence< sequence < sequence < long > > > aSeqDim3); + + void testConstructorsService( + [in] com::sun::star::uno::XComponentContext context) + raises (BadConstructorArguments); + + XCurrentContextChecker getCurrentContextChecker(); +}; + +}; }; }; diff --git a/testtools/source/bridgetest/idl/makefile.mk b/testtools/source/bridgetest/idl/makefile.mk new file mode 100644 index 000000000000..b056aec1c0be --- /dev/null +++ b/testtools/source/bridgetest/idl/makefile.mk @@ -0,0 +1,70 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2000, 2010 Oracle and/or its affiliates. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org 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 version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* + +PRJ := ..$/..$/.. +PRJNAME := testtools +TARGET := bridgetest_idl + +.INCLUDE: settings.mk +.INCLUDE: target.mk +.IF "$(L10N_framework)"=="" +ALLTAR: $(MISC)$/$(TARGET).cppumaker.done $(MISC)$/$(TARGET).javamaker.done + +$(MISC)$/$(TARGET).cppumaker.done: $(BIN)$/bridgetest.rdb + $(CPPUMAKER) -O$(INCCOM) -BUCR $< -X$(SOLARBINDIR)/types.rdb + $(TOUCH) $@ + +$(MISC)$/$(TARGET).javamaker.done: $(BIN)$/bridgetest.rdb + $(JAVAMAKER) -O$(CLASSDIR) -BUCR -nD -X$(SOLARBINDIR)/types.rdb $< + $(TOUCH) $@ + +$(BIN)$/bridgetest.rdb: bridgetest.idl + $(IDLC) -O$(MISC)$/$(TARGET) -I$(SOLARIDLDIR) -cid -we $< + - $(RM) $@ + $(REGMERGE) $@ /UCR $(MISC)$/$(TARGET)$/bridgetest.urd + +.IF "$(GUI)" == "WNT" +.IF "$(COM)" != "GCC" + +CLIMAKERFLAGS = +.IF "$(debug)" != "" +CLIMAKERFLAGS += --verbose +.ENDIF + +ALLTAR: $(MISC)$/$(TARGET).cppumaker.done \ + $(MISC)$/$(TARGET).javamaker.done \ + $(BIN)$/cli_types_bridgetest.dll + +$(BIN)$/cli_types_bridgetest.dll: $(BIN)$/bridgetest.rdb + $(CLIMAKER) $(CLIMAKERFLAGS) --out $@ -r $(SOLARBINDIR)$/cli_uretypes.dll \ + -X $(SOLARBINDIR)$/types.rdb $< + $(TOUCH) $@ + +.ENDIF +.ENDIF # GUI, WNT +.ENDIF # L10N_framework + diff --git a/testtools/source/bridgetest/makefile.mk b/testtools/source/bridgetest/makefile.mk new file mode 100644 index 000000000000..9b75a1aed1e3 --- /dev/null +++ b/testtools/source/bridgetest/makefile.mk @@ -0,0 +1,218 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2000, 2010 Oracle and/or its affiliates. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org 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 version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* + +PRJ=..$/.. + +PRJNAME=testtools +TARGET=bridgetest +USE_DEFFILE=TRUE +ENABLE_EXCEPTIONS=TRUE +LIBTARGET=NO + +.INCLUDE: settings.mk +.IF "$(L10N_framework)"=="" +DLLPRE = # no leading "lib" on .so files + +.IF "$(GUI)"=="WNT" +BATCH_SUFFIX=.bat +GIVE_EXEC_RIGHTS=@echo +MY_URE_INTERNAL_JAVA_DIR=$(strip $(subst,\,/ file:///$(shell @$(WRAPCMD) echo $(SOLARBINDIR)))) +MY_LOCAL_CLASSDIR=$(strip $(subst,\,/ file:///$(shell $(WRAPCMD) echo $(PWD)$/$(CLASSDIR)))) +.ELIF "$(GUI)"=="OS2" +BATCH_SUFFIX=.cmd +GIVE_EXEC_RIGHTS=@echo +MY_URE_INTERNAL_JAVA_DIR=$(strip $(subst,\,/ file:///$(shell @$(WRAPCMD) echo $(SOLARBINDIR)))) +MY_LOCAL_CLASSDIR=$(strip $(subst,\,/ file:///$(shell $(WRAPCMD) echo $(PWD)$/$(CLASSDIR)))) +.ELSE +GIVE_EXEC_RIGHTS=chmod +x +MY_URE_INTERNAL_JAVA_DIR=file://$(SOLARBINDIR) +MY_LOCAL_CLASSDIR=file://$(PWD)$/$(CLASSDIR) +.ENDIF + +.IF "$(GUI)"=="WNT" +.IF "$(compcheck)" != "" +CFLAGSCXX += -DCOMPCHECK +.ENDIF +.ENDIF + +SLOFILES = \ + $(SLO)$/bridgetest.obj \ + $(SLO)$/cppobj.obj \ + $(SLO)$/currentcontextchecker.obj \ + $(SLO)$/multi.obj + +# ---- test ---- + +LIB1TARGET=$(SLB)$/cppobj.lib +LIB1OBJFILES= \ + $(SLO)$/cppobj.obj $(SLO)$/currentcontextchecker.obj $(SLO)$/multi.obj + +SHL1TARGET = cppobj.uno +SHL1STDLIBS= \ + $(CPPULIB) \ + $(CPPUHELPERLIB) \ + $(SALLIB) + +SHL1LIBS= $(LIB1TARGET) +SHL1DEF= $(MISC)$/$(SHL1TARGET).def +DEF1NAME= $(SHL1TARGET) +SHL1VERSIONMAP = $(SOLARENV)/src/component.map + +# ---- test object ---- + +LIB2TARGET=$(SLB)$/bridgetest.lib +LIB2OBJFILES= \ + $(SLO)$/bridgetest.obj \ + $(SLO)$/currentcontextchecker.obj \ + $(SLO)$/multi.obj + +SHL2TARGET = bridgetest.uno +SHL2STDLIBS= \ + $(CPPULIB) \ + $(CPPUHELPERLIB) \ + $(SALLIB) + +SHL2LIBS= $(LIB2TARGET) +SHL2DEF= $(MISC)$/$(SHL2TARGET).def +DEF2NAME= $(SHL2TARGET) +SHL2VERSIONMAP = $(SOLARENV)/src/component.map + +SHL3TARGET = constructors.uno +SHL3OBJS = $(SLO)$/constructors.obj +SHL3STDLIBS = $(CPPULIB) $(CPPUHELPERLIB) $(SALLIB) +SHL3VERSIONMAP = $(SOLARENV)/src/component.map +SHL3IMPLIB = i$(SHL3TARGET) +DEF3NAME = $(SHL3TARGET) + +.IF "$(SOLAR_JAVA)" != "" +JARFILES = java_uno.jar jurt.jar ridl.jar +JAVATARGETS=\ + $(DLLDEST)$/bridgetest_javaserver$(BATCH_SUFFIX) \ + $(DLLDEST)$/bridgetest_inprocess_java$(BATCH_SUFFIX) +.ENDIF + +# --- Targets ------------------------------------------------------ +.ENDIF # L10N_framework + +.INCLUDE : target.mk +.IF "$(L10N_framework)"=="" +ALLTAR: \ + runtest \ + $(DLLDEST)$/uno_types.rdb \ + $(DLLDEST)$/uno_services.rdb \ + $(DLLDEST)$/bridgetest_server$(BATCH_SUFFIX) \ + $(DLLDEST)$/bridgetest_client$(BATCH_SUFFIX) \ + $(JAVATARGETS) + +################################################################# + +runtest : $(DLLDEST)$/uno_types.rdb $(DLLDEST)$/uno_services.rdb makefile.mk +.IF "$(COM)$(OS)$(CPU)" == "GCCMACOSXP" + @echo "Mac OSX PPC GCC fails this test!, likely broken UNO bridge. Fix me." +.ELSE + cd $(DLLDEST) && $(AUGMENT_LIBRARY_PATH) $(SOLARBINDIR)/uno \ + -ro uno_services.rdb -ro uno_types.rdb \ + -s com.sun.star.test.bridge.BridgeTest -- \ + com.sun.star.test.bridge.CppTestObject +.ENDIF + +$(DLLDEST)$/uno_types.rdb : $(SOLARBINDIR)$/udkapi.rdb + echo $(DLLDEST) + $(GNUCOPY) $? $@ + $(REGMERGE) $@ / $(BIN)$/bridgetest.rdb + +$(DLLDEST)$/bridgetest_client$(BATCH_SUFFIX) .ERRREMOVE: makefile.mk + echo '$(AUGMENT_LIBRARY_PATH)' '$(SOLARBINDIR)'/uno -ro uno_services.rdb -ro uno_types.rdb \ + -s com.sun.star.test.bridge.BridgeTest -- \ + -u \''uno:socket,host=127.0.0.1,port=2002;urp;test'\' > $@ + $(GIVE_EXEC_RIGHTS) $@ + +$(DLLDEST)$/bridgetest_server$(BATCH_SUFFIX) .ERRREMOVE: makefile.mk + echo '$(AUGMENT_LIBRARY_PATH)' '$(SOLARBINDIR)'/uno -ro uno_services.rdb -ro uno_types.rdb \ + -s com.sun.star.test.bridge.CppTestObject \ + -u \''uno:socket,host=127.0.0.1,port=2002;urp;test'\' --singleaccept \ + > $@ + $(GIVE_EXEC_RIGHTS) $@ + + +.IF "$(SOLAR_JAVA)" != "" +# jar-files, which regcomp needs so that it can use java +MY_JARS=java_uno.jar ridl.jar jurt.jar juh.jar + +# CLASSPATH, which regcomp needs to be run +MY_CLASSPATH_TMP=$(foreach,i,$(MY_JARS) $(SOLARBINDIR)$/$i)$(PATH_SEPERATOR)$(XCLASSPATH) +MY_CLASSPATH=$(strip $(subst,!,$(PATH_SEPERATOR) $(MY_CLASSPATH_TMP:s/ /!/)))$(PATH_SEPERATOR)..$/class + +# Use "127.0.0.1" instead of "localhost", see #i32281#: +$(DLLDEST)$/bridgetest_javaserver$(BATCH_SUFFIX) : makefile.mk + -rm -f $@ + echo java -classpath "$(MY_CLASSPATH)$(PATH_SEPERATOR)..$/class$/testComponent.jar" \ + com.sun.star.comp.bridge.TestComponentMain \""uno:socket,host=127.0.0.1,port=2002;urp;test"\" singleaccept > $@ + $(GIVE_EXEC_RIGHTS) $@ + +$(DLLDEST)$/bridgetest_inprocess_java$(BATCH_SUFFIX) .ERRREMOVE: makefile.mk + echo '$(AUGMENT_LIBRARY_PATH)' '$(SOLARBINDIR)'/uno -ro uno_services.rdb -ro uno_types.rdb \ + -s com.sun.star.test.bridge.BridgeTest \ + -env:URE_INTERNAL_JAVA_DIR=$(MY_URE_INTERNAL_JAVA_DIR) \ + -- com.sun.star.test.bridge.JavaTestObject noCurrentContext > $@ + $(GIVE_EXEC_RIGHTS) $@ +.ENDIF + +$(DLLDEST)$/uno_services.rdb .ERRREMOVE: $(DLLDEST)$/uno_types.rdb \ + $(DLLDEST)$/bridgetest.uno$(DLLPOST) $(DLLDEST)$/cppobj.uno$(DLLPOST) \ + $(MISC)$/$(TARGET)$/bootstrap.rdb $(SHL3TARGETN) + - $(MKDIR) $(@:d) + $(REGCOMP) -register -br $(DLLDEST)$/uno_types.rdb \ + -r $(DLLDEST)$/uno_services.rdb -wop \ + -c acceptor.uno$(DLLPOST) \ + -c bridgefac.uno$(DLLPOST) \ + -c connector.uno$(DLLPOST) \ + -c remotebridge.uno$(DLLPOST) \ + -c uuresolver.uno$(DLLPOST) \ + -c stocservices.uno$(DLLPOST) + cd $(DLLDEST) && $(REGCOMP) -register -br uno_types.rdb \ + -r uno_services.rdb -wop=./ \ + -c .$/bridgetest.uno$(DLLPOST) \ + -c .$/cppobj.uno$(DLLPOST) \ + -c .$/$(SHL3TARGETN:f) +.IF "$(SOLAR_JAVA)" != "" + $(REGCOMP) -register -br $(DLLDEST)$/uno_types.rdb -r $@ \ + -c javaloader.uno$(DLLPOST) -c javavm.uno$(DLLPOST) + $(REGCOMP) -register -br $(MISC)$/$(TARGET)$/bootstrap.rdb -r $@ -c \ + $(MY_LOCAL_CLASSDIR)/testComponent.jar \ + -env:URE_INTERNAL_JAVA_DIR=$(MY_URE_INTERNAL_JAVA_DIR) +.ENDIF + +$(MISC)$/$(TARGET)$/bootstrap.rdb .ERRREMOVE: + - $(MKDIR) $(@:d) + $(COPY) $(SOLARBINDIR)$/types.rdb $@ +.IF "$(SOLAR_JAVA)" != "" + $(REGCOMP) -register -r $@ -c javaloader.uno$(DLLPOST) \ + -c javavm.uno$(DLLPOST) -c stocservices.uno$(DLLPOST) +.ENDIF +.ENDIF # L10N_framework + diff --git a/testtools/source/bridgetest/multi.cxx b/testtools/source/bridgetest/multi.cxx new file mode 100644 index 000000000000..26755df71acf --- /dev/null +++ b/testtools/source/bridgetest/multi.cxx @@ -0,0 +1,240 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_testtools.hxx" + +#include "sal/config.h" + +#include "multi.hxx" + +#include "rtl/string.hxx" +#include "rtl/textenc.h" +#include "rtl/ustring.hxx" + +#include <sstream> + +namespace css = com::sun::star; + +namespace { + +struct CheckFailed { + explicit CheckFailed(rtl::OUString const & theMessage): message(theMessage) + {} + + rtl::OUString message; +}; + +template< typename T > void checkEqual(T const & value, T const & argument) { + if (argument != value) { + std::ostringstream s; + s << value << " != " << argument; + throw CheckFailed( + rtl::OStringToOUString( + rtl::OString(s.str().c_str()), RTL_TEXTENCODING_UTF8)); + } +} + +} + +namespace testtools { namespace bridgetest { + +rtl::OUString testMulti( + com::sun::star::uno::Reference< test::testtools::bridgetest::XMulti > + const & multi) +{ + try { + checkEqual( + 0.0, + css::uno::Reference< test::testtools::bridgetest::XMultiBase1 >( + multi, css::uno::UNO_QUERY_THROW)->getatt1()); + checkEqual( + 0.0, + static_cast< test::testtools::bridgetest::XMultiBase2 * >( + multi.get())->getatt1()); + checkEqual( + 0.0, + css::uno::Reference< test::testtools::bridgetest::XMultiBase2 >( + multi, css::uno::UNO_QUERY_THROW)->getatt1()); + checkEqual( + 0.0, + static_cast< test::testtools::bridgetest::XMultiBase5 * >( + multi.get())->getatt1()); + checkEqual( + 0.0, + css::uno::Reference< test::testtools::bridgetest::XMultiBase5 >( + multi, css::uno::UNO_QUERY_THROW)->getatt1()); + css::uno::Reference< test::testtools::bridgetest::XMultiBase5 >( + multi, css::uno::UNO_QUERY_THROW)->setatt1(0.1); + checkEqual( + 0.1, + css::uno::Reference< test::testtools::bridgetest::XMultiBase1 >( + multi, css::uno::UNO_QUERY_THROW)->getatt1()); + checkEqual( + 0.1, + static_cast< test::testtools::bridgetest::XMultiBase2 * >( + multi.get())->getatt1()); + checkEqual( + 0.1, + css::uno::Reference< test::testtools::bridgetest::XMultiBase2 >( + multi, css::uno::UNO_QUERY_THROW)->getatt1()); + checkEqual( + 0.1, + static_cast< test::testtools::bridgetest::XMultiBase5 * >( + multi.get())->getatt1()); + checkEqual( + 0.1, + css::uno::Reference< test::testtools::bridgetest::XMultiBase5 >( + multi, css::uno::UNO_QUERY_THROW)->getatt1()); + checkEqual< sal_Int32 >( + 11 * 1, + css::uno::Reference< test::testtools::bridgetest::XMultiBase1 >( + multi, css::uno::UNO_QUERY_THROW)->fn11(1)); + checkEqual< sal_Int32 >( + 11 * 1, + static_cast< test::testtools::bridgetest::XMultiBase2 * >( + multi.get())->fn11(1)); + checkEqual< sal_Int32 >( + 11 * 2, + css::uno::Reference< test::testtools::bridgetest::XMultiBase2 >( + multi, css::uno::UNO_QUERY_THROW)->fn11(2)); + checkEqual< sal_Int32 >( + 11 * 1, + static_cast< test::testtools::bridgetest::XMultiBase5 * >( + multi.get())->fn11(1)); + checkEqual< sal_Int32 >( + 11 * 5, + css::uno::Reference< test::testtools::bridgetest::XMultiBase5 >( + multi, css::uno::UNO_QUERY_THROW)->fn11(5)); + checkEqual( + rtl::OUString::createFromAscii("12" "abc"), + css::uno::Reference< test::testtools::bridgetest::XMultiBase1 >( + multi, css::uno::UNO_QUERY_THROW)->fn12( + rtl::OUString::createFromAscii("abc"))); + checkEqual( + rtl::OUString::createFromAscii("12" "abc-2"), + static_cast< test::testtools::bridgetest::XMultiBase2 * >( + multi.get())->fn12(rtl::OUString::createFromAscii("abc-2"))); + checkEqual( + rtl::OUString::createFromAscii("12" "abc-2"), + css::uno::Reference< test::testtools::bridgetest::XMultiBase2 >( + multi, css::uno::UNO_QUERY_THROW)->fn12( + rtl::OUString::createFromAscii("abc-2"))); + checkEqual( + rtl::OUString::createFromAscii("12" "abc-5"), + static_cast< test::testtools::bridgetest::XMultiBase5 * >( + multi.get())->fn12(rtl::OUString::createFromAscii("abc-5"))); + checkEqual( + rtl::OUString::createFromAscii("12" "abc-5"), + css::uno::Reference< test::testtools::bridgetest::XMultiBase5 >( + multi, css::uno::UNO_QUERY_THROW)->fn12( + rtl::OUString::createFromAscii("abc-5"))); + checkEqual< sal_Int32 >(21 * 2, multi->fn21(2)); + checkEqual( + rtl::OUString::createFromAscii("22" "de"), + multi->fn22(rtl::OUString::createFromAscii("de"))); + checkEqual< sal_Int32 >( + 31 * 3, + css::uno::Reference< test::testtools::bridgetest::XMultiBase3 >( + multi, css::uno::UNO_QUERY_THROW)->fn31(3)); + checkEqual< sal_Int32 >( + 31 * 5, + static_cast< test::testtools::bridgetest::XMultiBase5 * >( + multi.get())->fn31(5)); + checkEqual< sal_Int32 >( + 31 * 5, + css::uno::Reference< test::testtools::bridgetest::XMultiBase5 >( + multi, css::uno::UNO_QUERY_THROW)->fn31(5)); + checkEqual( + 0.0, + css::uno::Reference< test::testtools::bridgetest::XMultiBase3 >( + multi, css::uno::UNO_QUERY_THROW)->getatt3()); + checkEqual( + 0.0, + static_cast< test::testtools::bridgetest::XMultiBase5 * >( + multi.get())->getatt3()); + checkEqual( + 0.0, + css::uno::Reference< test::testtools::bridgetest::XMultiBase5 >( + multi, css::uno::UNO_QUERY_THROW)->getatt3()); + css::uno::Reference< test::testtools::bridgetest::XMultiBase3 >( + multi, css::uno::UNO_QUERY_THROW)->setatt3(0.3); + checkEqual( + 0.3, + css::uno::Reference< test::testtools::bridgetest::XMultiBase3 >( + multi, css::uno::UNO_QUERY_THROW)->getatt3()); + checkEqual( + 0.3, + static_cast< test::testtools::bridgetest::XMultiBase5 * >( + multi.get())->getatt3()); + checkEqual( + 0.3, + css::uno::Reference< test::testtools::bridgetest::XMultiBase5 >( + multi, css::uno::UNO_QUERY_THROW)->getatt3()); + checkEqual( + rtl::OUString::createFromAscii("32" "f"), + css::uno::Reference< test::testtools::bridgetest::XMultiBase3 >( + multi, css::uno::UNO_QUERY_THROW)->fn32( + rtl::OUString::createFromAscii("f"))); + checkEqual( + rtl::OUString::createFromAscii("32" "f-5"), + static_cast< test::testtools::bridgetest::XMultiBase5 * >( + multi.get())->fn32(rtl::OUString::createFromAscii("f-5"))); + checkEqual( + rtl::OUString::createFromAscii("32" "f-5"), + css::uno::Reference< test::testtools::bridgetest::XMultiBase5 >( + multi, css::uno::UNO_QUERY_THROW)->fn32( + rtl::OUString::createFromAscii("f-5"))); + checkEqual< sal_Int32 >( + 33, + css::uno::Reference< test::testtools::bridgetest::XMultiBase3 >( + multi, css::uno::UNO_QUERY_THROW)->fn33()); + checkEqual< sal_Int32 >( + 33, + static_cast< test::testtools::bridgetest::XMultiBase5 * >( + multi.get())->fn33()); + checkEqual< sal_Int32 >( + 33, + css::uno::Reference< test::testtools::bridgetest::XMultiBase5 >( + multi, css::uno::UNO_QUERY_THROW)->fn33()); + checkEqual< sal_Int32 >(41 * 4, multi->fn41(4)); + checkEqual< sal_Int32 >(61 * 6, multi->fn61(6)); + checkEqual( + rtl::OUString::createFromAscii("62" ""), + multi->fn62(rtl::OUString::createFromAscii(""))); + checkEqual< sal_Int32 >(71 * 7, multi->fn71(7)); + checkEqual( + rtl::OUString::createFromAscii("72" "g"), + multi->fn72(rtl::OUString::createFromAscii("g"))); + checkEqual< sal_Int32 >(73, multi->fn73()); + } catch (CheckFailed const & f) { + return f.message; + } + return rtl::OUString(); +} + +} } diff --git a/testtools/source/bridgetest/multi.hxx b/testtools/source/bridgetest/multi.hxx new file mode 100644 index 000000000000..14af118fe7da --- /dev/null +++ b/testtools/source/bridgetest/multi.hxx @@ -0,0 +1,126 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef INCLUDED_testtools_source_bridgetest_multi_hxx +#define INCLUDED_testtools_source_bridgetest_multi_hxx + +#include "sal/config.h" + +#include "com/sun/star/uno/Reference.hxx" +#include "com/sun/star/uno/RuntimeException.hpp" +#include "cppuhelper/implbase1.hxx" +#include "rtl/ustring.hxx" +#include "sal/types.h" +#include "test/testtools/bridgetest/XMulti.hpp" + +namespace testtools { namespace bridgetest { + +class Multi: public cppu::WeakImplHelper1< test::testtools::bridgetest::XMulti > +{ +public: + Multi(): m_attribute1(0.0), m_attribute3(0.0) {} + + virtual double SAL_CALL getatt1() + throw (com::sun::star::uno::RuntimeException) + { return m_attribute1; } + + virtual void SAL_CALL setatt1(double value) + throw (com::sun::star::uno::RuntimeException) + { m_attribute1 = value; } + + virtual sal_Int32 SAL_CALL fn11(sal_Int32 arg) + throw (com::sun::star::uno::RuntimeException) + { return 11 * arg; } + + virtual rtl::OUString SAL_CALL fn12(rtl::OUString const & arg) + throw (com::sun::star::uno::RuntimeException) + { return rtl::OUString::createFromAscii("12") + arg; } + + virtual sal_Int32 SAL_CALL fn21(sal_Int32 arg) + throw (com::sun::star::uno::RuntimeException) + { return 21 * arg; } + + virtual rtl::OUString SAL_CALL fn22(rtl::OUString const & arg) + throw (com::sun::star::uno::RuntimeException) + { return rtl::OUString::createFromAscii("22") + arg; } + + virtual double SAL_CALL getatt3() + throw (com::sun::star::uno::RuntimeException) + { return m_attribute3; } + + virtual void SAL_CALL setatt3(double value) + throw (com::sun::star::uno::RuntimeException) + { m_attribute3 = value; } + + virtual sal_Int32 SAL_CALL fn31(sal_Int32 arg) + throw (com::sun::star::uno::RuntimeException) + { return 31 * arg; } + + virtual rtl::OUString SAL_CALL fn32(rtl::OUString const & arg) + throw (com::sun::star::uno::RuntimeException) + { return rtl::OUString::createFromAscii("32") + arg; } + + virtual sal_Int32 SAL_CALL fn33() + throw (com::sun::star::uno::RuntimeException) + { return 33; } + + virtual sal_Int32 SAL_CALL fn41(sal_Int32 arg) + throw (com::sun::star::uno::RuntimeException) + { return 41 * arg; } + + virtual sal_Int32 SAL_CALL fn61(sal_Int32 arg) + throw (com::sun::star::uno::RuntimeException) + { return 61 * arg; } + + virtual rtl::OUString SAL_CALL fn62(rtl::OUString const & arg) + throw (com::sun::star::uno::RuntimeException) + { return rtl::OUString::createFromAscii("62") + arg; } + + virtual sal_Int32 SAL_CALL fn71(sal_Int32 arg) + throw (com::sun::star::uno::RuntimeException) + { return 71 * arg; } + + virtual rtl::OUString SAL_CALL fn72(rtl::OUString const & arg) + throw (com::sun::star::uno::RuntimeException) + { return rtl::OUString::createFromAscii("72") + arg; } + + virtual sal_Int32 SAL_CALL fn73() + throw (com::sun::star::uno::RuntimeException) + { return 73; } + +private: + double m_attribute1; + double m_attribute3; +}; + +rtl::OUString testMulti( + com::sun::star::uno::Reference< test::testtools::bridgetest::XMulti > + const & multi); + +} } + +#endif diff --git a/testtools/source/bridgetest/pyuno/core.py b/testtools/source/bridgetest/pyuno/core.py new file mode 100644 index 000000000000..7199b5d86ca5 --- /dev/null +++ b/testtools/source/bridgetest/pyuno/core.py @@ -0,0 +1,367 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2000, 2010 Oracle and/or its affiliates. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org 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 version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* +import pyuno +import uno +import unittest +import exceptions +import types + +def suite(ctx): + suite = unittest.TestSuite() + suite.addTest(TestCase("testErrors",ctx)) + suite.addTest(TestCase("testBaseTypes",ctx)) + suite.addTest(TestCase("testOutparam",ctx)) + suite.addTest(TestCase("testStruct",ctx)) + suite.addTest(TestCase("testType",ctx)) + suite.addTest(TestCase("testEnum",ctx)) + suite.addTest(TestCase("testBool",ctx)) + suite.addTest(TestCase("testChar",ctx)) + suite.addTest(TestCase("testUnicode",ctx)) + suite.addTest(TestCase("testConstant",ctx)) + suite.addTest(TestCase("testExceptions",ctx)) + suite.addTest(TestCase("testInterface",ctx)) + suite.addTest(TestCase("testByteSequence",ctx)) + suite.addTest(TestCase("testInvoke",ctx)) + return suite + +def equalsEps( a,b,eps ): + if a - eps <= b and a+eps >= b: + return 1 + return 0 + +def assign( rData, bBool, cChar, nByte, nShort, nUShort, nLong, nULong, nHyper,\ + nUHyper, fFloat, fDouble, eEnum, rStr, xTest, 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; + + +class PythonTransporter: + def __init__( self ): + pass + + def transportAny( self, arg ): + return arg + +class TestCase( unittest.TestCase): + + def __init__(self,method,ctx): + unittest.TestCase.__init__(self,method) + self.ctx = ctx + + def setUp(self): + # the testcomponent from the testtools project + self.tobj = self.ctx.ServiceManager.createInstanceWithContext( + 'com.sun.star.test.bridge.CppTestObject' , self.ctx ) + + self.tobj.Bool = 1 + self.tobj.Char = 'h' + self.tobj.Byte = 43 + self.tobj.Short = -42 + self.tobj.UShort = 44 + self.tobj.Long = 42 + self.tobj.ULong = 41 + self.tobj.Hyper = 46 + self.tobj.UHyper = 47 + self.tobj.Float = 4.3 + self.tobj.Double = 4.2 + self.tobj.Enum = 4 + self.tobj.String = "yabadabadoo" + self.tobj.Interface = self.ctx + self.tobj.Any = self.tobj.String + mystruct = uno.createUnoStruct( "test.testtools.bridgetest.TestData" ) + assign( mystruct, 1, 'h', 43, -42,44,42,41,46,47,4.3,4.2,4,"yabadabadoo",self.ctx,"yabadabadoo") + self.tobj.Struct = mystruct + + self.testElement = uno.createUnoStruct( "test.testtools.bridgetest.TestElement" ) + self.testElement.String = "foo" + self.testElement2 = uno.createUnoStruct( "test.testtools.bridgetest.TestElement" ) + self.testElement2.String = "42" + self.tobj.Sequence = (self.testElement,self.testElement2) + + def testBaseTypes(self): + self.failUnless( 42 == self.tobj.Long , "Long attribute" ) + self.failUnless( 41 == self.tobj.ULong , "ULong attribute" ) + self.failUnless( 43 == self.tobj.Byte , "Byte attribute" ) + self.failUnless( 44 == self.tobj.UShort , "UShort attribute" ) + self.failUnless( -42 == self.tobj.Short , "Short attribute" ) + self.failUnless( 46 == self.tobj.Hyper , "Hyper attribute" ) + self.failUnless( 47 == self.tobj.UHyper , "UHyper attribute" ) + self.failUnless( self.tobj.Bool , "Bool attribute2" ) + self.failUnless( "yabadabadoo" == self.tobj.String , "String attribute" ) + self.failUnless( self.tobj.Sequence[0] == self.testElement , "Sequence test") + self.failUnless( self.tobj.Sequence[1] == self.testElement2 , "Sequence2 test") + self.failUnless( equalsEps( 4.3,self.tobj.Float,0.0001) , "float test" ) + self.failUnless( 4.2 == self.tobj.Double , "double test" ) + self.failUnless( self.ctx == self.tobj.Interface , + "object identity test with C++ object" ) + self.failUnless( not self.ctx == self.tobj , "object not identical test " ) + self.failUnless( 42 == self.tobj.transportAny( 42 ), "transportAny long" ) + self.failUnless( "woo, this is python" == self.tobj.transportAny( "woo, this is python" ), \ + "string roundtrip via any test" ) + + def testEnum( self ): + e1 = uno.Enum( "com.sun.star.uno.TypeClass" , "LONG" ) + e2 = uno.Enum( "com.sun.star.uno.TypeClass" , "LONG" ) + e3 = uno.Enum( "com.sun.star.uno.TypeClass" , "UNSIGNED_LONG" ) + e4 = uno.Enum( "test.testtools.bridgetest.TestEnum" , "TWO" ) + self.failUnless( e1 == e2 , "equal enum test" ) + self.failUnless( not (e1 == e3) , "different enums test" ) + self.failUnless( self.tobj.transportAny( e3 ) == e3, "enum roundtrip test" ) + self.tobj.Enum = e4 + self.failUnless( e4 == self.tobj.Enum , "enum assignment failed" ) + + def testType(self ): + t1 = uno.getTypeByName( "com.sun.star.lang.XComponent" ) + t2 = uno.getTypeByName( "com.sun.star.lang.XComponent" ) + t3 = uno.getTypeByName( "com.sun.star.lang.EventObject" ) + self.failUnless( t1.typeClass == \ + uno.Enum( "com.sun.star.uno.TypeClass", "INTERFACE" ), "typeclass of type test" ) + self.failUnless( t3.typeClass == \ + uno.Enum( "com.sun.star.uno.TypeClass", "STRUCT" ), "typeclass of type test") + self.failUnless( t1 == t2 , "equal type test" ) + self.failUnless( t1 == t2 , "equal type test" ) + self.failUnless( t1 == self.tobj.transportAny( t1 ), "type rountrip test" ) + + def testBool( self ): + self.failUnless( uno.Bool(1) , "uno.Bool true test" ) + self.failUnless( not uno.Bool(0) , "uno.Bool false test" ) + self.failUnless( uno.Bool( "true") , "uno.Bool true1 test" ) + self.failUnless( not uno.Bool( "false") , "uno.Bool true1 test" ) + + self.tobj.Bool = uno.Bool(1) + self.failUnless( self.tobj.Bool , "bool true attribute test" ) + self.tobj.Bool = uno.Bool(0) + self.failUnless( not self.tobj.Bool , "bool true attribute test" ) + + # new boolean semantic + self.failUnless( id( self.tobj.transportAny( True ) ) == id(True) , "boolean preserve test") + self.failUnless( id( self.tobj.transportAny( False ) ) == id(False) , "boolean preserve test" ) + self.failUnless( id( self.tobj.transportAny(1) ) != id( True ), "boolean preserve test" ) + self.failUnless( id( self.tobj.transportAny(0) ) != id( False ), "boolean preserve test" ) + + def testChar( self ): + self.tobj.Char = uno.Char( u'h' ) + self.failUnless( self.tobj.Char == uno.Char( u'h' ), "char type test" ) + self.failUnless( isinstance( self.tobj.transportAny( uno.Char(u'h') ),uno.Char),"char preserve test" ) + + def testStruct( self ): + mystruct = uno.createUnoStruct( "test.testtools.bridgetest.TestData" ) + assign( mystruct, 1, 'h', 43, -42,44,42,41,46,47,4.3,4.2,4,"yabadabadoo",self.ctx,"yabadabadoo") + self.tobj.Struct = mystruct + aSecondStruct = self.tobj.Struct + + self.failUnless( self.tobj.Struct == mystruct, "struct roundtrip for equality test" ) + self.failUnless( aSecondStruct == mystruct, "struct roundtrip for equality test2" ) + aSecondStruct.Short = 720 + self.failUnless( not aSecondStruct == mystruct , "different structs equality test" ) + self.failUnless( not self.ctx == mystruct , "object is not equal to struct test" ) + self.failUnless( mystruct == self.tobj.transportAny( mystruct ), "struct roundtrip with any test" ) + my2ndstruct = uno.createUnoStruct( "test.testtools.bridgetest.TestData", \ + 1, 'h', 43, -42,44,42,41,46,47,4.3,4.2,4,"yabadabadoo",self.ctx,"yabadabadoo",()) + self.failUnless( my2ndstruct == mystruct, "struct non-default ctor test" ) + def testUnicode( self ): + uni = u'\0148' + self.tobj.String = uni + self.failUnless( uni == self.tobj.String ) + + + self.tobj.String = u'dubidu' + self.failUnless( u'dubidu' == self.tobj.String , "unicode comparison test") + self.failUnless( 'dubidu' == self.tobj.String , "unicode vs. string comparison test" ) + + def testConstant( self ): + self.failUnless( uno.getConstantByName( "com.sun.star.beans.PropertyConcept.ATTRIBUTES" ) == 4,\ + "constant retrieval test" ) + + def testExceptions( self ): + unoExc = uno.getClass( "com.sun.star.uno.Exception" ) + ioExc = uno.getClass( "com.sun.star.io.IOException" ) + dispExc = uno.getClass( "com.sun.star.lang.DisposedException" ) + wasHere = 0 + try: + raise ioExc( "huhuh" , self.tobj ) + except unoExc , instance: + wasHere = 1 + self.failUnless( wasHere , "exceptiont test 1" ) + + wasHere = 0 + try: + raise ioExc + except ioExc: + wasHere = 1 + else: + self.failUnless( wasHere, "exception test 2" ) + + wasHere = 0 + try: + raise dispExc + except ioExc: + pass + except unoExc: + wasHere = 1 + self.failUnless(wasHere, "exception test 3") + + illegalArg = uno.getClass( "com.sun.star.lang.IllegalArgumentException" ) + wasHere = 0 + try: + self.tobj.raiseException( 1 , "foo" , self.tobj ) + self.failUnless( 0 , "exception test 5a" ) + except ioExc: + self.failUnless( 0 , "exception test 5b" ) + except illegalArg, i: + self.failUnless( 1 == i.ArgumentPosition , "exception member test" ) + self.failUnless( "foo" == i.Message , "exception member test 2 " ) + wasHere = 1 + else: + self.failUnless( 0, "except test 5c" ) + self.failUnless( wasHere, "illegal argument exception test failed" ) + + def testInterface(self): + clazz = uno.getClass( "com.sun.star.lang.XComponent" ) + self.failUnless( "com.sun.star.lang.XComponent" == clazz.__pyunointerface__ ) + self.failUnless( issubclass( clazz, uno.getClass( "com.sun.star.uno.XInterface" ) ) ) + self.tobj.Interface = None + + + def testOutparam( self): + # outparameter + struct, mybool,mychar,mybyte,myshort,myushort,mylong,myulong,myhyper,myuhyper,myfloat, \ + mydouble,myenum,mystring,myinterface,myany,myseq,my2ndstruct = self.tobj.getValues( \ + None,None,None,None,None,None,None,None,None,None, \ + None,None,None,None,None,None,None) + self.failUnless(struct == self.tobj.Struct, "outparam 1 test") + self.failUnless(self.tobj.Bool, "outparam 2 test") + self.failUnless(mychar == self.tobj.Char, "outparam 3 test") + self.failUnless(mybyte == self.tobj.Byte, "outparam 4 test") + self.failUnless(myshort == self.tobj.Short, "outparam 5 test") + self.failUnless(myushort == self.tobj.UShort, "outparam 6 test") + self.failUnless(mylong == self.tobj.Long, "outparam 7 test") + self.failUnless(myulong == self.tobj.ULong, "outparam 8 test") + self.failUnless(myhyper == self.tobj.Hyper, "outparam 9 test") + self.failUnless(myuhyper == self.tobj.UHyper, "outparam 10 test") + self.failUnless(myfloat == self.tobj.Float, "outparam 11 test") + self.failUnless(mydouble == self.tobj.Double, "outparam 12 test") + self.failUnless(myenum == self.tobj.Enum, "outparam 13 test") + self.failUnless(mystring == self.tobj.String, "outparam 14 test") + self.failUnless(myinterface == self.tobj.Interface, "outparam 15 test") + self.failUnless(myany == self.tobj.Any, "outparam 16 test") + self.failUnless(myseq == self.tobj.Sequence, "outparam 17 test") + self.failUnless(my2ndstruct == struct, "outparam 18 test") + +# should work, debug on windows, why not +# struct, mybool,mychar,mybyte,myshort,myushort,mylong,myulong,myhyper,myuhyper,myfloat,\ +# mydouble,myenum,mystring,myinterface,myany,myseq,my2ndstruct = self.tobj.setValues2( \ +# mybool,mychar,mybyte,myshort,myushort,mylong,myulong,myhyper,myuhyper,myfloat,\ +# mydouble,myenum,mystring,myinterface,myany,myseq,my2ndstruct) +# self.failUnless(struct == self.tobj.Struct, "outparam 1 test") +# self.failUnless( mybool and self.tobj.Bool, "outparam 2 test") +# self.failUnless(mychar == self.tobj.Char, "outparam 3 test") +# self.failUnless(mybyte == self.tobj.Byte, "outparam 4 test") +# self.failUnless(myshort == self.tobj.Short, "outparam 5 test") +# self.failUnless(myushort == self.tobj.UShort, "outparam 6 test") +# self.failUnless(mylong == self.tobj.Long, "outparam 7 test") +# self.failUnless(myulong == self.tobj.ULong, "outparam 8 test") +# self.failUnless(myhyper == self.tobj.Hyper, "outparam 9 test") +# self.failUnless(myuhyper == self.tobj.UHyper, "outparam 10 test") +# self.failUnless(myfloat == self.tobj.Float, "outparam 11 test") +# self.failUnless(mydouble == self.tobj.Double, "outparam 12 test") +# self.failUnless(myenum == self.tobj.Enum, "outparam 13 test") +# self.failUnless(mystring == self.tobj.String, "outparam 14 test") +# self.failUnless(myinterface == self.tobj.Interface, "outparam 15 test") +# self.failUnless(myany == self.tobj.Any, "outparam 16 test") +# self.failUnless(myseq == self.tobj.Sequence, "outparam 17 test") +# self.failUnless(my2ndstruct == struct, "outparam 18 test") + + def testErrors( self ): + + wasHere = 0 + try: + self.tobj.a = 5 + self.fail("attribute a shouldn't exist") + except AttributeError: + wasHere = 1 + except IllegalArgumentException: + wasHere = 1 + self.failUnless( wasHere, "wrong attribute test" ) + + IllegalArgumentException = uno.getClass("com.sun.star.lang.IllegalArgumentException" ) + RuntimeException = uno.getClass("com.sun.star.uno.RuntimeException" ) + +# TODO: Remove this once it is done +# wrong number of arguments bug !? + self.failUnlessRaises( IllegalArgumentException, self.tobj.transportAny, 42, 43 ) + self.failUnlessRaises( IllegalArgumentException, self.tobj.transportAny ) + self.failUnlessRaises( RuntimeException, uno.getClass, "a.b" ) + self.failUnlessRaises( RuntimeException, uno.getClass, "com.sun.star.uno.TypeClass" ) + + self.failUnlessRaises( RuntimeException, uno.Enum, "a" , "b" ) + self.failUnlessRaises( RuntimeException, uno.Enum, "com.sun.star.uno.TypeClass" , "b" ) + self.failUnlessRaises( RuntimeException, uno.Enum, "com.sun.star.uno.XInterface" , "b" ) + + tcInterface =uno.Enum( "com.sun.star.uno.TypeClass" , "INTERFACE" ) + self.failUnlessRaises( RuntimeException, uno.Type, "a", tcInterface ) + self.failUnlessRaises( RuntimeException, uno.Type, "com.sun.star.uno.Exception", tcInterface ) + + self.failUnlessRaises( (RuntimeException,exceptions.RuntimeError), uno.getTypeByName, "a" ) + + self.failUnlessRaises( (RuntimeException), uno.getConstantByName, "a" ) + self.failUnlessRaises( (RuntimeException), uno.getConstantByName, "com.sun.star.uno.XInterface" ) + + def testByteSequence( self ): + s = uno.ByteSequence( "ab" ) + self.failUnless( s == uno.ByteSequence( "ab" ) ) + self.failUnless( uno.ByteSequence( "abc" ) == s + uno.ByteSequence( "c" ) ) + self.failUnless( uno.ByteSequence( "abc" ) == s + "c" ) + self.failUnless( s + "c" == "abc" ) + self.failUnless( s == uno.ByteSequence( s ) ) + self.failUnless( s[0] == 'a' ) + self.failUnless( s[1] == 'b' ) + + + def testInvoke( self ): + self.failUnless( 5 == uno.invoke( self.tobj , "transportAny" , (uno.Any("byte", 5),) ) ) + self.failUnless( 5 == uno.invoke( + PythonTransporter(), "transportAny" , (uno.Any( "byte", 5 ),) ) ) + t = uno.getTypeByName( "long" ) + mystruct = uno.createUnoStruct( + "com.sun.star.beans.PropertyValue", "foo",0,uno.Any(t,2),0 ) + mystruct.Value = uno.Any(t, 1) + + diff --git a/testtools/source/bridgetest/pyuno/impl.py b/testtools/source/bridgetest/pyuno/impl.py new file mode 100644 index 000000000000..1b37921aa3ba --- /dev/null +++ b/testtools/source/bridgetest/pyuno/impl.py @@ -0,0 +1,196 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2000, 2010 Oracle and/or its affiliates. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org 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 version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* +"tests bridging python implementations of UNO objects" +import unittest +import uno +import unohelper +import os +import sys + +from com.sun.star.io import XOutputStream, XInputStream, typeOfXOutputStream, typeOfXInputStream +from com.sun.star.lang import XTypeProvider, typeOfXTypeProvider, XEventListener +from com.sun.star.uno import XCurrentContext + +class SequenceOutputStream( unohelper.Base, XOutputStream ): + def __init__( self ): + self.s = uno.ByteSequence("") + self.closed = 0 + + def closeOutput(self): + self.closed = 1 + + def writeBytes( self, seq ): + self.s = self.s + seq + + def flush( self ): + pass + + def getSequence( self ): + return self.s + + +class SequenceInputStream( XInputStream, unohelper.Base ): + def __init__( self, seq ): + self.s = seq + self.nIndex = 0 + self.closed = 0 + + def closeInput( self): + self.closed = 1 + self.s = None + + def skipBytes( self, nByteCount ): + if( nByteCount + self.nIndex > len(self.s) ): + nByteCount = len(self.s) - self.nIndex + self.nIndex += nByteCount + + def readBytes( self, retSeq, nByteCount ): + nRet = 0 + if( self.nIndex + nByteCount > len(self.s) ): + nRet = len(self.s) - self.nIndex + else: + nRet = nByteCount + retSeq = uno.ByteSequence(self.s.value[self.nIndex : self.nIndex + nRet ]) + self.nIndex = self.nIndex + nRet + return nRet, retSeq + + def readSomeBytes( self, retSeq , nByteCount ): + #as we never block ! + return readBytes( retSeq, nByteCount ) + + def available( self ): + return len( self.s ) - self.nIndex + +class SequenceInputStream2( SequenceInputStream ): + def __init__( self, seq ): + SequenceInputStream.__init__( self, seq ) + +class TestCase(unittest.TestCase): + def __init__(self,method,ctx): + unittest.TestCase.__init__(self,method) + self.ctx = ctx + + def setUp(self): + self.tobj = self.ctx.ServiceManager.createInstanceWithContext( \ + "com.sun.star.test.bridge.CppTestObject",self.ctx) + self.pipe = self.ctx.ServiceManager.createInstanceWithContext( \ + "com.sun.star.io.Pipe" , self.ctx ) + + def testStandard( self ): + dataOut = self.ctx.ServiceManager.createInstanceWithContext( \ + "com.sun.star.io.DataOutputStream", self.ctx ) + streamOut = SequenceOutputStream() + dataOut.setOutputStream( streamOut ) + dataOut.writeShort( 42 ) + dataOut.writeLong( 43 ) + dataOut.closeOutput() + + dataInput = self.ctx.ServiceManager.createInstanceWithContext( \ + "com.sun.star.io.DataInputStream", self.ctx ) + + dataInput.setInputStream( SequenceInputStream2( streamOut.getSequence() ) ) + + self.failUnless( 42 == dataInput.readShort() ) + self.failUnless( 43 == dataInput.readLong() ) + self.failUnless( self.tobj.transportAny( streamOut ) == streamOut ) + + +class NullDevice: + def write( self, string ): + pass + + +class EventListener( unohelper.Base, XEventListener ): + def __init__( self ): + self.disposingCalled = False + + def disposing( self , eventObject ): + self.disposingCalled = True + +class TestHelperCase( unittest.TestCase ): + + def __init__(self,method): + unittest.TestCase.__init__(self,method) + + def testUrlHelper( self ): + systemPath = os.getcwd() + if systemPath.startswith( "/" ): + self.failUnless( "/tmp" == unohelper.fileUrlToSystemPath( "file:///tmp" ) ) + self.failUnless( "file:///tmp" == unohelper.systemPathToFileUrl( "/tmp" )) + else: + self.failUnless( "c:\\temp" == unohelper.fileUrlToSystemPath( "file:///c:/temp" ) ) + self.failUnless( "file:///c:/temp" == unohelper.systemPathToFileUrl( "c:\\temp" ) ) + + systemPath = unohelper.systemPathToFileUrl( systemPath ) + self.failUnless( systemPath + "/a" == unohelper.absolutize( systemPath, "a" ) ) + def testInspect( self ): + dev = NullDevice() +# dev = sys.stdout + unohelper.inspect( uno.getComponentContext() , dev ) + unohelper.inspect( uno.getComponentContext().ServiceManager , dev ) + unohelper.inspect( uno.getTypeByName( "com.sun.star.lang.XComponent" ) , dev ) + + def testListener( self ): + smgr = uno.getComponentContext().ServiceManager.createInstance( + "com.sun.star.lang.ServiceManager" ) + + # check, whether listeners + listener = EventListener() + smgr.addEventListener( listener ) + smgr.dispose() + self.failUnless( listener.disposingCalled ) + + # check, whether listeners can be removed + smgr = uno.getComponentContext().ServiceManager.createInstance( + "com.sun.star.lang.ServiceManager" ) + listener = EventListener() + smgr.addEventListener( listener ) + smgr.removeEventListener( listener ) + smgr.dispose() + self.failUnless( not listener.disposingCalled ) + + def testCurrentContext( self ): + oldContext = uno.getCurrentContext() + try: + uno.setCurrentContext( + unohelper.CurrentContext( oldContext,{"My42":42}) ) + self.failUnless( 42 == uno.getCurrentContext().getValueByName( "My42" ) ) + self.failUnless( None == uno.getCurrentContext().getValueByName( "My43" ) ) + finally: + uno.setCurrentContext( oldContext ) + + + +def suite( ctx ): + suite = unittest.TestSuite() + suite.addTest(TestCase("testStandard",ctx)) + suite.addTest(TestHelperCase( "testUrlHelper" )) + suite.addTest(TestHelperCase( "testInspect" )) + suite.addTest(TestHelperCase( "testListener" ) ) + suite.addTest(TestHelperCase( "testCurrentContext" ) ) + return suite + diff --git a/testtools/source/bridgetest/pyuno/importer.py b/testtools/source/bridgetest/pyuno/importer.py new file mode 100644 index 000000000000..540cbb12a47b --- /dev/null +++ b/testtools/source/bridgetest/pyuno/importer.py @@ -0,0 +1,78 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2000, 2010 Oracle and/or its affiliates. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org 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 version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* +import unittest +import uno +import unohelper + +from com.sun.star.lang import EventObject,IllegalArgumentException,typeOfIllegalArgumentException +from test.testtools.bridgetest.TestEnum import TWO +from com.sun.star.uno.TypeClass import UNSIGNED_LONG,EXCEPTION +class ImporterTestCase(unittest.TestCase): + def __init__(self,method,ctx): + unittest.TestCase.__init__(self,method) + self.ctx = ctx + + def setUp(self): + self.tobj = self.ctx.ServiceManager.createInstanceWithContext( \ + "com.sun.star.test.bridge.CppTestObject",self.ctx) + + def testStandard( self ): + self.failUnless( IllegalArgumentException != None, "none-test" ) + self.failUnlessRaises( IllegalArgumentException, self.tobj.raiseException, 1,"foo",self.tobj) + + self.failUnless( TWO == uno.Enum( "test.testtools.bridgetest.TestEnum","TWO"), "enum" ) + self.failUnless( UNSIGNED_LONG == uno.Enum( "com.sun.star.uno.TypeClass", "UNSIGNED_LONG" ) ) + self.failUnless( typeOfIllegalArgumentException == + uno.Type( "com.sun.star.lang.IllegalArgumentException", EXCEPTION) ) + + # should not throw an exception + e = EventObject() + e.Source = self.ctx + e = EventObject( self.ctx ) + e = EventObject( e ) + + def testDynamicComponentRegistration( self ): + ctx = uno.getComponentContext() + self.failUnless( + not ("com.sun.star.connection.Acceptor" in ctx.ServiceManager.getAvailableServiceNames()), + "precondition for dynamic component registration test is not fulfilled" ) + self.failUnless( + not ("com.sun.star.connection.Connector" in ctx.ServiceManager.getAvailableServiceNames()), + "precondition for dynamic component registration test is not fulfilled" ) + unohelper.addComponentsToContext( + ctx , ctx, ("acceptor.uno","connector.uno"), "com.sun.star.loader.SharedLibrary" ) + self.failUnless( + ("com.sun.star.connection.Acceptor" in ctx.ServiceManager.getAvailableServiceNames()) ) + self.failUnless( + ("com.sun.star.connection.Connector" in ctx.ServiceManager.getAvailableServiceNames())) + +def suite( ctx ): + suite = unittest.TestSuite() + suite.addTest(ImporterTestCase("testStandard",ctx)) + suite.addTest(ImporterTestCase("testDynamicComponentRegistration",ctx)) + return suite + diff --git a/testtools/source/bridgetest/pyuno/main.py b/testtools/source/bridgetest/pyuno/main.py new file mode 100644 index 000000000000..835109f1f89a --- /dev/null +++ b/testtools/source/bridgetest/pyuno/main.py @@ -0,0 +1,49 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2000, 2010 Oracle and/or its affiliates. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org 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 version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* +import uno +import unohelper +import importer +import unittest +import core +import impl +import os +import sys + +ctx = uno.getComponentContext() +# needed for the tests +unohelper.addComponentsToContext(ctx,ctx,(os.environ["FOO"]+"/cppobj.uno",os.environ["FOO"]+"/bridgetest.uno","streams.uno","bootstrap.uno"),"com.sun.star.loader.SharedLibrary") + +unohelper.addComponentsToContext(ctx,ctx,("vnd.openoffice.pymodule:samplecomponent",),"com.sun.star.loader.Python") + +runner = unittest.TextTestRunner(sys.stderr,1,2) + +suite = unittest.TestSuite() +suite.addTest(importer.suite(ctx)) +suite.addTest(core.suite(ctx)) +suite.addTest(impl.suite(ctx)) + +runner.run(suite) diff --git a/testtools/source/bridgetest/pyuno/makefile.mk b/testtools/source/bridgetest/pyuno/makefile.mk new file mode 100644 index 000000000000..fb7a78f71f4a --- /dev/null +++ b/testtools/source/bridgetest/pyuno/makefile.mk @@ -0,0 +1,108 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2000, 2010 Oracle and/or its affiliates. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org 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 version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* + +PRJ=..$/..$/.. + +PRJNAME=pyuno +TARGET=test +LIBTARGET=NO +TARGETTYPE=CUI +ENABLE_EXCEPTIONS=TRUE + +# --- Settings ----------------------------------------------------- + +.INCLUDE : settings.mk +# --- Files -------------------------------------------------------- +.IF "$(L10N_framework)"=="" +PYEXC=$(DLLDEST)$/python$(EXECPOST) +REGEXC=$(DLLDEST)$/regcomp$(EXECPOST) + +.IF "$(SYSTEM_PYTHON)"!="YES" +PYTHON=$(AUGMENT_LIBRARY_PATH) $(WRAPCMD) $(SOLARBINDIR)/python +.ELSE # "$(SYSTEM_PYTHON)"!="YES" +PYTHON=$(AUGMENT_LIBRARY_PATH) $(WRAPCMD) python +.ENDIF # "$(SYSTEM_PYTHON)"!="YES" +.IF "$(GUI)"=="WNT" +PYTHONPATH:=$(SOLARLIBDIR)$/pyuno;$(PWD);$(SOLARLIBDIR);$(SOLARLIBDIR)$/python;$(SOLARLIBDIR)$/python$/lib-dynload +.ELSE # "$(GUI)"=="WNT" +PYTHONPATH:=$(SOLARLIBDIR)$/pyuno:$(PWD):$(SOLARLIBDIR):$(SOLARLIBDIR)$/python:$(SOLARLIBDIR)$/python$/lib-dynload +.ENDIF # "$(GUI)"=="WNT" +.EXPORT: PYTHONPATH + +.IF "$(GUI)"!="WNT" && "$(GUI)"!="OS2" +TEST_ENV=export FOO=file://$(shell @pwd)$/$(DLLDEST) \ + UNO_TYPES=pyuno_regcomp.rdb UNO_SERVICES=pyuno_regcomp.rdb +.ELSE # "$(GUI)" != "WNT" +# aaaaaa, how to get the current working directory on windows ??? +CWD_TMP=$(strip $(shell @echo "import os;print os.getcwd()" | $(PYTHON))) +TEST_ENV=export FOO=file:///$(strip $(subst,\,/ $(CWD_TMP)$/$(DLLDEST))) && \ + export UNO_TYPES=pyuno_regcomp.rdb && export UNO_SERVICES=pyuno_regcomp.rdb +.ENDIF # "$(GUI)"!="WNT" +PYFILES = \ + $(DLLDEST)$/core.py \ + $(DLLDEST)$/importer.py \ + $(DLLDEST)$/main.py \ + $(DLLDEST)$/impl.py \ + $(DLLDEST)$/samplecomponent.py \ + $(DLLDEST)$/testcomp.py \ + +PYCOMPONENTS = \ + samplecomponent + +ALL : \ + $(PYFILES) \ + $(DLLDEST)$/pyuno_regcomp.rdb \ + doc \ + ALLTAR +.ENDIF # L10N_framework + +.INCLUDE : target.mk +.IF "$(L10N_framework)"=="" +$(DLLDEST)$/%.py: %.py + cp $? $@ + +$(DLLDEST)$/python$(EXECPOST) : $(SOLARBINDIR)$/python$(EXECPOST) + cp $? $@ + +$(DLLDEST)$/regcomp$(EXECPOST) : $(SOLARBINDIR)$/regcomp$(EXECPOST) + cp $? $@ + +$(DLLDEST)$/pyuno_regcomp.rdb: $(DLLDEST)$/uno_types.rdb $(SOLARBINDIR)$/pyuno_services.rdb + -rm -f $@ + $(WRAPCMD) $(REGMERGE) $(DLLDEST)$/pyuno_regcomp.rdb / $(DLLDEST)$/uno_types.rdb $(SOLARBINDIR)$/pyuno_services.rdb + +doc .PHONY: + @echo start test with dmake runtest + +runtest : ALL + cd $(DLLDEST) && $(TEST_ENV) && $(PYTHON) main.py + cd $(DLLDEST) && $(TEST_ENV) && $(WRAPCMD) $(REGCOMP) -register -br pyuno_regcomp.rdb -r dummy.rdb \ + -l com.sun.star.loader.Python $(foreach,i,$(PYCOMPONENTS) -c vnd.openoffice.pymodule:$(i)) + cd $(DLLDEST) && $(TEST_ENV) && $(WRAPCMD) $(REGCOMP) -register -br pyuno_regcomp.rdb -r dummy2.rdb \ + -l com.sun.star.loader.Python -c vnd.sun.star.expand:$$FOO/samplecomponent.py +.ENDIF # L10N_framework + diff --git a/testtools/source/bridgetest/pyuno/pyuno b/testtools/source/bridgetest/pyuno/pyuno new file mode 100644 index 000000000000..cf2da2cad60a --- /dev/null +++ b/testtools/source/bridgetest/pyuno/pyuno @@ -0,0 +1,2 @@ +UNO_TYPES=uno_types.rdb +UNO_SERVICES=pyuno_services.rdb diff --git a/testtools/source/bridgetest/pyuno/samplecomponent.py b/testtools/source/bridgetest/pyuno/samplecomponent.py new file mode 100644 index 000000000000..6d378008de8d --- /dev/null +++ b/testtools/source/bridgetest/pyuno/samplecomponent.py @@ -0,0 +1,154 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2000, 2010 Oracle and/or its affiliates. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org 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 version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* +import uno +import unohelper + +from com.sun.star.lang import IllegalArgumentException,XServiceInfo +from com.sun.star.uno import RuntimeException +from com.sun.star.beans import UnknownPropertyException +from test.testtools.bridgetest import TestData,XRecursiveCall,XBridgeTestBase + +g_ImplementationHelper = unohelper.ImplementationHelper() +g_implName = "org.openoffice.comp.pyuno.PythonTestObject" + +g_attribs = "RuntimeException", "Bool", "Char", "Byte", "Short", "UShort", \ + "Long", "ULong", "Hyper", "UHyper", "Float", "Double", "Enum", \ + "String", "Interface", "Any" , "Sequence" , "Struct" + +def assign( rData, bBool, cChar, nByte, nShort, nUShort, nLong, nULong, nHyper,\ + nUHyper, fFloat, fDouble, eEnum, rStr, xTest, 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; + +class MyRecursiveCall( XRecursiveCall, unohelper.Base ): + def callRecursivly( xCall, nToCall ): + if nToCall: + xCall.callRecursivly( self, nToCall -1 ) + +class SampleUnoComponent( XBridgeTestBase,XServiceInfo ): + def __init__(self,ctx): + self.__dict__["callid"] = 0 + self.__dict__["sequenceBroken"] = 0 + + def transportAny( self, value ): + return value + + def raiseException( self, ArgumentPosition, Message, Context ): + raise IllegalArgumentException( Message, Context, ArgumentPosition ) + + def raiseRuntimeExceptionOneway(self, Message, Context ): + raise RuntimeException( Message, Context ) + + def setValues( self, bBool, cChar, nByte, nShort, nUShort, nLong,\ + nULong, nHyper, nUHyper, fFloat, fDouble, eEnum, \ + aString, xInterface, aAny, aSequence, aStruct ): + self.__dict__["data"] = TestDataElements( bBool, cChar, nByte, nShort, nUShort, nLong, + nULong, nHyper, nUHyper, fFloat, fDouble, eEnum, aStruct, xInterface, + aAny, aSequence ) + self.__dict__["Struct"] = aStruct + + def setValues2( self, bBool, cChar, nByte, nShort, nUShort, nLong, nULong,\ + nHyper, nUHyper, fFloat, fDouble, eEnum, \ + aString, xInterface, aAny, aSequence, aStruct ): + self.__dict__["Struct"] = TestData( cChar, nByte, nShort, nUShort, nLong, nULong, nHyper,\ + nUHyper, fFloat, fDouble, eEnum, aStruct, xInterface,\ + aAny, aSequence ) + self.__dict__["Struct"] = aStruct + return bBool, cChar, nByte, nShort, nUShort, nLong, nULong, nHyper, nUHyper, nULong, \ + nHyper, nUHyper, fFloat, fDouble, eEnum, aStruct, xInterface, aAny, \ + (aSequence[1],aSequence[0]), aStruct + + def getValues(self, a,b,c,d,e,f,g,h, i,j,k,l,m,n): + v = self.__dict__["data"] + return self.__dict__["Struct"],v.Bool, v.Char, v.Byte, v.Short, v.UShort, v.Long, \ + v.ULong, v.Hyper, v.UHyper, v.Float, v.Double, v.Enum, v.String, v.Interface, \ + v.Any, v.Sequence, self.__dict__["Struct"] + + def call( self, callid, nWaitMUSEC ): + if self.__dict__["callid"] >= callid: + self.__dict__["sequenceBroken"] = 1 + else: + self.__dict__["callid"] = callid + + def callOneway( self, nCallId, nWaitMUSEC ): + call( nCallId, nWaitMUSEC ) + + def sequenceOfCallTestPassed(): + return self.__dict__["sequenceBroken"] + + def startRecursiveCall( xCall , nToCall ): + if nToCall: + xCall.callRecursivly( MyRecursiveCall(), nToCall -1 ) + + def checkExistence( self, name ): + found = 0 + for x in g_attribs: + if x == name: + found = 1 + break + if not found: + raise UnknownPropertyException( "Property "+name+" is unknown", self ) + + def __setattr__( self, name, value ): + checkExistence( name ) + self.__dict__[name] = value + + def __getattr__( self, name ): + checkExistence( name ) + return self.__dict__[name] + + def getSupportedServices( self ): + return g_ImplementationHelper.getSupportedServices(g_implName) + def supportsService( self, ServiceName ): + return g_ImplementationHelper.supportsService( g_implName, ServiceName ) + def getImplementationName(self): + return g_implName + + +g_ImplementationHelper.addImplementation( \ + SampleUnoComponent,g_implName,("com.sun.star.test.bridge.PythonTestObject",),) + +#g_ImplementationEntries = \ +# unohelper.ImplementationEntry( \ +# "org.openoffice.comp.SamplePythonComponent", \ +# ("com.sun.star.test.bridge.PythonTestObject",), \ +# SampleUnoComponent) \ +# , + diff --git a/testtools/source/bridgetest/pyuno/testcomp.py b/testtools/source/bridgetest/pyuno/testcomp.py new file mode 100644 index 000000000000..14521cf5d342 --- /dev/null +++ b/testtools/source/bridgetest/pyuno/testcomp.py @@ -0,0 +1,40 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2000, 2010 Oracle and/or its affiliates. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org 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 version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* +import uno +import pythonloader + +ctx = uno.getComponentContext() + +loader = pythonloader.Loader( ctx ) +comp = loader.activate( "org.openoffice.comp.pyuno.PythonTestObject" , "", "samplecomponent", ctx ) +ctx.ServiceManager.insert( comp) + +bridgetest = ctx.ServiceManager.createInstanceWithContext( "com.sun.star.test.bridge.BridgeTest", ctx ) +#bridgetest.run( "com.sun.star.test.bridge.PythonTestObject" ) + + + diff --git a/testtools/source/cliversioning/makefile.mk b/testtools/source/cliversioning/makefile.mk new file mode 100644 index 000000000000..57971b47984f --- /dev/null +++ b/testtools/source/cliversioning/makefile.mk @@ -0,0 +1,142 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2000, 2010 Oracle and/or its affiliates. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org 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 version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +# ************************************************************************/ + + +# Builds the SpreadSheet examples of the Developers Guide. + +PRJ = ..$/.. +PRJNAME = cli_ure +TARGET := test_climaker +PACKAGE = cliversion + +.INCLUDE: settings.mk +.INCLUDE : $(PRJ)$/util$/makefile.pmk + +#.IF "$(BUILD_FOR_CLI)" == "" + +.IF "$(debug)" != "" +CSCFLAGS += -checked+ -define:DEBUG -define:TRACE -debug+ +.ELSE +CSCFLAGS += -optimize+ +.ENDIF + + +EXETARGET2=$(BIN)$/runtests.exe + +.IF "$(name)" != "" +TESTLIB=$(BIN)$/$(name) +.ELSE +TESTLIB=$(BIN)$/version_current.dll +.ENDIF +VERSIONLIBS=version_libs + +CLI_URE = $(SOLARBINDIR)$/cli_ure.dll +CLI_URETYPES = $(SOLARBINDIR)$/cli_uretypes.dll +CLI_BASETYPES = $(SOLARBINDIR)$/cli_basetypes.dll +CLI_CPPUHELPER = $(SOLARBINDIR)$/cli_cppuhelper.dll +CLI_OOOTYPES = $(SOLARBINDIR)$/cli_oootypes.dll + + +.INCLUDE: target.mk + +.IF "$(BUILD_FOR_CLI)" == "" +ALLTAR: + +.ELSE +ALLTAR: \ + $(EXETARGET2) \ + $(TESTLIB) \ + $(MISC)$/copyassemblies.done \ + COPYVERSIONLIBS \ + RUNINSTRUCTIONS + +.ENDIF + + +COPYVERSIONLIBS: + -$(GNUCOPY) $(VERSIONLIBS)$/* $(BIN) + + +$(MISC)$/copyassemblies.done .ERRREMOVE: + $(GNUCOPY) $(CLI_CPPUHELPER) $(BIN)$/$(CLI_CPPUHELPER:f) + $(GNUCOPY) $(CLI_BASETYPES) $(BIN)$/$(CLI_BASETYPES:f) + $(GNUCOPY) $(CLI_URETYPES) $(BIN)$/$(CLI_URETYPES:f) + $(GNUCOPY) $(CLI_URE) $(BIN)$/$(CLI_URE:f) + $(GNUCOPY) $(CLI_OOOTYPES) $(BIN)$/$(CLI_OOOTYPES:f) + $(TOUCH) $@ + +CSFILES2 = runtests.cs + +.IF "$(CCNUMVER)" >= "001399999999" +CSCPLATFORMX86 = -platform:x86 +.ELSE +CSCPLATFORMX86 = +.ENDIF + +$(EXETARGET2): $(CSFILES2) + $(CSC) $(CSCFLAGS) -target:exe -out:$(EXETARGET2) $(CSCPLATFORMX86)\ + $(CSFILES2) + +CSFILESLIB = version.cs +$(TESTLIB): $(CSFILESLIB) $(SOLARBINDIR)$/cliureversion.mk + $(CSC) $(CSCFLAGS) -target:library -out:$(TESTLIB) \ + -reference:$(SOLARBINDIR)$/cli_ure.dll \ + -reference:$(SOLARBINDIR)$/cli_uretypes.dll \ + -reference:$(SOLARBINDIR)$/cli_basetypes.dll \ + -reference:$(SOLARBINDIR)$/cli_cppuhelper.dll \ + -reference:$(SOLARBINDIR)$/cli_oootypes.dll \ + $(CSFILESLIB) + + + +RUNINSTRUCTIONS : + @echo . + @echo ########################### N O T E ###################################### + @echo . + @echo To run the test go to qa\cliversioning, run dmake and follow instructions. + @echo . + @echo Or install an office with full system integration and run $(BIN)$/runtests.exe + @echo in a console withouth build environment. + @echo . + @echo Or install an office with setup /a. Expand PATH with the bin folder of the URE. + @echo Set UNO_PATH=system_path_to_program_folder + @echo This must be the program folder of the brand layer. + @echo For example, c:\staroffice\Sun\staroffice 9\program + @echo Run runtests.exe. + @echo . + @echo To build a test library with run. + @echo + @echo dmake name=version_10_10_10.dll + @echo + @echo The name must always start with 'version_'. + @echo ########################### N O T E ###################################### + @echo . + @echo . + + + +#.ENDIF diff --git a/testtools/source/cliversioning/old_version_libs_v2/readme.txt b/testtools/source/cliversioning/old_version_libs_v2/readme.txt new file mode 100644 index 000000000000..fa8e70201008 --- /dev/null +++ b/testtools/source/cliversioning/old_version_libs_v2/readme.txt @@ -0,0 +1,3 @@ +The test library contained here are not working anymore with the current OOo. +In OOo 3.0 there was a breaking change. cli_types.dll was split up into cli_uretypes.dll +and cli_oootypes.dll.
\ No newline at end of file diff --git a/testtools/source/cliversioning/old_version_libs_v2/version_2_0_0.dll b/testtools/source/cliversioning/old_version_libs_v2/version_2_0_0.dll Binary files differnew file mode 100644 index 000000000000..ce79aaed792f --- /dev/null +++ b/testtools/source/cliversioning/old_version_libs_v2/version_2_0_0.dll diff --git a/testtools/source/cliversioning/old_version_libs_v2/version_2_0_1.dll b/testtools/source/cliversioning/old_version_libs_v2/version_2_0_1.dll Binary files differnew file mode 100644 index 000000000000..7c6941a93484 --- /dev/null +++ b/testtools/source/cliversioning/old_version_libs_v2/version_2_0_1.dll diff --git a/testtools/source/cliversioning/old_version_libs_v2/version_2_0_2.dll b/testtools/source/cliversioning/old_version_libs_v2/version_2_0_2.dll Binary files differnew file mode 100644 index 000000000000..a43ee438800c --- /dev/null +++ b/testtools/source/cliversioning/old_version_libs_v2/version_2_0_2.dll diff --git a/testtools/source/cliversioning/old_version_libs_v2/version_2_0_3.dll b/testtools/source/cliversioning/old_version_libs_v2/version_2_0_3.dll Binary files differnew file mode 100644 index 000000000000..c7b95c249a4b --- /dev/null +++ b/testtools/source/cliversioning/old_version_libs_v2/version_2_0_3.dll diff --git a/testtools/source/cliversioning/old_version_libs_v2/version_2_0_3r3.dll b/testtools/source/cliversioning/old_version_libs_v2/version_2_0_3r3.dll Binary files differnew file mode 100644 index 000000000000..985295f87a62 --- /dev/null +++ b/testtools/source/cliversioning/old_version_libs_v2/version_2_0_3r3.dll diff --git a/testtools/source/cliversioning/old_version_libs_v2/version_2_0_4.dll b/testtools/source/cliversioning/old_version_libs_v2/version_2_0_4.dll Binary files differnew file mode 100644 index 000000000000..f396e6c6a40f --- /dev/null +++ b/testtools/source/cliversioning/old_version_libs_v2/version_2_0_4.dll diff --git a/testtools/source/cliversioning/old_version_libs_v2/version_2_1.dll b/testtools/source/cliversioning/old_version_libs_v2/version_2_1.dll Binary files differnew file mode 100644 index 000000000000..8505133d8356 --- /dev/null +++ b/testtools/source/cliversioning/old_version_libs_v2/version_2_1.dll diff --git a/testtools/source/cliversioning/old_version_libs_v2/version_2_2.dll b/testtools/source/cliversioning/old_version_libs_v2/version_2_2.dll Binary files differnew file mode 100644 index 000000000000..11fc723df085 --- /dev/null +++ b/testtools/source/cliversioning/old_version_libs_v2/version_2_2.dll diff --git a/testtools/source/cliversioning/old_version_libs_v2/version_2_2_1.dll b/testtools/source/cliversioning/old_version_libs_v2/version_2_2_1.dll Binary files differnew file mode 100644 index 000000000000..5cc6432149d3 --- /dev/null +++ b/testtools/source/cliversioning/old_version_libs_v2/version_2_2_1.dll diff --git a/testtools/source/cliversioning/old_version_libs_v2/version_2_3.dll b/testtools/source/cliversioning/old_version_libs_v2/version_2_3.dll Binary files differnew file mode 100644 index 000000000000..8a8b3b147d6c --- /dev/null +++ b/testtools/source/cliversioning/old_version_libs_v2/version_2_3.dll diff --git a/testtools/source/cliversioning/old_version_libs_v2/version_2_3_1.dll b/testtools/source/cliversioning/old_version_libs_v2/version_2_3_1.dll Binary files differnew file mode 100644 index 000000000000..d77db4db2aab --- /dev/null +++ b/testtools/source/cliversioning/old_version_libs_v2/version_2_3_1.dll diff --git a/testtools/source/cliversioning/old_version_libs_v2/version_2_4.dll b/testtools/source/cliversioning/old_version_libs_v2/version_2_4.dll Binary files differnew file mode 100644 index 000000000000..f002dc053e11 --- /dev/null +++ b/testtools/source/cliversioning/old_version_libs_v2/version_2_4.dll diff --git a/testtools/source/cliversioning/old_version_libs_v2/version_2_4_1.dll b/testtools/source/cliversioning/old_version_libs_v2/version_2_4_1.dll Binary files differnew file mode 100644 index 000000000000..a90155915ada --- /dev/null +++ b/testtools/source/cliversioning/old_version_libs_v2/version_2_4_1.dll diff --git a/testtools/source/cliversioning/readme.txt b/testtools/source/cliversioning/readme.txt new file mode 100644 index 000000000000..f1d6431a93b8 --- /dev/null +++ b/testtools/source/cliversioning/readme.txt @@ -0,0 +1,106 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2000, 2010 Oracle and/or its affiliates. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org 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 version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +# ************************************************************************/ + + + + +WINDOWS ONLY, no other platforms + + + + +This test checks if the cli assemblies and their policy files are installed in the +GAC and if the policy files are correct. The office must be installed with complete +system integration. That is, one does not use setup /a for starting the +installation. + +In OOo 3.0 there was a breanking change so that the test created for previous +version do not work anymore. To use these old tests one needs to install a +version of OOo less than v 3.0. Then one needs to check out the cli_ure module +for that version. The tests are contained in cli_ure/qa/versioning. + +In the sub directory version_libs are libraries which are linked with (referencing) +cli_cppuhelper +cli_basetypes +cli_ure +cli_uretypes +cli_oootypes + +They are named version_3_0_0 etc, where the name indicates the version of the +office for which they were initially build. If there are only the assemblies +for example OOo2.0.2 installed and a client was build with the assemblies from +OOo2 then the policy assemblies must make the correct redirection. + +When calling dmake then the executable runtest.exe and version_current.dll are +build. When runtest runs then it loads all dlls, which names start with +"version", from the same directory and tries to run a particular test code +which is only available in the version_xxx.dll s. The code in the +version_xxx.dlls uses the cli default bootstrap mechanism to find the office +installation and start the office. When running runtest in a build environment +then it may use the wrong libraries for bootstrapping in which case the test +fails. Then one has to set PATH which must point to the program directory of +the office installation. For example: + +set PATH=d:\office\program + +runtest stops when a test failed to run. It writes error information to the +console which shows which version_xxx.dll failed to run and if this was due to +a referenced assembly that could not be loaded. This would be the case if such +an assembly or the policy assembly is not properly installed or the redirection +in the policy assembly is wrong. + +The version_current.dll references the assemblies in the current build +environment. version_current.dll is also executed when runtest is started. + +To run the whole test one can either +1. start testools/wntmsci11.pro/bin/runtests.exe in a console where no +environment is set. +2. Call dmake run in testools/qa/cliversions + +For a limited test one can call in this directory +dmake run office=d:\office +There must not be an office installed in the system (the assemblies from the GAC +would then be used). Only the test with the version_current.dll will succeed +because there are no policy files installed. This test requires that all +assemblies are copied next to runtests.exe - the makefile will do that. + +The parameter office must be a system path to the office installation +directory. The java code calls runtest and also sets PATH so that the test +works in the build environment. It also sets UNO_PATH so that the office will be +found. If the test says that it failed, then one should run runtest directly +because it puts out more information. + + + +Creating a new version_xxx.dll +============================== +When a version of our assemblies changes then one should provide a new version dll which test exactly the assemblies with the changed version. This is easily done: +1. set the build environment in which the new versions are effectiv. +2 call: dmake name=version_xxx.dll +3. copy the new version dll from the output tree into qa/versioning/version_libs +4. commit the new version.dll using the -kb switch (only when creating the new file : cvs new -kb version_3_1_0.dll) + diff --git a/testtools/source/cliversioning/runtests.cs b/testtools/source/cliversioning/runtests.cs new file mode 100644 index 000000000000..fdf1761f4ace --- /dev/null +++ b/testtools/source/cliversioning/runtests.cs @@ -0,0 +1,127 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +using System; +using System.Reflection; +using System.IO; + +// __________ implementation ____________________________________ + +/** Create and modify a spreadsheet document. + */ +namespace cliversion +{ +public class RunTests +{ + + public static int Main(String[] args) + { +// System.Diagnostics.Debugger.Launch(); + //get the path to the directory + string sLocation = Assembly.GetExecutingAssembly().Location; + sLocation = sLocation.Substring(0, sLocation.LastIndexOf('\\')); + // Create a reference to the current directory. + DirectoryInfo di = new DirectoryInfo(sLocation); + // Create an array representing the files in the current directory. + FileInfo[] fi = di.GetFiles(); + + //For every found dll try to figure out if it contains a + //cliversion.Version class + foreach (FileInfo fiTemp in fi) + { + if (fiTemp.Extension != ".dll" + || ! fiTemp.Name.StartsWith("version")) + continue; + + Assembly ass = null; + Object objVersion = null; + try + { + string sName = fiTemp.Name.Substring(0, fiTemp.Name.LastIndexOf(".dll")); + ass = Assembly.Load(sName); + } + catch (BadImageFormatException) + { + continue; + } + catch (Exception e) + { + Console.WriteLine("#Unexpected Exception"); + Console.WriteLine(e.Message); + return -1; + } + + //Assembly is loaded, instantiate cliversion.Version + try + { + //This runs the test + objVersion = ass.CreateInstance("cliversion.Version"); + if (objVersion == null) + continue; + Console.WriteLine("#Tested successfully " + fiTemp.Name); + //Starting the office the second time may fail without this pause + System.Threading.Thread.Sleep(2000); + } + catch (Exception e) + { + TargetInvocationException te = e as TargetInvocationException; + if (te != null) + { + FileNotFoundException fe = e.InnerException as FileNotFoundException; + if (fe != null) + { + Console.WriteLine(fiTemp.Name + " did not find " + fe.FileName + + ". Maybe the " + fe.FileName + " is not installed or does not match the referenced version." + + "Original message: " + fe.Message + "\n\n FusionLog: \n" + fe.FusionLog ); + return -1; + } + FileLoadException fl = e.InnerException as FileLoadException; + if (fl != null) + { + Console.WriteLine(fiTemp.Name + " could not load " + fl.FileName + + ". Maybe the version of " + fl.FileName + " does not match the referenced version. " + + "Original message: " + fl.Message + "\n\n FusionLog: \n" + fl.FusionLog ); + return -1; + } + + if (e.InnerException != null) + { + Console.WriteLine(e.InnerException); + } + } + Console.WriteLine("#Unexpected Exception"); + Console.WriteLine(e.Message); + return -1; + } + } + //For some unknown reason this program hangs sometimes when started from java. This is + //a workaround that makes the problem disappear. + System.Threading.Thread.Sleep(1000); + return 0; + } +} +} diff --git a/testtools/source/cliversioning/version.cs b/testtools/source/cliversioning/version.cs new file mode 100644 index 000000000000..6071ad339f84 --- /dev/null +++ b/testtools/source/cliversioning/version.cs @@ -0,0 +1,608 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +using System; +using unoidl.com.sun.star.lang; +using unoidl.com.sun.star.uno; +using unoidl.com.sun.star.frame; +using unoidl.com.sun.star.util; + +namespace cliversion +{ +public class Version +{ + public Version() + { + try + { +// System.Diagnostics.Debugger.Launch(); + + //link with cli_ure.dll + uno.util.WeakBase wb = new uno.util.WeakBase(); + using ( SpreadsheetSample aSample = new SpreadsheetSample() ) + { + aSample.doCellRangeSamples(); + aSample.terminate(); + } + } + catch (System.Exception ) + { + //This exception is thrown if we link with a library which is not + //available + throw; + } + } +} + +class SpreadsheetSample: SpreadsheetDocHelper +{ + public SpreadsheetSample() + { + } + /** All samples regarding the service com.sun.star.sheet.SheetCellRange. */ + public void doCellRangeSamples() + { + unoidl.com.sun.star.sheet.XSpreadsheet xSheet = getSpreadsheet( 0 ); + unoidl.com.sun.star.table.XCellRange xCellRange = null; + unoidl.com.sun.star.beans.XPropertySet xPropSet = null; + unoidl.com.sun.star.table.CellRangeAddress aRangeAddress = null; + + // Preparation + setFormula( xSheet, "B5", "First cell" ); + setFormula( xSheet, "B6", "Second cell" ); + // Get cell range B5:B6 by position - (column, row, column, row) + xCellRange = xSheet.getCellRangeByPosition( 1, 4, 1, 5 ); + + + // --- Change cell range properties. --- + xPropSet = (unoidl.com.sun.star.beans.XPropertySet) xCellRange; + // from com.sun.star.styles.CharacterProperties + xPropSet.setPropertyValue( + "CharColor", new uno.Any( (Int32) 0x003399 ) ); + xPropSet.setPropertyValue( + "CharHeight", new uno.Any( (Single) 20.0 ) ); + // from com.sun.star.styles.ParagraphProperties + xPropSet.setPropertyValue( + "ParaLeftMargin", new uno.Any( (Int32) 500 ) ); + // from com.sun.star.table.CellProperties + xPropSet.setPropertyValue( + "IsCellBackgroundTransparent", new uno.Any( false ) ); + xPropSet.setPropertyValue( + "CellBackColor", new uno.Any( (Int32) 0x99CCFF ) ); + + + // --- Replace text in all cells. --- + unoidl.com.sun.star.util.XReplaceable xReplace = + (unoidl.com.sun.star.util.XReplaceable) xCellRange; + unoidl.com.sun.star.util.XReplaceDescriptor xReplaceDesc = + xReplace.createReplaceDescriptor(); + xReplaceDesc.setSearchString( "cell" ); + xReplaceDesc.setReplaceString( "text" ); + // property SearchWords searches for whole cells! + xReplaceDesc.setPropertyValue( "SearchWords", new uno.Any( false ) ); + int nCount = xReplace.replaceAll( xReplaceDesc ); + + // --- Merge cells. --- + xCellRange = xSheet.getCellRangeByName( "F3:G6" ); + prepareRange( xSheet, "E1:H7", "XMergeable" ); + unoidl.com.sun.star.util.XMergeable xMerge = + (unoidl.com.sun.star.util.XMergeable) xCellRange; + xMerge.merge( true ); + + + // --- Column properties. --- + xCellRange = xSheet.getCellRangeByName( "B1" ); + unoidl.com.sun.star.table.XColumnRowRange xColRowRange = + (unoidl.com.sun.star.table.XColumnRowRange) xCellRange; + unoidl.com.sun.star.table.XTableColumns xColumns = + xColRowRange.getColumns(); + + uno.Any aColumnObj = xColumns.getByIndex( 0 ); + xPropSet = (unoidl.com.sun.star.beans.XPropertySet) aColumnObj.Value; + xPropSet.setPropertyValue( "Width", new uno.Any( (Int32) 6000 ) ); + + unoidl.com.sun.star.container.XNamed xNamed = + (unoidl.com.sun.star.container.XNamed) aColumnObj.Value; + + // --- Cell range data --- + prepareRange( xSheet, "A9:C30", "XCellRangeData" ); + + xCellRange = xSheet.getCellRangeByName( "A10:C30" ); + unoidl.com.sun.star.sheet.XCellRangeData xData = + (unoidl.com.sun.star.sheet.XCellRangeData) xCellRange; + uno.Any [][] aValues = + { + new uno.Any [] { new uno.Any( "Name" ), + new uno.Any( "Fruit" ), + new uno.Any( "Quantity" ) }, + new uno.Any [] { new uno.Any( "Alice" ), + new uno.Any( "Apples" ), + new uno.Any( (Double) 3.0 ) }, + new uno.Any [] { new uno.Any( "Alice" ), + new uno.Any( "Oranges" ), + new uno.Any( (Double) 7.0 ) }, + new uno.Any [] { new uno.Any( "Bob" ), + new uno.Any( "Apples" ), + new uno.Any( (Double) 3.0 ) }, + new uno.Any [] { new uno.Any( "Alice" ), + new uno.Any( "Apples" ), + new uno.Any( (Double) 9.0 ) }, + new uno.Any [] { new uno.Any( "Bob" ), + new uno.Any( "Apples" ), + new uno.Any( (Double) 5.0 ) }, + new uno.Any [] { new uno.Any( "Bob" ), + new uno.Any( "Oranges" ), + new uno.Any( (Double) 6.0 ) }, + new uno.Any [] { new uno.Any( "Alice" ), + new uno.Any( "Oranges" ), + new uno.Any( (Double) 3.0 ) }, + new uno.Any [] { new uno.Any( "Alice" ), + new uno.Any( "Apples" ), + new uno.Any( (Double) 8.0 ) }, + new uno.Any [] { new uno.Any( "Alice" ), + new uno.Any( "Oranges" ), + new uno.Any( (Double) 1.0 ) }, + new uno.Any [] { new uno.Any( "Bob" ), + new uno.Any( "Oranges" ), + new uno.Any( (Double) 2.0 ) }, + new uno.Any [] { new uno.Any( "Bob" ), + new uno.Any( "Oranges" ), + new uno.Any( (Double) 7.0 ) }, + new uno.Any [] { new uno.Any( "Bob" ), + new uno.Any( "Apples" ), + new uno.Any( (Double) 1.0 ) }, + new uno.Any [] { new uno.Any( "Alice" ), + new uno.Any( "Apples" ), + new uno.Any( (Double) 8.0 ) }, + new uno.Any [] { new uno.Any( "Alice" ), + new uno.Any( "Oranges" ), + new uno.Any( (Double) 8.0 ) }, + new uno.Any [] { new uno.Any( "Alice" ), + new uno.Any( "Apples" ), + new uno.Any( (Double) 7.0 ) }, + new uno.Any [] { new uno.Any( "Bob" ), + new uno.Any( "Apples" ), + new uno.Any( (Double) 1.0 ) }, + new uno.Any [] { new uno.Any( "Bob" ), + new uno.Any( "Oranges" ), + new uno.Any( (Double) 9.0 ) }, + new uno.Any [] { new uno.Any( "Bob" ), + new uno.Any( "Oranges" ), + new uno.Any( (Double) 3.0 ) }, + new uno.Any [] { new uno.Any( "Alice" ), + new uno.Any( "Oranges" ), + new uno.Any( (Double) 4.0 ) }, + new uno.Any [] { new uno.Any( "Alice" ), + new uno.Any( "Apples" ), + new uno.Any( (Double) 9.0 ) } + }; + xData.setDataArray( aValues ); + + + // --- Get cell range address. --- + unoidl.com.sun.star.sheet.XCellRangeAddressable xRangeAddr = + (unoidl.com.sun.star.sheet.XCellRangeAddressable) xCellRange; + aRangeAddress = xRangeAddr.getRangeAddress(); + + // --- Sheet operation. --- + // uses the range filled with XCellRangeData + unoidl.com.sun.star.sheet.XSheetOperation xSheetOp = + (unoidl.com.sun.star.sheet.XSheetOperation) xData; + double fResult = xSheetOp.computeFunction( + unoidl.com.sun.star.sheet.GeneralFunction.AVERAGE ); + + // --- Fill series --- + // Prepare the example + setValue( xSheet, "E10", 1 ); + setValue( xSheet, "E11", 4 ); + setDate( xSheet, "E12", 30, 1, 2002 ); + setFormula( xSheet, "I13", "Text 10" ); + setFormula( xSheet, "E14", "Jan" ); + setValue( xSheet, "K14", 10 ); + setValue( xSheet, "E16", 1 ); + setValue( xSheet, "F16", 2 ); + setDate( xSheet, "E17", 28, 2, 2002 ); + setDate( xSheet, "F17", 28, 1, 2002 ); + setValue( xSheet, "E18", 6 ); + setValue( xSheet, "F18", 4 ); + + } + + /** Returns the XCellSeries interface of a cell range. + @param xSheet The spreadsheet containing the cell range. + @param aRange The address of the cell range. + @return The XCellSeries interface. */ + private unoidl.com.sun.star.sheet.XCellSeries getCellSeries( + unoidl.com.sun.star.sheet.XSpreadsheet xSheet, String aRange ) + { + return (unoidl.com.sun.star.sheet.XCellSeries) + xSheet.getCellRangeByName( aRange ); + } + +} + +/** This is a helper class for the spreadsheet and table samples. + It connects to a running office and creates a spreadsheet document. + Additionally it contains various helper functions. + */ +class SpreadsheetDocHelper : System.IDisposable +{ + +// __ private members ___________________________________________ + + private const String msDataSheetName = "Data"; + + private unoidl.com.sun.star.uno.XComponentContext m_xContext; + private unoidl.com.sun.star.lang.XMultiServiceFactory mxMSFactory; + private unoidl.com.sun.star.sheet.XSpreadsheetDocument mxDocument; + +// ________________________________________________________________ + + public SpreadsheetDocHelper() + { +// System.Diagnostics.Debugger.Launch(); + // Connect to a running office and get the service manager + mxMSFactory = connect(); + // Create a new spreadsheet document + mxDocument = initDocument(); + } + +// __ helper methods ____________________________________________ + + /** Returns the service manager. + @return XMultiServiceFactory interface of the service manager. */ + public unoidl.com.sun.star.lang.XMultiServiceFactory getServiceManager() + { + return mxMSFactory; + } + + /** Returns the whole spreadsheet document. + @return XSpreadsheetDocument interface of the document. */ + public unoidl.com.sun.star.sheet.XSpreadsheetDocument getDocument() + { + return mxDocument; + } + + /** Returns the spreadsheet with the specified index (0-based). + @param nIndex The index of the sheet. + @return XSpreadsheet interface of the sheet. */ + public unoidl.com.sun.star.sheet.XSpreadsheet getSpreadsheet( int nIndex ) + { + // Collection of sheets + unoidl.com.sun.star.sheet.XSpreadsheets xSheets = + mxDocument.getSheets(); + + unoidl.com.sun.star.container.XIndexAccess xSheetsIA = + (unoidl.com.sun.star.container.XIndexAccess) xSheets; + + unoidl.com.sun.star.sheet.XSpreadsheet xSheet = + (unoidl.com.sun.star.sheet.XSpreadsheet) + xSheetsIA.getByIndex( nIndex ).Value; + + return xSheet; + } + + /** Inserts a new empty spreadsheet with the specified name. + @param aName The name of the new sheet. + @param nIndex The insertion index. + @return The XSpreadsheet interface of the new sheet. */ + public unoidl.com.sun.star.sheet.XSpreadsheet insertSpreadsheet( + String aName, short nIndex ) + { + // Collection of sheets + unoidl.com.sun.star.sheet.XSpreadsheets xSheets = + mxDocument.getSheets(); + + xSheets.insertNewByName( aName, nIndex ); + unoidl.com.sun.star.sheet.XSpreadsheet xSheet = + (unoidl.com.sun.star.sheet.XSpreadsheet) + xSheets.getByName( aName ).Value; + + return xSheet; + } + +// ________________________________________________________________ +// Methods to fill values into cells. + + /** Writes a double value into a spreadsheet. + @param xSheet The XSpreadsheet interface of the spreadsheet. + @param aCellName The address of the cell (or a named range). + @param fValue The value to write into the cell. */ + public void setValue( + unoidl.com.sun.star.sheet.XSpreadsheet xSheet, + String aCellName, + double fValue ) + { + xSheet.getCellRangeByName( aCellName ).getCellByPosition( + 0, 0 ).setValue( fValue ); + } + + /** Writes a formula into a spreadsheet. + @param xSheet The XSpreadsheet interface of the spreadsheet. + @param aCellName The address of the cell (or a named range). + @param aFormula The formula to write into the cell. */ + public void setFormula( + unoidl.com.sun.star.sheet.XSpreadsheet xSheet, + String aCellName, + String aFormula ) + { + xSheet.getCellRangeByName( aCellName ).getCellByPosition( + 0, 0 ).setFormula( aFormula ); + } + + /** Writes a date with standard date format into a spreadsheet. + @param xSheet The XSpreadsheet interface of the spreadsheet. + @param aCellName The address of the cell (or a named range). + @param nDay The day of the date. + @param nMonth The month of the date. + @param nYear The year of the date. */ + public void setDate( + unoidl.com.sun.star.sheet.XSpreadsheet xSheet, + String aCellName, + int nDay, int nMonth, int nYear ) + { + // Set the date value. + unoidl.com.sun.star.table.XCell xCell = + xSheet.getCellRangeByName( aCellName ).getCellByPosition( 0, 0 ); + String aDateStr = nMonth + "/" + nDay + "/" + nYear; + xCell.setFormula( aDateStr ); + + // Set standard date format. + unoidl.com.sun.star.util.XNumberFormatsSupplier xFormatsSupplier = + (unoidl.com.sun.star.util.XNumberFormatsSupplier) getDocument(); + unoidl.com.sun.star.util.XNumberFormatTypes xFormatTypes = + (unoidl.com.sun.star.util.XNumberFormatTypes) + xFormatsSupplier.getNumberFormats(); + int nFormat = xFormatTypes.getStandardFormat( + unoidl.com.sun.star.util.NumberFormat.DATE, + new unoidl.com.sun.star.lang.Locale() ); + + unoidl.com.sun.star.beans.XPropertySet xPropSet = + (unoidl.com.sun.star.beans.XPropertySet) xCell; + xPropSet.setPropertyValue( + "NumberFormat", + new uno.Any( (Int32) nFormat ) ); + } + + /** Draws a colored border around the range and writes the headline + in the first cell. + + @param xSheet The XSpreadsheet interface of the spreadsheet. + @param aRange The address of the cell range (or a named range). + @param aHeadline The headline text. */ + public void prepareRange( + unoidl.com.sun.star.sheet.XSpreadsheet xSheet, + String aRange, String aHeadline ) + { + unoidl.com.sun.star.beans.XPropertySet xPropSet = null; + unoidl.com.sun.star.table.XCellRange xCellRange = null; + + // draw border + xCellRange = xSheet.getCellRangeByName( aRange ); + xPropSet = (unoidl.com.sun.star.beans.XPropertySet) xCellRange; + unoidl.com.sun.star.table.BorderLine aLine = + new unoidl.com.sun.star.table.BorderLine(); + aLine.Color = 0x99CCFF; + aLine.InnerLineWidth = aLine.LineDistance = 0; + aLine.OuterLineWidth = 100; + unoidl.com.sun.star.table.TableBorder aBorder = + new unoidl.com.sun.star.table.TableBorder(); + aBorder.TopLine = aBorder.BottomLine = aBorder.LeftLine = + aBorder.RightLine = aLine; + aBorder.IsTopLineValid = aBorder.IsBottomLineValid = true; + aBorder.IsLeftLineValid = aBorder.IsRightLineValid = true; + xPropSet.setPropertyValue( + "TableBorder", + new uno.Any( + typeof (unoidl.com.sun.star.table.TableBorder), aBorder ) ); + + // draw headline + unoidl.com.sun.star.sheet.XCellRangeAddressable xAddr = + (unoidl.com.sun.star.sheet.XCellRangeAddressable) xCellRange; + unoidl.com.sun.star.table.CellRangeAddress aAddr = + xAddr.getRangeAddress(); + + xCellRange = xSheet.getCellRangeByPosition( + aAddr.StartColumn, + aAddr.StartRow, aAddr.EndColumn, aAddr.StartRow ); + + xPropSet = (unoidl.com.sun.star.beans.XPropertySet) xCellRange; + xPropSet.setPropertyValue( + "CellBackColor", new uno.Any( (Int32) 0x99CCFF ) ); + // write headline + unoidl.com.sun.star.table.XCell xCell = + xCellRange.getCellByPosition( 0, 0 ); + xCell.setFormula( aHeadline ); + xPropSet = (unoidl.com.sun.star.beans.XPropertySet) xCell; + xPropSet.setPropertyValue( + "CharColor", new uno.Any( (Int32) 0x003399 ) ); + xPropSet.setPropertyValue( + "CharWeight", + new uno.Any( (Single) unoidl.com.sun.star.awt.FontWeight.BOLD ) ); + } + +// ________________________________________________________________ +// Methods to create cell addresses and range addresses. + + /** Creates a unoidl.com.sun.star.table.CellAddress and initializes it + with the given range. + @param xSheet The XSpreadsheet interface of the spreadsheet. + @param aCell The address of the cell (or a named cell). */ + public unoidl.com.sun.star.table.CellAddress createCellAddress( + unoidl.com.sun.star.sheet.XSpreadsheet xSheet, + String aCell ) + { + unoidl.com.sun.star.sheet.XCellAddressable xAddr = + (unoidl.com.sun.star.sheet.XCellAddressable) + xSheet.getCellRangeByName( aCell ).getCellByPosition( 0, 0 ); + return xAddr.getCellAddress(); + } + + /** Creates a unoidl.com.sun.star.table.CellRangeAddress and initializes + it with the given range. + @param xSheet The XSpreadsheet interface of the spreadsheet. + @param aRange The address of the cell range (or a named range). */ + public unoidl.com.sun.star.table.CellRangeAddress createCellRangeAddress( + unoidl.com.sun.star.sheet.XSpreadsheet xSheet, String aRange ) + { + unoidl.com.sun.star.sheet.XCellRangeAddressable xAddr = + (unoidl.com.sun.star.sheet.XCellRangeAddressable) + xSheet.getCellRangeByName( aRange ); + return xAddr.getRangeAddress(); + } + +// ________________________________________________________________ +// Methods to convert cell addresses and range addresses to strings. + + /** Returns the text address of the cell. + @param nColumn The column index. + @param nRow The row index. + @return A string containing the cell address. */ + public String getCellAddressString( int nColumn, int nRow ) + { + String aStr = ""; + if (nColumn > 25) + aStr += (char) ('A' + nColumn / 26 - 1); + aStr += (char) ('A' + nColumn % 26); + aStr += (nRow + 1); + return aStr; + } + + /** Returns the text address of the cell range. + @param aCellRange The cell range address. + @return A string containing the cell range address. */ + public String getCellRangeAddressString( + unoidl.com.sun.star.table.CellRangeAddress aCellRange ) + { + return + getCellAddressString( aCellRange.StartColumn, aCellRange.StartRow ) + + ":" + + getCellAddressString( aCellRange.EndColumn, aCellRange.EndRow ); + } + + /** Returns the text address of the cell range. + @param xCellRange The XSheetCellRange interface of the cell range. + @param bWithSheet true = Include sheet name. + @return A string containing the cell range address. */ + public String getCellRangeAddressString( + unoidl.com.sun.star.sheet.XSheetCellRange xCellRange, bool bWithSheet ) + { + String aStr = ""; + if (bWithSheet) + { + unoidl.com.sun.star.sheet.XSpreadsheet xSheet = + xCellRange.getSpreadsheet(); + unoidl.com.sun.star.container.XNamed xNamed = + (unoidl.com.sun.star.container.XNamed) xSheet; + aStr += xNamed.getName() + "."; + } + unoidl.com.sun.star.sheet.XCellRangeAddressable xAddr = + (unoidl.com.sun.star.sheet.XCellRangeAddressable) xCellRange; + aStr += getCellRangeAddressString( xAddr.getRangeAddress() ); + return aStr; + } + + /** Returns a list of addresses of all cell ranges contained in the + collection. + + @param xRangesIA The XIndexAccess interface of the collection. + @return A string containing the cell range address list. */ + public String getCellRangeListString( + unoidl.com.sun.star.container.XIndexAccess xRangesIA ) + { + String aStr = ""; + int nCount = xRangesIA.getCount(); + for (int nIndex = 0; nIndex < nCount; ++nIndex) + { + if (nIndex > 0) + aStr += " "; + uno.Any aRangeObj = xRangesIA.getByIndex( nIndex ); + unoidl.com.sun.star.sheet.XSheetCellRange xCellRange = + (unoidl.com.sun.star.sheet.XSheetCellRange) aRangeObj.Value; + aStr += getCellRangeAddressString( xCellRange, false ); + } + return aStr; + } + +// ________________________________________________________________ + + /** Connect to a running office that is accepting connections. + @return The ServiceManager to instantiate office components. */ + private XMultiServiceFactory connect() + { + + m_xContext = uno.util.Bootstrap.bootstrap(); + + return (XMultiServiceFactory) m_xContext.getServiceManager(); + } + + public void Dispose() + { + + } + + /** Creates an empty spreadsheet document. + @return The XSpreadsheetDocument interface of the document. */ + private unoidl.com.sun.star.sheet.XSpreadsheetDocument initDocument() + { + XComponentLoader aLoader = (XComponentLoader) + mxMSFactory.createInstance( "com.sun.star.frame.Desktop" ); + + XComponent xComponent = aLoader.loadComponentFromURL( + "private:factory/scalc", "_blank", 0, + new unoidl.com.sun.star.beans.PropertyValue[0] ); + + return (unoidl.com.sun.star.sheet.XSpreadsheetDocument) xComponent; + } + + + public void terminate() + { + XModifiable xMod = (XModifiable) mxDocument; + if (xMod != null) + xMod.setModified(false); + XDesktop aDesktop = (XDesktop) + mxMSFactory.createInstance( "com.sun.star.frame.Desktop" ); + if (aDesktop != null) + { + try + { + aDesktop.terminate(); + } + catch (DisposedException d) + { + //This exception may be thrown because shutting down OOo using + //XDesktop terminate does not really work. In the case of the + //Exception OOo will still terminate. + } + } + } + +// ________________________________________________________________ +} + +} diff --git a/testtools/source/cliversioning/version_libs/readme.txt b/testtools/source/cliversioning/version_libs/readme.txt new file mode 100644 index 000000000000..a78c22e1a45e --- /dev/null +++ b/testtools/source/cliversioning/version_libs/readme.txt @@ -0,0 +1,3 @@ +These binary files are needed for this test. They have been linked with +earlier versions of the cli libraries, and cannot be build this way again +in a current version of the build environment.
\ No newline at end of file diff --git a/testtools/source/cliversioning/version_libs/version_3_0_0.dll b/testtools/source/cliversioning/version_libs/version_3_0_0.dll Binary files differnew file mode 100644 index 000000000000..71769a44f287 --- /dev/null +++ b/testtools/source/cliversioning/version_libs/version_3_0_0.dll diff --git a/testtools/source/cliversioning/version_libs/version_3_0_1.dll b/testtools/source/cliversioning/version_libs/version_3_0_1.dll Binary files differnew file mode 100644 index 000000000000..823cfc8c8678 --- /dev/null +++ b/testtools/source/cliversioning/version_libs/version_3_0_1.dll diff --git a/testtools/source/cliversioning/version_libs/version_3_1.dll b/testtools/source/cliversioning/version_libs/version_3_1.dll Binary files differnew file mode 100755 index 000000000000..b16da2df5d39 --- /dev/null +++ b/testtools/source/cliversioning/version_libs/version_3_1.dll diff --git a/testtools/source/cliversioning/version_libs/version_3_1_1.dll b/testtools/source/cliversioning/version_libs/version_3_1_1.dll Binary files differnew file mode 100644 index 000000000000..9ff42fc230a1 --- /dev/null +++ b/testtools/source/cliversioning/version_libs/version_3_1_1.dll diff --git a/testtools/source/cliversioning/version_libs/version_3_2.dll b/testtools/source/cliversioning/version_libs/version_3_2.dll Binary files differnew file mode 100755 index 000000000000..e89232441766 --- /dev/null +++ b/testtools/source/cliversioning/version_libs/version_3_2.dll diff --git a/testtools/source/cliversioning/version_libs/version_3_2_1.dll b/testtools/source/cliversioning/version_libs/version_3_2_1.dll Binary files differnew file mode 100755 index 000000000000..037f5ddee846 --- /dev/null +++ b/testtools/source/cliversioning/version_libs/version_3_2_1.dll diff --git a/testtools/source/performance/cli_testobj_performance.cs b/testtools/source/performance/cli_testobj_performance.cs new file mode 100644 index 000000000000..5397f93c7b3c --- /dev/null +++ b/testtools/source/performance/cli_testobj_performance.cs @@ -0,0 +1,118 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +using System; +using System.Diagnostics; +using uno; +using uno.util; +using unoidl.com.sun.star.uno; +using unoidl.com.sun.star.lang; +using unoidl.com.sun.star.test.performance; + +namespace testobj +{ + +[ServiceImplementation( "com.sun.star.test.performance.cli_uno.TestObject" )] +public class PerformanceTestObject : ServiceBase, XPerformanceTest +{ + private XComponentContext m_xContext; + + public PerformanceTestObject( XComponentContext xContext ) + { + m_xContext = xContext; + } + public PerformanceTestObject() + { + } + + private int _long; + private long _hyper; + private float _float; + private double _double; + private String _string = ""; + private Object _xInterface; + private Any _any; + private Object[] _interface_sequence = new Object[0]; + private ComplexTypes _complexTypes = new ComplexTypes(); + + // Attributes + public int getLong_attr() { return _long; } + public void setLong_attr( int _long_attr ) { _long = _long_attr; } + public long getHyper_attr() { return _hyper; } + public void setHyper_attr( long _hyper_attr ) { _hyper = _hyper_attr; } + public float getFloat_attr() { return _float; } + public void setFloat_attr( float _float_attr ) { _float = _float; } + public double getDouble_attr() { return _double; } + public void setDouble_attr( double _double_attr ) { _double = _double_attr; } + public String getString_attr() { return _string; } + public void setString_attr( String _string_attr ) { _string = _string_attr; } + public Object getInterface_attr() { return _xInterface; } + public void setInterface_attr( Object _interface_attr ) { _xInterface = _interface_attr; } + public Any getAny_attr() { return _any; } + public void setAny_attr( ref Any _any_attr ) { _any = _any_attr; } + public Object[] getSequence_attr() { return _interface_sequence; } + public void setSequence_attr(Object[] _sequence_attr ) { _interface_sequence = _sequence_attr; } + public ComplexTypes getStruct_attr() { return _complexTypes; } + public void setStruct_attr( ComplexTypes _struct_attr ) { _complexTypes = _struct_attr; } + + // Methods + public void async() {} + public void sync( ) {} + public ComplexTypes complex_in( /*IN*/ComplexTypes aVal ) { return aVal; } + public ComplexTypes complex_inout( /*INOUT*/ref ComplexTypes aVal ) { return aVal; } + public void complex_oneway( /*IN*/ComplexTypes aVal ) {} + public void complex_noreturn( /*IN*/ComplexTypes aVal ) {} + public XPerformanceTest createObject( ) { return new PerformanceTestObject(); } + public int getLong() { return _long; } + public void setLong(/*IN*/int n) { _long = n; } + public long getHyper() { return _hyper; } + public void setHyper(/*IN*/long n) { _hyper = n; } + public float getFloat() { return _float; } + public void setFloat( /*IN*/float f ) { _float = f; } + public double getDouble( ) { return _double; } + public void setDouble( /*IN*/double f ) { _double = f; } + public String getString( ) { return _string; } + public void setString( /*IN*/String s ) { _string = s; } + public Object getInterface( ) { return _xInterface; } + public void setInterface( /*IN*/Object x ) { _xInterface = x; } + public Any getAny( ) { return _any; } + public void setAny( /*IN*/ref Any a ) { _any = a; } + public Object[] getSequence( ) { return _interface_sequence; } + public void setSequence( /*IN*/Object[] seq ) + { +#if DEBUG +// Debug.WriteLine( "#### " + GetType().FullName + ".setSequence:" + seq ); + Console.WriteLine( "#### " + GetType().FullName + ".setSequence:" + seq ); +#endif + _interface_sequence = seq; + } + public ComplexTypes getStruct( ) { return _complexTypes; } + public void setStruct( /*IN*/ComplexTypes c ) { _complexTypes = c; } + public void raiseRuntimeException( ) { throw new RuntimeException(); } +} + +} 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..a4b179b05634 --- /dev/null +++ b/testtools/source/performance/makefile.mk @@ -0,0 +1,98 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2000, 2010 Oracle and/or its affiliates. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org 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 version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* + +PRJ=..$/.. + +PRJNAME=testtools +TARGET=performancetest +ENABLE_EXCEPTIONS=TRUE +USE_DEFFILE=TRUE +LIBTARGET=NO + +# --- Settings ----------------------------------------------------- + +.INCLUDE : settings.mk + +# ------------------------------------------------------------------ + +LIB1TARGET=$(SLB)$/perftest.lib +LIB1OBJFILES= \ + $(SLO)$/ubtest.obj + +SHL1TARGET = perftest.uno + +SHL1VERSIONMAP = $(SOLARENV)$/src$/component.map + +SHL1STDLIBS= \ + $(CPPULIB) \ + $(CPPUHELPERLIB) \ + $(SALLIB) + +SHL1LIBS= $(LIB1TARGET) +SHL1DEF= $(MISC)$/$(SHL1TARGET).def +DEF1NAME= $(SHL1TARGET) + +# ---- test object ---- + +LIB2TARGET=$(SLB)$/perfobj.lib +LIB2OBJFILES= \ + $(SLO)$/ubobject.obj + +SHL2TARGET = perfobj.uno + +SHL2VERSIONMAP = $(SOLARENV)$/src$/component.map + +SHL2STDLIBS= \ + $(CPPULIB) \ + $(CPPUHELPERLIB) \ + $(SALLIB) + +SHL2LIBS= $(LIB2TARGET) +SHL2DEF= $(MISC)$/$(SHL2TARGET).def +DEF2NAME= $(SHL2TARGET) + +# ---- pseudo uno bridge ---- + +LIB3TARGET=$(SLB)$/pseudo.lib +LIB3OBJFILES= \ + $(SLO)$/pseudo.obj + +SHL3TARGET=pseudo_uno_uno + +SHL3VERSIONMAP = pseudo_uno_uno.map + +SHL3STDLIBS= \ + $(CPPULIB) \ + $(SALLIB) + +SHL3LIBS= $(LIB3TARGET) +SHL3DEF= $(MISC)$/$(SHL3TARGET).def +DEF3NAME= $(SHL3TARGET) + +# --- Targets ------------------------------------------------------ + +.INCLUDE : target.mk diff --git a/testtools/source/performance/pseudo.cxx b/testtools/source/performance/pseudo.cxx new file mode 100644 index 000000000000..a6f9d63b500d --- /dev/null +++ b/testtools/source/performance/pseudo.cxx @@ -0,0 +1,274 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_testtools.hxx" +#include <osl/diagnose.h> +#include <osl/interlck.h> +#include <rtl/ustring.hxx> +#include <typelib/typedescription.h> +#include <uno/dispatcher.h> +#include <uno/environment.h> +#include <uno/mapping.h> +#include <uno/lbnames.h> + +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 ); + +#if OSL_DEBUG_LEVEL > 1 + *(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" void SAL_CALL uno_initEnvironment( uno_Environment * pUnoEnv ) +{ + OSL_ENSURE( sal_False, "### no impl: unexpected call!" ); +} +//################################################################################################## +extern "C" 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; + } +} diff --git a/testtools/source/performance/pseudo_uno_uno.map b/testtools/source/performance/pseudo_uno_uno.map new file mode 100644 index 000000000000..6399ed5720ad --- /dev/null +++ b/testtools/source/performance/pseudo_uno_uno.map @@ -0,0 +1,7 @@ +UDK_3_0_0 { + global: + uno_initEnvironment; + uno_ext_getMapping; + local: + *; +}; diff --git a/testtools/source/performance/ubobject.cxx b/testtools/source/performance/ubobject.cxx new file mode 100644 index 000000000000..e1e4c414c06a --- /dev/null +++ b/testtools/source/performance/ubobject.cxx @@ -0,0 +1,308 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_testtools.hxx" + +#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() + { osl_incrementInterlockedCount( &_nRef ); } + virtual void SAL_CALL release() throw() + { 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; +} +} diff --git a/testtools/source/performance/ubtest.cxx b/testtools/source/performance/ubtest.cxx new file mode 100644 index 000000000000..af174d8f306a --- /dev/null +++ b/testtools/source/performance/ubtest.cxx @@ -0,0 +1,1337 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_testtools.hxx" + +#include <stdio.h> +#include <math.h> +#include <string> +#include <hash_map> +#include <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> +#include <osl/time.h> + +#ifdef SAL_W32 +#include <windows.h> +#else +#include <sys/times.h> +#include <unistd.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 = sysconf(_SC_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]; + ::snprintf( ar, sizeof(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]; + ::snprintf( ar, sizeof(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, &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 ); +#if OSL_DEBUG_LEVEL > 1 + out ("; compiled with OSL_DEBUG_LEVEL > 1", 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; +} +} diff --git a/testtools/source/servicetests/LocalServiceTest.java b/testtools/source/servicetests/LocalServiceTest.java new file mode 100644 index 000000000000..bb12235d1b37 --- /dev/null +++ b/testtools/source/servicetests/LocalServiceTest.java @@ -0,0 +1,53 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +package testtools.servicetests; + +import com.sun.star.comp.helper.Bootstrap; +import com.sun.star.container.XSet; +import com.sun.star.lang.XMultiComponentFactory; +import com.sun.star.uno.UnoRuntime; +import com.sun.star.uno.XComponentContext; + +public final class LocalServiceTest extends TestBase { + protected TestServiceFactory getTestServiceFactory() throws Exception { + return new TestServiceFactory() { + public Object get() throws Exception { + XComponentContext context + = Bootstrap.createInitialComponentContext(null); + XMultiComponentFactory serviceManager + = context.getServiceManager(); + UnoRuntime.queryInterface(XSet.class, serviceManager). + insert(new TestService()); + return serviceManager.createInstanceWithContext( + "testtools.servicetests.TestService2", context); + } + + public void dispose() throws Exception {} + }; + } +} diff --git a/testtools/source/servicetests/RemoteServiceTest.java b/testtools/source/servicetests/RemoteServiceTest.java new file mode 100644 index 000000000000..8abf6674f1e5 --- /dev/null +++ b/testtools/source/servicetests/RemoteServiceTest.java @@ -0,0 +1,121 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +package testtools.servicetests; + +import com.sun.star.bridge.XBridgeFactory; +import com.sun.star.bridge.XInstanceProvider; +import com.sun.star.bridge.UnoUrlResolver; +import com.sun.star.comp.helper.Bootstrap; +import com.sun.star.connection.Acceptor; +import com.sun.star.connection.XConnection; +import com.sun.star.container.XSet; +import com.sun.star.lang.XMultiComponentFactory; +import com.sun.star.uno.UnoRuntime; +import com.sun.star.uno.XComponentContext; +import complexlib.ComplexTestCase; +import java.io.BufferedReader; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.PrintStream; + +public final class RemoteServiceTest extends TestBase { + protected TestServiceFactory getTestServiceFactory() throws Exception { + final Process p = Runtime.getRuntime().exec(new String[] { + "java", "-classpath", System.getProperty("java.class.path"), + Server.class.getName() }); + pipe(p.getInputStream(), System.out, "CO> "); + pipe(p.getErrorStream(), System.err, "CE> "); + Thread.sleep(5000); // wait for server to start accepting + return new TestServiceFactory() { + public Object get() throws Exception { + return (UnoUrlResolver.create( + Bootstrap.createInitialComponentContext(null))). + resolve( + "uno:" + CONNECTION_DESCRIPTION + ";" + + PROTOCOL_DESCRIPTION + + ";testtools.servicetests.TestService2"); + } + + public void dispose() throws Exception { + p.waitFor(); + } + }; + } + + public static final class Server { + public static void main(String[] arguments) throws Exception { + XComponentContext context + = Bootstrap.createInitialComponentContext(null); + XMultiComponentFactory serviceManager + = context.getServiceManager(); + UnoRuntime.queryInterface(XSet.class, serviceManager). + insert(new TestService()); + final Object instance = serviceManager.createInstanceWithContext( + "testtools.servicetests.TestService2", context); + XBridgeFactory bridgeFactory + = UnoRuntime.queryInterface( + XBridgeFactory.class, + serviceManager.createInstanceWithContext( + "com.sun.star.bridge.BridgeFactory", context)); + XConnection connection = Acceptor.create(context).accept( + CONNECTION_DESCRIPTION); + bridgeFactory.createBridge( + "", PROTOCOL_DESCRIPTION, connection, + new XInstanceProvider() { + public Object getInstance(String instanceName) { + return instance; + } + }); + } + } + + private void pipe(final InputStream in, final PrintStream out, + final String prefix) { + new Thread("Pipe: " + prefix) { + public void run() { + BufferedReader r + = new BufferedReader(new InputStreamReader(in)); + try { + for (;;) { + String s = r.readLine(); + if (s == null) { + break; + } + out.println(prefix + s); + } + } catch (java.io.IOException e) { + e.printStackTrace(System.err); + } + } + }.start(); + } + + private static final String CONNECTION_DESCRIPTION + = "socket,host=localhost,port=12345"; + private static final String PROTOCOL_DESCRIPTION = "urp"; +} diff --git a/testtools/source/servicetests/TestBase.java b/testtools/source/servicetests/TestBase.java new file mode 100644 index 000000000000..248ff96007e2 --- /dev/null +++ b/testtools/source/servicetests/TestBase.java @@ -0,0 +1,145 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +package testtools.servicetests; + +import com.sun.star.uno.UnoRuntime; +import complexlib.ComplexTestCase; +import util.WaitUnreachable; + +public abstract class TestBase extends ComplexTestCase { + public final String[] getTestMethodNames() { + return new String[] { "test" }; + } + + public final void test() throws Exception { + TestServiceFactory factory = getTestServiceFactory(); + TestService2 t = UnoRuntime.queryInterface( + TestService2.class, factory.get()); + assure(t != null); + assure(UnoRuntime.queryInterface(TestService1.class, t) == t); + assure(UnoRuntime.queryInterface(XTestService1.class, t) == t); + assure(UnoRuntime.queryInterface(XTestService2.class, t) == t); + assure(t.fn1() == 1); + assure(t.getProp1() == 1); + t.setProp1(0); + assure(t.getProp1() == 0); + assure(t.getProp2() == 2); + /*try { + t.getProp3Void(); + failed(); + } catch (VoidPropertyException e) { + }*/ + assure(t.getProp3Long() == 3); + /*try { + t.getProp4None(); + failed(); + } catch (OptionalPropertyException e) { + }*/ + assure(t.getProp4Long() == 4); + /*try { + t.getProp5None(); + failed(); + } catch (OptionalPropertyException e) { + } + try { + t.getProp5Void(); + failed(); + } catch (VoidPropertyException e) { + }*/ + assure(t.getProp5Long() == 5); + assure(t.getProp6() == 6); + /*t.clearProp6(); + try { + t.getProp6(); + failed(); + } catch (VoidPropertyException e) { + }*/ + t.setProp6(0); + assure(t.getProp6() == 0); + /*try { + t.getProp7None(); + failed(); + } catch (OptionalPropertyException e) { + } + try { + t.setProp7None(0); + failed(); + } catch (OptionalPropertyException e) { + } + try { + t.clearProp7None(); + failed(); + } catch (OptionalPropertyException e) { + }*/ + assure(t.getProp7() == 7); + /*t.clearProp7(); + try { + t.getProp7(); + failed(); + } catch (VoidPropertyException e) { + }*/ + t.setProp7(0); + assure(t.getProp7() == 0); + /*try { + t.getProp8None(); + failed(); + } catch (OptionalPropertyException e) { + } + try { + t.setProp8None(0); + failed(); + } catch (OptionalPropertyException e) { + }*/ + assure(t.getProp8Long() == 8); + t.setProp8Long(0); + assure(t.getProp8Long() == 0); + assure(t.fn2() == 2); + XTestService3 t3 = UnoRuntime.queryInterface(XTestService3.class, t); + assure(t3 != null); + assure(t3.fn3() == 3); + XTestService4 t4 = UnoRuntime.queryInterface(XTestService4.class, t); + assure(t4 == null); + WaitUnreachable u = new WaitUnreachable(t); + t = null; + WaitUnreachable.ensureFinalization(t3); + t3 = null; + WaitUnreachable.ensureFinalization(t4); + t4 = null; + u.waitUnreachable(); + factory.dispose(); + } + + protected abstract TestServiceFactory getTestServiceFactory() + throws Exception; + + protected interface TestServiceFactory { + Object get() throws Exception; + + void dispose() throws Exception; + } +} diff --git a/testtools/source/servicetests/TestService.java b/testtools/source/servicetests/TestService.java new file mode 100644 index 000000000000..279aaabe4b70 --- /dev/null +++ b/testtools/source/servicetests/TestService.java @@ -0,0 +1,197 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +package testtools.servicetests; + +import com.sun.star.lang.NoSupportException; +import com.sun.star.lang.XServiceInfo; +import com.sun.star.lang.XSingleComponentFactory; +/*import com.sun.star.uno.OptionalPropertyException;*/ +/*import com.sun.star.uno.VoidPropertyException;*/ +import com.sun.star.uno.XComponentContext; + +public final class TestService implements XServiceInfo, XSingleComponentFactory +{ + public String getImplementationName() { + return getClass().getName(); + } + + public boolean supportsService(String serviceName) { + return serviceName.equals(SERVICE_NAME); + } + + public String[] getSupportedServiceNames() { + return new String[] { SERVICE_NAME }; + } + + public Object createInstanceWithContext(XComponentContext context) + throws com.sun.star.uno.Exception + { + return new Service(); + } + + public Object createInstanceWithArgumentsAndContext( + Object[] arguments, XComponentContext context) + throws com.sun.star.uno.Exception + { + throw new NoSupportException( + "createInstanceWithArgumentsAndContext", this); + } + + private static final class Service implements TestService2, XTestService3 { + public int fn1() { + return 1; + } + + public int getProp1() { + return prop1; + } + + public void setProp1(int value) { + prop1 = value; + } + + public int getProp2() { + return 2; + } + + /*public int getProp3Void() throws VoidPropertyException { + throw new VoidPropertyException("Prop3Void", this); + }*/ + + public int getProp3Long() /*throws VoidPropertyException*/ { + return 3; + } + + /*public int getProp4None() throws OptionalPropertyException { + throw new OptionalPropertyException("Prop4None", this); + }*/ + + public int getProp4Long() /*throws OptionalPropertyException*/ { + return 4; + } + + /*public int getProp5None() + throws OptionalPropertyException, VoidPropertyException + { + throw new OptionalPropertyException("Prop4None", this); + }*/ + + /*public int getProp5Void() + throws OptionalPropertyException, VoidPropertyException + { + throw new VoidPropertyException("Prop4None", this); + }*/ + + public int getProp5Long() + /*throws OptionalPropertyException, VoidPropertyException*/ + { + return 5; + } + + public int getProp6() /*throws VoidPropertyException*/ { + /*if (prop6 == null) { + throw new VoidPropertyException("Prop6", this); + } else {*/ + return prop6.intValue(); + /*}*/ + } + + public void setProp6(int value) { + prop6 = new Integer(value); + } + + /*public void clearProp6() { + prop6 = null; + }*/ + + /*public int getProp7None() + throws OptionalPropertyException, VoidPropertyException + { + throw new OptionalPropertyException("Prop7None", this); + }*/ + + /*public void setProp7None(int value) throws OptionalPropertyException { + throw new OptionalPropertyException("Prop7None", this); + }*/ + + /*public void clearProp7None() throws OptionalPropertyException { + throw new OptionalPropertyException("Prop7None", this); + }*/ + + public int getProp7() + /*throws OptionalPropertyException, VoidPropertyException*/ + { + /*if (prop7 == null) { + throw new VoidPropertyException("Prop7", this); + } else {*/ + return prop7.intValue(); + /*}*/ + } + + public void setProp7(int value) /*throws OptionalPropertyException*/ { + prop7 = new Integer(value); + } + + /*public void clearProp7() throws OptionalPropertyException { + prop7 = null; + }*/ + + /*public int getProp8None() throws OptionalPropertyException { + throw new OptionalPropertyException("Prop8None", this); + }*/ + + /*public void setProp8None(int value) throws OptionalPropertyException { + throw new OptionalPropertyException("Prop8None", this); + }*/ + + public int getProp8Long() /*throws OptionalPropertyException*/ { + return prop8; + } + + public void setProp8Long(int value) /*throws OptionalPropertyException*/ + { + prop8 = value; + } + + public int fn2() { + return 2; + } + + public int fn3() { + return 3; + } + + private int prop1 = 1; + private Integer prop6 = new Integer(6); + private Integer prop7 = new Integer(7); + private int prop8 = 8; + } + + private static final String SERVICE_NAME + = "testtools.servicetests.TestService2"; +} diff --git a/testtools/source/servicetests/TestService1.idl b/testtools/source/servicetests/TestService1.idl new file mode 100644 index 000000000000..3bf04c6cdc5f --- /dev/null +++ b/testtools/source/servicetests/TestService1.idl @@ -0,0 +1,55 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef __testtools_servicetests_TestService1_idl__ +#define __testtools_servicetests_TestService1_idl__ + +#include "XTestService1.idl" + +module testtools { module servicetests { + +interface TestService1 { + interface XTestService1; + [attribute] long Prop1; + [attribute, readonly] long Prop2; + /*[attribute, readonly, maybevoid] long Prop3Void;*/ + [attribute, readonly/*, maybevoid*/] long Prop3Long; + /*[attribute, readonly, optional] long Prop4None;*/ + [attribute, readonly/*, optional*/] long Prop4Long; + /*[attribute, readonly, maybevoid, optional] long Prop5None;*/ + /*[attribute, readonly, maybevoid, optional] long Prop5Void;*/ + [attribute, readonly/*, maybevoid, optional*/] long Prop5Long; + [attribute/*, maybevoid*/] long Prop6; + /*[attribute, maybevoid, optional] long Prop7None;*/ + [attribute/*, maybevoid, optional*/] long Prop7; + /*[attribute, optional] long Prop8None;*/ + [attribute/*, optional*/] long Prop8Long; +}; + +}; }; + +#endif diff --git a/testtools/source/servicetests/TestService2.idl b/testtools/source/servicetests/TestService2.idl new file mode 100644 index 000000000000..cf487bcd8dc2 --- /dev/null +++ b/testtools/source/servicetests/TestService2.idl @@ -0,0 +1,47 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef __testtools_servicetests_TestService2_idl__ +#define __testtools_servicetests_TestService2_idl__ + +#include "TestService1.idl" +#include "XTestService2.idl" +#include "XTestService3.idl" +#include "XTestService4.idl" + +module testtools { module servicetests { + +interface TestService2 { + interface TestService1; + interface XTestService2; + /*[optional] interface XTestService3;*/ + /*[optional] interface XTestService4;*/ +}; + +}; }; + +#endif diff --git a/testtools/source/servicetests/XTestService1.idl b/testtools/source/servicetests/XTestService1.idl new file mode 100644 index 000000000000..6d6bf1e44802 --- /dev/null +++ b/testtools/source/servicetests/XTestService1.idl @@ -0,0 +1,41 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef __testtools_servicetests_XTestService1_idl__ +#define __testtools_servicetests_XTestService1_idl__ + +#include <com/sun/star/uno/XInterface.idl> + +module testtools { module servicetests { + +interface XTestService1: com::sun::star::uno::XInterface { + long fn1(); +}; + +}; }; + +#endif diff --git a/testtools/source/servicetests/XTestService2.idl b/testtools/source/servicetests/XTestService2.idl new file mode 100644 index 000000000000..be7de2437244 --- /dev/null +++ b/testtools/source/servicetests/XTestService2.idl @@ -0,0 +1,41 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef __testtools_servicetests_XTestService2_idl__ +#define __testtools_servicetests_XTestService2_idl__ + +#include <com/sun/star/uno/XInterface.idl> + +module testtools { module servicetests { + +interface XTestService2: com::sun::star::uno::XInterface { + long fn2(); +}; + +}; }; + +#endif diff --git a/testtools/source/servicetests/XTestService3.idl b/testtools/source/servicetests/XTestService3.idl new file mode 100644 index 000000000000..1933ecf729e6 --- /dev/null +++ b/testtools/source/servicetests/XTestService3.idl @@ -0,0 +1,41 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef __testtools_servicetests_XTestService3_idl__ +#define __testtools_servicetests_XTestService3_idl__ + +#include <com/sun/star/uno/XInterface.idl> + +module testtools { module servicetests { + +interface XTestService3: com::sun::star::uno::XInterface { + long fn3(); +}; + +}; }; + +#endif diff --git a/testtools/source/servicetests/XTestService4.idl b/testtools/source/servicetests/XTestService4.idl new file mode 100644 index 000000000000..5d7e80c9a8ed --- /dev/null +++ b/testtools/source/servicetests/XTestService4.idl @@ -0,0 +1,41 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef __testtools_servicetests_XTestService4_idl__ +#define __testtools_servicetests_XTestService4_idl__ + +#include <com/sun/star/uno/XInterface.idl> + +module testtools { module servicetests { + +interface XTestService4: com::sun::star::uno::XInterface { + long fn4(); +}; + +}; }; + +#endif diff --git a/testtools/source/servicetests/makefile.mk b/testtools/source/servicetests/makefile.mk new file mode 100644 index 000000000000..d92d9775821e --- /dev/null +++ b/testtools/source/servicetests/makefile.mk @@ -0,0 +1,44 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2000, 2010 Oracle and/or its affiliates. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org 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 version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* + +PRJ := ..$/.. +PRJNAME := testtools +TARGET := testtools_servicetests + +PACKAGE := testtools$/servicetests +JAVATESTFILES := LocalServiceTest.java RemoteServiceTest.java +JAVAFILES := TestBase.java TestService.java +IDLTESTFILES := \ + TestService1.idl \ + TestService2.idl \ + XTestService1.idl \ + XTestService2.idl \ + XTestService3.idl \ + XTestService4.idl +JARFILES := juh.jar jurt.jar ridl.jar + +.INCLUDE: javaunittest.mk diff --git a/testtools/util/makefile.pmk b/testtools/util/makefile.pmk new file mode 100644 index 000000000000..6a3ea0d706e4 --- /dev/null +++ b/testtools/util/makefile.pmk @@ -0,0 +1,35 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2000, 2010 Oracle and/or its affiliates. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org 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 version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* + +# no translation here anyway +.IF "$(L10N_framework)"=="" +.IF "$(COM)" == "MSC" +BUILD_FOR_CLI = "true" +CFLAGSENABLESYMBOLS:=-Z7 +.ENDIF +.ENDIF # "L10N_framework"=="" + |