update emoji autocorrect entries from po-files
[LibreOffice.git] / stoc / test / testconv.cxx
blob950a9129f59b54452c526fc7f581419b6f2ba1e3
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
21 #include <sal/main.h>
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>
32 #include <float.h>
33 #include <stdio.h>
36 using namespace cppu;
37 using namespace osl;
38 using namespace css::uno;
39 using namespace css::lang;
40 using namespace css::script;
41 using namespace css::reflection;
42 using namespace css::registry;
45 const double MIN_DOUBLE = -DBL_MAX;
46 const double MAX_DOUBLE = DBL_MAX;
47 const double MIN_FLOAT = -FLT_MAX;
48 const double MAX_FLOAT = FLT_MAX;
51 static void printValue( const Any & rVal )
53 // print value
54 OString aStr( OUStringToOString( rVal.getValueType().getTypeName(), RTL_TEXTENCODING_ISO_8859_1 ) );
55 printf( "(%s)", aStr.getStr() );
57 switch (rVal.getValueTypeClass())
59 case TypeClass_VOID:
60 printf( "void" );
61 break;
62 case TypeClass_ANY:
63 if (rVal.hasValue())
64 printValue( *(Any *)rVal.getValue() );
65 break;
66 case TypeClass_BOOLEAN:
67 printf( "%s", (*(sal_Bool *)rVal.getValue() ? "true" : "false") );
68 break;
69 case TypeClass_CHAR:
71 char ar[2];
72 ar[0] = (char)*(sal_Unicode *)rVal.getValue();
73 ar[1] = 0;
74 printf( "%s", ar );
75 break;
77 case TypeClass_BYTE:
78 printf( "%x", (int)*(sal_Int8 *)rVal.getValue() );
79 break;
80 case TypeClass_SHORT:
81 printf( "%x", *(sal_Int16 *)rVal.getValue() );
82 break;
83 case TypeClass_UNSIGNED_SHORT:
84 printf( "%x", *(sal_uInt16 *)rVal.getValue() );
85 break;
86 case TypeClass_LONG:
87 printf( "%lx", static_cast<long>(*(sal_Int32 *)rVal.getValue()) );
88 break;
89 case TypeClass_UNSIGNED_LONG:
90 printf( "%lx", static_cast<unsigned long>(*(sal_uInt32 *)rVal.getValue()) );
91 break;
92 case TypeClass_HYPER:
93 printf( "%lx", (long)*(sal_Int64 *)rVal.getValue() );
94 break;
95 case TypeClass_UNSIGNED_HYPER:
96 printf( "%lx", (unsigned long)*(sal_uInt64 *)rVal.getValue() );
97 break;
98 case TypeClass_FLOAT:
99 printf( "%f", *(float *)rVal.getValue() );
100 break;
101 case TypeClass_DOUBLE:
102 printf( "%g", *(double *)rVal.getValue() );
103 break;
104 case TypeClass_STRING:
106 OString aStr2( OUStringToOString( *(OUString *)rVal.getValue(), RTL_TEXTENCODING_ISO_8859_1 ) );
107 printf( aStr2.getStr() );
108 break;
110 case TypeClass_ENUM:
112 typelib_EnumTypeDescription * pEnumTD = 0;
113 TYPELIB_DANGER_GET( (typelib_TypeDescription **)&pEnumTD, rVal.getValueTypeRef() );
115 for ( sal_Int32 nPos = pEnumTD->nEnumValues; nPos--; )
117 if (pEnumTD->pEnumValues[nPos] == *(int *)rVal.getValue())
119 printf( OUStringToOString(pEnumTD->ppEnumNames[nPos]->buffer, RTL_TEXTENCODING_ASCII_US).getStr() );
120 TYPELIB_DANGER_RELEASE( (typelib_TypeDescription *)pEnumTD );
121 return;
124 TYPELIB_DANGER_RELEASE( (typelib_TypeDescription *)pEnumTD );
125 printf( ">ENUM not found!<" );
126 break;
128 case TypeClass_SEQUENCE:
130 uno_Sequence * pSeq = *(uno_Sequence **)rVal.getValue();
131 typelib_TypeDescription * pSeqTD = 0;
132 TYPELIB_DANGER_GET( &pSeqTD, rVal.getValueTypeRef() );
133 typelib_TypeDescription * pElemTD = 0;
134 TYPELIB_DANGER_GET( &pElemTD, ((typelib_IndirectTypeDescription *)pSeqTD)->pType );
136 sal_Int32 nLen = pSeq->nElements;
137 if (nLen)
139 printf( "{ " );
140 for ( sal_Int32 nPos = 0; nPos < nLen; ++nPos )
142 printValue( Any( ((char *)pSeq->elements) + (nPos * pElemTD->nSize), pElemTD ) );
143 if (nPos < (nLen-1))
144 printf( ", " );
146 printf( " }" );
149 TYPELIB_DANGER_RELEASE( pElemTD );
150 TYPELIB_DANGER_RELEASE( pSeqTD );
151 break;
154 default:
155 printf( ">not printable<" );
156 break;
160 static Reference< XTypeConverter > s_xConverter;
163 static sal_Bool convertTo( const Type & rDestType, const Any & rVal, sal_Bool bExpectSuccess )
165 sal_Bool bCanConvert = sal_False;
166 Any aRet;
168 OString aExcMsg;
172 aRet = s_xConverter->convertTo( rVal, rDestType );
173 bCanConvert = sal_True;
175 catch (const Exception & rExc)
177 aExcMsg = OUStringToOString( rExc.Message, RTL_TEXTENCODING_ASCII_US );
180 if (bExpectSuccess && !bCanConvert)
182 printf( "# conversion of " );
183 printValue( rVal );
184 printf( " to " );
185 printf( OUStringToOString(rDestType.getTypeName(), RTL_TEXTENCODING_ASCII_US).getStr() );
186 printf( " failed, but success was expected! [" );
187 printf( aExcMsg.getStr() );
188 printf( "]\n" );
189 aRet = s_xConverter->convertTo( rVal, rDestType );
190 #if OSL_DEBUG_LEVEL > 1
191 // for debugging, to trace again
194 aRet = s_xConverter->convertTo( rVal, rDestType );
196 catch (Exception &)
199 #endif
200 return sal_False;
202 if (!bExpectSuccess && bCanConvert)
204 printf( "# conversion of " );
205 printValue( rVal );
206 printf( " to " );
207 printValue( aRet );
208 printf( " was successful, but was not expected to be!\n" );
209 #if OSL_DEBUG_LEVEL > 1
210 // for debugging, to trace again
211 aRet = s_xConverter->convertTo( rVal, rDestType );
212 #endif
213 return sal_False;
216 #ifdef __RECONVERSION_OUTPUT__
217 //= re-conversion output =
218 if (bCanConvert)
220 // re convert to original type
221 sal_Bool bReConvert = sal_False;
222 Any aRet2;
226 aRet2 = s_xConverter->convertTo( aRet, rVal.getValueType() );
227 bReConvert = sal_True;
229 catch (const Exception & rExc)
231 aExcMsg = OUStringToOString( rExc.Message, RTL_TEXTENCODING_ISO_8859_1 );
234 if (bReConvert)
236 if (rVal != aRet2)
238 printf( "# re-conversion of " );
239 printValue( rVal );
240 printf( " to " );
241 printValue( aRet );
242 printf( " to " );
243 printValue( aRet2 );
244 printf( ": first and last do not match!\n" );
247 else
249 printf( "# re-conversion of " );
250 printValue( aRet );
251 printf( " to " );
252 printf( rVal.getValueType().getTypeName().getStr() );
253 printf( " failed! [" );
254 printf( aExcMsg.getStr() );
255 printf( "]\n" );
258 #endif
260 return sal_True;
265 typedef struct _ConvBlock
267 Any _value;
268 sal_Bool _toString, _toDouble, _toFloat;
269 sal_Bool _toUINT32, _toINT32, _toUINT16, _toINT16, _toBYTE, _toBOOL, _toChar;
270 sal_Bool _toTypeClass, _toSeqINT16, _toSeqAny;
272 _ConvBlock()
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_ )
280 : _value( rValue_ )
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_ )
287 } ConvBlock;
291 static sal_Int32 initBlocks( ConvBlock * pTestBlocks )
293 Any aVal;
295 sal_uInt32 nElems = 0;
297 // ==BYTE==
298 aVal <<= OUString("0xff");
299 pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0 );
300 aVal <<= OUString("255");
301 pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0 );
302 aVal <<= (sal_Int8)0xffu;
303 pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 0, 0, 0 );
304 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
305 aVal <<= OUString("0x80");
306 pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0 );
307 aVal <<= OUString("128");
308 pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0 );
309 aVal <<= (sal_Int8)( 0x80u );
310 pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 0, 0, 0 );
311 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
312 aVal <<= OUString("0x7f");
313 pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 );
314 aVal <<= OUString("127");
315 pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 );
316 aVal <<= (sal_Int8)( 0x7f );
317 pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0 );
318 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
319 aVal <<= OUString("5");
320 pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 0, 0 );
321 aVal <<= OUString("+5");
322 pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 );
323 aVal <<= (sal_Int8)( 5 );
324 pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0 );
325 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
326 aVal <<= OUString("-5");
327 pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 0, 1, 0, 1, 1, 0, 0, 0, 0, 0 );
328 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
329 aVal <<= (sal_Int8)( -5 );
330 pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 0, 0, 0 );
331 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
332 aVal <<= OUString("256");
333 pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0 );
334 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
335 // ==UINT16==
336 aVal <<= OUString("65535");
337 pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0 );
338 aVal <<= OUString("0xffff");
339 pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0 );
340 aVal <<= (sal_uInt16)( 0xffff );
341 pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 0, 0 );
342 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
343 aVal <<= OUString("32768");
344 pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0 );
345 aVal <<= (sal_uInt16)( 0x8000 );
346 pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 0, 0 );
347 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
348 aVal <<= OUString("32767");
349 pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0 );
350 aVal <<= OUString("0x7fff");
351 pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0 );
352 aVal <<= (sal_uInt16)( 0x7fff );
353 pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 0, 0 );
354 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
355 aVal <<= OUString("256");
356 pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0 );
357 aVal <<= OUString("0x100");
358 pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0 );
359 aVal <<= (sal_uInt16)( 0x100 );
360 pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 0, 0 );
361 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
362 aVal <<= (sal_uInt16)( 5 );
363 pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0 );
364 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
365 aVal <<= (sal_uInt16)( -5 ); // is 0xfffb
366 pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 0, 0 );
367 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
368 // ==INT16==
369 aVal <<= (sal_Int16)( -1 );
370 pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 0, 0, 0 );
371 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
372 aVal <<= (sal_Int16)( -0x8000 );
373 pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0 );
374 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
375 aVal <<= (sal_Int16)( 0x7fff );
376 pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 0, 0 );
377 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
378 aVal <<= (sal_Int16)( 0x100 );
379 pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 0, 0 );
380 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
381 aVal <<= (sal_Int16)( 5 );
382 pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0 );
383 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
384 aVal <<= (sal_Int16)( -5 );
385 pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 0, 0, 0 );
386 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
387 // ==UINT32==
388 aVal <<= OUString("+4294967295");
389 pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 );
390 aVal <<= OUString("4294967295");
391 pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 );
392 aVal <<= OUString("0xffffffff");
393 pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 );
394 aVal <<= (sal_uInt32)( 0xffffffff );
395 pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0 );
396 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
397 aVal <<= OUString("-2147483648");
398 pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 );
399 aVal <<= OUString("-0x80000000");
400 pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 );
401 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
402 aVal <<= (sal_uInt32)( 0x80000000 );
403 pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0 );
404 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
405 aVal <<= OUString("2147483647");
406 pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0 );
407 aVal <<= OUString("0x7fffffff");
408 pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0 );
409 aVal <<= (sal_uInt32)( 0x7fffffff );
410 pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0 );
411 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
412 aVal <<= OUString("65536");
413 pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0 );
414 aVal <<= OUString("0x10000");
415 pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0 );
416 aVal <<= (sal_uInt32)( 0x10000 );
417 pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0 );
418 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
419 aVal <<= (sal_uInt32)( 0x8000 );
420 pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 0, 0 );
421 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
422 aVal <<= (sal_uInt32)( 5 );
423 pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0 );
424 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
425 aVal <<= OUString("0xfffffffb");
426 pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 );
427 aVal <<= (sal_uInt32)( -5 ); // is 0xfffffffb
428 pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0 );
429 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
430 // ==INT32==
431 aVal <<= (sal_Int32)( 0xffffffff ); // is -1
432 pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 0, 0, 0 );
433 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
434 aVal <<= (sal_Int32)( 0x80000000 );
435 pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0 );
436 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
437 aVal <<= (sal_Int32)( 0x7fffffff );
438 pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0 );
439 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
440 aVal <<= (sal_Int32)( 0x10000 );
441 pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0 );
442 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
443 aVal <<= (sal_Int32)( -0x8001 );
444 pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0 );
445 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
446 aVal <<= (sal_Int32)( 5 );
447 pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0 );
448 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
449 aVal <<= (sal_Int32)( -5 );
450 pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 0, 0, 0 );
451 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
452 // ==FLOAT==
453 aVal <<= OUString("-3.4e+38");
454 pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 );
455 aVal <<= (float)( MIN_FLOAT );
456 pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 );
457 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
458 aVal <<= OUString("+3.4e+38");
459 pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 );
460 aVal <<= (float)( MAX_FLOAT );
461 pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 );
462 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
463 aVal <<= OUString("9e-20");
464 pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 );
465 aVal <<= (float)( 9e-20 );
466 pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0 );
467 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
468 aVal <<= OUString("+.7071067811865");
469 pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 );
470 aVal <<= (float)( .7071067811865 );
471 pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0 );
472 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
473 aVal <<= OUString("3.14159265359");
474 pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 );
475 aVal <<= (float)( 3.14159265359 );
476 pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0 );
477 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
478 aVal <<= (float)( 5 );
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 // ==DOUBLE==
482 aVal <<= OUString("-1.7976931348623155e+308");
483 pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 );
484 aVal <<= (double)( MIN_DOUBLE );
485 pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 );
486 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
487 aVal <<= OUString("1.7976931348623155e+308");
488 pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 );
489 aVal <<= (double)( MAX_DOUBLE );
490 pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 );
491 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
492 aVal <<= (double)( MIN_FLOAT );
493 pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 );
494 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
495 aVal <<= (double)( MAX_FLOAT );
496 pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 );
497 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
498 aVal <<= (double)( -((double)0x80000000) );
499 pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0 );
500 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
501 aVal <<= (double)( -((double)0x80000001) );
502 pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 );
503 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
504 aVal <<= (double)( 0x7fffffff );
505 pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0 );
506 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
507 aVal <<= (double)( 0x80000000 );
508 pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0 );
509 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
510 aVal <<= (double)( 0xffffffff );
511 pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0 );
512 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
513 aVal <<= OUString("0x100000000");
514 pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 );
515 aVal <<= (double)( SAL_CONST_INT64(0x100000000) );
516 pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 );
517 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
518 aVal <<= (double)( 5 );
519 pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0 );
520 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
521 // ==CHAR==
522 sal_Unicode c = 'A';
523 aVal.setValue( &c, cppu::UnoType<cppu::UnoCharType>::get() );
524 pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0 );
525 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
526 aVal <<= OUString("A");
527 pTestBlocks[nElems++] = ConvBlock( aVal, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0 );
528 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
529 // ==BOOL==
530 aVal <<= OUString("0");
531 pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0 );
532 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
533 aVal <<= OUString("1");
534 pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0 );
535 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
536 aVal <<= OUString("False");
537 pTestBlocks[nElems++] = ConvBlock( aVal, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 );
538 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
539 aVal <<= OUString("true");
540 pTestBlocks[nElems++] = ConvBlock( aVal, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 );
541 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
543 sal_Bool bTmp = sal_True;
544 aVal.setValue( &bTmp, cppu::UnoType<bool>::get() );
545 pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0 );
546 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
547 // ==ZERO STRINGS==
548 aVal <<= OUString();
549 pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 );
550 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
551 aVal <<= OUString("-");
552 pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 0, 0 );
553 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
554 aVal <<= OUString("-0");
555 pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 );
556 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
557 // ==TYPECLASS ENUM==
558 aVal <<= OUString("eNuM");
559 pTestBlocks[nElems++] = ConvBlock( aVal, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0 );
560 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
561 aVal <<= OUString("DOUBLE");
562 pTestBlocks[nElems++] = ConvBlock( aVal, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0 );
563 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
564 int e = 1;
565 aVal.setValue( &e, cppu::UnoType<TypeClass>::get());
566 pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 0 );
567 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
568 aVal.setValue( &e, cppu::UnoType<FieldAccessMode>::get());
569 pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 );
570 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
571 // ==SEQ of INT==
572 Sequence< sal_Int32 > aINT32Seq( 3 ), aINT32Seq2( 3 );
573 sal_Int32 * pINT32Seq = aINT32Seq.getArray();
574 pINT32Seq[0] = -32768;
575 pINT32Seq[1] = 0;
576 pINT32Seq[2] = 32767;
577 aVal <<= aINT32Seq;
578 pTestBlocks[nElems++] = ConvBlock( aVal, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1 );
579 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
580 pINT32Seq = aINT32Seq2.getArray();
581 pINT32Seq[0] = -32768;
582 pINT32Seq[1] = -32769;
583 pINT32Seq[2] = 32767;
584 aVal <<= aINT32Seq2;
585 pTestBlocks[nElems++] = ConvBlock( aVal, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 );
586 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
587 // ==SEQ of ANY==
588 Sequence< Any > aAnySeq( 2 ), aAnySeq2( 2 );
589 Any * pAnySeq = aAnySeq.getArray();
590 pAnySeq[0] = makeAny( aINT32Seq );
591 pAnySeq[1] = makeAny( OUString("lala") );
592 aVal <<= aAnySeq;
593 pTestBlocks[nElems++] = ConvBlock( aVal, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 );
594 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
595 pAnySeq = aAnySeq2.getArray();
596 pAnySeq[0] <<= (sal_Int32)4711;
597 pAnySeq[1] <<= OUString("0815");
598 aVal <<= aAnySeq2;
599 pTestBlocks[nElems++] = ConvBlock( aVal, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1 );
600 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
601 return nElems;
605 static void test_Conversion( const Reference< XMultiServiceFactory > & xMgr )
607 printf( "test_Conversion(): start...\n" );
609 Reference< XTypeConverter > xConverter( xMgr->createInstance(
610 OUString("com.sun.star.script.Converter") ), UNO_QUERY );
612 ConvBlock * pTestBlocks = new ConvBlock[256];
613 sal_Int32 nPos = initBlocks( pTestBlocks );
615 s_xConverter = xConverter;
616 while (nPos--)
618 const ConvBlock& rBlock = pTestBlocks[nPos];
619 const Any & rVal = rBlock._value;
621 convertTo( cppu::UnoType<OUString>::get(), rVal, rBlock._toString );
622 convertTo( cppu::UnoType<float>::get(), rVal, rBlock._toFloat );
623 convertTo( cppu::UnoType<double>::get(), rVal, rBlock._toDouble );
624 convertTo( cppu::UnoType<sal_uInt32>::get(), rVal, rBlock._toUINT32 );
625 convertTo( cppu::UnoType<sal_Int32>::get(), rVal, rBlock._toINT32 );
626 convertTo( cppu::UnoType<cppu::UnoUnsignedShortType>::get(), rVal, rBlock._toUINT16 );
627 convertTo( cppu::UnoType<sal_Int16>::get(), rVal, rBlock._toINT16 );
628 convertTo( cppu::UnoType<sal_Int8>::get(), rVal, rBlock._toBYTE );
629 convertTo( cppu::UnoType<bool>::get(), rVal, rBlock._toBOOL );
630 convertTo( cppu::UnoType<cppu::UnoCharType>::get(), rVal, rBlock._toChar );
631 convertTo( cppu::UnoType<TypeClass>::get(), rVal, rBlock._toTypeClass );
632 convertTo( cppu::UnoType<Sequence< sal_Int16 >>::get(), rVal, rBlock._toSeqINT16 );
633 convertTo( cppu::UnoType<Sequence< Any >>::get(), rVal, rBlock._toSeqAny );
635 convertTo( cppu::UnoType<void>::get(), rVal, sal_True ); // anything converts to void
637 s_xConverter.clear();
639 delete [] pTestBlocks;
641 Any aRet;
642 aRet = xConverter->convertTo( Any( &xMgr, cppu::UnoType<XMultiServiceFactory>::get()),
643 cppu::UnoType<XServiceInfo>::get());
644 aRet = xConverter->convertTo( aRet, cppu::UnoType<XMultiServiceFactory>::get());
645 aRet = xConverter->convertTo( aRet, cppu::UnoType<XServiceInfo>::get());
646 aRet <<= SAL_CONST_INT64(0x7fffffffffffffff);
647 aRet = xConverter->convertTo( aRet, cppu::UnoType<sal_uInt64>::get());
648 OSL_ASSERT( *(const sal_uInt64 *)aRet.getValue() == SAL_CONST_UINT64(0x7fffffffffffffff) );
649 aRet <<= SAL_CONST_UINT64(0xffffffffffffffff);
650 aRet = xConverter->convertTo( aRet, cppu::UnoType<sal_uInt64>::get());
651 OSL_ASSERT( *(const sal_uInt64 *)aRet.getValue() == SAL_CONST_UINT64(0xffffffffffffffff) );
652 aRet <<= SAL_CONST_INT64(-1);
653 aRet = xConverter->convertTo( aRet, cppu::UnoType<sal_Int8>::get());
654 OSL_ASSERT( *(const sal_Int8 *)aRet.getValue() == (-1) );
655 printf( "test_Conversion(): end.\n" );
658 SAL_IMPLEMENT_MAIN()
660 Reference< XMultiServiceFactory > xMgr( createRegistryServiceFactory( OUString("stoctest.rdb") ) );
664 Reference< XImplementationRegistration > xImplReg(
665 xMgr->createInstance("com.sun.star.registry.ImplementationRegistration"), UNO_QUERY );
666 OSL_ENSURE( xImplReg.is(), "### no impl reg!" );
668 OUString aLibName("stocservices.uno" SAL_DLLEXTENSION );
669 xImplReg->registerImplementation(
670 OUString("com.sun.star.loader.SharedLibrary"),
671 aLibName, Reference< XSimpleRegistry >() );
673 test_Conversion( xMgr );
675 catch (const Exception & rExc)
677 OSL_FAIL( "### exception occurred!" );
678 OString aMsg( OUStringToOString( rExc.Message, RTL_TEXTENCODING_ASCII_US ) );
679 OSL_TRACE( "### exception occurred: " );
680 OSL_TRACE( "%s", aMsg.getStr() );
681 OSL_TRACE( "\n" );
684 Reference< XComponent >( xMgr, UNO_QUERY )->dispose();
685 return 0;
688 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */