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