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