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>
39 using namespace css::uno
;
40 using namespace css::lang
;
41 using namespace css::script
;
42 using namespace css::reflection
;
43 using namespace css::registry
;
46 const double MIN_DOUBLE
= -DBL_MAX
;
47 const double MAX_DOUBLE
= DBL_MAX
;
48 const double MIN_FLOAT
= -FLT_MAX
;
49 const double MAX_FLOAT
= FLT_MAX
;
52 static void printValue( const Any
& rVal
)
55 OString
aStr( OUStringToOString( rVal
.getValueType().getTypeName(), RTL_TEXTENCODING_ISO_8859_1
) );
56 printf( "(%s)", aStr
.getStr() );
58 switch (rVal
.getValueTypeClass())
65 printValue( *(Any
*)rVal
.getValue() );
67 case TypeClass_BOOLEAN
:
68 printf( "%s", (*(sal_Bool
*)rVal
.getValue() ? "true" : "false") );
73 ar
[0] = (char)*(sal_Unicode
*)rVal
.getValue();
79 printf( "%x", (int)*(sal_Int8
*)rVal
.getValue() );
82 printf( "%x", *(sal_Int16
*)rVal
.getValue() );
84 case TypeClass_UNSIGNED_SHORT
:
85 printf( "%x", *(sal_uInt16
*)rVal
.getValue() );
88 printf( "%lx", static_cast<long>(*(sal_Int32
*)rVal
.getValue()) );
90 case TypeClass_UNSIGNED_LONG
:
91 printf( "%lx", static_cast<unsigned long>(*(sal_uInt32
*)rVal
.getValue()) );
94 printf( "%lx", (long)*(sal_Int64
*)rVal
.getValue() );
96 case TypeClass_UNSIGNED_HYPER
:
97 printf( "%lx", (unsigned long)*(sal_uInt64
*)rVal
.getValue() );
100 printf( "%f", *(float *)rVal
.getValue() );
102 case TypeClass_DOUBLE
:
103 printf( "%g", *(double *)rVal
.getValue() );
105 case TypeClass_STRING
:
107 OString
aStr2( OUStringToOString( *(OUString
*)rVal
.getValue(), RTL_TEXTENCODING_ISO_8859_1
) );
108 printf( aStr2
.getStr() );
113 typelib_EnumTypeDescription
* pEnumTD
= 0;
114 TYPELIB_DANGER_GET( (typelib_TypeDescription
**)&pEnumTD
, rVal
.getValueTypeRef() );
116 for ( sal_Int32 nPos
= pEnumTD
->nEnumValues
; nPos
--; )
118 if (pEnumTD
->pEnumValues
[nPos
] == *(int *)rVal
.getValue())
120 printf( OUStringToOString(pEnumTD
->ppEnumNames
[nPos
]->buffer
, RTL_TEXTENCODING_ASCII_US
).getStr() );
121 TYPELIB_DANGER_RELEASE( (typelib_TypeDescription
*)pEnumTD
);
125 TYPELIB_DANGER_RELEASE( (typelib_TypeDescription
*)pEnumTD
);
126 printf( ">ENUM not found!<" );
129 case TypeClass_SEQUENCE
:
131 uno_Sequence
* pSeq
= *(uno_Sequence
**)rVal
.getValue();
132 typelib_TypeDescription
* pSeqTD
= 0;
133 TYPELIB_DANGER_GET( &pSeqTD
, rVal
.getValueTypeRef() );
134 typelib_TypeDescription
* pElemTD
= 0;
135 TYPELIB_DANGER_GET( &pElemTD
, ((typelib_IndirectTypeDescription
*)pSeqTD
)->pType
);
137 sal_Int32 nLen
= pSeq
->nElements
;
141 for ( sal_Int32 nPos
= 0; nPos
< nLen
; ++nPos
)
143 printValue( Any( ((char *)pSeq
->elements
) + (nPos
* pElemTD
->nSize
), pElemTD
) );
150 TYPELIB_DANGER_RELEASE( pElemTD
);
151 TYPELIB_DANGER_RELEASE( pSeqTD
);
156 printf( ">not printable<" );
161 static Reference
< XTypeConverter
> s_xConverter
;
164 static sal_Bool
convertTo( const Type
& rDestType
, const Any
& rVal
, sal_Bool bExpectSuccess
)
166 sal_Bool bCanConvert
= sal_False
;
173 aRet
= s_xConverter
->convertTo( rVal
, rDestType
);
174 bCanConvert
= sal_True
;
176 catch (const Exception
& rExc
)
178 aExcMsg
= OUStringToOString( rExc
.Message
, RTL_TEXTENCODING_ASCII_US
);
181 if (bExpectSuccess
&& !bCanConvert
)
183 printf( "# conversion of " );
186 printf( OUStringToOString(rDestType
.getTypeName(), RTL_TEXTENCODING_ASCII_US
).getStr() );
187 printf( " failed, but success was expected! [" );
188 printf( aExcMsg
.getStr() );
190 aRet
= s_xConverter
->convertTo( rVal
, rDestType
);
191 #if OSL_DEBUG_LEVEL > 0
192 // for debugging, to trace again
195 aRet
= s_xConverter
->convertTo( rVal
, rDestType
);
203 if (!bExpectSuccess
&& bCanConvert
)
205 printf( "# conversion of " );
209 printf( " was successful, but was not expected to be!\n" );
210 #if OSL_DEBUG_LEVEL > 0
211 // for debugging, to trace again
212 aRet
= s_xConverter
->convertTo( rVal
, rDestType
);
217 #ifdef __RECONVERSION_OUTPUT__
218 //= re-conversion output =
221 // re convert to original type
222 sal_Bool bReConvert
= sal_False
;
227 aRet2
= s_xConverter
->convertTo( aRet
, rVal
.getValueType() );
228 bReConvert
= sal_True
;
230 catch (const Exception
& rExc
)
232 aExcMsg
= OUStringToOString( rExc
.Message
, RTL_TEXTENCODING_ISO_8859_1
);
239 printf( "# re-conversion of " );
245 printf( ": first and last do not match!\n" );
250 printf( "# re-conversion of " );
253 printf( rVal
.getValueType().getTypeName().getStr() );
254 printf( " failed! [" );
255 printf( aExcMsg
.getStr() );
265 typedef struct _ConvBlock
268 sal_Bool _toString
, _toDouble
, _toFloat
;
269 sal_Bool _toUINT32
, _toINT32
, _toUINT16
, _toINT16
, _toBYTE
, _toBOOL
, _toChar
;
270 sal_Bool _toTypeClass
, _toSeqINT16
, _toSeqAny
;
275 _ConvBlock( const Any
& rValue_
,
276 sal_Bool toString_
, sal_Bool toDouble_
, sal_Bool toFloat_
,
277 sal_Bool toUINT32_
, sal_Bool toINT32_
, sal_Bool toUINT16_
, sal_Bool toINT16_
,
278 sal_Bool toBYTE_
, sal_Bool toBOOL_
, sal_Bool toChar_
,
279 sal_Bool toTypeClass_
, sal_Bool toSeqINT16_
, sal_Bool toSeqAny_
)
281 , _toString( toString_
), _toDouble( toDouble_
), _toFloat( toFloat_
)
282 , _toUINT32( toUINT32_
), _toINT32( toINT32_
), _toUINT16( toUINT16_
), _toINT16( toINT16_
)
283 , _toBYTE( toBYTE_
), _toBOOL( toBOOL_
), _toChar( toChar_
)
284 , _toTypeClass( toTypeClass_
), _toSeqINT16( toSeqINT16_
), _toSeqAny( toSeqAny_
)
290 static sal_Int32
initBlocks( ConvBlock
* pTestBlocks
)
294 sal_uInt32 nElems
= 0;
297 aVal
<<= OUString("0xff");
298 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0 );
299 aVal
<<= OUString("255");
300 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0 );
301 aVal
<<= (sal_Int8
)0xffu
;
302 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 0, 0, 0 );
303 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
304 aVal
<<= OUString("0x80");
305 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0 );
306 aVal
<<= OUString("128");
307 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0 );
308 aVal
<<= (sal_Int8
)( 0x80u
);
309 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 0, 0, 0 );
310 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
311 aVal
<<= OUString("0x7f");
312 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 );
313 aVal
<<= OUString("127");
314 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 );
315 aVal
<<= (sal_Int8
)( 0x7f );
316 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0 );
317 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
318 aVal
<<= OUString("5");
319 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 0, 0 );
320 aVal
<<= OUString("+5");
321 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 );
322 aVal
<<= (sal_Int8
)( 5 );
323 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0 );
324 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
325 aVal
<<= OUString("-5");
326 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 0, 1, 0, 1, 1, 0, 0, 0, 0, 0 );
327 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
328 aVal
<<= (sal_Int8
)( -5 );
329 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 0, 0, 0 );
330 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
331 aVal
<<= OUString("256");
332 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0 );
333 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
335 aVal
<<= OUString("65535");
336 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0 );
337 aVal
<<= OUString("0xffff");
338 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0 );
339 aVal
<<= (sal_uInt16
)( 0xffff );
340 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 0, 0 );
341 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
342 aVal
<<= OUString("32768");
343 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0 );
344 aVal
<<= (sal_uInt16
)( 0x8000 );
345 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 0, 0 );
346 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
347 aVal
<<= OUString("32767");
348 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0 );
349 aVal
<<= OUString("0x7fff");
350 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0 );
351 aVal
<<= (sal_uInt16
)( 0x7fff );
352 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 0, 0 );
353 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
354 aVal
<<= OUString("256");
355 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0 );
356 aVal
<<= OUString("0x100");
357 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0 );
358 aVal
<<= (sal_uInt16
)( 0x100 );
359 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 0, 0 );
360 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
361 aVal
<<= (sal_uInt16
)( 5 );
362 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0 );
363 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
364 aVal
<<= (sal_uInt16
)( -5 ); // is 0xfffb
365 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 0, 0 );
366 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
368 aVal
<<= (sal_Int16
)( -1 );
369 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 0, 0, 0 );
370 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
371 aVal
<<= (sal_Int16
)( -0x8000 );
372 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0 );
373 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
374 aVal
<<= (sal_Int16
)( 0x7fff );
375 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 0, 0 );
376 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
377 aVal
<<= (sal_Int16
)( 0x100 );
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
)( 5 );
381 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 0, 1, 0, 1, 1, 1, 0, 0, 0, 0 );
385 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
387 aVal
<<= OUString("+4294967295");
388 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 );
389 aVal
<<= OUString("4294967295");
390 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 );
391 aVal
<<= OUString("0xffffffff");
392 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 );
393 aVal
<<= (sal_uInt32
)( 0xffffffff );
394 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0 );
395 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
396 aVal
<<= OUString("-2147483648");
397 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 );
398 aVal
<<= OUString("-0x80000000");
399 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 );
400 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
401 aVal
<<= (sal_uInt32
)( 0x80000000 );
402 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0 );
403 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
404 aVal
<<= OUString("2147483647");
405 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0 );
406 aVal
<<= OUString("0x7fffffff");
407 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0 );
408 aVal
<<= (sal_uInt32
)( 0x7fffffff );
409 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0 );
410 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
411 aVal
<<= OUString("65536");
412 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0 );
413 aVal
<<= OUString("0x10000");
414 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0 );
415 aVal
<<= (sal_uInt32
)( 0x10000 );
416 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0 );
417 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
418 aVal
<<= (sal_uInt32
)( 0x8000 );
419 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 0, 0 );
420 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
421 aVal
<<= (sal_uInt32
)( 5 );
422 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0 );
423 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
424 aVal
<<= OUString("0xfffffffb");
425 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 );
426 aVal
<<= (sal_uInt32
)( -5 ); // is 0xfffffffb
427 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0 );
428 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
430 aVal
<<= (sal_Int32
)( 0xffffffff ); // is -1
431 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 0, 0, 0 );
432 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
433 aVal
<<= (sal_Int32
)( 0x80000000 );
434 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0 );
435 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
436 aVal
<<= (sal_Int32
)( 0x7fffffff );
437 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 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
)( 0x10000 );
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
)( -0x8001 );
443 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 0, 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
)( 5 );
446 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 0, 1, 0, 1, 1, 1, 0, 0, 0, 0 );
450 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
452 aVal
<<= OUString("-3.4e+38");
453 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 );
454 aVal
<<= (float)( MIN_FLOAT
);
455 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 );
456 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
457 aVal
<<= OUString("+3.4e+38");
458 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 );
459 aVal
<<= (float)( MAX_FLOAT
);
460 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 );
461 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
462 aVal
<<= OUString("9e-20");
463 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 );
464 aVal
<<= (float)( 9e-20 );
465 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0 );
466 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
467 aVal
<<= OUString("+.7071067811865");
468 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 );
469 aVal
<<= (float)( M_SQRT1_2
);
470 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0 );
471 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
472 aVal
<<= OUString("3.14159265359");
473 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 );
474 aVal
<<= (float)( M_PI
);
475 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0 );
476 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
477 aVal
<<= (float)( 5 );
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
481 aVal
<<= OUString("-1.7976931348623155e+308");
482 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 );
483 aVal
<<= (double)( MIN_DOUBLE
);
484 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 );
485 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
486 aVal
<<= OUString("1.7976931348623155e+308");
487 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 );
488 aVal
<<= (double)( MAX_DOUBLE
);
489 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 );
490 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
491 aVal
<<= (double)( MIN_FLOAT
);
492 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 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)( MAX_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)( -((double)0x80000000) );
498 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 0, 1, 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)0x80000001) );
501 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 0, 0, 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)( 0x7fffffff );
504 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 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)( 0x80000000 );
507 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 0, 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)( 0xffffffff );
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
<<= OUString("0x100000000");
513 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 );
514 aVal
<<= (double)( SAL_CONST_INT64(0x100000000) );
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)( 5 );
518 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0 );
519 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
522 aVal
.setValue( &c
, cppu::UnoType
<cppu::UnoCharType
>::get() );
523 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0 );
524 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
525 aVal
<<= OUString("A");
526 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0 );
527 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
529 aVal
<<= OUString("0");
530 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0 );
531 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
532 aVal
<<= OUString("1");
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("False");
536 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 );
537 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
538 aVal
<<= OUString("true");
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
542 sal_Bool bTmp
= sal_True
;
543 aVal
.setValue( &bTmp
, cppu::UnoType
<bool>::get() );
544 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0 );
545 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
548 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 );
549 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
550 aVal
<<= OUString("-");
551 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 0, 0 );
552 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
553 aVal
<<= OUString("-0");
554 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 );
555 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
556 // ==TYPECLASS ENUM==
557 aVal
<<= OUString("eNuM");
558 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0 );
559 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
560 aVal
<<= OUString("DOUBLE");
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
564 aVal
.setValue( &e
, cppu::UnoType
<TypeClass
>::get());
565 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 0 );
566 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
567 aVal
.setValue( &e
, cppu::UnoType
<FieldAccessMode
>::get());
568 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 );
569 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
571 Sequence
< sal_Int32
> aINT32Seq( 3 ), aINT32Seq2( 3 );
572 sal_Int32
* pINT32Seq
= aINT32Seq
.getArray();
573 pINT32Seq
[0] = -32768;
575 pINT32Seq
[2] = 32767;
577 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1 );
578 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
579 pINT32Seq
= aINT32Seq2
.getArray();
580 pINT32Seq
[0] = -32768;
581 pINT32Seq
[1] = -32769;
582 pINT32Seq
[2] = 32767;
584 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 );
585 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
587 Sequence
< Any
> aAnySeq( 2 ), aAnySeq2( 2 );
588 Any
* pAnySeq
= aAnySeq
.getArray();
589 pAnySeq
[0] = makeAny( aINT32Seq
);
590 pAnySeq
[1] = makeAny( OUString("lala") );
592 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 );
593 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
594 pAnySeq
= aAnySeq2
.getArray();
595 pAnySeq
[0] <<= (sal_Int32
)4711;
596 pAnySeq
[1] <<= OUString("0815");
598 pTestBlocks
[nElems
++] = ConvBlock( aVal
, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1 );
599 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
604 static void test_Conversion( const Reference
< XMultiServiceFactory
> & xMgr
)
606 printf( "test_Conversion(): start...\n" );
608 Reference
< XTypeConverter
> xConverter( xMgr
->createInstance( "com.sun.star.script.Converter" ), UNO_QUERY
);
610 ConvBlock
* pTestBlocks
= new ConvBlock
[256];
611 sal_Int32 nPos
= initBlocks( pTestBlocks
);
613 s_xConverter
= xConverter
;
616 const ConvBlock
& rBlock
= pTestBlocks
[nPos
];
617 const Any
& rVal
= rBlock
._value
;
619 convertTo( cppu::UnoType
<OUString
>::get(), rVal
, rBlock
._toString
);
620 convertTo( cppu::UnoType
<float>::get(), rVal
, rBlock
._toFloat
);
621 convertTo( cppu::UnoType
<double>::get(), rVal
, rBlock
._toDouble
);
622 convertTo( cppu::UnoType
<sal_uInt32
>::get(), rVal
, rBlock
._toUINT32
);
623 convertTo( cppu::UnoType
<sal_Int32
>::get(), rVal
, rBlock
._toINT32
);
624 convertTo( cppu::UnoType
<cppu::UnoUnsignedShortType
>::get(), rVal
, rBlock
._toUINT16
);
625 convertTo( cppu::UnoType
<sal_Int16
>::get(), rVal
, rBlock
._toINT16
);
626 convertTo( cppu::UnoType
<sal_Int8
>::get(), rVal
, rBlock
._toBYTE
);
627 convertTo( cppu::UnoType
<bool>::get(), rVal
, rBlock
._toBOOL
);
628 convertTo( cppu::UnoType
<cppu::UnoCharType
>::get(), rVal
, rBlock
._toChar
);
629 convertTo( cppu::UnoType
<TypeClass
>::get(), rVal
, rBlock
._toTypeClass
);
630 convertTo( cppu::UnoType
<Sequence
< sal_Int16
>>::get(), rVal
, rBlock
._toSeqINT16
);
631 convertTo( cppu::UnoType
<Sequence
< Any
>>::get(), rVal
, rBlock
._toSeqAny
);
633 convertTo( cppu::UnoType
<void>::get(), rVal
, sal_True
); // anything converts to void
635 s_xConverter
.clear();
637 delete [] pTestBlocks
;
640 aRet
= xConverter
->convertTo( Any( &xMgr
, cppu::UnoType
<XMultiServiceFactory
>::get()),
641 cppu::UnoType
<XServiceInfo
>::get());
642 aRet
= xConverter
->convertTo( aRet
, cppu::UnoType
<XMultiServiceFactory
>::get());
643 aRet
= xConverter
->convertTo( aRet
, cppu::UnoType
<XServiceInfo
>::get());
644 aRet
<<= SAL_CONST_INT64(0x7fffffffffffffff);
645 aRet
= xConverter
->convertTo( aRet
, cppu::UnoType
<sal_uInt64
>::get());
646 OSL_ASSERT( *(const sal_uInt64
*)aRet
.getValue() == SAL_CONST_UINT64(0x7fffffffffffffff) );
647 aRet
<<= SAL_CONST_UINT64(0xffffffffffffffff);
648 aRet
= xConverter
->convertTo( aRet
, cppu::UnoType
<sal_uInt64
>::get());
649 OSL_ASSERT( *(const sal_uInt64
*)aRet
.getValue() == SAL_CONST_UINT64(0xffffffffffffffff) );
650 aRet
<<= SAL_CONST_INT64(-1);
651 aRet
= xConverter
->convertTo( aRet
, cppu::UnoType
<sal_Int8
>::get());
652 OSL_ASSERT( *(const sal_Int8
*)aRet
.getValue() == (-1) );
653 printf( "test_Conversion(): end.\n" );
658 Reference
< XMultiServiceFactory
> xMgr( createRegistryServiceFactory( OUString("stoctest.rdb") ) );
662 Reference
< XImplementationRegistration
> xImplReg(
663 xMgr
->createInstance("com.sun.star.registry.ImplementationRegistration"), UNO_QUERY
);
664 OSL_ENSURE( xImplReg
.is(), "### no impl reg!" );
666 OUString
aLibName("stocservices.uno" SAL_DLLEXTENSION
);
667 xImplReg
->registerImplementation(
668 OUString("com.sun.star.loader.SharedLibrary"),
669 aLibName
, Reference
< XSimpleRegistry
>() );
671 test_Conversion( xMgr
);
673 catch (const Exception
& rExc
)
675 DBG_UNHANDLED_EXCEPTION("stoc", "### exception occurred: " << rExc
);
678 Reference
< XComponent
>( xMgr
, UNO_QUERY
)->dispose();
682 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */