xref: /trunk/main/stoc/test/testiadapter.cxx (revision 91144cd0085a7583d2099b982122deb2184ab956)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_stoc.hxx"
26 
27 #include <stdio.h>
28 
29 #include <sal/main.h>
30 #include <osl/diagnose.h>
31 
32 #include <cppuhelper/servicefactory.hxx>
33 #include <cppuhelper/weak.hxx>
34 
35 #include <test/XLanguageBindingTest.hpp>
36 #include <com/sun/star/registry/XSimpleRegistry.hpp>
37 #include <com/sun/star/registry/XImplementationRegistration.hpp>
38 #include <com/sun/star/script/XInvocation.hpp>
39 #include <com/sun/star/script/XInvocationAdapterFactory.hpp>
40 #include <com/sun/star/script/XInvocationAdapterFactory2.hpp>
41 #include <com/sun/star/lang/XComponent.hpp>
42 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
43 
44 #include <cppuhelper/implbase1.hxx>
45 
46 
47 using namespace test;
48 using namespace rtl;
49 using namespace cppu;
50 using namespace osl;
51 using namespace com::sun::star::uno;
52 using namespace com::sun::star::script;
53 using namespace com::sun::star::beans;
54 using namespace com::sun::star::lang;
55 using namespace com::sun::star::reflection;
56 using namespace com::sun::star::lang;
57 using namespace com::sun::star::registry;
58 
59 
60 //==================================================================================================
equals(const test::TestElement & rData1,const test::TestElement & rData2)61 sal_Bool equals( const test::TestElement & rData1, const test::TestElement & rData2 )
62 {
63     OSL_ENSURE( rData1.Bool == rData2.Bool, "### bool does not match!" );
64     OSL_ENSURE( rData1.Char == rData2.Char, "### char does not match!" );
65     OSL_ENSURE( rData1.Byte == rData2.Byte, "### byte does not match!" );
66     OSL_ENSURE( rData1.Short == rData2.Short, "### short does not match!" );
67     OSL_ENSURE( rData1.UShort == rData2.UShort, "### unsigned short does not match!" );
68     OSL_ENSURE( rData1.Long == rData2.Long, "### long does not match!" );
69     OSL_ENSURE( rData1.ULong == rData2.ULong, "### unsigned long does not match!" );
70     OSL_ENSURE( rData1.Hyper == rData2.Hyper, "### hyper does not match!" );
71     OSL_ENSURE( rData1.UHyper == rData2.UHyper, "### unsigned hyper does not match!" );
72     OSL_ENSURE( rData1.Float == rData2.Float, "### float does not match!" );
73     OSL_ENSURE( rData1.Double == rData2.Double, "### double does not match!" );
74     OSL_ENSURE( rData1.Enum == rData2.Enum, "### enum does not match!" );
75     OSL_ENSURE( rData1.String == rData2.String, "### string does not match!" );
76     OSL_ENSURE( rData1.Interface == rData2.Interface, "### interface does not match!" );
77     OSL_ENSURE( rData1.Any == rData2.Any, "### any does not match!" );
78 
79     return (rData1.Bool == rData2.Bool &&
80             rData1.Char == rData2.Char &&
81             rData1.Byte == rData2.Byte &&
82             rData1.Short == rData2.Short &&
83             rData1.UShort == rData2.UShort &&
84             rData1.Long == rData2.Long &&
85             rData1.ULong == rData2.ULong &&
86             rData1.Hyper == rData2.Hyper &&
87             rData1.UHyper == rData2.UHyper &&
88             rData1.Float == rData2.Float &&
89             rData1.Double == rData2.Double &&
90             rData1.Enum == rData2.Enum &&
91             rData1.String == rData2.String &&
92             rData1.Interface == rData2.Interface &&
93             rData1.Any == rData2.Any);
94 }
95 //==================================================================================================
equals(const test::TestData & rData1,const test::TestData & rData2)96 sal_Bool equals( const test::TestData & rData1, const test::TestData & rData2 )
97 {
98     sal_Int32 nLen;
99 
100     if ((rData1.Sequence == rData2.Sequence) &&
101         equals( (const test::TestElement &)rData1, (const test::TestElement &)rData2 ) &&
102         (nLen = rData1.Sequence.getLength()) == rData2.Sequence.getLength())
103     {
104         // once again by hand sequence ==
105         const test::TestElement * pElements1 = rData1.Sequence.getConstArray();
106         const test::TestElement * pElements2 = rData2.Sequence.getConstArray();
107         for ( ; nLen--; )
108         {
109             if (! equals( pElements1[nLen], pElements2[nLen] ))
110             {
111                 OSL_ENSURE( sal_False, "### sequence element did not match!" );
112                 return sal_False;
113             }
114         }
115         return sal_True;
116     }
117     return sal_False;
118 }
119 //==================================================================================================
assign(test::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,test::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)120 void assign( test::TestElement & rData,
121              sal_Bool bBool, sal_Unicode cChar, sal_Int8 nByte,
122              sal_Int16 nShort, sal_uInt16 nUShort,
123              sal_Int32 nLong, sal_uInt32 nULong,
124              sal_Int64 nHyper, sal_uInt64 nUHyper,
125              float fFloat, double fDouble,
126              test::TestEnum eEnum, const ::rtl::OUString& rStr,
127              const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& xTest,
128              const ::com::sun::star::uno::Any& rAny )
129 {
130     rData.Bool = bBool;
131     rData.Char = cChar;
132     rData.Byte = nByte;
133     rData.Short = nShort;
134     rData.UShort = nUShort;
135     rData.Long = nLong;
136     rData.ULong = nULong;
137     rData.Hyper = nHyper;
138     rData.UHyper = nUHyper;
139     rData.Float = fFloat;
140     rData.Double = fDouble;
141     rData.Enum = eEnum;
142     rData.String = rStr;
143     rData.Interface = xTest;
144     rData.Any = rAny;
145 }
146 //==================================================================================================
assign(test::TestData & rData,sal_Bool bBool,sal_Unicode cChar,sal_Int8 nByte,sal_Int16 nShort,sal_uInt16 nUShort,sal_Int32 nLong,sal_uInt32 nULong,sal_Int64 nHyper,sal_uInt64 nUHyper,float fFloat,double fDouble,test::TestEnum eEnum,const::rtl::OUString & rStr,const::com::sun::star::uno::Reference<::com::sun::star::uno::XInterface> & xTest,const::com::sun::star::uno::Any & rAny,const com::sun::star::uno::Sequence<test::TestElement> & rSequence)147 void assign( test::TestData & rData,
148              sal_Bool bBool, sal_Unicode cChar, sal_Int8 nByte,
149              sal_Int16 nShort, sal_uInt16 nUShort,
150              sal_Int32 nLong, sal_uInt32 nULong,
151              sal_Int64 nHyper, sal_uInt64 nUHyper,
152              float fFloat, double fDouble,
153              test::TestEnum eEnum, const ::rtl::OUString& rStr,
154              const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& xTest,
155              const ::com::sun::star::uno::Any& rAny,
156              const com::sun::star::uno::Sequence< test::TestElement >& rSequence )
157 {
158     assign( (test::TestElement &)rData,
159             bBool, cChar, nByte, nShort, nUShort, nLong, nULong, nHyper, nUHyper, fFloat, fDouble,
160             eEnum, rStr, xTest, rAny );
161     rData.Sequence = rSequence;
162 }
163 
164 //==================================================================================================
165 class Test_Impl : public WeakImplHelper1< XLanguageBindingTest >
166 {
167     test::TestData _aData, _aStructData;
168 
169 public:
~Test_Impl()170     virtual ~Test_Impl()
171         { OSL_TRACE( "> scalar Test_Impl dtor <\n" ); }
172 
173     // XLBTestBase
174     virtual void SAL_CALL setValues( sal_Bool bBool, sal_Unicode cChar, sal_Int8 nByte,
175                                      sal_Int16 nShort, sal_uInt16 nUShort,
176                                      sal_Int32 nLong, sal_uInt32 nULong,
177                                      sal_Int64 nHyper, sal_uInt64 nUHyper,
178                                      float fFloat, double fDouble,
179                                      test::TestEnum eEnum, const ::rtl::OUString& rStr,
180                                      const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& xTest,
181                                      const ::com::sun::star::uno::Any& rAny,
182                                      const ::com::sun::star::uno::Sequence<test::TestElement >& rSequence,
183                                      const test::TestData& rStruct );
184 
185     virtual test::TestData SAL_CALL setValues2( sal_Bool& bBool, sal_Unicode& cChar, sal_Int8& nByte,
186                                                 sal_Int16& nShort, sal_uInt16& nUShort,
187                                                 sal_Int32& nLong, sal_uInt32& nULong,
188                                                 sal_Int64& nHyper, sal_uInt64& nUHyper,
189                                                 float& fFloat, double& fDouble,
190                                                 test::TestEnum& eEnum, rtl::OUString& rStr,
191                                                 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& xTest,
192                                                 ::com::sun::star::uno::Any& rAny,
193                                                 ::com::sun::star::uno::Sequence<test::TestElement >& rSequence,
194                                                 test::TestData& rStruct );
195 
196     virtual test::TestData SAL_CALL getValues( sal_Bool& bBool, sal_Unicode& cChar, sal_Int8& nByte,
197                                                sal_Int16& nShort, sal_uInt16& nUShort,
198                                                sal_Int32& nLong, sal_uInt32& nULong,
199                                                sal_Int64& nHyper, sal_uInt64& nUHyper,
200                                                float& fFloat, double& fDouble,
201                                                test::TestEnum& eEnum, rtl::OUString& rStr,
202                                                ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& xTest,
203                                                ::com::sun::star::uno::Any& rAny,
204                                                ::com::sun::star::uno::Sequence< test::TestElement >& rSequence,
205                                                test::TestData& rStruct );
206 
getBool()207     virtual sal_Bool SAL_CALL getBool()
208         { return _aData.Bool; }
getByte()209     virtual sal_Int8 SAL_CALL getByte()
210         { return _aData.Byte; }
getChar()211     virtual sal_Unicode SAL_CALL getChar()
212         { return _aData.Char; }
getShort()213     virtual sal_Int16 SAL_CALL getShort()
214         { return _aData.Short; }
getUShort()215     virtual sal_uInt16 SAL_CALL getUShort()
216         { return _aData.UShort; }
getLong()217     virtual sal_Int32 SAL_CALL getLong()
218         { return _aData.Long; }
getULong()219     virtual sal_uInt32 SAL_CALL getULong()
220         { return _aData.ULong; }
getHyper()221     virtual sal_Int64 SAL_CALL getHyper()
222         { return _aData.Hyper; }
getUHyper()223     virtual sal_uInt64 SAL_CALL getUHyper()
224         { return _aData.UHyper; }
getFloat()225     virtual float SAL_CALL getFloat()
226         { return _aData.Float; }
getDouble()227     virtual double SAL_CALL getDouble()
228         { return _aData.Double; }
getEnum()229     virtual test::TestEnum SAL_CALL getEnum()
230         { return _aData.Enum; }
getString()231     virtual rtl::OUString SAL_CALL getString()
232         { return _aData.String; }
getInterface()233     virtual com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL getInterface(  )
234         { return _aData.Interface; }
getAny()235     virtual com::sun::star::uno::Any SAL_CALL getAny()
236         { return _aData.Any; }
getSequence()237     virtual com::sun::star::uno::Sequence< test::TestElement > SAL_CALL getSequence()
238         { return _aData.Sequence; }
getStruct()239     virtual test::TestData SAL_CALL getStruct()
240         { return _aStructData; }
241 
setBool(sal_Bool _bool)242     virtual void SAL_CALL setBool( sal_Bool _bool )
243         { _aData.Bool = _bool; }
setByte(sal_Int8 _byte)244     virtual void SAL_CALL setByte( sal_Int8 _byte )
245         { _aData.Byte = _byte; }
setChar(sal_Unicode _char)246     virtual void SAL_CALL setChar( sal_Unicode _char )
247         { _aData.Char = _char; }
setShort(sal_Int16 _short)248     virtual void SAL_CALL setShort( sal_Int16 _short )
249         { _aData.Short = _short; }
setUShort(sal_uInt16 _ushort)250     virtual void SAL_CALL setUShort( sal_uInt16 _ushort )
251         { _aData.UShort = _ushort; }
setLong(sal_Int32 _long)252     virtual void SAL_CALL setLong( sal_Int32 _long )
253         { _aData.Long = _long; }
setULong(sal_uInt32 _ulong)254     virtual void SAL_CALL setULong( sal_uInt32 _ulong )
255         { _aData.ULong = _ulong; }
setHyper(sal_Int64 _hyper)256     virtual void SAL_CALL setHyper( sal_Int64 _hyper )
257         { _aData.Hyper = _hyper; }
setUHyper(sal_uInt64 _uhyper)258     virtual void SAL_CALL setUHyper( sal_uInt64 _uhyper )
259         { _aData.UHyper = _uhyper; }
setFloat(float _float)260     virtual void SAL_CALL setFloat( float _float )
261         { _aData.Float = _float; }
setDouble(double _double)262     virtual void SAL_CALL setDouble( double _double )
263         { _aData.Double = _double; }
setEnum(test::TestEnum _enum)264     virtual void SAL_CALL setEnum( test::TestEnum _enum )
265         { _aData.Enum = _enum; }
setString(const::rtl::OUString & _string)266     virtual void SAL_CALL setString( const ::rtl::OUString& _string )
267         { _aData.String = _string; }
setInterface(const::com::sun::star::uno::Reference<::com::sun::star::uno::XInterface> & _interface)268     virtual void SAL_CALL setInterface( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _interface )
269         { _aData.Interface = _interface; }
setAny(const::com::sun::star::uno::Any & _any)270     virtual void SAL_CALL setAny( const ::com::sun::star::uno::Any& _any )
271         { _aData.Any = _any; }
setSequence(const::com::sun::star::uno::Sequence<test::TestElement> & _sequence)272     virtual void SAL_CALL setSequence( const ::com::sun::star::uno::Sequence<test::TestElement >& _sequence )
273         { _aData.Sequence = _sequence; }
setStruct(const test::TestData & _struct)274     virtual void SAL_CALL setStruct( const test::TestData& _struct )
275         { _aStructData = _struct; }
276 
277     // XLanguageBindingTest
278     virtual test::TestData SAL_CALL raiseException( 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, test::TestEnum& eEnum, ::rtl::OUString& aString, ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& xInterface, ::com::sun::star::uno::Any& aAny, ::com::sun::star::uno::Sequence<test::TestElement >& aSequence,test::TestData& aStruct );
279 
280     virtual sal_Int32 SAL_CALL getRuntimeException();
281     virtual void SAL_CALL setRuntimeException( sal_Int32 _runtimeexception );
282 };
283 //==================================================================================================
284 class XLB_Invocation : public WeakImplHelper1< XInvocation >
285 {
286     Reference< XLanguageBindingTest > _xLBT;
287 
288 public:
XLB_Invocation(const Reference<XMultiServiceFactory> &,const Reference<XLanguageBindingTest> & xLBT)289     XLB_Invocation( const Reference< XMultiServiceFactory > & /*xMgr*/,
290                     const Reference< XLanguageBindingTest > & xLBT )
291         : _xLBT( xLBT )
292         {}
293 
294     // XInvocation
getIntrospection()295     virtual Reference< XIntrospectionAccess > SAL_CALL getIntrospection()
296         { return Reference< XIntrospectionAccess >(); }
297     virtual Any SAL_CALL invoke( const OUString & rFunctionName,
298                                  const Sequence< Any > & rParams,
299                                  Sequence< sal_Int16 > & rOutParamIndex,
300                                  Sequence< Any > & rOutParam );
301     virtual void SAL_CALL setValue( const OUString & rPropertyName, const Any & rValue );
302     virtual Any SAL_CALL getValue( const OUString & rPropertyName );
303     virtual sal_Bool SAL_CALL hasMethod( const OUString & rName );
304     virtual sal_Bool SAL_CALL hasProperty( const OUString & rName );
305 };
306 //__________________________________________________________________________________________________
invoke(const OUString & rFunctionName,const Sequence<Any> & rParams,Sequence<sal_Int16> & rOutParamIndex,Sequence<Any> & rOutParam)307 Any XLB_Invocation::invoke( const OUString & rFunctionName,
308                             const Sequence< Any > & rParams,
309                             Sequence< sal_Int16 > & rOutParamIndex,
310                             Sequence< Any > & rOutParam )
311 {
312     bool bImplementedMethod = true;
313 
314     Any aRet;
315 
316     OSL_ASSERT( rOutParam.getLength() == 0 );
317     OSL_ASSERT( rOutParamIndex.getLength() == 0 );
318 
319     try
320     {
321         sal_Bool aBool;
322         sal_Unicode aChar;
323         sal_Int8 nByte;
324         sal_Int16 nShort;
325         sal_uInt16 nUShort;
326         sal_Int32 nLong;
327         sal_uInt32 nULong;
328         sal_Int64 nHyper;
329         sal_uInt64 nUHyper;
330         float fFloat;
331         double fDouble;
332         TestEnum eEnum;
333         OUString aString;
334         Reference< XInterface > xInterface;
335         Any aAny;
336         Sequence< TestElement > aSeq;
337         TestData aData;
338 
339         if (rFunctionName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("setValues") ))
340         {
341             OSL_ASSERT( rParams.getLength() == 17 );
342             aBool = *(sal_Bool *)rParams[0].getValue();
343             aChar = *(sal_Unicode *)rParams[1].getValue();
344             rParams[2] >>= nByte;
345             rParams[3] >>= nShort;
346             rParams[4] >>= nUShort;
347             rParams[5] >>= nLong;
348             rParams[6] >>= nULong;
349             rParams[7] >>= nHyper;
350             rParams[8] >>= nUHyper;
351             rParams[9] >>= fFloat;
352             rParams[10] >>= fDouble;
353             rParams[11] >>= eEnum;
354             rParams[12] >>= aString;
355             rParams[13] >>= xInterface;
356             rParams[14] >>= aAny;
357             rParams[15] >>= aSeq;
358             rParams[16] >>= aData;
359 
360             _xLBT->setValues( aBool, aChar, nByte, nShort, nUShort, nLong, nULong,
361                               nHyper, nUHyper, fFloat, fDouble, eEnum, aString, xInterface,
362                               aAny, aSeq, aData );
363 
364             rOutParamIndex.realloc( 0 );
365             rOutParam.realloc( 0 );
366         }
367         else if (rFunctionName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("setValues2") ))
368         {
369             aBool = *(sal_Bool *)rParams[0].getValue();
370             aChar = *(sal_Unicode *)rParams[1].getValue();
371             rParams[2] >>= nByte;
372             rParams[3] >>= nShort;
373             rParams[4] >>= nUShort;
374             rParams[5] >>= nLong;
375             rParams[6] >>= nULong;
376             rParams[7] >>= nHyper;
377             rParams[8] >>= nUHyper;
378             rParams[9] >>= fFloat;
379             rParams[10] >>= fDouble;
380             rParams[11] >>= eEnum;
381             rParams[12] >>= aString;
382             rParams[13] >>= xInterface;
383             rParams[14] >>= aAny;
384             rParams[15] >>= aSeq;
385             rParams[16] >>= aData;
386 
387             aRet <<= _xLBT->setValues2( aBool, aChar, nByte, nShort, nUShort, nLong, nULong,
388                                         nHyper, nUHyper, fFloat, fDouble, eEnum, aString, xInterface,
389                                         aAny, aSeq, aData );
390 
391             rOutParamIndex.realloc( 17 );
392             rOutParamIndex[0] = 0;
393             rOutParamIndex[1] = 1;
394             rOutParamIndex[2] = 2;
395             rOutParamIndex[3] = 3;
396             rOutParamIndex[4] = 4;
397             rOutParamIndex[5] = 5;
398             rOutParamIndex[6] = 6;
399             rOutParamIndex[7] = 7;
400             rOutParamIndex[8] = 8;
401             rOutParamIndex[9] = 9;
402             rOutParamIndex[10] = 10;
403             rOutParamIndex[11] = 11;
404             rOutParamIndex[12] = 12;
405             rOutParamIndex[13] = 13;
406             rOutParamIndex[14] = 14;
407             rOutParamIndex[15] = 15;
408             rOutParamIndex[16] = 16;
409 
410             rOutParam.realloc( 17 );
411             rOutParam[0].setValue( &aBool, ::getCppuBooleanType() );
412             rOutParam[1].setValue( &aChar, ::getCppuCharType() );
413             rOutParam[2] <<= nByte;
414             rOutParam[3] <<= nShort;
415             rOutParam[4] <<= nUShort;
416             rOutParam[5] <<= nLong;
417             rOutParam[6] <<= nULong;
418             rOutParam[7] <<= nHyper;
419             rOutParam[8] <<= nUHyper;
420             rOutParam[9] <<= fFloat;
421             rOutParam[10] <<= fDouble;
422             rOutParam[11] <<= eEnum;
423             rOutParam[12] <<= aString;
424             rOutParam[13] <<= xInterface;
425             rOutParam[14] <<= aAny;
426             rOutParam[15] <<= aSeq;
427             rOutParam[16] <<= aData;
428         }
429         else if (rFunctionName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("getValues") ))
430         {
431             aRet <<= _xLBT->getValues( aBool, aChar, nByte, nShort, nUShort, nLong, nULong,
432                                        nHyper, nUHyper, fFloat, fDouble, eEnum, aString, xInterface,
433                                        aAny, aSeq, aData );
434 
435             rOutParamIndex.realloc( 17 );
436             rOutParamIndex[0] = 0;
437             rOutParamIndex[1] = 1;
438             rOutParamIndex[2] = 2;
439             rOutParamIndex[3] = 3;
440             rOutParamIndex[4] = 4;
441             rOutParamIndex[5] = 5;
442             rOutParamIndex[6] = 6;
443             rOutParamIndex[7] = 7;
444             rOutParamIndex[8] = 8;
445             rOutParamIndex[9] = 9;
446             rOutParamIndex[10] = 10;
447             rOutParamIndex[11] = 11;
448             rOutParamIndex[12] = 12;
449             rOutParamIndex[13] = 13;
450             rOutParamIndex[14] = 14;
451             rOutParamIndex[15] = 15;
452             rOutParamIndex[16] = 16;
453 
454             rOutParam.realloc( 17 );
455             rOutParam[0].setValue( &aBool, ::getCppuBooleanType() );
456             rOutParam[1].setValue( &aChar, ::getCppuCharType() );
457             rOutParam[2] <<= nByte;
458             rOutParam[3] <<= nShort;
459             rOutParam[4] <<= nUShort;
460             rOutParam[5] <<= nLong;
461             rOutParam[6] <<= nULong;
462             rOutParam[7] <<= nHyper;
463             rOutParam[8] <<= nUHyper;
464             rOutParam[9] <<= fFloat;
465             rOutParam[10] <<= fDouble;
466             rOutParam[11] <<= eEnum;
467             rOutParam[12] <<= aString;
468             rOutParam[13] <<= xInterface;
469             rOutParam[14] <<= aAny;
470             rOutParam[15] <<= aSeq;
471             rOutParam[16] <<= aData;
472         }
473         else if (rFunctionName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("raiseException") ))
474         {
475             aRet <<= _xLBT->raiseException( aBool, aChar, nByte, nShort, nUShort, nLong, nULong,
476                                             nHyper, nUHyper, fFloat, fDouble, eEnum, aString, xInterface,
477                                             aAny, aSeq, aData );
478 
479             rOutParamIndex.realloc( 17 );
480             rOutParamIndex[0] = 0;
481             rOutParamIndex[1] = 1;
482             rOutParamIndex[2] = 2;
483             rOutParamIndex[3] = 3;
484             rOutParamIndex[4] = 4;
485             rOutParamIndex[5] = 5;
486             rOutParamIndex[6] = 6;
487             rOutParamIndex[7] = 7;
488             rOutParamIndex[8] = 8;
489             rOutParamIndex[9] = 9;
490             rOutParamIndex[10] = 10;
491             rOutParamIndex[11] = 11;
492             rOutParamIndex[12] = 12;
493             rOutParamIndex[13] = 13;
494             rOutParamIndex[14] = 14;
495             rOutParamIndex[15] = 15;
496             rOutParamIndex[16] = 16;
497 
498             rOutParam.realloc( 17 );
499             rOutParam[0].setValue( &aBool, ::getCppuBooleanType() );
500             rOutParam[1].setValue( &aChar, ::getCppuCharType() );
501             rOutParam[2] <<= nByte;
502             rOutParam[3] <<= nShort;
503             rOutParam[4] <<= nUShort;
504             rOutParam[5] <<= nLong;
505             rOutParam[6] <<= nULong;
506             rOutParam[7] <<= nHyper;
507             rOutParam[8] <<= nUHyper;
508             rOutParam[9] <<= fFloat;
509             rOutParam[10] <<= fDouble;
510             rOutParam[11] <<= eEnum;
511             rOutParam[12] <<= aString;
512             rOutParam[13] <<= xInterface;
513             rOutParam[14] <<= aAny;
514             rOutParam[15] <<= aSeq;
515             rOutParam[16] <<= aData;
516         }
517         else
518         {
519             bImplementedMethod = false;
520         }
521     }
522     catch (IllegalArgumentException & rExc)
523     {
524         // thrown by raiseException() call
525         InvocationTargetException aExc;
526         aExc.TargetException <<= rExc;
527         throw aExc;
528     }
529     catch (Exception &)
530     {
531         OSL_ENSURE( sal_False, "### unexpected exception caught!" );
532         throw;
533     }
534 
535     if (! bImplementedMethod)
536     {
537         throw IllegalArgumentException(
538             OUString( RTL_CONSTASCII_USTRINGPARAM("not an implemented method!") ),
539             (OWeakObject *)this, 0 );
540     }
541 
542     return aRet;
543 }
544 //__________________________________________________________________________________________________
setValue(const OUString & rName,const Any & rValue)545 void XLB_Invocation::setValue( const OUString & rName, const Any & rValue )
546 {
547     if (rName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("Bool") ))
548         _xLBT->setBool( *(const sal_Bool *)rValue.getValue() );
549     else if (rName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("Byte") ))
550         _xLBT->setByte( *(const sal_Int8 *)rValue.getValue() );
551     else if (rName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("Char") ))
552         _xLBT->setChar( *(const sal_Unicode *)rValue.getValue() );
553     else if (rName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("Short") ))
554         _xLBT->setShort( *(const sal_Int16 *)rValue.getValue() );
555     else if (rName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("UShort") ))
556         _xLBT->setUShort( *(const sal_uInt16 *)rValue.getValue() );
557     else if (rName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("Long") ))
558         _xLBT->setLong( *(const sal_Int32 *)rValue.getValue() );
559     else if (rName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("ULong") ))
560         _xLBT->setULong( *(const sal_uInt32 *)rValue.getValue() );
561     else if (rName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("Hyper") ))
562         _xLBT->setHyper( *(const sal_Int64 *)rValue.getValue() );
563     else if (rName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("UHyper") ))
564         _xLBT->setUHyper( *(const sal_uInt64 *)rValue.getValue() );
565     else if (rName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("Float") ))
566         _xLBT->setFloat( *(const float *)rValue.getValue() );
567     else if (rName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("Double") ))
568         _xLBT->setDouble( *(const double *)rValue.getValue() );
569     else if (rName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("Enum") ))
570         _xLBT->setEnum( *(const TestEnum *)rValue.getValue() );
571     else if (rName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("String") ))
572         _xLBT->setString( *(const OUString *)rValue.getValue() );
573     else if (rName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("Interface") ))
574         _xLBT->setInterface( *(const Reference< XInterface > *)rValue.getValue() );
575     else if (rName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("Any") ))
576         _xLBT->setAny( rValue );
577     else if (rName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("Sequence") ))
578         _xLBT->setSequence( *(const Sequence< TestElement > *)rValue.getValue() );
579     else if (rName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("Struct") ))
580         _xLBT->setStruct( *(const TestData *)rValue.getValue() );
581     else if (rName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("RuntimeException") ))
582         _xLBT->setRuntimeException( *(const sal_Int32 *)rValue.getValue() );
583 }
584 //__________________________________________________________________________________________________
getValue(const OUString & rName)585 Any XLB_Invocation::getValue( const OUString & rName )
586 {
587     Any aRet;
588     if (rName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("Bool") ))
589     {
590         sal_Bool aBool = _xLBT->getBool();
591         aRet.setValue( &aBool, ::getCppuBooleanType() );
592     }
593     else if (rName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("Byte") ))
594         aRet <<= _xLBT->getByte();
595     else if (rName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("Char") ))
596     {
597         sal_Unicode aChar = _xLBT->getChar();
598         aRet.setValue( &aChar, ::getCppuCharType() );
599     }
600     else if (rName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("Short") ))
601         aRet <<= _xLBT->getShort();
602     else if (rName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("UShort") ))
603         aRet <<= _xLBT->getUShort();
604     else if (rName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("Long") ))
605         aRet <<= _xLBT->getLong();
606     else if (rName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("ULong") ))
607         aRet <<= _xLBT->getULong();
608     else if (rName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("Hyper") ))
609         aRet <<= _xLBT->getHyper();
610     else if (rName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("UHyper") ))
611         aRet <<= _xLBT->getUHyper();
612     else if (rName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("Float") ))
613         aRet <<= _xLBT->getFloat();
614     else if (rName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("Double") ))
615         aRet <<= _xLBT->getDouble();
616     else if (rName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("Enum") ))
617         aRet <<= _xLBT->getEnum();
618     else if (rName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("String") ))
619         aRet <<= _xLBT->getString();
620     else if (rName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("Interface") ))
621         aRet <<= _xLBT->getInterface();
622     else if (rName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("Any") ))
623         aRet <<= _xLBT->getAny();
624     else if (rName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("Sequence") ))
625         aRet <<= _xLBT->getSequence();
626     else if (rName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("Struct") ))
627         aRet <<= _xLBT->getStruct();
628     else if (rName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("RuntimeException") ))
629         aRet <<= _xLBT->getRuntimeException();
630     return aRet;
631 }
632 //__________________________________________________________________________________________________
hasMethod(const OUString & rName)633 sal_Bool XLB_Invocation::hasMethod( const OUString & rName )
634 {
635     return (rName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("raiseException") ) ||
636             rName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("getValues") ) ||
637             rName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("setValues2") ) ||
638             rName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("setValues") ) ||
639             rName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("acquire") ) ||
640             rName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("release") ) ||
641             rName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("queryInterface") ));
642 }
643 //__________________________________________________________________________________________________
hasProperty(const OUString & rName)644 sal_Bool XLB_Invocation::hasProperty( const OUString & rName )
645 {
646     return (rName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("Bool") ) ||
647             rName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("Byte") ) ||
648             rName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("Char") ) ||
649             rName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("Short") ) ||
650             rName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("UShort") ) ||
651             rName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("Long") ) ||
652             rName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("ULong") ) ||
653             rName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("Hyper") ) ||
654             rName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("UHyper") ) ||
655             rName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("Float") ) ||
656             rName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("Double") ) ||
657             rName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("Enum") ) ||
658             rName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("String") ) ||
659             rName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("Interface") ) ||
660             rName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("Any") ) ||
661             rName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("Sequence") ) ||
662             rName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("Struct") ) ||
663             rName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("RuntimeException") ) );
664 }
665 
666 //##################################################################################################
667 
668 //__________________________________________________________________________________________________
setValues(sal_Bool bBool,sal_Unicode cChar,sal_Int8 nByte,sal_Int16 nShort,sal_uInt16 nUShort,sal_Int32 nLong,sal_uInt32 nULong,sal_Int64 nHyper,sal_uInt64 nUHyper,float fFloat,double fDouble,test::TestEnum eEnum,const::rtl::OUString & rStr,const::com::sun::star::uno::Reference<::com::sun::star::uno::XInterface> & xTest,const::com::sun::star::uno::Any & rAny,const::com::sun::star::uno::Sequence<test::TestElement> & rSequence,const test::TestData & rStruct)669 void Test_Impl::setValues( sal_Bool bBool, sal_Unicode cChar, sal_Int8 nByte,
670                            sal_Int16 nShort, sal_uInt16 nUShort,
671                            sal_Int32 nLong, sal_uInt32 nULong,
672                            sal_Int64 nHyper, sal_uInt64 nUHyper,
673                            float fFloat, double fDouble,
674                            test::TestEnum eEnum, const ::rtl::OUString& rStr,
675                            const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& xTest,
676                            const ::com::sun::star::uno::Any& rAny,
677                            const ::com::sun::star::uno::Sequence<test::TestElement >& rSequence,
678                            const test::TestData& rStruct )
679 {
680     assign( _aData,
681             bBool, cChar, nByte, nShort, nUShort, nLong, nULong, nHyper, nUHyper, fFloat, fDouble,
682             eEnum, rStr, xTest, rAny, rSequence );
683     _aStructData = rStruct;
684 }
685 //__________________________________________________________________________________________________
setValues2(sal_Bool & bBool,sal_Unicode & cChar,sal_Int8 & nByte,sal_Int16 & nShort,sal_uInt16 & nUShort,sal_Int32 & nLong,sal_uInt32 & nULong,sal_Int64 & nHyper,sal_uInt64 & nUHyper,float & fFloat,double & fDouble,test::TestEnum & eEnum,rtl::OUString & rStr,::com::sun::star::uno::Reference<::com::sun::star::uno::XInterface> & xTest,::com::sun::star::uno::Any & rAny,::com::sun::star::uno::Sequence<test::TestElement> & rSequence,test::TestData & rStruct)686 test::TestData Test_Impl::setValues2( sal_Bool& bBool, sal_Unicode& cChar, sal_Int8& nByte,
687                                       sal_Int16& nShort, sal_uInt16& nUShort,
688                                       sal_Int32& nLong, sal_uInt32& nULong,
689                                       sal_Int64& nHyper, sal_uInt64& nUHyper,
690                                       float& fFloat, double& fDouble,
691                                       test::TestEnum& eEnum, rtl::OUString& rStr,
692                                       ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& xTest,
693                                       ::com::sun::star::uno::Any& rAny,
694                                       ::com::sun::star::uno::Sequence<test::TestElement >& rSequence,
695                                       test::TestData& rStruct )
696 {
697     assign( _aData,
698             bBool, cChar, nByte, nShort, nUShort, nLong, nULong, nHyper, nUHyper, fFloat, fDouble,
699             eEnum, rStr, xTest, rAny, rSequence );
700     _aStructData = rStruct;
701     return _aStructData;
702 }
703 //__________________________________________________________________________________________________
getValues(sal_Bool & bBool,sal_Unicode & cChar,sal_Int8 & nByte,sal_Int16 & nShort,sal_uInt16 & nUShort,sal_Int32 & nLong,sal_uInt32 & nULong,sal_Int64 & nHyper,sal_uInt64 & nUHyper,float & fFloat,double & fDouble,test::TestEnum & eEnum,rtl::OUString & rStr,::com::sun::star::uno::Reference<::com::sun::star::uno::XInterface> & xTest,::com::sun::star::uno::Any & rAny,::com::sun::star::uno::Sequence<test::TestElement> & rSequence,test::TestData & rStruct)704 test::TestData Test_Impl::getValues( sal_Bool& bBool, sal_Unicode& cChar, sal_Int8& nByte,
705                                      sal_Int16& nShort, sal_uInt16& nUShort,
706                                      sal_Int32& nLong, sal_uInt32& nULong,
707                                      sal_Int64& nHyper, sal_uInt64& nUHyper,
708                                      float& fFloat, double& fDouble,
709                                      test::TestEnum& eEnum, rtl::OUString& rStr,
710                                      ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& xTest,
711                                      ::com::sun::star::uno::Any& rAny,
712                                      ::com::sun::star::uno::Sequence<test::TestElement >& rSequence,
713                                      test::TestData& rStruct )
714 {
715      bBool = _aData.Bool;
716      cChar = _aData.Char;
717      nByte = _aData.Byte;
718      nShort = _aData.Short;
719      nUShort = _aData.UShort;
720      nLong = _aData.Long;
721      nULong = _aData.ULong;
722      nHyper = _aData.Hyper;
723      nUHyper = _aData.UHyper;
724      fFloat = _aData.Float;
725      fDouble = _aData.Double;
726      eEnum = _aData.Enum;
727      rStr = _aData.String;
728      xTest = _aData.Interface;
729      rAny = _aData.Any;
730      rSequence = _aData.Sequence;
731      rStruct = _aStructData;
732      return _aStructData;
733 }
734 
735 //==================================================================================================
performTest(const Reference<XLanguageBindingTest> & xLBT)736 sal_Bool performTest( const Reference<XLanguageBindingTest > & xLBT )
737 {
738     OSL_ENSURE( xLBT.is(), "### no test interface!" );
739     if (xLBT.is())
740     {
741         // this data is never ever granted access to by calls other than equals(), assign()!
742         test::TestData aData; // test against this data
743 
744         Reference<XInterface > xI( *new OWeakObject() );
745 
746         assign( (test::TestElement &)aData,
747                 sal_True, '@', 17, 0x1234, 0xfedc, 0x12345678, 0xfedcba98,
748                 SAL_CONST_INT64(0x123456789abcdef0),
749                 SAL_CONST_UINT64(0xfedcba9876543210),
750                 (float)17.0815, 3.1415926359, TestEnum_LOLA, OUString::createFromAscii("dumdidum"), xI,
751                 Any( &xI, ::getCppuType( (const Reference<XInterface > *)0 ) ) );
752 
753         OSL_ENSURE( aData.Any == xI, "### unexpected any!" );
754         OSL_ENSURE( !(aData.Any != xI), "### unexpected any!" );
755 
756         aData.Sequence = Sequence<test::TestElement >( (const test::TestElement *)&aData, 1 );
757         // aData complete
758         //================================================================================
759 
760         // this is a manually copy of aData for first setting...
761         test::TestData aSetData;
762 
763         assign( (test::TestElement &)aSetData,
764                 aData.Bool, aData.Char, aData.Byte, aData.Short, aData.UShort,
765                 aData.Long, aData.ULong, aData.Hyper, aData.UHyper, aData.Float, aData.Double,
766                 aData.Enum, aData.String, xI,
767                 Any( &xI, ::getCppuType( (const Reference<XInterface > *)0 ) ) );
768 
769         aSetData.Sequence = Sequence<test::TestElement >( (const test::TestElement *)&aSetData, 1 );
770 
771         xLBT->setValues(
772             aSetData.Bool, aSetData.Char, aSetData.Byte, aSetData.Short, aSetData.UShort,
773             aSetData.Long, aSetData.ULong, aSetData.Hyper, aSetData.UHyper, aSetData.Float, aSetData.Double,
774             aSetData.Enum, aSetData.String, aSetData.Interface, aSetData.Any, aSetData.Sequence, aSetData );
775 
776         {
777         test::TestData aRet, aRet2;
778         xLBT->getValues(
779             aRet.Bool, aRet.Char, aRet.Byte, aRet.Short, aRet.UShort,
780             aRet.Long, aRet.ULong, aRet.Hyper, aRet.UHyper, aRet.Float, aRet.Double,
781             aRet.Enum, aRet.String, aRet.Interface, aRet.Any, aRet.Sequence, aRet2 );
782 
783         OSL_ASSERT( equals( aData, aRet ) && equals( aData, aRet2 ) );
784 
785         // set last retrieved values
786         test::TestData aSV2ret = xLBT->setValues2(
787             aRet.Bool, aRet.Char, aRet.Byte, aRet.Short, aRet.UShort,
788             aRet.Long, aRet.ULong, aRet.Hyper, aRet.UHyper, aRet.Float, aRet.Double,
789             aRet.Enum, aRet.String, aRet.Interface, aRet.Any, aRet.Sequence, aRet2 );
790 
791         OSL_ASSERT( equals( aData, aSV2ret ) && equals( aData, aRet2 ) );
792         }
793         {
794         test::TestData aRet, aRet2;
795         test::TestData aGVret = xLBT->getValues(
796             aRet.Bool, aRet.Char, aRet.Byte, aRet.Short, aRet.UShort,
797             aRet.Long, aRet.ULong, aRet.Hyper, aRet.UHyper, aRet.Float, aRet.Double,
798             aRet.Enum, aRet.String, aRet.Interface, aRet.Any, aRet.Sequence, aRet2 );
799 
800         OSL_ASSERT( equals( aData, aRet ) && equals( aData, aRet2 ) && equals( aData, aGVret ) );
801 
802         // set last retrieved values
803         xLBT->setBool( aRet.Bool );
804         xLBT->setChar( aRet.Char );
805         xLBT->setByte( aRet.Byte );
806         xLBT->setShort( aRet.Short );
807         xLBT->setUShort( aRet.UShort );
808         xLBT->setLong( aRet.Long );
809         xLBT->setULong( aRet.ULong );
810         xLBT->setHyper( aRet.Hyper );
811         xLBT->setUHyper( aRet.UHyper );
812         xLBT->setFloat( aRet.Float );
813         xLBT->setDouble( aRet.Double );
814         xLBT->setEnum( aRet.Enum );
815         xLBT->setString( aRet.String );
816         xLBT->setInterface( aRet.Interface );
817         xLBT->setAny( aRet.Any );
818         xLBT->setSequence( aRet.Sequence );
819         xLBT->setStruct( aRet2 );
820         }
821         {
822         test::TestData aRet, aRet2;
823         aRet.Hyper = xLBT->getHyper();
824         aRet.UHyper = xLBT->getUHyper();
825         aRet.Float = xLBT->getFloat();
826         aRet.Double = xLBT->getDouble();
827         aRet.Byte = xLBT->getByte();
828         aRet.Char = xLBT->getChar();
829         aRet.Bool = xLBT->getBool();
830         aRet.Short = xLBT->getShort();
831         aRet.UShort = xLBT->getUShort();
832         aRet.Long = xLBT->getLong();
833         aRet.ULong = xLBT->getULong();
834         aRet.Enum = xLBT->getEnum();
835         aRet.String = xLBT->getString();
836         aRet.Interface = xLBT->getInterface();
837         aRet.Any = xLBT->getAny();
838         aRet.Sequence = xLBT->getSequence();
839         aRet2 = xLBT->getStruct();
840 
841         return (equals( aData, aRet ) && equals( aData, aRet2 ));
842         }
843     }
844     return sal_False;
845 }
846 
847 //__________________________________________________________________________________________________
raiseException(sal_Bool &,sal_Unicode &,sal_Int8 &,sal_Int16 &,sal_uInt16 &,sal_Int32 &,sal_uInt32 &,sal_Int64 &,sal_uInt64 &,float &,double &,test::TestEnum &,::rtl::OUString &,::com::sun::star::uno::Reference<::com::sun::star::uno::XInterface> &,::com::sun::star::uno::Any &,::com::sun::star::uno::Sequence<test::TestElement> &,test::TestData &)848 test::TestData Test_Impl::raiseException( 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*/, test::TestEnum& /*eEnum*/, ::rtl::OUString& /*aString*/, ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& /*xInterface*/, ::com::sun::star::uno::Any& /*aAny*/, ::com::sun::star::uno::Sequence< test::TestElement >& /*aSequence*/, test::TestData& /*aStruct*/ )
849 {
850     IllegalArgumentException aExc;
851     aExc.ArgumentPosition = 5;
852     aExc.Message          = OUString::createFromAscii("dum dum dum ich tanz im kreis herum...");
853     aExc.Context          = *this;
854     throw aExc;
855 }
856 //__________________________________________________________________________________________________
getRuntimeException()857 sal_Int32 Test_Impl::getRuntimeException()
858 {
859     RuntimeException aExc;
860     aExc.Message          = OUString::createFromAscii("dum dum dum ich tanz im kreis herum...");
861     aExc.Context          = *this;
862     throw aExc;
863 }
864 //__________________________________________________________________________________________________
setRuntimeException(sal_Int32)865 void Test_Impl::setRuntimeException( sal_Int32 /*_runtimeexception*/ )
866 {
867     RuntimeException aExc;
868     aExc.Message          = OUString::createFromAscii("dum dum dum ich tanz im kreis herum...");
869     aExc.Context          = *this;
870     throw aExc;
871 }
872 
873 //==================================================================================================
raiseException(const Reference<XLanguageBindingTest> & xLBT)874 sal_Bool raiseException( const Reference<XLanguageBindingTest > & xLBT )
875 {
876     try
877     {
878         try
879         {
880             try
881             {
882                 test::TestData aRet, aRet2;
883                 xLBT->raiseException(
884                     aRet.Bool, aRet.Char, aRet.Byte, aRet.Short, aRet.UShort,
885                     aRet.Long, aRet.ULong, aRet.Hyper, aRet.UHyper, aRet.Float, aRet.Double,
886                     aRet.Enum, aRet.String, aRet.Interface, aRet.Any, aRet.Sequence, aRet2 );
887                 return sal_False;
888             }
889             catch (IllegalArgumentException aExc)
890             {
891                 OSL_ENSURE( aExc.ArgumentPosition == 5 &&
892 //                               aExc.Context == xLBT &&
893                              aExc.Message.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("dum dum dum ich tanz im kreis herum...")),
894                              "### unexpected exception content!" );
895 
896                 Reference<XLanguageBindingTest > xLBT2(
897                     Reference<XLanguageBindingTest >::query( aExc.Context ) );
898 
899                 OSL_ENSURE( xLBT2.is(), "### unexpected source of exception!" );
900                 if (xLBT2.is())
901                     xLBT2->getRuntimeException();
902                 else
903                     return sal_False;
904             }
905         }
906         catch (const RuntimeException & rExc)
907         {
908             OSL_ENSURE(//rExc.Context == xLBT &&
909                         rExc.Message.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("dum dum dum ich tanz im kreis herum...")),
910                         "### unexpected exception content!" );
911 
912             Reference<XLanguageBindingTest > xLBT2(
913                 Reference<XLanguageBindingTest >::query( rExc.Context ) );
914 
915             OSL_ENSURE( xLBT2.is(), "### unexpected source of exception!" );
916             if (xLBT2.is())
917                 xLBT2->setRuntimeException( 0xcafebabe );
918             else
919                 return sal_False;
920         }
921     }
922     catch (Exception & aExc)
923     {
924         OSL_ENSURE( //aExc.Context == xLBT &&
925                      aExc.Message.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("dum dum dum ich tanz im kreis herum...")),
926                      "### unexpected exception content!" );
927         return (//aExc.Context == xLBT &&
928                 aExc.Message.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("dum dum dum ich tanz im kreis herum...")));
929     }
930     return sal_False;
931 }
932 
933 //==================================================================================================
test_adapter(const Reference<XMultiServiceFactory> & xMgr)934 static sal_Bool test_adapter( const Reference< XMultiServiceFactory > & xMgr )
935 {
936     Reference< XInvocationAdapterFactory > xAdapFac(
937         xMgr->createInstance( OUString::createFromAscii("com.sun.star.script.InvocationAdapterFactory") ), UNO_QUERY );
938     Reference< XInvocationAdapterFactory2 > xAdapFac2( xAdapFac, UNO_QUERY_THROW );
939 
940     Reference< XLanguageBindingTest > xOriginal( (XLanguageBindingTest *)new Test_Impl() );
941     Reference< XInvocation > xInvok( new XLB_Invocation( xMgr, xOriginal ) );
942     Reference< XLanguageBindingTest > xLBT( xAdapFac->createAdapter(
943         xInvok, ::getCppuType( (const Reference< XLanguageBindingTest > *)0 ) ), UNO_QUERY );
944     Reference< XLanguageBindingTest > xLBT2(
945         xAdapFac->createAdapter(
946             xInvok, ::getCppuType( (const Reference< XLanguageBindingTest > *)0 ) ), UNO_QUERY );
947     if (xLBT != xLBT2)
948         return sal_False;
949     Reference< XInterface > xLBT3(
950         xAdapFac->createAdapter(
951             xInvok, ::getCppuType( (const Reference< XInterface > *)0 ) ), UNO_QUERY );
952     if (xLBT != xLBT3)
953         return sal_False;
954     Type ar[ 2 ] = {
955         ::getCppuType( (const Reference< XLBTestBase > *)0 ),
956         ::getCppuType( (const Reference< XInterface > *)0 ) };
957     Reference< XInterface > xLBT4(
958         xAdapFac2->createAdapter( xInvok, Sequence< Type >( ar, 2 ) ), UNO_QUERY );
959     if (xLBT != xLBT4)
960         return sal_False;
961     Reference< XSimpleRegistry > xInvalidAdapter(
962         xAdapFac->createAdapter(
963             xInvok, ::getCppuType( (const Reference< XSimpleRegistry > *)0 ) ), UNO_QUERY );
964     if (xLBT == xInvalidAdapter)
965         return sal_False;
966 
967     try
968     {
969         xInvalidAdapter->isValid();
970         return sal_False;
971     }
972     catch (RuntimeException &)
973     {
974     }
975 
976     return (performTest( xLBT ) && raiseException( xLBT ));
977 }
978 //==================================================================================================
test_invocation(const Reference<XMultiServiceFactory> & xMgr)979 static sal_Bool test_invocation( const Reference< XMultiServiceFactory > & xMgr )
980 {
981     Reference< XInvocationAdapterFactory > xAdapFac(
982         xMgr->createInstance( OUString::createFromAscii("com.sun.star.script.InvocationAdapterFactory") ), UNO_QUERY );
983     Reference< XSingleServiceFactory > xInvocFac(
984         xMgr->createInstance( OUString::createFromAscii("com.sun.star.script.Invocation") ), UNO_QUERY );
985 
986     Reference< XLanguageBindingTest > xOriginal( (XLanguageBindingTest *)new Test_Impl() );
987     Any aOriginal( &xOriginal, ::getCppuType( &xOriginal ) );
988     Reference< XInvocation > xInvok(
989         xInvocFac->createInstanceWithArguments( Sequence< Any >( &aOriginal, 1 ) ), UNO_REF_QUERY );
990 
991     Reference< XLanguageBindingTest > xLBT( xAdapFac->createAdapter(
992         xInvok, ::getCppuType( (const Reference< XLanguageBindingTest > *)0 ) ), UNO_QUERY );
993 
994     return (performTest( xLBT ) && raiseException( xLBT ));
995 }
996 
SAL_IMPLEMENT_MAIN()997 SAL_IMPLEMENT_MAIN()
998 {
999     Reference< XMultiServiceFactory > xMgr( createRegistryServiceFactory(
1000         OUString( RTL_CONSTASCII_USTRINGPARAM("stoctest.rdb") ) ) );
1001 
1002     try
1003     {
1004         Reference< XImplementationRegistration > xImplReg(
1005             xMgr->createInstance(
1006                 OUString(
1007                     RTL_CONSTASCII_USTRINGPARAM(
1008                         "com.sun.star.registry.ImplementationRegistration") ) ),
1009             UNO_QUERY );
1010         OSL_ENSURE( xImplReg.is(), "### no impl reg!" );
1011 
1012         xImplReg->registerImplementation(
1013             OUString::createFromAscii("com.sun.star.loader.SharedLibrary"),
1014             OUString::createFromAscii("invocadapt.uno" SAL_DLLEXTENSION),
1015             Reference< XSimpleRegistry >() );
1016         xImplReg->registerImplementation(
1017             OUString::createFromAscii("com.sun.star.loader.SharedLibrary"),
1018             OUString::createFromAscii("stocservices.uno" SAL_DLLEXTENSION),
1019             Reference< XSimpleRegistry >() );
1020         xImplReg->registerImplementation(
1021             OUString::createFromAscii("com.sun.star.loader.SharedLibrary"),
1022             OUString::createFromAscii("invocation.uno" SAL_DLLEXTENSION),
1023             Reference< XSimpleRegistry >() );
1024         xImplReg->registerImplementation(
1025             OUString::createFromAscii("com.sun.star.loader.SharedLibrary"),
1026             OUString::createFromAscii("reflection.uno" SAL_DLLEXTENSION),
1027             Reference< XSimpleRegistry >() );
1028         xImplReg->registerImplementation(
1029             OUString::createFromAscii("com.sun.star.loader.SharedLibrary"),
1030             OUString::createFromAscii("introspection.uno" SAL_DLLEXTENSION),
1031             Reference< XSimpleRegistry >() );
1032 
1033         if (test_adapter( xMgr ))
1034         {
1035             fprintf( stderr, "> test_iadapter() succeeded.\n" );
1036             if (test_invocation( xMgr ))
1037             {
1038                 fprintf( stderr, "> test_invocation() succeeded.\n" );
1039             }
1040         }
1041     }
1042     catch (Exception & rExc)
1043     {
1044         fprintf( stderr, "> exception occurred: " );
1045         OString aMsg( OUStringToOString( rExc.Message, RTL_TEXTENCODING_ASCII_US ) );
1046         fprintf( stderr, "%s\n", aMsg.getStr() );
1047     }
1048 
1049     Reference< XComponent >( xMgr, UNO_QUERY )->dispose();
1050 
1051     return 0;
1052 }
1053