1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: test_di.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #if !defined(OSL_DEBUG_LEVEL) || OSL_DEBUG_LEVEL == 0
32 # undef OSL_DEBUG_LEVEL
33 # define OSL_DEBUG_LEVEL 2
36 // MARKER(update_precomp.py): autogen include statement, do not remove
37 #include "precompiled_cppu.hxx"
41 #include <rtl/ustring.hxx>
42 #include <osl/diagnose.h>
44 #include <sal/types.h>
46 #include <uno/dispatcher.h>
47 #include <uno/environment.h>
48 #include <uno/mapping.hxx>
51 // #include <uno/cuno.h>
52 // #include <test/XLanguageBindingTest.h>
54 #include <cppuhelper/weak.hxx>
55 #include <cppuhelper/queryinterface.hxx>
56 #include <cppu/macros.hxx>
57 #include <test/XLanguageBindingTest.hpp>
59 #include <cppuhelper/implbase1.hxx>
61 #include <com/sun/star/lang/XComponent.hpp>
62 #include <com/sun/star/lang/DisposedException.hpp>
69 using namespace com::sun::star
;
70 using namespace com::sun::star::uno
;
73 //==================================================================================================
74 sal_Bool
equals( const test::TestElement
& rData1
, const test::TestElement
& rData2
)
76 OSL_ENSURE( rData1
.Bool
== rData2
.Bool
, "### bool does not match!" );
77 OSL_ENSURE( rData1
.Char
== rData2
.Char
, "### char does not match!" );
78 OSL_ENSURE( rData1
.Byte
== rData2
.Byte
, "### byte does not match!" );
79 OSL_ENSURE( rData1
.Short
== rData2
.Short
, "### short does not match!" );
80 OSL_ENSURE( rData1
.UShort
== rData2
.UShort
, "### unsigned short does not match!" );
81 OSL_ENSURE( rData1
.Long
== rData2
.Long
, "### long does not match!" );
82 OSL_ENSURE( rData1
.ULong
== rData2
.ULong
, "### unsigned long does not match!" );
83 OSL_ENSURE( rData1
.Hyper
== rData2
.Hyper
, "### hyper does not match!" );
84 OSL_ENSURE( rData1
.UHyper
== rData2
.UHyper
, "### unsigned hyper does not match!" );
85 OSL_ENSURE( rData1
.Float
== rData2
.Float
, "### float does not match!" );
86 OSL_ENSURE( rData1
.Double
== rData2
.Double
, "### double does not match!" );
87 OSL_ENSURE( rData1
.Enum
== rData2
.Enum
, "### enum does not match!" );
88 OSL_ENSURE( rData1
.String
== rData2
.String
, "### string does not match!" );
89 OSL_ENSURE( rData1
.Interface
== rData2
.Interface
, "### interface does not match!" );
90 OSL_ENSURE( rData1
.Any
== rData2
.Any
, "### any does not match!" );
92 return (rData1
.Bool
== rData2
.Bool
&&
93 rData1
.Char
== rData2
.Char
&&
94 rData1
.Byte
== rData2
.Byte
&&
95 rData1
.Short
== rData2
.Short
&&
96 rData1
.UShort
== rData2
.UShort
&&
97 rData1
.Long
== rData2
.Long
&&
98 rData1
.ULong
== rData2
.ULong
&&
99 rData1
.Hyper
== rData2
.Hyper
&&
100 rData1
.UHyper
== rData2
.UHyper
&&
101 rData1
.Float
== rData2
.Float
&&
102 rData1
.Double
== rData2
.Double
&&
103 rData1
.Enum
== rData2
.Enum
&&
104 rData1
.String
== rData2
.String
&&
105 rData1
.Interface
== rData2
.Interface
&&
106 rData1
.Any
== rData2
.Any
);
108 //==================================================================================================
109 sal_Bool
equals( const test::TestData
& rData1
, const test::TestData
& rData2
)
113 if ((rData1
.Sequence
== rData2
.Sequence
) &&
114 equals( (const test::TestElement
&)rData1
, (const test::TestElement
&)rData2
) &&
115 (nLen
= rData1
.Sequence
.getLength()) == rData2
.Sequence
.getLength())
117 // once again by hand sequence ==
118 const test::TestElement
* pElements1
= rData1
.Sequence
.getConstArray();
119 const test::TestElement
* pElements2
= rData2
.Sequence
.getConstArray();
122 if (! equals( pElements1
[nLen
], pElements2
[nLen
] ))
124 OSL_ENSURE( sal_False
, "### sequence element did not match!" );
132 //==================================================================================================
133 void assign( test::TestElement
& rData
,
134 sal_Bool bBool
, sal_Unicode cChar
, sal_Int8 nByte
,
135 sal_Int16 nShort
, sal_uInt16 nUShort
,
136 sal_Int32 nLong
, sal_uInt32 nULong
,
137 sal_Int64 nHyper
, sal_uInt64 nUHyper
,
138 float fFloat
, double fDouble
,
139 test::TestEnum eEnum
, const ::rtl::OUString
& rStr
,
140 const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
>& xTest
,
141 const ::com::sun::star::uno::Any
& rAny
)
146 rData
.Short
= nShort
;
147 rData
.UShort
= nUShort
;
149 rData
.ULong
= nULong
;
150 rData
.Hyper
= nHyper
;
151 rData
.UHyper
= nUHyper
;
152 rData
.Float
= fFloat
;
153 rData
.Double
= fDouble
;
156 rData
.Interface
= xTest
;
159 //==================================================================================================
160 void assign( test::TestData
& rData
,
161 sal_Bool bBool
, sal_Unicode cChar
, sal_Int8 nByte
,
162 sal_Int16 nShort
, sal_uInt16 nUShort
,
163 sal_Int32 nLong
, sal_uInt32 nULong
,
164 sal_Int64 nHyper
, sal_uInt64 nUHyper
,
165 float fFloat
, double fDouble
,
166 test::TestEnum eEnum
, const ::rtl::OUString
& rStr
,
167 const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
>& xTest
,
168 const ::com::sun::star::uno::Any
& rAny
,
169 const com::sun::star::uno::Sequence
< test::TestElement
>& rSequence
)
171 assign( (test::TestElement
&)rData
,
172 bBool
, cChar
, nByte
, nShort
, nUShort
, nLong
, nULong
, nHyper
, nUHyper
, fFloat
, fDouble
,
173 eEnum
, rStr
, xTest
, rAny
);
174 rData
.Sequence
= rSequence
;
177 //==================================================================================================
178 class TestDummy
: public OWeakObject
181 sal_Int32
getRefCount() const
182 { return m_refCount
; }
185 { OSL_TRACE( "> scalar TestDummy dtor <\n" ); }
187 //==================================================================================================
188 class Test_Impl
: public cppu::WeakImplHelper1
< XLanguageBindingTest
>
190 test::TestData _aData
, _aStructData
;
193 sal_Int32
getRefCount() const
194 { return m_refCount
; }
197 { OSL_TRACE( "> scalar Test_Impl dtor <\n" ); }
200 virtual void SAL_CALL
setValues( sal_Bool bBool
, sal_Unicode cChar
, sal_Int8 nByte
,
201 sal_Int16 nShort
, sal_uInt16 nUShort
,
202 sal_Int32 nLong
, sal_uInt32 nULong
,
203 sal_Int64 nHyper
, sal_uInt64 nUHyper
,
204 float fFloat
, double fDouble
,
205 test::TestEnum eEnum
, const ::rtl::OUString
& rStr
,
206 const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
>& xTest
,
207 const ::com::sun::star::uno::Any
& rAny
,
208 const ::com::sun::star::uno::Sequence
<test::TestElement
>& rSequence
,
209 const test::TestData
& rStruct
)
210 throw(com::sun::star::uno::RuntimeException
);
212 virtual test::TestData SAL_CALL
setValues2( sal_Bool
& bBool
, sal_Unicode
& cChar
, sal_Int8
& nByte
,
213 sal_Int16
& nShort
, sal_uInt16
& nUShort
,
214 sal_Int32
& nLong
, sal_uInt32
& nULong
,
215 sal_Int64
& nHyper
, sal_uInt64
& nUHyper
,
216 float& fFloat
, double& fDouble
,
217 test::TestEnum
& eEnum
, rtl::OUString
& rStr
,
218 ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
>& xTest
,
219 ::com::sun::star::uno::Any
& rAny
,
220 ::com::sun::star::uno::Sequence
<test::TestElement
>& rSequence
,
221 test::TestData
& rStruct
)
222 throw(com::sun::star::uno::RuntimeException
);
224 virtual test::TestData SAL_CALL
getValues( sal_Bool
& bBool
, sal_Unicode
& cChar
, sal_Int8
& nByte
,
225 sal_Int16
& nShort
, sal_uInt16
& nUShort
,
226 sal_Int32
& nLong
, sal_uInt32
& nULong
,
227 sal_Int64
& nHyper
, sal_uInt64
& nUHyper
,
228 float& fFloat
, double& fDouble
,
229 test::TestEnum
& eEnum
, rtl::OUString
& rStr
,
230 ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
>& xTest
,
231 ::com::sun::star::uno::Any
& rAny
,
232 ::com::sun::star::uno::Sequence
< test::TestElement
>& rSequence
,
233 test::TestData
& rStruct
)
234 throw(com::sun::star::uno::RuntimeException
);
236 virtual test::SmallStruct
echoSmallStruct(const test::SmallStruct
& rStruct
) throw(com::sun::star::uno::RuntimeException
)
238 virtual test::MediumStruct
echoMediumStruct(const test::MediumStruct
& rStruct
) throw(com::sun::star::uno::RuntimeException
)
240 virtual test::BigStruct
echoBigStruct(const test::BigStruct
& rStruct
) throw(com::sun::star::uno::RuntimeException
)
242 virtual test::AllFloats
echoAllFloats(const test::AllFloats
& rStruct
) throw(com::sun::star::uno::RuntimeException
)
245 virtual sal_Bool SAL_CALL
getBool() throw(com::sun::star::uno::RuntimeException
)
246 { return _aData
.Bool
; }
247 virtual sal_Int8 SAL_CALL
getByte() throw(com::sun::star::uno::RuntimeException
)
248 { return _aData
.Byte
; }
249 virtual sal_Unicode SAL_CALL
getChar() throw(com::sun::star::uno::RuntimeException
)
250 { return _aData
.Char
; }
251 virtual sal_Int16 SAL_CALL
getShort() throw(com::sun::star::uno::RuntimeException
)
252 { return _aData
.Short
; }
253 virtual sal_uInt16 SAL_CALL
getUShort() throw(com::sun::star::uno::RuntimeException
)
254 { return _aData
.UShort
; }
255 virtual sal_Int32 SAL_CALL
getLong() throw(com::sun::star::uno::RuntimeException
)
256 { return _aData
.Long
; }
257 virtual sal_uInt32 SAL_CALL
getULong() throw(com::sun::star::uno::RuntimeException
)
258 { return _aData
.ULong
; }
259 virtual sal_Int64 SAL_CALL
getHyper() throw(com::sun::star::uno::RuntimeException
)
260 { return _aData
.Hyper
; }
261 virtual sal_uInt64 SAL_CALL
getUHyper() throw(com::sun::star::uno::RuntimeException
)
262 { return _aData
.UHyper
; }
263 virtual float SAL_CALL
getFloat() throw(com::sun::star::uno::RuntimeException
)
264 { return _aData
.Float
; }
265 virtual double SAL_CALL
getDouble() throw(com::sun::star::uno::RuntimeException
)
266 { return _aData
.Double
; }
267 virtual test::TestEnum SAL_CALL
getEnum() throw(com::sun::star::uno::RuntimeException
)
268 { return _aData
.Enum
; }
269 virtual rtl::OUString SAL_CALL
getString() throw(com::sun::star::uno::RuntimeException
)
270 { return _aData
.String
; }
271 virtual com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
> SAL_CALL
getInterface( ) throw(com::sun::star::uno::RuntimeException
)
272 { return _aData
.Interface
; }
273 virtual com::sun::star::uno::Any SAL_CALL
getAny() throw(com::sun::star::uno::RuntimeException
)
274 { return _aData
.Any
; }
275 virtual com::sun::star::uno::Sequence
< test::TestElement
> SAL_CALL
getSequence() throw(com::sun::star::uno::RuntimeException
)
276 { return _aData
.Sequence
; }
277 virtual test::TestData SAL_CALL
getStruct() throw(com::sun::star::uno::RuntimeException
)
278 { return _aStructData
; }
280 virtual void SAL_CALL
setBool( sal_Bool _bool
) throw(::com::sun::star::uno::RuntimeException
)
281 { _aData
.Bool
= _bool
; }
282 virtual void SAL_CALL
setByte( sal_Int8 _byte
) throw(::com::sun::star::uno::RuntimeException
)
283 { _aData
.Byte
= _byte
; }
284 virtual void SAL_CALL
setChar( sal_Unicode _char
) throw(::com::sun::star::uno::RuntimeException
)
285 { _aData
.Char
= _char
; }
286 virtual void SAL_CALL
setShort( sal_Int16 _short
) throw(::com::sun::star::uno::RuntimeException
)
287 { _aData
.Short
= _short
; }
288 virtual void SAL_CALL
setUShort( sal_uInt16 _ushort
) throw(::com::sun::star::uno::RuntimeException
)
289 { _aData
.UShort
= _ushort
; }
290 virtual void SAL_CALL
setLong( sal_Int32 _long
) throw(::com::sun::star::uno::RuntimeException
)
291 { _aData
.Long
= _long
; }
292 virtual void SAL_CALL
setULong( sal_uInt32 _ulong
) throw(::com::sun::star::uno::RuntimeException
)
293 { _aData
.ULong
= _ulong
; }
294 virtual void SAL_CALL
setHyper( sal_Int64 _hyper
) throw(::com::sun::star::uno::RuntimeException
)
295 { _aData
.Hyper
= _hyper
; }
296 virtual void SAL_CALL
setUHyper( sal_uInt64 _uhyper
) throw(::com::sun::star::uno::RuntimeException
)
297 { _aData
.UHyper
= _uhyper
; }
298 virtual void SAL_CALL
setFloat( float _float
) throw(::com::sun::star::uno::RuntimeException
)
299 { _aData
.Float
= _float
; }
300 virtual void SAL_CALL
setDouble( double _double
) throw(::com::sun::star::uno::RuntimeException
)
301 { _aData
.Double
= _double
; }
302 virtual void SAL_CALL
setEnum( test::TestEnum _enum
) throw(::com::sun::star::uno::RuntimeException
)
303 { _aData
.Enum
= _enum
; }
304 virtual void SAL_CALL
setString( const ::rtl::OUString
& _string
) throw(::com::sun::star::uno::RuntimeException
)
305 { _aData
.String
= _string
; }
306 virtual void SAL_CALL
setInterface( const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
>& _interface
) throw(::com::sun::star::uno::RuntimeException
)
307 { _aData
.Interface
= _interface
; }
308 virtual void SAL_CALL
setAny( const ::com::sun::star::uno::Any
& _any
) throw(::com::sun::star::uno::RuntimeException
)
309 { _aData
.Any
= _any
; }
310 virtual void SAL_CALL
setSequence( const ::com::sun::star::uno::Sequence
<test::TestElement
>& _sequence
) throw(::com::sun::star::uno::RuntimeException
)
311 { _aData
.Sequence
= _sequence
; }
312 virtual void SAL_CALL
setStruct( const test::TestData
& _struct
) throw(::com::sun::star::uno::RuntimeException
)
313 { _aStructData
= _struct
; }
315 // XLanguageBindingTest
316 virtual test::TestData SAL_CALL
raiseException( sal_Bool
& bBool
, sal_Unicode
& cChar
, sal_Int8
& nByte
, sal_Int16
& nShort
, sal_uInt16
& nUShort
, sal_Int32
& nLong
, sal_uInt32
& nULong
, sal_Int64
& nHyper
, sal_uInt64
& nUHyper
, float& fFloat
, double& fDouble
, test::TestEnum
& eEnum
, ::rtl::OUString
& aString
, ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
>& xInterface
, ::com::sun::star::uno::Any
& aAny
, ::com::sun::star::uno::Sequence
<test::TestElement
>& aSequence
,test::TestData
& aStruct
)
317 throw(::com::sun::star::lang::IllegalArgumentException
, ::com::sun::star::uno::RuntimeException
);
319 virtual sal_Int32 SAL_CALL
getRuntimeException() throw(::com::sun::star::uno::RuntimeException
);
320 virtual void SAL_CALL
setRuntimeException( sal_Int32 _runtimeexception
) throw(::com::sun::star::uno::RuntimeException
);
322 //__________________________________________________________________________________________________
323 void Test_Impl::setValues( sal_Bool bBool
, sal_Unicode cChar
, sal_Int8 nByte
,
324 sal_Int16 nShort
, sal_uInt16 nUShort
,
325 sal_Int32 nLong
, sal_uInt32 nULong
,
326 sal_Int64 nHyper
, sal_uInt64 nUHyper
,
327 float fFloat
, double fDouble
,
328 test::TestEnum eEnum
, const ::rtl::OUString
& rStr
,
329 const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
>& xTest
,
330 const ::com::sun::star::uno::Any
& rAny
,
331 const ::com::sun::star::uno::Sequence
<test::TestElement
>& rSequence
,
332 const test::TestData
& rStruct
)
333 throw(com::sun::star::uno::RuntimeException
)
336 bBool
, cChar
, nByte
, nShort
, nUShort
, nLong
, nULong
, nHyper
, nUHyper
, fFloat
, fDouble
,
337 eEnum
, rStr
, xTest
, rAny
, rSequence
);
338 _aStructData
= rStruct
;
340 //__________________________________________________________________________________________________
341 test::TestData
Test_Impl::setValues2( sal_Bool
& bBool
, sal_Unicode
& cChar
, sal_Int8
& nByte
,
342 sal_Int16
& nShort
, sal_uInt16
& nUShort
,
343 sal_Int32
& nLong
, sal_uInt32
& nULong
,
344 sal_Int64
& nHyper
, sal_uInt64
& nUHyper
,
345 float& fFloat
, double& fDouble
,
346 test::TestEnum
& eEnum
, rtl::OUString
& rStr
,
347 ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
>& xTest
,
348 ::com::sun::star::uno::Any
& rAny
,
349 ::com::sun::star::uno::Sequence
<test::TestElement
>& rSequence
,
350 test::TestData
& rStruct
)
351 throw(com::sun::star::uno::RuntimeException
)
354 bBool
, cChar
, nByte
, nShort
, nUShort
, nLong
, nULong
, nHyper
, nUHyper
, fFloat
, fDouble
,
355 eEnum
, rStr
, xTest
, rAny
, rSequence
);
356 _aStructData
= rStruct
;
359 //__________________________________________________________________________________________________
360 test::TestData
Test_Impl::getValues( sal_Bool
& bBool
, sal_Unicode
& cChar
, sal_Int8
& nByte
,
361 sal_Int16
& nShort
, sal_uInt16
& nUShort
,
362 sal_Int32
& nLong
, sal_uInt32
& nULong
,
363 sal_Int64
& nHyper
, sal_uInt64
& nUHyper
,
364 float& fFloat
, double& fDouble
,
365 test::TestEnum
& eEnum
, rtl::OUString
& rStr
,
366 ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
>& xTest
,
367 ::com::sun::star::uno::Any
& rAny
,
368 ::com::sun::star::uno::Sequence
<test::TestElement
>& rSequence
,
369 test::TestData
& rStruct
)
370 throw(com::sun::star::uno::RuntimeException
)
375 nShort
= _aData
.Short
;
376 nUShort
= _aData
.UShort
;
378 nULong
= _aData
.ULong
;
379 nHyper
= _aData
.Hyper
;
380 nUHyper
= _aData
.UHyper
;
381 fFloat
= _aData
.Float
;
382 fDouble
= _aData
.Double
;
384 rStr
= _aData
.String
;
385 xTest
= _aData
.Interface
;
387 rSequence
= _aData
.Sequence
;
388 rStruct
= _aStructData
;
392 //==================================================================================================
393 static sal_Bool
performTest(
394 const Reference
< XLanguageBindingTest
> & xLBT
,
395 const Reference
< XInterface
> & xDummyInterface
)
397 OSL_ENSURE( xLBT
.is() && xDummyInterface
.is(), "### no test interfaces!" );
398 if (xLBT
.is() && xDummyInterface
.is())
400 // this data is never ever granted access to by calls other than equals(), assign()!
401 test::TestData aData
; // test against this data
403 assign( (test::TestElement
&)aData
,
404 sal_True
, '@', 17, 0x1234, 0xfedc, 0x12345678, 0xfedcba98,
405 SAL_CONST_INT64(0x123456789abcdef0),
406 SAL_CONST_UINT64(0xfedcba9876543210),
407 (float)17.0815, 3.1415926359, TestEnum_LOLA
,
408 OUString::createFromAscii("dumdidum"), xDummyInterface
,
409 makeAny( xDummyInterface
) );
410 aData
.Sequence
= Sequence
<test::TestElement
>( (const test::TestElement
*)&aData
, 1 );
411 OSL_ENSURE( aData
.Any
== xDummyInterface
, "### unexpected any!" );
412 OSL_ENSURE( !(aData
.Any
!= xDummyInterface
), "### unexpected any!" );
414 // aData complete ==> never touched again
415 //================================================================================
417 // this is a manually copy of aData for first setting...
418 test::TestData
aSetData0( aData
); // copy ctor
420 test::TestData aSetData1
= aSetData0
;
422 test::TestData aSetData
;
423 assign( (test::TestElement
&)aSetData
,
424 aSetData1
.Bool
, aSetData1
.Char
, aSetData1
.Byte
, aSetData1
.Short
, aSetData1
.UShort
,
425 aSetData1
.Long
, aSetData1
.ULong
, aSetData1
.Hyper
, aSetData1
.UHyper
,
426 aSetData1
.Float
, aSetData1
.Double
,
427 aSetData1
.Enum
, aSetData1
.String
, aSetData1
.Interface
, aSetData1
.Any
);
428 // switch over to new sequence allocation
429 aSetData
.Sequence
= Sequence
<test::TestElement
>( (const test::TestElement
*)&aSetData
, 1 );
432 aSetData
.Bool
, aSetData
.Char
, aSetData
.Byte
, aSetData
.Short
, aSetData
.UShort
,
433 aSetData
.Long
, aSetData
.ULong
, aSetData
.Hyper
, aSetData
.UHyper
, aSetData
.Float
, aSetData
.Double
,
434 aSetData
.Enum
, aSetData
.String
, aSetData
.Interface
, aSetData
.Any
, aSetData
.Sequence
, aSetData
);
437 test::TestData aRet
, aRet2
;
439 aRet
.Bool
, aRet
.Char
, aRet
.Byte
, aRet
.Short
, aRet
.UShort
,
440 aRet
.Long
, aRet
.ULong
, aRet
.Hyper
, aRet
.UHyper
, aRet
.Float
, aRet
.Double
,
441 aRet
.Enum
, aRet
.String
, aRet
.Interface
, aRet
.Any
, aRet
.Sequence
, aRet2
);
443 OSL_ASSERT( equals( aData
, aRet
) && equals( aData
, aRet2
) );
445 // set last retrieved values
446 test::TestData aSV2ret
= xLBT
->setValues2(
447 aRet
.Bool
, aRet
.Char
, aRet
.Byte
, aRet
.Short
, aRet
.UShort
,
448 aRet
.Long
, aRet
.ULong
, aRet
.Hyper
, aRet
.UHyper
, aRet
.Float
, aRet
.Double
,
449 aRet
.Enum
, aRet
.String
, aRet
.Interface
, aRet
.Any
, aRet
.Sequence
, aRet2
);
451 OSL_ASSERT( equals( aData
, aSV2ret
) && equals( aData
, aRet2
) );
454 test::TestData aRet
, aRet2
;
455 test::TestData aGVret
= xLBT
->getValues(
456 aRet
.Bool
, aRet
.Char
, aRet
.Byte
, aRet
.Short
, aRet
.UShort
,
457 aRet
.Long
, aRet
.ULong
, aRet
.Hyper
, aRet
.UHyper
, aRet
.Float
, aRet
.Double
,
458 aRet
.Enum
, aRet
.String
, aRet
.Interface
, aRet
.Any
, aRet
.Sequence
, aRet2
);
460 OSL_ASSERT( equals( aData
, aRet
) && equals( aData
, aRet2
) && equals( aData
, aGVret
) );
462 // set last retrieved values
463 xLBT
->setBool( aRet
.Bool
);
464 xLBT
->setChar( aRet
.Char
);
465 xLBT
->setByte( aRet
.Byte
);
466 xLBT
->setShort( aRet
.Short
);
467 xLBT
->setUShort( aRet
.UShort
);
468 xLBT
->setLong( aRet
.Long
);
469 xLBT
->setULong( aRet
.ULong
);
470 xLBT
->setHyper( aRet
.Hyper
);
471 xLBT
->setUHyper( aRet
.UHyper
);
472 xLBT
->setFloat( aRet
.Float
);
473 xLBT
->setDouble( aRet
.Double
);
474 xLBT
->setEnum( aRet
.Enum
);
475 xLBT
->setString( aRet
.String
);
476 xLBT
->setInterface( aRet
.Interface
);
477 xLBT
->setAny( aRet
.Any
);
478 xLBT
->setSequence( aRet
.Sequence
);
479 xLBT
->setStruct( aRet2
);
482 test::TestData aRet
, aRet2
;
483 aRet
.Hyper
= xLBT
->getHyper();
484 aRet
.UHyper
= xLBT
->getUHyper();
485 aRet
.Float
= xLBT
->getFloat();
486 aRet
.Double
= xLBT
->getDouble();
487 aRet
.Byte
= xLBT
->getByte();
488 aRet
.Char
= xLBT
->getChar();
489 aRet
.Bool
= xLBT
->getBool();
490 aRet
.Short
= xLBT
->getShort();
491 aRet
.UShort
= xLBT
->getUShort();
492 aRet
.Long
= xLBT
->getLong();
493 aRet
.ULong
= xLBT
->getULong();
494 aRet
.Enum
= xLBT
->getEnum();
495 aRet
.String
= xLBT
->getString();
496 aRet
.Interface
= xLBT
->getInterface();
497 aRet
.Any
= xLBT
->getAny();
498 aRet
.Sequence
= xLBT
->getSequence();
499 aRet2
= xLBT
->getStruct();
501 OSL_ASSERT( equals( aData
, aRet
) && equals( aData
, aRet2
) );
504 test::SmallStruct
aIn(1, 2);
505 test::SmallStruct aOut
= xLBT
->echoSmallStruct(aIn
);
506 OSL_ASSERT( memcmp(&aIn
, &aOut
, sizeof(test::SmallStruct
)) == 0 );
509 test::MediumStruct
aIn(1, 2, 3, 4);
510 test::MediumStruct aOut
= xLBT
->echoMediumStruct(aIn
);
511 OSL_ASSERT( memcmp(&aIn
, &aOut
, sizeof(test::MediumStruct
)) == 0 );
514 test::BigStruct
aIn(1, 2, 3, 4, 5, 6, 7, 8);
515 test::BigStruct aOut
= xLBT
->echoBigStruct(aIn
);
516 OSL_ASSERT( memcmp(&aIn
, &aOut
, sizeof(test::BigStruct
)) == 0 );
519 test::AllFloats
aIn(1.1, 2.2, 3.3, 4.4);
520 test::AllFloats aOut
= xLBT
->echoAllFloats(aIn
);
521 return( memcmp(&aIn
, &aOut
, sizeof(test::AllFloats
)) == 0 );
527 //__________________________________________________________________________________________________
528 test::TestData
Test_Impl::raiseException( sal_Bool
& /*bBool*/, sal_Unicode
& /*cChar*/, sal_Int8
& /*nByte*/, sal_Int16
& /*nShort*/, sal_uInt16
& /*nUShort*/, sal_Int32
& /*nLong*/, sal_uInt32
& /*nULong*/, sal_Int64
& /*nHyper*/, sal_uInt64
& /*nUHyper*/, float& /*fFloat*/, double& /*fDouble*/, test::TestEnum
& /*eEnum*/, ::rtl::OUString
& /*aString*/, ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
>& /*xInterface*/, ::com::sun::star::uno::Any
& /*aAny*/, ::com::sun::star::uno::Sequence
< test::TestElement
>& /*aSequence*/, test::TestData
& /*aStruct*/ )
529 throw(::com::sun::star::lang::IllegalArgumentException
, ::com::sun::star::uno::RuntimeException
)
531 lang::IllegalArgumentException aExc
;
532 aExc
.ArgumentPosition
= 5;
533 aExc
.Message
= OUString::createFromAscii( "dum dum dum ich tanz im kreis herum..." );
534 aExc
.Context
= getInterface();
537 //__________________________________________________________________________________________________
538 sal_Int32
Test_Impl::getRuntimeException() throw(::com::sun::star::uno::RuntimeException
)
540 lang::DisposedException aExc
;
541 aExc
.Message
= OUString::createFromAscii( "dum dum dum ich tanz im kreis herum..." );
542 aExc
.Context
= getInterface();
545 //__________________________________________________________________________________________________
546 void Test_Impl::setRuntimeException( sal_Int32
/*_runtimeexception*/ ) throw(::com::sun::star::uno::RuntimeException
)
548 lang::DisposedException aExc
;
549 aExc
.Message
= OUString::createFromAscii( "dum dum dum ich tanz im kreis herum..." );
550 aExc
.Context
= getInterface();
554 static void raising1( const Reference
< XLanguageBindingTest
> & xLBT
)
556 test::TestData aRet
, aRet2
;
557 xLBT
->raiseException(
558 aRet
.Bool
, aRet
.Char
, aRet
.Byte
, aRet
.Short
, aRet
.UShort
,
559 aRet
.Long
, aRet
.ULong
, aRet
.Hyper
, aRet
.UHyper
, aRet
.Float
, aRet
.Double
,
560 aRet
.Enum
, aRet
.String
, aRet
.Interface
, aRet
.Any
, aRet
.Sequence
, aRet2
);
562 static void raising2( const Reference
< XLanguageBindingTest
> & xLBT
)
568 catch (RuntimeException
&)
576 //==================================================================================================
577 sal_Bool
raiseException( const Reference
< XLanguageBindingTest
> & xLBT
)
581 xLBT
->getRuntimeException();
583 catch (lang::DisposedException
& exc
)
585 OSL_ENSURE( exc
.Context
== xLBT
->getInterface() &&
586 exc
.Message
.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("dum dum dum ich tanz im kreis herum...") ),
587 "### unexpected exception content!" );
589 catch (RuntimeException
&)
601 sal_Int32 nCount
= 0;
610 catch (RuntimeException
&)
613 catch (lang::IllegalArgumentException aExc
)
616 OSL_ENSURE( aExc
.ArgumentPosition
== 5 &&
617 aExc
.Context
== xLBT
->getInterface() &&
618 aExc
.Message
.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("dum dum dum ich tanz im kreis herum...") ),
619 "### unexpected exception content!" );
621 /** it is certain, that the RuntimeException testing will fail, if no */
622 xLBT
->getRuntimeException();
625 catch (const RuntimeException
& rExc
)
628 OSL_ENSURE( rExc
.Context
== xLBT
->getInterface() &&
629 rExc
.Message
.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("dum dum dum ich tanz im kreis herum...") ),
630 "### unexpected exception content!" );
632 /** it is certain, that the RuntimeException testing will fail, if no */
633 xLBT
->setRuntimeException( 0xcafebabe );
635 catch (lang::IllegalArgumentException
&)
639 catch (Exception
& rExc
)
642 OSL_ENSURE( rExc
.Context
== xLBT
->getInterface() &&
643 rExc
.Message
.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("dum dum dum ich tanz im kreis herum...") ),
644 "### unexpected exception content!" );
645 return (nCount
== 3 &&
646 rExc
.Context
== xLBT
->getInterface() &&
647 rExc
.Message
.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("dum dum dum ich tanz im kreis herum...") ));
652 //==================================================================================================
653 static void checkInvalidInterfaceQuery(
654 Reference
< XInterface
> const & xObj
)
658 Any
aRet( xObj
->queryInterface( ::getCppuType( (const lang::IllegalArgumentException
*)0 ) ) );
659 OSL_ASSERT( ! aRet
.hasValue() );
661 catch (RuntimeException
&)
666 Reference
< lang::XComponent
> xComp( xObj
, UNO_QUERY_THROW
);
669 catch (RuntimeException
& /*exc*/)
671 // OString str( OUStringToOString( exc.Message, RTL_TEXTENCODING_ASCII_US ) );
672 // OSL_TRACE( str.getStr() );
676 //==================================================================================================
677 static bool perform_test(
678 Reference
< XLanguageBindingTest
> const & xObj
,
679 Reference
< XInterface
> const & xDummy
)
681 checkInvalidInterfaceQuery( xObj
);
683 if (performTest( xObj
, xDummy
))
685 ::fprintf( stderr
, "> invocation test succeeded!\n" );
686 if (raiseException( xObj
))
688 ::fprintf( stderr
, "> exception test succeeded!\n" );
693 ::fprintf( stderr
, "> exception test failed!\n" );
697 ::fprintf( stderr
, "> dynamic invocation test failed!\n" );
701 //==================================================================================================
702 void test_CppBridge(void)
706 TestDummy
* p
= new TestDummy();
707 Reference
< XInterface
> xDummy( *p
);
709 Test_Impl
* p2
= new Test_Impl();
710 Reference
< XLanguageBindingTest
> xOriginal( p2
);
711 checkInvalidInterfaceQuery( xOriginal
);
713 const char * pExtraMapping
= "";
715 Reference
< XLanguageBindingTest
> xMapped
;
717 uno_Interface
* pUnoI
= 0;
719 OUString
aCppEnvTypeName( RTL_CONSTASCII_USTRINGPARAM(CPPU_CURRENT_LANGUAGE_BINDING_NAME
) );
720 OUString
aUnoEnvTypeName( RTL_CONSTASCII_USTRINGPARAM(UNO_LB_UNO
) );
722 uno_Environment
* pCppEnv
= 0;
723 uno_Environment
* pUnoEnv
= 0;
724 ::uno_getEnvironment( &pCppEnv
, aCppEnvTypeName
.pData
, 0 );
725 ::uno_getEnvironment( &pUnoEnv
, aUnoEnvTypeName
.pData
, 0 );
728 Mapping
mapping( pCppEnv
, pUnoEnv
);
729 mapping
.mapInterface( (void **)&pUnoI
, xOriginal
.get(), ::getCppuType( &xOriginal
) );
733 ::uno_createEnvironment( &pCppEnv
, aCppEnvTypeName
.pData
, 0 );
734 mapping
= Mapping( pUnoEnv
, pCppEnv
);
735 mapping
.mapInterface( (void **)&xMapped
, pUnoI
, ::getCppuType( &xMapped
) );
736 // ano C++a -> ano UNOa
737 ::uno_createEnvironment( &pUnoEnv
, aUnoEnvTypeName
.pData
, 0 );
738 mapping
= Mapping( pCppEnv
, pUnoEnv
);
739 mapping
.mapInterface( (void **)&pUnoI
, xMapped
.get(), ::getCppuType( &xMapped
) );
740 pExtraMapping
= " <-> c++ <-> uno";
743 // ano UNOa -> ano C++b
744 ::uno_createEnvironment( &pCppEnv
, aCppEnvTypeName
.pData
, 0 );
745 mapping
= Mapping( pUnoEnv
, pCppEnv
);
746 mapping
.mapInterface( (void **)&xMapped
, pUnoI
, ::getCppuType( &xMapped
) );
747 (*pUnoI
->release
)( pUnoI
);
748 (*pCppEnv
->release
)( pCppEnv
);
749 (*pUnoEnv
->release
)( pUnoEnv
);
752 if (perform_test( xMapped
, xDummy
))
754 ::fprintf( stderr
, "> C++-UNO test (c++ <-> uno%s <-> c++ [component impl]) succeeded!\n", pExtraMapping
);
758 ::fprintf( stderr
, "> C++-UNO test (c++ <-> uno%s <-> c++ [component impl]) failed!\n", pExtraMapping
);
762 OSL_ENSURE( p2
->getRefCount() == 1, "### test object ref count > 1 !" );
764 OSL_ENSURE( p
->getRefCount() == 1, "### dummy object ref count > 1 !" );
768 //==================================================================================================
769 void test_CBridge(void)
773 TestDummy
* p
= new TestDummy();
774 Reference
< XInterface
> xDummy( *p
);
776 Test_Impl
* p2
= new Test_Impl();
777 Reference
< XLanguageBindingTest
> xOriginal( p2
);
778 checkInvalidInterfaceQuery( xOriginal
);
780 Reference
< XLanguageBindingTest
> xMapped
;
782 uno_Interface
* pUnoI2
= 0;
784 uno_Interface
* pUnoI1
= 0;
786 OUString
aCppEnvTypeName( RTL_CONSTASCII_USTRINGPARAM(CPPU_CURRENT_LANGUAGE_BINDING_NAME
) );
787 OUString
aCEnvTypeName( RTL_CONSTASCII_USTRINGPARAM(UNO_LB_C
) );
788 OUString
aUnoEnvTypeName( RTL_CONSTASCII_USTRINGPARAM(UNO_LB_UNO
) );
791 uno_Environment
* pCppEnv
= 0;
792 uno_Environment
* pUnoEnv
= 0;
793 ::uno_getEnvironment( &pCppEnv
, aCppEnvTypeName
.pData
, 0 );
794 ::uno_getEnvironment( &pUnoEnv
, aUnoEnvTypeName
.pData
, 0 );
795 Mapping
aCpp2Uno( pCppEnv
, pUnoEnv
);
796 aCpp2Uno
.mapInterface( (void **)&pUnoI1
, xOriginal
.get(), ::getCppuType( &xOriginal
) );
797 (*pCppEnv
->release
)( pCppEnv
);
800 uno_Environment
* pCEnv
= 0;
801 ::uno_getEnvironment( &pCEnv
, aCEnvTypeName
.pData
, 0 );
802 Mapping
aUno2C( pUnoEnv
, pCEnv
);
803 aUno2C
.mapInterface( &pC
, pUnoI1
, ::getCppuType( &xOriginal
) );
804 (*pUnoI1
->release
)( pUnoI1
);
805 (*pUnoEnv
->release
)( pUnoEnv
);
808 uno_Environment
* pAnoUnoEnv
= 0;
809 ::uno_createEnvironment( &pAnoUnoEnv
, aUnoEnvTypeName
.pData
, 0 ); // anonymous
810 Mapping
aC2Uno( pCEnv
, pAnoUnoEnv
);
811 aC2Uno
.mapInterface( (void **)&pUnoI2
, pC
, ::getCppuType( &xOriginal
) );
812 (*pCEnv
->pExtEnv
->releaseInterface
)( pCEnv
->pExtEnv
, pC
);
813 (*pCEnv
->release
)( pCEnv
);
815 // ano UNO -> ano C++
816 uno_Environment
* pAnoCppEnv
= 0;
817 ::uno_createEnvironment( &pAnoCppEnv
, aCppEnvTypeName
.pData
, 0 );
818 Mapping
aUno2Cpp( pAnoUnoEnv
, pAnoCppEnv
);
819 (*pAnoCppEnv
->release
)( pAnoCppEnv
);
820 (*pAnoUnoEnv
->release
)( pAnoUnoEnv
);
821 aUno2Cpp
.mapInterface( (void **)&xMapped
, pUnoI2
, ::getCppuType( &xOriginal
) );
822 (*pUnoI2
->release
)( pUnoI2
);
825 if (perform_test( xMapped
, xDummy
))
827 ::fprintf( stderr
, "> C-UNO test (c++ <-> uno <-> c <-> uno <-> c++ [component impl]) succeeded!\n" );
831 ::fprintf( stderr
, "> C-UNO test (c++ <-> uno <-> c <-> uno <-> c++ [component impl]) failed!\n" );
835 OSL_ENSURE( p
->getRefCount() == 1, "### test object ref count > 1 !" );
837 OSL_ENSURE( p
->getRefCount() == 1, "### dummy object ref count > 1 !" );
841 //==================================================================================================
842 extern "C" com_sun_star_uno_XInterface
* SAL_CALL
createTestObject();
844 void test_CBridge2(void)
848 TestDummy
* p
= new TestDummy();
849 Reference
< XInterface
> xDummy( *p
);
851 com_sun_star_uno_XInterface
* pXIface
= createTestObject();
852 test_XLanguageBindingTest
* pXLBTest
= 0;
854 Reference
< XLanguageBindingTest
> xMapped
;
856 OSL_ENSURE( pXIface
!= 0, "create test object failed\n");
858 /* Get interface XFoo2 */
859 if (CUNO_EXCEPTION_OCCURED( CUNO_CALL(pXIface
)->queryInterface( pXIface
, &aExc
, (com_sun_star_uno_XInterface
**)&pXLBTest
, ::getCppuType( &xMapped
).getTypeLibType()) ))
861 uno_any_destruct( &aExc
, 0 );
863 OSL_ENSURE( pXLBTest
!= 0, "query_Interface XLanguageBindingTest failed\n");
866 OUString( RTL_CONSTASCII_USTRINGPARAM(UNO_LB_C
) ),
867 OUString( RTL_CONSTASCII_USTRINGPARAM(CPPU_CURRENT_LANGUAGE_BINDING_NAME
) ) );
868 aC2Cpp
.mapInterface( (void **)&xMapped
, pXLBTest
, ::getCppuType( &xMapped
) );
870 OSL_ENSURE( xMapped
.is(), "mapping interface failed\n");
872 if (perform_test( xMapped
, xDummy
))
874 ::fprintf( stderr
, "> second C-UNO test (c++ <-> uno <-> c [component impl]) succeeded!\n" );
878 ::fprintf( stderr
, "> second C-UNO test (c++ <-> uno <-> c [component impl]) failed!\n" );
883 CUNO_CALL(pXIface
)->release( pXIface
);
884 CUNO_CALL(pXLBTest
)->release( (com_sun_star_uno_XInterface
*)pXLBTest
);
886 OSL_ENSURE( p
->getRefCount() == 1, "### dummy object ref count > 1 !" );