1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
22 #include <osl/diagnose.h>
23 #include <rtl/ustrbuf.hxx>
24 #include <cppuhelper/servicefactory.hxx>
26 #include <com/sun/star/lang/XComponent.hpp>
27 #include <com/sun/star/lang/XServiceInfo.hpp>
28 #include <com/sun/star/script/XTypeConverter.hpp>
29 #include <com/sun/star/reflection/FieldAccessMode.hpp>
30 #include <com/sun/star/registry/XImplementationRegistration.hpp>
38 using namespace com::sun::star::uno
;
39 using namespace com::sun::star::lang
;
40 using namespace com::sun::star::script
;
41 using namespace com::sun::star::reflection
;
42 using namespace com::sun::star::registry
;
44 using ::rtl::OUString
;
45 using ::rtl::OUStringToOString
;
47 const double MIN_DOUBLE
= -DBL_MAX
;
48 const double MAX_DOUBLE
= DBL_MAX
;
49 const double MIN_FLOAT
= -FLT_MAX
;
50 const double MAX_FLOAT
= FLT_MAX
;
52 //==================================================================================================
53 static void printValue( const Any
& rVal
)
56 OString
aStr( OUStringToOString( rVal
.getValueType().getTypeName(), RTL_TEXTENCODING_ISO_8859_1
) );
57 printf( "(%s)", aStr
.getStr() );
59 switch (rVal
.getValueTypeClass())
66 printValue( *(Any
*)rVal
.getValue() );
68 case TypeClass_BOOLEAN
:
69 printf( "%s", (*(sal_Bool
*)rVal
.getValue() ? "true" : "false") );
74 ar
[0] = (char)*(sal_Unicode
*)rVal
.getValue();
80 printf( "%x", (int)*(sal_Int8
*)rVal
.getValue() );
83 printf( "%x", *(sal_Int16
*)rVal
.getValue() );
85 case TypeClass_UNSIGNED_SHORT
:
86 printf( "%x", *(sal_uInt16
*)rVal
.getValue() );
89 printf( "%lx", static_cast<long>(*(sal_Int32
*)rVal
.getValue()) );
91 case TypeClass_UNSIGNED_LONG
:
92 printf( "%lx", static_cast<unsigned long>(*(sal_uInt32
*)rVal
.getValue()) );
95 printf( "%lx", (long)*(sal_Int64
*)rVal
.getValue() );
97 case TypeClass_UNSIGNED_HYPER
:
98 printf( "%lx", (unsigned long)*(sal_uInt64
*)rVal
.getValue() );
100 case TypeClass_FLOAT
:
101 printf( "%f", *(float *)rVal
.getValue() );
103 case TypeClass_DOUBLE
:
104 printf( "%g", *(double *)rVal
.getValue() );
106 case TypeClass_STRING
:
108 OString
aStr2( OUStringToOString( *(OUString
*)rVal
.getValue(), RTL_TEXTENCODING_ISO_8859_1
) );
109 printf( aStr2
.getStr() );
114 typelib_EnumTypeDescription
* pEnumTD
= 0;
115 TYPELIB_DANGER_GET( (typelib_TypeDescription
**)&pEnumTD
, rVal
.getValueTypeRef() );
117 for ( sal_Int32 nPos
= pEnumTD
->nEnumValues
; nPos
--; )
119 if (pEnumTD
->pEnumValues
[nPos
] == *(int *)rVal
.getValue())
121 printf( OUStringToOString(pEnumTD
->ppEnumNames
[nPos
]->buffer
, RTL_TEXTENCODING_ASCII_US
).getStr() );
122 TYPELIB_DANGER_RELEASE( (typelib_TypeDescription
*)pEnumTD
);
126 TYPELIB_DANGER_RELEASE( (typelib_TypeDescription
*)pEnumTD
);
127 printf( ">ENUM not found!<" );
130 case TypeClass_SEQUENCE
:
132 uno_Sequence
* pSeq
= *(uno_Sequence
**)rVal
.getValue();
133 typelib_TypeDescription
* pSeqTD
= 0;
134 TYPELIB_DANGER_GET( &pSeqTD
, rVal
.getValueTypeRef() );
135 typelib_TypeDescription
* pElemTD
= 0;
136 TYPELIB_DANGER_GET( &pElemTD
, ((typelib_IndirectTypeDescription
*)pSeqTD
)->pType
);
138 sal_Int32 nLen
= pSeq
->nElements
;
142 for ( sal_Int32 nPos
= 0; nPos
< nLen
; ++nPos
)
144 printValue( Any( ((char *)pSeq
->elements
) + (nPos
* pElemTD
->nSize
), pElemTD
) );
151 TYPELIB_DANGER_RELEASE( pElemTD
);
152 TYPELIB_DANGER_RELEASE( pSeqTD
);
157 printf( ">not printable<" );
162 static Reference
< XTypeConverter
> s_xConverter
;
164 //==================================================================================================
165 static sal_Bool
convertTo( const Type
& rDestType
, const Any
& rVal
, sal_Bool bExpectSuccess
)
167 sal_Bool bCanConvert
= sal_False
;
174 aRet
= s_xConverter
->convertTo( rVal
, rDestType
);
175 bCanConvert
= sal_True
;
177 catch (const Exception
& rExc
)
179 aExcMsg
= OUStringToOString( rExc
.Message
, RTL_TEXTENCODING_ASCII_US
);
182 if (bExpectSuccess
&& !bCanConvert
)
184 printf( "# conversion of " );
187 printf( OUStringToOString(rDestType
.getTypeName(), RTL_TEXTENCODING_ASCII_US
).getStr() );
188 printf( " failed, but success was expected! [" );
189 printf( aExcMsg
.getStr() );
191 aRet
= s_xConverter
->convertTo( rVal
, rDestType
);
192 #if OSL_DEBUG_LEVEL > 1
193 // for debugging, to trace again
196 aRet
= s_xConverter
->convertTo( rVal
, rDestType
);
204 if (!bExpectSuccess
&& bCanConvert
)
206 printf( "# conversion of " );
210 printf( " was successful, but was not expected to be!\n" );
211 #if OSL_DEBUG_LEVEL > 1
212 // for debugging, to trace again
213 aRet
= s_xConverter
->convertTo( rVal
, rDestType
);
218 #ifdef __RECONVERSION_OUTPUT__
219 //= re-conversion output =
222 // re convert to original type
223 sal_Bool bReConvert
= sal_False
;
228 aRet2
= s_xConverter
->convertTo( aRet
, rVal
.getValueType() );
229 bReConvert
= sal_True
;
231 catch (const Exception
& rExc
)
233 aExcMsg
= OUStringToOString( rExc
.Message
, RTL_TEXTENCODING_ISO_8859_1
);
240 printf( "# re-conversion of " );
246 printf( ": first and last do not match!\n" );
251 printf( "# re-conversion of " );
254 printf( rVal
.getValueType().getTypeName().getStr() );
255 printf( " failed! [" );
256 printf( aExcMsg
.getStr() );
266 //==================================================================================================
267 typedef struct _ConvBlock
270 sal_Bool _toString
, _toDouble
, _toFloat
;
271 sal_Bool _toUINT32
, _toINT32
, _toUINT16
, _toINT16
, _toBYTE
, _toBOOL
, _toChar
;
272 sal_Bool _toTypeClass
, _toSeqINT16
, _toSeqAny
;
277 _ConvBlock( const Any
& rValue_
,
278 sal_Bool toString_
, sal_Bool toDouble_
, sal_Bool toFloat_
,
279 sal_Bool toUINT32_
, sal_Bool toINT32_
, sal_Bool toUINT16_
, sal_Bool toINT16_
,
280 sal_Bool toBYTE_
, sal_Bool toBOOL_
, sal_Bool toChar_
,
281 sal_Bool toTypeClass_
, sal_Bool toSeqINT16_
, sal_Bool toSeqAny_
)
283 , _toString( toString_
), _toDouble( toDouble_
), _toFloat( toFloat_
)
284 , _toUINT32( toUINT32_
), _toINT32( toINT32_
), _toUINT16( toUINT16_
), _toINT16( toINT16_
)
285 , _toBYTE( toBYTE_
), _toBOOL( toBOOL_
), _toChar( toChar_
)
286 , _toTypeClass( toTypeClass_
), _toSeqINT16( toSeqINT16_
), _toSeqAny( toSeqAny_
)
292 //==================================================================================================
293 static sal_Int32
initBlocks( ConvBlock
* pTestBlocks
)
297 sal_uInt32 nElems
= 0;
300 aVal
<<= OUString(RTL_CONSTASCII_USTRINGPARAM("0xff"));
301 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0 );
302 aVal
<<= OUString(RTL_CONSTASCII_USTRINGPARAM("255"));
303 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0 );
304 aVal
<<= (sal_Int8
)0xffu
;
305 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 0, 0, 0 );
306 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
307 aVal
<<= OUString(RTL_CONSTASCII_USTRINGPARAM("0x80"));
308 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0 );
309 aVal
<<= OUString(RTL_CONSTASCII_USTRINGPARAM("128"));
310 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0 );
311 aVal
<<= (sal_Int8
)( 0x80u
);
312 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 0, 0, 0 );
313 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
314 aVal
<<= OUString(RTL_CONSTASCII_USTRINGPARAM("0x7f"));
315 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 );
316 aVal
<<= OUString(RTL_CONSTASCII_USTRINGPARAM("127"));
317 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 );
318 aVal
<<= (sal_Int8
)( 0x7f );
319 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0 );
320 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
321 aVal
<<= OUString(RTL_CONSTASCII_USTRINGPARAM("5"));
322 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 0, 0 );
323 aVal
<<= OUString(RTL_CONSTASCII_USTRINGPARAM("+5"));
324 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 );
325 aVal
<<= (sal_Int8
)( 5 );
326 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0 );
327 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
328 aVal
<<= OUString(RTL_CONSTASCII_USTRINGPARAM("-5"));
329 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 0, 1, 0, 1, 1, 0, 0, 0, 0, 0 );
330 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
331 aVal
<<= (sal_Int8
)( -5 );
332 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 0, 0, 0 );
333 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
334 aVal
<<= OUString(RTL_CONSTASCII_USTRINGPARAM("256"));
335 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0 );
336 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
338 aVal
<<= OUString(RTL_CONSTASCII_USTRINGPARAM("65535"));
339 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0 );
340 aVal
<<= OUString(RTL_CONSTASCII_USTRINGPARAM("0xffff"));
341 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0 );
342 aVal
<<= (sal_uInt16
)( 0xffff );
343 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 0, 0 );
344 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
345 aVal
<<= OUString(RTL_CONSTASCII_USTRINGPARAM("32768"));
346 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0 );
347 aVal
<<= (sal_uInt16
)( 0x8000 );
348 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 0, 0 );
349 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
350 aVal
<<= OUString(RTL_CONSTASCII_USTRINGPARAM("32767"));
351 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0 );
352 aVal
<<= OUString(RTL_CONSTASCII_USTRINGPARAM("0x7fff"));
353 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0 );
354 aVal
<<= (sal_uInt16
)( 0x7fff );
355 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 0, 0 );
356 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
357 aVal
<<= OUString(RTL_CONSTASCII_USTRINGPARAM("256"));
358 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0 );
359 aVal
<<= OUString(RTL_CONSTASCII_USTRINGPARAM("0x100"));
360 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0 );
361 aVal
<<= (sal_uInt16
)( 0x100 );
362 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 0, 0 );
363 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
364 aVal
<<= (sal_uInt16
)( 5 );
365 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0 );
366 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
367 aVal
<<= (sal_uInt16
)( -5 ); // is 0xfffb
368 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 0, 0 );
369 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
371 aVal
<<= (sal_Int16
)( -1 );
372 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 0, 0, 0 );
373 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
374 aVal
<<= (sal_Int16
)( -0x8000 );
375 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0 );
376 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
377 aVal
<<= (sal_Int16
)( 0x7fff );
378 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 0, 0 );
379 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
380 aVal
<<= (sal_Int16
)( 0x100 );
381 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 0, 0 );
382 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
383 aVal
<<= (sal_Int16
)( 5 );
384 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0 );
385 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
386 aVal
<<= (sal_Int16
)( -5 );
387 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 0, 0, 0 );
388 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
390 aVal
<<= OUString(RTL_CONSTASCII_USTRINGPARAM("+4294967295"));
391 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 );
392 aVal
<<= OUString(RTL_CONSTASCII_USTRINGPARAM("4294967295"));
393 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 );
394 aVal
<<= OUString(RTL_CONSTASCII_USTRINGPARAM("0xffffffff"));
395 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 );
396 aVal
<<= (sal_uInt32
)( 0xffffffff );
397 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0 );
398 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
399 aVal
<<= OUString(RTL_CONSTASCII_USTRINGPARAM("-2147483648"));
400 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 );
401 aVal
<<= OUString(RTL_CONSTASCII_USTRINGPARAM("-0x80000000"));
402 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 );
403 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
404 aVal
<<= (sal_uInt32
)( 0x80000000 );
405 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0 );
406 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
407 aVal
<<= OUString(RTL_CONSTASCII_USTRINGPARAM("2147483647"));
408 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0 );
409 aVal
<<= OUString(RTL_CONSTASCII_USTRINGPARAM("0x7fffffff"));
410 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0 );
411 aVal
<<= (sal_uInt32
)( 0x7fffffff );
412 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0 );
413 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
414 aVal
<<= OUString(RTL_CONSTASCII_USTRINGPARAM("65536"));
415 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0 );
416 aVal
<<= OUString(RTL_CONSTASCII_USTRINGPARAM("0x10000"));
417 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0 );
418 aVal
<<= (sal_uInt32
)( 0x10000 );
419 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0 );
420 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
421 aVal
<<= (sal_uInt32
)( 0x8000 );
422 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 0, 0 );
423 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
424 aVal
<<= (sal_uInt32
)( 5 );
425 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0 );
426 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
427 aVal
<<= OUString(RTL_CONSTASCII_USTRINGPARAM("0xfffffffb"));
428 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 );
429 aVal
<<= (sal_uInt32
)( -5 ); // is 0xfffffffb
430 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0 );
431 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
433 aVal
<<= (sal_Int32
)( 0xffffffff ); // is -1
434 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 0, 0, 0 );
435 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
436 aVal
<<= (sal_Int32
)( 0x80000000 );
437 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0 );
438 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
439 aVal
<<= (sal_Int32
)( 0x7fffffff );
440 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0 );
441 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
442 aVal
<<= (sal_Int32
)( 0x10000 );
443 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0 );
444 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
445 aVal
<<= (sal_Int32
)( -0x8001 );
446 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0 );
447 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
448 aVal
<<= (sal_Int32
)( 5 );
449 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0 );
450 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
451 aVal
<<= (sal_Int32
)( -5 );
452 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 0, 0, 0 );
453 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
455 aVal
<<= OUString(RTL_CONSTASCII_USTRINGPARAM("-3.4e+38"));
456 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 );
457 aVal
<<= (float)( MIN_FLOAT
);
458 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 );
459 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
460 aVal
<<= OUString(RTL_CONSTASCII_USTRINGPARAM("+3.4e+38"));
461 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 );
462 aVal
<<= (float)( MAX_FLOAT
);
463 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 );
464 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
465 aVal
<<= OUString(RTL_CONSTASCII_USTRINGPARAM("9e-20"));
466 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 );
467 aVal
<<= (float)( 9e-20 );
468 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0 );
469 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
470 aVal
<<= OUString(RTL_CONSTASCII_USTRINGPARAM("+.7071067811865"));
471 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 );
472 aVal
<<= (float)( .7071067811865 );
473 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0 );
474 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
475 aVal
<<= OUString(RTL_CONSTASCII_USTRINGPARAM("3.14159265359"));
476 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 );
477 aVal
<<= (float)( 3.14159265359 );
478 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0 );
479 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
480 aVal
<<= (float)( 5 );
481 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0 );
482 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
484 aVal
<<= OUString(RTL_CONSTASCII_USTRINGPARAM("-1.7976931348623155e+308"));
485 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 );
486 aVal
<<= (double)( MIN_DOUBLE
);
487 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 );
488 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
489 aVal
<<= OUString(RTL_CONSTASCII_USTRINGPARAM("1.7976931348623155e+308"));
490 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 );
491 aVal
<<= (double)( MAX_DOUBLE
);
492 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 );
493 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
494 aVal
<<= (double)( MIN_FLOAT
);
495 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 );
496 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
497 aVal
<<= (double)( MAX_FLOAT
);
498 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 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
<<= (double)( -((double)0x80000000) );
501 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0 );
502 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
503 aVal
<<= (double)( -((double)0x80000001) );
504 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 );
505 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
506 aVal
<<= (double)( 0x7fffffff );
507 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0 );
508 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
509 aVal
<<= (double)( 0x80000000 );
510 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0 );
511 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
512 aVal
<<= (double)( 0xffffffff );
513 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0 );
514 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
515 aVal
<<= OUString(RTL_CONSTASCII_USTRINGPARAM("0x100000000"));
516 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 );
517 aVal
<<= (double)( SAL_CONST_INT64(0x100000000) );
518 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 0, 0, 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)( 5 );
521 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0 );
522 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
525 aVal
.setValue( &c
, ::getCharCppuType() );
526 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0 );
527 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
528 aVal
<<= OUString(RTL_CONSTASCII_USTRINGPARAM("A"));
529 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0 );
530 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
532 aVal
<<= OUString(RTL_CONSTASCII_USTRINGPARAM("0"));
533 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0 );
534 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
535 aVal
<<= OUString(RTL_CONSTASCII_USTRINGPARAM("1"));
536 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0 );
537 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
538 aVal
<<= OUString(RTL_CONSTASCII_USTRINGPARAM("False"));
539 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 );
540 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
541 aVal
<<= OUString(RTL_CONSTASCII_USTRINGPARAM("true"));
542 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 );
543 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
545 sal_Bool bTmp
= sal_True
;
546 aVal
.setValue( &bTmp
, getBooleanCppuType() );
547 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0 );
548 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
551 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 );
552 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
553 aVal
<<= OUString(RTL_CONSTASCII_USTRINGPARAM("-"));
554 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 0, 0 );
555 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
556 aVal
<<= OUString(RTL_CONSTASCII_USTRINGPARAM("-0"));
557 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 );
558 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
559 // ==TYPECLASS ENUM==
560 aVal
<<= OUString(RTL_CONSTASCII_USTRINGPARAM("eNuM"));
561 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0 );
562 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
563 aVal
<<= OUString(RTL_CONSTASCII_USTRINGPARAM("DOUBLE"));
564 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0 );
565 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
567 aVal
.setValue( &e
, ::getCppuType( (const TypeClass
*)0 ) );
568 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 0 );
569 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
570 aVal
.setValue( &e
, ::getCppuType( (const FieldAccessMode
*)0 ) );
571 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 );
572 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
574 Sequence
< sal_Int32
> aINT32Seq( 3 ), aINT32Seq2( 3 );
575 sal_Int32
* pINT32Seq
= aINT32Seq
.getArray();
576 pINT32Seq
[0] = -32768;
578 pINT32Seq
[2] = 32767;
580 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1 );
581 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
582 pINT32Seq
= aINT32Seq2
.getArray();
583 pINT32Seq
[0] = -32768;
584 pINT32Seq
[1] = -32769;
585 pINT32Seq
[2] = 32767;
587 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 );
588 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
590 Sequence
< Any
> aAnySeq( 2 ), aAnySeq2( 2 ), aAnySeq3( 2 );
591 Any
* pAnySeq
= aAnySeq
.getArray();
592 pAnySeq
[0] = makeAny( aINT32Seq
);
593 pAnySeq
[1] = makeAny( OUString(RTL_CONSTASCII_USTRINGPARAM("lala")) );
595 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 );
596 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
597 pAnySeq
= aAnySeq2
.getArray();
598 pAnySeq
[0] <<= (sal_Int32
)4711;
599 pAnySeq
[1] <<= OUString(RTL_CONSTASCII_USTRINGPARAM("0815"));
601 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1 );
602 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
603 pAnySeq
= aAnySeq3
.getArray();
604 pAnySeq
[0] <<= OUString(RTL_CONSTASCII_USTRINGPARAM("TypeClass_UNION"));
605 pAnySeq
[1] <<= OUString(RTL_CONSTASCII_USTRINGPARAM("TypeClass_ENUM"));
607 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 );
608 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
612 //==================================================================================================
613 static void test_Conversion( const Reference
< XMultiServiceFactory
> & xMgr
)
615 printf( "test_Conversion(): start...\n" );
617 Reference
< XTypeConverter
> xConverter( xMgr
->createInstance(
618 OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.script.Converter")) ), UNO_QUERY
);
620 ConvBlock
* pTestBlocks
= new ConvBlock
[256];
621 sal_Int32 nPos
= initBlocks( pTestBlocks
);
623 s_xConverter
= xConverter
;
626 const ConvBlock
& rBlock
= pTestBlocks
[nPos
];
627 const Any
& rVal
= rBlock
._value
;
629 convertTo( ::getCppuType( (const OUString
*)0 ), rVal
, rBlock
._toString
);
630 convertTo( ::getCppuType( (const float *)0 ), rVal
, rBlock
._toFloat
);
631 convertTo( ::getCppuType( (const double *)0 ), rVal
, rBlock
._toDouble
);
632 convertTo( ::getCppuType( (const sal_uInt32
*)0 ), rVal
, rBlock
._toUINT32
);
633 convertTo( ::getCppuType( (const sal_Int32
*)0 ), rVal
, rBlock
._toINT32
);
634 convertTo( ::getCppuType( (const sal_uInt16
*)0 ), rVal
, rBlock
._toUINT16
);
635 convertTo( ::getCppuType( (const sal_Int16
*)0 ), rVal
, rBlock
._toINT16
);
636 convertTo( ::getCppuType( (const sal_Int8
*)0 ), rVal
, rBlock
._toBYTE
);
637 convertTo( ::getBooleanCppuType(), rVal
, rBlock
._toBOOL
);
638 convertTo( ::getCharCppuType(), rVal
, rBlock
._toChar
);
639 convertTo( ::getCppuType( (const TypeClass
*)0 ), rVal
, rBlock
._toTypeClass
);
640 convertTo( ::getCppuType( (const Sequence
< sal_Int16
> *)0 ), rVal
, rBlock
._toSeqINT16
);
641 convertTo( ::getCppuType( (const Sequence
< Any
> *)0 ), rVal
, rBlock
._toSeqAny
);
643 convertTo( ::getVoidCppuType(), rVal
, sal_True
); // anything converts to void
645 s_xConverter
.clear();
647 delete [] pTestBlocks
;
650 aRet
= xConverter
->convertTo( Any( &xMgr
, ::getCppuType( (const Reference
< XMultiServiceFactory
> *)0 ) ),
651 ::getCppuType( (const Reference
< XServiceInfo
> *)0 ) );
652 aRet
= xConverter
->convertTo( aRet
, ::getCppuType( (const Reference
< XMultiServiceFactory
> *)0 ) );
653 aRet
= xConverter
->convertTo( aRet
, ::getCppuType( (const Reference
< XServiceInfo
> *)0 ) );
654 aRet
<<= SAL_CONST_INT64(0x7fffffffffffffff);
655 aRet
= xConverter
->convertTo( aRet
, ::getCppuType( (const sal_uInt64
*)0 ) );
656 OSL_ASSERT( *(const sal_uInt64
*)aRet
.getValue() == SAL_CONST_UINT64(0x7fffffffffffffff) );
657 aRet
<<= SAL_CONST_UINT64(0xffffffffffffffff);
658 aRet
= xConverter
->convertTo( aRet
, ::getCppuType( (const sal_uInt64
*)0 ) );
659 OSL_ASSERT( *(const sal_uInt64
*)aRet
.getValue() == SAL_CONST_UINT64(0xffffffffffffffff) );
660 aRet
<<= SAL_CONST_INT64(-1);
661 aRet
= xConverter
->convertTo( aRet
, ::getCppuType( (const sal_Int8
*)0 ) );
662 OSL_ASSERT( *(const sal_Int8
*)aRet
.getValue() == (-1) );
663 printf( "test_Conversion(): end.\n" );
668 Reference
< XMultiServiceFactory
> xMgr( createRegistryServiceFactory( OUString(RTL_CONSTASCII_USTRINGPARAM("stoctest.rdb")) ) );
672 Reference
< XImplementationRegistration
> xImplReg(
673 xMgr
->createInstance( OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.registry.ImplementationRegistration")) ), UNO_QUERY
);
674 OSL_ENSURE( xImplReg
.is(), "### no impl reg!" );
677 RTL_CONSTASCII_USTRINGPARAM("stocservices.uno" SAL_DLLEXTENSION
) );
678 xImplReg
->registerImplementation(
679 OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.loader.SharedLibrary")),
680 aLibName
, Reference
< XSimpleRegistry
>() );
682 test_Conversion( xMgr
);
684 catch (const Exception
& rExc
)
686 OSL_FAIL( "### exception occurred!" );
687 OString
aMsg( OUStringToOString( rExc
.Message
, RTL_TEXTENCODING_ASCII_US
) );
688 OSL_TRACE( "### exception occurred: " );
689 OSL_TRACE( "%s", aMsg
.getStr() );
693 Reference
< XComponent
>( xMgr
, UNO_QUERY
)->dispose();
697 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */