Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / stoc / test / testiadapter.cxx
blobca5afc4029f477f0086131012ec81cda32d29aed
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include <stdio.h>
23 #include <sal/main.h>
24 #include <sal/log.hxx>
25 #include <osl/diagnose.h>
27 #include <cppuhelper/servicefactory.hxx>
28 #include <cppuhelper/weak.hxx>
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>
39 #include <cppuhelper/implbase.hxx>
40 #include <cmath>
43 using namespace test;
44 using namespace cppu;
45 using namespace osl;
46 using namespace css::uno;
47 using namespace css::script;
48 using namespace css::beans;
49 using namespace css::lang;
50 using namespace css::reflection;
51 using namespace css::registry;
54 sal_Bool equals( const test::TestElement & rData1, const test::TestElement & rData2 )
56 OSL_ENSURE( rData1.Bool == rData2.Bool, "### bool does not match!" );
57 OSL_ENSURE( rData1.Char == rData2.Char, "### char does not match!" );
58 OSL_ENSURE( rData1.Byte == rData2.Byte, "### byte does not match!" );
59 OSL_ENSURE( rData1.Short == rData2.Short, "### short does not match!" );
60 OSL_ENSURE( rData1.UShort == rData2.UShort, "### unsigned short does not match!" );
61 OSL_ENSURE( rData1.Long == rData2.Long, "### long does not match!" );
62 OSL_ENSURE( rData1.ULong == rData2.ULong, "### unsigned long does not match!" );
63 OSL_ENSURE( rData1.Hyper == rData2.Hyper, "### hyper does not match!" );
64 OSL_ENSURE( rData1.UHyper == rData2.UHyper, "### unsigned hyper does not match!" );
65 OSL_ENSURE( rData1.Float == rData2.Float, "### float does not match!" );
66 OSL_ENSURE( rData1.Double == rData2.Double, "### double does not match!" );
67 OSL_ENSURE( rData1.Enum == rData2.Enum, "### enum does not match!" );
68 OSL_ENSURE( rData1.String == rData2.String, "### string does not match!" );
69 OSL_ENSURE( rData1.Interface == rData2.Interface, "### interface does not match!" );
70 OSL_ENSURE( rData1.Any == rData2.Any, "### any does not match!" );
72 return (rData1.Bool == rData2.Bool &&
73 rData1.Char == rData2.Char &&
74 rData1.Byte == rData2.Byte &&
75 rData1.Short == rData2.Short &&
76 rData1.UShort == rData2.UShort &&
77 rData1.Long == rData2.Long &&
78 rData1.ULong == rData2.ULong &&
79 rData1.Hyper == rData2.Hyper &&
80 rData1.UHyper == rData2.UHyper &&
81 rData1.Float == rData2.Float &&
82 rData1.Double == rData2.Double &&
83 rData1.Enum == rData2.Enum &&
84 rData1.String == rData2.String &&
85 rData1.Interface == rData2.Interface &&
86 rData1.Any == rData2.Any);
89 sal_Bool equals( const test::TestData & rData1, const test::TestData & rData2 )
91 sal_Int32 nLen;
93 if ((rData1.Sequence == rData2.Sequence) &&
94 equals( (const test::TestElement &)rData1, (const test::TestElement &)rData2 ) &&
95 (nLen = rData1.Sequence.getLength()) == rData2.Sequence.getLength())
97 // once again by hand sequence ==
98 const test::TestElement * pElements1 = rData1.Sequence.getConstArray();
99 const test::TestElement * pElements2 = rData2.Sequence.getConstArray();
100 for ( ; nLen--; )
102 if (! equals( pElements1[nLen], pElements2[nLen] ))
104 OSL_FAIL( "### sequence element did not match!" );
105 return sal_False;
108 return sal_True;
110 return sal_False;
113 void assign( test::TestElement & rData,
114 sal_Bool bBool, sal_Unicode cChar, sal_Int8 nByte,
115 sal_Int16 nShort, sal_uInt16 nUShort,
116 sal_Int32 nLong, sal_uInt32 nULong,
117 sal_Int64 nHyper, sal_uInt64 nUHyper,
118 float fFloat, double fDouble,
119 test::TestEnum eEnum, const OUString& rStr,
120 const css::uno::Reference< css::uno::XInterface >& xTest,
121 const css::uno::Any& rAny )
123 rData.Bool = bBool;
124 rData.Char = cChar;
125 rData.Byte = nByte;
126 rData.Short = nShort;
127 rData.UShort = nUShort;
128 rData.Long = nLong;
129 rData.ULong = nULong;
130 rData.Hyper = nHyper;
131 rData.UHyper = nUHyper;
132 rData.Float = fFloat;
133 rData.Double = fDouble;
134 rData.Enum = eEnum;
135 rData.String = rStr;
136 rData.Interface = xTest;
137 rData.Any = rAny;
140 void assign( test::TestData & rData,
141 sal_Bool bBool, sal_Unicode cChar, sal_Int8 nByte,
142 sal_Int16 nShort, sal_uInt16 nUShort,
143 sal_Int32 nLong, sal_uInt32 nULong,
144 sal_Int64 nHyper, sal_uInt64 nUHyper,
145 float fFloat, double fDouble,
146 test::TestEnum eEnum, const OUString& rStr,
147 const css::uno::Reference< css::uno::XInterface >& xTest,
148 const css::uno::Any& rAny,
149 const css::uno::Sequence< test::TestElement >& rSequence )
151 assign( (test::TestElement &)rData,
152 bBool, cChar, nByte, nShort, nUShort, nLong, nULong, nHyper, nUHyper, fFloat, fDouble,
153 eEnum, rStr, xTest, rAny );
154 rData.Sequence = rSequence;
158 class Test_Impl : public WeakImplHelper< XLanguageBindingTest >
160 test::TestData _aData, _aStructData;
162 public:
163 virtual ~Test_Impl()
164 { SAL_INFO("stoc", "> scalar Test_Impl dtor <" ); }
166 // XLBTestBase
167 virtual void SAL_CALL setValues( sal_Bool bBool, sal_Unicode cChar, sal_Int8 nByte,
168 sal_Int16 nShort, sal_uInt16 nUShort,
169 sal_Int32 nLong, sal_uInt32 nULong,
170 sal_Int64 nHyper, sal_uInt64 nUHyper,
171 float fFloat, double fDouble,
172 test::TestEnum eEnum, const OUString& rStr,
173 const css::uno::Reference< css::uno::XInterface >& xTest,
174 const css::uno::Any& rAny,
175 const css::uno::Sequence<test::TestElement >& rSequence,
176 const test::TestData& rStruct )
177 throw(css::uno::RuntimeException);
179 virtual test::TestData SAL_CALL setValues2( sal_Bool& bBool, sal_Unicode& cChar, sal_Int8& nByte,
180 sal_Int16& nShort, sal_uInt16& nUShort,
181 sal_Int32& nLong, sal_uInt32& nULong,
182 sal_Int64& nHyper, sal_uInt64& nUHyper,
183 float& fFloat, double& fDouble,
184 test::TestEnum& eEnum, OUString& rStr,
185 css::uno::Reference< css::uno::XInterface >& xTest,
186 css::uno::Any& rAny,
187 css::uno::Sequence<test::TestElement >& rSequence,
188 test::TestData& rStruct )
189 throw(css::uno::RuntimeException);
191 virtual test::TestData SAL_CALL getValues( sal_Bool& bBool, sal_Unicode& cChar, sal_Int8& nByte,
192 sal_Int16& nShort, sal_uInt16& nUShort,
193 sal_Int32& nLong, sal_uInt32& nULong,
194 sal_Int64& nHyper, sal_uInt64& nUHyper,
195 float& fFloat, double& fDouble,
196 test::TestEnum& eEnum, OUString& rStr,
197 css::uno::Reference< css::uno::XInterface >& xTest,
198 css::uno::Any& rAny,
199 css::uno::Sequence< test::TestElement >& rSequence,
200 test::TestData& rStruct )
201 throw(css::uno::RuntimeException);
203 virtual sal_Bool SAL_CALL getBool() throw(css::uno::RuntimeException)
204 { return _aData.Bool; }
205 virtual sal_Int8 SAL_CALL getByte() throw(css::uno::RuntimeException)
206 { return _aData.Byte; }
207 virtual sal_Unicode SAL_CALL getChar() throw(css::uno::RuntimeException)
208 { return _aData.Char; }
209 virtual sal_Int16 SAL_CALL getShort() throw(css::uno::RuntimeException)
210 { return _aData.Short; }
211 virtual sal_uInt16 SAL_CALL getUShort() throw(css::uno::RuntimeException)
212 { return _aData.UShort; }
213 virtual sal_Int32 SAL_CALL getLong() throw(css::uno::RuntimeException)
214 { return _aData.Long; }
215 virtual sal_uInt32 SAL_CALL getULong() throw(css::uno::RuntimeException)
216 { return _aData.ULong; }
217 virtual sal_Int64 SAL_CALL getHyper() throw(css::uno::RuntimeException)
218 { return _aData.Hyper; }
219 virtual sal_uInt64 SAL_CALL getUHyper() throw(css::uno::RuntimeException)
220 { return _aData.UHyper; }
221 virtual float SAL_CALL getFloat() throw(css::uno::RuntimeException)
222 { return _aData.Float; }
223 virtual double SAL_CALL getDouble() throw(css::uno::RuntimeException)
224 { return _aData.Double; }
225 virtual test::TestEnum SAL_CALL getEnum() throw(css::uno::RuntimeException)
226 { return _aData.Enum; }
227 virtual OUString SAL_CALL getString() throw(css::uno::RuntimeException)
228 { return _aData.String; }
229 virtual css::uno::Reference< css::uno::XInterface > SAL_CALL getInterface( ) throw(css::uno::RuntimeException)
230 { return _aData.Interface; }
231 virtual css::uno::Any SAL_CALL getAny() throw(css::uno::RuntimeException)
232 { return _aData.Any; }
233 virtual css::uno::Sequence< test::TestElement > SAL_CALL getSequence() throw(css::uno::RuntimeException)
234 { return _aData.Sequence; }
235 virtual test::TestData SAL_CALL getStruct() throw(css::uno::RuntimeException)
236 { return _aStructData; }
238 virtual void SAL_CALL setBool( sal_Bool _bool ) throw(css::uno::RuntimeException)
239 { _aData.Bool = _bool; }
240 virtual void SAL_CALL setByte( sal_Int8 _byte ) throw(css::uno::RuntimeException)
241 { _aData.Byte = _byte; }
242 virtual void SAL_CALL setChar( sal_Unicode _char ) throw(css::uno::RuntimeException)
243 { _aData.Char = _char; }
244 virtual void SAL_CALL setShort( sal_Int16 _short ) throw(css::uno::RuntimeException)
245 { _aData.Short = _short; }
246 virtual void SAL_CALL setUShort( sal_uInt16 _ushort ) throw(css::uno::RuntimeException)
247 { _aData.UShort = _ushort; }
248 virtual void SAL_CALL setLong( sal_Int32 _long ) throw(css::uno::RuntimeException)
249 { _aData.Long = _long; }
250 virtual void SAL_CALL setULong( sal_uInt32 _ulong ) throw(css::uno::RuntimeException)
251 { _aData.ULong = _ulong; }
252 virtual void SAL_CALL setHyper( sal_Int64 _hyper ) throw(css::uno::RuntimeException)
253 { _aData.Hyper = _hyper; }
254 virtual void SAL_CALL setUHyper( sal_uInt64 _uhyper ) throw(css::uno::RuntimeException)
255 { _aData.UHyper = _uhyper; }
256 virtual void SAL_CALL setFloat( float _float ) throw(css::uno::RuntimeException)
257 { _aData.Float = _float; }
258 virtual void SAL_CALL setDouble( double _double ) throw(css::uno::RuntimeException)
259 { _aData.Double = _double; }
260 virtual void SAL_CALL setEnum( test::TestEnum _enum ) throw(css::uno::RuntimeException)
261 { _aData.Enum = _enum; }
262 virtual void SAL_CALL setString( const OUString& _string ) throw(css::uno::RuntimeException)
263 { _aData.String = _string; }
264 virtual void SAL_CALL setInterface( const css::uno::Reference< css::uno::XInterface >& _interface ) throw(css::uno::RuntimeException)
265 { _aData.Interface = _interface; }
266 virtual void SAL_CALL setAny( const css::uno::Any& _any ) throw(css::uno::RuntimeException)
267 { _aData.Any = _any; }
268 virtual void SAL_CALL setSequence( const css::uno::Sequence<test::TestElement >& _sequence ) throw(css::uno::RuntimeException)
269 { _aData.Sequence = _sequence; }
270 virtual void SAL_CALL setStruct( const test::TestData& _struct ) throw(css::uno::RuntimeException)
271 { _aStructData = _struct; }
273 // XLanguageBindingTest
274 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 )
275 throw(css::lang::IllegalArgumentException, css::uno::RuntimeException);
277 virtual sal_Int32 SAL_CALL getRuntimeException() throw(css::uno::RuntimeException);
278 virtual void SAL_CALL setRuntimeException( sal_Int32 _runtimeexception ) throw(css::uno::RuntimeException);
281 class XLB_Invocation : public WeakImplHelper< XInvocation >
283 Reference< XLanguageBindingTest > _xLBT;
285 public:
286 XLB_Invocation( const Reference< XMultiServiceFactory > & /*xMgr*/,
287 const Reference< XLanguageBindingTest > & xLBT )
288 : _xLBT( xLBT )
291 // XInvocation
292 virtual Reference< XIntrospectionAccess > SAL_CALL getIntrospection() throw(css::uno::RuntimeException)
293 { return Reference< XIntrospectionAccess >(); }
294 virtual Any SAL_CALL invoke( const OUString & rFunctionName,
295 const Sequence< Any > & rParams,
296 Sequence< sal_Int16 > & rOutParamIndex,
297 Sequence< Any > & rOutParam ) throw(css::lang::IllegalArgumentException, css::script::CannotConvertException, css::reflection::InvocationTargetException, css::uno::RuntimeException);
298 virtual void SAL_CALL setValue( const OUString & rPropertyName, const Any & rValue ) throw(css::beans::UnknownPropertyException, css::script::CannotConvertException, css::reflection::InvocationTargetException, css::uno::RuntimeException);
299 virtual Any SAL_CALL getValue( const OUString & rPropertyName ) throw(css::beans::UnknownPropertyException, css::uno::RuntimeException);
300 virtual sal_Bool SAL_CALL hasMethod( const OUString & rName ) throw(css::uno::RuntimeException);
301 virtual sal_Bool SAL_CALL hasProperty( const OUString & rName ) throw(css::uno::RuntimeException);
304 Any XLB_Invocation::invoke( const OUString & rFunctionName,
305 const Sequence< Any > & rParams,
306 Sequence< sal_Int16 > & rOutParamIndex,
307 Sequence< Any > & rOutParam )
308 throw(css::lang::IllegalArgumentException, css::script::CannotConvertException, css::reflection::InvocationTargetException, css::uno::RuntimeException)
310 bool bImplementedMethod = true;
312 Any aRet;
314 OSL_ASSERT( rOutParam.getLength() == 0 );
315 OSL_ASSERT( rOutParamIndex.getLength() == 0 );
319 sal_Bool aBool;
320 sal_Unicode aChar;
321 sal_Int8 nByte;
322 sal_Int16 nShort;
323 sal_uInt16 nUShort;
324 sal_Int32 nLong;
325 sal_uInt32 nULong;
326 sal_Int64 nHyper;
327 sal_uInt64 nUHyper;
328 float fFloat = 0.0;
329 double fDouble = 0.0;
330 TestEnum eEnum;
331 OUString aString;
332 Reference< XInterface > xInterface;
333 Any aAny;
334 Sequence< TestElement > aSeq;
335 TestData aData;
337 if ( rFunctionName == "setValues" )
339 OSL_ASSERT( rParams.getLength() == 17 );
340 aBool = *(sal_Bool *)rParams[0].getValue();
341 aChar = *(sal_Unicode *)rParams[1].getValue();
342 rParams[2] >>= nByte;
343 rParams[3] >>= nShort;
344 rParams[4] >>= nUShort;
345 rParams[5] >>= nLong;
346 rParams[6] >>= nULong;
347 rParams[7] >>= nHyper;
348 rParams[8] >>= nUHyper;
349 rParams[9] >>= fFloat;
350 rParams[10] >>= fDouble;
351 rParams[11] >>= eEnum;
352 rParams[12] >>= aString;
353 rParams[13] >>= xInterface;
354 rParams[14] >>= aAny;
355 rParams[15] >>= aSeq;
356 rParams[16] >>= aData;
358 _xLBT->setValues( aBool, aChar, nByte, nShort, nUShort, nLong, nULong,
359 nHyper, nUHyper, fFloat, fDouble, eEnum, aString, xInterface,
360 aAny, aSeq, aData );
362 rOutParamIndex.realloc( 0 );
363 rOutParam.realloc( 0 );
365 else if ( rFunctionName == "setValues2" )
367 aBool = *(sal_Bool *)rParams[0].getValue();
368 aChar = *(sal_Unicode *)rParams[1].getValue();
369 rParams[2] >>= nByte;
370 rParams[3] >>= nShort;
371 rParams[4] >>= nUShort;
372 rParams[5] >>= nLong;
373 rParams[6] >>= nULong;
374 rParams[7] >>= nHyper;
375 rParams[8] >>= nUHyper;
376 rParams[9] >>= fFloat;
377 rParams[10] >>= fDouble;
378 rParams[11] >>= eEnum;
379 rParams[12] >>= aString;
380 rParams[13] >>= xInterface;
381 rParams[14] >>= aAny;
382 rParams[15] >>= aSeq;
383 rParams[16] >>= aData;
385 aRet <<= _xLBT->setValues2( aBool, aChar, nByte, nShort, nUShort, nLong, nULong,
386 nHyper, nUHyper, fFloat, fDouble, eEnum, aString, xInterface,
387 aAny, aSeq, aData );
389 rOutParamIndex.realloc( 17 );
390 rOutParamIndex[0] = 0;
391 rOutParamIndex[1] = 1;
392 rOutParamIndex[2] = 2;
393 rOutParamIndex[3] = 3;
394 rOutParamIndex[4] = 4;
395 rOutParamIndex[5] = 5;
396 rOutParamIndex[6] = 6;
397 rOutParamIndex[7] = 7;
398 rOutParamIndex[8] = 8;
399 rOutParamIndex[9] = 9;
400 rOutParamIndex[10] = 10;
401 rOutParamIndex[11] = 11;
402 rOutParamIndex[12] = 12;
403 rOutParamIndex[13] = 13;
404 rOutParamIndex[14] = 14;
405 rOutParamIndex[15] = 15;
406 rOutParamIndex[16] = 16;
408 rOutParam.realloc( 17 );
409 rOutParam[0].setValue( &aBool, cppu::UnoType<bool>::get() );
410 rOutParam[1].setValue( &aChar, cppu::UnoType<cppu::UnoCharType>::get() );
411 rOutParam[2] <<= nByte;
412 rOutParam[3] <<= nShort;
413 rOutParam[4] <<= nUShort;
414 rOutParam[5] <<= nLong;
415 rOutParam[6] <<= nULong;
416 rOutParam[7] <<= nHyper;
417 rOutParam[8] <<= nUHyper;
418 rOutParam[9] <<= fFloat;
419 rOutParam[10] <<= fDouble;
420 rOutParam[11] <<= eEnum;
421 rOutParam[12] <<= aString;
422 rOutParam[13] <<= xInterface;
423 rOutParam[14] <<= aAny;
424 rOutParam[15] <<= aSeq;
425 rOutParam[16] <<= aData;
427 else if ( rFunctionName == "getValues" )
429 aRet <<= _xLBT->getValues( aBool, aChar, nByte, nShort, nUShort, nLong, nULong,
430 nHyper, nUHyper, fFloat, fDouble, eEnum, aString, xInterface,
431 aAny, aSeq, aData );
433 rOutParamIndex.realloc( 17 );
434 rOutParamIndex[0] = 0;
435 rOutParamIndex[1] = 1;
436 rOutParamIndex[2] = 2;
437 rOutParamIndex[3] = 3;
438 rOutParamIndex[4] = 4;
439 rOutParamIndex[5] = 5;
440 rOutParamIndex[6] = 6;
441 rOutParamIndex[7] = 7;
442 rOutParamIndex[8] = 8;
443 rOutParamIndex[9] = 9;
444 rOutParamIndex[10] = 10;
445 rOutParamIndex[11] = 11;
446 rOutParamIndex[12] = 12;
447 rOutParamIndex[13] = 13;
448 rOutParamIndex[14] = 14;
449 rOutParamIndex[15] = 15;
450 rOutParamIndex[16] = 16;
452 rOutParam.realloc( 17 );
453 rOutParam[0].setValue( &aBool, cppu::UnoType<bool>::get() );
454 rOutParam[1].setValue( &aChar, cppu::UnoType<cppu::UnoCharType>::get() );
455 rOutParam[2] <<= nByte;
456 rOutParam[3] <<= nShort;
457 rOutParam[4] <<= nUShort;
458 rOutParam[5] <<= nLong;
459 rOutParam[6] <<= nULong;
460 rOutParam[7] <<= nHyper;
461 rOutParam[8] <<= nUHyper;
462 rOutParam[9] <<= fFloat;
463 rOutParam[10] <<= fDouble;
464 rOutParam[11] <<= eEnum;
465 rOutParam[12] <<= aString;
466 rOutParam[13] <<= xInterface;
467 rOutParam[14] <<= aAny;
468 rOutParam[15] <<= aSeq;
469 rOutParam[16] <<= aData;
471 else if ( rFunctionName == "raiseException" )
473 aRet <<= _xLBT->raiseException( aBool, aChar, nByte, nShort, nUShort, nLong, nULong,
474 nHyper, nUHyper, fFloat, fDouble, eEnum, aString, xInterface,
475 aAny, aSeq, aData );
477 rOutParamIndex.realloc( 17 );
478 rOutParamIndex[0] = 0;
479 rOutParamIndex[1] = 1;
480 rOutParamIndex[2] = 2;
481 rOutParamIndex[3] = 3;
482 rOutParamIndex[4] = 4;
483 rOutParamIndex[5] = 5;
484 rOutParamIndex[6] = 6;
485 rOutParamIndex[7] = 7;
486 rOutParamIndex[8] = 8;
487 rOutParamIndex[9] = 9;
488 rOutParamIndex[10] = 10;
489 rOutParamIndex[11] = 11;
490 rOutParamIndex[12] = 12;
491 rOutParamIndex[13] = 13;
492 rOutParamIndex[14] = 14;
493 rOutParamIndex[15] = 15;
494 rOutParamIndex[16] = 16;
496 rOutParam.realloc( 17 );
497 rOutParam[0].setValue( &aBool, cppu::UnoType<bool>::get() );
498 rOutParam[1].setValue( &aChar, cppu::UnoType<cppu::UnoCharType>::get() );
499 rOutParam[2] <<= nByte;
500 rOutParam[3] <<= nShort;
501 rOutParam[4] <<= nUShort;
502 rOutParam[5] <<= nLong;
503 rOutParam[6] <<= nULong;
504 rOutParam[7] <<= nHyper;
505 rOutParam[8] <<= nUHyper;
506 rOutParam[9] <<= fFloat;
507 rOutParam[10] <<= fDouble;
508 rOutParam[11] <<= eEnum;
509 rOutParam[12] <<= aString;
510 rOutParam[13] <<= xInterface;
511 rOutParam[14] <<= aAny;
512 rOutParam[15] <<= aSeq;
513 rOutParam[16] <<= aData;
515 else
517 bImplementedMethod = false;
520 catch (const IllegalArgumentException & rExc)
522 // thrown by raiseException() call
523 InvocationTargetException aExc;
524 aExc.TargetException <<= rExc;
525 throw aExc;
527 catch (Exception &)
529 OSL_FAIL( "### unexpected exception caught!" );
530 throw;
533 if (! bImplementedMethod)
535 throw IllegalArgumentException(
536 OUString( "not an implemented method!" ),
537 (OWeakObject *)this, 0 );
540 return aRet;
543 void XLB_Invocation::setValue( const OUString & rName, const Any & rValue )
544 throw(css::beans::UnknownPropertyException, css::script::CannotConvertException, css::reflection::InvocationTargetException, css::uno::RuntimeException)
546 if ( rName == "Bool" )
547 _xLBT->setBool( *(const sal_Bool *)rValue.getValue() );
548 else if ( rName == "Byte" )
549 _xLBT->setByte( *(const sal_Int8 *)rValue.getValue() );
550 else if ( rName == "Char" )
551 _xLBT->setChar( *(const sal_Unicode *)rValue.getValue() );
552 else if ( rName == "Short" )
553 _xLBT->setShort( *(const sal_Int16 *)rValue.getValue() );
554 else if ( rName == "UShort" )
555 _xLBT->setUShort( *(const sal_uInt16 *)rValue.getValue() );
556 else if ( rName == "Long" )
557 _xLBT->setLong( *(const sal_Int32 *)rValue.getValue() );
558 else if ( rName == "ULong" )
559 _xLBT->setULong( *(const sal_uInt32 *)rValue.getValue() );
560 else if ( rName == "Hyper" )
561 _xLBT->setHyper( *(const sal_Int64 *)rValue.getValue() );
562 else if ( rName == "UHyper" )
563 _xLBT->setUHyper( *(const sal_uInt64 *)rValue.getValue() );
564 else if ( rName == "Float" )
565 _xLBT->setFloat( *(const float *)rValue.getValue() );
566 else if ( rName == "Double" )
567 _xLBT->setDouble( *(const double *)rValue.getValue() );
568 else if ( rName == "Enum" )
569 _xLBT->setEnum( *(const TestEnum *)rValue.getValue() );
570 else if ( rName == "String" )
571 _xLBT->setString( *(const OUString *)rValue.getValue() );
572 else if ( rName == "Interface" )
573 _xLBT->setInterface( *(const Reference< XInterface > *)rValue.getValue() );
574 else if ( rName == "Any" )
575 _xLBT->setAny( rValue );
576 else if ( rName == "Sequence" )
577 _xLBT->setSequence( *(const Sequence< TestElement > *)rValue.getValue() );
578 else if ( rName == "Struct" )
579 _xLBT->setStruct( *(const TestData *)rValue.getValue() );
580 else if ( rName == "RuntimeException" )
581 _xLBT->setRuntimeException( *(const sal_Int32 *)rValue.getValue() );
584 Any XLB_Invocation::getValue( const OUString & rName )
585 throw(css::beans::UnknownPropertyException, css::uno::RuntimeException)
587 Any aRet;
588 if ( rName == "Bool" )
590 sal_Bool aBool = _xLBT->getBool();
591 aRet.setValue( &aBool, cppu::UnoType<bool>::get() );
593 else if ( rName == "Byte" )
594 aRet <<= _xLBT->getByte();
595 else if ( rName == "Char" )
597 sal_Unicode aChar = _xLBT->getChar();
598 aRet.setValue( &aChar, cppu::UnoType<cppu::UnoCharType>::get() );
600 else if ( rName == "Short" )
601 aRet <<= _xLBT->getShort();
602 else if ( rName == "UShort" )
603 aRet <<= _xLBT->getUShort();
604 else if ( rName == "Long" )
605 aRet <<= _xLBT->getLong();
606 else if ( rName == "ULong" )
607 aRet <<= _xLBT->getULong();
608 else if ( rName == "Hyper" )
609 aRet <<= _xLBT->getHyper();
610 else if ( rName == "UHyper" )
611 aRet <<= _xLBT->getUHyper();
612 else if ( rName == "Float" )
613 aRet <<= _xLBT->getFloat();
614 else if ( rName == "Double" )
615 aRet <<= _xLBT->getDouble();
616 else if ( rName == "Enum" )
617 aRet <<= _xLBT->getEnum();
618 else if ( rName == "String" )
619 aRet <<= _xLBT->getString();
620 else if ( rName == "Interface" )
621 aRet <<= _xLBT->getInterface();
622 else if ( rName == "Any" )
623 aRet <<= _xLBT->getAny();
624 else if ( rName == "Sequence" )
625 aRet <<= _xLBT->getSequence();
626 else if ( rName == "Struct" )
627 aRet <<= _xLBT->getStruct();
628 else if ( rName == "RuntimeException" )
629 aRet <<= _xLBT->getRuntimeException();
630 return aRet;
633 sal_Bool XLB_Invocation::hasMethod( const OUString & rName )
634 throw(css::uno::RuntimeException)
636 return (rName == "raiseException" ||
637 rName == "getValues" ||
638 rName == "setValues2" ||
639 rName == "setValues" ||
640 rName == "acquire" ||
641 rName == "release" ||
642 rName == "queryInterface" );
645 sal_Bool XLB_Invocation::hasProperty( const OUString & rName )
646 throw(css::uno::RuntimeException)
648 return (rName == "Bool" ||
649 rName == "Byte" ||
650 rName == "Char" ||
651 rName == "Short" ||
652 rName == "UShort" ||
653 rName == "Long" ||
654 rName == "ULong" ||
655 rName == "Hyper" ||
656 rName == "UHyper" ||
657 rName == "Float" ||
658 rName == "Double" ||
659 rName == "Enum" ||
660 rName == "String" ||
661 rName == "Interface" ||
662 rName == "Any" ||
663 rName == "Sequence" ||
664 rName == "Struct" ||
665 rName == "RuntimeException" );
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 OUString& rStr,
675 const css::uno::Reference< css::uno::XInterface >& xTest,
676 const css::uno::Any& rAny,
677 const css::uno::Sequence<test::TestElement >& rSequence,
678 const test::TestData& rStruct )
679 throw(css::uno::RuntimeException)
681 assign( _aData,
682 bBool, cChar, nByte, nShort, nUShort, nLong, nULong, nHyper, nUHyper, fFloat, fDouble,
683 eEnum, rStr, xTest, rAny, rSequence );
684 _aStructData = rStruct;
687 test::TestData Test_Impl::setValues2( sal_Bool& bBool, sal_Unicode& cChar, sal_Int8& nByte,
688 sal_Int16& nShort, sal_uInt16& nUShort,
689 sal_Int32& nLong, sal_uInt32& nULong,
690 sal_Int64& nHyper, sal_uInt64& nUHyper,
691 float& fFloat, double& fDouble,
692 test::TestEnum& eEnum, OUString& rStr,
693 css::uno::Reference< css::uno::XInterface >& xTest,
694 css::uno::Any& rAny,
695 css::uno::Sequence<test::TestElement >& rSequence,
696 test::TestData& rStruct )
697 throw(css::uno::RuntimeException)
699 assign( _aData,
700 bBool, cChar, nByte, nShort, nUShort, nLong, nULong, nHyper, nUHyper, fFloat, fDouble,
701 eEnum, rStr, xTest, rAny, rSequence );
702 _aStructData = rStruct;
703 return _aStructData;
706 test::TestData Test_Impl::getValues( sal_Bool& bBool, sal_Unicode& cChar, sal_Int8& nByte,
707 sal_Int16& nShort, sal_uInt16& nUShort,
708 sal_Int32& nLong, sal_uInt32& nULong,
709 sal_Int64& nHyper, sal_uInt64& nUHyper,
710 float& fFloat, double& fDouble,
711 test::TestEnum& eEnum, OUString& rStr,
712 css::uno::Reference< css::uno::XInterface >& xTest,
713 css::uno::Any& rAny,
714 css::uno::Sequence<test::TestElement >& rSequence,
715 test::TestData& rStruct )
716 throw(css::uno::RuntimeException)
718 bBool = _aData.Bool;
719 cChar = _aData.Char;
720 nByte = _aData.Byte;
721 nShort = _aData.Short;
722 nUShort = _aData.UShort;
723 nLong = _aData.Long;
724 nULong = _aData.ULong;
725 nHyper = _aData.Hyper;
726 nUHyper = _aData.UHyper;
727 fFloat = _aData.Float;
728 fDouble = _aData.Double;
729 eEnum = _aData.Enum;
730 rStr = _aData.String;
731 xTest = _aData.Interface;
732 rAny = _aData.Any;
733 rSequence = _aData.Sequence;
734 rStruct = _aStructData;
735 return _aStructData;
739 sal_Bool performTest( const Reference<XLanguageBindingTest > & xLBT )
741 OSL_ENSURE( xLBT.is(), "### no test interface!" );
742 if (xLBT.is())
744 // this data is never ever granted access to by calls other than equals(), assign()!
745 test::TestData aData; // test against this data
747 Reference<XInterface > xI( *new OWeakObject() );
749 assign( (test::TestElement &)aData,
750 sal_True, '@', 17, 0x1234, 0xfedc, 0x12345678, 0xfedcba98,
751 SAL_CONST_INT64(0x123456789abcdef0),
752 SAL_CONST_UINT64(0xfedcba9876543210),
753 (float)17.03125, M_PI, TestEnum_LOLA, OUString("dumdidum"), xI,
754 Any( &xI, cppu::UnoType<XInterface>::get()) );
756 OSL_ENSURE( aData.Any == xI, "### unexpected any!" );
757 OSL_ENSURE( !(aData.Any != xI), "### unexpected any!" );
759 aData.Sequence = Sequence<test::TestElement >( (const test::TestElement *)&aData, 1 );
760 // aData complete
763 // this is a manually copy of aData for first setting...
764 test::TestData aSetData;
766 assign( (test::TestElement &)aSetData,
767 aData.Bool, aData.Char, aData.Byte, aData.Short, aData.UShort,
768 aData.Long, aData.ULong, aData.Hyper, aData.UHyper, aData.Float, aData.Double,
769 aData.Enum, aData.String, xI,
770 Any( &xI, cppu::UnoType<XInterface>::get()) );
772 aSetData.Sequence = Sequence<test::TestElement >( (const test::TestElement *)&aSetData, 1 );
774 xLBT->setValues(
775 aSetData.Bool, aSetData.Char, aSetData.Byte, aSetData.Short, aSetData.UShort,
776 aSetData.Long, aSetData.ULong, aSetData.Hyper, aSetData.UHyper, aSetData.Float, aSetData.Double,
777 aSetData.Enum, aSetData.String, aSetData.Interface, aSetData.Any, aSetData.Sequence, aSetData );
780 test::TestData aRet, aRet2;
781 xLBT->getValues(
782 aRet.Bool, aRet.Char, aRet.Byte, aRet.Short, aRet.UShort,
783 aRet.Long, aRet.ULong, aRet.Hyper, aRet.UHyper, aRet.Float, aRet.Double,
784 aRet.Enum, aRet.String, aRet.Interface, aRet.Any, aRet.Sequence, aRet2 );
786 OSL_ASSERT( equals( aData, aRet ) && equals( aData, aRet2 ) );
788 // set last retrieved values
789 test::TestData aSV2ret = xLBT->setValues2(
790 aRet.Bool, aRet.Char, aRet.Byte, aRet.Short, aRet.UShort,
791 aRet.Long, aRet.ULong, aRet.Hyper, aRet.UHyper, aRet.Float, aRet.Double,
792 aRet.Enum, aRet.String, aRet.Interface, aRet.Any, aRet.Sequence, aRet2 );
794 OSL_ASSERT( equals( aData, aSV2ret ) && equals( aData, aRet2 ) );
797 test::TestData aRet, aRet2;
798 test::TestData aGVret = xLBT->getValues(
799 aRet.Bool, aRet.Char, aRet.Byte, aRet.Short, aRet.UShort,
800 aRet.Long, aRet.ULong, aRet.Hyper, aRet.UHyper, aRet.Float, aRet.Double,
801 aRet.Enum, aRet.String, aRet.Interface, aRet.Any, aRet.Sequence, aRet2 );
803 OSL_ASSERT( equals( aData, aRet ) && equals( aData, aRet2 ) && equals( aData, aGVret ) );
805 // set last retrieved values
806 xLBT->setBool( aRet.Bool );
807 xLBT->setChar( aRet.Char );
808 xLBT->setByte( aRet.Byte );
809 xLBT->setShort( aRet.Short );
810 xLBT->setUShort( aRet.UShort );
811 xLBT->setLong( aRet.Long );
812 xLBT->setULong( aRet.ULong );
813 xLBT->setHyper( aRet.Hyper );
814 xLBT->setUHyper( aRet.UHyper );
815 xLBT->setFloat( aRet.Float );
816 xLBT->setDouble( aRet.Double );
817 xLBT->setEnum( aRet.Enum );
818 xLBT->setString( aRet.String );
819 xLBT->setInterface( aRet.Interface );
820 xLBT->setAny( aRet.Any );
821 xLBT->setSequence( aRet.Sequence );
822 xLBT->setStruct( aRet2 );
825 test::TestData aRet, aRet2;
826 aRet.Hyper = xLBT->getHyper();
827 aRet.UHyper = xLBT->getUHyper();
828 aRet.Float = xLBT->getFloat();
829 aRet.Double = xLBT->getDouble();
830 aRet.Byte = xLBT->getByte();
831 aRet.Char = xLBT->getChar();
832 aRet.Bool = xLBT->getBool();
833 aRet.Short = xLBT->getShort();
834 aRet.UShort = xLBT->getUShort();
835 aRet.Long = xLBT->getLong();
836 aRet.ULong = xLBT->getULong();
837 aRet.Enum = xLBT->getEnum();
838 aRet.String = xLBT->getString();
839 aRet.Interface = xLBT->getInterface();
840 aRet.Any = xLBT->getAny();
841 aRet.Sequence = xLBT->getSequence();
842 aRet2 = xLBT->getStruct();
844 return (equals( aData, aRet ) && equals( aData, aRet2 ));
847 return sal_False;
851 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*/ )
852 throw(css::lang::IllegalArgumentException, css::uno::RuntimeException)
854 IllegalArgumentException aExc;
855 aExc.ArgumentPosition = 5;
856 aExc.Message = "dum dum dum I dance around the circle...";
857 aExc.Context = *this;
858 throw aExc;
861 sal_Int32 Test_Impl::getRuntimeException() throw(css::uno::RuntimeException)
863 RuntimeException aExc;
864 aExc.Message = "dum dum dum I dance around the circle...";
865 aExc.Context = *this;
866 throw aExc;
869 void Test_Impl::setRuntimeException( sal_Int32 /*_runtimeexception*/ ) throw(css::uno::RuntimeException)
871 RuntimeException aExc;
872 aExc.Message = "dum dum dum I dance around the circle...";
873 aExc.Context = *this;
874 throw aExc;
878 sal_Bool raiseException( const Reference<XLanguageBindingTest > & xLBT )
886 test::TestData aRet, aRet2;
887 xLBT->raiseException(
888 aRet.Bool, aRet.Char, aRet.Byte, aRet.Short, aRet.UShort,
889 aRet.Long, aRet.ULong, aRet.Hyper, aRet.UHyper, aRet.Float, aRet.Double,
890 aRet.Enum, aRet.String, aRet.Interface, aRet.Any, aRet.Sequence, aRet2 );
891 return sal_False;
893 catch (const IllegalArgumentException &aExc)
895 OSL_ENSURE( aExc.ArgumentPosition == 5 &&
896 aExc.Message.startsWith("dum dum dum I dance around the circle..."),
897 "### unexpected exception content!" );
899 Reference<XLanguageBindingTest > xLBT2(
900 Reference<XLanguageBindingTest >::query( aExc.Context ) );
902 OSL_ENSURE( xLBT2.is(), "### unexpected source of exception!" );
903 if (xLBT2.is())
904 xLBT2->getRuntimeException();
905 else
906 return sal_False;
909 catch (const RuntimeException & rExc)
911 OSL_ENSURE( rExc.Message.startsWith("dum dum dum I dance around the circle..."),
912 "### unexpected exception content!" );
914 Reference<XLanguageBindingTest > xLBT2(
915 Reference<XLanguageBindingTest >::query( rExc.Context ) );
917 OSL_ENSURE( xLBT2.is(), "### unexpected source of exception!" );
918 if (xLBT2.is())
919 xLBT2->setRuntimeException( 0xcafebabe );
920 else
921 return sal_False;
924 catch (const Exception & aExc)
926 OSL_ENSURE( aExc.Message.startsWith("dum dum dum I dance around the circle..."),
927 "### unexpected exception content!" );
928 return aExc.Message.startsWith("dum dum dum I dance around the circle...");
930 return sal_False;
934 static sal_Bool test_adapter( const Reference< XMultiServiceFactory > & xMgr )
936 Reference< XInvocationAdapterFactory > xAdapFac(
937 xMgr->createInstance("com.sun.star.script.InvocationAdapterFactory"), UNO_QUERY );
938 Reference< XInvocationAdapterFactory2 > xAdapFac2( xAdapFac, UNO_QUERY_THROW );
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, cppu::UnoType<XLanguageBindingTest>::get()), UNO_QUERY );
944 Reference< XLanguageBindingTest > xLBT2(
945 xAdapFac->createAdapter(
946 xInvok, cppu::UnoType<XLanguageBindingTest>::get()), UNO_QUERY );
947 if (xLBT != xLBT2)
948 return sal_False;
949 Reference< XInterface > xLBT3(
950 xAdapFac->createAdapter(
951 xInvok, cppu::UnoType<XInterface>::get()), UNO_QUERY );
952 if (xLBT != xLBT3)
953 return sal_False;
954 Type ar[ 2 ] = {
955 cppu::UnoType<XLBTestBase>::get(),
956 cppu::UnoType<XInterface>::get()};
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, cppu::UnoType<XSimpleRegistry>::get()), UNO_QUERY );
964 if (xLBT == xInvalidAdapter)
965 return sal_False;
969 xInvalidAdapter->isValid();
970 return sal_False;
972 catch (RuntimeException &)
976 return (performTest( xLBT ) && raiseException( xLBT ));
979 static sal_Bool test_invocation( const Reference< XMultiServiceFactory > & xMgr )
981 Reference< XInvocationAdapterFactory > xAdapFac(
982 xMgr->createInstance("com.sun.star.script.InvocationAdapterFactory"), UNO_QUERY );
983 Reference< XSingleServiceFactory > xInvocFac(
984 xMgr->createInstance("com.sun.star.script.Invocation"), UNO_QUERY );
986 Reference< XLanguageBindingTest > xOriginal( (XLanguageBindingTest *)new Test_Impl() );
987 Any aOriginal( &xOriginal, cppu::UnoType<decltype(xOriginal)>::get() );
988 Reference< XInvocation > xInvok(
989 xInvocFac->createInstanceWithArguments( Sequence< Any >( &aOriginal, 1 ) ), UNO_QUERY );
991 Reference< XLanguageBindingTest > xLBT( xAdapFac->createAdapter(
992 xInvok, cppu::UnoType<XLanguageBindingTest>::get()), UNO_QUERY );
994 return (performTest( xLBT ) && raiseException( xLBT ));
997 SAL_IMPLEMENT_MAIN()
999 Reference< XMultiServiceFactory > xMgr( createRegistryServiceFactory(
1000 OUString( "stoctest.rdb" ) ) );
1004 Reference< XImplementationRegistration > xImplReg(
1005 xMgr->createInstance( "com.sun.star.registry.ImplementationRegistration" ),
1006 UNO_QUERY );
1007 OSL_ENSURE( xImplReg.is(), "### no impl reg!" );
1009 xImplReg->registerImplementation(
1010 OUString("com.sun.star.loader.SharedLibrary"),
1011 OUString("invocadapt.uno" SAL_DLLEXTENSION),
1012 Reference< XSimpleRegistry >() );
1013 xImplReg->registerImplementation(
1014 OUString("com.sun.star.loader.SharedLibrary"),
1015 OUString("stocservices.uno" SAL_DLLEXTENSION),
1016 Reference< XSimpleRegistry >() );
1017 xImplReg->registerImplementation(
1018 OUString("com.sun.star.loader.SharedLibrary"),
1019 OUString("invocation.uno" SAL_DLLEXTENSION),
1020 Reference< XSimpleRegistry >() );
1021 xImplReg->registerImplementation(
1022 OUString("com.sun.star.loader.SharedLibrary"),
1023 OUString("reflection.uno" SAL_DLLEXTENSION),
1024 Reference< XSimpleRegistry >() );
1025 xImplReg->registerImplementation(
1026 OUString("com.sun.star.loader.SharedLibrary"),
1027 OUString("introspection.uno" SAL_DLLEXTENSION),
1028 Reference< XSimpleRegistry >() );
1030 if (test_adapter( xMgr ))
1032 fprintf( stderr, "> test_iadapter() succeeded.\n" );
1033 if (test_invocation( xMgr ))
1035 fprintf( stderr, "> test_invocation() succeeded.\n" );
1039 catch (const Exception & rExc)
1041 fprintf( stderr, "> exception occurred: " );
1042 OString aMsg( OUStringToOString( rExc.Message, RTL_TEXTENCODING_ASCII_US ) );
1043 fprintf( stderr, "%s\n", aMsg.getStr() );
1046 Reference< XComponent >( xMgr, UNO_QUERY )->dispose();
1048 return 0;
1051 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */