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: testcppu.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"
43 #include <uno/environment.h>
44 #include <uno/mapping.hxx>
46 #include <uno/dispatcher.h>
47 #include <rtl/alloc.h>
48 #include <rtl/unload.h>
50 #include <cppuhelper/queryinterface.hxx>
51 #include <com/sun/star/uno/Exception.hpp>
52 #include <com/sun/star/uno/XInterface.hpp>
53 #include <com/sun/star/uno/Uik.hpp>
54 #include <rtl/ustring.hxx>
55 #include <osl/diagnose.h>
56 #include <osl/interlck.h>
57 #include <sal/types.h>
59 #include <test/Test1.hpp>
60 #include <test/Test2.hpp>
61 #include <test/TdTest1.hpp>
62 #include <test/Test3.hpp>
63 #include <test/Base.hpp>
64 #include <test/Base1.hpp>
65 #include <test/Base2.hpp>
67 #include <uno/current_context.hxx>
68 #include <cppuhelper/bootstrap.hxx>
69 #include <cppuhelper/implbase1.hxx>
71 #include <com/sun/star/lang/XComponent.hpp>
72 #include <com/sun/star/container/XHierarchicalNameAccess.hpp>
73 #include <com/sun/star/uno/XCurrentContext.hpp>
74 #include <com/sun/star/beans/XPropertySet.hpp>
75 #include <com/sun/star/beans/PropertyValue.hpp>
76 #include <test/XSimpleInterface.hpp>
77 #include <test/XLanguageBindingTest.hpp>
78 #include <com/sun/star/registry/XSimpleRegistry.hpp>
84 using namespace com::sun::star
;
85 using namespace com::sun::star::uno
;
86 using namespace com::sun::star::lang
;
87 using namespace com::sun::star::registry
;
91 sal_Int32
getSize( const Type
& rT
)
94 typelib_TypeDescription
* pTD
= 0;
95 typelib_typedescriptionreference_getDescription( &pTD
, rT
.getTypeLibType() );
97 typelib_typedescription_release( pTD
);
108 // the following don't compile, which is ok:
109 a
.get
<sal_Unicode
>();
111 a
.has
<sal_Unicode
>();
113 Any
a_( static_cast<sal_Unicode
>('a') );
115 OSL_ASSERT( a
.getValueTypeClass() == TypeClass_BOOLEAN
);
116 OSL_ASSERT( !a
.get
<bool>() && !a
.get
<sal_Bool
>() );
118 OSL_ASSERT( a
.getValueTypeClass() == TypeClass_BOOLEAN
);
119 OSL_ASSERT( !a
.get
<bool>() && !a
.get
<sal_Bool
>() );
121 OSL_ASSERT( a
.getValueTypeClass() == TypeClass_BOOLEAN
);
122 OSL_ASSERT( !a
.get
<bool>() && !a
.get
<sal_Bool
>() );
123 Any
b( static_cast<sal_Int8
>(32) );
124 OSL_ASSERT( b
.getValueTypeClass() == TypeClass_BYTE
);
125 OSL_ASSERT( b
.get
<sal_Int64
>() == 32 &&
126 b
.get
<sal_uInt64
>() == 32 &&
127 b
.get
<sal_Int32
>() == 32 &&
128 b
.get
<sal_uInt32
>() == 32 &&
129 b
.get
<sal_Int16
>() == 32 &&
130 b
.get
<sal_Int8
>() == 32 );
131 OSL_ASSERT( b
.has
<sal_Int64
>() &&
132 b
.has
<sal_uInt64
>() &&
133 b
.has
<sal_Int32
>() &&
134 b
.has
<sal_uInt32
>() &&
135 b
.has
<sal_Int16
>() &&
138 OSL_ASSERT( b
.getValueTypeClass() == TypeClass_BOOLEAN
);
139 OSL_ASSERT( b
.get
<bool>() && b
.get
<sal_Bool
>() );
144 catch (RuntimeException
& /*exc*/) {
148 const Sequence
<beans::PropertyValue
> seq(
149 b
.get
< Sequence
<beans::PropertyValue
> >() );
152 catch (RuntimeException
& /*exc*/) {
156 sal_Int32 big
= 0x7fffffff;
159 Sequence
< Sequence
< Any
> > seq( big
);
161 catch (::std::bad_alloc
&)
166 Sequence
< Sequence
< Any
> > seq( 0, big
);
168 catch (::std::bad_alloc
&)
173 Sequence
< Sequence
< Any
> > seq
;
176 catch (::std::bad_alloc
&)
181 // test the size of types
182 OSL_ENSURE( sizeof( Uik
) == getSize( getCppuType( (Uik
*)0) ),
184 OSL_ENSURE( sizeof( Test1
) == getSize( getCppuType( (Test1
*)0).getTypeLibType() ),
185 "bad sizeof test1" );
186 // OSL_ENSURE( sizeof( TdTest1 ) == getSize( get_test_TdTest1_Type().getTypeLibType() ),
187 // "bad sizeof TypedefTest1" );
188 OSL_ENSURE( sizeof( Test2
) == getSize( getCppuType( (Test2
*)0).getTypeLibType() ),
189 "bad sizeof test2" );
193 nPos = (sal_Int32)&((Test3 *)0)->nInt8;
194 nPos = (sal_Int32)&((Test3 *)0)->nFloat;
195 nPos = (sal_Int32)&((Test3 *)0)->nuInt8;
196 nPos = (sal_Int32)&((Test3 *)0)->nDouble;
197 nPos = (sal_Int32)&((Test3 *)0)->nInt16;
198 nPos = (sal_Int32)&((Test3 *)0)->aString;
199 nPos = (sal_Int32)&((Test3 *)0)->nuInt16;
200 nPos = (sal_Int32)&((Test3 *)0)->nInt64;
201 nPos = (sal_Int32)&((Test3 *)0)->nInt32;
202 nPos = (sal_Int32)&((Test3 *)0)->nuInt64;
203 nPos = (sal_Int32)&((Test3 *)0)->nuInt32;
204 nPos = (sal_Int32)&((Test3 *)0)->eType;
205 nPos = (sal_Int32)&((Test3 *)0)->wChar;
206 nPos = (sal_Int32)&((Test3 *)0)->td;
207 nPos = (sal_Int32)&((Test3 *)0)->bBool;
208 nPos = (sal_Int32)&((Test3 *)0)->aAny;
210 OSL_ENSURE( sizeof( Test3
) == getSize( getCppuType( (Test3
*)0).getTypeLibType() ),
211 "bad sizeof test3" );
215 // test the default constructor
220 uno_type_constructData( &a1
, getCppuType( (Test1
*)0).getTypeLibType() );
221 OSL_ASSERT( a1
.nInt16
== 0 && a1
.dDouble
== 0.0 && a1
.bBool
== sal_False
);
225 a2
.aTest1
.nInt16
= 4;
226 a2
.aTest1
.dDouble
= 3.6;
227 a2
.aTest1
.dDouble
= sal_True
;
228 uno_type_constructData( &a2
, getCppuType( (Test2
*)0).getTypeLibType() );
229 OSL_ASSERT( a2
.nInt16
== 0 && a2
.aTest1
.nInt16
== 0 && a2
.aTest1
.dDouble
== 0.0 && a2
.aTest1
.bBool
== sal_False
);
231 Test3
* pa3
= (Test3
*)new char[ sizeof( Test3
) ];
234 a3
.nFloat
= (float)2;
242 a3
.eType
= TypeClass_STRUCT
;
247 uno_type_constructData( &a3
, getCppuType( (Test3
*)0).getTypeLibType() );
248 OSL_ASSERT( a3
.nInt8
== 0 && a3
.nFloat
== (float)0
249 && a3
.nDouble
== 0 && a3
.nInt16
== 0 && a3
.aString
== OUString()
250 && a3
.nuInt16
== 0 && a3
.nInt64
== 0 && a3
.nInt32
== 0
251 && a3
.nuInt64
== 0 && a3
.nuInt32
== 0 && a3
.eType
== TypeClass_VOID
252 && a3
.wChar
== L
'\0' && a3
.td
.nInt16
== 0 && a3
.td
.dDouble
== 0
253 && a3
.bBool
== sal_False
);
254 OSL_ASSERT( a3
.aAny
.getValueType() == getCppuVoidType() );
255 delete[] reinterpret_cast< char * >(pa3
);
259 // test the destructor
260 long a1
[ sizeof( Test1
) / sizeof(long) +1 ];
261 uno_type_constructData( &a1
, getCppuType( (Test1
*)0).getTypeLibType() );
262 uno_type_destructData( &a1
, getCppuType( (Test1
*)0).getTypeLibType(), reinterpret_cast<uno_ReleaseFunc
>(cpp_release
) );
264 long a2
[ sizeof( Test2
) / sizeof(long) +1 ];
265 uno_type_constructData( &a2
, getCppuType( (Test2
*)0).getTypeLibType() );
266 uno_type_destructData( &a2
, getCppuType( (Test2
*)0).getTypeLibType(), reinterpret_cast<uno_ReleaseFunc
>(cpp_release
) );
268 long a3
[ sizeof( Test3
) / sizeof(long) +1 ];
269 uno_type_constructData( &a3
, getCppuType( (Test3
*)0).getTypeLibType() );
270 OUString
aTestString( RTL_CONSTASCII_USTRINGPARAM("test") );
271 ((Test3
*)a3
)->aString
= aTestString
;
272 uno_type_destructData( &a3
, getCppuType( (Test3
*)0).getTypeLibType(), reinterpret_cast<uno_ReleaseFunc
>(cpp_release
) );
273 OSL_ASSERT( aTestString
.pData
->refCount
== 1 );
277 // test the copy constructor
282 char sz1
[sizeof( Test1
)];
283 uno_type_copyData( sz1
, &a1
, getCppuType( (Test1
*)0).getTypeLibType(), reinterpret_cast<uno_AcquireFunc
>(cpp_acquire
) );
284 OSL_ASSERT( ((Test1
*)sz1
)->nInt16
== 4 && ((Test1
*)sz1
)->dDouble
== 3.6 && ((Test1
*)sz1
)->bBool
== sal_True
);
288 a2
.aTest1
.nInt16
= 4;
289 a2
.aTest1
.dDouble
= 3.6;
290 a2
.aTest1
.bBool
= sal_True
;
291 char sz2
[sizeof( Test2
)];
292 uno_type_copyData( sz2
, &a2
, getCppuType( (Test2
*)0).getTypeLibType(),
293 reinterpret_cast<uno_AcquireFunc
>(cpp_acquire
) );
294 OSL_ASSERT( ((Test2
*)sz2
)->nInt16
== 2 );
295 OSL_ASSERT(((Test2
*)sz2
)->aTest1
.nInt16
== 4 );
296 OSL_ASSERT( ((Test2
*)sz2
)->aTest1
.dDouble
== 3.6 );
297 OSL_ASSERT(((Test2
*)sz2
)->aTest1
.bBool
== sal_True
);
301 a3
.nFloat
= (float)2;
304 a3
.aString
= OUString::createFromAscii("2");
310 a3
.eType
= TypeClass_STRUCT
;
315 a3
.aAny
= makeAny( (sal_Int32
)2 );
316 char sz3
[sizeof( Test3
)];
317 uno_type_copyData( sz3
, &a3
, getCppuType( (Test3
*)0).getTypeLibType(),
318 reinterpret_cast<uno_AcquireFunc
>(cpp_acquire
) );
319 OSL_ASSERT( ((Test3
*)sz3
)->nInt8
== 2 );
320 OSL_ASSERT( ((Test3
*)sz3
)->nFloat
== (float)2 );
321 OSL_ASSERT( ((Test3
*)sz3
)->nDouble
== 2 );
322 OSL_ASSERT( ((Test3
*)sz3
)->nInt16
== 2 );
323 OSL_ASSERT( ((Test3
*)sz3
)->aString
== OUString::createFromAscii("2") );
324 OSL_ASSERT( ((Test3
*)sz3
)->nuInt16
== 2 );
325 OSL_ASSERT( ((Test3
*)sz3
)->nInt64
== 2 );
326 OSL_ASSERT( ((Test3
*)sz3
)->nInt32
== 2 );
327 OSL_ASSERT( ((Test3
*)sz3
)->nuInt64
== 2 );
328 OSL_ASSERT( ((Test3
*)sz3
)->nuInt32
== 2 );
329 OSL_ASSERT( ((Test3
*)sz3
)->eType
== TypeClass_STRUCT
);
330 OSL_ASSERT( ((Test3
*)sz3
)->wChar
== L
'2' );
331 OSL_ASSERT( ((Test3
*)sz3
)->td
.nInt16
== 2 );
332 OSL_ASSERT( ((Test3
*)sz3
)->td
.dDouble
== 2 );
333 OSL_ASSERT( ((Test3
*)sz3
)->bBool
== sal_True
);
334 OSL_ASSERT( ((Test3
*)sz3
)->aAny
.getValueType() == getCppuType( (sal_Int32
*)0 ) );
335 OSL_ASSERT( *(sal_Int32
*)((Test3
*)sz3
)->aAny
.getValue() == 2 );
336 ((Test3
*)sz3
)->~Test3();
340 sal_Bool bAssignable
;
347 bAssignable
= uno_type_assignData(
348 &sz1
, getCppuType( (Test1
*)0).getTypeLibType(),
349 &a1
, getCppuType( (Test1
*)0).getTypeLibType(),
350 reinterpret_cast<uno_QueryInterfaceFunc
>(cpp_queryInterface
),
351 reinterpret_cast<uno_AcquireFunc
>(cpp_acquire
),
352 reinterpret_cast<uno_ReleaseFunc
>(cpp_release
) );
353 OSL_ASSERT( bAssignable
);
354 OSL_ASSERT( sz1
.nInt16
== 4 && sz1
.dDouble
== 3.6 && sz1
.bBool
== sal_True
);
358 a2
.aTest1
.nInt16
= 4;
359 a2
.aTest1
.dDouble
= 3.6;
360 a2
.aTest1
.bBool
= sal_True
;
362 bAssignable
= uno_type_assignData(
363 &sz2
, getCppuType( (Test2
*)0).getTypeLibType(),
364 &a2
, getCppuType( (Test2
*)0).getTypeLibType(),
365 reinterpret_cast<uno_QueryInterfaceFunc
>(cpp_queryInterface
),
366 reinterpret_cast<uno_AcquireFunc
>(cpp_acquire
),
367 reinterpret_cast<uno_ReleaseFunc
>(cpp_release
) );
368 OSL_ASSERT( bAssignable
);
369 OSL_ASSERT( sz2
.nInt16
== 2 && sz2
.aTest1
.nInt16
== 4
370 && sz2
.aTest1
.dDouble
== 3.6 && sz2
.aTest1
.bBool
== sal_True
);
375 a3
.nFloat
= (float)2;
378 a3
.aString
= OUString::createFromAscii("2");
384 a3
.eType
= TypeClass_STRUCT
;
389 a3
.aAny
= makeAny( (sal_Int32
)2 );
390 OSL_ASSERT( a3
.aAny
.isExtractableTo( ::getCppuType( (sal_Int64
const *)0 ) ) );
391 OSL_ASSERT( ::getCppuType( (sal_Int64
const *)0 ).isAssignableFrom( a3
.aAny
.getValueType() ) );
392 bAssignable
= uno_type_assignData(
393 &sz3
, getCppuType( (Test3
*)0).getTypeLibType(),
394 &a3
, getCppuType( (Test3
*)0).getTypeLibType(),
395 reinterpret_cast<uno_QueryInterfaceFunc
>(cpp_queryInterface
),
396 reinterpret_cast<uno_AcquireFunc
>(cpp_acquire
),
397 reinterpret_cast<uno_ReleaseFunc
>(cpp_release
) );
398 OSL_ASSERT( bAssignable
);
399 OSL_ASSERT( sz3
.nInt8
== 2 );
400 OSL_ASSERT( sz3
.nFloat
== (float)2 );
401 OSL_ASSERT( sz3
.nDouble
== 2 );
402 OSL_ASSERT( sz3
.nInt16
== 2 );
403 OSL_ASSERT( sz3
.aString
== OUString::createFromAscii("2") );
404 OSL_ASSERT( sz3
.nuInt16
== 2 );
405 OSL_ASSERT( sz3
.nInt64
== 2 );
406 OSL_ASSERT( sz3
.nInt32
== 2 );
407 OSL_ASSERT( sz3
.nuInt64
== 2 );
408 OSL_ASSERT( sz3
.nuInt32
== 2 );
409 OSL_ASSERT( sz3
.eType
== TypeClass_STRUCT
);
410 OSL_ASSERT( sz3
.wChar
== L
'2' );
411 OSL_ASSERT( sz3
.td
.nInt16
== 2 );
412 OSL_ASSERT( sz3
.td
.dDouble
== 2 );
413 OSL_ASSERT( sz3
.bBool
== sal_True
);
414 OSL_ASSERT( sz3
.aAny
.getValueType() == getCppuType( (sal_Int32
*)0 ) );
415 OSL_ASSERT( *(sal_Int32
*)sz3
.aAny
.getValue() == 2 );
417 // test not assigneable values
418 bAssignable
= uno_type_assignData(
419 &a1
, getCppuType( (Test1
*)0).getTypeLibType(),
420 &a2
, getCppuType( (Test2
*)0).getTypeLibType(),
421 reinterpret_cast<uno_QueryInterfaceFunc
>(cpp_queryInterface
),
422 reinterpret_cast<uno_AcquireFunc
>(cpp_acquire
), reinterpret_cast<uno_ReleaseFunc
>(cpp_release
) );
423 OSL_ASSERT( !bAssignable
);
430 OSL_ASSERT( tb
.getValueType() == ::getCppuBooleanType() );
431 OSL_ASSERT( tb
== makeAny( true ) );
432 Any aAny
= makeAny( (sal_Int8
)2 );
433 OSL_ASSERT( aAny
.getValueType() == getCppuType( (sal_Int8
*)0 ) );
434 OSL_ASSERT( *(sal_Int8
*)aAny
.getValue() == 2 );
435 aAny
= makeAny( (float)2 );
436 OSL_ASSERT( aAny
.getValueType() == getCppuType( (float *)0 ) );
437 OSL_ASSERT( *(float*)aAny
.getValue() == (float)2 );
438 aAny
= makeAny( (sal_Int8
)2 );
439 OSL_ASSERT( aAny
.getValueType() == getCppuType( (sal_Int8
*)0 ) );
440 OSL_ASSERT( *(sal_Int8
*)aAny
.getValue() == 2 );
441 aAny
= makeAny( (double)2 );
442 OSL_ASSERT( aAny
.getValueType() == getCppuType( (double *)0 ) );
443 OSL_ASSERT( *(double*)aAny
.getValue() == (double)2 );
444 aAny
= makeAny( (sal_Int16
)2 );
445 OSL_ASSERT( aAny
.getValueType() == getCppuType( (sal_Int16
*)0 ) );
446 OSL_ASSERT( *(sal_Int16
*)aAny
.getValue() == 2 );
447 aAny
= makeAny( OUString( RTL_CONSTASCII_USTRINGPARAM("test") ) );
448 OSL_ASSERT( aAny
.getValueType() == getCppuType( (OUString
*)0 ) );
449 OSL_ASSERT( *(OUString
*)aAny
.getValue() == OUString::createFromAscii("test") );
450 aAny
= makeAny( (sal_uInt16
)2 );
451 OSL_ASSERT( aAny
.getValueType() == getCppuType( (sal_uInt16
*)0 ) );
452 OSL_ASSERT( *(sal_Int16
*)aAny
.getValue() == 2 );
453 sal_Int64 aInt64
= SAL_CONST_INT64(0x200000000);
454 aAny
= makeAny( aInt64
);
455 OSL_ASSERT( aAny
.getValueType() == getCppuType( (sal_Int64
*)0 ) );
456 OSL_ASSERT( *(sal_Int64
*)aAny
.getValue() == SAL_CONST_INT64(0x200000000) );
457 aAny
= makeAny( (sal_Int32
)2 );
458 OSL_ASSERT( aAny
.getValueType() == getCppuType( (sal_Int32
*)0 ) );
459 OSL_ASSERT( *(sal_Int32
*)aAny
.getValue() == 2 );
460 sal_uInt64 auInt64
= SAL_CONST_UINT64(0x200000000);
461 aAny
= makeAny( auInt64
);
462 OSL_ASSERT( aAny
.getValueType() == getCppuType( (sal_uInt64
*)0 ) );
463 OSL_ASSERT( *(sal_uInt64
*)aAny
.getValue() == SAL_CONST_UINT64(0x200000000) );
464 aAny
= makeAny( (sal_uInt32
)2 );
465 OSL_ASSERT( aAny
.getValueType() == getCppuType( (sal_uInt32
*)0 ) );
466 OSL_ASSERT( *(sal_uInt32
*)aAny
.getValue() == 2 );
467 aAny
= makeAny( TypeClass_STRUCT
);
468 OSL_ASSERT( aAny
.getValueType() == getCppuType( (TypeClass
*)0 ) );
469 OSL_ASSERT( *(TypeClass
*)aAny
.getValue() == TypeClass_STRUCT
);
470 sal_Unicode c
= L
'2';
471 aAny
.setValue( &c
, getCppuCharType() );
472 OSL_ASSERT( aAny
.getValueType() == getCppuCharType() );
473 OSL_ASSERT( *(sal_Unicode
*)aAny
.getValue() == L
'2' );
474 sal_Bool b2
= sal_True
;
475 aAny
.setValue( &b2
, getCppuBooleanType() );
476 OSL_ASSERT( aAny
.getValueType() == getCppuBooleanType() );
477 OSL_ASSERT( *(sal_Bool
*)aAny
.getValue() == sal_True
);
481 // test: operator <<=( any, value )
483 aAny
<<= (sal_Int8
)2;
484 OSL_ASSERT( aAny
.getValueType() == getCppuType( (sal_Int8
*)0 ) );
485 OSL_ASSERT( *(sal_Int8
*)aAny
.getValue() == 2 );
486 aAny
<<=( (float)2 );
487 OSL_ASSERT( aAny
.getValueType() == getCppuType( (float *)0 ) );
488 OSL_ASSERT( *(float*)aAny
.getValue() == (float)2 );
489 // aAny <<=( (sal_uInt8)2 );
490 // OSL_ASSERT( aAny.getValueType() == getCppuType( (sal_uInt8 *)0 ) );
491 // OSL_ASSERT( *(sal_uInt8*)aAny.getValue() == 2 );
492 aAny
<<=( (double)2 );
493 OSL_ASSERT( aAny
.getValueType() == getCppuType( (double *)0 ) );
494 OSL_ASSERT( *(double*)aAny
.getValue() == (double)2 );
495 aAny
<<=( (sal_Int16
)2 );
496 OSL_ASSERT( aAny
.getValueType() == getCppuType( (sal_Int16
*)0 ) );
497 OSL_ASSERT( *(sal_Int16
*)aAny
.getValue() == 2 );
498 aAny
<<=( OUString( RTL_CONSTASCII_USTRINGPARAM("test") ) );
499 OSL_ASSERT( aAny
.getValueType() == getCppuType( (OUString
*)0 ) );
500 OSL_ASSERT( *(OUString
*)aAny
.getValue() == OUString::createFromAscii("test") );
501 aAny
<<=( (sal_uInt16
)2 );
502 OSL_ASSERT( aAny
.getValueType() == getCppuType( (sal_uInt16
*)0 ) );
503 OSL_ASSERT( *(sal_Int16
*)aAny
.getValue() == 2 );
504 sal_Int64 aInt64
= SAL_CONST_INT64(0x200000000);
506 OSL_ASSERT( aAny
.getValueType() == getCppuType( (sal_Int64
*)0 ) );
507 OSL_ASSERT( *(sal_Int64
*)aAny
.getValue() == SAL_CONST_UINT64(0x200000000) );
508 aAny
<<=( (sal_Int32
)2 );
509 OSL_ASSERT( aAny
.getValueType() == getCppuType( (sal_Int32
*)0 ) );
510 OSL_ASSERT( *(sal_Int32
*)aAny
.getValue() == 2 );
511 sal_uInt64 auInt64
= SAL_CONST_UINT64(0x200000000);
513 OSL_ASSERT( aAny
.getValueType() == getCppuType( (sal_uInt64
*)0 ) );
514 OSL_ASSERT( *(sal_uInt64
*)aAny
.getValue() == SAL_CONST_UINT64(0x200000000) );
515 aAny
<<=( (sal_uInt32
)2 );
516 OSL_ASSERT( aAny
.getValueType() == getCppuType( (sal_uInt32
*)0 ) );
517 OSL_ASSERT( *(sal_uInt32
*)aAny
.getValue() == 2 );
518 aAny
<<=( TypeClass_STRUCT
);
519 OSL_ASSERT( aAny
.getValueType() == getCppuType( (TypeClass
*)0 ) );
520 OSL_ASSERT( *(TypeClass
*)aAny
.getValue() == TypeClass_STRUCT
);
525 Sequence
< Any
> seqAny( 1 );
526 seqAny
[ 0 ] <<= sal_Int32(5);
527 seqAny
.realloc( 200000 ); // hopefully different memory
528 seqAny
[ 1 ] <<= sal_Int32(6);
530 uno_Any
* pAnys
= (uno_Any
*)seqAny
.getConstArray();
531 OSL_ASSERT( pAnys
[ 1 ].pData
== &pAnys
[ 1 ].pReserved
);
532 OSL_ASSERT( *(sal_Int32
*)pAnys
[ 1 ].pData
== sal_Int32(6) );
533 OSL_ASSERT( pAnys
[ 0 ].pData
== &pAnys
[ 0 ].pReserved
);
534 OSL_ASSERT( *(sal_Int32
*)pAnys
[ 0 ].pData
== sal_Int32(5) );
538 // test: operator >>=( any, value )
540 makeAny( (sal_Int8
)2) >>= a3
.nInt8
;
541 OSL_ASSERT( (makeAny( (sal_Int8
)2) >>= a3
.nInt8
) && a3
.nInt8
== 2 );
542 OSL_ASSERT( (makeAny( (float)2) >>= a3
.nFloat
) && a3
.nFloat
==(float)2 );
543 OSL_ASSERT( (makeAny( (double)2) >>= a3
.nDouble
) && a3
.nDouble
== 2 );
544 OSL_ASSERT( (makeAny( (sal_Int16
)2) >>= a3
.nInt16
) && a3
.nInt16
== 2 );
545 OSL_ASSERT( (makeAny( OUString( RTL_CONSTASCII_USTRINGPARAM("2") )) >>= a3
.aString
) &&
546 a3
.aString
== OUString::createFromAscii("2") );
547 OSL_ASSERT( (makeAny( (sal_uInt16
)2) >>= a3
.nuInt16
) && a3
.nuInt16
== 2 );
548 sal_Int64 aInt64
= SAL_CONST_INT64(0x200000000);
549 OSL_ASSERT( makeAny( aInt64
) >>= a3
.nInt64
);
550 OSL_ASSERT( a3
.nInt64
== SAL_CONST_INT64(0x200000000) );
551 OSL_ASSERT( (makeAny( (sal_Int32
)2) >>= a3
.nInt32
) && a3
.nInt32
== 2 );
552 sal_uInt64 auInt64
= SAL_CONST_UINT64(0x200000000);
553 OSL_ASSERT( makeAny( auInt64
) >>= a3
.nuInt64
);
554 OSL_ASSERT( a3
.nuInt64
== SAL_CONST_UINT64(0x200000000) );
555 OSL_ASSERT( (makeAny( (sal_uInt32
)2) >>= a3
.nuInt32
) && a3
.nuInt32
== 2 );
556 OSL_ASSERT( (makeAny( TypeClass_STRUCT
) >>= a3
.eType
) && a3
.eType
== TypeClass_STRUCT
);
557 //OSL_ASSERT( (makeAny( L'2' ) >>= a3.wChar) && a3.nInt8 ==L'2';
558 OSL_ASSERT( (makeAny( (sal_Int16
)2) >>= a3
.td
.nInt16
) && a3
.nInt16
== 2 );
559 OSL_ASSERT( (makeAny( (double)2) >>= a3
.td
.dDouble
) && a3
.nDouble
== 2 );
560 //OSL_ASSERT( (makeAny( (sal_True)2) >>= a3.bBool) && a3.nInt8 ==sal_True;
562 // Only one negative test, the implementation has only one if to test this
563 OSL_ASSERT( (makeAny( (float)2) >>= a3
.nFloat
) && a3
.nFloat
==(float)2 );
568 Sequence
< Test1
> aTestSeq
;
569 OSL_ASSERT( aTestSeq
.getLength() == 0 );
570 sal_Int32 szInt32
[2] = { 1, 2 };
571 Sequence
< sal_Int32
> aInt32Seq( szInt32
, 2 );
572 OSL_ASSERT( aInt32Seq
.getLength() == 2 );
573 OSL_ASSERT( aInt32Seq
[0] == 1 && aInt32Seq
[1] == 2 );
574 OSL_ASSERT( aInt32Seq
.getArray()[0] == 1 && aInt32Seq
.getArray()[1] == 2 );
575 Sequence
< sal_Int32
> aNextInt32Seq( aInt32Seq
);
576 OSL_ASSERT( aNextInt32Seq
[0] == 1 && aNextInt32Seq
[1] == 2 );
578 OSL_ASSERT( aInt32Seq
[0] == 45 && aInt32Seq
[1] == 2 );
579 OSL_ASSERT( aNextInt32Seq
[0] == 1 && aNextInt32Seq
[1] == 2 );
580 sal_Int32
* pArray
= aNextInt32Seq
.getArray();
581 OSL_ASSERT( pArray
[0] == 1 && pArray
[1] == 2 );
582 Sequence
< double > aDoubleSeq( 5 );
583 OSL_ASSERT( aDoubleSeq
[4] == 0.0 );
584 Sequence
< OUString
> aStringSeq( 5 );
585 OSL_ASSERT( aStringSeq
[4] == OUString() );
587 sal_Int32 szInt32
[2] = { 1, 2 };
588 Sequence
<sal_Int32
> aInt32Seq( szInt32
, 2 );
589 Sequence
<sal_Int32
> aNextInt32Seq( aInt32Seq
);
590 aNextInt32Seq
.realloc( 1 ); // split of sequence
591 const sal_Int32
* pArray
= aNextInt32Seq
.getConstArray();
592 OSL_ASSERT( pArray
[0] == 1 );
593 aInt32Seq
.realloc( 1 ); // reallocate mem
594 pArray
= aInt32Seq
.getConstArray();
595 OSL_ASSERT( pArray
[0] == 1 );
597 Sequence
<sal_Int32
> aInt32Seq2( aInt32Seq
);
598 aInt32Seq
.realloc( 0 );
599 aInt32Seq
.realloc( 1 );
600 aInt32Seq
.realloc( 0 );
603 class TestInterface
: public XInterface
607 void SAL_CALL
acquire() throw ()
608 { osl_incrementInterlockedCount( &nRefCount
); }
609 void SAL_CALL
release() throw ()
610 { if( !osl_decrementInterlockedCount( &nRefCount
) ) delete this; }
611 Any SAL_CALL
queryInterface( const Type
& rType
) throw (RuntimeException
)
612 { return cppu::queryInterface( rType
, static_cast< XInterface
* >( this ) ); }
614 TestInterface() : nRefCount( 0 ) {}
619 struct SimpleInterface
: public TestInterface
, public XSimpleInterface
621 void SAL_CALL
acquire() throw ()
622 { TestInterface::acquire(); }
623 void SAL_CALL
release() throw ()
624 { TestInterface::release(); }
625 Any SAL_CALL
queryInterface( const Type
& rType
) throw (RuntimeException
)
627 Any
aRet( cppu::queryInterface( rType
, static_cast< XSimpleInterface
* >( this ) ) );
628 return (aRet
.hasValue() ? aRet
: TestInterface::queryInterface( rType
));
630 virtual void SAL_CALL
method() throw(::com::sun::star::uno::RuntimeException
)
634 static sal_Bool s_aAssignableFromTab
[11][11] =
636 /* from CH,BO,BY,SH,US,LO,UL,HY,UH,FL,DO */
637 /* TypeClass_CHAR */ { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
638 /* TypeClass_BOOLEAN */ { 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
639 /* TypeClass_BYTE */ { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 },
640 /* TypeClass_SHORT */ { 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0 },
641 /* TypeClass_UNSIGNED_SHORT */ { 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0 },
642 /* TypeClass_LONG */ { 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0 },
643 /* TypeClass_UNSIGNED_LONG */ { 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0 },
644 /* TypeClass_HYPER */ { 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0 },
645 /* TypeClass_UNSIGNED_HYPER */ { 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0 },
646 /* TypeClass_FLOAT */ { 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0 },
647 /* TypeClass_DOUBLE */ { 0, 0, 1, 1, 1, 1, 1, 0, 0, 1, 1 }
650 void test_assignSimple( const T
& rVal
, /*const*/ Any
/*&*/ rAny
)
652 typelib_TypeDescription
* pTD
= 0;
653 ::getCppuType( &rVal
).getDescription( &pTD
);
654 sal_Bool bTable
= s_aAssignableFromTab
[pTD
->eTypeClass
-1][rAny
.getValueTypeClass()-1];
656 (bTable
!=sal_False
) ==
657 (typelib_typedescriptionreference_isAssignableFrom(
658 pTD
->pWeakRef
, rAny
.getValueTypeRef() )!=sal_False
) );
660 OSL_ASSERT( (bTable
!=sal_False
) == ((rAny
>>= t
)!=sal_False
) );
662 OSL_ASSERT( t
== rVal
);
663 typelib_typedescription_release( pTD
);
666 void test_simple_assignment( const T
& rVal
)
669 sal_Bool tr
= sal_True
;
670 typelib_TypeDescription
* pBoolTD
= 0;
671 ::getCppuBooleanType().getDescription( &pBoolTD
);
672 Any
a( &tr
, pBoolTD
);
673 test_assignSimple( rVal
, a
);
674 OSL_ASSERT( typelib_typedescriptionreference_isAssignableFrom( pBoolTD
->pWeakRef
, a
.getValueTypeRef() ) );
675 typelib_typedescription_release( pBoolTD
);
676 OSL_ASSERT( *(sal_Bool
*)a
.getValue() );
678 sal_Unicode ch
= 'a';
679 typelib_TypeDescription
* pCharTD
= 0;
680 ::getCppuCharType().getDescription( &pCharTD
);
681 a
.setValue( &ch
, pCharTD
);
682 test_assignSimple( rVal
, a
);
683 OSL_ASSERT( typelib_typedescriptionreference_isAssignableFrom( pCharTD
->pWeakRef
, a
.getValueTypeRef() ) );
684 typelib_typedescription_release( pCharTD
);
685 OSL_ASSERT( *(sal_Unicode
*)a
.getValue() == 'a' );
689 test_assignSimple( rVal
, a
);
691 test_assignSimple( rVal
, a
);
693 test_assignSimple( rVal
, a
);
695 test_assignSimple( rVal
, a
);
697 test_assignSimple( rVal
, a
);
699 test_assignSimple( rVal
, a
);
701 test_assignSimple( rVal
, a
);
703 test_assignSimple( rVal
, a
);
705 test_assignSimple( rVal
, a
);
707 static void testAssignment()
710 test_simple_assignment( (sal_Int8
)5 );
711 test_simple_assignment( (sal_Int16
)5 );
712 test_simple_assignment( (sal_uInt16
)5 );
713 test_simple_assignment( (sal_Int32
)5 );
714 test_simple_assignment( (sal_uInt32
)5 );
715 test_simple_assignment( (sal_Int64
)5 );
716 test_simple_assignment( (sal_uInt64
)5 );
717 test_simple_assignment( (float)5 );
718 test_simple_assignment( (double)5 );
719 // some complex things
722 TestElement te
; // derived from simple
724 OSL_ASSERT( !(a
>>= te
) );
725 OSL_ASSERT( a
>>= ts
);
727 OSL_ASSERT( (a
>>= te
) && (a
>>= ts
) );
729 Reference
< XSimpleInterface
> xOriginal( new SimpleInterface() );
731 Reference
< XInterface
> x
;
732 OSL_ASSERT( (a
>>= x
) && (a
== xOriginal
) && (xOriginal
== x
) && (x
== xOriginal
) );
734 Sequence
< TestElement
> aSeq( 5 );
735 Sequence
< TestElement
> aSeq2( 3 );
738 OSL_ASSERT( a
>>= aSeq2
);
739 OSL_ASSERT( aSeq2
[1].Byte
== 17 );
741 OSL_ASSERT( aSeq
!= aSeq2
);
742 OSL_ASSERT( a
!= aSeq2
);
744 OSL_ASSERT( a
>>= aSeq
);
745 OSL_ASSERT( a
== aSeq
);
746 OSL_ASSERT( !(a
!= aSeq
) );
747 OSL_ASSERT( aSeq
== aSeq2
);
748 OSL_ASSERT( aSeq
[1].Byte
== 20 );
751 sal_uInt64 n
= (sal_uInt64
)(sal_Int64
)-5;
752 a
.setValue( &n
, getCppuType( (sal_uInt64
*)0 ) );
755 b
.setValue( &n2
, getCppuType( (sal_Int8
*)0 ) );
756 OSL_ASSERT( a
!= b
);
759 void test_interface()
763 Reference
< XInterface
> xIFace
;
764 OSL_ASSERT( !xIFace
.is() );
765 xIFace
.clear(); // do nothing
769 void test_inheritance()
771 OSL_ASSERT( sizeof( Base
) == getSize( getCppuType( (Base
*)0).getTypeLibType() ) );
772 OSL_ASSERT( sizeof( Base1
) == getSize( getCppuType( (Base1
*)0).getTypeLibType() ) );
773 OSL_ASSERT( sizeof( Base2
) == getSize( getCppuType( (Base2
*)0).getTypeLibType() ) );
776 sal_Int32 nCallback_1
;
778 void SAL_CALL typedescription_Callback_1
781 typelib_TypeDescription
** ppRet
,
782 rtl_uString
* pTypeName
785 OSL_ENSURE( pContext
== (void *)1, "### unexpected context!" );
788 typelib_typedescription_release( *ppRet
);
792 OUString
aTypeName( pTypeName
);
793 if( -1 != aTypeName
.indexOf( OUString::createFromAscii("1_") ) )
796 OUString
aName( RTL_CONSTASCII_USTRINGPARAM("unsigned short") );
798 typelib_CompoundMember_Init aMember
= { typelib_TypeClass_UNSIGNED_SHORT
,
801 typelib_typedescription_new(
803 typelib_TypeClass_STRUCT
, pTypeName
, 0,
810 void SAL_CALL typedescription_Callback
813 typelib_TypeDescription
** ppRet
,
814 rtl_uString
* pTypeName
817 OSL_ENSURE( pContext
== (void *)0, "### unexpected context!" );
820 typelib_typedescription_release( *ppRet
);
824 OUString
aTypeName( pTypeName
);
825 if( -1 != aTypeName
.indexOf( OUString::createFromAscii("cachetest") ) )
828 aTypeName
= OUString( RTL_CONSTASCII_USTRINGPARAM("1_") ) + aTypeName
;
830 typelib_CompoundMember_Init aMember
= { typelib_TypeClass_STRUCT
,
833 typelib_typedescription_new(
835 typelib_TypeClass_STRUCT
, pTypeName
, 0,
844 typelib_typedescription_registerCallback(
846 reinterpret_cast<typelib_typedescription_Callback
>(typedescription_Callback_1
) );
847 typelib_typedescription_registerCallback(
849 reinterpret_cast<typelib_typedescription_Callback
>(typedescription_Callback
) );
851 for( sal_Int32 i
= 0; i
< 300; i
++ )
853 typelib_TypeDescription
* pTD
= 0;
854 OUString
aTypeName( RTL_CONSTASCII_USTRINGPARAM("cachetest") );
855 aTypeName
= aTypeName
+ OUString::valueOf( i
);
856 typelib_typedescription_getByName( &pTD
, aTypeName
.pData
);
857 typelib_typedescription_release( pTD
);
859 OSL_ASSERT( nCallback_1
== 300 );
860 OSL_ASSERT( nCallback
== 300 );
861 // The cache size is 200 so the description "cachetest200" is in the cache
862 typelib_TypeDescription
* pTD
= 0;
863 OUString
aName200( RTL_CONSTASCII_USTRINGPARAM("cachetest200") );
864 typelib_typedescription_getByName( &pTD
, aName200
.pData
);
865 OSL_ASSERT( nCallback_1
== 300 );
866 OSL_ASSERT( nCallback
== 300 );
867 // The cache size is 200 so the description "cachetest199" is not in the cache
868 // "1_cachetest199" is loaded too.
869 OUString
aName199( RTL_CONSTASCII_USTRINGPARAM("cachetest199") );
870 typelib_typedescription_getByName( &pTD
, aName199
.pData
);
871 typelib_typedescription_release( pTD
);
872 OSL_ASSERT( nCallback_1
== 301 );
873 OSL_ASSERT( nCallback
== 301 );
875 typelib_typedescription_revokeCallback(
877 reinterpret_cast<typelib_typedescription_Callback
>(typedescription_Callback_1
) );
878 typelib_typedescription_revokeCallback(
880 reinterpret_cast<typelib_typedescription_Callback
>(typedescription_Callback
) );
883 static OUString s_aAddPurpose
;
885 static void SAL_CALL
getMappingCallback(
886 uno_Mapping
** /*ppMapping*/,
887 uno_Environment
* /*pFrom*/, uno_Environment
* /*pTo*/, rtl_uString
* pAddPurpose
)
889 s_aAddPurpose
= pAddPurpose
;
891 static void testMappingCallback()
893 uno_registerMappingCallback( reinterpret_cast<uno_getMappingFunc
>(getMappingCallback
) );
894 OSL_ASSERT( ! s_aAddPurpose
.getLength() );
896 OUString( RTL_CONSTASCII_USTRINGPARAM(CPPU_CURRENT_LANGUAGE_BINDING_NAME
) ),
897 OUString( RTL_CONSTASCII_USTRINGPARAM(CPPU_CURRENT_LANGUAGE_BINDING_NAME
) ),
898 OUString( RTL_CONSTASCII_USTRINGPARAM("test") ) );
899 uno_revokeMappingCallback( reinterpret_cast<uno_getMappingFunc
>(getMappingCallback
) );
900 OSL_ASSERT( s_aAddPurpose
.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("test") ) );
901 s_aAddPurpose
= OUString();
903 OUString( RTL_CONSTASCII_USTRINGPARAM(CPPU_CURRENT_LANGUAGE_BINDING_NAME
) ),
904 OUString( RTL_CONSTASCII_USTRINGPARAM(CPPU_CURRENT_LANGUAGE_BINDING_NAME
) ),
905 OUString( RTL_CONSTASCII_USTRINGPARAM("test") ) );
906 OSL_ASSERT( ! s_aAddPurpose
.getLength() );
909 static void testEnvironments(void)
911 uno_Environment
** ppEnv
;
915 ::uno_getRegisteredEnvironments(
916 &ppEnv
, &nLen
, ::rtl_allocateMemory
, aTypeName
.pData
);
920 for ( sal_Int32 nPos
= 0; nPos
< nLen
; ++nPos
)
922 uno_Environment
* pEnv
= ppEnv
[ nPos
];
925 ::uno_dumpEnvironment( stderr
, pEnv
, 0 );
927 // call some releases
928 void ** ppInterfaces
= 0;
929 sal_Int32 nInterfaces
;
931 uno_ExtEnvironment
* pExtEnv
= pEnv
->pExtEnv
;
932 (*pExtEnv
->getRegisteredInterfaces
)(
933 pExtEnv
, &ppInterfaces
, &nInterfaces
, ::rtl_allocateMemory
);
936 while (nInterfaces
--)
938 void * p
= ppInterfaces
[ nInterfaces
];
939 (*pExtEnv
->releaseInterface
)( pExtEnv
, p
);
941 ::rtl_freeMemory( ppInterfaces
);
944 (*pEnv
->release
)( pEnv
);
946 ::rtl_freeMemory( ppEnv
);
950 inline const ::com::sun::star::uno::Type
& SAL_CALL
getCppuType( const Sequence
< OUString
[2][4] >* ) SAL_THROW( () )
952 return getCppuSequenceType
< OUString
[2][4] >( getCppuArrayType2( (const OUString (*)[2][4])0 ) );
955 //==================================================================================================
957 : public ::cppu::WeakImplHelper1
< XCurrentContext
>
959 Reference
< XCurrentContext
> m_xDel
;
963 inline Test_CContext( sal_Int32 val
, OUString
const & rName
,
964 Reference
< XCurrentContext
> const & xDel
)
971 virtual Any SAL_CALL
getValueByName( OUString
const & rName
)
972 throw (RuntimeException
);
974 //__________________________________________________________________________________________________
975 Any
Test_CContext::getValueByName( OUString
const & rName
)
976 throw (RuntimeException
)
980 return makeAny( m_value
);
982 else if (m_xDel
.is())
984 return m_xDel
->getValueByName( rName
);
988 //==================================================================================================
989 static void testCurrentContext()
992 ContextLayer
layer( new Test_CContext(
993 5, OUString( RTL_CONSTASCII_USTRINGPARAM("Value1") ),
994 Reference
< XCurrentContext
>() ) );
995 Reference
< XCurrentContext
> xCC( getCurrentContext() );
998 xCC
->getValueByName( OUString( RTL_CONSTASCII_USTRINGPARAM("Value1") ) ) == (sal_Int16
)5 &&
999 !xCC
->getValueByName( OUString( RTL_CONSTASCII_USTRINGPARAM("Value2") ) ).hasValue() );
1000 OSL_ASSERT( ! layer
.getPreviousContext().is() );
1003 ContextLayer
layer2( new Test_CContext(
1004 7, OUString( RTL_CONSTASCII_USTRINGPARAM("Value2") ),
1006 OSL_ASSERT( layer2
.getPreviousContext() == xCC
);
1007 xCC
= getCurrentContext();
1010 xCC
->getValueByName( OUString( RTL_CONSTASCII_USTRINGPARAM("Value1") ) ) == (sal_Int16
)5 &&
1011 xCC
->getValueByName( OUString( RTL_CONSTASCII_USTRINGPARAM("Value2") ) ) == (sal_Int16
)7 &&
1012 !xCC
->getValueByName( OUString( RTL_CONSTASCII_USTRINGPARAM("dummy") ) ).hasValue() );
1014 uno_Interface
* pContext
= 0;
1015 OUString
aEnvName( RTL_CONSTASCII_USTRINGPARAM(UNO_LB_UNO
) );
1016 OSL_VERIFY( ::uno_getCurrentContext( (void **)&pContext
, aEnvName
.pData
, 0 ) );
1017 (*pContext
->release
)( pContext
);
1019 OSL_ASSERT( ! layer
.getPreviousContext().is() );
1021 OSL_ASSERT( ! getCurrentContext().is() );
1024 void testArray(void)
1027 getCppuArrayType2( &a
);
1029 getCppuArrayType1( (const long (*)[5])0 );
1030 getCppuArrayType2( (const long (*)[6][7])0 );
1031 getCppuArrayType3( (const long (*)[7][8][9])0 );
1032 getCppuArrayType4( (const long (*)[8][9][10][11])0 );
1033 getCppuArrayType5( (const long (*)[9][10][11][12][13])0 );
1034 getCppuArrayType6( (const long (*)[10][11][12][13][14][15])0 );
1036 getCppuArrayType2( (const Reference
< XInterface
> (*)[6][7])0 );
1038 getCppuArrayType1( (const Test1 (*)[5])0 );
1039 getCppuArrayType2( (const Test1 (*)[6][7])0 );
1040 getCppuArrayType3( (const Test1 (*)[7][8][9])0 );
1041 getCppuArrayType4( (const Test1 (*)[8][9][10][11])0 );
1042 getCppuArrayType5( (const Test1 (*)[9][10][11][12][13])0 );
1043 getCppuArrayType6( (const Test1 (*)[10][11][12][13][14][15])0 );
1045 typelib_TypeDescription
* pType
= NULL
;
1046 typelib_TypeDescriptionReference
* pTypeRef
= NULL
;
1047 sal_Int32 pDim
[] = { 2, 4 };
1048 Type rType
= getCppuType((const sal_Int32
*)0);
1049 typelib_typedescription_newArray(&pType
, rType
.getTypeLibType(), 2, pDim
);
1050 OSL_ASSERT( pType
);
1051 typelib_typedescriptionreference_new(&pTypeRef
, typelib_TypeClass_ARRAY
, pType
->pTypeName
);
1052 OSL_ASSERT( pTypeRef
);
1055 sal_Int32 a2
[2][4] = { {1,2,3,4}, {5,6,7,8} };
1056 uno_constructData( &a1
, pType
);
1057 // uno_type_constructData( &a1, pTypeRef );
1059 sal_Bool bAssignable
= uno_assignData(&a1
, pType
, a2
, pType
,
1060 reinterpret_cast<uno_QueryInterfaceFunc
>(cpp_queryInterface
),
1061 reinterpret_cast<uno_AcquireFunc
>(cpp_acquire
),
1062 reinterpret_cast<uno_ReleaseFunc
>(cpp_release
) );
1064 for ( i
=0; i
<2; i
++ )
1065 for ( j
=0; j
<4; j
++ )
1066 OSL_ASSERT( a1
[i
][j
] == a2
[i
][j
] );
1068 uno_destructData( a1
, pType
, reinterpret_cast<uno_ReleaseFunc
>(cpp_release
) );
1069 // uno_type_destructData( &a1, pTypeRef, cpp_release );
1070 uno_destructData( a2
, pType
, reinterpret_cast<uno_ReleaseFunc
>(cpp_release
) );
1072 typelib_typedescription_release(pType
);
1073 typelib_typedescriptionreference_release(pTypeRef
);
1077 typelib_typedescription_newArray(&pType
, getCppuType((const OUString
*)0).getTypeLibType(), 2, pDim
);
1078 OSL_ASSERT( pType
);
1079 typelib_typedescriptionreference_new(&pTypeRef
, typelib_TypeClass_ARRAY
, pType
->pTypeName
);
1080 OSL_ASSERT( pTypeRef
);
1082 OUString
s1(OUString::createFromAscii("Hallo"));
1083 OUString
s2(OUString::createFromAscii("jetzt"));
1084 OUString
s3(OUString::createFromAscii("teste"));
1085 OUString
s4(OUString::createFromAscii("ich"));
1086 OUString
s5(OUString::createFromAscii("ein"));
1087 OUString
s6(OUString::createFromAscii("Array"));
1088 OUString
s7(OUString::createFromAscii("mit"));
1089 OUString
s8(OUString::createFromAscii("strings"));
1090 OUString st1
,st2
,st3
,st4
,st5
,st6
,st7
,st8
;
1092 void* p
= rtl_allocateMemory(8 * sizeof(rtl_uString
*));
1093 void* p2
= rtl_allocateMemory(8 * sizeof(rtl_uString
*));
1094 rtl_uString
** ppS
= (rtl_uString
**)p
;
1095 rtl_uString
* sa1
[2][4] = { {st1
.pData
,st2
.pData
,st3
.pData
,st4
.pData
},
1096 {st5
.pData
,st6
.pData
,st7
.pData
,st8
.pData
} };
1097 rtl_uString
* sa2
[2][4] = { {s1
.pData
,s2
.pData
,s3
.pData
,s4
.pData
},
1098 {s5
.pData
,s6
.pData
,s7
.pData
,s8
.pData
} };
1099 uno_constructData( p
, pType
);
1101 bAssignable
= uno_assignData(p
, pType
, sa2
, pType
,
1102 reinterpret_cast<uno_QueryInterfaceFunc
>(cpp_queryInterface
),
1103 reinterpret_cast<uno_AcquireFunc
>(cpp_acquire
),
1104 reinterpret_cast<uno_ReleaseFunc
>(cpp_release
) );
1106 bAssignable
= uno_assignData(sa1
, pType
, p
, pType
,
1107 reinterpret_cast<uno_QueryInterfaceFunc
>(cpp_queryInterface
),
1108 reinterpret_cast<uno_AcquireFunc
>(cpp_acquire
),
1109 reinterpret_cast<uno_ReleaseFunc
>(cpp_release
) );
1111 for ( i
=0; i
<2; i
++ )
1112 for ( j
=0; j
<4; j
++ )
1113 OSL_ASSERT( sa1
[i
][j
] == sa2
[i
][j
] );
1127 OUString (*sB
)[2][4];
1128 aa1
.setValue(&sA
, getCppuArrayType2( (const OUString (*)[2][4])0 ));
1130 arrayType
= aa2
.getValueType();
1131 sB
= (OUString(*)[2][4])aa2
.getValue();
1132 for ( i
=0; i
<2; i
++ )
1133 for ( j
=0; j
<4; j
++ )
1134 OSL_ASSERT( sA
[i
][j
] == (*sB
)[i
][j
] );
1136 // requires a specialized getCppuType function 'getCppuType( const Sequence< OUString[2][4] >* )'
1137 // Sequence< OUString[2][4] > aSeq(2);
1138 // OUString (*pSeq)[2][4] = aSeq.getArray();
1139 // uno_copyData(pSeq[0], sA, pType, cpp_acquire);
1140 // uno_copyData(pSeq[1], sA, pType, cpp_acquire);
1142 // OSL_ASSERT( aSeq[0][0][0] == sA[0][0] );
1143 // OSL_ASSERT( aSeq[0][0][1] == sA[0][1] );
1144 // OSL_ASSERT( aSeq[0][0][2] == sA[0][2] );
1145 // OSL_ASSERT( aSeq[0][0][3] == sA[0][3] );
1146 // OSL_ASSERT( aSeq[0][1][0] == sA[1][0] );
1147 // OSL_ASSERT( aSeq[0][1][1] == sA[1][1] );
1148 // OSL_ASSERT( aSeq[0][1][2] == sA[1][2] );
1149 // OSL_ASSERT( aSeq[0][1][3] == sA[1][3] );
1151 // OSL_ASSERT( aSeq[1][0][0] == sA[0][0] );
1152 // OSL_ASSERT( aSeq[1][0][1] == sA[0][1] );
1153 // OSL_ASSERT( aSeq[1][0][2] == sA[0][2] );
1154 // OSL_ASSERT( aSeq[1][0][3] == sA[0][3] );
1155 // OSL_ASSERT( aSeq[1][1][0] == sA[1][0] );
1156 // OSL_ASSERT( aSeq[1][1][1] == sA[1][1] );
1157 // OSL_ASSERT( aSeq[1][1][2] == sA[1][2] );
1158 // OSL_ASSERT( aSeq[1][1][3] == sA[1][3] );
1160 uno_constructData( p2
, pType
);
1161 ppS
= (rtl_uString
**)p2
;
1162 uno_copyData(p2
, sa1
, pType
, reinterpret_cast<uno_AcquireFunc
>(cpp_acquire
));
1163 uno_copyData(sa2
, p2
, pType
, reinterpret_cast<uno_AcquireFunc
>(cpp_acquire
));
1165 uno_destructData( p
, pType
, reinterpret_cast<uno_ReleaseFunc
>(cpp_release
));
1166 uno_destructData( p2
, pType
, reinterpret_cast<uno_ReleaseFunc
>(cpp_release
) );
1167 uno_destructData( sa1
, pType
, reinterpret_cast<uno_ReleaseFunc
>(cpp_release
) );
1168 uno_destructData( sa2
, pType
, reinterpret_cast<uno_ReleaseFunc
>(cpp_release
) );
1172 typelib_typedescription_release(pType
);
1173 typelib_typedescriptionreference_release(pTypeRef
);
1181 SAL_IMPLEMENT_MAIN()
1183 rtl::OUString
const cppName(
1184 RTL_CONSTASCII_USTRINGPARAM(CPPU_CURRENT_LANGUAGE_BINDING_NAME
) );
1185 uno_Environment
* pCppEnv
= 0;
1186 uno_getEnvironment( &pCppEnv
, cppName
.pData
, 0 );
1187 uno_getEnvironment( &pCppEnv
, cppName
.pData
, 0 );
1188 (*pCppEnv
->release
)( pCppEnv
);
1191 typelib_setCacheSize( 200 );
1192 Reference
< registry::XSimpleRegistry
> xRegistry(
1193 ::cppu::createSimpleRegistry() );
1194 xRegistry
->open( OUString( RTL_CONSTASCII_USTRINGPARAM("testcppu.rdb") ), sal_True
, sal_False
);
1195 Reference
< XComponentContext
> xContext(
1196 ::cppu::bootstrap_InitialComponentContext( xRegistry
) );
1198 ::rtl_unloadUnusedModules( 0 );
1199 testMappingCallback();
1200 ::rtl_unloadUnusedModules( 0 );
1203 // void test_security( const Reference< XMultiServiceFactory > & );
1204 // test_security( xMgr );
1206 // C++, C bridges test
1207 void test_CppBridge(void);
1209 ::rtl_unloadUnusedModules( 0 );
1210 // void test_CBridge(void);
1211 // void test_CBridge2(void);
1215 testCurrentContext();
1219 #if 0 // cache test not possible if types are loaded dynamically (cppumaker -L)
1226 Reference
< XComponent
> xComp( xContext
, UNO_QUERY_THROW
);
1227 xComp
.set( xContext
, UNO_QUERY_THROW
);
1228 Reference
< XInterface
> x(
1229 xContext
->getValueByName(
1230 OUString( RTL_CONSTASCII_USTRINGPARAM("/singletons/com.sun.star.reflection.theTypeDescriptionManager") ) ), UNO_QUERY_THROW
);
1233 catch (Exception
& exc
) {
1234 fprintf( stderr
, "error: %s\n", rtl::OUStringToOString(
1235 exc
.Message
, RTL_TEXTENCODING_UTF8
).getStr() );
1238 typelib_setCacheSize( 0 );
1239 ::rtl_unloadUnusedModules( 0 );
1241 ::rtl_unloadUnusedModules( 0 );