1d48fe848SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3d48fe848SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4d48fe848SAndrew Rist * or more contributor license agreements. See the NOTICE file
5d48fe848SAndrew Rist * distributed with this work for additional information
6d48fe848SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7d48fe848SAndrew Rist * to you under the Apache License, Version 2.0 (the
8d48fe848SAndrew Rist * "License"); you may not use this file except in compliance
9d48fe848SAndrew Rist * with the License. You may obtain a copy of the License at
10d48fe848SAndrew Rist *
11d48fe848SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12d48fe848SAndrew Rist *
13d48fe848SAndrew Rist * Unless required by applicable law or agreed to in writing,
14d48fe848SAndrew Rist * software distributed under the License is distributed on an
15d48fe848SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16d48fe848SAndrew Rist * KIND, either express or implied. See the License for the
17d48fe848SAndrew Rist * specific language governing permissions and limitations
18d48fe848SAndrew Rist * under the License.
19d48fe848SAndrew Rist *
20d48fe848SAndrew Rist *************************************************************/
21d48fe848SAndrew Rist
22d48fe848SAndrew 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 //--------------------------------------------------------------------------------------------------
getSupportedServiceNames()81cdf0e10cSrcweir inline static Sequence< OUString > getSupportedServiceNames()
82cdf0e10cSrcweir {
83cdf0e10cSrcweir OUString aName( RTL_CONSTASCII_USTRINGPARAM(SERVICENAME) );
84cdf0e10cSrcweir return Sequence< OUString >( &aName, 1 );
85cdf0e10cSrcweir }
86cdf0e10cSrcweir
check(bool b,char const * message)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
checkEmpty(rtl::OUString const & string,char const * message)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:
TestBridgeImpl(const Reference<XComponentContext> & xContext)115cdf0e10cSrcweir TestBridgeImpl( const Reference< XComponentContext > & xContext )
116cdf0e10cSrcweir : m_xContext( xContext )
117cdf0e10cSrcweir {}
~TestBridgeImpl()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 //==================================================================================================
equals(const TestElement & rData1,const TestElement & rData2)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 //==================================================================================================
equals(const TestData & rData1,const TestData & rData2)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 //==================================================================================================
assign(TestElement & rData,sal_Bool bBool,sal_Unicode cChar,sal_Int8 nByte,sal_Int16 nShort,sal_uInt16 nUShort,sal_Int32 nLong,sal_uInt32 nULong,sal_Int64 nHyper,sal_uInt64 nUHyper,float fFloat,double fDouble,TestEnum eEnum,const::rtl::OUString & rStr,const::com::sun::star::uno::Reference<::com::sun::star::uno::XInterface> & xTest,const::com::sun::star::uno::Any & rAny)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 >
testAny(T const & value,Reference<XBridgeTest> const & xLBT,char const * typeName=0)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
performAnyTest(const Reference<XBridgeTest> & xLBT,const TestData & data)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 //_______________________________________________________________________________________
performSequenceOfCallTest(const Reference<XBridgeTest> & xLBT)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:
callRecursivly(const::com::sun::star::uno::Reference<XRecursiveCall> & xCall,sal_Int32 nToCall)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 //_______________________________________________________________________________________
performRecursiveCallTest(const Reference<XBridgeTest> & xLBT)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 //______________________________________________________________________________
MyClass()355cdf0e10cSrcweir MyClass::MyClass()
356cdf0e10cSrcweir {
357cdf0e10cSrcweir }
358cdf0e10cSrcweir //______________________________________________________________________________
~MyClass()359cdf0e10cSrcweir MyClass::~MyClass()
360cdf0e10cSrcweir {
361cdf0e10cSrcweir }
362cdf0e10cSrcweir //______________________________________________________________________________
acquire()363cdf0e10cSrcweir void MyClass::acquire() throw ()
364cdf0e10cSrcweir {
365cdf0e10cSrcweir OWeakObject::acquire();
366cdf0e10cSrcweir }
367cdf0e10cSrcweir //______________________________________________________________________________
release()368cdf0e10cSrcweir void MyClass::release() throw ()
369cdf0e10cSrcweir {
370cdf0e10cSrcweir OWeakObject::release();
371cdf0e10cSrcweir }
372cdf0e10cSrcweir
373cdf0e10cSrcweir //==================================================================================================
performTest(const Reference<XComponentContext> & xContext,const Reference<XBridgeTest> & xLBT,bool noCurrentContext)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 }
547*c25219e0SPedro Giffuni #if !defined(OS2) && !(defined(FREEBSD) && defined(INTEL))
548*c25219e0SPedro Giffuni // see i120310 for OS2 details
549*c25219e0SPedro Giffuni // FreeBSD i386 coredumps on this test in cpp_vtable_call():
550*c25219e0SPedro Giffuni // pTypeDescr appears to point to garbage, pMapFunctionIndexToMemberIndex
551*c25219e0SPedro Giffuni // points to unreadable memory, as does abase.pTypeName. Refcounts
552*c25219e0SPedro Giffuni // don't look reasonable, etc.
553cdf0e10cSrcweir // Test instantiated polymorphic struct types:
554cdf0e10cSrcweir {
555cdf0e10cSrcweir bRet &= check(
556cdf0e10cSrcweir (xLBT->transportPolyBoolean(
557cdf0e10cSrcweir TestPolyStruct< sal_Bool >(true)).
558cdf0e10cSrcweir member),
559cdf0e10cSrcweir "transportPolyBoolean");
560cdf0e10cSrcweir TestPolyStruct< sal_Int64 > tps1(12345);
561cdf0e10cSrcweir xLBT->transportPolyHyper(tps1);
562cdf0e10cSrcweir bRet &= check(tps1.member == 12345, "transportPolyHyper");
563cdf0e10cSrcweir Sequence< Any > seq(2);
564cdf0e10cSrcweir seq[0] <<= static_cast< sal_uInt32 >(33);
565cdf0e10cSrcweir seq[1] <<= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ABC"));
566cdf0e10cSrcweir TestPolyStruct< Sequence< Any > > tps2(seq);
567cdf0e10cSrcweir TestPolyStruct< Sequence< Any > > tps3;
568cdf0e10cSrcweir xLBT->transportPolySequence(tps2, tps3);
569cdf0e10cSrcweir bRet &= check(
570cdf0e10cSrcweir tps3.member.getLength() == 2,
571cdf0e10cSrcweir "transportPolySequence, length");
572cdf0e10cSrcweir sal_uInt32 v0 = sal_uInt32();
573cdf0e10cSrcweir tps3.member[0] >>= v0;
574cdf0e10cSrcweir bRet &= check(v0 == 33, "transportPolySequence, element 0");
575cdf0e10cSrcweir rtl::OUString v1;
576cdf0e10cSrcweir tps3.member[1] >>= v1;
577cdf0e10cSrcweir bRet &= check(
578cdf0e10cSrcweir v1.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("ABC")),
579cdf0e10cSrcweir "transportPolySequence, element 1");
580cdf0e10cSrcweir bRet &= check(
581cdf0e10cSrcweir xLBT->getNullPolyLong().member == 0, "getNullPolyLong");
582cdf0e10cSrcweir bRet &= check(
583cdf0e10cSrcweir xLBT->getNullPolyString().member.getLength() == 0,
584cdf0e10cSrcweir "getNullPolyString");
585cdf0e10cSrcweir bRet &= check(
586cdf0e10cSrcweir xLBT->getNullPolyType().member == Type(),
587cdf0e10cSrcweir "getNullPolyType");
588cdf0e10cSrcweir Any nullAny(xLBT->getNullPolyAny().member);
589cdf0e10cSrcweir bRet &= check(
590cdf0e10cSrcweir (((nullAny.getValueTypeName() ==
591cdf0e10cSrcweir rtl::OUString(
592cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM(
593cdf0e10cSrcweir "com.sun.star.uno.XInterface"))) &&
594cdf0e10cSrcweir !static_cast< Reference< XInterface > const * >(
595cdf0e10cSrcweir nullAny.getValue())->is())
596cdf0e10cSrcweir || nullAny == Any()),
597cdf0e10cSrcweir "getNullPolyAny");
598cdf0e10cSrcweir bRet &= check(
599cdf0e10cSrcweir xLBT->getNullPolySequence().member.getLength() == 0,
600cdf0e10cSrcweir "getNullPolySequence");
601cdf0e10cSrcweir bRet &= check(
602cdf0e10cSrcweir xLBT->getNullPolyEnum().member == TestEnum_TEST,
603cdf0e10cSrcweir "getNullPolyEnum");
604cdf0e10cSrcweir bRet &= check(
605cdf0e10cSrcweir xLBT->getNullPolyBadEnum().member == TestBadEnum_M,
606cdf0e10cSrcweir "getNullPolyBadEnum");
607cdf0e10cSrcweir bRet &= check(
608cdf0e10cSrcweir xLBT->getNullPolyStruct().member.member == 0,
609cdf0e10cSrcweir "getNullPolyStruct");
610cdf0e10cSrcweir bRet &= check(
611cdf0e10cSrcweir !xLBT->getNullPolyInterface().member.is(),
612cdf0e10cSrcweir "getNullPolyInterface");
613cdf0e10cSrcweir }
614ff2e7b24SYuri Dario #endif // OS2
615ff2e7b24SYuri Dario
616cdf0e10cSrcweir // Any test:
617cdf0e10cSrcweir bRet &= check(performAnyTest(xLBT , aData), "any test");
618cdf0e10cSrcweir // Sequence of call test:
619cdf0e10cSrcweir bRet &= check(
620cdf0e10cSrcweir performSequenceOfCallTest(xLBT), "sequence of call test");
621cdf0e10cSrcweir // Recursive call test:
622cdf0e10cSrcweir bRet &= check(performRecursiveCallTest(xLBT), "recursive test");
623cdf0e10cSrcweir bRet &= check(
624cdf0e10cSrcweir equals(aData, aRet) && equals(aData, aRet2),
625cdf0e10cSrcweir "recursive test results");
626cdf0e10cSrcweir // Multiple inheritance test:
627cdf0e10cSrcweir bRet &= checkEmpty(
628cdf0e10cSrcweir testtools::bridgetest::testMulti(xLBT->getMulti()),
629cdf0e10cSrcweir "remote multi");
630cdf0e10cSrcweir bRet &= checkEmpty(
631cdf0e10cSrcweir xLBT->testMulti(new testtools::bridgetest::Multi),
632cdf0e10cSrcweir "local multi");
633cdf0e10cSrcweir }
634cdf0e10cSrcweir }
635cdf0e10cSrcweir {
636cdf0e10cSrcweir Reference< XBridgeTest2 > xBT2(xLBT, UNO_QUERY);
637cdf0e10cSrcweir if (!xBT2.is()) {
638cdf0e10cSrcweir return bRet;
639cdf0e10cSrcweir }
640cdf0e10cSrcweir // Perform sequence tests (XBridgeTest2); create the sequence which is
641cdf0e10cSrcweir // compared with the results:
642cdf0e10cSrcweir sal_Bool _arBool[] = { true, false, true };
643cdf0e10cSrcweir sal_Unicode _arChar[] = { 0x0065, 0x0066, 0x0067 };
644cdf0e10cSrcweir sal_Int8 _arByte[] = { 1, 2, -1 };
645cdf0e10cSrcweir sal_Int16 _arShort[] = { -0x8000, 1, 0x7FFF };
646cdf0e10cSrcweir sal_uInt16 _arUShort[] = { 0 , 1, 0xFFFF };
64736fb5f50SHerbert Dürr sal_Int32 _arLong[] = { -0x7FFFFFFF, 1, 0x7FFFFFFF };
648cdf0e10cSrcweir sal_uInt32 _arULong[] = { 0, 1, 0xFFFFFFFF };
649cdf0e10cSrcweir sal_Int64 _arHyper[] = {
65036fb5f50SHerbert Dürr SAL_CONST_INT64(-0x7FFFFFFFFFFFFFFF), 1,
65136fb5f50SHerbert Dürr SAL_CONST_INT64(+0x7FFFFFFFFFFFFFFF) };
652cdf0e10cSrcweir sal_uInt64 _arUHyper[] = { 0, 1, SAL_CONST_UINT64(0xFFFFFFFFFFFFFFFF) };
653cdf0e10cSrcweir float _arFloat[] = { 1.1f, 2.2f, 3.3f };
654cdf0e10cSrcweir double _arDouble[] = { 1.11, 2.22, 3.33 };
655cdf0e10cSrcweir OUString _arString[] = {
656cdf0e10cSrcweir OUString(RTL_CONSTASCII_USTRINGPARAM("String 1")),
657cdf0e10cSrcweir OUString(RTL_CONSTASCII_USTRINGPARAM("String 2")),
658cdf0e10cSrcweir OUString(RTL_CONSTASCII_USTRINGPARAM("String 3")) };
659cdf0e10cSrcweir sal_Bool _aBool = true;
660cdf0e10cSrcweir sal_Int32 _aInt = 0xBABEBABE;
661cdf0e10cSrcweir float _aFloat = 3.14f;
662cdf0e10cSrcweir Any _any1(&_aBool, getCppuBooleanType());
663cdf0e10cSrcweir Any _any2(&_aInt, getCppuType((sal_Int32 *) 0));
664cdf0e10cSrcweir Any _any3(&_aFloat, getCppuType((float *) 0));
665cdf0e10cSrcweir Any _arAny[] = { _any1, _any2, _any3 };
666cdf0e10cSrcweir Reference< XInterface > _arObj[3];
667cdf0e10cSrcweir _arObj[0] = new OWeakObject();
668cdf0e10cSrcweir _arObj[1] = new OWeakObject();
669cdf0e10cSrcweir _arObj[2] = new OWeakObject();
670cdf0e10cSrcweir TestEnum _arEnum[] = { TestEnum_ONE, TestEnum_TWO, TestEnum_CHECK };
671cdf0e10cSrcweir TestElement _arStruct[3];
672cdf0e10cSrcweir assign(
673cdf0e10cSrcweir _arStruct[0], true, '@', 17, 0x1234, 0xFEDC, 0x12345678, 0xFEDCBA98,
674cdf0e10cSrcweir SAL_CONST_INT64(0x123456789ABCDEF0),
675cdf0e10cSrcweir SAL_CONST_UINT64(0xFEDCBA9876543210), 17.0815f, 3.1415926359,
676cdf0e10cSrcweir TestEnum_LOLA, OUSTR(STRING_TEST_CONSTANT), _arObj[0],
677cdf0e10cSrcweir Any(&_arObj[0], getCppuType((Reference< XInterface > const *) 0)));
678cdf0e10cSrcweir assign(
679cdf0e10cSrcweir _arStruct[1], true, 'A', 17, 0x1234, 0xFEDC, 0x12345678, 0xFEDCBA98,
680cdf0e10cSrcweir SAL_CONST_INT64(0x123456789ABCDEF0),
681cdf0e10cSrcweir SAL_CONST_UINT64(0xFEDCBA9876543210), 17.0815f, 3.1415926359,
682cdf0e10cSrcweir TestEnum_TWO, OUSTR(STRING_TEST_CONSTANT), _arObj[1],
683cdf0e10cSrcweir Any(&_arObj[1], getCppuType((Reference< XInterface > const *) 0)));
684cdf0e10cSrcweir assign(
685cdf0e10cSrcweir _arStruct[2], true, 'B', 17, 0x1234, 0xFEDC, 0x12345678, 0xFEDCBA98,
686cdf0e10cSrcweir SAL_CONST_INT64(0x123456789ABCDEF0),
687cdf0e10cSrcweir SAL_CONST_UINT64(0xFEDCBA9876543210), 17.0815f, 3.1415926359,
688cdf0e10cSrcweir TestEnum_CHECK, OUSTR(STRING_TEST_CONSTANT), _arObj[2],
689cdf0e10cSrcweir Any(&_arObj[2], getCppuType((Reference< XInterface > const *) 0)));
690cdf0e10cSrcweir {
691cdf0e10cSrcweir Sequence<sal_Bool> arBool(_arBool, 3);
692cdf0e10cSrcweir Sequence<sal_Unicode> arChar( _arChar, 3);
693cdf0e10cSrcweir Sequence<sal_Int8> arByte(_arByte, 3);
694cdf0e10cSrcweir Sequence<sal_Int16> arShort(_arShort, 3);
695cdf0e10cSrcweir Sequence<sal_uInt16> arUShort(_arUShort, 3);
696cdf0e10cSrcweir Sequence<sal_Int32> arLong(_arLong, 3);
697cdf0e10cSrcweir Sequence<sal_uInt32> arULong(_arULong, 3);
698cdf0e10cSrcweir Sequence<sal_Int64> arHyper(_arHyper, 3);
699cdf0e10cSrcweir Sequence<sal_uInt64> arUHyper(_arUHyper, 3);
700cdf0e10cSrcweir Sequence<float> arFloat(_arFloat, 3);
701cdf0e10cSrcweir Sequence<double> arDouble(_arDouble, 3);
702cdf0e10cSrcweir Sequence<OUString> arString(_arString, 3);
703cdf0e10cSrcweir Sequence<Any> arAny(_arAny, 3);
704cdf0e10cSrcweir Sequence<Reference<XInterface> > arObject(_arObj, 3);
705cdf0e10cSrcweir Sequence<TestEnum> arEnum(_arEnum, 3);
706cdf0e10cSrcweir Sequence<TestElement> arStruct(_arStruct, 3);
707cdf0e10cSrcweir Sequence<Sequence<sal_Int32> > _arSeqLong2[3];
708cdf0e10cSrcweir for (int j = 0; j != 3; ++j) {
709cdf0e10cSrcweir Sequence< sal_Int32 > _arSeqLong[3];
710cdf0e10cSrcweir for (int i = 0; i != 3; ++i) {
711cdf0e10cSrcweir _arSeqLong[i] = Sequence< sal_Int32 >(_arLong, 3);
712cdf0e10cSrcweir }
713cdf0e10cSrcweir _arSeqLong2[j] = Sequence< Sequence< sal_Int32 > >(
714cdf0e10cSrcweir _arSeqLong, 3);
715cdf0e10cSrcweir }
716cdf0e10cSrcweir Sequence< Sequence< Sequence< sal_Int32> > > arLong3(
717cdf0e10cSrcweir _arSeqLong2, 3);
718cdf0e10cSrcweir Sequence< Sequence< sal_Int32 > > seqSeqRet(
719cdf0e10cSrcweir xBT2->setDim2(arLong3[0]));
720cdf0e10cSrcweir bRet &= check(seqSeqRet == arLong3[0], "sequence test");
721cdf0e10cSrcweir Sequence< Sequence< Sequence< sal_Int32 > > > seqSeqRet2(
722cdf0e10cSrcweir xBT2->setDim3(arLong3));
723cdf0e10cSrcweir bRet &= check(seqSeqRet2 == arLong3, "sequence test");
724cdf0e10cSrcweir Sequence< Any > seqAnyRet(xBT2->setSequenceAny(arAny));
725cdf0e10cSrcweir bRet &= check(seqAnyRet == arAny, "sequence test");
726cdf0e10cSrcweir Sequence< sal_Bool > seqBoolRet(xBT2->setSequenceBool(arBool));
727cdf0e10cSrcweir bRet &= check(seqBoolRet == arBool, "sequence test");
728cdf0e10cSrcweir Sequence< sal_Int8 > seqByteRet(xBT2->setSequenceByte(arByte));
729cdf0e10cSrcweir bRet &= check(seqByteRet == arByte, "sequence test");
730cdf0e10cSrcweir Sequence< sal_Unicode > seqCharRet(xBT2->setSequenceChar(arChar));
731cdf0e10cSrcweir bRet &= check(seqCharRet == arChar, "sequence test");
732cdf0e10cSrcweir Sequence< sal_Int16 > seqShortRet(xBT2->setSequenceShort(arShort));
733cdf0e10cSrcweir bRet &= check(seqShortRet == arShort, "sequence test");
734cdf0e10cSrcweir Sequence< sal_Int32 > seqLongRet(xBT2->setSequenceLong(arLong));
735cdf0e10cSrcweir bRet &= check(seqLongRet == arLong, "sequence test");
736cdf0e10cSrcweir Sequence< sal_Int64 > seqHyperRet(xBT2->setSequenceHyper(arHyper));
737cdf0e10cSrcweir bRet &= check(seqHyperRet == arHyper, "sequence test");
738cdf0e10cSrcweir Sequence< float > seqFloatRet(xBT2->setSequenceFloat(arFloat));
739cdf0e10cSrcweir bRet &= check(seqFloatRet == arFloat, "sequence test");
740cdf0e10cSrcweir Sequence< double > seqDoubleRet(xBT2->setSequenceDouble(arDouble));
741cdf0e10cSrcweir bRet &= check(seqDoubleRet == arDouble, "sequence test");
742cdf0e10cSrcweir Sequence< TestEnum > seqEnumRet(xBT2->setSequenceEnum(arEnum));
743cdf0e10cSrcweir bRet &= check(seqEnumRet == arEnum, "sequence test");
744cdf0e10cSrcweir Sequence< sal_uInt16 > seqUShortRet(
745cdf0e10cSrcweir xBT2->setSequenceUShort(arUShort));
746cdf0e10cSrcweir bRet &= check(seqUShortRet == arUShort, "sequence test");
747cdf0e10cSrcweir Sequence< sal_uInt32 > seqULongRet(xBT2->setSequenceULong(arULong));
748cdf0e10cSrcweir bRet &= check(seqULongRet == arULong, "sequence test");
749cdf0e10cSrcweir Sequence< sal_uInt64 > seqUHyperRet(
750cdf0e10cSrcweir xBT2->setSequenceUHyper(arUHyper));
751cdf0e10cSrcweir bRet &= check(seqUHyperRet == arUHyper, "sequence test");
752cdf0e10cSrcweir Sequence< Reference< XInterface > > seqObjectRet(
753cdf0e10cSrcweir xBT2->setSequenceXInterface(arObject));
754cdf0e10cSrcweir bRet &= check(seqObjectRet == arObject, "sequence test");
755cdf0e10cSrcweir Sequence< OUString > seqStringRet(
756cdf0e10cSrcweir xBT2->setSequenceString(arString));
757cdf0e10cSrcweir bRet &= check(seqStringRet == arString, "sequence test");
758cdf0e10cSrcweir Sequence< TestElement > seqStructRet(
759cdf0e10cSrcweir xBT2->setSequenceStruct(arStruct));
760cdf0e10cSrcweir bRet &= check(seqStructRet == arStruct, "sequence test");
761cdf0e10cSrcweir Sequence< sal_Bool > arBoolTemp(cloneSequence(arBool));
762cdf0e10cSrcweir Sequence< sal_Unicode > arCharTemp(cloneSequence(arChar));
763cdf0e10cSrcweir Sequence< sal_Int8 > arByteTemp(cloneSequence(arByte));
764cdf0e10cSrcweir Sequence< sal_Int16 > arShortTemp(cloneSequence(arShort));
765cdf0e10cSrcweir Sequence< sal_uInt16 > arUShortTemp(cloneSequence(arUShort));
766cdf0e10cSrcweir Sequence< sal_Int32 > arLongTemp(cloneSequence(arLong));
767cdf0e10cSrcweir Sequence< sal_uInt32 > arULongTemp(cloneSequence(arULong));
768cdf0e10cSrcweir Sequence< sal_Int64 > arHyperTemp(cloneSequence(arHyper));
769cdf0e10cSrcweir Sequence< sal_uInt64 > arUHyperTemp(cloneSequence(arUHyper));
770cdf0e10cSrcweir Sequence< float > arFloatTemp(cloneSequence(arFloat));
771cdf0e10cSrcweir Sequence< double > arDoubleTemp(cloneSequence(arDouble));
772cdf0e10cSrcweir Sequence< TestEnum > arEnumTemp(cloneSequence(arEnum));
773cdf0e10cSrcweir Sequence< OUString > arStringTemp(cloneSequence(arString));
774cdf0e10cSrcweir Sequence< Reference< XInterface > > arObjectTemp(
775cdf0e10cSrcweir cloneSequence(arObject));
776cdf0e10cSrcweir Sequence< Any > arAnyTemp(cloneSequence(arAny));
777cdf0e10cSrcweir Sequence< Sequence< sal_Int32 > > arLong2Temp(arLong3[0]);
778cdf0e10cSrcweir Sequence< Sequence< Sequence< sal_Int32 > > > arLong3Temp(arLong3);
779cdf0e10cSrcweir xBT2->setSequencesInOut(
780cdf0e10cSrcweir arBoolTemp, arCharTemp, arByteTemp, arShortTemp, arUShortTemp,
781cdf0e10cSrcweir arLongTemp,arULongTemp, arHyperTemp, arUHyperTemp, arFloatTemp,
782cdf0e10cSrcweir arDoubleTemp, arEnumTemp, arStringTemp, arObjectTemp, arAnyTemp,
783cdf0e10cSrcweir arLong2Temp, arLong3Temp);
784cdf0e10cSrcweir bRet &= check(
785cdf0e10cSrcweir (arBoolTemp == arBool && arCharTemp == arChar &&
786cdf0e10cSrcweir arByteTemp == arByte && arShortTemp == arShort &&
787cdf0e10cSrcweir arUShortTemp == arUShort && arLongTemp == arLong &&
788cdf0e10cSrcweir arULongTemp == arULong && arHyperTemp == arHyper &&
789cdf0e10cSrcweir arUHyperTemp == arUHyper && arFloatTemp == arFloat &&
790cdf0e10cSrcweir arDoubleTemp == arDouble && arEnumTemp == arEnum &&
791cdf0e10cSrcweir arStringTemp == arString && arObjectTemp == arObject &&
792cdf0e10cSrcweir arAnyTemp == arAny && arLong2Temp == arLong3[0] &&
793cdf0e10cSrcweir arLong3Temp == arLong3),
794cdf0e10cSrcweir "sequence test");
795cdf0e10cSrcweir Sequence< sal_Bool > arBoolOut;
796cdf0e10cSrcweir Sequence< sal_Unicode > arCharOut;
797cdf0e10cSrcweir Sequence< sal_Int8 > arByteOut;
798cdf0e10cSrcweir Sequence< sal_Int16 > arShortOut;
799cdf0e10cSrcweir Sequence< sal_uInt16 > arUShortOut;
800cdf0e10cSrcweir Sequence< sal_Int32 > arLongOut;
801cdf0e10cSrcweir Sequence< sal_uInt32 > arULongOut;
802cdf0e10cSrcweir Sequence< sal_Int64 > arHyperOut;
803cdf0e10cSrcweir Sequence< sal_uInt64 > arUHyperOut;
804cdf0e10cSrcweir Sequence< float > arFloatOut;
805cdf0e10cSrcweir Sequence< double > arDoubleOut;
806cdf0e10cSrcweir Sequence< TestEnum > arEnumOut;
807cdf0e10cSrcweir Sequence< OUString > arStringOut;
808cdf0e10cSrcweir Sequence< Reference< XInterface > > arObjectOut;
809cdf0e10cSrcweir Sequence< Any > arAnyOut;
810cdf0e10cSrcweir Sequence< Sequence< sal_Int32 > > arLong2Out;
811cdf0e10cSrcweir Sequence< Sequence< Sequence< sal_Int32 > > > arLong3Out;
812cdf0e10cSrcweir xBT2->setSequencesOut(
813cdf0e10cSrcweir arBoolOut, arCharOut, arByteOut, arShortOut, arUShortOut,
814cdf0e10cSrcweir arLongOut,arULongOut, arHyperOut, arUHyperOut, arFloatOut,
815cdf0e10cSrcweir arDoubleOut, arEnumOut, arStringOut, arObjectOut, arAnyOut,
816cdf0e10cSrcweir arLong2Out, arLong3Out);
817cdf0e10cSrcweir bRet &= check(
818cdf0e10cSrcweir (arBoolOut == arBool && arCharOut == arChar &&
819cdf0e10cSrcweir arByteOut == arByte && arShortOut == arShort &&
820cdf0e10cSrcweir arUShortOut == arUShort && arLongOut == arLong &&
821cdf0e10cSrcweir arULongOut == arULong && arHyperOut == arHyper &&
822cdf0e10cSrcweir arUHyperOut == arUHyper && arFloatOut == arFloat &&
823cdf0e10cSrcweir arDoubleOut == arDouble && arEnumOut == arEnum &&
824cdf0e10cSrcweir arStringOut == arString && arObjectOut == arObject &&
825cdf0e10cSrcweir arAnyOut == arAny && arLong2Out == arLong3[0] &&
826cdf0e10cSrcweir arLong3Out == arLong3),
827cdf0e10cSrcweir "sequence test");
828cdf0e10cSrcweir }
829cdf0e10cSrcweir {
830cdf0e10cSrcweir // Test with empty sequences:
831cdf0e10cSrcweir Sequence< Sequence< sal_Int32 > > arLong2;
832cdf0e10cSrcweir Sequence< Sequence< sal_Int32 > > seqSeqRet(xBT2->setDim2(arLong2));
833cdf0e10cSrcweir bRet &= check(seqSeqRet == arLong2, "sequence test");
834cdf0e10cSrcweir Sequence< Sequence< Sequence< sal_Int32 > > > arLong3;
835cdf0e10cSrcweir Sequence< Sequence< Sequence< sal_Int32 > > > seqSeqRet2(
836cdf0e10cSrcweir xBT2->setDim3(arLong3));
837cdf0e10cSrcweir bRet &= check(seqSeqRet2 == arLong3, "sequence test");
838cdf0e10cSrcweir Sequence< Any > arAny;
839cdf0e10cSrcweir Sequence< Any > seqAnyRet(xBT2->setSequenceAny(arAny));
840cdf0e10cSrcweir bRet &= check(seqAnyRet == arAny, "sequence test");
841cdf0e10cSrcweir Sequence< sal_Bool > arBool;
842cdf0e10cSrcweir Sequence< sal_Bool > seqBoolRet(xBT2->setSequenceBool(arBool));
843cdf0e10cSrcweir bRet &= check(seqBoolRet == arBool, "sequence test");
844cdf0e10cSrcweir Sequence< sal_Int8 > arByte;
845cdf0e10cSrcweir Sequence< sal_Int8 > seqByteRet(xBT2->setSequenceByte(arByte));
846cdf0e10cSrcweir bRet &= check(seqByteRet == arByte, "sequence test");
847cdf0e10cSrcweir Sequence< sal_Unicode > arChar;
848cdf0e10cSrcweir Sequence< sal_Unicode > seqCharRet(xBT2->setSequenceChar(arChar));
849cdf0e10cSrcweir bRet &= check(seqCharRet == arChar, "sequence test");
850cdf0e10cSrcweir Sequence< sal_Int16 > arShort;
851cdf0e10cSrcweir Sequence< sal_Int16 > seqShortRet(xBT2->setSequenceShort(arShort));
852cdf0e10cSrcweir bRet &= check(seqShortRet == arShort, "sequence test");
853cdf0e10cSrcweir Sequence< sal_Int32 > arLong;
854cdf0e10cSrcweir Sequence< sal_Int32 > seqLongRet(xBT2->setSequenceLong(arLong));
855cdf0e10cSrcweir bRet &= check(seqLongRet == arLong, "sequence test");
856cdf0e10cSrcweir Sequence< sal_Int64 > arHyper;
857cdf0e10cSrcweir Sequence< sal_Int64 > seqHyperRet(xBT2->setSequenceHyper(arHyper));
858cdf0e10cSrcweir bRet &= check(seqHyperRet == arHyper, "sequence test");
859cdf0e10cSrcweir Sequence< float > arFloat;
860cdf0e10cSrcweir Sequence< float > seqFloatRet(xBT2->setSequenceFloat(arFloat));
861cdf0e10cSrcweir bRet &= check(seqFloatRet == arFloat, "sequence test");
862cdf0e10cSrcweir Sequence< double > arDouble;
863cdf0e10cSrcweir Sequence< double > seqDoubleRet(xBT2->setSequenceDouble(arDouble));
864cdf0e10cSrcweir bRet &= check(seqDoubleRet == arDouble, "sequence test");
865cdf0e10cSrcweir Sequence< TestEnum > arEnum;
866cdf0e10cSrcweir Sequence< TestEnum > seqEnumRet(xBT2->setSequenceEnum(arEnum));
867cdf0e10cSrcweir bRet &= check(seqEnumRet == arEnum, "sequence test");
868cdf0e10cSrcweir Sequence< sal_uInt16 > arUShort;
869cdf0e10cSrcweir Sequence< sal_uInt16 > seqUShortRet(
870cdf0e10cSrcweir xBT2->setSequenceUShort(arUShort));
871cdf0e10cSrcweir bRet &= check(seqUShortRet == arUShort, "sequence test");
872cdf0e10cSrcweir Sequence< sal_uInt32 > arULong;
873cdf0e10cSrcweir Sequence< sal_uInt32 > seqULongRet(xBT2->setSequenceULong(arULong));
874cdf0e10cSrcweir bRet &= check(seqULongRet == arULong, "sequence test");
875cdf0e10cSrcweir Sequence< sal_uInt64 > arUHyper;
876cdf0e10cSrcweir Sequence< sal_uInt64 > seqUHyperRet(
877cdf0e10cSrcweir xBT2->setSequenceUHyper(arUHyper));
878cdf0e10cSrcweir bRet &= check(seqUHyperRet == arUHyper, "sequence test");
879cdf0e10cSrcweir Sequence< Reference< XInterface > > arObject;
880cdf0e10cSrcweir Sequence< Reference< XInterface > > seqObjectRet(
881cdf0e10cSrcweir xBT2->setSequenceXInterface(arObject));
882cdf0e10cSrcweir bRet &= check(seqObjectRet == arObject, "sequence test");
883cdf0e10cSrcweir Sequence< OUString > arString;
884cdf0e10cSrcweir Sequence< OUString > seqStringRet(
885cdf0e10cSrcweir xBT2->setSequenceString(arString));
886cdf0e10cSrcweir bRet &= check(seqStringRet == arString, "sequence test");
887cdf0e10cSrcweir Sequence< TestElement > arStruct;
888cdf0e10cSrcweir Sequence< TestElement > seqStructRet(
889cdf0e10cSrcweir xBT2->setSequenceStruct(arStruct));
890cdf0e10cSrcweir bRet &= check(seqStructRet == arStruct, "sequence test");
891cdf0e10cSrcweir }
892cdf0e10cSrcweir // Issue #i60341# shows that the most interesting case is were Java
893cdf0e10cSrcweir // calls the constructors; however, since this client is currently not
894cdf0e10cSrcweir // available in Java, while the server is, the logic is reversed here:
895cdf0e10cSrcweir try {
896cdf0e10cSrcweir xBT2->testConstructorsService(xContext);
897cdf0e10cSrcweir } catch (BadConstructorArguments &) {
898cdf0e10cSrcweir bRet = false;
899cdf0e10cSrcweir }
900cdf0e10cSrcweir if (!noCurrentContext) {
901cdf0e10cSrcweir if (!(new testtools::bridgetest::CurrentContextChecker)->perform(
902cdf0e10cSrcweir xBT2->getCurrentContextChecker(), 0, 1))
903cdf0e10cSrcweir {
904cdf0e10cSrcweir bRet = false;
905cdf0e10cSrcweir }
906cdf0e10cSrcweir if (!(new testtools::bridgetest::CurrentContextChecker)->perform(
907cdf0e10cSrcweir xBT2->getCurrentContextChecker(), 0, 2))
908cdf0e10cSrcweir {
909cdf0e10cSrcweir bRet = false;
910cdf0e10cSrcweir }
911cdf0e10cSrcweir if (!(new testtools::bridgetest::CurrentContextChecker)->perform(
912cdf0e10cSrcweir xBT2->getCurrentContextChecker(), 1, 2))
913cdf0e10cSrcweir {
914cdf0e10cSrcweir bRet = false;
915cdf0e10cSrcweir }
916cdf0e10cSrcweir if (!(new testtools::bridgetest::CurrentContextChecker)->perform(
917cdf0e10cSrcweir xBT2->getCurrentContextChecker(), 1, 3))
918cdf0e10cSrcweir {
919cdf0e10cSrcweir bRet = false;
920cdf0e10cSrcweir }
921cdf0e10cSrcweir }
922cdf0e10cSrcweir }
923cdf0e10cSrcweir return bRet;
924cdf0e10cSrcweir }
925cdf0e10cSrcweir
raiseOnewayException(const Reference<XBridgeTest> & xLBT)926cdf0e10cSrcweir static sal_Bool raiseOnewayException( const Reference < XBridgeTest > & xLBT )
927cdf0e10cSrcweir {
928cdf0e10cSrcweir sal_Bool bReturn = sal_True;
929cdf0e10cSrcweir OUString sCompare = OUSTR(STRING_TEST_CONSTANT);
930cdf0e10cSrcweir Reference<XInterface> const x(xLBT->getInterface());
931cdf0e10cSrcweir try
932cdf0e10cSrcweir {
933cdf0e10cSrcweir // Note : the exception may fly or not (e.g. remote scenario).
934cdf0e10cSrcweir // When it flies, it must contain the correct elements.
935cdf0e10cSrcweir xLBT->raiseRuntimeExceptionOneway( sCompare, x );
936cdf0e10cSrcweir }
937cdf0e10cSrcweir catch( RuntimeException & e )
938cdf0e10cSrcweir {
939cdf0e10cSrcweir bReturn = (
940cdf0e10cSrcweir #if OSL_DEBUG_LEVEL == 0
941cdf0e10cSrcweir // java stack traces trash Message
942cdf0e10cSrcweir e.Message == sCompare &&
943cdf0e10cSrcweir #endif
944cdf0e10cSrcweir xLBT->getInterface() == e.Context &&
945cdf0e10cSrcweir x == e.Context );
946cdf0e10cSrcweir }
947cdf0e10cSrcweir return bReturn;
948cdf0e10cSrcweir }
949cdf0e10cSrcweir
950cdf0e10cSrcweir //==================================================================================================
raiseException(const Reference<XBridgeTest> & xLBT)951cdf0e10cSrcweir static sal_Bool raiseException( const Reference< XBridgeTest > & xLBT )
952cdf0e10cSrcweir {
953cdf0e10cSrcweir sal_Int32 nCount = 0;
954cdf0e10cSrcweir try
955cdf0e10cSrcweir {
956cdf0e10cSrcweir try
957cdf0e10cSrcweir {
958cdf0e10cSrcweir try
959cdf0e10cSrcweir {
960cdf0e10cSrcweir TestData aRet, aRet2;
961cdf0e10cSrcweir xLBT->raiseException(
962cdf0e10cSrcweir 5, OUSTR(STRING_TEST_CONSTANT),
963cdf0e10cSrcweir xLBT->getInterface() );
964cdf0e10cSrcweir }
965cdf0e10cSrcweir catch (IllegalArgumentException aExc)
966cdf0e10cSrcweir {
967cdf0e10cSrcweir if (aExc.ArgumentPosition == 5 &&
968cdf0e10cSrcweir #if OSL_DEBUG_LEVEL == 0
969cdf0e10cSrcweir // java stack traces trash Message
970cdf0e10cSrcweir aExc.Message.compareToAscii( STRING_TEST_CONSTANT ) == 0 &&
971cdf0e10cSrcweir #endif
972cdf0e10cSrcweir aExc.Context == xLBT->getInterface())
973cdf0e10cSrcweir {
974cdf0e10cSrcweir #ifdef COMPCHECK
975cdf0e10cSrcweir //When we check if a new compiler still works then we must not call
976cdf0e10cSrcweir //getRuntimeException because it uses cppu::getCaughtException which
977cdf0e10cSrcweir //does only work if all libs are build with the same runtime.
978cdf0e10cSrcweir return true;
979cdf0e10cSrcweir #else
980cdf0e10cSrcweir ++nCount;
981cdf0e10cSrcweir #endif
982cdf0e10cSrcweir }
983cdf0e10cSrcweir else
984cdf0e10cSrcweir {
985cdf0e10cSrcweir check( sal_False, "### unexpected exception content!" );
986cdf0e10cSrcweir }
987cdf0e10cSrcweir
988cdf0e10cSrcweir /** it is certain, that the RuntimeException testing will fail, if no */
989cdf0e10cSrcweir xLBT->getRuntimeException();
990cdf0e10cSrcweir }
991cdf0e10cSrcweir }
992cdf0e10cSrcweir catch (const RuntimeException & rExc)
993cdf0e10cSrcweir {
994cdf0e10cSrcweir if (rExc.Context == xLBT->getInterface()
995cdf0e10cSrcweir #if OSL_DEBUG_LEVEL == 0
996cdf0e10cSrcweir // java stack traces trash Message
997cdf0e10cSrcweir && rExc.Message.compareToAscii( STRING_TEST_CONSTANT ) == 0
998cdf0e10cSrcweir #endif
999cdf0e10cSrcweir )
1000cdf0e10cSrcweir {
1001cdf0e10cSrcweir ++nCount;
1002cdf0e10cSrcweir }
1003cdf0e10cSrcweir else
1004cdf0e10cSrcweir {
1005cdf0e10cSrcweir check( sal_False, "### unexpected exception content!" );
1006cdf0e10cSrcweir }
1007cdf0e10cSrcweir
1008cdf0e10cSrcweir /** it is certain, that the RuntimeException testing will fail, if no */
1009cdf0e10cSrcweir xLBT->setRuntimeException( 0xcafebabe );
1010cdf0e10cSrcweir }
1011cdf0e10cSrcweir }
1012cdf0e10cSrcweir catch (Exception & rExc)
1013cdf0e10cSrcweir {
1014cdf0e10cSrcweir if (rExc.Context == xLBT->getInterface()
1015cdf0e10cSrcweir #if OSL_DEBUG_LEVEL == 0
1016cdf0e10cSrcweir // java stack traces trash Message
1017cdf0e10cSrcweir && rExc.Message.compareToAscii( STRING_TEST_CONSTANT ) == 0
1018cdf0e10cSrcweir #endif
1019cdf0e10cSrcweir )
1020cdf0e10cSrcweir {
1021cdf0e10cSrcweir ++nCount;
1022cdf0e10cSrcweir }
1023cdf0e10cSrcweir else
1024cdf0e10cSrcweir {
1025cdf0e10cSrcweir check( sal_False, "### unexpected exception content!" );
1026cdf0e10cSrcweir }
1027cdf0e10cSrcweir return (nCount == 3);
1028cdf0e10cSrcweir }
1029cdf0e10cSrcweir return sal_False;
1030cdf0e10cSrcweir }
1031cdf0e10cSrcweir
1032cdf0e10cSrcweir /* Returns an acquired sequence
1033cdf0e10cSrcweir */
cloneSequence(const uno_Sequence * val,const Type & type)1034cdf0e10cSrcweir uno_Sequence* cloneSequence(const uno_Sequence* val, const Type& type)
1035cdf0e10cSrcweir {
1036cdf0e10cSrcweir TypeDescription td(type);
1037cdf0e10cSrcweir td.makeComplete();
1038cdf0e10cSrcweir typelib_TypeDescription* pTdRaw = td.get();
1039cdf0e10cSrcweir typelib_IndirectTypeDescription* pIndirectTd =
1040cdf0e10cSrcweir (typelib_IndirectTypeDescription*) pTdRaw;
1041cdf0e10cSrcweir
1042cdf0e10cSrcweir typelib_TypeDescription* pTdElem = pIndirectTd->pType->pType;
1043cdf0e10cSrcweir sal_Int8* buf = new sal_Int8[pTdElem->nSize * val->nElements];
1044cdf0e10cSrcweir sal_Int8* pBufCur = buf;
1045cdf0e10cSrcweir
1046cdf0e10cSrcweir uno_Sequence* retSeq = NULL;
1047cdf0e10cSrcweir switch (pTdElem->eTypeClass)
1048cdf0e10cSrcweir {
1049cdf0e10cSrcweir case TypeClass_SEQUENCE:
1050cdf0e10cSrcweir {
1051cdf0e10cSrcweir Type _tElem(pTdElem->pWeakRef);
1052cdf0e10cSrcweir for (int i = 0; i < val->nElements; i++)
1053cdf0e10cSrcweir {
1054cdf0e10cSrcweir uno_Sequence* seq = cloneSequence(
1055cdf0e10cSrcweir *(uno_Sequence**) (&val->elements + i * pTdElem->nSize),
1056cdf0e10cSrcweir _tElem);
1057cdf0e10cSrcweir *((uno_Sequence**) pBufCur) = seq;
1058cdf0e10cSrcweir pBufCur += pTdElem->nSize;
1059cdf0e10cSrcweir }
1060cdf0e10cSrcweir break;
1061cdf0e10cSrcweir }
1062cdf0e10cSrcweir default:
1063cdf0e10cSrcweir uno_type_sequence_construct(
1064cdf0e10cSrcweir &retSeq, type.getTypeLibType(), (void*) val->elements,
1065cdf0e10cSrcweir val->nElements, reinterpret_cast< uno_AcquireFunc >(cpp_acquire));
1066cdf0e10cSrcweir break;
1067cdf0e10cSrcweir }
1068cdf0e10cSrcweir delete[] buf;
1069cdf0e10cSrcweir return retSeq;
1070cdf0e10cSrcweir }
1071cdf0e10cSrcweir
1072cdf0e10cSrcweir template< class T>
cloneSequence(const Sequence<T> & val)1073cdf0e10cSrcweir Sequence<T> cloneSequence(const Sequence<T>& val)
1074cdf0e10cSrcweir {
1075cdf0e10cSrcweir Sequence<T> seq( cloneSequence(val.get(), getCppuType(&val)), SAL_NO_ACQUIRE);
1076cdf0e10cSrcweir return seq;
1077cdf0e10cSrcweir }
1078cdf0e10cSrcweir
1079cdf0e10cSrcweir template< class T >
makeSurrogate(Reference<T> & rOut,Reference<T> const & rOriginal)1080cdf0e10cSrcweir inline bool makeSurrogate(
1081cdf0e10cSrcweir Reference< T > & rOut, Reference< T > const & rOriginal )
1082cdf0e10cSrcweir {
1083cdf0e10cSrcweir rOut.clear();
1084cdf0e10cSrcweir if (! rOriginal.is())
1085cdf0e10cSrcweir return false;
1086cdf0e10cSrcweir
1087cdf0e10cSrcweir Environment aCppEnv_official;
1088cdf0e10cSrcweir Environment aUnoEnv_ano;
1089cdf0e10cSrcweir Environment aCppEnv_ano;
1090cdf0e10cSrcweir
1091cdf0e10cSrcweir OUString aCppEnvTypeName(
1092cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM(CPPU_CURRENT_LANGUAGE_BINDING_NAME) );
1093cdf0e10cSrcweir OUString aUnoEnvTypeName(
1094cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM(UNO_LB_UNO) );
1095cdf0e10cSrcweir // official:
1096cdf0e10cSrcweir uno_getEnvironment(
1097cdf0e10cSrcweir reinterpret_cast< uno_Environment ** >( &aCppEnv_official ),
1098cdf0e10cSrcweir aCppEnvTypeName.pData, 0 );
1099cdf0e10cSrcweir // anonymous:
1100cdf0e10cSrcweir uno_createEnvironment(
1101cdf0e10cSrcweir reinterpret_cast< uno_Environment ** >( &aCppEnv_ano ),
1102cdf0e10cSrcweir aCppEnvTypeName.pData, 0 );
1103cdf0e10cSrcweir uno_createEnvironment(
1104cdf0e10cSrcweir reinterpret_cast< uno_Environment ** >( &aUnoEnv_ano ),
1105cdf0e10cSrcweir aUnoEnvTypeName.pData, 0 );
1106cdf0e10cSrcweir
1107cdf0e10cSrcweir UnoInterfaceReference unoI;
1108cdf0e10cSrcweir Mapping cpp2uno( aCppEnv_official.get(), aUnoEnv_ano.get() );
1109cdf0e10cSrcweir Mapping uno2cpp( aUnoEnv_ano.get(), aCppEnv_ano.get() );
1110cdf0e10cSrcweir if (!cpp2uno.is() || !uno2cpp.is())
1111cdf0e10cSrcweir {
1112cdf0e10cSrcweir throw RuntimeException(
1113cdf0e10cSrcweir OUSTR("cannot get C++-UNO mappings!"),
1114cdf0e10cSrcweir Reference< XInterface >() );
1115cdf0e10cSrcweir }
1116cdf0e10cSrcweir cpp2uno.mapInterface(
1117cdf0e10cSrcweir reinterpret_cast< void ** >( &unoI.m_pUnoI ),
1118cdf0e10cSrcweir rOriginal.get(), ::getCppuType( &rOriginal ) );
1119cdf0e10cSrcweir if (! unoI.is())
1120cdf0e10cSrcweir {
1121cdf0e10cSrcweir throw RuntimeException(
1122cdf0e10cSrcweir OUSTR("mapping C++ to binary UNO failed!"),
1123cdf0e10cSrcweir Reference< XInterface >() );
1124cdf0e10cSrcweir }
1125cdf0e10cSrcweir uno2cpp.mapInterface(
1126cdf0e10cSrcweir reinterpret_cast< void ** >( &rOut ),
1127cdf0e10cSrcweir unoI.get(), ::getCppuType( &rOriginal ) );
1128cdf0e10cSrcweir if (! rOut.is())
1129cdf0e10cSrcweir {
1130cdf0e10cSrcweir throw RuntimeException(
1131cdf0e10cSrcweir OUSTR("mapping binary UNO to C++ failed!"),
1132cdf0e10cSrcweir Reference< XInterface >() );
1133cdf0e10cSrcweir }
1134cdf0e10cSrcweir
1135cdf0e10cSrcweir return rOut.is();
1136cdf0e10cSrcweir }
1137cdf0e10cSrcweir
1138cdf0e10cSrcweir //==================================================================================================
run(const Sequence<OUString> & rArgs)1139cdf0e10cSrcweir sal_Int32 TestBridgeImpl::run( const Sequence< OUString > & rArgs )
1140cdf0e10cSrcweir throw (RuntimeException)
1141cdf0e10cSrcweir {
1142cdf0e10cSrcweir bool bRet = false;
1143cdf0e10cSrcweir try
1144cdf0e10cSrcweir {
1145cdf0e10cSrcweir if (! rArgs.getLength())
1146cdf0e10cSrcweir {
1147cdf0e10cSrcweir throw RuntimeException( OUString( RTL_CONSTASCII_USTRINGPARAM(
1148cdf0e10cSrcweir "no test object specified!\n"
1149cdf0e10cSrcweir "usage : ServiceName of test object | -u unourl of test object\n" ) ),
1150cdf0e10cSrcweir Reference< XInterface >() );
1151cdf0e10cSrcweir }
1152cdf0e10cSrcweir
1153cdf0e10cSrcweir Reference< XInterface > xOriginal;
1154cdf0e10cSrcweir bool remote;
1155cdf0e10cSrcweir sal_Int32 i;
1156cdf0e10cSrcweir if( rArgs.getLength() > 1 && 0 == rArgs[0].compareToAscii( "-u" ) )
1157cdf0e10cSrcweir {
1158cdf0e10cSrcweir remote = true;
1159cdf0e10cSrcweir i = 2;
1160cdf0e10cSrcweir }
1161cdf0e10cSrcweir else
1162cdf0e10cSrcweir {
1163cdf0e10cSrcweir remote = false;
1164cdf0e10cSrcweir i = 1;
1165cdf0e10cSrcweir }
1166cdf0e10cSrcweir bool noCurrentContext = false;
1167cdf0e10cSrcweir if (i < rArgs.getLength()
1168cdf0e10cSrcweir && rArgs[i].equalsAsciiL(
1169cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM("noCurrentContext")))
1170cdf0e10cSrcweir {
1171cdf0e10cSrcweir noCurrentContext = true;
1172cdf0e10cSrcweir ++i;
1173cdf0e10cSrcweir }
1174cdf0e10cSrcweir bool stress = false;
1175cdf0e10cSrcweir if (i < rArgs.getLength()
1176cdf0e10cSrcweir && rArgs[i].equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("stress")))
1177cdf0e10cSrcweir {
1178cdf0e10cSrcweir stress = true;
1179cdf0e10cSrcweir ++i;
1180cdf0e10cSrcweir }
1181cdf0e10cSrcweir
1182cdf0e10cSrcweir for (;;) {
1183cdf0e10cSrcweir Reference< XInterface > o;
1184cdf0e10cSrcweir if (remote) {
1185cdf0e10cSrcweir o = UnoUrlResolver::create(m_xContext)->resolve(rArgs[1]);
1186cdf0e10cSrcweir } else {
1187cdf0e10cSrcweir o = m_xContext->getServiceManager()->createInstanceWithContext(
1188cdf0e10cSrcweir rArgs[0], m_xContext);
1189cdf0e10cSrcweir }
1190cdf0e10cSrcweir if (!stress) {
1191cdf0e10cSrcweir xOriginal = o;
1192cdf0e10cSrcweir break;
1193cdf0e10cSrcweir }
1194cdf0e10cSrcweir }
1195cdf0e10cSrcweir
1196cdf0e10cSrcweir if (! xOriginal.is())
1197cdf0e10cSrcweir {
1198cdf0e10cSrcweir throw RuntimeException(
1199cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM(
1200cdf0e10cSrcweir "cannot get test object!") ),
1201cdf0e10cSrcweir Reference< XInterface >() );
1202cdf0e10cSrcweir }
1203cdf0e10cSrcweir Reference< XBridgeTest > xTest( xOriginal, UNO_QUERY );
1204cdf0e10cSrcweir if (! xTest.is())
1205cdf0e10cSrcweir {
1206cdf0e10cSrcweir throw RuntimeException(
1207cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM("test object does not implement XBridgeTest!") ),
1208cdf0e10cSrcweir Reference< XInterface >() );
1209cdf0e10cSrcweir }
1210cdf0e10cSrcweir
1211cdf0e10cSrcweir Reference<XBridgeTest > xLBT;
1212cdf0e10cSrcweir bRet = check( makeSurrogate( xLBT, xTest ), "makeSurrogate" );
1213cdf0e10cSrcweir bRet = check(
1214cdf0e10cSrcweir performTest( m_xContext, xLBT, noCurrentContext ), "standard test" )
1215cdf0e10cSrcweir && bRet;
1216cdf0e10cSrcweir bRet = check( raiseException( xLBT ) , "exception test" )&& bRet;
1217cdf0e10cSrcweir bRet = check( raiseOnewayException( xLBT ),
1218cdf0e10cSrcweir "oneway exception test" ) && bRet;
1219cdf0e10cSrcweir if (! bRet)
1220cdf0e10cSrcweir {
1221cdf0e10cSrcweir throw RuntimeException(
1222cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM("error: test failed!") ),
1223cdf0e10cSrcweir Reference< XInterface >() );
1224cdf0e10cSrcweir }
1225cdf0e10cSrcweir }
1226cdf0e10cSrcweir catch (Exception & exc)
1227cdf0e10cSrcweir {
1228cdf0e10cSrcweir OString cstr( OUStringToOString( exc.Message, RTL_TEXTENCODING_ASCII_US ) );
122986e1cf34SPedro Giffuni fprintf( stderr, "exception occurred: %s\n", cstr.getStr() );
1230cdf0e10cSrcweir throw;
1231cdf0e10cSrcweir }
1232cdf0e10cSrcweir
1233cdf0e10cSrcweir if( bRet )
1234cdf0e10cSrcweir {
1235cdf0e10cSrcweir printf( "\n\n ### test succeeded!\n" );
1236cdf0e10cSrcweir }
1237cdf0e10cSrcweir else
1238cdf0e10cSrcweir {
1239cdf0e10cSrcweir printf( "\n> ### test failed!\n" );
1240cdf0e10cSrcweir }
1241cdf0e10cSrcweir
1242cdf0e10cSrcweir return 0;
1243cdf0e10cSrcweir }
1244cdf0e10cSrcweir
1245cdf0e10cSrcweir // XServiceInfo
1246cdf0e10cSrcweir //__________________________________________________________________________________________________
getImplementationName()1247cdf0e10cSrcweir OUString TestBridgeImpl::getImplementationName()
1248cdf0e10cSrcweir throw (RuntimeException)
1249cdf0e10cSrcweir {
1250cdf0e10cSrcweir return OUString( RTL_CONSTASCII_USTRINGPARAM(IMPLNAME) );
1251cdf0e10cSrcweir }
1252cdf0e10cSrcweir //__________________________________________________________________________________________________
supportsService(const OUString & rServiceName)1253cdf0e10cSrcweir sal_Bool TestBridgeImpl::supportsService( const OUString & rServiceName )
1254cdf0e10cSrcweir throw (RuntimeException)
1255cdf0e10cSrcweir {
1256cdf0e10cSrcweir const Sequence< OUString > & rSNL = getSupportedServiceNames();
1257cdf0e10cSrcweir const OUString * pArray = rSNL.getConstArray();
1258cdf0e10cSrcweir for ( sal_Int32 nPos = rSNL.getLength(); nPos--; )
1259cdf0e10cSrcweir {
1260cdf0e10cSrcweir if (pArray[nPos] == rServiceName)
1261cdf0e10cSrcweir return sal_True;
1262cdf0e10cSrcweir }
1263cdf0e10cSrcweir return sal_False;
1264cdf0e10cSrcweir }
1265cdf0e10cSrcweir //__________________________________________________________________________________________________
getSupportedServiceNames()1266cdf0e10cSrcweir Sequence< OUString > TestBridgeImpl::getSupportedServiceNames()
1267cdf0e10cSrcweir throw (RuntimeException)
1268cdf0e10cSrcweir {
1269cdf0e10cSrcweir return bridge_test::getSupportedServiceNames();
1270cdf0e10cSrcweir }
1271cdf0e10cSrcweir
1272cdf0e10cSrcweir // ...
1273cdf0e10cSrcweir
1274cdf0e10cSrcweir //==================================================================================================
TestBridgeImpl_create(const Reference<XComponentContext> & xContext)1275cdf0e10cSrcweir static Reference< XInterface > SAL_CALL TestBridgeImpl_create(
1276cdf0e10cSrcweir const Reference< XComponentContext > & xContext )
1277cdf0e10cSrcweir {
1278cdf0e10cSrcweir return Reference< XInterface >(
1279cdf0e10cSrcweir static_cast< OWeakObject * >( new TestBridgeImpl( xContext ) ) );
1280cdf0e10cSrcweir }
1281cdf0e10cSrcweir
1282cdf0e10cSrcweir }
1283cdf0e10cSrcweir
1284cdf0e10cSrcweir extern "C"
1285cdf0e10cSrcweir {
1286cdf0e10cSrcweir //==================================================================================================
component_getImplementationEnvironment(const sal_Char ** ppEnvTypeName,uno_Environment **)1287cdf0e10cSrcweir void SAL_CALL component_getImplementationEnvironment(
1288cdf0e10cSrcweir const sal_Char ** ppEnvTypeName, uno_Environment ** )
1289cdf0e10cSrcweir {
1290cdf0e10cSrcweir *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
1291cdf0e10cSrcweir }
1292cdf0e10cSrcweir //==================================================================================================
component_getFactory(const sal_Char * pImplName,void * pServiceManager,void *)1293cdf0e10cSrcweir void * SAL_CALL component_getFactory(
1294cdf0e10cSrcweir const sal_Char * pImplName, void * pServiceManager, void * )
1295cdf0e10cSrcweir {
1296cdf0e10cSrcweir void * pRet = 0;
1297cdf0e10cSrcweir
1298cdf0e10cSrcweir if (pServiceManager && rtl_str_compare( pImplName, IMPLNAME ) == 0)
1299cdf0e10cSrcweir {
1300cdf0e10cSrcweir Reference< XInterface > xFactory(
1301cdf0e10cSrcweir createSingleComponentFactory(
1302cdf0e10cSrcweir bridge_test::TestBridgeImpl_create,
1303cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM(IMPLNAME) ),
1304cdf0e10cSrcweir bridge_test::getSupportedServiceNames() ) );
1305cdf0e10cSrcweir
1306cdf0e10cSrcweir if (xFactory.is())
1307cdf0e10cSrcweir {
1308cdf0e10cSrcweir xFactory->acquire();
1309cdf0e10cSrcweir pRet = xFactory.get();
1310cdf0e10cSrcweir }
1311cdf0e10cSrcweir }
1312cdf0e10cSrcweir
1313cdf0e10cSrcweir return pRet;
1314cdf0e10cSrcweir }
1315cdf0e10cSrcweir }
1316