LCOV - code coverage report
Current view: top level - libreoffice/testtools/source/bridgetest - bridgetest.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 605 673 89.9 %
Date: 2012-12-17 Functions: 57 60 95.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : 
      21             : #include <stdio.h>
      22             : #include <string.h>
      23             : #include <osl/diagnose.h>
      24             : #include "osl/diagnose.hxx"
      25             : #include <osl/time.h>
      26             : #include <sal/types.h>
      27             : #include "typelib/typedescription.hxx"
      28             : #include <uno/dispatcher.hxx>
      29             : #include "uno/mapping.hxx"
      30             : #include <uno/data.h>
      31             : #include "uno/environment.hxx"
      32             : 
      33             : #include <cppuhelper/factory.hxx>
      34             : #include <cppuhelper/implbase2.hxx>
      35             : #include <cppuhelper/implbase1.hxx>
      36             : 
      37             : #include <com/sun/star/lang/XServiceInfo.hpp>
      38             : #include <com/sun/star/lang/XComponent.hpp>
      39             : #include <com/sun/star/lang/XMain.hpp>
      40             : #include <com/sun/star/bridge/UnoUrlResolver.hpp>
      41             : #include <com/sun/star/bridge/XUnoUrlResolver.hpp>
      42             : #include "com/sun/star/uno/RuntimeException.hpp"
      43             : #include "com/sun/star/uno/Type.hxx"
      44             : 
      45             : #include "test/testtools/bridgetest/BadConstructorArguments.hpp"
      46             : #include "test/testtools/bridgetest/TestPolyStruct.hpp"
      47             : #include "test/testtools/bridgetest/XBridgeTest.hpp"
      48             : #include "test/testtools/bridgetest/XBridgeTest2.hpp"
      49             : #include "test/testtools/bridgetest/XMulti.hpp"
      50             : 
      51             : #include "currentcontextchecker.hxx"
      52             : #include "multi.hxx"
      53             : 
      54             : using namespace osl;
      55             : using namespace cppu;
      56             : using namespace com::sun::star::uno;
      57             : using namespace com::sun::star::lang;
      58             : using namespace com::sun::star::registry;
      59             : using namespace com::sun::star::bridge;
      60             : using namespace test::testtools::bridgetest;
      61             : 
      62             : using ::rtl::OUString;
      63             : using ::rtl::OString;
      64             : using ::rtl::OUStringToOString;
      65             : 
      66             : #define SERVICENAME     "com.sun.star.test.bridge.BridgeTest"
      67             : #define IMPLNAME        "com.sun.star.comp.bridge.BridgeTest"
      68             : 
      69             : #define OUSTR(x) ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(x) )
      70             : #define STRING_TEST_CONSTANT "\" paco\' chorizo\\\' \"\'"
      71             : 
      72             : namespace bridge_test
      73             : {
      74             : template< class T>
      75             : Sequence<T> cloneSequence(const Sequence<T>& val);
      76             : 
      77             : //--------------------------------------------------------------------------------------------------
      78           2 : inline static Sequence< OUString > getSupportedServiceNames()
      79             : {
      80           2 :     OUString aName( RTL_CONSTASCII_USTRINGPARAM(SERVICENAME) );
      81           2 :     return Sequence< OUString >( &aName, 1 );
      82             : }
      83             : 
      84        1142 : static bool check( bool b , char const * message )
      85             : {
      86        1142 :     if ( ! b )
      87           0 :         fprintf( stderr, "%s failed\n" , message );
      88        1142 :     return b;
      89             : }
      90             : 
      91             : namespace {
      92             : 
      93           4 : bool checkEmpty(rtl::OUString const & string, char const * message) {
      94           4 :     bool ok = string.isEmpty();
      95           4 :     if (!ok) {
      96             :         fprintf(
      97             :             stderr, "%s failed: %s\n", message,
      98           0 :             rtl::OUStringToOString(string, RTL_TEXTENCODING_UTF8).getStr());
      99             :     }
     100           4 :     return ok;
     101             : }
     102             : 
     103             : }
     104             : 
     105             : //==================================================================================================
     106             : class TestBridgeImpl : public osl::DebugBase<TestBridgeImpl>,
     107             :                        public WeakImplHelper2< XMain, XServiceInfo >
     108             : {
     109             :     Reference< XComponentContext > m_xContext;
     110             : 
     111             : public:
     112           2 :     TestBridgeImpl( const Reference< XComponentContext > & xContext )
     113           2 :         : m_xContext( xContext )
     114           2 :         {}
     115           4 :     virtual ~TestBridgeImpl()
     116           2 :     {
     117           4 :     }
     118             : 
     119             :     // XServiceInfo
     120             :     virtual OUString SAL_CALL getImplementationName() throw (RuntimeException);
     121             :     virtual sal_Bool SAL_CALL supportsService( const OUString & rServiceName ) throw (RuntimeException);
     122             :     virtual Sequence< OUString > SAL_CALL getSupportedServiceNames() throw (RuntimeException);
     123             : 
     124             :     // XMain
     125             :     virtual sal_Int32 SAL_CALL run( const Sequence< OUString > & rArgs ) throw (RuntimeException);
     126             : };
     127             : 
     128             : //==================================================================================================
     129          66 : static sal_Bool equals( const TestElement & rData1, const TestElement & rData2 )
     130             : {
     131          66 :     check( rData1.Bool == rData2.Bool, "### bool does not match!" );
     132          66 :     check( rData1.Char == rData2.Char, "### char does not match!" );
     133          66 :     check( rData1.Byte == rData2.Byte, "### byte does not match!" );
     134          66 :     check( rData1.Short == rData2.Short, "### short does not match!" );
     135          66 :     check( rData1.UShort == rData2.UShort, "### unsigned short does not match!" );
     136          66 :     check( rData1.Long == rData2.Long, "### long does not match!" );
     137          66 :     check( rData1.ULong == rData2.ULong, "### unsigned long does not match!" );
     138          66 :     check( rData1.Hyper == rData2.Hyper, "### hyper does not match!" );
     139          66 :     check( rData1.UHyper == rData2.UHyper, "### unsigned hyper does not match!" );
     140          66 :     check( rData1.Float == rData2.Float, "### float does not match!" );
     141          66 :     check( rData1.Double == rData2.Double, "### double does not match!" );
     142          66 :     check( rData1.Enum == rData2.Enum, "### enum does not match!" );
     143          66 :     check( rData1.String == rData2.String, "### string does not match!" );
     144          66 :     check( rData1.Interface == rData2.Interface, "### interface does not match!" );
     145          66 :     check( rData1.Any == rData2.Any, "### any does not match!" );
     146             : 
     147             :     return (rData1.Bool == rData2.Bool &&
     148             :             rData1.Char == rData2.Char &&
     149             :             rData1.Byte == rData2.Byte &&
     150             :             rData1.Short == rData2.Short &&
     151             :             rData1.UShort == rData2.UShort &&
     152             :             rData1.Long == rData2.Long &&
     153             :             rData1.ULong == rData2.ULong &&
     154             :             rData1.Hyper == rData2.Hyper &&
     155             :             rData1.UHyper == rData2.UHyper &&
     156             :             rData1.Float == rData2.Float &&
     157             :             rData1.Double == rData2.Double &&
     158             :             rData1.Enum == rData2.Enum &&
     159          66 :             rData1.String == rData2.String &&
     160          66 :             rData1.Interface == rData2.Interface &&
     161         198 :             rData1.Any == rData2.Any);
     162             : }
     163             : //==================================================================================================
     164          22 : static sal_Bool equals( const TestData & rData1, const TestData & rData2 )
     165             : {
     166             :     sal_Int32 nLen;
     167             : 
     168          88 :     if ((rData1.Sequence == rData2.Sequence) &&
     169          22 :         equals( (const TestElement &)rData1, (const TestElement &)rData2 ) &&
     170          44 :         (nLen = rData1.Sequence.getLength()) == rData2.Sequence.getLength())
     171             :     {
     172             :         // once again by hand sequence ==
     173          22 :         const TestElement * pElements1 = rData1.Sequence.getConstArray();
     174          22 :         const TestElement * pElements2 = rData2.Sequence.getConstArray();
     175          22 :         for ( ; nLen--; )
     176             :         {
     177          44 :             if (! equals( pElements1[nLen], pElements2[nLen] ))
     178             :             {
     179           0 :                 check( sal_False, "### sequence element did not match!" );
     180           0 :                 return sal_False;
     181             :             }
     182             :         }
     183          22 :         return sal_True;
     184             :     }
     185           0 :     return sal_False;
     186             : }
     187             : //==================================================================================================
     188          10 : static void assign( TestElement & rData,
     189             :                     sal_Bool bBool, sal_Unicode cChar, sal_Int8 nByte,
     190             :                     sal_Int16 nShort, sal_uInt16 nUShort,
     191             :                     sal_Int32 nLong, sal_uInt32 nULong,
     192             :                     sal_Int64 nHyper, sal_uInt64 nUHyper,
     193             :                     float fFloat, double fDouble,
     194             :                     TestEnum eEnum, const ::rtl::OUString& rStr,
     195             :                     const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& xTest,
     196             :                     const ::com::sun::star::uno::Any& rAny )
     197             : {
     198          10 :     rData.Bool = bBool;
     199          10 :     rData.Char = cChar;
     200          10 :     rData.Byte = nByte;
     201          10 :     rData.Short = nShort;
     202          10 :     rData.UShort = nUShort;
     203          10 :     rData.Long = nLong;
     204          10 :     rData.ULong = nULong;
     205          10 :     rData.Hyper = nHyper;
     206          10 :     rData.UHyper = nUHyper;
     207          10 :     rData.Float = fFloat;
     208          10 :     rData.Double = fDouble;
     209          10 :     rData.Enum = eEnum;
     210          10 :     rData.String = rStr;
     211          10 :     rData.Interface = xTest;
     212          10 :     rData.Any = rAny;
     213          10 : }
     214             : 
     215             : namespace {
     216             : 
     217             : template < typename T >
     218          28 : bool testAny(
     219             :     T const & value, Reference< XBridgeTest > const & xLBT,
     220             :     char const * typeName = 0)
     221             : {
     222          28 :     Any any;
     223          28 :     any <<=  value;
     224          28 :     Any any2 = xLBT->transportAny(any);
     225          28 :     bool success = true;
     226          28 :     if (any != any2) {
     227             :         fprintf(
     228             :             stderr, "any is different after roundtrip: in %s, out %s\n",
     229             :             OUStringToOString(
     230             :                 any.getValueType().getTypeName(),
     231             :                 RTL_TEXTENCODING_ASCII_US).getStr(),
     232             :             OUStringToOString(
     233             :                 any2.getValueType().getTypeName(),
     234           0 :                 RTL_TEXTENCODING_ASCII_US).getStr());
     235           0 :         success = false;
     236             :     }
     237          28 :     if (typeName != 0
     238             :         && !any2.getValueType().getTypeName().equalsAscii(typeName))
     239             :     {
     240             :         fprintf(
     241             :             stderr, "any has wrong type after roundtrip: %s instead of %s\n",
     242             :             OUStringToOString(
     243             :                 any2.getValueType().getTypeName(),
     244             :                 RTL_TEXTENCODING_ASCII_US).getStr(),
     245           0 :             typeName);
     246           0 :         success = false;
     247             :     }
     248          28 :     return success;
     249             : }
     250             : 
     251             : }
     252             : 
     253           2 : static sal_Bool performAnyTest( const Reference< XBridgeTest > &xLBT, const TestData &data)
     254             : {
     255           2 :     bool bReturn = true;
     256           2 :     bReturn = testAny( data.Byte ,xLBT ) && bReturn;
     257           2 :     bReturn = testAny( data.Short,xLBT ) && bReturn;
     258           2 :     bReturn = testAny( data.UShort,xLBT ) && bReturn;
     259           2 :     bReturn = testAny( data.Long,xLBT ) && bReturn;
     260           2 :     bReturn = testAny( data.ULong,xLBT ) && bReturn;
     261           2 :     bReturn = testAny( data.Hyper,xLBT ) && bReturn;
     262           2 :     bReturn = testAny( data.UHyper,xLBT ) && bReturn;
     263           2 :     bReturn = testAny( data.Float,xLBT ) && bReturn;
     264           2 :     bReturn = testAny( data.Double,xLBT ) && bReturn;
     265           2 :     bReturn = testAny( data.Enum,xLBT ) && bReturn;
     266           2 :     bReturn = testAny( data.String,xLBT ) && bReturn;
     267           2 :     bReturn = testAny( data.Interface,xLBT ) && bReturn;
     268           2 :     bReturn = testAny( data, xLBT ) && bReturn;
     269             :     bReturn &= testAny(
     270             :         TestPolyStruct< sal_Unicode >(' '), xLBT,
     271           2 :         "test.testtools.bridgetest.TestPolyStruct<char>");
     272             : 
     273           2 :     Any a;
     274             :     {
     275           2 :         a.setValue( &(data.Bool) , getCppuBooleanType() );
     276           2 :         Any a2 = xLBT->transportAny( a );
     277           2 :         OSL_ASSERT( a2 == a );
     278             :     }
     279             : 
     280             :     {
     281           2 :         a.setValue( &(data.Char) , getCppuCharType() );
     282           2 :         Any a2 = xLBT->transportAny( a );
     283           2 :         OSL_ASSERT( a2 == a );
     284             :     }
     285             : 
     286           2 :     return bReturn;
     287             : }
     288             : 
     289             : //_______________________________________________________________________________________
     290           2 : static sal_Bool performSequenceOfCallTest( const Reference < XBridgeTest > &xLBT )
     291             : {
     292             :     sal_Int32 i,nRounds;
     293           2 :     sal_Int32 nGlobalIndex = 0;
     294           2 :     const sal_Int32 nWaitTimeSpanMUSec = 10000;
     295          22 :     for( nRounds = 0 ; nRounds < 10 ; nRounds ++ )
     296             :     {
     297         110 :         for( i = 0 ; i < nRounds ; i ++ )
     298             :         {
     299             :             // fire oneways
     300          90 :             xLBT->callOneway( nGlobalIndex , nWaitTimeSpanMUSec );
     301          90 :             nGlobalIndex ++;
     302             :         }
     303             : 
     304             :         // call synchron
     305          20 :         xLBT->call( nGlobalIndex , nWaitTimeSpanMUSec );
     306          20 :         nGlobalIndex ++;
     307             :     }
     308             : 
     309           2 :     return xLBT->sequenceOfCallTestPassed();
     310             : }
     311             : 
     312           6 : class ORecursiveCall : public WeakImplHelper1< XRecursiveCall >
     313             : {
     314             : private:
     315             :     Mutex m_mutex;
     316             : 
     317             : public:
     318          50 :     void SAL_CALL callRecursivly(
     319             :         const ::com::sun::star::uno::Reference< XRecursiveCall >& xCall,
     320             :         sal_Int32 nToCall )
     321             :         throw(::com::sun::star::uno::RuntimeException)
     322             :         {
     323          50 :             MutexGuard guard( m_mutex );
     324          50 :             if( nToCall )
     325             :             {
     326          50 :                 nToCall --;
     327          50 :                 xCall->callRecursivly( this , nToCall );
     328          50 :             }
     329             : 
     330          50 :         }
     331             : };
     332             : 
     333             : 
     334             : //_______________________________________________________________________________________
     335           2 : static sal_Bool performRecursiveCallTest( const Reference < XBridgeTest > & xLBT )
     336             : {
     337           2 :     xLBT->startRecursiveCall( new ORecursiveCall , 50 );
     338             :     // on failure, the test would lock up or crash
     339           2 :     return sal_True;
     340             : }
     341             : 
     342             : class MyClass : public osl::DebugBase<MyClass>, public OWeakObject
     343             : {
     344             : public:
     345             :     MyClass();
     346             :     virtual ~MyClass();
     347             :     virtual void SAL_CALL acquire() throw ();
     348             :     virtual void SAL_CALL release() throw ();
     349             : };
     350             : 
     351             : //______________________________________________________________________________
     352           2 : MyClass::MyClass()
     353             : {
     354           2 : }
     355             : //______________________________________________________________________________
     356           4 : MyClass::~MyClass()
     357             : {
     358           4 : }
     359             : //______________________________________________________________________________
     360         160 : void MyClass::acquire() throw ()
     361             : {
     362         160 :     OWeakObject::acquire();
     363         160 : }
     364             : //______________________________________________________________________________
     365         160 : void MyClass::release() throw ()
     366             : {
     367         160 :     OWeakObject::release();
     368         160 : }
     369             : 
     370             : //==================================================================================================
     371           2 : static sal_Bool performTest(
     372             :     const Reference<XComponentContext> & xContext,
     373             :     const Reference<XBridgeTest > & xLBT,
     374             :     bool noCurrentContext )
     375             : {
     376           2 :     check(xLBT.is(), "### no test interface!");
     377           2 :     bool bRet = true;
     378           2 :     if (xLBT.is()) {
     379             :         // this data is never ever granted access to by calls other than
     380             :         // equals(), assign()!
     381           2 :         TestData aData; // test against this data
     382           2 :         Reference< XInterface > xI(new MyClass);
     383             :         assign(
     384             :             (TestElement &) aData, true, '@', 17, 0x1234, 0xFEDC, 0x12345678,
     385             :             0xFEDCBA98, SAL_CONST_INT64(0x123456789ABCDEF0),
     386             :             SAL_CONST_UINT64(0xFEDCBA9876543210), 17.0815f, 3.1415926359,
     387             :             TestEnum_LOLA, OUSTR(STRING_TEST_CONSTANT), xI,
     388           2 :             Any(&xI, getCppuType((Reference< XInterface > const *) 0)));
     389           2 :         bRet &= check(aData.Any == xI, "### unexpected any!");
     390           2 :         bRet &= check(!(aData.Any != xI), "### unexpected any!");
     391           2 :         aData.Sequence.realloc(2);
     392           2 :         aData.Sequence[0] = *(TestElement const *) &aData;
     393             :         // aData.Sequence[1] is empty
     394             :         // aSetData is a manually copy of aData for first setting:
     395           2 :         TestData aSetData;
     396             :         assign(
     397             :             (TestElement &) aSetData, aData.Bool, aData.Char, aData.Byte,
     398             :             aData.Short, aData.UShort, aData.Long, aData.ULong, aData.Hyper,
     399             :             aData.UHyper, aData.Float, aData.Double, aData.Enum, aData.String,
     400           2 :             xI, Any(&xI, getCppuType((Reference< XInterface > const *) 0)));
     401           2 :         aSetData.Sequence.realloc(2);
     402           2 :         aSetData.Sequence[0] = *(TestElement const *) &aSetData;
     403             :         // aSetData.Sequence[1] is empty
     404           2 :         xLBT->setValues(
     405             :             aSetData.Bool, aSetData.Char, aSetData.Byte, aSetData.Short,
     406             :             aSetData.UShort, aSetData.Long, aSetData.ULong, aSetData.Hyper,
     407             :             aSetData.UHyper, aSetData.Float, aSetData.Double, aSetData.Enum,
     408             :             aSetData.String, aSetData.Interface, aSetData.Any,
     409           2 :             aSetData.Sequence, aSetData);
     410             :         {
     411           2 :             TestData aRet;
     412           2 :             TestData aRet2;
     413           2 :             xLBT->getValues(
     414             :                 aRet.Bool, aRet.Char, aRet.Byte, aRet.Short, aRet.UShort,
     415             :                 aRet.Long, aRet.ULong, aRet.Hyper, aRet.UHyper, aRet.Float,
     416             :                 aRet.Double, aRet.Enum, aRet.String, aRet.Interface, aRet.Any,
     417           2 :                 aRet.Sequence, aRet2);
     418             :             bRet &= check(
     419           2 :                 equals(aData, aRet) && equals(aData, aRet2), "getValues test");
     420             :             // Set last retrieved values:
     421             :             TestData aSV2ret(
     422           2 :                 xLBT->setValues2(
     423             :                     aRet.Bool, aRet.Char, aRet.Byte, aRet.Short, aRet.UShort,
     424             :                     aRet.Long, aRet.ULong, aRet.Hyper, aRet.UHyper, aRet.Float,
     425             :                     aRet.Double, aRet.Enum, aRet.String, aRet.Interface,
     426           2 :                     aRet.Any, aRet.Sequence, aRet2));
     427             :             // Check inout sequence order (=> inout sequence parameter was
     428             :             // switched by test objects):
     429           2 :             TestElement temp(aRet.Sequence[0]);
     430           2 :             aRet.Sequence[0] = aRet.Sequence[1];
     431           2 :             aRet.Sequence[1] = temp;
     432             :             bRet &= check(
     433           4 :                 equals(aData, aSV2ret) && equals(aData, aRet2),
     434           4 :                 "getValues2 test");
     435             :         }
     436             :         {
     437           2 :             TwoFloats aIn(1.1f, 2.2f);
     438           2 :             TwoFloats aOut = xLBT->echoTwoFloats(aIn);
     439           2 :             bRet = check( memcmp(&aIn, &aOut, sizeof(TwoFloats)) == 0, "two floats struct test" ) && bRet;
     440             :         }
     441             :         {
     442           2 :             FourFloats aIn(3.3f, 4.4f, 5.5f, 6.6f);
     443           2 :             FourFloats aOut = xLBT->echoFourFloats(aIn);
     444           2 :             bRet = check( memcmp(&aIn, &aOut, sizeof(FourFloats)) == 0, "four floats struct test" ) && bRet;
     445             :         }
     446             :         {
     447           2 :             MixedFloatAndInteger aIn(7.7f, 8);
     448           2 :             MixedFloatAndInteger aOut = xLBT->echoMixedFloatAndInteger(aIn);
     449           2 :             bRet = check( memcmp(&aIn, &aOut, sizeof(MixedFloatAndInteger)) == 0, "mixed float and integer struct test" ) && bRet;
     450             :         }
     451             :         {
     452           2 :             ThreeByteStruct aIn(9, 10, 11);
     453           2 :             ThreeByteStruct aOut = xLBT->echoThreeByteStruct(aIn);
     454           2 :             bRet = check( memcmp(&aIn, &aOut, sizeof(ThreeByteStruct)) == 0, "three byte struct test" ) && bRet;
     455             :         }
     456             :         {
     457           2 :             TestData aRet;
     458           2 :             TestData aRet2;
     459             :             TestData aGVret(
     460           2 :                 xLBT->getValues(
     461             :                     aRet.Bool, aRet.Char, aRet.Byte, aRet.Short, aRet.UShort,
     462             :                     aRet.Long, aRet.ULong, aRet.Hyper, aRet.UHyper, aRet.Float,
     463             :                     aRet.Double, aRet.Enum, aRet.String, aRet.Interface,
     464           2 :                     aRet.Any, aRet.Sequence, aRet2));
     465             :             bRet &= check(
     466           4 :                 (equals(aData, aRet) && equals(aData, aRet2) &&
     467           2 :                  equals(aData, aGVret)),
     468           6 :                 "getValues test");
     469             :             // Set last retrieved values:
     470           2 :             xLBT->setBool(aRet.Bool);
     471           2 :             xLBT->setChar(aRet.Char);
     472           2 :             xLBT->setByte(aRet.Byte);
     473           2 :             xLBT->setShort(aRet.Short);
     474           2 :             xLBT->setUShort(aRet.UShort);
     475           2 :             xLBT->setLong(aRet.Long);
     476           2 :             xLBT->setULong(aRet.ULong);
     477           2 :             xLBT->setHyper(aRet.Hyper);
     478           2 :             xLBT->setUHyper(aRet.UHyper);
     479           2 :             xLBT->setFloat(aRet.Float);
     480           2 :             xLBT->setDouble(aRet.Double);
     481           2 :             xLBT->setEnum(aRet.Enum);
     482           2 :             xLBT->setString(aRet.String);
     483           2 :             xLBT->setInterface(aRet.Interface);
     484           2 :             xLBT->setAny(aRet.Any);
     485           2 :             xLBT->setSequence(aRet.Sequence);
     486           2 :             xLBT->setStruct(aRet2);
     487             :         }
     488             :         {
     489           2 :             TestData aRet;
     490           2 :             aRet.Hyper = xLBT->getHyper();
     491           2 :             aRet.UHyper = xLBT->getUHyper();
     492           2 :             aRet.Float = xLBT->getFloat();
     493           2 :             aRet.Double = xLBT->getDouble();
     494           2 :             aRet.Byte = xLBT->getByte();
     495           2 :             aRet.Char = xLBT->getChar();
     496           2 :             aRet.Bool = xLBT->getBool();
     497           2 :             aRet.Short = xLBT->getShort();
     498           2 :             aRet.UShort = xLBT->getUShort();
     499           2 :             aRet.Long = xLBT->getLong();
     500           2 :             aRet.ULong = xLBT->getULong();
     501           2 :             aRet.Enum = xLBT->getEnum();
     502           2 :             aRet.String = xLBT->getString();
     503           2 :             aRet.Interface = xLBT->getInterface();
     504           2 :             aRet.Any = xLBT->getAny();
     505           2 :             aRet.Sequence = xLBT->getSequence();
     506           2 :             TestData aRet2(xLBT->getStruct());
     507             :             bRet &= check(
     508           4 :                 equals(aData, aRet) && equals(aData, aRet2),
     509           4 :                 "struct comparison test");
     510             :             {
     511           2 :                 SmallStruct aIn(1, 2);
     512           2 :                 SmallStruct aOut(xLBT->echoSmallStruct(aIn));
     513             :                 bRet &= check(
     514           2 :                     memcmp(&aIn, &aOut, sizeof(SmallStruct)) == 0,
     515           2 :                     "small struct test");
     516             :             }
     517             :             {
     518           2 :                 MediumStruct aIn(1, 2, 3, 4);
     519           2 :                 MediumStruct aOut(xLBT->echoMediumStruct(aIn));
     520             :                 bRet &= check(
     521           2 :                     memcmp(&aIn, &aOut, sizeof(MediumStruct)) == 0,
     522           2 :                     "medium struct test");
     523             :             }
     524             :             {
     525           2 :                 BigStruct aIn(1, 2, 3, 4, 5, 6, 7, 8);
     526           2 :                 BigStruct aOut(xLBT->echoBigStruct(aIn));
     527             :                 bRet &= check(
     528           2 :                     memcmp(&aIn, &aOut, sizeof(BigStruct)) == 0,
     529           2 :                     "big struct test");
     530             :             }
     531             :             {
     532           2 :                 sal_Int32 i2 = xLBT->testPPCAlignment(0, 0, 0, 0, 0xBEAF);
     533           2 :                 bRet &= check(i2 == 0xBEAF, "ppc-style alignment test");
     534             :             }
     535             :             {
     536           2 :                 double d1 = xLBT->testTenDoubles(0.1, 0.2, 0.3, 0.4, 0.5,
     537           2 :                     0.6, 0.7, 0.8, 0.9, 1.0);
     538           2 :                 bRet &= check(d1 == 5.5, "armhf doubles test");
     539             :             }
     540             :             // Test extended attributes that raise exceptions:
     541             :             try {
     542           2 :                 xLBT->getRaiseAttr1();
     543           0 :                 bRet &= check(false, "getRaiseAttr1 did not throw");
     544           2 :             } catch (const RuntimeException &) {
     545           0 :             } catch (...) {
     546           0 :                 bRet &= check(false, "getRaiseAttr1 threw wrong type");
     547             :             }
     548             :             try {
     549           2 :                 xLBT->setRaiseAttr1(0);
     550           0 :                 bRet &= check(false, "setRaiseAttr1 did not throw");
     551           2 :             } catch (const IllegalArgumentException &) {
     552           0 :             } catch (...) {
     553           0 :                 bRet &= check(false, "setRaiseAttr1 threw wrong type");
     554             :             }
     555             :             try {
     556           2 :                 xLBT->getRaiseAttr2();
     557           0 :                 bRet &= check(false, "getRaiseAttr2 did not throw");
     558           2 :             } catch (const IllegalArgumentException &) {
     559           0 :             } catch (...) {
     560           0 :                 bRet &= check(false, "getRaiseAttr2 threw wrong type");
     561             :             }
     562             :             // Test instantiated polymorphic struct types:
     563             :             {
     564             :                 bRet &= check(
     565           2 :                     (xLBT->transportPolyBoolean(
     566           4 :                         TestPolyStruct< sal_Bool >(true)).
     567             :                      member),
     568           2 :                     "transportPolyBoolean");
     569           2 :                 TestPolyStruct< sal_Int64 > tps1(12345);
     570           2 :                 xLBT->transportPolyHyper(tps1);
     571           2 :                 bRet &= check(tps1.member == 12345, "transportPolyHyper");
     572           2 :                 Sequence< Any > seq(2);
     573           2 :                 seq[0] <<= static_cast< sal_uInt32 >(33);
     574           2 :                 seq[1] <<= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ABC"));
     575           2 :                 TestPolyStruct< Sequence< Any > > tps2(seq);
     576           2 :                 TestPolyStruct< Sequence< Any > > tps3;
     577           2 :                 xLBT->transportPolySequence(tps2, tps3);
     578             :                 bRet &= check(
     579           2 :                     tps3.member.getLength() == 2,
     580           2 :                     "transportPolySequence, length");
     581           2 :                 sal_uInt32 v0 = sal_uInt32();
     582           2 :                 tps3.member[0] >>= v0;
     583           2 :                 bRet &= check(v0 == 33, "transportPolySequence, element 0");
     584           2 :                 rtl::OUString v1;
     585           2 :                 tps3.member[1] >>= v1;
     586           2 :                 bRet &= check( v1 == "ABC", "transportPolySequence, element 1" );
     587             :                 bRet &= check(
     588           2 :                     xLBT->getNullPolyLong().member == 0, "getNullPolyLong");
     589             :                 bRet &= check(
     590           4 :                     xLBT->getNullPolyString().member.isEmpty(),
     591           2 :                     "getNullPolyString");
     592             :                 bRet &= check(
     593           4 :                     xLBT->getNullPolyType().member == Type(),
     594           2 :                     "getNullPolyType");
     595           2 :                 Any nullAny(xLBT->getNullPolyAny().member);
     596             :                 bRet &= check(
     597             :                     (((nullAny.getValueTypeName() ==
     598             :                        rtl::OUString(
     599             :                            RTL_CONSTASCII_USTRINGPARAM(
     600           8 :                                "com.sun.star.uno.XInterface"))) &&
     601             :                       !static_cast< Reference< XInterface > const * >(
     602           0 :                           nullAny.getValue())->is())
     603           6 :                      || nullAny == Any()),
     604          12 :                     "getNullPolyAny");
     605             :                 bRet &= check(
     606           4 :                     xLBT->getNullPolySequence().member.getLength() == 0,
     607           2 :                     "getNullPolySequence");
     608             :                 bRet &= check(
     609           2 :                     xLBT->getNullPolyEnum().member == TestEnum_TEST,
     610           2 :                     "getNullPolyEnum");
     611             :                 bRet &= check(
     612           2 :                     xLBT->getNullPolyBadEnum().member == TestBadEnum_M,
     613           2 :                     "getNullPolyBadEnum");
     614             :                 bRet &= check(
     615           2 :                     xLBT->getNullPolyStruct().member.member == 0,
     616           2 :                     "getNullPolyStruct");
     617             :                 bRet &= check(
     618           4 :                     !xLBT->getNullPolyInterface().member.is(),
     619           4 :                     "getNullPolyInterface");
     620             :             }
     621             :             // Any test:
     622           2 :             bRet &= check(performAnyTest(xLBT , aData), "any test");
     623             :             // Sequence of call test:
     624             :             bRet &= check(
     625           2 :                 performSequenceOfCallTest(xLBT), "sequence of call test");
     626             :             // Recursive call test:
     627           2 :             bRet &= check(performRecursiveCallTest(xLBT), "recursive test");
     628             :             bRet &= check(
     629           4 :                 equals(aData, aRet) && equals(aData, aRet2),
     630           4 :                 "recursive test results");
     631             :             // Multiple inheritance test:
     632             :             bRet &= checkEmpty(
     633           4 :                 testtools::bridgetest::testMulti(xLBT->getMulti()),
     634           4 :                 "remote multi");
     635             :             bRet &= checkEmpty(
     636           4 :                 xLBT->testMulti(new testtools::bridgetest::Multi),
     637           4 :                 "local multi");
     638           2 :         }
     639             :     }
     640             :     {
     641           2 :         Reference< XBridgeTest2 > xBT2(xLBT, UNO_QUERY);
     642           2 :         if (!xBT2.is()) {
     643           0 :             return bRet;
     644             :         }
     645             :         // Perform sequence tests (XBridgeTest2); create the sequence which is
     646             :         // compared with the results:
     647           2 :         sal_Bool _arBool[] = { true, false, true };
     648           2 :         sal_Unicode _arChar[] = { 0x0065, 0x0066, 0x0067 };
     649           2 :         sal_Int8 _arByte[] = { 1, 2, -1 };
     650           2 :         sal_Int16 _arShort[] = { -0x8000, 1, 0x7FFF };
     651           2 :         sal_uInt16 _arUShort[] = { 0 , 1, 0xFFFF };
     652             :         sal_Int32 _arLong[] = {
     653           2 :             static_cast< sal_Int32 >(0x80000000), 1, 0x7FFFFFFF };
     654           2 :         sal_uInt32 _arULong[] = { 0, 1, 0xFFFFFFFF };
     655             :         sal_Int64 _arHyper[] = {
     656             :             static_cast< sal_Int64 >(SAL_CONST_INT64(0x8000000000000000)), 1,
     657           2 :             SAL_CONST_INT64(0x7FFFFFFFFFFFFFFF) };
     658           2 :         sal_uInt64 _arUHyper[] = { 0, 1, SAL_CONST_UINT64(0xFFFFFFFFFFFFFFFF) };
     659           2 :         float _arFloat[] = { 1.1f, 2.2f, 3.3f };
     660           2 :         double _arDouble[] = { 1.11, 2.22, 3.33 };
     661             :         OUString _arString[] = {
     662             :             OUString(RTL_CONSTASCII_USTRINGPARAM("String 1")),
     663             :             OUString(RTL_CONSTASCII_USTRINGPARAM("String 2")),
     664           8 :             OUString(RTL_CONSTASCII_USTRINGPARAM("String 3")) };
     665           2 :         sal_Bool _aBool = true;
     666           2 :         sal_Int32 _aInt = 0xBABEBABE;
     667           2 :         float _aFloat = 3.14f;
     668           2 :         Any _any1(&_aBool, getCppuBooleanType());
     669           2 :         Any _any2(&_aInt, getCppuType((sal_Int32 *) 0));
     670           2 :         Any _any3(&_aFloat, getCppuType((float *) 0));
     671           8 :         Any _arAny[] = { _any1, _any2, _any3 };
     672           8 :         Reference< XInterface > _arObj[3];
     673           2 :         _arObj[0] = new OWeakObject();
     674           2 :         _arObj[1] = new OWeakObject();
     675           2 :         _arObj[2] = new OWeakObject();
     676           2 :         TestEnum _arEnum[] = { TestEnum_ONE, TestEnum_TWO, TestEnum_CHECK };
     677           8 :         TestElement _arStruct[3];
     678             :         assign(
     679             :             _arStruct[0], true, '@', 17, 0x1234, 0xFEDC, 0x12345678, 0xFEDCBA98,
     680             :             SAL_CONST_INT64(0x123456789ABCDEF0),
     681             :             SAL_CONST_UINT64(0xFEDCBA9876543210), 17.0815f, 3.1415926359,
     682             :             TestEnum_LOLA, OUSTR(STRING_TEST_CONSTANT), _arObj[0],
     683           2 :             Any(&_arObj[0], getCppuType((Reference< XInterface > const *) 0)));
     684             :         assign(
     685             :             _arStruct[1], true, 'A', 17, 0x1234, 0xFEDC, 0x12345678, 0xFEDCBA98,
     686             :             SAL_CONST_INT64(0x123456789ABCDEF0),
     687             :             SAL_CONST_UINT64(0xFEDCBA9876543210), 17.0815f, 3.1415926359,
     688             :             TestEnum_TWO, OUSTR(STRING_TEST_CONSTANT), _arObj[1],
     689           2 :             Any(&_arObj[1], getCppuType((Reference< XInterface > const *) 0)));
     690             :         assign(
     691             :             _arStruct[2], true, 'B', 17, 0x1234, 0xFEDC, 0x12345678, 0xFEDCBA98,
     692             :             SAL_CONST_INT64(0x123456789ABCDEF0),
     693             :             SAL_CONST_UINT64(0xFEDCBA9876543210), 17.0815f, 3.1415926359,
     694             :             TestEnum_CHECK, OUSTR(STRING_TEST_CONSTANT), _arObj[2],
     695           2 :             Any(&_arObj[2], getCppuType((Reference< XInterface > const *) 0)));
     696             :         {
     697           2 :             Sequence<sal_Bool> arBool(_arBool, 3);
     698           2 :             Sequence<sal_Unicode> arChar( _arChar, 3);
     699           2 :             Sequence<sal_Int8> arByte(_arByte, 3);
     700           2 :             Sequence<sal_Int16> arShort(_arShort, 3);
     701           2 :             Sequence<sal_uInt16> arUShort(_arUShort, 3);
     702           2 :             Sequence<sal_Int32> arLong(_arLong, 3);
     703           2 :             Sequence<sal_uInt32> arULong(_arULong, 3);
     704           2 :             Sequence<sal_Int64> arHyper(_arHyper, 3);
     705           2 :             Sequence<sal_uInt64> arUHyper(_arUHyper, 3);
     706           2 :             Sequence<float> arFloat(_arFloat, 3);
     707           2 :             Sequence<double> arDouble(_arDouble, 3);
     708           2 :             Sequence<OUString> arString(_arString, 3);
     709           2 :             Sequence<Any> arAny(_arAny, 3);
     710           2 :             Sequence<Reference<XInterface> > arObject(_arObj, 3);
     711           2 :             Sequence<TestEnum> arEnum(_arEnum, 3);
     712           2 :             Sequence<TestElement> arStruct(_arStruct, 3);
     713           8 :             Sequence<Sequence<sal_Int32> > _arSeqLong2[3];
     714           8 :             for (int j = 0; j != 3; ++j) {
     715          24 :                 Sequence< sal_Int32 > _arSeqLong[3];
     716          24 :                 for (int i = 0; i != 3; ++i) {
     717          18 :                     _arSeqLong[i] = Sequence< sal_Int32 >(_arLong, 3);
     718             :                 }
     719             :                 _arSeqLong2[j] = Sequence< Sequence< sal_Int32 > >(
     720           6 :                     _arSeqLong, 3);
     721          24 :             }
     722             :             Sequence< Sequence< Sequence< sal_Int32> > > arLong3(
     723           2 :                 _arSeqLong2, 3);
     724             :             Sequence< Sequence< sal_Int32 > > seqSeqRet(
     725           2 :                 xBT2->setDim2(arLong3[0]));
     726           2 :             bRet &= check(seqSeqRet == arLong3[0], "sequence test");
     727             :             Sequence< Sequence< Sequence< sal_Int32 > > > seqSeqRet2(
     728           2 :                 xBT2->setDim3(arLong3));
     729           2 :             bRet &= check(seqSeqRet2 == arLong3, "sequence test");
     730           2 :             Sequence< Any > seqAnyRet(xBT2->setSequenceAny(arAny));
     731           2 :             bRet &= check(seqAnyRet == arAny, "sequence test");
     732           2 :             Sequence< sal_Bool > seqBoolRet(xBT2->setSequenceBool(arBool));
     733           2 :             bRet &= check(seqBoolRet == arBool, "sequence test");
     734           2 :             Sequence< sal_Int8 > seqByteRet(xBT2->setSequenceByte(arByte));
     735           2 :             bRet &= check(seqByteRet == arByte, "sequence test");
     736           2 :             Sequence< sal_Unicode > seqCharRet(xBT2->setSequenceChar(arChar));
     737           2 :             bRet &= check(seqCharRet == arChar, "sequence test");
     738           2 :             Sequence< sal_Int16 > seqShortRet(xBT2->setSequenceShort(arShort));
     739           2 :             bRet &= check(seqShortRet == arShort, "sequence test");
     740           2 :             Sequence< sal_Int32 > seqLongRet(xBT2->setSequenceLong(arLong));
     741           2 :             bRet &= check(seqLongRet == arLong, "sequence test");
     742           2 :             Sequence< sal_Int64 > seqHyperRet(xBT2->setSequenceHyper(arHyper));
     743           2 :             bRet &= check(seqHyperRet == arHyper, "sequence test");
     744           2 :             Sequence< float > seqFloatRet(xBT2->setSequenceFloat(arFloat));
     745           2 :             bRet &= check(seqFloatRet == arFloat, "sequence test");
     746           2 :             Sequence< double > seqDoubleRet(xBT2->setSequenceDouble(arDouble));
     747           2 :             bRet &= check(seqDoubleRet == arDouble, "sequence test");
     748           2 :             Sequence< TestEnum > seqEnumRet(xBT2->setSequenceEnum(arEnum));
     749           2 :             bRet &= check(seqEnumRet == arEnum, "sequence test");
     750             :             Sequence< sal_uInt16 > seqUShortRet(
     751           2 :                 xBT2->setSequenceUShort(arUShort));
     752           2 :             bRet &= check(seqUShortRet == arUShort, "sequence test");
     753           2 :             Sequence< sal_uInt32 > seqULongRet(xBT2->setSequenceULong(arULong));
     754           2 :             bRet &= check(seqULongRet == arULong, "sequence test");
     755             :             Sequence< sal_uInt64 > seqUHyperRet(
     756           2 :                 xBT2->setSequenceUHyper(arUHyper));
     757           2 :             bRet &= check(seqUHyperRet == arUHyper, "sequence test");
     758             :             Sequence< Reference< XInterface > > seqObjectRet(
     759           2 :                 xBT2->setSequenceXInterface(arObject));
     760           2 :             bRet &= check(seqObjectRet == arObject, "sequence test");
     761             :             Sequence< OUString > seqStringRet(
     762           2 :                 xBT2->setSequenceString(arString));
     763           2 :             bRet &= check(seqStringRet == arString, "sequence test");
     764             :             Sequence< TestElement > seqStructRet(
     765           2 :                 xBT2->setSequenceStruct(arStruct));
     766           2 :             bRet &= check(seqStructRet == arStruct, "sequence test");
     767           2 :             Sequence< sal_Bool > arBoolTemp(cloneSequence(arBool));
     768           2 :             Sequence< sal_Unicode > arCharTemp(cloneSequence(arChar));
     769           2 :             Sequence< sal_Int8 > arByteTemp(cloneSequence(arByte));
     770           2 :             Sequence< sal_Int16 > arShortTemp(cloneSequence(arShort));
     771           2 :             Sequence< sal_uInt16 > arUShortTemp(cloneSequence(arUShort));
     772           2 :             Sequence< sal_Int32 > arLongTemp(cloneSequence(arLong));
     773           2 :             Sequence< sal_uInt32 > arULongTemp(cloneSequence(arULong));
     774           2 :             Sequence< sal_Int64 > arHyperTemp(cloneSequence(arHyper));
     775           2 :             Sequence< sal_uInt64 > arUHyperTemp(cloneSequence(arUHyper));
     776           2 :             Sequence< float > arFloatTemp(cloneSequence(arFloat));
     777           2 :             Sequence< double > arDoubleTemp(cloneSequence(arDouble));
     778           2 :             Sequence< TestEnum > arEnumTemp(cloneSequence(arEnum));
     779           2 :             Sequence< OUString > arStringTemp(cloneSequence(arString));
     780             :             Sequence< Reference< XInterface > > arObjectTemp(
     781           2 :                 cloneSequence(arObject));
     782           2 :             Sequence< Any > arAnyTemp(cloneSequence(arAny));
     783           2 :             Sequence< Sequence< sal_Int32 > > arLong2Temp(arLong3[0]);
     784           2 :             Sequence< Sequence< Sequence< sal_Int32 > > > arLong3Temp(arLong3);
     785           2 :             xBT2->setSequencesInOut(
     786             :                 arBoolTemp, arCharTemp, arByteTemp, arShortTemp, arUShortTemp,
     787             :                 arLongTemp,arULongTemp, arHyperTemp, arUHyperTemp, arFloatTemp,
     788             :                 arDoubleTemp, arEnumTemp, arStringTemp, arObjectTemp, arAnyTemp,
     789           2 :                 arLong2Temp, arLong3Temp);
     790             :             bRet &= check(
     791           4 :                 (arBoolTemp == arBool && arCharTemp == arChar &&
     792           4 :                  arByteTemp == arByte && arShortTemp == arShort &&
     793           4 :                  arUShortTemp == arUShort && arLongTemp == arLong &&
     794           4 :                  arULongTemp == arULong && arHyperTemp == arHyper &&
     795           4 :                  arUHyperTemp == arUHyper && arFloatTemp == arFloat &&
     796           4 :                  arDoubleTemp == arDouble && arEnumTemp == arEnum &&
     797           4 :                  arStringTemp == arString && arObjectTemp == arObject &&
     798           4 :                  arAnyTemp == arAny && arLong2Temp == arLong3[0] &&
     799           2 :                  arLong3Temp == arLong3),
     800          34 :                 "sequence test");
     801           2 :             Sequence< sal_Bool > arBoolOut;
     802           2 :             Sequence< sal_Unicode > arCharOut;
     803           2 :             Sequence< sal_Int8 > arByteOut;
     804           2 :             Sequence< sal_Int16 > arShortOut;
     805           2 :             Sequence< sal_uInt16 > arUShortOut;
     806           2 :             Sequence< sal_Int32 > arLongOut;
     807           2 :             Sequence< sal_uInt32 > arULongOut;
     808           2 :             Sequence< sal_Int64 > arHyperOut;
     809           2 :             Sequence< sal_uInt64 > arUHyperOut;
     810           2 :             Sequence< float > arFloatOut;
     811           2 :             Sequence< double > arDoubleOut;
     812           2 :             Sequence< TestEnum > arEnumOut;
     813           2 :             Sequence< OUString > arStringOut;
     814           2 :             Sequence< Reference< XInterface > > arObjectOut;
     815           2 :             Sequence< Any > arAnyOut;
     816           2 :             Sequence< Sequence< sal_Int32 > > arLong2Out;
     817           2 :             Sequence< Sequence< Sequence< sal_Int32 > > > arLong3Out;
     818           2 :             xBT2->setSequencesOut(
     819             :                 arBoolOut, arCharOut, arByteOut, arShortOut, arUShortOut,
     820             :                 arLongOut,arULongOut, arHyperOut, arUHyperOut, arFloatOut,
     821             :                 arDoubleOut, arEnumOut, arStringOut, arObjectOut, arAnyOut,
     822           2 :                 arLong2Out, arLong3Out);
     823             :             bRet &= check(
     824           4 :                 (arBoolOut == arBool && arCharOut == arChar &&
     825           4 :                  arByteOut == arByte && arShortOut == arShort &&
     826           4 :                  arUShortOut == arUShort && arLongOut == arLong &&
     827           4 :                  arULongOut == arULong && arHyperOut == arHyper &&
     828           4 :                  arUHyperOut == arUHyper && arFloatOut == arFloat &&
     829           4 :                  arDoubleOut == arDouble && arEnumOut == arEnum &&
     830           4 :                  arStringOut == arString && arObjectOut == arObject &&
     831           4 :                  arAnyOut == arAny && arLong2Out == arLong3[0] &&
     832           2 :                  arLong3Out == arLong3),
     833          40 :                 "sequence test");
     834             :         }
     835             :         {
     836             :             // Test with empty sequences:
     837           2 :             Sequence< Sequence< sal_Int32 > > arLong2;
     838           2 :             Sequence< Sequence< sal_Int32 > > seqSeqRet(xBT2->setDim2(arLong2));
     839           2 :             bRet &= check(seqSeqRet == arLong2, "sequence test");
     840           2 :             Sequence< Sequence< Sequence< sal_Int32 > > > arLong3;
     841             :             Sequence< Sequence< Sequence< sal_Int32 > > > seqSeqRet2(
     842           2 :                 xBT2->setDim3(arLong3));
     843           2 :             bRet &= check(seqSeqRet2 == arLong3, "sequence test");
     844           2 :             Sequence< Any > arAny;
     845           2 :             Sequence< Any > seqAnyRet(xBT2->setSequenceAny(arAny));
     846           2 :             bRet &= check(seqAnyRet == arAny, "sequence test");
     847           2 :             Sequence< sal_Bool > arBool;
     848           2 :             Sequence< sal_Bool > seqBoolRet(xBT2->setSequenceBool(arBool));
     849           2 :             bRet &= check(seqBoolRet == arBool, "sequence test");
     850           2 :             Sequence< sal_Int8 > arByte;
     851           2 :             Sequence< sal_Int8 > seqByteRet(xBT2->setSequenceByte(arByte));
     852           2 :             bRet &= check(seqByteRet == arByte, "sequence test");
     853           2 :             Sequence< sal_Unicode > arChar;
     854           2 :             Sequence< sal_Unicode > seqCharRet(xBT2->setSequenceChar(arChar));
     855           2 :             bRet &= check(seqCharRet == arChar, "sequence test");
     856           2 :             Sequence< sal_Int16 > arShort;
     857           2 :             Sequence< sal_Int16 > seqShortRet(xBT2->setSequenceShort(arShort));
     858           2 :             bRet &= check(seqShortRet == arShort, "sequence test");
     859           2 :             Sequence< sal_Int32 > arLong;
     860           2 :             Sequence< sal_Int32 > seqLongRet(xBT2->setSequenceLong(arLong));
     861           2 :             bRet &= check(seqLongRet == arLong, "sequence test");
     862           2 :             Sequence< sal_Int64 > arHyper;
     863           2 :             Sequence< sal_Int64 > seqHyperRet(xBT2->setSequenceHyper(arHyper));
     864           2 :             bRet &= check(seqHyperRet == arHyper, "sequence test");
     865           2 :             Sequence< float > arFloat;
     866           2 :             Sequence< float > seqFloatRet(xBT2->setSequenceFloat(arFloat));
     867           2 :             bRet &= check(seqFloatRet == arFloat, "sequence test");
     868           2 :             Sequence< double > arDouble;
     869           2 :             Sequence< double > seqDoubleRet(xBT2->setSequenceDouble(arDouble));
     870           2 :             bRet &= check(seqDoubleRet == arDouble, "sequence test");
     871           2 :             Sequence< TestEnum > arEnum;
     872           2 :             Sequence< TestEnum > seqEnumRet(xBT2->setSequenceEnum(arEnum));
     873           2 :             bRet &= check(seqEnumRet == arEnum, "sequence test");
     874           2 :             Sequence< sal_uInt16 > arUShort;
     875             :             Sequence< sal_uInt16 > seqUShortRet(
     876           2 :                 xBT2->setSequenceUShort(arUShort));
     877           2 :             bRet &= check(seqUShortRet == arUShort, "sequence test");
     878           2 :             Sequence< sal_uInt32 > arULong;
     879           2 :             Sequence< sal_uInt32 > seqULongRet(xBT2->setSequenceULong(arULong));
     880           2 :             bRet &= check(seqULongRet == arULong, "sequence test");
     881           2 :             Sequence< sal_uInt64 > arUHyper;
     882             :             Sequence< sal_uInt64 > seqUHyperRet(
     883           2 :                 xBT2->setSequenceUHyper(arUHyper));
     884           2 :             bRet &= check(seqUHyperRet == arUHyper, "sequence test");
     885           2 :             Sequence< Reference< XInterface > > arObject;
     886             :             Sequence< Reference< XInterface > > seqObjectRet(
     887           2 :                 xBT2->setSequenceXInterface(arObject));
     888           2 :             bRet &= check(seqObjectRet == arObject, "sequence test");
     889           2 :             Sequence< OUString > arString;
     890             :             Sequence< OUString > seqStringRet(
     891           2 :                 xBT2->setSequenceString(arString));
     892           2 :             bRet &= check(seqStringRet == arString, "sequence test");
     893           2 :             Sequence< TestElement > arStruct;
     894             :             Sequence< TestElement > seqStructRet(
     895           2 :                 xBT2->setSequenceStruct(arStruct));
     896           2 :             bRet &= check(seqStructRet == arStruct, "sequence test");
     897             :         }
     898             :         // Issue #i60341# shows that the most interesting case is were Java
     899             :         // calls the constructors; however, since this client is currently not
     900             :         // available in Java, while the server is, the logic is reversed here:
     901             :         try {
     902           2 :             xBT2->testConstructorsService(xContext);
     903           0 :         } catch (const BadConstructorArguments &) {
     904           0 :             bRet = false;
     905             :         }
     906           2 :         if (!noCurrentContext) {
     907           6 :             if (!(new testtools::bridgetest::CurrentContextChecker)->perform(
     908           6 :                     xBT2->getCurrentContextChecker(), 0, 1))
     909             :             {
     910           0 :                 bRet = false;
     911             :             }
     912           6 :             if (!(new testtools::bridgetest::CurrentContextChecker)->perform(
     913           6 :                     xBT2->getCurrentContextChecker(), 0, 2))
     914             :             {
     915           0 :                 bRet = false;
     916             :             }
     917           6 :             if (!(new testtools::bridgetest::CurrentContextChecker)->perform(
     918           6 :                     xBT2->getCurrentContextChecker(), 1, 2))
     919             :             {
     920           0 :                 bRet = false;
     921             :             }
     922           6 :             if (!(new testtools::bridgetest::CurrentContextChecker)->perform(
     923           6 :                     xBT2->getCurrentContextChecker(), 1, 3))
     924             :             {
     925           0 :                 bRet = false;
     926             :             }
     927          26 :         }
     928             :     }
     929           2 :     return bRet;
     930             : }
     931             : 
     932           2 : static sal_Bool raiseOnewayException( const Reference < XBridgeTest > & xLBT )
     933             : {
     934           2 :     sal_Bool bReturn = sal_True;
     935           2 :     OUString sCompare = OUSTR(STRING_TEST_CONSTANT);
     936           2 :     Reference<XInterface> const x(xLBT->getInterface());
     937             :     try
     938             :     {
     939             :         // Note : the exception may fly or not (e.g. remote scenario).
     940             :         //        When it flies, it must contain the correct elements.
     941           2 :         xLBT->raiseRuntimeExceptionOneway( sCompare, x );
     942             :     }
     943           2 :     catch( const RuntimeException & e )
     944             :     {
     945             :         bReturn = (
     946             : #if OSL_DEBUG_LEVEL == 0
     947             :             // java stack traces trash Message
     948           2 :             e.Message == sCompare &&
     949             : #endif
     950           6 :             xLBT->getInterface() == e.Context &&
     951           8 :             x == e.Context );
     952             :     }
     953           2 :     return bReturn;
     954             : }
     955             : 
     956             : //==================================================================================================
     957           2 : static sal_Bool raiseException( const Reference< XBridgeTest > & xLBT )
     958             : {
     959           2 :     sal_Int32 nCount = 0;
     960             :     try
     961             :     {
     962             :         try
     963             :         {
     964             :             try
     965             :             {
     966           2 :                 TestData aRet, aRet2;
     967           2 :                 xLBT->raiseException(
     968             :                     5, OUSTR(STRING_TEST_CONSTANT),
     969           4 :                     xLBT->getInterface() );
     970             :             }
     971           2 :             catch (const IllegalArgumentException &rExc)
     972             :             {
     973          10 :                 if (rExc.ArgumentPosition == 5 &&
     974             : #if OSL_DEBUG_LEVEL == 0
     975             :                     // java stack traces trash Message
     976           2 :                     rExc.Message.compareToAscii( STRING_TEST_CONSTANT ) == 0 &&
     977             : #endif
     978           6 :                     rExc.Context == xLBT->getInterface())
     979             :                 {
     980             : #ifdef COMPCHECK
     981             :                     //When we check if a new compiler still works then we must not call
     982             :                     //getRuntimeException because it uses cppu::getCaughtException which
     983             :                     //does only work if all libs are build with the same runtime.
     984             :                     return true;
     985             : #else
     986           2 :                     ++nCount;
     987             : #endif
     988             :                 }
     989             :                 else
     990             :                 {
     991           0 :                     check( sal_False, "### unexpected exception content!" );
     992             :                 }
     993             : 
     994             :                 /** it is certain, that the RuntimeException testing will fail, if no */
     995           2 :                 xLBT->getRuntimeException();
     996             :             }
     997             :         }
     998           2 :         catch (const RuntimeException & rExc)
     999             :         {
    1000           4 :             if (rExc.Context == xLBT->getInterface()
    1001             : #if OSL_DEBUG_LEVEL == 0
    1002             :                     // java stack traces trash Message
    1003           2 :                 && rExc.Message.compareToAscii( STRING_TEST_CONSTANT ) == 0
    1004             : #endif
    1005             :                 )
    1006             :             {
    1007           2 :                 ++nCount;
    1008             :             }
    1009             :             else
    1010             :             {
    1011           0 :                 check( sal_False, "### unexpected exception content!" );
    1012             :             }
    1013             : 
    1014             :             /** it is certain, that the RuntimeException testing will fail, if no */
    1015           2 :             xLBT->setRuntimeException( 0xcafebabe );
    1016             :         }
    1017             :     }
    1018           2 :     catch (const Exception & rExc)
    1019             :     {
    1020           4 :         if (rExc.Context == xLBT->getInterface()
    1021             : #if OSL_DEBUG_LEVEL == 0
    1022             :             // java stack traces trash Message
    1023           2 :             && rExc.Message.compareToAscii( STRING_TEST_CONSTANT ) == 0
    1024             : #endif
    1025             :             )
    1026             :         {
    1027           2 :             ++nCount;
    1028             :         }
    1029             :         else
    1030             :         {
    1031           0 :             check( sal_False, "### unexpected exception content!" );
    1032             :         }
    1033           2 :         return (nCount == 3);
    1034             :     }
    1035           0 :     return sal_False;
    1036             : }
    1037             : 
    1038             : /* Returns an acquired sequence
    1039             :  */
    1040          30 : uno_Sequence* cloneSequence(const uno_Sequence* val, const Type& type)
    1041             : {
    1042          30 :     TypeDescription td(type);
    1043          30 :     td.makeComplete();
    1044          30 :     typelib_TypeDescription* pTdRaw = td.get();
    1045             :     typelib_IndirectTypeDescription* pIndirectTd =
    1046          30 :         (typelib_IndirectTypeDescription*) pTdRaw;
    1047             : 
    1048          30 :     typelib_TypeDescription* pTdElem = pIndirectTd->pType->pType;
    1049          30 :     sal_Int8* buf = new sal_Int8[pTdElem->nSize * val->nElements];
    1050          30 :     sal_Int8* pBufCur = buf;
    1051             : 
    1052          30 :     uno_Sequence* retSeq = NULL;
    1053          30 :     switch (pTdElem->eTypeClass)
    1054             :     {
    1055             :     case TypeClass_SEQUENCE:
    1056             :     {
    1057           0 :         Type _tElem(pTdElem->pWeakRef);
    1058           0 :         for (int i = 0; i < val->nElements; i++)
    1059             :         {
    1060           0 :             sal_Int8 *pValBuf = (sal_Int8 *)(&val->elements + i * pTdElem->nSize);
    1061             : 
    1062             :             uno_Sequence* seq = cloneSequence(
    1063             :                 *(uno_Sequence**) (pValBuf),
    1064           0 :                 _tElem);
    1065           0 :             *((uno_Sequence**) pBufCur) = seq;
    1066           0 :             pBufCur += pTdElem->nSize;
    1067             :         }
    1068           0 :         break;
    1069             :     }
    1070             :     default:
    1071             :         uno_type_sequence_construct(
    1072             :             &retSeq, type.getTypeLibType(), (void*) val->elements,
    1073          30 :             val->nElements, reinterpret_cast< uno_AcquireFunc >(cpp_acquire));
    1074          30 :         break;
    1075             :     }
    1076          30 :     delete[] buf;
    1077          30 :     return retSeq;
    1078             : }
    1079             : 
    1080             : template< class T>
    1081          30 : Sequence<T> cloneSequence(const Sequence<T>& val)
    1082             : {
    1083          30 :     Sequence<T> seq( cloneSequence(val.get(), getCppuType(&val)), SAL_NO_ACQUIRE);
    1084          30 :     return seq;
    1085             : }
    1086             : 
    1087             : template< class T >
    1088           2 : inline bool makeSurrogate(
    1089             :     Reference< T > & rOut, Reference< T > const & rOriginal )
    1090             : {
    1091           2 :     rOut.clear();
    1092           2 :     if (! rOriginal.is())
    1093           0 :         return false;
    1094             : 
    1095           2 :     Environment aCppEnv_official;
    1096           2 :     Environment aUnoEnv_ano;
    1097           2 :     Environment aCppEnv_ano;
    1098             : 
    1099             :     OUString aCppEnvTypeName(
    1100           2 :         RTL_CONSTASCII_USTRINGPARAM(CPPU_CURRENT_LANGUAGE_BINDING_NAME) );
    1101             :     OUString aUnoEnvTypeName(
    1102           2 :         RTL_CONSTASCII_USTRINGPARAM(UNO_LB_UNO) );
    1103             :     // official:
    1104             :     uno_getEnvironment(
    1105             :         reinterpret_cast< uno_Environment ** >( &aCppEnv_official ),
    1106           2 :         aCppEnvTypeName.pData, 0 );
    1107             :     // anonymous:
    1108             :     uno_createEnvironment(
    1109             :         reinterpret_cast< uno_Environment ** >( &aCppEnv_ano ),
    1110           2 :         aCppEnvTypeName.pData, 0 );
    1111             :     uno_createEnvironment(
    1112             :         reinterpret_cast< uno_Environment ** >( &aUnoEnv_ano ),
    1113           2 :         aUnoEnvTypeName.pData, 0 );
    1114             : 
    1115           2 :     UnoInterfaceReference unoI;
    1116           2 :     Mapping cpp2uno( aCppEnv_official.get(), aUnoEnv_ano.get() );
    1117           2 :     Mapping uno2cpp( aUnoEnv_ano.get(), aCppEnv_ano.get() );
    1118           2 :     if (!cpp2uno.is() || !uno2cpp.is())
    1119             :     {
    1120             :         throw RuntimeException(
    1121             :             OUSTR("cannot get C++-UNO mappings!"),
    1122           0 :             Reference< XInterface >() );
    1123             :     }
    1124           2 :     cpp2uno.mapInterface(
    1125             :         reinterpret_cast< void ** >( &unoI.m_pUnoI ),
    1126             :         rOriginal.get(), ::getCppuType( &rOriginal ) );
    1127           2 :     if (! unoI.is())
    1128             :     {
    1129             :         throw RuntimeException(
    1130             :             OUSTR("mapping C++ to binary UNO failed!"),
    1131           0 :             Reference< XInterface >() );
    1132             :     }
    1133           2 :     uno2cpp.mapInterface(
    1134             :         reinterpret_cast< void ** >( &rOut ),
    1135             :         unoI.get(), ::getCppuType( &rOriginal ) );
    1136           2 :     if (! rOut.is())
    1137             :     {
    1138             :         throw RuntimeException(
    1139             :             OUSTR("mapping binary UNO to C++ failed!"),
    1140           0 :             Reference< XInterface >() );
    1141             :     }
    1142             : 
    1143           2 :     return rOut.is();
    1144             : }
    1145             : 
    1146             : //==================================================================================================
    1147           2 : sal_Int32 TestBridgeImpl::run( const Sequence< OUString > & rArgs )
    1148             :     throw (RuntimeException)
    1149             : {
    1150           2 :     bool bRet = false;
    1151             :     try
    1152             :     {
    1153           2 :         if (! rArgs.getLength())
    1154             :         {
    1155             :             throw RuntimeException( OUString( RTL_CONSTASCII_USTRINGPARAM(
    1156             :                                                   "no test object specified!\n"
    1157             :                                                   "usage : ServiceName of test object | -u unourl of test object\n" ) ),
    1158           0 :                                     Reference< XInterface >() );
    1159             :         }
    1160             : 
    1161           2 :         Reference< XInterface > xOriginal;
    1162             :         bool remote;
    1163             :         sal_Int32 i;
    1164           2 :         if( rArgs.getLength() > 1 && 0 == rArgs[0].compareToAscii( "-u" ) )
    1165             :         {
    1166           0 :             remote = true;
    1167           0 :             i = 2;
    1168             :         }
    1169             :         else
    1170             :         {
    1171           2 :             remote = false;
    1172           2 :             i = 1;
    1173             :         }
    1174           2 :         bool noCurrentContext = false;
    1175           2 :         if ( i < rArgs.getLength() && rArgs[i] == "noCurrentContext" )
    1176             :         {
    1177           0 :             noCurrentContext = true;
    1178           0 :             ++i;
    1179             :         }
    1180           2 :         bool stress = false;
    1181           2 :         if ( i < rArgs.getLength() && rArgs[i] == "stress" )
    1182             :         {
    1183           0 :             stress = true;
    1184           0 :             ++i;
    1185             :         }
    1186             : 
    1187           0 :         for (;;) {
    1188           2 :             Reference< XInterface > o;
    1189           2 :             if (remote) {
    1190           0 :                 o = UnoUrlResolver::create(m_xContext)->resolve(rArgs[1]);
    1191             :             } else {
    1192           4 :                 o = m_xContext->getServiceManager()->createInstanceWithContext(
    1193           2 :                     rArgs[0], m_xContext);
    1194             :             }
    1195           2 :             if (!stress) {
    1196           2 :                 xOriginal = o;
    1197             :                 break;
    1198             :             }
    1199           2 :         }
    1200             : 
    1201           2 :         if (! xOriginal.is())
    1202             :         {
    1203             :             throw RuntimeException(
    1204             :                 OUString( RTL_CONSTASCII_USTRINGPARAM(
    1205             :                               "cannot get test object!") ),
    1206           0 :                 Reference< XInterface >() );
    1207             :         }
    1208           2 :         Reference< XBridgeTest > xTest( xOriginal, UNO_QUERY );
    1209           2 :         if (! xTest.is())
    1210             :         {
    1211             :             throw RuntimeException(
    1212             :                 OUString( RTL_CONSTASCII_USTRINGPARAM("test object does not implement XBridgeTest!") ),
    1213           0 :                 Reference< XInterface >() );
    1214             :         }
    1215             : 
    1216           2 :         Reference<XBridgeTest > xLBT;
    1217           2 :         bRet = check( makeSurrogate( xLBT, xTest ), "makeSurrogate" );
    1218             :         bRet = check(
    1219           2 :             performTest( m_xContext, xLBT, noCurrentContext ), "standard test" )
    1220           2 :             && bRet;
    1221           2 :         bRet = check( raiseException( xLBT ) , "exception test" )&& bRet;
    1222           2 :         bRet = check( raiseOnewayException( xLBT ),
    1223           2 :                       "oneway exception test" ) && bRet;
    1224           2 :         if (! bRet)
    1225             :         {
    1226             :             throw RuntimeException(
    1227             :                 OUString( RTL_CONSTASCII_USTRINGPARAM("error: test failed!") ),
    1228           0 :                 Reference< XInterface >() );
    1229           2 :         }
    1230             :     }
    1231           0 :     catch (const Exception & exc)
    1232             :     {
    1233           0 :         OString cstr( OUStringToOString( exc.Message, RTL_TEXTENCODING_ASCII_US ) );
    1234           0 :         fprintf( stderr, "exception occurred: %s\n", cstr.getStr() );
    1235           0 :         throw;
    1236             :     }
    1237             : 
    1238           2 :     return bRet ? 0 : 1;
    1239             : }
    1240             : 
    1241             : // XServiceInfo
    1242             : //__________________________________________________________________________________________________
    1243           0 : OUString TestBridgeImpl::getImplementationName()
    1244             :     throw (RuntimeException)
    1245             : {
    1246           0 :     return OUString( RTL_CONSTASCII_USTRINGPARAM(IMPLNAME) );
    1247             : }
    1248             : //__________________________________________________________________________________________________
    1249           0 : sal_Bool TestBridgeImpl::supportsService( const OUString & rServiceName )
    1250             :     throw (RuntimeException)
    1251             : {
    1252           0 :     const Sequence< OUString > & rSNL = getSupportedServiceNames();
    1253           0 :     const OUString * pArray = rSNL.getConstArray();
    1254           0 :     for ( sal_Int32 nPos = rSNL.getLength(); nPos--; )
    1255             :     {
    1256           0 :         if (pArray[nPos] == rServiceName)
    1257           0 :             return sal_True;
    1258             :     }
    1259           0 :     return sal_False;
    1260             : }
    1261             : //__________________________________________________________________________________________________
    1262           0 : Sequence< OUString > TestBridgeImpl::getSupportedServiceNames()
    1263             :     throw (RuntimeException)
    1264             : {
    1265           0 :     return bridge_test::getSupportedServiceNames();
    1266             : }
    1267             : 
    1268             : // ...
    1269             : 
    1270             : //==================================================================================================
    1271           2 : static Reference< XInterface > SAL_CALL TestBridgeImpl_create(
    1272             :     const Reference< XComponentContext > & xContext )
    1273             : {
    1274             :     return Reference< XInterface >(
    1275           2 :         static_cast< OWeakObject * >( new TestBridgeImpl( xContext ) ) );
    1276             : }
    1277             : 
    1278             : }
    1279             : 
    1280             : extern "C"
    1281             : {
    1282             : //==================================================================================================
    1283           2 : SAL_DLLPUBLIC_EXPORT void * SAL_CALL component_getFactory(
    1284             :     const sal_Char * pImplName, void * pServiceManager,
    1285             :     SAL_UNUSED_PARAMETER void * )
    1286             : {
    1287           2 :     void * pRet = 0;
    1288             : 
    1289           2 :     if (pServiceManager && rtl_str_compare( pImplName, IMPLNAME ) == 0)
    1290             :     {
    1291             :         Reference< XInterface > xFactory(
    1292             :             createSingleComponentFactory(
    1293             :                 bridge_test::TestBridgeImpl_create,
    1294             :                 OUString( RTL_CONSTASCII_USTRINGPARAM(IMPLNAME) ),
    1295           2 :                 bridge_test::getSupportedServiceNames() ) );
    1296             : 
    1297           2 :         if (xFactory.is())
    1298             :         {
    1299           2 :             xFactory->acquire();
    1300           2 :             pRet = xFactory.get();
    1301           2 :         }
    1302             :     }
    1303             : 
    1304           2 :     return pRet;
    1305             : }
    1306             : }
    1307             : 
    1308             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10