diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 16:51:28 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 16:51:28 +0000 |
commit | 940b4d1848e8c70ab7642901a68594e8016caffc (patch) | |
tree | eb72f344ee6c3d9b80a7ecc079ea79e9fba8676d /testtools/source | |
parent | Initial commit. (diff) | |
download | libreoffice-940b4d1848e8c70ab7642901a68594e8016caffc.tar.xz libreoffice-940b4d1848e8c70ab7642901a68594e8016caffc.zip |
Adding upstream version 1:7.0.4.upstream/1%7.0.4upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testtools/source')
60 files changed, 13661 insertions, 0 deletions
diff --git a/testtools/source/bridgetest/bridgetest.component b/testtools/source/bridgetest/bridgetest.component new file mode 100644 index 000000000..ecbd2e333 --- /dev/null +++ b/testtools/source/bridgetest/bridgetest.component @@ -0,0 +1,25 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + --> + +<component loader="com.sun.star.loader.SharedLibrary" environment="@CPPU_ENV@" + xmlns="http://openoffice.org/2010/uno-components"> + <implementation name="com.sun.star.comp.bridge.BridgeTest"> + <service name="com.sun.star.test.bridge.BridgeTest"/> + </implementation> +</component> diff --git a/testtools/source/bridgetest/bridgetest.cxx b/testtools/source/bridgetest/bridgetest.cxx new file mode 100644 index 000000000..160c95998 --- /dev/null +++ b/testtools/source/bridgetest/bridgetest.cxx @@ -0,0 +1,1316 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + + +#include <stdio.h> +#include <string.h> +#include <o3tl/any.hxx> +#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/lbnames.h> +#include <uno/mapping.hxx> +#include <uno/data.h> +#include <uno/environment.hxx> + +#include <cppuhelper/factory.hxx> +#include <cppuhelper/implbase.hxx> +#include <cppuhelper/supportsservice.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/XSingleComponentFactory.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" +#include <memory> + +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 STRING_TEST_CONSTANT "\" paco\' chorizo\\\' \"\'" + +namespace bridge_test +{ +template<typename T, typename U = T> +static Sequence<T> cloneSequence(const Sequence<T>& val); + + +static Sequence< OUString > getSupportedServiceNames() +{ + return { SERVICENAME }; +} + +static bool check( bool b , char const * message ) +{ + if ( ! b ) + fprintf( stderr, "%s failed\n" , message ); + return b; +} + +namespace { + +bool checkEmpty(OUString const & string, char const * message) { + bool ok = string.isEmpty(); + if (!ok) { + fprintf( + stderr, "%s failed: %s\n", message, + OUStringToOString(string, RTL_TEXTENCODING_UTF8).getStr()); + } + return ok; +} + +class TestBridgeImpl : public osl::DebugBase<TestBridgeImpl>, + public WeakImplHelper< XMain, XServiceInfo > +{ + Reference< XComponentContext > m_xContext; + +public: + explicit TestBridgeImpl( const Reference< XComponentContext > & xContext ) + : m_xContext( xContext ) + {} + + // XServiceInfo + virtual OUString SAL_CALL getImplementationName() override; + virtual sal_Bool SAL_CALL supportsService( const OUString & rServiceName ) override; + virtual Sequence< OUString > SAL_CALL getSupportedServiceNames() override; + + // XMain + virtual sal_Int32 SAL_CALL run( const Sequence< OUString > & rArgs ) override; +}; + +} + +static 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.Byte2 == rData2.Byte2, "### byte2 does not match!" ); + check( rData1.Short2 == rData2.Short2, "### short2 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.Byte2 == rData2.Byte2 && + rData1.Short2 == rData2.Short2 && + rData1.Interface == rData2.Interface && + rData1.Any == rData2.Any); +} + +static bool equals( const TestData & rData1, const TestData & rData2 ) +{ + sal_Int32 nLen; + + if (rData1.Sequence != rData2.Sequence) + return false; + if (!equals( static_cast<const TestElement &>(rData1), static_cast<const TestElement &>(rData2) )) + return false; + nLen = rData1.Sequence.getLength(); + if (nLen == 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( false, "### sequence element did not match!" ); + return false; + } + } + return true; + } + return false; +} + +static void assign( TestElement & rData, + 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 OUString& rStr, + sal_Int8 nByte2, sal_Int16 nShort2, + const css::uno::Reference< css::uno::XInterface >& xTest, + const css::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.Byte2 = nByte2; + rData.Short2 = nShort2; + rData.Interface = xTest; + rData.Any = rAny; +} + +namespace { + +template < typename T > +bool testAny( + T const & value, Reference< XBridgeTest > const & xLBT, + char const * typeName = nullptr) +{ + 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 != nullptr + && !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 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.Byte2 ,xLBT ) && bReturn; + bReturn = testAny( data.Short2,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 <<= data.Bool; + OSL_ASSERT( xLBT->transportAny( a ) == a ); + } + + { + a <<= data.Char; + OSL_ASSERT( xLBT->transportAny( a ) == a ); + } + + return bReturn; +} + + +static 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(); +} + +namespace { + +class ORecursiveCall : public WeakImplHelper< XRecursiveCall > +{ +private: + Mutex m_mutex; + +public: + void SAL_CALL callRecursivly( + const css::uno::Reference< XRecursiveCall >& xCall, + sal_Int32 nToCall ) override + { + MutexGuard guard( m_mutex ); + if( nToCall ) + { + nToCall --; + xCall->callRecursivly( this , nToCall ); + } + + } +}; + +} + +static bool performRecursiveCallTest( const Reference < XBridgeTest > & xLBT ) +{ + xLBT->startRecursiveCall( new ORecursiveCall , 50 ); + // on failure, the test would lock up or crash + return true; +} + +namespace { + +class MyClass : public osl::DebugBase<MyClass>, public OWeakObject +{ +public: + MyClass(); +}; + +} + +MyClass::MyClass() +{ +} + +static 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( + static_cast<TestElement &>(aData), true, '@', 17, 0x1234, 0xFEDC, + 0x12345678, 0xFEDCBA98, SAL_CONST_INT64(0x123456789ABCDEF0), + SAL_CONST_UINT64(0xFEDCBA9876543210), 17.0815f, 3.1415926359, + TestEnum_LOLA, STRING_TEST_CONSTANT, 18, 0x5678, xI, + Any(&xI, cppu::UnoType<XInterface>::get())); + bRet &= check(aData.Any == xI, "### unexpected any!"); + bRet &= check(!(aData.Any != xI), "### unexpected any!"); + aData.Sequence.realloc(2); + aData.Sequence[0] = *static_cast<TestElement const *>(&aData); + // aData.Sequence[1] is empty + // aSetData is a manually copy of aData for first setting: + TestData aSetData; + 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, aData.Byte2, aData.Short2, xI, Any(&xI, cppu::UnoType<XInterface>::get())); + aSetData.Sequence.realloc(2); + aSetData.Sequence[0] = *static_cast<TestElement const *>(&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.Byte2, + aSetData.Short2, + aSetData.Interface, + aSetData.Any, + aSetData.Sequence, + aSetData); + { + TestData aRet; + TestData 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.Byte2, + aRet.Short2, + aRet.Interface, + aRet.Any, + aRet.Sequence, + aRet2); + bRet &= check( + equals(aData, aRet) && equals(aData, aRet2), "getValues test"); + // 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.Byte2, + aRet.Short2, + 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"); + } + { + TwoFloats aIn(1.1f, 2.2f); + TwoFloats aOut = xLBT->echoTwoFloats(aIn); + bRet = check( memcmp(&aIn, &aOut, sizeof(TwoFloats)) == 0, "two floats struct test" ) && bRet; + } + { + FourFloats aIn(3.3f, 4.4f, 5.5f, 6.6f); + FourFloats aOut = xLBT->echoFourFloats(aIn); + bRet = check( memcmp(&aIn, &aOut, sizeof(FourFloats)) == 0, "four floats struct test" ) && bRet; + } + { + MixedFloatAndInteger aIn(7.7f, 8); + MixedFloatAndInteger aOut = xLBT->echoMixedFloatAndInteger(aIn); + bRet = check( memcmp(&aIn, &aOut, sizeof(MixedFloatAndInteger)) == 0, "mixed float and integer struct test" ) && bRet; + } + { + ThreeByteStruct aIn(9, 10, 11); + ThreeByteStruct aOut = xLBT->echoThreeByteStruct(aIn); + bRet = check( memcmp(&aIn, &aOut, sizeof(ThreeByteStruct)) == 0, "three byte struct test" ) && bRet; + } + { + TestData aRet; + TestData 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.Byte2, + aRet.Short2, + aRet.Interface, + aRet.Any, + aRet.Sequence, + aRet2)); + bRet &= check( + (equals(aData, aRet) && equals(aData, aRet2) && + equals(aData, aGVret)), + "getValues test"); + // 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->setByte2(aRet.Byte2); + xLBT->setShort2(aRet.Short2); + xLBT->setInterface(aRet.Interface); + xLBT->setAny(aRet.Any); + xLBT->setSequence(aRet.Sequence); + xLBT->setStruct(aRet2); + } + { + TestData aRet; + 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.Byte2 = xLBT->getByte2(); + aRet.Short2 = xLBT->getShort2(); + aRet.Interface = xLBT->getInterface(); + aRet.Any = xLBT->getAny(); + aRet.Sequence = xLBT->getSequence(); + TestData aRet2(xLBT->getStruct()); + bRet &= check( + equals(aData, aRet) && equals(aData, aRet2), + "struct comparison test"); + { + SmallStruct aIn(1, 2); + SmallStruct aOut(xLBT->echoSmallStruct(aIn)); + bRet &= check( + memcmp(&aIn, &aOut, sizeof(SmallStruct)) == 0, + "small struct test"); + } + { + MediumStruct aIn(1, 2, 3, 4); + MediumStruct aOut(xLBT->echoMediumStruct(aIn)); + bRet &= check( + memcmp(&aIn, &aOut, sizeof(MediumStruct)) == 0, + "medium struct test"); + } + { + 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"); + } + { + sal_Int32 i2 = xLBT->testPPCAlignment(0, 0, 0, 0, 0xBEAF); + bRet &= check(i2 == 0xBEAF, "ppc-style alignment test"); + } + { + sal_Int32 i1 = xLBT->testPPC64Alignment(1.0, 2.0, 3.0, 0xBEAF); + bRet &= check(i1 == 0xBEAF, "ppc64-style alignment test"); + } + { + double d1 = xLBT->testTenDoubles(0.1, 0.2, 0.3, 0.4, 0.5, + 0.6, 0.7, 0.8, 0.9, 1.0); + bRet &= check(d1 == 5.5, "armhf doubles test"); + } + // Test extended attributes that raise exceptions: + try { + xLBT->getRaiseAttr1(); + bRet &= check(false, "getRaiseAttr1 did not throw"); + } catch (const RuntimeException &) { + } catch (...) { + bRet &= check(false, "getRaiseAttr1 threw wrong type"); + } + try { + xLBT->setRaiseAttr1(0); + bRet &= check(false, "setRaiseAttr1 did not throw"); + } catch (const IllegalArgumentException &) { + } catch (...) { + bRet &= check(false, "setRaiseAttr1 threw wrong type"); + } + try { + xLBT->getRaiseAttr2(); + bRet &= check(false, "getRaiseAttr2 did not throw"); + } catch (const 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] <<= OUString("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"); + OUString v1; + tps3.member[1] >>= v1; + bRet &= check( v1 == "ABC", "transportPolySequence, element 1" ); + bRet &= check( + xLBT->getNullPolyLong().member == 0, "getNullPolyLong"); + bRet &= check( + xLBT->getNullPolyString().member.isEmpty(), + "getNullPolyString"); + bRet &= check( + xLBT->getNullPolyType().member == Type(), + "getNullPolyType"); + Any nullAny(xLBT->getNullPolyAny().member); + auto ifc = o3tl::tryAccess<Reference<XInterface>>(nullAny); + bRet &= check( + !nullAny.hasValue() || (ifc && !ifc->is()), + "getNullPolyAny"); + bRet &= check( + !xLBT->getNullPolySequence().member.hasElements(), + "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"); + // Sequence of call test: + bRet &= check( + performSequenceOfCallTest(xLBT), "sequence of call test"); + // Recursive call test: + bRet &= check(performRecursiveCallTest(xLBT), "recursive test"); + bRet &= check( + equals(aData, aRet) && equals(aData, aRet2), + "recursive test results"); + // 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 is + // compared with the results: + sal_Int32 _arLong[] = { + static_cast< sal_Int32 >(0x80000000), 1, 0x7FFFFFFF }; + sal_Int32 _aInt = 0xBABEBABE; + float _aFloat = 3.14f; + Any _any1(true); + Any _any2(&_aInt, cppu::UnoType<sal_Int32>::get()); + Any _any3(&_aFloat, cppu::UnoType<float>::get()); + Any _arAny[] = { _any1, _any2, _any3 }; + Reference< XInterface > _arObj[3]; + _arObj[0] = new OWeakObject(); + _arObj[1] = new OWeakObject(); + _arObj[2] = new OWeakObject(); + TestElement _arStruct[3]; + assign( + _arStruct[0], true, '@', 17, 0x1234, 0xFEDC, 0x12345678, 0xFEDCBA98, + SAL_CONST_INT64(0x123456789ABCDEF0), + SAL_CONST_UINT64(0xFEDCBA9876543210), 17.0815f, 3.1415926359, + TestEnum_LOLA, STRING_TEST_CONSTANT, 18, 0x5678, _arObj[0], + Any(&_arObj[0], cppu::UnoType<XInterface>::get())); + assign( + _arStruct[1], true, 'A', 17, 0x1234, 0xFEDC, 0x12345678, 0xFEDCBA98, + SAL_CONST_INT64(0x123456789ABCDEF0), + SAL_CONST_UINT64(0xFEDCBA9876543210), 17.0815f, 3.1415926359, + TestEnum_TWO, STRING_TEST_CONSTANT, 18, 0x5678, _arObj[1], + Any(&_arObj[1], cppu::UnoType<XInterface>::get())); + assign( + _arStruct[2], true, 'B', 17, 0x1234, 0xFEDC, 0x12345678, 0xFEDCBA98, + SAL_CONST_INT64(0x123456789ABCDEF0), + SAL_CONST_UINT64(0xFEDCBA9876543210), 17.0815f, 3.1415926359, + TestEnum_CHECK, STRING_TEST_CONSTANT, 18, 0x5678, _arObj[2], + Any(&_arObj[2], cppu::UnoType<XInterface>::get())); + { + Sequence<sal_Bool> arBool({true, false, true}); + Sequence<sal_Unicode> arChar({0x0065, 0x0066, 0x0067}); + Sequence<sal_Int8> arByte({1, 2, -1}); + Sequence<sal_Int16> arShort({-0x8000, 1, 0x7FFF}); + Sequence<sal_uInt16> arUShort({0 , 1, 0xFFFF}); + Sequence<sal_Int32> arLong(_arLong, 3); + Sequence<sal_uInt32> arULong({0, 1, 0xFFFFFFFF}); + Sequence<sal_Int64> arHyper({ + static_cast<sal_Int64>(SAL_CONST_INT64(0x8000000000000000)), 1, + SAL_CONST_INT64(0x7FFFFFFFFFFFFFFF)}); + Sequence<sal_uInt64> arUHyper({ + 0, 1, SAL_CONST_UINT64(0xFFFFFFFFFFFFFFFF)}); + Sequence<float> arFloat({1.1f, 2.2f, 3.3f}); + Sequence<double> arDouble({1.11, 2.22, 3.33}); + Sequence<OUString> arString({ + OUString("String 1"), OUString("String 2"), + OUString("String 3")}); + Sequence<Any> arAny(_arAny, 3); + Sequence<Reference<XInterface> > arObject(_arObj, 3); + Sequence<TestEnum> arEnum({ + TestEnum_ONE, TestEnum_TWO, TestEnum_CHECK}); + 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"); + Sequence< Sequence< Sequence< sal_Int32 > > > seqSeqRet2( + xBT2->setDim3(arLong3)); + bRet &= check(seqSeqRet2 == arLong3, "sequence test"); + Sequence< Any > seqAnyRet(xBT2->setSequenceAny(arAny)); + bRet &= check(seqAnyRet == arAny, "sequence test"); + Sequence< sal_Bool > seqBoolRet(xBT2->setSequenceBool(arBool)); + bRet &= check(seqBoolRet == arBool, "sequence test"); + Sequence< sal_Int8 > seqByteRet(xBT2->setSequenceByte(arByte)); + bRet &= check(seqByteRet == arByte, "sequence test"); + Sequence< sal_Unicode > seqCharRet(xBT2->setSequenceChar(arChar)); + bRet &= check(seqCharRet == arChar, "sequence test"); + Sequence< sal_Int16 > seqShortRet(xBT2->setSequenceShort(arShort)); + bRet &= check(seqShortRet == arShort, "sequence test"); + Sequence< sal_Int32 > seqLongRet(xBT2->setSequenceLong(arLong)); + bRet &= check(seqLongRet == arLong, "sequence test"); + Sequence< sal_Int64 > seqHyperRet(xBT2->setSequenceHyper(arHyper)); + bRet &= check(seqHyperRet == arHyper, "sequence test"); + Sequence< float > seqFloatRet(xBT2->setSequenceFloat(arFloat)); + bRet &= check(seqFloatRet == arFloat, "sequence test"); + Sequence< double > seqDoubleRet(xBT2->setSequenceDouble(arDouble)); + bRet &= check(seqDoubleRet == arDouble, "sequence test"); + Sequence< TestEnum > seqEnumRet(xBT2->setSequenceEnum(arEnum)); + bRet &= check(seqEnumRet == arEnum, "sequence test"); + Sequence< sal_uInt16 > seqUShortRet( + xBT2->setSequenceUShort(arUShort)); + bRet &= check(seqUShortRet == arUShort, "sequence test"); + Sequence< sal_uInt32 > seqULongRet(xBT2->setSequenceULong(arULong)); + bRet &= check(seqULongRet == arULong, "sequence test"); + Sequence< sal_uInt64 > seqUHyperRet( + xBT2->setSequenceUHyper(arUHyper)); + bRet &= check(seqUHyperRet == arUHyper, "sequence test"); + Sequence< Reference< XInterface > > seqObjectRet( + xBT2->setSequenceXInterface(arObject)); + bRet &= check(seqObjectRet == arObject, "sequence test"); + Sequence< OUString > seqStringRet( + xBT2->setSequenceString(arString)); + bRet &= check(seqStringRet == arString, "sequence test"); + Sequence< TestElement > seqStructRet( + xBT2->setSequenceStruct(arStruct)); + bRet &= check(seqStructRet == arStruct, "sequence test"); + Sequence< sal_Bool > arBoolTemp(cloneSequence(arBool)); + Sequence< sal_Unicode > arCharTemp(cloneSequence<sal_Unicode, cppu::UnoCharType>(arChar)); + Sequence< sal_Int8 > arByteTemp(cloneSequence(arByte)); + Sequence< sal_Int16 > arShortTemp(cloneSequence(arShort)); + Sequence< sal_uInt16 > arUShortTemp(cloneSequence<sal_uInt16, cppu::UnoUnsignedShortType>(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)); + 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"); + 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"); + } + { + // Test with empty sequences: + Sequence< Sequence< sal_Int32 > > arLong2; + Sequence< Sequence< sal_Int32 > > seqSeqRet(xBT2->setDim2(arLong2)); + bRet &= check(seqSeqRet == arLong2, "sequence test"); + Sequence< Sequence< Sequence< sal_Int32 > > > arLong3; + Sequence< Sequence< Sequence< sal_Int32 > > > seqSeqRet2( + xBT2->setDim3(arLong3)); + bRet &= check(seqSeqRet2 == arLong3, "sequence test"); + Sequence< Any > arAny; + Sequence< Any > seqAnyRet(xBT2->setSequenceAny(arAny)); + bRet &= check(seqAnyRet == arAny, "sequence test"); + Sequence< sal_Bool > arBool; + Sequence< sal_Bool > seqBoolRet(xBT2->setSequenceBool(arBool)); + bRet &= check(seqBoolRet == arBool, "sequence test"); + Sequence< sal_Int8 > arByte; + Sequence< sal_Int8 > seqByteRet(xBT2->setSequenceByte(arByte)); + bRet &= check(seqByteRet == arByte, "sequence test"); + Sequence< sal_Unicode > arChar; + Sequence< sal_Unicode > seqCharRet(xBT2->setSequenceChar(arChar)); + bRet &= check(seqCharRet == arChar, "sequence test"); + Sequence< sal_Int16 > arShort; + Sequence< sal_Int16 > seqShortRet(xBT2->setSequenceShort(arShort)); + bRet &= check(seqShortRet == arShort, "sequence test"); + Sequence< sal_Int32 > arLong; + Sequence< sal_Int32 > seqLongRet(xBT2->setSequenceLong(arLong)); + bRet &= check(seqLongRet == arLong, "sequence test"); + Sequence< sal_Int64 > arHyper; + Sequence< sal_Int64 > seqHyperRet(xBT2->setSequenceHyper(arHyper)); + bRet &= check(seqHyperRet == arHyper, "sequence test"); + Sequence< float > arFloat; + Sequence< float > seqFloatRet(xBT2->setSequenceFloat(arFloat)); + bRet &= check(seqFloatRet == arFloat, "sequence test"); + Sequence< double > arDouble; + Sequence< double > seqDoubleRet(xBT2->setSequenceDouble(arDouble)); + bRet &= check(seqDoubleRet == arDouble, "sequence test"); + Sequence< TestEnum > arEnum; + Sequence< TestEnum > seqEnumRet(xBT2->setSequenceEnum(arEnum)); + bRet &= check(seqEnumRet == arEnum, "sequence test"); + Sequence< sal_uInt16 > arUShort; + Sequence< sal_uInt16 > seqUShortRet( + xBT2->setSequenceUShort(arUShort)); + bRet &= check(seqUShortRet == arUShort, "sequence test"); + Sequence< sal_uInt32 > arULong; + Sequence< sal_uInt32 > seqULongRet(xBT2->setSequenceULong(arULong)); + bRet &= check(seqULongRet == arULong, "sequence test"); + Sequence< sal_uInt64 > arUHyper; + Sequence< sal_uInt64 > seqUHyperRet( + xBT2->setSequenceUHyper(arUHyper)); + bRet &= check(seqUHyperRet == arUHyper, "sequence test"); + Sequence< Reference< XInterface > > arObject; + Sequence< Reference< XInterface > > seqObjectRet( + xBT2->setSequenceXInterface(arObject)); + bRet &= check(seqObjectRet == arObject, "sequence test"); + Sequence< OUString > arString; + Sequence< OUString > seqStringRet( + xBT2->setSequenceString(arString)); + bRet &= check(seqStringRet == arString, "sequence test"); + Sequence< TestElement > arStruct; + Sequence< TestElement > seqStructRet( + xBT2->setSequenceStruct(arStruct)); + bRet &= check(seqStructRet == arStruct, "sequence test"); + } + // 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 (const 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 bool raiseOnewayException( const Reference < XBridgeTest > & xLBT ) +{ + bool bReturn = true; + OUString sCompare = 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( const 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 bool raiseException( const Reference< XBridgeTest > & xLBT ) +{ + sal_Int32 nCount = 0; + try + { + try + { + try + { + xLBT->raiseException( + 5, STRING_TEST_CONSTANT, + xLBT->getInterface() ); + } + catch (const IllegalArgumentException &rExc) + { + if (rExc.ArgumentPosition == 5 && +#if OSL_DEBUG_LEVEL == 0 + // java stack traces trash Message + rExc.Message.startsWith(STRING_TEST_CONSTANT) && +#endif + rExc.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( 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.startsWith(STRING_TEST_CONSTANT) +#endif + ) + { + ++nCount; + } + else + { + check( false, "### unexpected exception content!" ); + } + + /** it is certain, that the RuntimeException testing will fail, if no */ + xLBT->setRuntimeException( 0xcafebabe ); + } + } + catch (const Exception & rExc) + { + if (rExc.Context == xLBT->getInterface() +#if OSL_DEBUG_LEVEL == 0 + // java stack traces trash Message + && rExc.Message.startsWith(STRING_TEST_CONSTANT) +#endif + ) + { + ++nCount; + } + else + { + check( false, "### unexpected exception content!" ); + } + return (nCount == 3); + } + return false; +} + +/* Returns an acquired sequence + */ +static uno_Sequence* cloneSequence(const uno_Sequence* val, const Type& type) +{ + TypeDescription td(type); + td.makeComplete(); + typelib_TypeDescription* pTdRaw = td.get(); + typelib_IndirectTypeDescription* pIndirectTd = + reinterpret_cast<typelib_IndirectTypeDescription*>(pTdRaw); + + typelib_TypeDescription* pTdElem = pIndirectTd->pType->pType; + std::unique_ptr<sal_Int8[]> buf(new sal_Int8[pTdElem->nSize * val->nElements]); + sal_Int8* pBufCur = buf.get(); + + uno_Sequence* retSeq = nullptr; + switch (static_cast<TypeClass>(pTdElem->eTypeClass)) + { + case TypeClass_SEQUENCE: + { + Type _tElem(pTdElem->pWeakRef); + for (int i = 0; i < val->nElements; i++) + { + sal_Int8 const *pValBuf = reinterpret_cast<sal_Int8 const *>(&val->elements + i * pTdElem->nSize); + + uno_Sequence* seq = cloneSequence( + reinterpret_cast<uno_Sequence const *>(pValBuf), + _tElem); + *reinterpret_cast<uno_Sequence**>(pBufCur) = seq; + pBufCur += pTdElem->nSize; + } + break; + } + default: + uno_type_sequence_construct( + &retSeq, type.getTypeLibType(), const_cast<char *>(val->elements), + val->nElements, reinterpret_cast< uno_AcquireFunc >(cpp_acquire)); + break; + } + return retSeq; +} + +template<typename T, typename U> +Sequence<T> cloneSequence(const Sequence<T>& val) +{ + Sequence<T> seq( cloneSequence(val.get(), cppu::UnoType<cppu::UnoSequenceType<U>>::get()), SAL_NO_ACQUIRE); + return seq; +} + +template< class T > +static 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( + CPPU_CURRENT_LANGUAGE_BINDING_NAME ); + OUString aUnoEnvTypeName( + UNO_LB_UNO ); + // official: + uno_getEnvironment( + reinterpret_cast< uno_Environment ** >( &aCppEnv_official ), + aCppEnvTypeName.pData, nullptr ); + // anonymous: + uno_createEnvironment( + reinterpret_cast< uno_Environment ** >( &aCppEnv_ano ), + aCppEnvTypeName.pData, nullptr ); + uno_createEnvironment( + reinterpret_cast< uno_Environment ** >( &aUnoEnv_ano ), + aUnoEnvTypeName.pData, nullptr ); + + 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("cannot get C++-UNO mappings!" ); + } + cpp2uno.mapInterface( + reinterpret_cast< void ** >( &unoI.m_pUnoI ), + rOriginal.get(), cppu::UnoType<decltype(rOriginal)>::get() ); + if (! unoI.is()) + { + throw RuntimeException( + "mapping C++ to binary UNO failed!" ); + } + uno2cpp.mapInterface( + reinterpret_cast< void ** >( &rOut ), + unoI.get(), cppu::UnoType<decltype(rOriginal)>::get() ); + if (! rOut.is()) + { + throw RuntimeException( + "mapping binary UNO to C++ failed!" ); + } + + return rOut.is(); +} + + +sal_Int32 TestBridgeImpl::run( const Sequence< OUString > & rArgs ) +{ + bool bRet = false; + try + { + if (! rArgs.hasElements()) + { + throw RuntimeException( "no test object specified!\n" + "usage : ServiceName of test object | -u unourl of test object" ); + } + + Reference< XInterface > xOriginal; + bool remote; + sal_Int32 i; + if( rArgs.getLength() > 1 && rArgs[0] == "-u" ) + { + remote = true; + i = 2; + } + else + { + remote = false; + i = 1; + } + bool noCurrentContext = false; + if ( i < rArgs.getLength() && rArgs[i] == "noCurrentContext" ) + { + noCurrentContext = true; + ++i; + } + bool stress = false; + if ( i < rArgs.getLength() && rArgs[i] == "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( "cannot get test object!" ); + } + Reference< XBridgeTest > xTest( xOriginal, UNO_QUERY_THROW ); + + 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; + if (! bRet) + { + throw RuntimeException( "error: test failed!" ); + } + } + catch (const Exception & exc) + { + OString cstr( OUStringToOString( exc.Message, RTL_TEXTENCODING_ASCII_US ) ); + fprintf( stderr, "exception occurred: %s\n", cstr.getStr() ); + throw; + } + + return bRet ? 0 : 1; +} + +// XServiceInfo + +OUString TestBridgeImpl::getImplementationName() +{ + return IMPLNAME; +} + +sal_Bool TestBridgeImpl::supportsService( const OUString & rServiceName ) +{ + return cppu::supportsService(this, rServiceName); +} + +Sequence< OUString > TestBridgeImpl::getSupportedServiceNames() +{ + return bridge_test::getSupportedServiceNames(); +} + + +static Reference< XInterface > TestBridgeImpl_create( + const Reference< XComponentContext > & xContext ) +{ + return Reference< XInterface >( + static_cast< OWeakObject * >( new TestBridgeImpl( xContext ) ) ); +} + +} + +extern "C" +{ + +SAL_DLLPUBLIC_EXPORT void * component_getFactory( + const char * pImplName, void * pServiceManager, + SAL_UNUSED_PARAMETER void * ) +{ + void * pRet = nullptr; + + if (pServiceManager && rtl_str_compare( pImplName, IMPLNAME ) == 0) + { + Reference< XInterface > xFactory( + createSingleComponentFactory( + bridge_test::TestBridgeImpl_create, + IMPLNAME, + bridge_test::getSupportedServiceNames() ) ); + + if (xFactory.is()) + { + xFactory->acquire(); + pRet = xFactory.get(); + } + } + + return pRet; +} +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ 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 000000000..7518e569d --- /dev/null +++ b/testtools/source/bridgetest/cli/cli_bridgetest_inprocess.cs @@ -0,0 +1,251 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +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 then 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 000000000..bb7c56fcf --- /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 000000000..00ed43a0f --- /dev/null +++ b/testtools/source/bridgetest/cli/cli_cpp_bridgetest.cxx @@ -0,0 +1,927 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + + +#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::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 + { + //Any, enum, int, bool char, float, double etc. + ret = val1->Equals(val2); + } + 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->Byte2 == rData2->Byte2, "### byte2 does not match!" ); + check( rData1->Short2 == rData2->Short2, "### short2 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->Byte2 == rData2->Byte2 && + rData1->Short2 == rData2->Short2 && + 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, + Byte nByte2, Int16 nShort2, + 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->Byte2 = nByte2; + rData->Short2 = nShort2; + 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, + Byte nByte2, Int16 nShort2, + Object* xTest, + Any rAny, + TestElement* rSequence[]) +{ + assign( static_cast<TestElement*>(rData), + bBool, cChar, nByte, nShort, nUShort, nLong, nULong, nHyper, nUHyper, fFloat, fDouble, + eEnum, rStr, nByte2, nShort2, 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( 0, data->Byte2,xLBT ) && bReturn; + bReturn = testAny( 0, data->Short2,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->Byte2, aData->Short2, + 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, + aData->Byte2, + aData->Short2, + 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->Byte2, aSetData->Short2, + 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->Byte2, + aSetData->Short2, + 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->Byte2, + & aRet->Short2, + & 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->Byte2, + & aRet->Short2, + & 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->Byte2, + & aRet->Short2, + & 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->Byte2 = aRet->Byte2; + xLBT->Short2 = aRet->Short2; + 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->Byte2 = xLBT->Byte2; + aRet->Short2 = xLBT->Short2; + 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(); + + 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, 18, 0x5678, 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, 18, 0x5678, 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, 18, 0x5678, arObject[2], + Any( __typeof(Object), arObject[2] ) ); + { + 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>)")); + 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; + } + { + Console::WriteLine(new String("cli_cpp_bridgetest: no test of " + "XBridgeTest2::setSequencesInOut and XBridgeTest2.setSequencesOut " + "because jagged arrays are not supported by C++ compiler")); + } + { + 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); + 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: + explicit 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 occurred 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); + } + } +}; + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ 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 000000000..9d629e062 --- /dev/null +++ b/testtools/source/bridgetest/cli/cli_cs_bridgetest.cs @@ -0,0 +1,1024 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +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 occurred 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 000000000..3fd5a4975 --- /dev/null +++ b/testtools/source/bridgetest/cli/cli_cs_multi.cs @@ -0,0 +1,110 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +namespace testtools::bridgetest::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 000000000..8f396c924 --- /dev/null +++ b/testtools/source/bridgetest/cli/cli_cs_testobj.cs @@ -0,0 +1,925 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +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 TwoFloats echoTwoFloats(/*[in]*/TwoFloats arg) + { + return arg; + } + + public FourFloats echoFourFloats(/*[in]*/FourFloats arg) + { + return arg; + } + + public MixedFloatAndInteger echoMixedFloatAndInteger(/*[in]*/MixedFloatAndInteger arg) + { + return arg; + } + + public ThreeByteStruct echoThreeByteStruct(/*[in]*/ThreeByteStruct arg) + { + return arg; + } + + public int testPPCAlignment( long l1, long l2, int i1, long l3, int i2 ) + { + return i2; + } + + public int testPPC64Alignment( double d1, double d2, double d3, int i1 ) + { + return i1; + } + + public double testTenDoubles( double d1, double d2, double d3, double d4, double d5, double d6, double d7, double d8, double d9, double d10 ) + { + return d1 + d2 + d3 + d4 + d5 + d6 + d7 + d8 + d9 + d10; + } + + // 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 000000000..9b55cad6e --- /dev/null +++ b/testtools/source/bridgetest/cli/cli_vb_bridgetest.vb @@ -0,0 +1,851 @@ +' +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.0. If a copy of the MPL was not distributed with this +' file, You can obtain one at http://mozilla.org/MPL/2.0/. +' +' This file incorporates work covered by the following license notice: +' +' Licensed to the Apache Software Foundation (ASF) under one or more +' contributor license agreements. See the NOTICE file distributed +' with this work for additional information regarding copyright +' ownership. The ASF licenses this file to you under the Apache +' License, Version 2.0 (the "License"); you may not use this file +' except in compliance with the License. You may obtain a copy of +' the License at http://www.apache.org/licenses/LICENSE-2.0 . +' + +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 occurred 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 000000000..d90b94e4a --- /dev/null +++ b/testtools/source/bridgetest/cli/cli_vb_testobj.vb @@ -0,0 +1,615 @@ +' +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.0. If a copy of the MPL was not distributed with this +' file, You can obtain one at http://mozilla.org/MPL/2.0/. +' +' This file incorporates work covered by the following license notice: +' +' Licensed to the Apache Software Foundation (ASF) under one or more +' contributor license agreements. See the NOTICE file distributed +' with this work for additional information regarding copyright +' ownership. The ASF licenses this file to you under the Apache +' License, Version 2.0 (the "License"); you may not use this file +' except in compliance with the License. You may obtain a copy of +' the License at http://www.apache.org/licenses/LICENSE-2.0 . +' + +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/constructors.component b/testtools/source/bridgetest/constructors.component new file mode 100644 index 000000000..ddde08316 --- /dev/null +++ b/testtools/source/bridgetest/constructors.component @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + --> + +<component loader="com.sun.star.loader.SharedLibrary" environment="@CPPU_ENV@" + xmlns="http://openoffice.org/2010/uno-components"> + <implementation name="comp.test.testtools.bridgetest.Constructors"> + <service name="test.testtools.bridgetest.Constructors"/> + </implementation> + <implementation name="comp.test.testtools.bridgetest.Constructors2"> + <service name="test.testtools.bridgetest.Constructors2"/> + </implementation> +</component> diff --git a/testtools/source/bridgetest/constructors.cxx b/testtools/source/bridgetest/constructors.cxx new file mode 100644 index 000000000..9683c1fac --- /dev/null +++ b/testtools/source/bridgetest/constructors.cxx @@ -0,0 +1,454 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + + +#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/implbase.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> + +namespace { + +namespace ttb = ::test::testtools::bridgetest; +class Impl: + public cppu::WeakImplHelper<css::lang::XInitialization> +{ +public: + Impl() {} + Impl(const Impl&) = delete; + Impl& operator=(const Impl&) = delete; + +private: + virtual ~Impl() override {} + + virtual void SAL_CALL initialize( + css::uno::Sequence< css::uno::Any > const & arguments) override; +}; + +void Impl::initialize(css::uno::Sequence< css::uno::Any > const & arguments) +{ + bool arg0; + ::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(); + sal_Unicode arg10 = sal_Unicode(); + OUString arg11; + css::uno::Type arg12; + bool arg13; + 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< sal_Unicode > arg24; + css::uno::Sequence< OUString > arg25; + css::uno::Sequence< css::uno::Type > arg26; + css::uno::Sequence< css::uno::Any > arg27; + bool arg27b; + css::uno::Sequence< css::uno::Sequence< sal_Bool > > arg28; + css::uno::Sequence< css::uno::Sequence< css::uno::Any > > arg29; + bool arg29b; + 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; + bool arg33b; + 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; + bool arg38b; + 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] >>= 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] >>= arg10) && arg10 == 'X' + && (arguments[11] >>= arg11) + && arg11 == "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] >>= 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] >>= arg24) && arg24.getLength() == 1 + && arg24[0] == 'X' + && (arguments[25] >>= arg25) && arg25.getLength() == 1 + && arg25[0] == "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::WeakImplHelper< + css::lang::XInitialization, ttb::XMultiBase1 > +{ +public: + Impl2(): m_attr1(0.0) {} + +private: + virtual ~Impl2() override {} + + virtual void SAL_CALL initialize( + css::uno::Sequence< css::uno::Any > const & arguments) override; + + //XMultiBase1 + virtual double SAL_CALL getatt1() override; + virtual void SAL_CALL setatt1( double _att1 ) override; + virtual ::sal_Int32 SAL_CALL fn11( ::sal_Int32 arg ) override; + virtual OUString SAL_CALL fn12( const OUString& arg ) override; + + + double m_attr1; +}; + +void Impl2::initialize(css::uno::Sequence< css::uno::Any > const & arguments) +{ + ttb::TestPolyStruct< css::uno::Type > arg0; + ttb::TestPolyStruct< css::uno::Any > arg1; + css::uno::Any arg1b(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< 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 >, + OUString > > arg15; + ttb::TestPolyStruct2< 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< 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 >, OUString> > > arg37; + css::uno::Sequence<ttb::TestPolyStruct2< 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>, OUString> > > > arg42; + css::uno::Sequence<css::uno::Sequence<ttb::TestPolyStruct2< + 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 + && (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 == "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 == "test" + && (arguments[16] >>= arg16) && arg16.member1 == "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] + && (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] >>= arg25) && arg25.member.getLength() == 1 + && arg25.member[0] == 'X' + && (arguments[26] >>= arg26) && arg26.member.getLength() == 1 + && arg26.member[0] == "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] != nullptr + && (arguments[30] >>= arg30) && arg30.member.getLength() == 1 + && arg30.member[0] != nullptr + && (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 + && (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 == "test" + && (arguments[38] >>= arg38) && arg38.getLength() == 1 + && arg38[0].member1 == "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 == "test" + && (arguments[43] >>= arg43) && arg43.getLength() == 1 + && arg43[0].getLength() == 1 + && arg43[0][0].member1 == "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() +{ + return m_attr1; +} + +void Impl2::setatt1( double _att1 ) +{ + m_attr1 = _att1; +} + +::sal_Int32 Impl2::fn11( ::sal_Int32 arg ) +{ + return 11 * arg; +} + +OUString Impl2::fn12( const OUString& arg ) +{ + return "12" + arg; +} + +css::uno::Reference< css::uno::XInterface > create( + SAL_UNUSED_PARAMETER css::uno::Reference< css::uno::XComponentContext > + const &) +{ + return static_cast< ::cppu::OWeakObject * >(new Impl); +} + +OUString getImplementationName() { + return + "comp.test.testtools.bridgetest.Constructors"; +} + +css::uno::Sequence< OUString > getSupportedServiceNames() { + return { "test.testtools.bridgetest.Constructors" }; +} + +css::uno::Reference< css::uno::XInterface > create2( + SAL_UNUSED_PARAMETER css::uno::Reference< css::uno::XComponentContext > + const &) +{ + return static_cast< ::cppu::OWeakObject * >(new Impl2); +} + +OUString getImplementationName2() { + return "comp.test.testtools.bridgetest.Constructors2"; +} + +css::uno::Sequence< OUString > getSupportedServiceNames2() { + return { "test.testtools.bridgetest.Constructors2" }; +} + +::cppu::ImplementationEntry const entries[] = { + { &create, &getImplementationName, &getSupportedServiceNames, + &::cppu::createSingleComponentFactory, nullptr, 0 }, + { &create2, &getImplementationName2, &getSupportedServiceNames2, + &::cppu::createSingleComponentFactory, nullptr, 0 }, + { nullptr, nullptr, nullptr, nullptr, nullptr, 0 } }; +} + +extern "C" SAL_DLLPUBLIC_EXPORT void * component_getFactory( + char const * implName, void * serviceManager, void * registryKey) +{ + return ::cppu::component_getFactoryHelper( + implName, serviceManager, registryKey, entries); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/testtools/source/bridgetest/cppobj.component b/testtools/source/bridgetest/cppobj.component new file mode 100644 index 000000000..5b11d8df3 --- /dev/null +++ b/testtools/source/bridgetest/cppobj.component @@ -0,0 +1,25 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + --> + +<component loader="com.sun.star.loader.SharedLibrary" environment="@CPPU_ENV@" + xmlns="http://openoffice.org/2010/uno-components"> + <implementation name="com.sun.star.comp.bridge.CppTestObject"> + <service name="com.sun.star.test.bridge.CppTestObject"/> + </implementation> +</component> diff --git a/testtools/source/bridgetest/cppobj.cxx b/testtools/source/bridgetest/cppobj.cxx new file mode 100644 index 000000000..1456c2964 --- /dev/null +++ b/testtools/source/bridgetest/cppobj.cxx @@ -0,0 +1,1223 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <stdio.h> + +#include <cppu/unotype.hxx> +#include <osl/diagnose.h> +#include <osl/diagnose.hxx> +#include <osl/thread.hxx> +#include <osl/mutex.hxx> +#include <osl/time.h> + +#include <cppuhelper/implbase.hxx> +#include <cppuhelper/factory.hxx> +#include <cppuhelper/exc_hlp.hxx> +#include <cppuhelper/compbase_ex.hxx> +#include <cppuhelper/supportsservice.hxx> +#include <com/sun/star/lang/IllegalArgumentException.hpp> +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/lang/XSingleServiceFactory.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 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; + +#ifdef _MSC_VER +#pragma warning (disable : 4503) // irrelevant for test code +#endif + +#define SERVICENAME "com.sun.star.test.bridge.CppTestObject" +#define IMPLNAME "com.sun.star.comp.bridge.CppTestObject" + +namespace bridge_object +{ + + +static Sequence< OUString > getSupportedServiceNames() +{ + return { SERVICENAME }; +} + + +static void assign( TestElement & rData, + 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 OUString& rStr, + sal_Int8 nByte2, sal_Int16 nShort2, + const css::uno::Reference< css::uno::XInterface >& xTest, + const css::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.Byte2 = nByte2; + rData.Short2 = nShort2; + rData.Interface = xTest; + rData.Any = rAny; +} + +static void assign( TestData & rData, + 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 OUString& rStr, + sal_Int8 nByte2, sal_Int16 nShort2, + const css::uno::Reference< css::uno::XInterface >& xTest, + const css::uno::Any& rAny, + const css::uno::Sequence< TestElement >& rSequence ) +{ + assign( static_cast<TestElement &>(rData), + bBool, cChar, nByte, nShort, nUShort, nLong, nULong, nHyper, nUHyper, fFloat, fDouble, + eEnum, rStr, nByte2, nShort2, xTest, rAny ); + rData.Sequence = rSequence; +} + +namespace { + +class Test_Impl : + public osl::DebugBase<Test_Impl>, + public WeakImplHelper< XBridgeTest2, XServiceInfo , XRecursiveCall > +{ + TestData _aData, _aStructData; + sal_Int32 m_nLastCallId; + bool m_bFirstCall; + 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( true ), + m_bSequenceOfCallTestPassed( true ) + {} + + void SAL_CALL acquire() throw () override + { + OWeakObject::acquire(); + } + void SAL_CALL release() throw () override + { + OWeakObject::release(); + } + + // XServiceInfo + virtual OUString SAL_CALL getImplementationName() override; + virtual sal_Bool SAL_CALL supportsService( const OUString & rServiceName ) override; + virtual Sequence< OUString > SAL_CALL getSupportedServiceNames() override; + + // 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 OUString& rStr, + sal_Int8 nByte2, + sal_Int16 nShort2, + const css::uno::Reference< css::uno::XInterface >& xTest, + const css::uno::Any& rAny, + const css::uno::Sequence<TestElement >& rSequence, + const ::test::testtools::bridgetest::TestDataElements& rStruct ) override; + + virtual ::test::testtools::bridgetest::TestDataElements 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, + OUString& rStr, + sal_Int8& nByte2, + sal_Int16& nShort2, + css::uno::Reference< css::uno::XInterface >& xTest, + css::uno::Any& rAny, + css::uno::Sequence<TestElement >& rSequence, + ::test::testtools::bridgetest::TestDataElements& rStruct ) override; + + virtual ::test::testtools::bridgetest::TestDataElements 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, + OUString& rStr, + sal_Int8& nByte2, + sal_Int16& nShort2, + css::uno::Reference< css::uno::XInterface >& xTest, + css::uno::Any& rAny, + css::uno::Sequence< TestElement >& rSequence, + ::test::testtools::bridgetest::TestDataElements& rStruct ) override; + + virtual SmallStruct SAL_CALL echoSmallStruct(const SmallStruct& rStruct) override + { return rStruct; } + virtual MediumStruct SAL_CALL echoMediumStruct(const MediumStruct& rStruct) override + { return rStruct; } + virtual BigStruct SAL_CALL echoBigStruct(const BigStruct& rStruct) override + { return rStruct; } + virtual TwoFloats SAL_CALL echoTwoFloats(const TwoFloats& rStruct) override + { return rStruct; } + virtual FourFloats SAL_CALL echoFourFloats(const FourFloats& rStruct) override + { return rStruct; } + virtual MixedFloatAndInteger SAL_CALL echoMixedFloatAndInteger(const MixedFloatAndInteger& rStruct) override + { return rStruct; } + virtual ThreeByteStruct SAL_CALL echoThreeByteStruct(const ThreeByteStruct& rStruct) override + { return rStruct; } + virtual sal_Int32 SAL_CALL testPPCAlignment( sal_Int64, sal_Int64, sal_Int32, sal_Int64, sal_Int32 i2 ) override + { return i2; } + virtual sal_Int32 SAL_CALL testPPC64Alignment( double , double , double , sal_Int32 i1 ) override + { return i1; } + virtual double SAL_CALL testTenDoubles( double d1, double d2, double d3, double d4, double d5, double d6, double d7, double d8, double d9, double d10 ) override + { return d1 + d2 + d3 + d4 + d5 + d6 + d7 + d8 + d9 + d10; } + virtual sal_Bool SAL_CALL getBool() override + { return _aData.Bool; } + virtual sal_Int8 SAL_CALL getByte() override + { return _aData.Byte; } + virtual sal_Unicode SAL_CALL getChar() override + { return _aData.Char; } + virtual sal_Int16 SAL_CALL getShort() override + { return _aData.Short; } + virtual sal_uInt16 SAL_CALL getUShort() override + { return _aData.UShort; } + virtual sal_Int32 SAL_CALL getLong() override + { return _aData.Long; } + virtual sal_uInt32 SAL_CALL getULong() override + { return _aData.ULong; } + virtual sal_Int64 SAL_CALL getHyper() override + { return _aData.Hyper; } + virtual sal_uInt64 SAL_CALL getUHyper() override + { return _aData.UHyper; } + virtual float SAL_CALL getFloat() override + { return _aData.Float; } + virtual double SAL_CALL getDouble() override + { return _aData.Double; } + virtual TestEnum SAL_CALL getEnum() override + { return _aData.Enum; } + virtual OUString SAL_CALL getString() override + { return _aData.String; } + virtual sal_Int8 SAL_CALL getByte2() override + { return _aData.Byte2; } + virtual sal_Int16 SAL_CALL getShort2() override + { return _aData.Short2; } + virtual css::uno::Reference< css::uno::XInterface > SAL_CALL getInterface( ) override + { return _aData.Interface; } + virtual css::uno::Any SAL_CALL getAny() override + { return _aData.Any; } + virtual css::uno::Sequence< TestElement > SAL_CALL getSequence() override + { return _aData.Sequence; } + virtual ::test::testtools::bridgetest::TestDataElements SAL_CALL getStruct() override + { return _aStructData; } + + virtual void SAL_CALL setBool( sal_Bool _bool ) override + { _aData.Bool = _bool; } + virtual void SAL_CALL setByte( sal_Int8 _byte ) override + { _aData.Byte = _byte; } + virtual void SAL_CALL setChar( sal_Unicode _char ) override + { _aData.Char = _char; } + virtual void SAL_CALL setShort( sal_Int16 _short ) override + { _aData.Short = _short; } + virtual void SAL_CALL setUShort( sal_uInt16 _ushort ) override + { _aData.UShort = _ushort; } + virtual void SAL_CALL setLong( sal_Int32 _long ) override + { _aData.Long = _long; } + virtual void SAL_CALL setULong( sal_uInt32 _ulong ) override + { _aData.ULong = _ulong; } + virtual void SAL_CALL setHyper( sal_Int64 _hyper ) override + { _aData.Hyper = _hyper; } + virtual void SAL_CALL setUHyper( sal_uInt64 _uhyper ) override + { _aData.UHyper = _uhyper; } + virtual void SAL_CALL setFloat( float _float ) override + { _aData.Float = _float; } + virtual void SAL_CALL setDouble( double _double ) override + { _aData.Double = _double; } + virtual void SAL_CALL setEnum( TestEnum _enum ) override + { _aData.Enum = _enum; } + virtual void SAL_CALL setString( const OUString& _string ) override + { _aData.String = _string; } + virtual void SAL_CALL setByte2( sal_Int8 _byte ) override + { _aData.Byte2 = _byte; } + virtual void SAL_CALL setShort2( sal_Int16 _short ) override + { _aData.Short2 = _short; } + virtual void SAL_CALL setInterface( const css::uno::Reference< css::uno::XInterface >& _interface ) override + { _aData.Interface = _interface; } + virtual void SAL_CALL setAny( const css::uno::Any& _any ) override + { _aData.Any = _any; } + virtual void SAL_CALL setSequence( const css::uno::Sequence<TestElement >& _sequence ) override + { _aData.Sequence = _sequence; } + virtual void SAL_CALL setStruct( const ::test::testtools::bridgetest::TestDataElements& _struct ) override + { _aStructData = _struct; } + + virtual sal_Int32 SAL_CALL getRaiseAttr1() override + { throw RuntimeException(); } + + virtual void SAL_CALL setRaiseAttr1(sal_Int32) override + { throw IllegalArgumentException(); } + + virtual sal_Int32 SAL_CALL getRaiseAttr2() override + { throw IllegalArgumentException(); } + + virtual TestPolyStruct< sal_Bool > SAL_CALL transportPolyBoolean( + TestPolyStruct< sal_Bool > const & arg) override + { return arg; } + + virtual void SAL_CALL transportPolyHyper(TestPolyStruct< sal_Int64 > &) override {} + + virtual void SAL_CALL transportPolySequence( + TestPolyStruct< Sequence< Any > > const & arg1, + TestPolyStruct< Sequence< Any > > & arg2) override + { arg2 = arg1; } + + virtual TestPolyStruct< sal_Int32 > SAL_CALL getNullPolyLong() override + { return TestPolyStruct< sal_Int32 >(0); /* work around MS compiler bug */ } + + virtual TestPolyStruct< OUString > SAL_CALL getNullPolyString() override + { return TestPolyStruct< OUString >(); } + + virtual TestPolyStruct< Type > SAL_CALL getNullPolyType() override + { return TestPolyStruct< Type >(); } + + virtual TestPolyStruct< Any > SAL_CALL getNullPolyAny() override + { return TestPolyStruct< Any >(); } + + virtual TestPolyStruct< Sequence< sal_Bool > > SAL_CALL + getNullPolySequence() override + { return TestPolyStruct< Sequence< sal_Bool > >(); } + + virtual TestPolyStruct< TestEnum > SAL_CALL getNullPolyEnum() override + { return TestPolyStruct< TestEnum >( + test::testtools::bridgetest::TestEnum_TEST); + /* work around MS compiler bug */ } + + virtual TestPolyStruct< TestBadEnum > SAL_CALL getNullPolyBadEnum() override + { return TestPolyStruct< TestBadEnum >( + test::testtools::bridgetest::TestBadEnum_M); + /* explicitly instantiate with default enumerator */ } + + virtual TestPolyStruct< TestStruct > SAL_CALL getNullPolyStruct() override + { return TestPolyStruct< TestStruct >(); } + + virtual TestPolyStruct< Reference< XBridgeTestBase > > SAL_CALL + getNullPolyInterface() override + { return TestPolyStruct< Reference< XBridgeTestBase > >(); } + + virtual css::uno::Any SAL_CALL transportAny( + const css::uno::Any& value ) override; + + virtual void SAL_CALL call( sal_Int32 nCallId, sal_Int32 nWaitMUSEC ) override; + virtual void SAL_CALL callOneway( sal_Int32 nCallId, sal_Int32 nWaitMUSEC ) override; + virtual sal_Bool SAL_CALL sequenceOfCallTestPassed( ) override; + virtual void SAL_CALL startRecursiveCall( + const css::uno::Reference< XRecursiveCall >& xCall, sal_Int32 nToCall ) override; + + virtual Reference< XMulti > SAL_CALL getMulti() override; + + virtual OUString SAL_CALL testMulti(Reference< XMulti > const & multi) override; + +public: // XBridgeTest + virtual ::test::testtools::bridgetest::TestDataElements SAL_CALL raiseException( sal_Int16 nArgumentPos, const OUString & rMsg, const Reference< XInterface > & xCOntext ) override; + + virtual void SAL_CALL raiseRuntimeExceptionOneway( + const OUString& Message, const css::uno::Reference< css::uno::XInterface >& Context ) override; + + virtual sal_Int32 SAL_CALL getRuntimeException() override; + virtual void SAL_CALL setRuntimeException( sal_Int32 _runtimeexception ) override; + + // XBridgeTest2 + virtual Sequence< sal_Bool > SAL_CALL setSequenceBool( + const Sequence< sal_Bool >& aSeq ) override; + virtual Sequence< sal_Unicode > SAL_CALL setSequenceChar( + const Sequence< sal_Unicode >& aSeq ) override; + virtual Sequence< sal_Int8 > SAL_CALL setSequenceByte( + const Sequence< sal_Int8 >& aSeq ) override; + virtual Sequence< sal_Int16 > SAL_CALL setSequenceShort( + const Sequence< sal_Int16 >& aSeq ) override; + virtual Sequence< sal_uInt16 > SAL_CALL setSequenceUShort( + const Sequence< sal_uInt16 >& aSeq ) override; + virtual Sequence< sal_Int32 > SAL_CALL setSequenceLong( + const Sequence< sal_Int32 >& aSeq ) override; + virtual Sequence< sal_uInt32 > SAL_CALL setSequenceULong( + const Sequence< sal_uInt32 >& aSeq ) override; + virtual Sequence< sal_Int64 > SAL_CALL setSequenceHyper( + const Sequence< sal_Int64 >& aSeq ) override; + virtual Sequence< sal_uInt64 > SAL_CALL setSequenceUHyper( + const Sequence< sal_uInt64 >& aSeq ) override; + virtual Sequence< float > SAL_CALL setSequenceFloat( + const Sequence< float >& aSeq ) override; + virtual Sequence< double > SAL_CALL setSequenceDouble( + const Sequence< double >& aSeq ) override; + virtual Sequence< TestEnum > SAL_CALL setSequenceEnum( + const Sequence< TestEnum >& aSeq ) override ; + virtual Sequence< OUString > SAL_CALL setSequenceString( + const Sequence< OUString >& aString ) override; + virtual Sequence< Reference< XInterface > > SAL_CALL setSequenceXInterface( + const Sequence< Reference< XInterface > >& aSeq ) override; + virtual Sequence<Any > SAL_CALL setSequenceAny( + const Sequence<Any >& aSeq ) override; + virtual Sequence<TestElement > SAL_CALL setSequenceStruct( + const Sequence< TestElement >& aSeq ) override; + virtual Sequence< Sequence< sal_Int32 > > SAL_CALL setDim2( + const Sequence<Sequence< sal_Int32 > >& aSeq ) override; + virtual Sequence< Sequence< Sequence< sal_Int32 > > > SAL_CALL setDim3( + const Sequence< Sequence< Sequence< sal_Int32 > > >& aSeq ) override; + 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 ) override; + 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 ) override; + virtual void SAL_CALL testConstructorsService( + Reference< XComponentContext > const & context) override; + virtual Reference< XCurrentContextChecker > SAL_CALL + getCurrentContextChecker() override; + +public: + virtual void SAL_CALL callRecursivly( const css::uno::Reference< XRecursiveCall >& xCall, sal_Int32 nToCall ) override; +}; + +//Dummy class for XComponent implementation +class Dummy : public osl::DebugBase<Dummy>, + public WeakComponentImplHelperBase +{ +public: + Dummy(): WeakComponentImplHelperBase(*Mutex::getGlobalMutex()){} + +}; + +} + +Any Test_Impl::transportAny( const Any & value ) +{ + return value; +} + + +namespace { + +void wait(sal_Int32 microSeconds) { + OSL_ASSERT(microSeconds >= 0 && microSeconds <= SAL_MAX_INT32 / 1000); + osl::Thread::wait(std::chrono::microseconds(microSeconds)); +} + +} + +void Test_Impl::call( sal_Int32 nCallId , sal_Int32 nWaitMUSEC ) +{ + wait(nWaitMUSEC); + if( m_bFirstCall ) + { + m_bFirstCall = false; + } + else + { + m_bSequenceOfCallTestPassed = m_bSequenceOfCallTestPassed && (nCallId > m_nLastCallId); + } + m_nLastCallId = nCallId; +} + + +void Test_Impl::callOneway( sal_Int32 nCallId , sal_Int32 nWaitMUSEC ) +{ + wait(nWaitMUSEC); + m_bSequenceOfCallTestPassed = m_bSequenceOfCallTestPassed && (nCallId > m_nLastCallId); + m_nLastCallId = nCallId; +} + + +sal_Bool Test_Impl::sequenceOfCallTestPassed() +{ + return m_bSequenceOfCallTestPassed; +} + + +void SAL_CALL Test_Impl::startRecursiveCall( + const css::uno::Reference< XRecursiveCall >& xCall, sal_Int32 nToCall ) +{ + MutexGuard guard( m_mutex ); + if( nToCall ) + { + nToCall --; + xCall->callRecursivly( this , nToCall ); + } +} + + +void SAL_CALL Test_Impl::callRecursivly( + const css::uno::Reference< XRecursiveCall >& xCall, + sal_Int32 nToCall ) +{ + MutexGuard guard( m_mutex ); + if( nToCall ) + { + nToCall --; + xCall->callRecursivly( this , nToCall ); + } +} + +Reference< XMulti > Test_Impl::getMulti() { + return new testtools::bridgetest::Multi; +} + +OUString Test_Impl::testMulti(Reference< XMulti > const & multi) +{ + 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 OUString& rStr, + sal_Int8 nByte2, + sal_Int16 nShort2, + const css::uno::Reference< css::uno::XInterface >& xTest, + const css::uno::Any& rAny, + const css::uno::Sequence<TestElement >& rSequence, + const ::test::testtools::bridgetest::TestDataElements& rStruct ) +{ + assign( _aData, + bBool, cChar, nByte, nShort, nUShort, nLong, nULong, nHyper, nUHyper, fFloat, fDouble, + eEnum, rStr, nByte2, nShort2, xTest, rAny, rSequence ); + _aStructData = rStruct; +} + +::test::testtools::bridgetest::TestDataElements 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, + OUString& rStr, + sal_Int8& nByte2, + sal_Int16& nShort2, + css::uno::Reference< css::uno::XInterface >& xTest, + css::uno::Any& rAny, + css::uno::Sequence<TestElement >& rSequence, + ::test::testtools::bridgetest::TestDataElements& rStruct ) +{ + assign( _aData, + bBool, cChar, nByte, nShort, nUShort, nLong, nULong, nHyper, nUHyper, fFloat, fDouble, + eEnum, rStr, nByte2, nShort2, xTest, rAny, rSequence ); + _aStructData = rStruct; + + TestElement elem = rSequence[ 0 ]; + rSequence[ 0 ] = rSequence[ 1 ]; + rSequence[ 1 ] = elem; + + return _aStructData; +} + +::test::testtools::bridgetest::TestDataElements 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, + OUString& rStr, + sal_Int8& nByte2, + sal_Int16& nShort2, + css::uno::Reference< css::uno::XInterface >& xTest, + css::uno::Any& rAny, + css::uno::Sequence<TestElement >& rSequence, + ::test::testtools::bridgetest::TestDataElements& rStruct ) +{ + 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; + nByte2 = _aData.Byte2; + nShort2 = _aData.Short2; + xTest = _aData.Interface; + rAny = _aData.Any; + rSequence = _aData.Sequence; + rStruct = _aStructData; + return _aStructData; +} + +::test::testtools::bridgetest::TestDataElements Test_Impl::raiseException( sal_Int16 nArgumentPos, const OUString & rMsg, const Reference< XInterface > & xContext ) +{ + 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 ) +{ + RuntimeException aExc; + aExc.Message = _aData.String = rMsg; + aExc.Context = _aData.Interface = xContext; + throw aExc; +} + +static void dothrow2(const RuntimeException& e) +{ + throw e; +} +static void dothrow(const RuntimeException& 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 ); + } + catch (...) // never throws anything + { + fprintf( stderr, "\ngetCaughtException() failed!\n" ); + exit( 1 ); + } + } +#endif + dothrow2( e ); +} + +sal_Int32 Test_Impl::getRuntimeException() +{ + try + { + dothrow( RuntimeException( _aData.String, _aData.Interface ) ); + } + catch (Exception &) + { + Any a( getCaughtException() ); + throwException( a ); + } + return 0; // for dummy +} + +void Test_Impl::setRuntimeException( sal_Int32 ) +{ + 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 ) +{ + _arBool = aSeq; + return aSeq; +} + +Sequence< sal_Unicode > SAL_CALL Test_Impl::setSequenceChar( + const Sequence< sal_Unicode >& aSeq ) +{ + _arChar = aSeq; + return aSeq; +} + +Sequence< sal_Int8 > SAL_CALL Test_Impl::setSequenceByte( + const Sequence< sal_Int8 >& aSeq ) +{ + _arByte = aSeq; + return aSeq; +} + +Sequence< sal_Int16 > SAL_CALL Test_Impl::setSequenceShort( + const Sequence< sal_Int16 >& aSeq ) +{ + _arShort = aSeq; + return aSeq; +} + +Sequence< sal_uInt16 > SAL_CALL Test_Impl::setSequenceUShort( + const Sequence< sal_uInt16 >& aSeq ) +{ + _arUShort = aSeq; + return aSeq; +} + +Sequence< sal_Int32 > SAL_CALL Test_Impl::setSequenceLong( + const Sequence< sal_Int32 >& aSeq ) +{ + _arLong = aSeq; + return aSeq; +} + +Sequence< sal_uInt32 > SAL_CALL Test_Impl::setSequenceULong( + const Sequence< sal_uInt32 >& aSeq ) +{ + _arULong = aSeq; + return aSeq; +} + +Sequence< sal_Int64 > SAL_CALL Test_Impl::setSequenceHyper( + const Sequence< sal_Int64 >& aSeq ) +{ + _arHyper = aSeq; + return aSeq; +} + +Sequence< sal_uInt64 > SAL_CALL Test_Impl::setSequenceUHyper( + const Sequence< sal_uInt64 >& aSeq ) +{ + _arUHyper = aSeq; + return aSeq; +} + +Sequence< float > SAL_CALL Test_Impl::setSequenceFloat( + const Sequence< float >& aSeq ) +{ + _arFloat = aSeq; + return aSeq; +} + +Sequence< double > SAL_CALL Test_Impl::setSequenceDouble( + const Sequence< double >& aSeq ) +{ + _arDouble = aSeq; + return aSeq; +} + +Sequence< TestEnum > SAL_CALL Test_Impl::setSequenceEnum( + const Sequence< TestEnum >& aSeq ) +{ + _arEnum = aSeq; + return aSeq; +} + +Sequence< OUString > SAL_CALL Test_Impl::setSequenceString( + const Sequence< OUString >& aSeq ) +{ + _arString = aSeq; + return aSeq; +} + +Sequence< Reference< XInterface > > SAL_CALL Test_Impl::setSequenceXInterface( + const Sequence< Reference< XInterface > >& aSeq ) +{ + _arObject = aSeq; + return aSeq; +} + +Sequence<Any > SAL_CALL Test_Impl::setSequenceAny( + const Sequence<Any >& aSeq ) +{ + _arAny = aSeq; + return aSeq; +} + +Sequence<TestElement > SAL_CALL Test_Impl::setSequenceStruct( + const Sequence< TestElement >& aSeq ) +{ + _arStruct = aSeq; + return aSeq; +} + +Sequence< Sequence< sal_Int32 > > SAL_CALL Test_Impl::setDim2( + const Sequence<Sequence< sal_Int32 > >& aSeq ) +{ + _arLong2 = aSeq; + return aSeq; +} + +Sequence< Sequence< Sequence< sal_Int32 > > > SAL_CALL Test_Impl::setDim3( + const Sequence< Sequence< Sequence< sal_Int32 > > >& aSeq ) +{ + _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 ) +{ + _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 ) +{ + 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) +{ + 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 { "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', + "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 >(nullptr)); + 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; + args[10] <<= u'X'; + args[11] <<= OUString("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] <<= arg24; + 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 >(nullptr); + Constructors::create2(context, args); + + Sequence<Type> argSeq1(1); argSeq1[0] = cppu::UnoType<sal_Int32>::get(); + Sequence<Reference<XInterface> > argSeq2 { static_cast<XComponent*>(new Dummy()) }; + Sequence<Reference<XComponent> > argSeq2a { 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("test"))); + Sequence<TestPolyStruct2<OUString, TestPolyStruct2<sal_Unicode, TestPolyStruct<Any> > > > argSeq9(1); + argSeq9[0] = TestPolyStruct2<OUString, TestPolyStruct2<sal_Unicode, TestPolyStruct<Any> > >( + OUString("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("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("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("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("test"))), + TestPolyStruct2<OUString, TestPolyStruct2<sal_Unicode,TestPolyStruct<Any> > >( + OUString("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() +{ + return new testtools::bridgetest::CurrentContextChecker; +} + +// XServiceInfo + +OUString Test_Impl::getImplementationName() +{ + return IMPLNAME; +} + +sal_Bool Test_Impl::supportsService( const OUString & rServiceName ) +{ + return cppu::supportsService(this, rServiceName); +} + +Sequence< OUString > Test_Impl::getSupportedServiceNames() +{ + return bridge_object::getSupportedServiceNames(); +} + + +static Reference< XInterface > Test_Impl_create( + SAL_UNUSED_PARAMETER const Reference< XMultiServiceFactory > & ) +{ + return Reference< XInterface >( static_cast<XBridgeTest *>(new Test_Impl()) ); +} + +} + +extern "C" +{ +SAL_DLLPUBLIC_EXPORT void * component_getFactory( + const char * pImplName, SAL_UNUSED_PARAMETER void * pServiceManager, + SAL_UNUSED_PARAMETER void * ) +{ + void * pRet = nullptr; + + if (pServiceManager && rtl_str_compare( pImplName, IMPLNAME ) == 0) + { + Reference< XSingleServiceFactory > xFactory( createSingleFactory( + static_cast< XMultiServiceFactory * >( pServiceManager ), + IMPLNAME, + bridge_object::Test_Impl_create, + bridge_object::getSupportedServiceNames() ) ); + + if (xFactory.is()) + { + xFactory->acquire(); + pRet = xFactory.get(); + } + } + + return pRet; +} +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/testtools/source/bridgetest/currentcontextchecker.cxx b/testtools/source/bridgetest/currentcontextchecker.cxx new file mode 100644 index 000000000..27de3c5e7 --- /dev/null +++ b/testtools/source/bridgetest/currentcontextchecker.cxx @@ -0,0 +1,108 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + + +#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/implbase.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 { + +static char const KEY[] = "testtools.bridgetest.Key"; +static char const VALUE[] = "good"; + +class CurrentContext: + public ::osl::DebugBase< CurrentContext >, + public ::cppu::WeakImplHelper< css::uno::XCurrentContext > +{ +public: + CurrentContext(); + + CurrentContext(const CurrentContext&) = delete; + CurrentContext& operator=(const CurrentContext&) = delete; + + virtual css::uno::Any SAL_CALL getValueByName(OUString const & Name) override; +}; + +CurrentContext::CurrentContext() {} + +css::uno::Any CurrentContext::getValueByName(OUString const & Name) +{ + return Name == KEY ? css::uno::makeAny(OUString(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) +{ + 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(KEY)); + if (a.getValueType() != ::cppu::UnoType< OUString >::get()) { + return false; + } + OUString s; + OSL_VERIFY(a >>= s); + return s == VALUE; + } else { + return other->perform( + this, setSteps >= 0 ? setSteps - 1 : -1, checkSteps - 1); + } +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/testtools/source/bridgetest/currentcontextchecker.hxx b/testtools/source/bridgetest/currentcontextchecker.hxx new file mode 100644 index 000000000..36ad5d6d0 --- /dev/null +++ b/testtools/source/bridgetest/currentcontextchecker.hxx @@ -0,0 +1,62 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#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/implbase.hxx> +#include <osl/diagnose.hxx> +#include <sal/types.h> +#include <test/testtools/bridgetest/XCurrentContextChecker.hpp> + +#include "dllapi.hxx" + +namespace testtools::bridgetest { + +class LO_DLLPUBLIC_TESTTOOLS CurrentContextChecker : + public ::osl::DebugBase< CurrentContextChecker >, + public ::cppu::WeakImplHelper< + ::test::testtools::bridgetest::XCurrentContextChecker > +{ +public: + CurrentContextChecker(); + + virtual ~CurrentContextChecker() override; + + virtual sal_Bool SAL_CALL perform( + css::uno::Reference< ::test::testtools::bridgetest::XCurrentContextChecker > const & other, + ::sal_Int32 setSteps, ::sal_Int32 checkSteps) override; + +private: + CurrentContextChecker(CurrentContextChecker const &) = delete; + void operator =(CurrentContextChecker const &) = delete; + + SAL_DLLPRIVATE bool performCheck( + css::uno::Reference< ::test::testtools::bridgetest::XCurrentContextChecker > const & other, + ::sal_Int32 setSteps, ::sal_Int32 checkSteps); +}; + +} + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/testtools/source/bridgetest/dllapi.hxx b/testtools/source/bridgetest/dllapi.hxx new file mode 100644 index 000000000..8777a934a --- /dev/null +++ b/testtools/source/bridgetest/dllapi.hxx @@ -0,0 +1,25 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#ifndef INCLUDED_TESTTOOLS_SOURCE_BRIDGETEST_DLLAPI_HXX +#define INCLUDED_TESTTOOLS_SOURCE_BRIDGETEST_DLLAPI_HXX + +#include <sal/config.h> + +#include <sal/types.h> + +#if defined LO_DLLIMPLEMENTATION_TESTTOOLS +#define LO_DLLPUBLIC_TESTTOOLS SAL_DLLPUBLIC_EXPORT +#else +#define LO_DLLPUBLIC_TESTTOOLS SAL_DLLPUBLIC_IMPORT +#endif + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/testtools/source/bridgetest/idl/bridgetest.idl b/testtools/source/bridgetest/idl/bridgetest.idl new file mode 100644 index 000000000..b40d46d07 --- /dev/null +++ b/testtools/source/bridgetest/idl/bridgetest.idl @@ -0,0 +1,634 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#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; + byte Byte2; + short Short; + short Short2; + 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; +}; +/** + * two floats, BSDs/MacOSX on intel handle returning small + * structs differently than Linux + */ +struct TwoFloats +{ + float a; + float b; +}; +/** + * all floats, ia64 handles them specially + */ +struct FourFloats +{ + float a; + float b; + float c; + float d; +}; +/** + * Small struct with mixed float and integers. + * Should return in registers on BSDs/MACOSx + */ +struct MixedFloatAndInteger +{ + float a; + long b; +}; +/** + * Small struct with three bytes. Should *not* return in registers on + * BSDs/MACOSx + */ +struct ThreeByteStruct +{ + byte a; + byte b; + byte c; +}; +/** + * complex types adding string, interface, 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 immediately. + * 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) + */ + 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] byte aByte2, + [in] short aShort2, + [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] byte aByte2, + [inout] short aShort2, + [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] byte aByte2, + [out] short aShort2, + [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 + */ + TwoFloats echoTwoFloats( [in] TwoFloats aStruct ); + + /** + * register return test 5 + */ + FourFloats echoFourFloats( [in] FourFloats aStruct ); + + /** + * register return test 6 + */ + MixedFloatAndInteger echoMixedFloatAndInteger( [in] MixedFloatAndInteger aStruct ); + + /** + * register return test 7 + */ + ThreeByteStruct echoThreeByteStruct( [in] ThreeByteStruct aStruct ); + + /** + * PPC Alignment test (#i107182#) + */ + long testPPCAlignment( [in] hyper l1, [in] hyper l2, [in] long i1, [in] hyper l3, [in] long i2 ); + + /** + * PPC64 Alignment test + */ + long testPPC64Alignment( [in] double d1, [in] double d2, [in] double d3, [in] long i1 ); + + + /** + * VFP ABI (armhf) doubles test + */ + double testTenDoubles( [in] double d1, [in] double d2, [in] double d3, [in] double d4, [in] double d5, [in] double d6, [in] double d7, [in] double d8, [in] double d9, [in] double d10 ); + + [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] byte Byte2; + [attribute] short Short2; + [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 extensively 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 ); + 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); +}; + + +/** + * Inheriting 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 exception may fly or not. When it flies, it should + * have the proper message and context. + ***/ + 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(); +}; + +}; }; }; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/testtools/source/bridgetest/idl/com/sun/star/test/performance/XPerformanceTest.idl b/testtools/source/bridgetest/idl/com/sun/star/test/performance/XPerformanceTest.idl new file mode 100644 index 000000000..7e3ae8e96 --- /dev/null +++ b/testtools/source/bridgetest/idl/com/sun/star/test/performance/XPerformanceTest.idl @@ -0,0 +1,130 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#ifndef __com_sun_star_test_performance_XPerformanceTest_idl__ +#define __com_sun_star_test_performance_XPerformanceTest_idl__ + +#include <com/sun/star/uno/XInterface.idl> + +module com +{ +module sun +{ +module star +{ +module test +{ +module performance +{ + +/** struct of simple types to be carried +*/ +published struct SimpleTypes +{ + 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; +}; +/** struct ComplexTypes adding Sequence, String, Interface, Any to SimpleTypes +*/ +published struct ComplexTypes : SimpleTypes +{ + sequence< long > Sequence; + string String; + com::sun::star::uno::XInterface Interface; + any Any; +}; + +/** A performance test object has to be implemented in a special way, that: + <ul> + <li>queryInterface() execution times remain (nearly) static</li> + <li>functions kept simple, thus there is (nearly) no execution time of the function itself</li> + <li>no dynamic data is ever returned except of createObject(), so return 0, empty strings etc.</li> + </ul> + The interface is divided into three sections: + <ul> + <li>measuring asynchron/ synchron calls</li> + <li>complex data calls with/out return value; in/out parameters</li> + <li>single data types like long, float, string etc.</li> + <li>method calls versa attribute calls</li> + <li>raising RuntimeException</li> + </ul> +*/ +published interface XPerformanceTest : com::sun::star::uno::XInterface +{ + void async(); + void sync(); + + ComplexTypes complex_in( [in] ComplexTypes aVal ); + ComplexTypes complex_inout( [inout] ComplexTypes aVal ); + + void complex_oneway( [in] ComplexTypes aVal ); + void complex_noreturn( [in] ComplexTypes aVal ); + + XPerformanceTest createObject(); + + [attribute] long Long_attr; + [attribute] hyper Hyper_attr; + [attribute] float Float_attr; + [attribute] double Double_attr; + [attribute] string String_attr; + [attribute] com::sun::star::uno::XInterface Interface_attr; + [attribute] any Any_attr; + [attribute] sequence< com::sun::star::uno::XInterface > Sequence_attr; + [attribute] ComplexTypes Struct_attr; + + long getLong(); + void setLong( [in] long n ); + hyper getHyper(); + void setHyper( [in] hyper n ); + float getFloat(); + void setFloat( [in] float f ); + double getDouble(); + void setDouble( [in] double f ); + string getString(); + void setString( [in] string s ); + com::sun::star::uno::XInterface getInterface(); + void setInterface( [in] com::sun::star::uno::XInterface x ); + any getAny(); + void setAny( [in] any a ); + sequence< com::sun::star::uno::XInterface > getSequence(); + void setSequence( [in] sequence< com::sun::star::uno::XInterface > seq ); + ComplexTypes getStruct(); + void setStruct( [in] ComplexTypes c ); + + void raiseRuntimeException(); +}; + + +}; +}; +}; +}; +}; + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/testtools/source/bridgetest/multi.cxx b/testtools/source/bridgetest/multi.cxx new file mode 100644 index 000000000..ce149f154 --- /dev/null +++ b/testtools/source/bridgetest/multi.cxx @@ -0,0 +1,224 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + + +#include <sal/config.h> + +#include "multi.hxx" + +#include <rtl/string.hxx> +#include <rtl/textenc.h> +#include <rtl/ustring.hxx> + +#include <sstream> + +namespace { + +struct CheckFailed { + explicit CheckFailed(OUString const & theMessage): message(theMessage) + {} + + OUString message; +}; + +template< typename T > void checkEqual(T const & value, T const & argument) { + if (argument != value) { + std::ostringstream s; + s << value << " != " << argument; + throw CheckFailed( + OStringToOUString( + OString(s.str().c_str()), RTL_TEXTENCODING_UTF8)); + } +} + +} + +namespace testtools::bridgetest { + +OUString testMulti( css::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( + OUString("12" "abc"), + css::uno::Reference< test::testtools::bridgetest::XMultiBase1 >( + multi, css::uno::UNO_QUERY_THROW)->fn12( + "abc")); + checkEqual( + OUString("12" "abc-2"), + static_cast< test::testtools::bridgetest::XMultiBase2 * >( + multi.get())->fn12("abc-2")); + checkEqual( + OUString("12" "abc-2"), + css::uno::Reference< test::testtools::bridgetest::XMultiBase2 >( + multi, css::uno::UNO_QUERY_THROW)->fn12("abc-2")); + checkEqual( + OUString("12" "abc-5"), + static_cast< test::testtools::bridgetest::XMultiBase5 * >( + multi.get())->fn12("abc-5")); + checkEqual( + OUString("12" "abc-5"), + css::uno::Reference< test::testtools::bridgetest::XMultiBase5 >( + multi, css::uno::UNO_QUERY_THROW)->fn12("abc-5")); + checkEqual< sal_Int32 >(21 * 2, multi->fn21(2)); + checkEqual( + OUString("22" "de"), + multi->fn22("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( + OUString("32" "f"), + css::uno::Reference< test::testtools::bridgetest::XMultiBase3 >( + multi, css::uno::UNO_QUERY_THROW)->fn32("f")); + checkEqual( + OUString("32" "f-5"), + static_cast< test::testtools::bridgetest::XMultiBase5 * >( + multi.get())->fn32("f-5")); + checkEqual( + OUString("32" "f-5"), + css::uno::Reference< test::testtools::bridgetest::XMultiBase5 >( + multi, css::uno::UNO_QUERY_THROW)->fn32("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( + OUString("62" ""), + multi->fn62(OUString())); + checkEqual< sal_Int32 >(71 * 7, multi->fn71(7)); + checkEqual( + OUString("72" "g"), + multi->fn72("g")); + checkEqual< sal_Int32 >(73, multi->fn73()); + } catch (CheckFailed const & f) { + return f.message; + } + return OUString(); +} + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/testtools/source/bridgetest/multi.hxx b/testtools/source/bridgetest/multi.hxx new file mode 100644 index 000000000..f8b6d404b --- /dev/null +++ b/testtools/source/bridgetest/multi.hxx @@ -0,0 +1,104 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#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/implbase.hxx> +#include <rtl/ustring.hxx> +#include <sal/types.h> +#include <test/testtools/bridgetest/XMulti.hpp> + +#include "dllapi.hxx" + +namespace testtools::bridgetest { + +class Multi: public cppu::WeakImplHelper< test::testtools::bridgetest::XMulti > +{ +public: + Multi(): m_attribute1(0.0), m_attribute3(0.0) {} + + virtual double SAL_CALL getatt1() override + { return m_attribute1; } + + virtual void SAL_CALL setatt1(double value) override + { m_attribute1 = value; } + + virtual sal_Int32 SAL_CALL fn11(sal_Int32 arg) override + { return 11 * arg; } + + virtual OUString SAL_CALL fn12(OUString const & arg) override + { return "12" + arg; } + + virtual sal_Int32 SAL_CALL fn21(sal_Int32 arg) override + { return 21 * arg; } + + virtual OUString SAL_CALL fn22(OUString const & arg) override + { return "22" + arg; } + + virtual double SAL_CALL getatt3() override + { return m_attribute3; } + + virtual void SAL_CALL setatt3(double value) override + { m_attribute3 = value; } + + virtual sal_Int32 SAL_CALL fn31(sal_Int32 arg) override + { return 31 * arg; } + + virtual OUString SAL_CALL fn32(OUString const & arg) override + { return "32" + arg; } + + virtual sal_Int32 SAL_CALL fn33() override + { return 33; } + + virtual sal_Int32 SAL_CALL fn41(sal_Int32 arg) override + { return 41 * arg; } + + virtual sal_Int32 SAL_CALL fn61(sal_Int32 arg) override + { return 61 * arg; } + + virtual OUString SAL_CALL fn62(OUString const & arg) override + { return "62" + arg; } + + virtual sal_Int32 SAL_CALL fn71(sal_Int32 arg) override + { return 71 * arg; } + + virtual OUString SAL_CALL fn72(OUString const & arg) override + { return "72" + arg; } + + virtual sal_Int32 SAL_CALL fn73() override + { return 73; } + +private: + double m_attribute1; + double m_attribute3; +}; + +LO_DLLPUBLIC_TESTTOOLS +OUString testMulti( css::uno::Reference< test::testtools::bridgetest::XMulti > const & multi); + +} + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/testtools/source/bridgetest/pyuno/core.py b/testtools/source/bridgetest/pyuno/core.py new file mode 100644 index 000000000..c56e9f144 --- /dev/null +++ b/testtools/source/bridgetest/pyuno/core.py @@ -0,0 +1,358 @@ +# +# This file is part of the LibreOffice project. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# This file incorporates work covered by the following license notice: +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed +# with this work for additional information regarding copyright +# ownership. The ASF licenses this file to you under the Apache +# License, Version 2.0 (the "License"); you may not use this file +# except in compliance with the License. You may obtain a copy of +# the License at http://www.apache.org/licenses/LICENSE-2.0 . +# +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 roundtrip 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 , "exception 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( b"ab" ) + self.failUnless( s == uno.ByteSequence( b"ab" ) ) + self.failUnless( uno.ByteSequence( b"abc" ) == s + uno.ByteSequence( b"c" ) ) + self.failUnless( uno.ByteSequence( b"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 000000000..7fe940424 --- /dev/null +++ b/testtools/source/bridgetest/pyuno/impl.py @@ -0,0 +1,187 @@ +# +# This file is part of the LibreOffice project. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# This file incorporates work covered by the following license notice: +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed +# with this work for additional information regarding copyright +# ownership. The ASF licenses this file to you under the Apache +# License, Version 2.0 (the "License"); you may not use this file +# except in compliance with the License. You may obtain a copy of +# the License at http://www.apache.org/licenses/LICENSE-2.0 . +# +"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 000000000..c4ce8c175 --- /dev/null +++ b/testtools/source/bridgetest/pyuno/importer.py @@ -0,0 +1,69 @@ +# +# This file is part of the LibreOffice project. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# This file incorporates work covered by the following license notice: +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed +# with this work for additional information regarding copyright +# ownership. The ASF licenses this file to you under the Apache +# License, Version 2.0 (the "License"); you may not use this file +# except in compliance with the License. You may obtain a copy of +# the License at http://www.apache.org/licenses/LICENSE-2.0 . +# +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 000000000..9dc101a2e --- /dev/null +++ b/testtools/source/bridgetest/pyuno/main.py @@ -0,0 +1,40 @@ +# +# This file is part of the LibreOffice project. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# This file incorporates work covered by the following license notice: +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed +# with this work for additional information regarding copyright +# ownership. The ASF licenses this file to you under the Apache +# License, Version 2.0 (the "License"); you may not use this file +# except in compliance with the License. You may obtain a copy of +# the License at http://www.apache.org/licenses/LICENSE-2.0 . +# +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 000000000..112be23c9 --- /dev/null +++ b/testtools/source/bridgetest/pyuno/makefile.mk @@ -0,0 +1,117 @@ +# +# This file is part of the LibreOffice project. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# This file incorporates work covered by the following license notice: +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed +# with this work for additional information regarding copyright +# ownership. The ASF licenses this file to you under the Apache +# License, Version 2.0 (the "License"); you may not use this file +# except in compliance with the License. You may obtain a copy of +# the License at http://www.apache.org/licenses/LICENSE-2.0 . +# + +PRJ=..$/..$/.. + +PRJNAME=pyuno +TARGET=test +LIBTARGET=NO +TARGETTYPE=CUI +ENABLE_EXCEPTIONS=TRUE + +my_components = pythonloader + +# --- Settings ----------------------------------------------------- + +.INCLUDE : settings.mk + +.IF "$(CROSS_COMPILING)"=="YES" + +all: +# nothing + +.ENDIF + +# --- Files -------------------------------------------------------- +.IF "$(DISABLE_PYTHON)" != "TRUE" +.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_FOR_BUILD) +.ENDIF # "$(SYSTEM_PYTHON)"!="YES" +.IF "$(OS)"=="WNT" +PYTHONPATH:=$(SOLARLIBDIR)$/pyuno;$(PWD);$(SOLARLIBDIR);$(SOLARLIBDIR)$/python;$(SOLARLIBDIR)$/python$/lib-dynload +.ELSE # "$(OS)"=="WNT" +PYTHONPATH:=$(SOLARLIBDIR)$/pyuno:$(PWD):$(SOLARLIBDIR):$(SOLARLIBDIR)$/python:$(SOLARLIBDIR)$/python$/lib-dynload +.ENDIF # "$(OS)"=="WNT" +.EXPORT: PYTHONPATH + +.IF "$(OS)"!="WNT" +TEST_ENV=export FOO=file://$(shell @pwd)$/$(DLLDEST) \ + UNO_TYPES=uno_types.rdb UNO_SERVICES=pyuno_services.rdb +.ELSE # "$(OS)" != "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=uno_types.rdb && export UNO_SERVICES=pyuno_services.rdb +.ENDIF # "$(OS)"!="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_services.rdb \ + doc \ + ALLTAR +.ENDIF # L10N_framework +.ENDIF # DISABLE_PYTHON + +.INCLUDE : target.mk + +.IF "$(DISABLE_PYTHON)" != "TRUE" +.IF "$(L10N_framework)"=="" +$(DLLDEST)$/%.py: %.py + cp $? $@ + +$(DLLDEST)$/python$(EXECPOST) : $(SOLARBINDIR)$/python$(EXECPOST) + cp $? $@ + +$(DLLDEST)$/regcomp$(EXECPOST) : $(SOLARBINDIR)$/regcomp$(EXECPOST) + cp $? $@ + +$(DLLDEST)$/pyuno_services.rdb .ERRREMOVE : \ + $(SOLARENV)/bin/packcomponents.xslt $(MISC)/pyuno_services.input \ + $(my_components:^"$(SOLARXMLDIR)/":+".component") + $(XSLTPROC) --nonet --stringparam prefix $(SOLARXMLDIR)/ -o $@ \ + $(SOLARENV)/bin/packcomponents.xslt $(MISC)/pyuno_services.input + +$(MISC)/pyuno_services.input : + echo \ + '<list>$(my_components:^"<filename>":+".component</filename>")</list>' \ + > $@ + +doc .PHONY: + @echo start test with dmake runtest + +runtest : ALL + cd $(DLLDEST) && $(TEST_ENV) && $(PYTHON) main.py +.ENDIF # L10N_framework +.ENDIF # DISABLE_PYTHON + diff --git a/testtools/source/bridgetest/pyuno/pyuno b/testtools/source/bridgetest/pyuno/pyuno new file mode 100644 index 000000000..cf2da2cad --- /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 000000000..a434cd0b4 --- /dev/null +++ b/testtools/source/bridgetest/pyuno/samplecomponent.py @@ -0,0 +1,145 @@ +# +# This file is part of the LibreOffice project. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# This file incorporates work covered by the following license notice: +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed +# with this work for additional information regarding copyright +# ownership. The ASF licenses this file to you under the Apache +# License, Version 2.0 (the "License"); you may not use this file +# except in compliance with the License. You may obtain a copy of +# the License at http://www.apache.org/licenses/LICENSE-2.0 . +# +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 000000000..e519d5e8e --- /dev/null +++ b/testtools/source/bridgetest/pyuno/testcomp.py @@ -0,0 +1,31 @@ +# +# This file is part of the LibreOffice project. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# This file incorporates work covered by the following license notice: +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed +# with this work for additional information regarding copyright +# ownership. The ASF licenses this file to you under the Apache +# License, Version 2.0 (the "License"); you may not use this file +# except in compliance with the License. You may obtain a copy of +# the License at http://www.apache.org/licenses/LICENSE-2.0 . +# +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/bridgetest/testComponent.component b/testtools/source/bridgetest/testComponent.component new file mode 100644 index 000000000..e488f702d --- /dev/null +++ b/testtools/source/bridgetest/testComponent.component @@ -0,0 +1,29 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + --> + +<component loader="com.sun.star.loader.Java2" + xmlns="http://openoffice.org/2010/uno-components"> + <implementation + name="com.sun.star.comp.bridge.TestComponent$_PerformancTestObject"> + <service name="com.sun.star.comp.benchmark.JavaTestObject"/> + </implementation> + <implementation name="com.sun.star.comp.bridge.TestComponent$_TestObject"> + <service name="com.sun.star.test.bridge.JavaTestObject"/> + </implementation> +</component> diff --git a/testtools/source/cliversioning/makefile.mk b/testtools/source/cliversioning/makefile.mk new file mode 100644 index 000000000..aabbeb296 --- /dev/null +++ b/testtools/source/cliversioning/makefile.mk @@ -0,0 +1,134 @@ +# +# This file is part of the LibreOffice project. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# This file incorporates work covered by the following license notice: +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed +# with this work for additional information regarding copyright +# ownership. The ASF licenses this file to you under the Apache +# License, Version 2.0 (the "License"); you may not use this file +# except in compliance with the License. You may obtain a copy of +# the License at http://www.apache.org/licenses/LICENSE-2.0 . +# + +# Builds the SpreadSheet examples of the Developers Guide. + +PRJ = ..$/.. +PRJNAME = cli_ure +TARGET := test_climaker +PACKAGE = cliversion + +.INCLUDE: settings.mk + +.IF "$(CROSS_COMPILING)"=="YES" + +all: +# nothing + +.ENDIF + +.INCLUDE : $(PRJ)$/util$/makefile.pmk + +.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 without 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 . diff --git a/testtools/source/cliversioning/readme.txt b/testtools/source/cliversioning/readme.txt new file mode 100644 index 000000000..c2878c383 --- /dev/null +++ b/testtools/source/cliversioning/readme.txt @@ -0,0 +1,93 @@ +# +# This file is part of the LibreOffice project. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# This file incorporates work covered by the following license notice: +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed +# with this work for additional information regarding copyright +# ownership. The ASF licenses this file to you under the Apache +# License, Version 2.0 (the "License"); you may not use this file +# except in compliance with the License. You may obtain a copy of +# the License at http://www.apache.org/licenses/LICENSE-2.0 . +# + + +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 breaking 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 effective. +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 000000000..40cccefc6 --- /dev/null +++ b/testtools/source/cliversioning/runtests.cs @@ -0,0 +1,118 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +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 000000000..b1717148d --- /dev/null +++ b/testtools/source/cliversioning/version.cs @@ -0,0 +1,599 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +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 000000000..a78c22e1a --- /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 000000000..71769a44f --- /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 000000000..823cfc8c8 --- /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 000000000..b16da2df5 --- /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 000000000..9ff42fc23 --- /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 000000000..e89232441 --- /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 000000000..037f5ddee --- /dev/null +++ b/testtools/source/cliversioning/version_libs/version_3_2_1.dll diff --git a/testtools/source/cliversioning/version_libs/version_3_3.dll b/testtools/source/cliversioning/version_libs/version_3_3.dll Binary files differnew file mode 100755 index 000000000..a63a43632 --- /dev/null +++ b/testtools/source/cliversioning/version_libs/version_3_3.dll diff --git a/testtools/source/performance/cli_testobj_performance.cs b/testtools/source/performance/cli_testobj_performance.cs new file mode 100644 index 000000000..4affe89cd --- /dev/null +++ b/testtools/source/performance/cli_testobj_performance.cs @@ -0,0 +1,109 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +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 000000000..51703a046 --- /dev/null +++ b/testtools/source/performance/exports.dxp @@ -0,0 +1,2 @@ +component_writeInfo +component_getFactory diff --git a/testtools/source/performance/makefile.mk b/testtools/source/performance/makefile.mk new file mode 100644 index 000000000..be63e5349 --- /dev/null +++ b/testtools/source/performance/makefile.mk @@ -0,0 +1,89 @@ +# +# This file is part of the LibreOffice project. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# This file incorporates work covered by the following license notice: +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed +# with this work for additional information regarding copyright +# ownership. The ASF licenses this file to you under the Apache +# License, Version 2.0 (the "License"); you may not use this file +# except in compliance with the License. You may obtain a copy of +# the License at http://www.apache.org/licenses/LICENSE-2.0 . +# + +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 = $(ENFORCEDSHLPREFIX)$(ENFORCEDSHLPREFIX)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 = $(ENFORCEDSHLPREFIX)$(ENFORCEDSHLPREFIX)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 000000000..8417a0aa9 --- /dev/null +++ b/testtools/source/performance/pseudo.cxx @@ -0,0 +1,264 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#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> + + +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 > 0 + *(int *)pProxy = 0xdeadbabe; +#endif + delete pThis; +} + +static void SAL_CALL pseudo_unoInterfaceProxy_acquire( uno_Interface * pUnoI ) +{ + if (1 == osl_atomic_increment( &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_atomic_decrement( & 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_atomic_increment( & static_cast< pseudo_Mapping * >( pMapping )->nRef )) + { + OUString aMappingPurpose("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_atomic_decrement( & 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_FAIL( "### 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("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; + } +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/testtools/source/performance/pseudo_uno_uno.map b/testtools/source/performance/pseudo_uno_uno.map new file mode 100644 index 000000000..87862c4d1 --- /dev/null +++ b/testtools/source/performance/pseudo_uno_uno.map @@ -0,0 +1,25 @@ +# +# This file is part of the LibreOffice project. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# This file incorporates work covered by the following license notice: +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed +# with this work for additional information regarding copyright +# ownership. The ASF licenses this file to you under the Apache +# License, Version 2.0 (the "License"); you may not use this file +# except in compliance with the License. You may obtain a copy of +# the License at http://www.apache.org/licenses/LICENSE-2.0 . +# + +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 000000000..e437e9c9c --- /dev/null +++ b/testtools/source/performance/ubobject.cxx @@ -0,0 +1,278 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + + +#include <osl/diagnose.h> +#include <osl/interlck.h> + +#include <cppuhelper/factory.hxx> +#include <cppuhelper/supportsservice.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 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() +{ + return { SERVICENAME }; +} + + +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 ) + {} + explicit ServiceImpl( const Reference< XMultiServiceFactory > & xMgr ) + : _nRef( 0 ) + {} + + // XInterface + virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type& aType ) throw(css::uno::RuntimeException) + { + // execution time remains appr. constant any time + Any aRet; + if (aType == cppu::UnoType<XInterface>::get()) + { + void * p = (XInterface *)(XPerformanceTest *)this; + aRet.setValue( &p, cppu::UnoType<XInterface>::get() ); + } + if (aType == cppu::UnoType<XPerformanceTest>::get()) + { + void * p = (XPerformanceTest *)this; + aRet.setValue( &p, cppu::UnoType<XPerformanceTest>::get() ); + } + if (! aRet.hasValue()) + { + void * p = (XPerformanceTest *)this; + Any aDummy( &p, cppu::UnoType<XPerformanceTest>::get() ); + } + return aRet; + } + virtual void SAL_CALL acquire() throw() + { osl_atomic_increment( &_nRef ); } + virtual void SAL_CALL release() throw() + { if (! osl_atomic_decrement( &_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(css::uno::RuntimeException) + { return 0; } + virtual void SAL_CALL setLong_attr( sal_Int32 _attributelong ) throw(css::uno::RuntimeException) + {} + virtual sal_Int64 SAL_CALL getHyper_attr() throw(css::uno::RuntimeException) + { return 0; } + virtual void SAL_CALL setHyper_attr( sal_Int64 _attributehyper ) throw(css::uno::RuntimeException) + {} + virtual float SAL_CALL getFloat_attr() throw(css::uno::RuntimeException) + { return 0.0; } + virtual void SAL_CALL setFloat_attr( float _attributefloat ) throw(css::uno::RuntimeException) + {} + virtual double SAL_CALL getDouble_attr() throw(css::uno::RuntimeException) + { return 0.0; } + virtual void SAL_CALL setDouble_attr( double _attributedouble ) throw(css::uno::RuntimeException) + {} + virtual OUString SAL_CALL getString_attr() throw(css::uno::RuntimeException) + { return _aDummyString; } + virtual void SAL_CALL setString_attr( const OUString& _attributestring ) throw(css::uno::RuntimeException) + {} + virtual Reference< XInterface > SAL_CALL getInterface_attr() throw(css::uno::RuntimeException) + { return Reference< XInterface >(); } + virtual void SAL_CALL setInterface_attr( const Reference< XInterface >& _attributeinterface ) throw(css::uno::RuntimeException) + {} + virtual Any SAL_CALL getAny_attr() throw(css::uno::RuntimeException) + { return _aDummyAny; } + virtual void SAL_CALL setAny_attr( const Any& _attributeany ) throw(css::uno::RuntimeException) + {} + virtual Sequence< Reference< XInterface > > SAL_CALL getSequence_attr() throw(css::uno::RuntimeException) + { return _aDummySequence; } + virtual void SAL_CALL setSequence_attr( const Sequence< Reference< XInterface > >& _attributesequence ) throw(css::uno::RuntimeException) + {} + virtual ComplexTypes SAL_CALL getStruct_attr() throw(css::uno::RuntimeException) + { return _aDummyStruct; } + virtual void SAL_CALL setStruct_attr( const css::test::performance::ComplexTypes& _attributestruct ) throw(css::uno::RuntimeException) + {} + + // Methods + virtual sal_Int32 SAL_CALL getLong() throw(css::uno::RuntimeException) + { return 0; } + virtual void SAL_CALL setLong( sal_Int32 _long ) throw(css::uno::RuntimeException) + {} + virtual sal_Int64 SAL_CALL getHyper() throw(css::uno::RuntimeException) + { return 0; } + virtual void SAL_CALL setHyper( sal_Int64 _hyper ) throw(css::uno::RuntimeException) + {} + virtual float SAL_CALL getFloat() throw(css::uno::RuntimeException) + { return 0; } + virtual void SAL_CALL setFloat( float _float ) throw(css::uno::RuntimeException) + {} + virtual double SAL_CALL getDouble() throw(css::uno::RuntimeException) + { return 0; } + virtual void SAL_CALL setDouble( double _double ) throw(css::uno::RuntimeException) + {} + virtual OUString SAL_CALL getString() throw(css::uno::RuntimeException) + { return _aDummyString; } + virtual void SAL_CALL setString( const OUString& _string ) throw(css::uno::RuntimeException) + {} + virtual Reference< XInterface > SAL_CALL getInterface() throw(css::uno::RuntimeException) + { return Reference< XInterface >(); } + virtual void SAL_CALL setInterface( const css::uno::Reference< css::uno::XInterface >& _interface ) throw(css::uno::RuntimeException) + {} + virtual Any SAL_CALL getAny() throw(css::uno::RuntimeException) + { return _aDummyAny; } + virtual void SAL_CALL setAny( const css::uno::Any& _any ) throw(css::uno::RuntimeException) + {} + virtual Sequence< Reference< XInterface > > SAL_CALL getSequence() throw(css::uno::RuntimeException) + { return _aDummySequence; } + virtual void SAL_CALL setSequence( const Sequence< Reference< XInterface > >& _sequence ) throw(css::uno::RuntimeException) + {} + virtual ComplexTypes SAL_CALL getStruct() throw(css::uno::RuntimeException) + { return _aDummyStruct; } + virtual void SAL_CALL setStruct( const css::test::performance::ComplexTypes& c ) throw(css::uno::RuntimeException) + {} + + virtual void SAL_CALL async() throw(css::uno::RuntimeException) + {} + virtual void SAL_CALL sync() throw(css::uno::RuntimeException) + {} + virtual ComplexTypes SAL_CALL complex_in( const css::test::performance::ComplexTypes& aVal ) throw(css::uno::RuntimeException) + { return aVal; } + virtual ComplexTypes SAL_CALL complex_inout( css::test::performance::ComplexTypes& aVal ) throw(css::uno::RuntimeException) + { return aVal; } + virtual void SAL_CALL complex_oneway( const css::test::performance::ComplexTypes& aVal ) throw(css::uno::RuntimeException) + {} + virtual void SAL_CALL complex_noreturn( const css::test::performance::ComplexTypes& aVal ) throw(css::uno::RuntimeException) + {} + virtual Reference< XPerformanceTest > SAL_CALL createObject() throw(css::uno::RuntimeException) + { return new ServiceImpl(); } + virtual void SAL_CALL raiseRuntimeException( ) throw(css::uno::RuntimeException) + { throw _aDummyRE; } +}; + + +// XServiceInfo + +OUString ServiceImpl::getImplementationName() + throw (RuntimeException) +{ + return OUString( IMPLNAME ); +} + +sal_Bool ServiceImpl::supportsService( const OUString & rServiceName ) + throw (RuntimeException) +{ + return cppu::supportsService(this, rServiceName); +} + +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" +{ +sal_Bool SAL_CALL component_writeInfo( + void * pServiceManager, void * pRegistryKey ) +{ + if (pRegistryKey) + { + try + { + Reference< XRegistryKey > xNewKey( + reinterpret_cast< XRegistryKey * >( pRegistryKey )->createKey( + OUString( ("/" IMPLNAME "/UNO/SERVICES") ) ) ); + xNewKey->createKey( OUString( SERVICENAME ) ); + + return sal_True; + } + catch (InvalidRegistryException &) + { + OSL_FAIL( "### InvalidRegistryException!" ); + } + } + return sal_False; +} + +SAL_DLLPUBLIC_EXPORT void * SAL_CALL component_getFactory( + const 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( IMPLNAME ), + benchmark_object::ServiceImpl_create, + benchmark_object::getSupportedServiceNames() ) ); + + if (xFactory.is()) + { + xFactory->acquire(); + pRet = xFactory.get(); + } + } + + return pRet; +} +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/testtools/source/performance/ubtest.cxx b/testtools/source/performance/ubtest.cxx new file mode 100644 index 000000000..c30f31ba7 --- /dev/null +++ b/testtools/source/performance/ubtest.cxx @@ -0,0 +1,1275 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + + +#include <stdio.h> +#include <math.h> +#include <string> +#include <map> +#include <unordered_map> + +#include <osl/diagnose.h> +#include <osl/mutex.hxx> +#include <osl/module.h> +#include <osl/process.h> +#include <osl/thread.hxx> +#include <osl/conditn.hxx> +#include <osl/time.h> + +#ifdef _WIN32 +#if !defined WIN32_LEAN_AND_MEAN +# define WIN32_LEAN_AND_MEAN +#endif +#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/lbnames.h> +#include <uno/mapping.hxx> + +#include <cppuhelper/factory.hxx> +#include <cppuhelper/implbase.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 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 _WIN32 + 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 char * pText, FILE * stream = stderr, + sal_Int32 nStart = -1, char cFillchar = ' ' ) +{ + static sal_Int32 s_nPos = 0; + + char ar[2] = { cFillchar, 0 }; + while (s_nPos < nStart) + { + ::fprintf( stream, ar ); + ++s_nPos; + } + + ::fprintf( stream, pText ); + + for ( const 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, 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, char cFillchar = ' ' ) +{ + 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, char cFillchar = ' ' ) +{ + 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.append( "lib" ); + aLibNameBuf.append( rLibName ); + aLibNameBuf.append( ".so" ); +#else + aLibNameBuf.append( rLibName ); + aLibNameBuf.append( ".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( COMPONENT_GETENV ); + if (pSym = osl_getSymbol( lib, aGetEnvName.pData )) + { + uno_Environment * pCurrentEnv = 0; + uno_Environment * pEnv = 0; + const 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( CPPU_CURRENT_LANGUAGE_BINDING_NAME ); + uno_getEnvironment( &pCurrentEnv, aCppEnvTypeName.pData, 0 ); + if (pCurrentEnv) + bNeedsMapping = (pEnv != pCurrentEnv); + } + } + + OUString aGetFactoryName( 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(), cppu::UnoType<XMultiServiceFactory>::get() ); + void * pKey = aCurrent2Env.mapInterface( + xKey.get(), cppu::UnoType<XRegistryKey>::get() ); + + 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, cppu::UnoType<XSingleServiceFactory>::get() ); + (*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( CREATE_COMPONENT_FACTORY_FUNCTION ); + if (pSym = osl_getSymbol( lib, aGetFactoryName.pData )) + { + OUString aCppEnvTypeName( CPPU_CURRENT_LANGUAGE_BINDING_NAME ); + OUString aUnoEnvTypeName( 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(), cppu::UnoType<XMultiServiceFactory>::get() ); + uno_Interface * pUKey = (uno_Interface *)aCpp2Uno.mapInterface( + xKey.get(), cppu::UnoType<XRegistryKey>::get() ); + + 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, cppu::UnoType<XSingleServiceFactory>::get() ); + (*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("acceptor"), + OUString("com.sun.star.comp.stoc.Acceptor"), + xMgr, Reference< XRegistryKey >() ) ) ); + // connector + xSet->insert( makeAny( loadLibComponentFactory( + OUString("connector"), + OUString("com.sun.star.comp.stoc.Connector"), + xMgr, Reference< XRegistryKey >() ) ) ); + // iiop bridge + xSet->insert( makeAny( loadLibComponentFactory( + OUString("remotebridge"), + OUString("com.sun.star.bridge.Bridge.various"), + xMgr, Reference< XRegistryKey >() ) ) ); + // bridge factory + xSet->insert( makeAny( loadLibComponentFactory( + OUString("brdgfctr"), + OUString("com.sun.star.comp.stoc.BridgeFactory"), + xMgr, Reference< XRegistryKey >() ) ) ); + // uno url resolver + xSet->insert( makeAny( loadLibComponentFactory( + OUString("uuresolver"), + OUString("com.sun.star.comp.bridge.UnoUrlResolver"), + xMgr, Reference< XRegistryKey >() ) ) ); + // java loader +// xSet->insert( makeAny( loadLibComponentFactory( +// OUString("javaloader"), +// OUString("com.sun.star.comp.stoc.JavaComponentLoader"), +// xMgr, Reference< XRegistryKey >() ) ) ); + } + s_bSet = sal_True; + } + } + x = xMgr->createInstance( rServiceName ); + } + + if (! x.is()) + { + throw RuntimeException( "cannot get service instance \"" + rServiceName ); + } + + rxOut = Reference< T >::query( x ); + if (! rxOut.is()) + { + throw RuntimeException( "service instance \"" + rServiceName + + "\" does not support demanded interface \"" + cppu::UnoType<T>::get().getTypeName() ); + } +} + + +inline static Sequence< OUString > getSupportedServiceNames() +{ + return { SERVICENAME }; +} + + +class TestImpl : public WeakImplHelper< XServiceInfo, XMain > +{ + Reference< XMultiServiceFactory > _xSMgr; + + Reference< XInterface > _xDirect; + Reference< XInterface > getDirect() throw (Exception); + Reference< XInterface > resolveObject( const OUString & rUnoUrl ) throw (Exception); + +public: + explicit 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( IMPLNAME ); +} + +sal_Bool TestImpl::supportsService( const OUString & rServiceName ) + throw (RuntimeException) +{ + return cppu::supportsService(this, rServiceName); +} + +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("perfobj"), + OUString("com.sun.star.comp.performance.PerformanceTestObject"), + _xSMgr, Reference< XRegistryKey >() ) ); + if (! xFac.is()) + throw RuntimeException("no test object available!" ); + _xDirect = xFac->createInstance(); + } + } + return _xDirect; +} + +Reference< XInterface > TestImpl::resolveObject( const OUString & rUnoUrl ) + throw (Exception) +{ + Reference< XUnoUrlResolver > xResolver; + createInstance( + xResolver, _xSMgr, + OUString("com.sun.star.bridge.UnoUrlResolver") ); + + Reference< XInterface > xResolvedObject( xResolver->resolve( rUnoUrl ) ); + + if (! xResolvedObject.is()) + { + throw RuntimeException( "cannot resolve object \"" + rUnoUrl + "\"!" ); + } + + 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 char * pText, sal_Int64 nLoop, sal_uInt32 nTicks ); +}; + +void TimingSheet::insert( const char * pText, sal_Int64 nLoop, sal_uInt32 nTicks ) +{ + _entries[ pText ] = TimeEntry( nLoop, nTicks ); +} + +typedef std::unordered_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_THROW ); + + sal_Int64 i; + sal_uInt32 tStart, tEnd; + + const Type & rKnownType = cppu::UnoType<XPerformanceTest>::get(); + const Type & rUnKnownType = cppu::UnoType<XSet>::get(); + + 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 (empty)", 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 existing 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].startsWith( rParam ) && + 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("dms"); + + try + { + OUString aLoopStr( extractParam( rArgs, OUString("loop") ) ); + if (aLoopStr.getLength()) + { + sal_Int64 n = aLoopStr.toInt64(); + if (n > 0) + nLoop = n; + } + + OUString aDurationStr( extractParam( rArgs , OUString("duration" ) ) ); + if( aDurationStr.getLength() ) + { + sal_Int64 n = aDurationStr.toInt64(); + if( n >0 ) + nLoop = nMagicNumberDirect * n; + } + + OUString aLogStr( extractParam( rArgs, OUString("log") ) ); + if (aLogStr.getLength()) + { + if (aLogStr.equalsAscii( "stderr" ) ) + { + stream = stderr; + } + else if (aLogStr.equalsAscii( "stdout" ) ) + { + stream = stdout; + } + else + { + OString aFileName( OUStringToOString( aLogStr, RTL_TEXTENCODING_ASCII_US ) ); + stream = ::fopen( aFileName.getStr(), "w" ); + if (! stream) + { + throw RuntimeException( "cannot open file for writing: \"" + aLogStr + "\"!" ); + } + } + } + + OUString aArgStr( extractParam( rArgs, OUString("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 == stdout) + 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( 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("pseudo") ); + if (! aMapping.is()) + throw RuntimeException("no pseudo mapping available!" ); + + Reference< XInterface > xMapped; + Reference< XInterface > xDirect( getDirect() ); + aMapping.mapInterface( reinterpret_cast< void ** >( &xMapped ), xDirect.get(), + cppu::UnoType<decltype(xDirect)>::get() ); + if (! xMapped.is()) + throw RuntimeException("mapping object failed!" ); + + 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("cannot get current security handle!" ); + + OUString aArgs[] = { + OUString("-c"), + OUString("com.sun.star.comp.performance.PerformanceTestObject"), + OUString("-l"), +#ifdef SAL_UNX + OUString("libperfobj.so"), +#else + OUString("perfobj.dll"), +#endif + OUString("-r"), + OUString("applicat.rdb"), + OUString("-u"), + OUString("uno:socket,host=localhost,port=6000;iiop;TestRemoteObject"), + OUString("--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, + }; + + 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("uno"); + OUString aWorkingDir("."); + 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("cannot start server process!" ); + osl_freeProcessHandle( hProcess ); + + // wait three seconds + osl::Thread::wait(std::chrono::seconds(3)); + + // connect and resolve outer process object + Reference< XInterface > xResolvedObject( resolveObject( OUString("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("url") ) ); + if (! aUnoUrl.getLength()) + throw RuntimeException( "performance test r(emote) needs additional uno url!" ); + + // 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("com.sun.star.comp.benchmark.JavaTestObject"), + nLoop / 1000 ); + } + + + // dump out tables + + out( "\nTimes( ratio to direct in process )", stream ); + out( ":", stream ); + + sal_Int32 nPos = 60; + out( "[direct in process]", stream, nPos ); + for ( const auto& rSheet : aSheets ) + { + nPos += 40; + out( "[", stream, nPos ); + out( rSheet.first.c_str(), stream ); + out( "]", stream ); + } + for ( const auto& rTopics : aDirect._entries ) + { + const std::string & rTopic = rTopics.first; + + out( "\n", stream ); + out( rTopic.c_str(), stream ); + + out( ":", stream, 58, '.' ); + + sal_Int32 nPos = 60; + + double secs = rTopics.second.secPerCall(); + if (secs > 0.0) + { + out( secs * 1000, stream, nPos ); + out( "ms", stream ); + } + else + { + out( "NA", stream, nPos ); + } + + for ( const auto& rSheet : aSheets ) + { + const t_TimeEntryMap::const_iterator iFind( rSheet.second._entries.find( rTopic ) ); + OSL_ENSURE( iFind != rSheet.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( rTopics.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" +{ + +sal_Bool SAL_CALL component_writeInfo( + void * pServiceManager, void * pRegistryKey ) +{ + if (pRegistryKey) + { + try + { + Reference< XRegistryKey > xNewKey( + reinterpret_cast< XRegistryKey * >( pRegistryKey )->createKey( + OUString( "/" IMPLNAME "/UNO/SERVICES" ) ) ); + xNewKey->createKey( OUString( SERVICENAME ) ); + + return sal_True; + } + catch (InvalidRegistryException &) + { + OSL_FAIL( "### InvalidRegistryException!" ); + } + } + return sal_False; +} + +SAL_DLLPUBLIC_EXPORT void * SAL_CALL component_getFactory( + const 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( IMPLNAME ), + benchmark_test::TestImpl_create, + benchmark_test::getSupportedServiceNames() ) ); + + if (xFactory.is()) + { + xFactory->acquire(); + pRet = xFactory.get(); + } + } + + return pRet; +} +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/testtools/source/servicetests/LocalServiceTest.java b/testtools/source/servicetests/LocalServiceTest.java new file mode 100644 index 000000000..ee890faa4 --- /dev/null +++ b/testtools/source/servicetests/LocalServiceTest.java @@ -0,0 +1,45 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +package 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 { + @Override + 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 000000000..e63048bf6 --- /dev/null +++ b/testtools/source/servicetests/RemoteServiceTest.java @@ -0,0 +1,113 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +package servicetests; + +import com.sun.star.bridge.XBridgeFactory; +import com.sun.star.bridge.XInstanceProvider; +import com.sun.star.bridge.XUnoUrlResolver; +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 java.io.BufferedReader; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.PrintStream; + +public final class RemoteServiceTest extends TestBase { + @Override + 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 { + XUnoUrlResolver resolver = UnoUrlResolver.create(Bootstrap.createInitialComponentContext(null)); + String sUrl = "uno:" + CONNECTION_DESCRIPTION + ";" + + PROTOCOL_DESCRIPTION + + ";testtools.servicetests.TestService2"; + return resolver.resolve(sUrl); + } + + 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) { + @Override + 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 000000000..20532ff4d --- /dev/null +++ b/testtools/source/servicetests/TestBase.java @@ -0,0 +1,80 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +package servicetests; + +import com.sun.star.uno.UnoRuntime; +import complexlib.ComplexTestCase; +import util.WaitUnreachable; + +public abstract class TestBase extends ComplexTestCase { + @Override + 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); + assure(t.getProp3Long() == 3); + assure(t.getProp4Long() == 4); + assure(t.getProp5Long() == 5); + assure(t.getProp6() == 6); + t.setProp6(0); + assure(t.getProp6() == 0); + assure(t.getProp7() == 7); + t.setProp7(0); + assure(t.getProp7() == 0); + 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 000000000..a825f0df1 --- /dev/null +++ b/testtools/source/servicetests/TestService.java @@ -0,0 +1,127 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +package 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 getProp3Long(){ + return 3; + } + public int getProp4Long(){ + return 4; + } + + public int getProp5Long() + { + return 5; + } + + public int getProp6() { + return prop6.intValue(); + } + + public void setProp6(int value) { + prop6 = Integer.valueOf(value); + } + + public int getProp7() + { + return prop7.intValue(); + } + + public void setProp7(int value) { + prop7 = Integer.valueOf(value); + } + + public int getProp8Long() { + return prop8; + } + + public void setProp8Long(int value) + { + prop8 = value; + } + + public int fn2() { + return 2; + } + + public int fn3() { + return 3; + } + + private int prop1 = 1; + private Integer prop6 = Integer.valueOf(6); + private Integer prop7 = Integer.valueOf(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 000000000..386b62e58 --- /dev/null +++ b/testtools/source/servicetests/TestService1.idl @@ -0,0 +1,49 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef __testtools_servicetests_TestService1_idl__ +#define __testtools_servicetests_TestService1_idl__ + +#include <XTestService1.idl> + +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 + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/testtools/source/servicetests/TestService2.idl b/testtools/source/servicetests/TestService2.idl new file mode 100644 index 000000000..dc06f5c45 --- /dev/null +++ b/testtools/source/servicetests/TestService2.idl @@ -0,0 +1,41 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef __testtools_servicetests_TestService2_idl__ +#define __testtools_servicetests_TestService2_idl__ + +#include <TestService1.idl> +#include <XTestService2.idl> +#include <XTestService3.idl> +#include <XTestService4.idl> + +module servicetests { + +interface TestService2 { + interface TestService1; + interface XTestService2; + /*[optional] interface XTestService3;*/ + /*[optional] interface XTestService4;*/ +}; + +}; + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/testtools/source/servicetests/XTestService1.idl b/testtools/source/servicetests/XTestService1.idl new file mode 100644 index 000000000..9e0d80295 --- /dev/null +++ b/testtools/source/servicetests/XTestService1.idl @@ -0,0 +1,35 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef __testtools_servicetests_XTestService1_idl__ +#define __testtools_servicetests_XTestService1_idl__ + +#include <com/sun/star/uno/XInterface.idl> + +module servicetests { + +interface XTestService1: com::sun::star::uno::XInterface { + long fn1(); +}; + +}; + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/testtools/source/servicetests/XTestService2.idl b/testtools/source/servicetests/XTestService2.idl new file mode 100644 index 000000000..98f48b49b --- /dev/null +++ b/testtools/source/servicetests/XTestService2.idl @@ -0,0 +1,35 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef __testtools_servicetests_XTestService2_idl__ +#define __testtools_servicetests_XTestService2_idl__ + +#include <com/sun/star/uno/XInterface.idl> + +module servicetests { + +interface XTestService2: com::sun::star::uno::XInterface { + long fn2(); +}; + +}; + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/testtools/source/servicetests/XTestService3.idl b/testtools/source/servicetests/XTestService3.idl new file mode 100644 index 000000000..493426542 --- /dev/null +++ b/testtools/source/servicetests/XTestService3.idl @@ -0,0 +1,35 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef __testtools_servicetests_XTestService3_idl__ +#define __testtools_servicetests_XTestService3_idl__ + +#include <com/sun/star/uno/XInterface.idl> + +module servicetests { + +interface XTestService3: com::sun::star::uno::XInterface { + long fn3(); +}; + +}; + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/testtools/source/servicetests/XTestService4.idl b/testtools/source/servicetests/XTestService4.idl new file mode 100644 index 000000000..f2d7e5b9b --- /dev/null +++ b/testtools/source/servicetests/XTestService4.idl @@ -0,0 +1,35 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef __testtools_servicetests_XTestService4_idl__ +#define __testtools_servicetests_XTestService4_idl__ + +#include <com/sun/star/uno/XInterface.idl> + +module servicetests { + +interface XTestService4: com::sun::star::uno::XInterface { + long fn4(); +}; + +}; + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/testtools/source/servicetests/makefile.mk b/testtools/source/servicetests/makefile.mk new file mode 100644 index 000000000..fd59d8415 --- /dev/null +++ b/testtools/source/servicetests/makefile.mk @@ -0,0 +1,35 @@ +# +# This file is part of the LibreOffice project. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# This file incorporates work covered by the following license notice: +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed +# with this work for additional information regarding copyright +# ownership. The ASF licenses this file to you under the Apache +# License, Version 2.0 (the "License"); you may not use this file +# except in compliance with the License. You may obtain a copy of +# the License at http://www.apache.org/licenses/LICENSE-2.0 . +# + +PRJ := ..$/.. +PRJNAME := testtools +TARGET := testtools_servicetests + +PACKAGE := 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 |