fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / stoc / test / testiadapter.cxx
blob5099f886aa75ee0404b106569c1b0cfaa87b8ba4
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 <osl/diagnose.h>
26 #include <cppuhelper/servicefactory.hxx>
27 #include <cppuhelper/weak.hxx>
29 #include <test/XLanguageBindingTest.hpp>
30 #include <com/sun/star/registry/XSimpleRegistry.hpp>
31 #include <com/sun/star/registry/XImplementationRegistration.hpp>
32 #include <com/sun/star/script/XInvocation.hpp>
33 #include <com/sun/star/script/XInvocationAdapterFactory.hpp>
34 #include <com/sun/star/script/XInvocationAdapterFactory2.hpp>
35 #include <com/sun/star/lang/XComponent.hpp>
36 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
38 #include <cppuhelper/implbase1.hxx>
41 using namespace test;
42 using namespace cppu;
43 using namespace osl;
44 using namespace css::uno;
45 using namespace css::script;
46 using namespace css::beans;
47 using namespace css::lang;
48 using namespace css::reflection;
49 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 WeakImplHelper1< XLanguageBindingTest >
160 test::TestData _aData, _aStructData;
162 public:
163 virtual ~Test_Impl()
164 { OSL_TRACE( "> scalar Test_Impl dtor <\n" ); }
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 WeakImplHelper1< 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" );
671 void Test_Impl::setValues( sal_Bool bBool, sal_Unicode cChar, sal_Int8 nByte,
672 sal_Int16 nShort, sal_uInt16 nUShort,
673 sal_Int32 nLong, sal_uInt32 nULong,
674 sal_Int64 nHyper, sal_uInt64 nUHyper,
675 float fFloat, double fDouble,
676 test::TestEnum eEnum, const OUString& rStr,
677 const css::uno::Reference< css::uno::XInterface >& xTest,
678 const css::uno::Any& rAny,
679 const css::uno::Sequence<test::TestElement >& rSequence,
680 const test::TestData& rStruct )
681 throw(css::uno::RuntimeException)
683 assign( _aData,
684 bBool, cChar, nByte, nShort, nUShort, nLong, nULong, nHyper, nUHyper, fFloat, fDouble,
685 eEnum, rStr, xTest, rAny, rSequence );
686 _aStructData = rStruct;
689 test::TestData Test_Impl::setValues2( sal_Bool& bBool, sal_Unicode& cChar, sal_Int8& nByte,
690 sal_Int16& nShort, sal_uInt16& nUShort,
691 sal_Int32& nLong, sal_uInt32& nULong,
692 sal_Int64& nHyper, sal_uInt64& nUHyper,
693 float& fFloat, double& fDouble,
694 test::TestEnum& eEnum, OUString& rStr,
695 css::uno::Reference< css::uno::XInterface >& xTest,
696 css::uno::Any& rAny,
697 css::uno::Sequence<test::TestElement >& rSequence,
698 test::TestData& rStruct )
699 throw(css::uno::RuntimeException)
701 assign( _aData,
702 bBool, cChar, nByte, nShort, nUShort, nLong, nULong, nHyper, nUHyper, fFloat, fDouble,
703 eEnum, rStr, xTest, rAny, rSequence );
704 _aStructData = rStruct;
705 return _aStructData;
708 test::TestData Test_Impl::getValues( sal_Bool& bBool, sal_Unicode& cChar, sal_Int8& nByte,
709 sal_Int16& nShort, sal_uInt16& nUShort,
710 sal_Int32& nLong, sal_uInt32& nULong,
711 sal_Int64& nHyper, sal_uInt64& nUHyper,
712 float& fFloat, double& fDouble,
713 test::TestEnum& eEnum, OUString& rStr,
714 css::uno::Reference< css::uno::XInterface >& xTest,
715 css::uno::Any& rAny,
716 css::uno::Sequence<test::TestElement >& rSequence,
717 test::TestData& rStruct )
718 throw(css::uno::RuntimeException)
720 bBool = _aData.Bool;
721 cChar = _aData.Char;
722 nByte = _aData.Byte;
723 nShort = _aData.Short;
724 nUShort = _aData.UShort;
725 nLong = _aData.Long;
726 nULong = _aData.ULong;
727 nHyper = _aData.Hyper;
728 nUHyper = _aData.UHyper;
729 fFloat = _aData.Float;
730 fDouble = _aData.Double;
731 eEnum = _aData.Enum;
732 rStr = _aData.String;
733 xTest = _aData.Interface;
734 rAny = _aData.Any;
735 rSequence = _aData.Sequence;
736 rStruct = _aStructData;
737 return _aStructData;
741 sal_Bool performTest( const Reference<XLanguageBindingTest > & xLBT )
743 OSL_ENSURE( xLBT.is(), "### no test interface!" );
744 if (xLBT.is())
746 // this data is never ever granted access to by calls other than equals(), assign()!
747 test::TestData aData; // test against this data
749 Reference<XInterface > xI( *new OWeakObject() );
751 assign( (test::TestElement &)aData,
752 sal_True, '@', 17, 0x1234, 0xfedc, 0x12345678, 0xfedcba98,
753 SAL_CONST_INT64(0x123456789abcdef0),
754 SAL_CONST_UINT64(0xfedcba9876543210),
755 (float)17.0815, 3.1415926359, TestEnum_LOLA, OUString("dumdidum"), xI,
756 Any( &xI, cppu::UnoType<XInterface>::get()) );
758 OSL_ENSURE( aData.Any == xI, "### unexpected any!" );
759 OSL_ENSURE( !(aData.Any != xI), "### unexpected any!" );
761 aData.Sequence = Sequence<test::TestElement >( (const test::TestElement *)&aData, 1 );
762 // aData complete
765 // this is a manually copy of aData for first setting...
766 test::TestData aSetData;
768 assign( (test::TestElement &)aSetData,
769 aData.Bool, aData.Char, aData.Byte, aData.Short, aData.UShort,
770 aData.Long, aData.ULong, aData.Hyper, aData.UHyper, aData.Float, aData.Double,
771 aData.Enum, aData.String, xI,
772 Any( &xI, cppu::UnoType<XInterface>::get()) );
774 aSetData.Sequence = Sequence<test::TestElement >( (const test::TestElement *)&aSetData, 1 );
776 xLBT->setValues(
777 aSetData.Bool, aSetData.Char, aSetData.Byte, aSetData.Short, aSetData.UShort,
778 aSetData.Long, aSetData.ULong, aSetData.Hyper, aSetData.UHyper, aSetData.Float, aSetData.Double,
779 aSetData.Enum, aSetData.String, aSetData.Interface, aSetData.Any, aSetData.Sequence, aSetData );
782 test::TestData aRet, aRet2;
783 xLBT->getValues(
784 aRet.Bool, aRet.Char, aRet.Byte, aRet.Short, aRet.UShort,
785 aRet.Long, aRet.ULong, aRet.Hyper, aRet.UHyper, aRet.Float, aRet.Double,
786 aRet.Enum, aRet.String, aRet.Interface, aRet.Any, aRet.Sequence, aRet2 );
788 OSL_ASSERT( equals( aData, aRet ) && equals( aData, aRet2 ) );
790 // set last retrieved values
791 test::TestData aSV2ret = xLBT->setValues2(
792 aRet.Bool, aRet.Char, aRet.Byte, aRet.Short, aRet.UShort,
793 aRet.Long, aRet.ULong, aRet.Hyper, aRet.UHyper, aRet.Float, aRet.Double,
794 aRet.Enum, aRet.String, aRet.Interface, aRet.Any, aRet.Sequence, aRet2 );
796 OSL_ASSERT( equals( aData, aSV2ret ) && equals( aData, aRet2 ) );
799 test::TestData aRet, aRet2;
800 test::TestData aGVret = xLBT->getValues(
801 aRet.Bool, aRet.Char, aRet.Byte, aRet.Short, aRet.UShort,
802 aRet.Long, aRet.ULong, aRet.Hyper, aRet.UHyper, aRet.Float, aRet.Double,
803 aRet.Enum, aRet.String, aRet.Interface, aRet.Any, aRet.Sequence, aRet2 );
805 OSL_ASSERT( equals( aData, aRet ) && equals( aData, aRet2 ) && equals( aData, aGVret ) );
807 // set last retrieved values
808 xLBT->setBool( aRet.Bool );
809 xLBT->setChar( aRet.Char );
810 xLBT->setByte( aRet.Byte );
811 xLBT->setShort( aRet.Short );
812 xLBT->setUShort( aRet.UShort );
813 xLBT->setLong( aRet.Long );
814 xLBT->setULong( aRet.ULong );
815 xLBT->setHyper( aRet.Hyper );
816 xLBT->setUHyper( aRet.UHyper );
817 xLBT->setFloat( aRet.Float );
818 xLBT->setDouble( aRet.Double );
819 xLBT->setEnum( aRet.Enum );
820 xLBT->setString( aRet.String );
821 xLBT->setInterface( aRet.Interface );
822 xLBT->setAny( aRet.Any );
823 xLBT->setSequence( aRet.Sequence );
824 xLBT->setStruct( aRet2 );
827 test::TestData aRet, aRet2;
828 aRet.Hyper = xLBT->getHyper();
829 aRet.UHyper = xLBT->getUHyper();
830 aRet.Float = xLBT->getFloat();
831 aRet.Double = xLBT->getDouble();
832 aRet.Byte = xLBT->getByte();
833 aRet.Char = xLBT->getChar();
834 aRet.Bool = xLBT->getBool();
835 aRet.Short = xLBT->getShort();
836 aRet.UShort = xLBT->getUShort();
837 aRet.Long = xLBT->getLong();
838 aRet.ULong = xLBT->getULong();
839 aRet.Enum = xLBT->getEnum();
840 aRet.String = xLBT->getString();
841 aRet.Interface = xLBT->getInterface();
842 aRet.Any = xLBT->getAny();
843 aRet.Sequence = xLBT->getSequence();
844 aRet2 = xLBT->getStruct();
846 return (equals( aData, aRet ) && equals( aData, aRet2 ));
849 return sal_False;
853 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*/ )
854 throw(css::lang::IllegalArgumentException, css::uno::RuntimeException)
856 IllegalArgumentException aExc;
857 aExc.ArgumentPosition = 5;
858 aExc.Message = "dum dum dum ich tanz im kreis herum...";
859 aExc.Context = *this;
860 throw aExc;
863 sal_Int32 Test_Impl::getRuntimeException() throw(css::uno::RuntimeException)
865 RuntimeException aExc;
866 aExc.Message = "dum dum dum ich tanz im kreis herum...";
867 aExc.Context = *this;
868 throw aExc;
871 void Test_Impl::setRuntimeException( sal_Int32 /*_runtimeexception*/ ) throw(css::uno::RuntimeException)
873 RuntimeException aExc;
874 aExc.Message = "dum dum dum ich tanz im kreis herum...";
875 aExc.Context = *this;
876 throw aExc;
880 sal_Bool raiseException( const Reference<XLanguageBindingTest > & xLBT )
888 test::TestData aRet, aRet2;
889 xLBT->raiseException(
890 aRet.Bool, aRet.Char, aRet.Byte, aRet.Short, aRet.UShort,
891 aRet.Long, aRet.ULong, aRet.Hyper, aRet.UHyper, aRet.Float, aRet.Double,
892 aRet.Enum, aRet.String, aRet.Interface, aRet.Any, aRet.Sequence, aRet2 );
893 return sal_False;
895 catch (const IllegalArgumentException &aExc)
897 OSL_ENSURE( aExc.ArgumentPosition == 5 &&
898 aExc.Message == "dum dum dum ich tanz im kreis herum...",
899 "### unexpected exception content!" );
901 Reference<XLanguageBindingTest > xLBT2(
902 Reference<XLanguageBindingTest >::query( aExc.Context ) );
904 OSL_ENSURE( xLBT2.is(), "### unexpected source of exception!" );
905 if (xLBT2.is())
906 xLBT2->getRuntimeException();
907 else
908 return sal_False;
911 catch (const RuntimeException & rExc)
913 OSL_ENSURE( rExc.Message == "dum dum dum ich tanz im kreis herum...",
914 "### unexpected exception content!" );
916 Reference<XLanguageBindingTest > xLBT2(
917 Reference<XLanguageBindingTest >::query( rExc.Context ) );
919 OSL_ENSURE( xLBT2.is(), "### unexpected source of exception!" );
920 if (xLBT2.is())
921 xLBT2->setRuntimeException( 0xcafebabe );
922 else
923 return sal_False;
926 catch (const Exception & aExc)
928 OSL_ENSURE( aExc.Message == "dum dum dum ich tanz im kreis herum...",
929 "### unexpected exception content!" );
930 return aExc.Message == "dum dum dum ich tanz im kreis herum...";
932 return sal_False;
936 static sal_Bool test_adapter( const Reference< XMultiServiceFactory > & xMgr )
938 Reference< XInvocationAdapterFactory > xAdapFac(
939 xMgr->createInstance("com.sun.star.script.InvocationAdapterFactory"), UNO_QUERY );
940 Reference< XInvocationAdapterFactory2 > xAdapFac2( xAdapFac, UNO_QUERY_THROW );
942 Reference< XLanguageBindingTest > xOriginal( (XLanguageBindingTest *)new Test_Impl() );
943 Reference< XInvocation > xInvok( new XLB_Invocation( xMgr, xOriginal ) );
944 Reference< XLanguageBindingTest > xLBT( xAdapFac->createAdapter(
945 xInvok, cppu::UnoType<XLanguageBindingTest>::get()), UNO_QUERY );
946 Reference< XLanguageBindingTest > xLBT2(
947 xAdapFac->createAdapter(
948 xInvok, cppu::UnoType<XLanguageBindingTest>::get()), UNO_QUERY );
949 if (xLBT != xLBT2)
950 return sal_False;
951 Reference< XInterface > xLBT3(
952 xAdapFac->createAdapter(
953 xInvok, cppu::UnoType<XInterface>::get()), UNO_QUERY );
954 if (xLBT != xLBT3)
955 return sal_False;
956 Type ar[ 2 ] = {
957 cppu::UnoType<XLBTestBase>::get(),
958 cppu::UnoType<XInterface>::get()};
959 Reference< XInterface > xLBT4(
960 xAdapFac2->createAdapter( xInvok, Sequence< Type >( ar, 2 ) ), UNO_QUERY );
961 if (xLBT != xLBT4)
962 return sal_False;
963 Reference< XSimpleRegistry > xInvalidAdapter(
964 xAdapFac->createAdapter(
965 xInvok, cppu::UnoType<XSimpleRegistry>::get()), UNO_QUERY );
966 if (xLBT == xInvalidAdapter)
967 return sal_False;
971 xInvalidAdapter->isValid();
972 return sal_False;
974 catch (RuntimeException &)
978 return (performTest( xLBT ) && raiseException( xLBT ));
981 static sal_Bool test_invocation( const Reference< XMultiServiceFactory > & xMgr )
983 Reference< XInvocationAdapterFactory > xAdapFac(
984 xMgr->createInstance("com.sun.star.script.InvocationAdapterFactory"), UNO_QUERY );
985 Reference< XSingleServiceFactory > xInvocFac(
986 xMgr->createInstance("com.sun.star.script.Invocation"), UNO_QUERY );
988 Reference< XLanguageBindingTest > xOriginal( (XLanguageBindingTest *)new Test_Impl() );
989 Any aOriginal( &xOriginal, cppu::UnoType<decltype(xOriginal)>::get() );
990 Reference< XInvocation > xInvok(
991 xInvocFac->createInstanceWithArguments( Sequence< Any >( &aOriginal, 1 ) ), UNO_QUERY );
993 Reference< XLanguageBindingTest > xLBT( xAdapFac->createAdapter(
994 xInvok, cppu::UnoType<XLanguageBindingTest>::get()), UNO_QUERY );
996 return (performTest( xLBT ) && raiseException( xLBT ));
999 SAL_IMPLEMENT_MAIN()
1001 Reference< XMultiServiceFactory > xMgr( createRegistryServiceFactory(
1002 OUString( "stoctest.rdb" ) ) );
1006 Reference< XImplementationRegistration > xImplReg(
1007 xMgr->createInstance(
1008 OUString( "com.sun.star.registry.ImplementationRegistration" ) ),
1009 UNO_QUERY );
1010 OSL_ENSURE( xImplReg.is(), "### no impl reg!" );
1012 xImplReg->registerImplementation(
1013 OUString("com.sun.star.loader.SharedLibrary"),
1014 OUString("invocadapt.uno" SAL_DLLEXTENSION),
1015 Reference< XSimpleRegistry >() );
1016 xImplReg->registerImplementation(
1017 OUString("com.sun.star.loader.SharedLibrary"),
1018 OUString("stocservices.uno" SAL_DLLEXTENSION),
1019 Reference< XSimpleRegistry >() );
1020 xImplReg->registerImplementation(
1021 OUString("com.sun.star.loader.SharedLibrary"),
1022 OUString("invocation.uno" SAL_DLLEXTENSION),
1023 Reference< XSimpleRegistry >() );
1024 xImplReg->registerImplementation(
1025 OUString("com.sun.star.loader.SharedLibrary"),
1026 OUString("reflection.uno" SAL_DLLEXTENSION),
1027 Reference< XSimpleRegistry >() );
1028 xImplReg->registerImplementation(
1029 OUString("com.sun.star.loader.SharedLibrary"),
1030 OUString("introspection.uno" SAL_DLLEXTENSION),
1031 Reference< XSimpleRegistry >() );
1033 if (test_adapter( xMgr ))
1035 fprintf( stderr, "> test_iadapter() succeeded.\n" );
1036 if (test_invocation( xMgr ))
1038 fprintf( stderr, "> test_invocation() succeeded.\n" );
1042 catch (const Exception & rExc)
1044 fprintf( stderr, "> exception occurred: " );
1045 OString aMsg( OUStringToOString( rExc.Message, RTL_TEXTENCODING_ASCII_US ) );
1046 fprintf( stderr, "%s\n", aMsg.getStr() );
1049 Reference< XComponent >( xMgr, UNO_QUERY )->dispose();
1051 return 0;
1054 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */