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: testconv.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 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_stoc.hxx"
35 #include <osl/diagnose.h>
36 #include <rtl/ustrbuf.hxx>
37 #include <cppuhelper/servicefactory.hxx>
39 #include <com/sun/star/lang/XComponent.hpp>
40 #include <com/sun/star/lang/XServiceInfo.hpp>
41 #include <com/sun/star/script/XTypeConverter.hpp>
42 #include <com/sun/star/reflection/FieldAccessMode.hpp>
43 #include <com/sun/star/registry/XImplementationRegistration.hpp>
52 using namespace com::sun::star::uno
;
53 using namespace com::sun::star::lang
;
54 using namespace com::sun::star::script
;
55 using namespace com::sun::star::reflection
;
56 using namespace com::sun::star::registry
;
58 const double MIN_DOUBLE
= -DBL_MAX
;
59 const double MAX_DOUBLE
= DBL_MAX
;
60 const double MIN_FLOAT
= -FLT_MAX
;
61 const double MAX_FLOAT
= FLT_MAX
;
63 //==================================================================================================
64 static void printValue( const Any
& rVal
)
67 OString
aStr( OUStringToOString( rVal
.getValueType().getTypeName(), RTL_TEXTENCODING_ISO_8859_1
) );
68 printf( "(%s)", aStr
.getStr() );
70 switch (rVal
.getValueTypeClass())
77 printValue( *(Any
*)rVal
.getValue() );
79 case TypeClass_BOOLEAN
:
80 printf( "%s", (*(sal_Bool
*)rVal
.getValue() ? "true" : "false") );
85 ar
[0] = (char)*(sal_Unicode
*)rVal
.getValue();
91 printf( "%x", (int)*(sal_Int8
*)rVal
.getValue() );
94 printf( "%x", *(sal_Int16
*)rVal
.getValue() );
96 case TypeClass_UNSIGNED_SHORT
:
97 printf( "%x", *(sal_uInt16
*)rVal
.getValue() );
100 printf( "%lx", static_cast<long>(*(sal_Int32
*)rVal
.getValue()) );
102 case TypeClass_UNSIGNED_LONG
:
103 printf( "%lx", static_cast<unsigned long>(*(sal_uInt32
*)rVal
.getValue()) );
105 case TypeClass_HYPER
:
106 printf( "%lx", (long)*(sal_Int64
*)rVal
.getValue() );
108 case TypeClass_UNSIGNED_HYPER
:
109 printf( "%lx", (unsigned long)*(sal_uInt64
*)rVal
.getValue() );
111 case TypeClass_FLOAT
:
112 printf( "%f", *(float *)rVal
.getValue() );
114 case TypeClass_DOUBLE
:
115 printf( "%g", *(double *)rVal
.getValue() );
117 case TypeClass_STRING
:
119 OString
aStr2( OUStringToOString( *(OUString
*)rVal
.getValue(), RTL_TEXTENCODING_ISO_8859_1
) );
120 printf( aStr2
.getStr() );
125 typelib_EnumTypeDescription
* pEnumTD
= 0;
126 TYPELIB_DANGER_GET( (typelib_TypeDescription
**)&pEnumTD
, rVal
.getValueTypeRef() );
128 for ( sal_Int32 nPos
= pEnumTD
->nEnumValues
; nPos
--; )
130 if (pEnumTD
->pEnumValues
[nPos
] == *(int *)rVal
.getValue())
132 printf( OUStringToOString(pEnumTD
->ppEnumNames
[nPos
]->buffer
, RTL_TEXTENCODING_ASCII_US
).getStr() );
133 TYPELIB_DANGER_RELEASE( (typelib_TypeDescription
*)pEnumTD
);
137 TYPELIB_DANGER_RELEASE( (typelib_TypeDescription
*)pEnumTD
);
138 printf( ">ENUM not found!<" );
141 case TypeClass_SEQUENCE
:
143 uno_Sequence
* pSeq
= *(uno_Sequence
**)rVal
.getValue();
144 typelib_TypeDescription
* pSeqTD
= 0;
145 TYPELIB_DANGER_GET( &pSeqTD
, rVal
.getValueTypeRef() );
146 typelib_TypeDescription
* pElemTD
= 0;
147 TYPELIB_DANGER_GET( &pElemTD
, ((typelib_IndirectTypeDescription
*)pSeqTD
)->pType
);
149 sal_Int32 nLen
= pSeq
->nElements
;
153 for ( sal_Int32 nPos
= 0; nPos
< nLen
; ++nPos
)
155 printValue( Any( ((char *)pSeq
->elements
) + (nPos
* pElemTD
->nSize
), pElemTD
) );
162 TYPELIB_DANGER_RELEASE( pElemTD
);
163 TYPELIB_DANGER_RELEASE( pSeqTD
);
168 printf( ">not printable<" );
173 static Reference
< XTypeConverter
> s_xConverter
;
175 //==================================================================================================
176 static sal_Bool
convertTo( const Type
& rDestType
, const Any
& rVal
, sal_Bool bExpectSuccess
)
178 sal_Bool bCanConvert
= sal_False
;
185 aRet
= s_xConverter
->convertTo( rVal
, rDestType
);
186 bCanConvert
= sal_True
;
188 catch (Exception
& rExc
)
190 aExcMsg
= OUStringToOString( rExc
.Message
, RTL_TEXTENCODING_ASCII_US
);
193 if (bExpectSuccess
&& !bCanConvert
)
195 printf( "# conversion of " );
198 printf( OUStringToOString(rDestType
.getTypeName(), RTL_TEXTENCODING_ASCII_US
).getStr() );
199 printf( " failed, but success was expected! [" );
200 printf( aExcMsg
.getStr() );
202 aRet
= s_xConverter
->convertTo( rVal
, rDestType
);
203 #if OSL_DEBUG_LEVEL > 1
204 // for debugging, to trace again
207 aRet
= s_xConverter
->convertTo( rVal
, rDestType
);
215 if (!bExpectSuccess
&& bCanConvert
)
217 printf( "# conversion of " );
221 printf( " was successful, but was not expected to be!\n" );
222 #if OSL_DEBUG_LEVEL > 1
223 // for debugging, to trace again
224 aRet
= s_xConverter
->convertTo( rVal
, rDestType
);
229 #ifdef __RECONVERSION_OUTPUT__
230 //= re-conversion output =
233 // re convert to original type
234 sal_Bool bReConvert
= sal_False
;
239 aRet2
= s_xConverter
->convertTo( aRet
, rVal
.getValueType() );
240 bReConvert
= sal_True
;
242 catch (Exception
& rExc
)
244 aExcMsg
= OUStringToOString( rExc
.Message
, RTL_TEXTENCODING_ISO_8859_1
);
251 printf( "# re-conversion of " );
257 printf( ": first and last do not match!\n" );
262 printf( "# re-conversion of " );
265 printf( rVal
.getValueType().getTypeName().getStr() );
266 printf( " failed! [" );
267 printf( aExcMsg
.getStr() );
277 //==================================================================================================
278 typedef struct _ConvBlock
281 sal_Bool _toString
, _toDouble
, _toFloat
;
282 sal_Bool _toUINT32
, _toINT32
, _toUINT16
, _toINT16
, _toBYTE
, _toBOOL
, _toChar
;
283 sal_Bool _toTypeClass
, _toSeqINT16
, _toSeqAny
;
288 _ConvBlock( const Any
& rValue_
,
289 sal_Bool toString_
, sal_Bool toDouble_
, sal_Bool toFloat_
,
290 sal_Bool toUINT32_
, sal_Bool toINT32_
, sal_Bool toUINT16_
, sal_Bool toINT16_
,
291 sal_Bool toBYTE_
, sal_Bool toBOOL_
, sal_Bool toChar_
,
292 sal_Bool toTypeClass_
, sal_Bool toSeqINT16_
, sal_Bool toSeqAny_
)
294 , _toString( toString_
), _toDouble( toDouble_
), _toFloat( toFloat_
)
295 , _toUINT32( toUINT32_
), _toINT32( toINT32_
), _toUINT16( toUINT16_
), _toINT16( toINT16_
)
296 , _toBYTE( toBYTE_
), _toBOOL( toBOOL_
), _toChar( toChar_
)
297 , _toTypeClass( toTypeClass_
), _toSeqINT16( toSeqINT16_
), _toSeqAny( toSeqAny_
)
303 //==================================================================================================
304 static sal_Int32
initBlocks( ConvBlock
* pTestBlocks
)
308 sal_uInt32 nElems
= 0;
311 aVal
<<= OUString::createFromAscii( "0xff" );
312 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0 );
313 aVal
<<= OUString::createFromAscii( "255" );
314 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0 );
315 aVal
<<= (sal_Int8
)0xffu
;
316 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 0, 0, 0 );
317 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
318 aVal
<<= OUString::createFromAscii( "0x80" );
319 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0 );
320 aVal
<<= OUString::createFromAscii( "128" );
321 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0 );
322 aVal
<<= (sal_Int8
)( 0x80u
);
323 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 0, 0, 0 );
324 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
325 aVal
<<= OUString::createFromAscii( "0x7f" );
326 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 );
327 aVal
<<= OUString::createFromAscii( "127" );
328 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 );
329 aVal
<<= (sal_Int8
)( 0x7f );
330 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0 );
331 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
332 aVal
<<= OUString::createFromAscii( "5" );
333 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 0, 0 );
334 aVal
<<= OUString::createFromAscii( "+5" );
335 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 );
336 aVal
<<= (sal_Int8
)( 5 );
337 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0 );
338 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
339 aVal
<<= OUString::createFromAscii( "-5" );
340 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 0, 1, 0, 1, 1, 0, 0, 0, 0, 0 );
341 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
342 aVal
<<= (sal_Int8
)( -5 );
343 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 0, 0, 0 );
344 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
345 aVal
<<= OUString::createFromAscii( "256" );
346 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0 );
347 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
349 aVal
<<= OUString::createFromAscii( "65535" );
350 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0 );
351 aVal
<<= OUString::createFromAscii( "0xffff" );
352 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0 );
353 aVal
<<= (sal_uInt16
)( 0xffff );
354 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 0, 0 );
355 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
356 aVal
<<= OUString::createFromAscii( "32768" );
357 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0 );
358 aVal
<<= (sal_uInt16
)( 0x8000 );
359 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 0, 0 );
360 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
361 aVal
<<= OUString::createFromAscii( "32767" );
362 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0 );
363 aVal
<<= OUString::createFromAscii( "0x7fff" );
364 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0 );
365 aVal
<<= (sal_uInt16
)( 0x7fff );
366 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 0, 0 );
367 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
368 aVal
<<= OUString::createFromAscii( "256" );
369 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0 );
370 aVal
<<= OUString::createFromAscii( "0x100" );
371 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0 );
372 aVal
<<= (sal_uInt16
)( 0x100 );
373 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 0, 0 );
374 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
375 aVal
<<= (sal_uInt16
)( 5 );
376 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0 );
377 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
378 aVal
<<= (sal_uInt16
)( -5 ); // is 0xfffb
379 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 0, 0 );
380 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
382 aVal
<<= (sal_Int16
)( -1 );
383 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 0, 0, 0 );
384 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
385 aVal
<<= (sal_Int16
)( -0x8000 );
386 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0 );
387 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
388 aVal
<<= (sal_Int16
)( 0x7fff );
389 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 0, 0 );
390 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
391 aVal
<<= (sal_Int16
)( 0x100 );
392 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 0, 0 );
393 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
394 aVal
<<= (sal_Int16
)( 5 );
395 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0 );
396 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
397 aVal
<<= (sal_Int16
)( -5 );
398 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 0, 0, 0 );
399 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
401 aVal
<<= OUString::createFromAscii( "+4294967295" );
402 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 );
403 aVal
<<= OUString::createFromAscii( "4294967295" );
404 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 );
405 aVal
<<= OUString::createFromAscii( "0xffffffff" );
406 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 );
407 aVal
<<= (sal_uInt32
)( 0xffffffff );
408 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0 );
409 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
410 aVal
<<= OUString::createFromAscii( "-2147483648" );
411 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 );
412 aVal
<<= OUString::createFromAscii( "-0x80000000" );
413 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 );
414 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
415 aVal
<<= (sal_uInt32
)( 0x80000000 );
416 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0 );
417 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
418 aVal
<<= OUString::createFromAscii( "2147483647" );
419 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0 );
420 aVal
<<= OUString::createFromAscii( "0x7fffffff" );
421 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0 );
422 aVal
<<= (sal_uInt32
)( 0x7fffffff );
423 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0 );
424 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
425 aVal
<<= OUString::createFromAscii( "65536" );
426 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0 );
427 aVal
<<= OUString::createFromAscii( "0x10000" );
428 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0 );
429 aVal
<<= (sal_uInt32
)( 0x10000 );
430 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0 );
431 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
432 aVal
<<= (sal_uInt32
)( 0x8000 );
433 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 0, 0 );
434 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
435 aVal
<<= (sal_uInt32
)( 5 );
436 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0 );
437 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
438 aVal
<<= OUString::createFromAscii( "0xfffffffb" );
439 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 );
440 aVal
<<= (sal_uInt32
)( -5 ); // is 0xfffffffb
441 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0 );
442 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
444 aVal
<<= (sal_Int32
)( 0xffffffff ); // is -1
445 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 0, 0, 0 );
446 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
447 aVal
<<= (sal_Int32
)( 0x80000000 );
448 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0 );
449 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
450 aVal
<<= (sal_Int32
)( 0x7fffffff );
451 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0 );
452 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
453 aVal
<<= (sal_Int32
)( 0x10000 );
454 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0 );
455 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
456 aVal
<<= (sal_Int32
)( -0x8001 );
457 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0 );
458 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
459 aVal
<<= (sal_Int32
)( 5 );
460 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0 );
461 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
462 aVal
<<= (sal_Int32
)( -5 );
463 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 0, 0, 0 );
464 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
466 aVal
<<= OUString::createFromAscii( "-3.4e+38" );
467 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 );
468 aVal
<<= (float)( MIN_FLOAT
);
469 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 );
470 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
471 aVal
<<= OUString::createFromAscii( "+3.4e+38" );
472 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 );
473 aVal
<<= (float)( MAX_FLOAT
);
474 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 );
475 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
476 aVal
<<= OUString::createFromAscii( "9e-20" );
477 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 );
478 aVal
<<= (float)( 9e-20 );
479 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0 );
480 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
481 aVal
<<= OUString::createFromAscii( "+.7071067811865" );
482 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 );
483 aVal
<<= (float)( .7071067811865 );
484 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0 );
485 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
486 aVal
<<= OUString::createFromAscii( "3.14159265359" );
487 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 );
488 aVal
<<= (float)( 3.14159265359 );
489 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0 );
490 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
491 aVal
<<= (float)( 5 );
492 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0 );
493 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
495 aVal
<<= OUString::createFromAscii( "-1.7976931348623155e+308" );
496 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 );
497 aVal
<<= (double)( MIN_DOUBLE
);
498 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 );
499 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
500 aVal
<<= OUString::createFromAscii( "1.7976931348623155e+308" );
501 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 );
502 aVal
<<= (double)( MAX_DOUBLE
);
503 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 );
504 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
505 aVal
<<= (double)( MIN_FLOAT
);
506 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 );
507 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
508 aVal
<<= (double)( MAX_FLOAT
);
509 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 );
510 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
511 aVal
<<= (double)( -((double)0x80000000) );
512 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0 );
513 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
514 aVal
<<= (double)( -((double)0x80000001) );
515 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 );
516 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
517 aVal
<<= (double)( 0x7fffffff );
518 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0 );
519 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
520 aVal
<<= (double)( 0x80000000 );
521 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0 );
522 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
523 aVal
<<= (double)( 0xffffffff );
524 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0 );
525 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
526 aVal
<<= OUString::createFromAscii( "0x100000000" );
527 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 );
529 aVal
<<= (double)( SAL_CONST_INT64(0x100000000) );
530 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 );
532 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
533 aVal
<<= (double)( 5 );
534 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0 );
535 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
538 aVal
.setValue( &c
, ::getCharCppuType() );
539 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0 );
540 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
541 aVal
<<= OUString::createFromAscii( "A" );
542 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0 );
543 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
545 aVal
<<= OUString::createFromAscii( "0" );
546 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0 );
547 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
548 aVal
<<= OUString::createFromAscii( "1" );
549 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0 );
550 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
551 aVal
<<= OUString::createFromAscii( "False" );
552 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 );
553 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
554 aVal
<<= OUString::createFromAscii( "true" );
555 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 );
556 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
558 sal_Bool bTmp
= sal_True
;
559 aVal
.setValue( &bTmp
, getBooleanCppuType() );
560 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0 );
561 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
564 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 );
565 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
566 aVal
<<= OUString::createFromAscii( "-" );
567 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 0, 0 );
568 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
569 aVal
<<= OUString::createFromAscii( "-0" );
570 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 );
571 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
572 // ==TYPECLASS ENUM==
573 aVal
<<= OUString::createFromAscii( "eNuM" );
574 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0 );
575 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
576 aVal
<<= OUString::createFromAscii( "DOUBLE" );
577 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0 );
578 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
580 aVal
.setValue( &e
, ::getCppuType( (const TypeClass
*)0 ) );
581 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 0 );
582 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
583 aVal
.setValue( &e
, ::getCppuType( (const FieldAccessMode
*)0 ) );
584 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 );
585 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
587 Sequence
< sal_Int32
> aINT32Seq( 3 ), aINT32Seq2( 3 );
588 sal_Int32
* pINT32Seq
= aINT32Seq
.getArray();
589 pINT32Seq
[0] = -32768;
591 pINT32Seq
[2] = 32767;
593 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1 );
594 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
595 pINT32Seq
= aINT32Seq2
.getArray();
596 pINT32Seq
[0] = -32768;
597 pINT32Seq
[1] = -32769;
598 pINT32Seq
[2] = 32767;
600 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 );
601 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
603 Sequence
< Any
> aAnySeq( 2 ), aAnySeq2( 2 ), aAnySeq3( 2 );
604 Any
* pAnySeq
= aAnySeq
.getArray();
605 pAnySeq
[0] = makeAny( aINT32Seq
);
606 pAnySeq
[1] = makeAny( OUString::createFromAscii("lala") );
608 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 );
609 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
610 pAnySeq
= aAnySeq2
.getArray();
611 pAnySeq
[0] <<= (sal_Int32
)4711;
612 pAnySeq
[1] <<= OUString::createFromAscii("0815");
614 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1 );
615 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
616 pAnySeq
= aAnySeq3
.getArray();
617 pAnySeq
[0] <<= OUString::createFromAscii("TypeClass_UNION");
618 pAnySeq
[1] <<= OUString::createFromAscii("TypeClass_ENUM");
620 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 );
621 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
625 //==================================================================================================
626 static void test_Conversion( const Reference
< XMultiServiceFactory
> & xMgr
)
628 printf( "test_Conversion(): start...\n" );
630 Reference
< XTypeConverter
> xConverter( xMgr
->createInstance(
631 OUString::createFromAscii( "com.sun.star.script.Converter" ) ), UNO_QUERY
);
633 ConvBlock
* pTestBlocks
= new ConvBlock
[256];
634 sal_Int32 nPos
= initBlocks( pTestBlocks
);
636 s_xConverter
= xConverter
;
639 const ConvBlock
& rBlock
= pTestBlocks
[nPos
];
640 const Any
& rVal
= rBlock
._value
;
642 convertTo( ::getCppuType( (const OUString
*)0 ), rVal
, rBlock
._toString
);
643 convertTo( ::getCppuType( (const float *)0 ), rVal
, rBlock
._toFloat
);
644 convertTo( ::getCppuType( (const double *)0 ), rVal
, rBlock
._toDouble
);
645 convertTo( ::getCppuType( (const sal_uInt32
*)0 ), rVal
, rBlock
._toUINT32
);
646 convertTo( ::getCppuType( (const sal_Int32
*)0 ), rVal
, rBlock
._toINT32
);
647 convertTo( ::getCppuType( (const sal_uInt16
*)0 ), rVal
, rBlock
._toUINT16
);
648 convertTo( ::getCppuType( (const sal_Int16
*)0 ), rVal
, rBlock
._toINT16
);
649 convertTo( ::getCppuType( (const sal_Int8
*)0 ), rVal
, rBlock
._toBYTE
);
650 convertTo( ::getBooleanCppuType(), rVal
, rBlock
._toBOOL
);
651 convertTo( ::getCharCppuType(), rVal
, rBlock
._toChar
);
652 convertTo( ::getCppuType( (const TypeClass
*)0 ), rVal
, rBlock
._toTypeClass
);
653 convertTo( ::getCppuType( (const Sequence
< sal_Int16
> *)0 ), rVal
, rBlock
._toSeqINT16
);
654 convertTo( ::getCppuType( (const Sequence
< Any
> *)0 ), rVal
, rBlock
._toSeqAny
);
656 convertTo( ::getVoidCppuType(), rVal
, sal_True
); // anything converts to void
658 s_xConverter
.clear();
660 delete [] pTestBlocks
;
663 aRet
= xConverter
->convertTo( Any( &xMgr
, ::getCppuType( (const Reference
< XMultiServiceFactory
> *)0 ) ),
664 ::getCppuType( (const Reference
< XServiceInfo
> *)0 ) );
665 aRet
= xConverter
->convertTo( aRet
, ::getCppuType( (const Reference
< XMultiServiceFactory
> *)0 ) );
666 aRet
= xConverter
->convertTo( aRet
, ::getCppuType( (const Reference
< XServiceInfo
> *)0 ) );
667 aRet
<<= SAL_CONST_INT64(0x7fffffffffffffff);
668 aRet
= xConverter
->convertTo( aRet
, ::getCppuType( (const sal_uInt64
*)0 ) );
669 OSL_ASSERT( *(const sal_uInt64
*)aRet
.getValue() == SAL_CONST_UINT64(0x7fffffffffffffff) );
670 aRet
<<= SAL_CONST_UINT64(0xffffffffffffffff);
671 aRet
= xConverter
->convertTo( aRet
, ::getCppuType( (const sal_uInt64
*)0 ) );
672 OSL_ASSERT( *(const sal_uInt64
*)aRet
.getValue() == SAL_CONST_UINT64(0xffffffffffffffff) );
673 aRet
<<= SAL_CONST_INT64(-1);
674 aRet
= xConverter
->convertTo( aRet
, ::getCppuType( (const sal_Int8
*)0 ) );
675 OSL_ASSERT( *(const sal_Int8
*)aRet
.getValue() == (-1) );
676 printf( "test_Conversion(): end.\n" );
681 Reference
< XMultiServiceFactory
> xMgr( createRegistryServiceFactory( OUString::createFromAscii("stoctest.rdb") ) );
685 Reference
< XImplementationRegistration
> xImplReg(
686 xMgr
->createInstance( OUString::createFromAscii("com.sun.star.registry.ImplementationRegistration") ), UNO_QUERY
);
687 OSL_ENSURE( xImplReg
.is(), "### no impl reg!" );
690 RTL_CONSTASCII_USTRINGPARAM("stocservices.uno" SAL_DLLEXTENSION
) );
691 xImplReg
->registerImplementation(
692 OUString::createFromAscii("com.sun.star.loader.SharedLibrary"),
693 aLibName
, Reference
< XSimpleRegistry
>() );
695 test_Conversion( xMgr
);
697 catch (Exception
& rExc
)
699 OSL_ENSURE( sal_False
, "### exception occured!" );
700 OString
aMsg( OUStringToOString( rExc
.Message
, RTL_TEXTENCODING_ASCII_US
) );
701 OSL_TRACE( "### exception occured: " );
702 OSL_TRACE( aMsg
.getStr() );
706 Reference
< XComponent
>( xMgr
, UNO_QUERY
)->dispose();