xref: /aoo42x/main/stoc/test/testconv.cxx (revision 647a425c)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_stoc.hxx"
26 
27 #include <sal/main.h>
28 #include <osl/diagnose.h>
29 #include <rtl/ustrbuf.hxx>
30 #include <cppuhelper/servicefactory.hxx>
31 
32 #include <com/sun/star/lang/XComponent.hpp>
33 #include <com/sun/star/lang/XServiceInfo.hpp>
34 #include <com/sun/star/script/XTypeConverter.hpp>
35 #include <com/sun/star/reflection/FieldAccessMode.hpp>
36 #include <com/sun/star/registry/XImplementationRegistration.hpp>
37 
38 #include <float.h>
39 #include <stdio.h>
40 
41 
42 using namespace rtl;
43 using namespace cppu;
44 using namespace osl;
45 using namespace com::sun::star::uno;
46 using namespace com::sun::star::lang;
47 using namespace com::sun::star::script;
48 using namespace com::sun::star::reflection;
49 using namespace com::sun::star::registry;
50 
51 const double MIN_DOUBLE		= -DBL_MAX;
52 const double MAX_DOUBLE		= DBL_MAX;
53 const double MIN_FLOAT		= -FLT_MAX;
54 const double MAX_FLOAT		= FLT_MAX;
55 
56 //==================================================================================================
57 static void printValue( const Any & rVal )
58 {
59 	// print value
60 	OString aStr( OUStringToOString( rVal.getValueType().getTypeName(), RTL_TEXTENCODING_ISO_8859_1 ) );
61 	printf( "(%s)", aStr.getStr() );
62 
63 	switch (rVal.getValueTypeClass())
64 	{
65 	case TypeClass_VOID:
66 		printf( "void" );
67 		break;
68 	case TypeClass_ANY:
69 		if (rVal.hasValue())
70 			printValue( *(Any *)rVal.getValue() );
71 		break;
72 	case TypeClass_BOOLEAN:
73 		printf( "%s", (*(sal_Bool *)rVal.getValue() ? "true" : "false") );
74 		break;
75 	case TypeClass_CHAR:
76 	{
77 		char ar[2];
78 		ar[0] = (char)*(sal_Unicode *)rVal.getValue();
79 		ar[1] = 0;
80 		printf( ar );
81 		break;
82 	}
83 	case TypeClass_BYTE:
84 		printf( "%x", (int)*(sal_Int8 *)rVal.getValue() );
85 		break;
86 	case TypeClass_SHORT:
87 		printf( "%x", *(sal_Int16 *)rVal.getValue() );
88 		break;
89 	case TypeClass_UNSIGNED_SHORT:
90 		printf( "%x", *(sal_uInt16 *)rVal.getValue() );
91 		break;
92 	case TypeClass_LONG:
93 		printf( "%lx", static_cast<long>(*(sal_Int32 *)rVal.getValue()) );
94 		break;
95 	case TypeClass_UNSIGNED_LONG:
96 		printf( "%lx", static_cast<unsigned long>(*(sal_uInt32 *)rVal.getValue()) );
97 		break;
98 	case TypeClass_HYPER:
99 		printf( "%lx", (long)*(sal_Int64 *)rVal.getValue() );
100 		break;
101 	case TypeClass_UNSIGNED_HYPER:
102 		printf( "%lx", (unsigned long)*(sal_uInt64 *)rVal.getValue() );
103 		break;
104 	case TypeClass_FLOAT:
105 		printf( "%f", *(float *)rVal.getValue() );
106 		break;
107 	case TypeClass_DOUBLE:
108 		printf( "%g", *(double *)rVal.getValue() );
109 		break;
110 	case TypeClass_STRING:
111 	{
112 		OString aStr2( OUStringToOString( *(OUString *)rVal.getValue(), RTL_TEXTENCODING_ISO_8859_1 ) );
113 		printf( aStr2.getStr() );
114 		break;
115 	}
116 	case TypeClass_ENUM:
117 	{
118 		typelib_EnumTypeDescription * pEnumTD = 0;
119 		TYPELIB_DANGER_GET( (typelib_TypeDescription **)&pEnumTD, rVal.getValueTypeRef() );
120 
121 		for ( sal_Int32 nPos = pEnumTD->nEnumValues; nPos--; )
122 		{
123 			if (pEnumTD->pEnumValues[nPos] == *(int *)rVal.getValue())
124 			{
125 				printf( OUStringToOString(pEnumTD->ppEnumNames[nPos]->buffer, RTL_TEXTENCODING_ASCII_US).getStr() );
126 				TYPELIB_DANGER_RELEASE( (typelib_TypeDescription *)pEnumTD );
127 				return;
128 			}
129 		}
130 		TYPELIB_DANGER_RELEASE( (typelib_TypeDescription *)pEnumTD );
131 		printf( ">ENUM not found!<" );
132 		break;
133 	}
134 	case TypeClass_SEQUENCE:
135 	{
136 		uno_Sequence * pSeq = *(uno_Sequence **)rVal.getValue();
137 		typelib_TypeDescription * pSeqTD = 0;
138 		TYPELIB_DANGER_GET( &pSeqTD, rVal.getValueTypeRef() );
139 		typelib_TypeDescription * pElemTD = 0;
140 		TYPELIB_DANGER_GET( &pElemTD, ((typelib_IndirectTypeDescription *)pSeqTD)->pType );
141 
142 		sal_Int32 nLen = pSeq->nElements;
143 		if (nLen)
144 		{
145 			printf( "{ " );
146 			for ( sal_Int32 nPos = 0; nPos < nLen; ++nPos )
147 			{
148 				printValue( Any( ((char *)pSeq->elements) + (nPos * pElemTD->nSize), pElemTD ) );
149 				if (nPos < (nLen-1))
150 					printf( ", " );
151 			}
152 			printf( " }" );
153 		}
154 
155 		TYPELIB_DANGER_RELEASE( pElemTD );
156 		TYPELIB_DANGER_RELEASE( pSeqTD );
157 		break;
158 	}
159 
160 	default:
161 		printf( ">not printable<" );
162 		break;
163 	}
164 }
165 
166 static Reference< XTypeConverter > s_xConverter;
167 
168 //==================================================================================================
169 static sal_Bool convertTo( const Type & rDestType, const Any & rVal, sal_Bool bExpectSuccess )
170 {
171 	sal_Bool bCanConvert = sal_False;
172 	Any aRet;
173 
174 	OString aExcMsg;
175 
176 	try
177 	{
178 		aRet = s_xConverter->convertTo( rVal, rDestType );
179 		bCanConvert = sal_True;
180 	}
181 	catch (Exception & rExc)
182 	{
183 		aExcMsg = OUStringToOString( rExc.Message, RTL_TEXTENCODING_ASCII_US );
184 	}
185 
186 	if (bExpectSuccess && !bCanConvert)
187 	{
188 		printf( "# conversion of " );
189 		printValue( rVal );
190 		printf( " to " );
191 		printf( OUStringToOString(rDestType.getTypeName(), RTL_TEXTENCODING_ASCII_US).getStr() );
192 		printf( " failed, but success was expected! [" );
193 		printf( aExcMsg.getStr() );
194 		printf( "]\n" );
195 		aRet = s_xConverter->convertTo( rVal, rDestType );
196 #if OSL_DEBUG_LEVEL > 1
197 		// for debugging, to trace again
198 		try
199 		{
200 			aRet = s_xConverter->convertTo( rVal, rDestType );
201 		}
202 		catch (Exception &)
203 		{
204 		}
205 #endif
206 		return sal_False;
207 	}
208 	if (!bExpectSuccess && bCanConvert)
209 	{
210 		printf( "# conversion of " );
211 		printValue( rVal );
212 		printf( " to " );
213 		printValue( aRet );
214 		printf( " was successful, but was not expected to be!\n" );
215 #if OSL_DEBUG_LEVEL > 1
216 		// for debugging, to trace again
217 		aRet = s_xConverter->convertTo( rVal, rDestType );
218 #endif
219 		return sal_False;
220 	}
221 
222 #ifdef __RECONVERSION_OUTPUT__
223 //= re-conversion output =
224 	if (bCanConvert)
225 	{
226 		// re convert to original type
227 		sal_Bool bReConvert = sal_False;
228 		Any aRet2;
229 
230 		try
231 		{
232 			aRet2 = s_xConverter->convertTo( aRet, rVal.getValueType() );
233 			bReConvert = sal_True;
234 		}
235 		catch (Exception & rExc)
236 		{
237 			aExcMsg = OUStringToOString( rExc.Message, RTL_TEXTENCODING_ISO_8859_1 );
238 		}
239 
240 		if (bReConvert)
241 		{
242 			if (rVal != aRet2)
243 			{
244 				printf( "# re-conversion of " );
245 				printValue( rVal );
246 				printf( " to " );
247 				printValue( aRet );
248 				printf( " to " );
249 				printValue( aRet2 );
250 				printf( ": first and last do not match!\n" );
251 			}
252 		}
253 		else
254 		{
255 			printf( "# re-conversion of " );
256 			printValue( aRet );
257 			printf( " to " );
258 			printf( rVal.getValueType().getTypeName().getStr() );
259 			printf( " failed! [" );
260 			printf( aExcMsg.getStr() );
261 			printf( "]\n" );
262 		}
263 	}
264 #endif
265 
266 	return sal_True;
267 }
268 
269 
270 //==================================================================================================
271 typedef struct _ConvBlock
272 {
273 	Any			_value;
274 	sal_Bool	_toString, _toDouble, _toFloat;
275 	sal_Bool	_toUINT32, _toINT32, _toUINT16, _toINT16, _toBYTE, _toBOOL, _toChar;
276 	sal_Bool	_toTypeClass, _toSeqINT16, _toSeqAny;
277 
278 	_ConvBlock()
279 	{
280 	}
281 	_ConvBlock( const Any & rValue_,
282 				sal_Bool toString_, sal_Bool toDouble_, sal_Bool toFloat_,
283 				sal_Bool toUINT32_, sal_Bool toINT32_, sal_Bool toUINT16_, sal_Bool toINT16_,
284 				sal_Bool toBYTE_, sal_Bool toBOOL_, sal_Bool toChar_,
285 				sal_Bool toTypeClass_, sal_Bool toSeqINT16_, sal_Bool toSeqAny_ )
286 		: _value( rValue_ )
287 		, _toString( toString_ ), _toDouble( toDouble_ ), _toFloat( toFloat_ )
288 		, _toUINT32( toUINT32_ ), _toINT32( toINT32_ ), _toUINT16( toUINT16_ ), _toINT16( toINT16_ )
289 		, _toBYTE( toBYTE_ ), _toBOOL( toBOOL_ ), _toChar( toChar_ )
290 		, _toTypeClass( toTypeClass_ ), _toSeqINT16( toSeqINT16_ ), _toSeqAny( toSeqAny_ )
291 	{
292 	}
293 } ConvBlock;
294 
295 
296 //==================================================================================================
297 static sal_Int32 initBlocks( ConvBlock * pTestBlocks )
298 {
299 	Any aVal;
300 
301 	sal_uInt32 nElems = 0;
302 
303 	// ==BYTE==
304 	aVal <<= OUString::createFromAscii( "0xff" );
305 	pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0 );
306 	aVal <<= OUString::createFromAscii( "255" );
307 	pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0 );
308 	aVal <<= (sal_Int8)0xffu;
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::createFromAscii( "0x80" );
312 	pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0 );
313 	aVal <<= OUString::createFromAscii( "128" );
314 	pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0 );
315 	aVal <<= (sal_Int8)( 0x80u );
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( "0x7f" );
319 	pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 );
320 	aVal <<= OUString::createFromAscii( "127" );
321 	pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 );
322 	aVal <<= (sal_Int8)( 0x7f );
323 	pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0 );
324 										 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
325 	aVal <<= OUString::createFromAscii( "5" );
326 	pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 0, 0 );
327 	aVal <<= OUString::createFromAscii( "+5" );
328 	pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 );
329 	aVal <<= (sal_Int8)( 5 );
330 	pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 0, 1, 0, 1, 1, 0, 0, 0, 0, 0 );
334 										 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
335 	aVal <<= (sal_Int8)( -5 );
336 	pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 0, 0, 0 );
337 										 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
338 	aVal <<= OUString::createFromAscii( "256" );
339 	pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0 );
340 										 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
341 	// ==UINT16==
342 	aVal <<= OUString::createFromAscii( "65535" );
343 	pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0 );
344 	aVal <<= OUString::createFromAscii( "0xffff" );
345 	pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0 );
346 	aVal <<= (sal_uInt16)( 0xffff );
347 	pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 0, 0 );
348 										 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
349 	aVal <<= OUString::createFromAscii( "32768" );
350 	pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0 );
351 	aVal <<= (sal_uInt16)( 0x8000 );
352 	pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 0, 0 );
353 										 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
354 	aVal <<= OUString::createFromAscii( "32767" );
355 	pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0 );
356 	aVal <<= OUString::createFromAscii( "0x7fff" );
357 	pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0 );
358 	aVal <<= (sal_uInt16)( 0x7fff );
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 <<= OUString::createFromAscii( "256" );
362 	pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0 );
363 	aVal <<= OUString::createFromAscii( "0x100" );
364 	pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0 );
365 	aVal <<= (sal_uInt16)( 0x100 );
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 <<= (sal_uInt16)( 5 );
369 	pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0 );
370 										 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
371 	aVal <<= (sal_uInt16)( -5 ); // is 0xfffb
372 	pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 0, 0 );
373 										 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
374 	// ==INT16==
375 	aVal <<= (sal_Int16)( -1 );
376 	pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 0, 0, 0 );
377 										 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
378 	aVal <<= (sal_Int16)( -0x8000 );
379 	pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0 );
380 										 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
381 	aVal <<= (sal_Int16)( 0x7fff );
382 	pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 0, 0 );
383 										 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
384 	aVal <<= (sal_Int16)( 0x100 );
385 	pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 0, 0 );
386 										 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
387 	aVal <<= (sal_Int16)( 5 );
388 	pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0 );
389 										 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
390 	aVal <<= (sal_Int16)( -5 );
391 	pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 0, 0, 0 );
392 										 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
393 	// ==UINT32==
394 	aVal <<= OUString::createFromAscii( "+4294967295" );
395 	pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 );
396 	aVal <<= OUString::createFromAscii( "4294967295" );
397 	pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 );
398 	aVal <<= OUString::createFromAscii( "0xffffffff" );
399 	pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 );
400 	aVal <<= (sal_uInt32)( 0xffffffff );
401 	pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0 );
402 										 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
403 	aVal <<= OUString::createFromAscii( "-2147483648" );
404 	pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 );
405 	aVal <<= OUString::createFromAscii( "-0x80000000" );
406 	pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 );
407 										 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
408 	aVal <<= (sal_uInt32)( 0x80000000 );
409 	pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 1, 0, 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::createFromAscii( "2147483647" );
412 	pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0 );
413 	aVal <<= OUString::createFromAscii( "0x7fffffff" );
414 	pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0 );
415 	aVal <<= (sal_uInt32)( 0x7fffffff );
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 <<= OUString::createFromAscii( "65536" );
419 	pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0 );
420 	aVal <<= OUString::createFromAscii( "0x10000" );
421 	pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0 );
422 	aVal <<= (sal_uInt32)( 0x10000 );
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 <<= (sal_uInt32)( 0x8000 );
426 	pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 0, 0 );
427 										 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
428 	aVal <<= (sal_uInt32)( 5 );
429 	pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0 );
430 										 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
431 	aVal <<= OUString::createFromAscii( "0xfffffffb" );
432 	pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 );
433 	aVal <<= (sal_uInt32)( -5 ); // is 0xfffffffb
434 	pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0 );
435 										 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
436 	// ==INT32==
437 	aVal <<= (sal_Int32)( 0xffffffff ); // is -1
438 	pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 0, 0, 0 );
439 										 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
440 	aVal <<= (sal_Int32)( 0x80000000 );
441 	pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 0, 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)( 0x7fffffff );
444 	pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 1, 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)( 0x10000 );
447 	pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0 );
448 										 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
449 	aVal <<= (sal_Int32)( -0x8001 );
450 	pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0 );
451 										 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
452 	aVal <<= (sal_Int32)( 5 );
453 	pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0 );
454 										 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
455 	aVal <<= (sal_Int32)( -5 );
456 	pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 0, 0, 0 );
457 										 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
458 	// ==FLOAT==
459 	aVal <<= OUString::createFromAscii( "-3.4e+38" );
460 	pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 );
461 	aVal <<= (float)( MIN_FLOAT );
462 	pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 );
463 										 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
464 	aVal <<= OUString::createFromAscii( "+3.4e+38" );
465 	pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 );
466 	aVal <<= (float)( MAX_FLOAT );
467 	pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 );
468 										 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
469 	aVal <<= OUString::createFromAscii( "9e-20" );
470 	pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 );
471 	aVal <<= (float)( 9e-20 );
472 	pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0 );
473 										 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
474 	aVal <<= OUString::createFromAscii( "+.7071067811865" );
475 	pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 );
476 	aVal <<= (float)( .7071067811865 );
477 	pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0 );
478 										 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
479 	aVal <<= OUString::createFromAscii( "3.14159265359" );
480 	pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 );
481 	aVal <<= (float)( 3.14159265359 );
482 	pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0 );
483 										 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
484 	aVal <<= (float)( 5 );
485 	pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0 );
486 										 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
487 	// ==DOUBLE==
488 	aVal <<= OUString::createFromAscii( "-1.7976931348623155e+308" );
489 	pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 );
490 	aVal <<= (double)( MIN_DOUBLE );
491 	pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 );
492 										 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
493 	aVal <<= OUString::createFromAscii( "1.7976931348623155e+308" );
494 	pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 );
495 	aVal <<= (double)( MAX_DOUBLE );
496 	pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 0, 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)( MIN_FLOAT );
499 	pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 0, 0, 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)( MAX_FLOAT );
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)( -((double)0x80000000) );
505 	pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 0, 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)( -((double)0x80000001) );
508 	pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 0, 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)( 0x7fffffff );
511 	pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0 );
512 										 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
513 	aVal <<= (double)( 0x80000000 );
514 	pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0 );
515 										 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
516 	aVal <<= (double)( 0xffffffff );
517 	pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0 );
518 										 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
519 	aVal <<= OUString::createFromAscii( "0x100000000" );
520     pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 );
521 #ifndef OS2
522 	aVal <<= (double)( SAL_CONST_INT64(0x100000000) );
523     pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 );
524 #endif
525 										 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
526 	aVal <<= (double)( 5 );
527 	pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0 );
528 										 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
529 	// ==CHAR==
530 	sal_Unicode c = 'A';
531 	aVal.setValue( &c, ::getCharCppuType() );
532 	pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0 );
533 										 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
534 	aVal <<= OUString::createFromAscii( "A" );
535 	pTestBlocks[nElems++] = ConvBlock( aVal, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0 );
536 										 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
537 	// ==BOOL==
538 	aVal <<= OUString::createFromAscii( "0" );
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( "1" );
542 	pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0 );
543 										 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
544 	aVal <<= OUString::createFromAscii( "False" );
545 	pTestBlocks[nElems++] = ConvBlock( aVal, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 );
546 										 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
547 	aVal <<= OUString::createFromAscii( "true" );
548 	pTestBlocks[nElems++] = ConvBlock( aVal, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 );
549 										 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
550 
551 	sal_Bool bTmp = sal_True;
552 	aVal.setValue( &bTmp, getBooleanCppuType() );
553 	pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0 );
554 										 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
555 	// ==ZERO STRINGS==
556 	aVal <<= OUString();
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 	aVal <<= OUString::createFromAscii( "-" );
560 	pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 0, 0 );
561 										 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
562 	aVal <<= OUString::createFromAscii( "-0" );
563 	pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 );
564 										 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
565 	// ==TYPECLASS ENUM==
566 	aVal <<= OUString::createFromAscii( "eNuM" );
567 	pTestBlocks[nElems++] = ConvBlock( aVal, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0 );
568 										 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
569 	aVal <<= OUString::createFromAscii( "DOUBLE" );
570 	pTestBlocks[nElems++] = ConvBlock( aVal, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0 );
571 										 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
572 	int e = 1;
573 	aVal.setValue( &e, ::getCppuType( (const TypeClass *)0 ) );
574 	pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 0 );
575 										 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
576 	aVal.setValue( &e, ::getCppuType( (const FieldAccessMode *)0 ) );
577 	pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 );
578 										 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
579 	// ==SEQ of INT==
580 	Sequence< sal_Int32 > aINT32Seq( 3 ), aINT32Seq2( 3 );
581 	sal_Int32 * pINT32Seq = aINT32Seq.getArray();
582 	pINT32Seq[0]	 = -32768;
583 	pINT32Seq[1]	 = 0;
584 	pINT32Seq[2]	 = 32767;
585 	aVal <<= aINT32Seq;
586 	pTestBlocks[nElems++] = ConvBlock( aVal, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1 );
587 										 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
588 	pINT32Seq = aINT32Seq2.getArray();
589 	pINT32Seq[0]	 = -32768;
590 	pINT32Seq[1]	 = -32769;
591 	pINT32Seq[2]	 = 32767;
592 	aVal <<= aINT32Seq2;
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 	// ==SEQ of ANY==
596 	Sequence< Any > aAnySeq( 2 ), aAnySeq2( 2 ), aAnySeq3( 2 );
597 	Any * pAnySeq	 = aAnySeq.getArray();
598 	pAnySeq[0]		 = makeAny( aINT32Seq );
599 	pAnySeq[1]		 = makeAny( OUString::createFromAscii("lala") );
600 	aVal <<= aAnySeq;
601 	pTestBlocks[nElems++] = ConvBlock( aVal, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 );
602 										 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
603 	pAnySeq = aAnySeq2.getArray();
604 	pAnySeq[0]		 <<= (sal_Int32)4711;
605 	pAnySeq[1]		 <<= OUString::createFromAscii("0815");
606 	aVal <<= aAnySeq2;
607 	pTestBlocks[nElems++] = ConvBlock( aVal, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1 );
608 										 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
609 	pAnySeq = aAnySeq3.getArray();
610 	pAnySeq[0]		 <<= OUString::createFromAscii("TypeClass_UNION");
611 	pAnySeq[1]		 <<= OUString::createFromAscii("TypeClass_ENUM");
612 	aVal <<= aAnySeq3;
613 	pTestBlocks[nElems++] = ConvBlock( aVal, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 );
614 										 // st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
615 	return nElems;
616 }
617 
618 //==================================================================================================
619 static void test_Conversion( const Reference< XMultiServiceFactory > & xMgr )
620 {
621 	printf( "test_Conversion(): start...\n" );
622 
623 	Reference< XTypeConverter > xConverter( xMgr->createInstance(
624 		OUString::createFromAscii( "com.sun.star.script.Converter" ) ), UNO_QUERY );
625 
626 	ConvBlock * pTestBlocks = new ConvBlock[256];
627 	sal_Int32 nPos = initBlocks( pTestBlocks );
628 
629 	s_xConverter = xConverter;
630 	while (nPos--)
631 	{
632 		const ConvBlock& rBlock = pTestBlocks[nPos];
633 		const Any & rVal		= rBlock._value;
634 
635 		convertTo( ::getCppuType( (const OUString *)0 ), rVal, rBlock._toString );
636 		convertTo( ::getCppuType( (const float *)0 ), rVal, rBlock._toFloat );
637 		convertTo( ::getCppuType( (const double *)0 ), rVal, rBlock._toDouble );
638 		convertTo( ::getCppuType( (const sal_uInt32 *)0 ), rVal, rBlock._toUINT32 );
639 		convertTo( ::getCppuType( (const sal_Int32 *)0 ), rVal, rBlock._toINT32 );
640 		convertTo( ::getCppuType( (const sal_uInt16 *)0 ), rVal, rBlock._toUINT16 );
641 		convertTo( ::getCppuType( (const sal_Int16 *)0 ), rVal, rBlock._toINT16 );
642 		convertTo( ::getCppuType( (const sal_Int8 *)0 ), rVal, rBlock._toBYTE );
643 		convertTo( ::getBooleanCppuType(), rVal, rBlock._toBOOL );
644 		convertTo( ::getCharCppuType(), rVal, rBlock._toChar );
645 		convertTo( ::getCppuType( (const TypeClass *)0 ), rVal, rBlock._toTypeClass );
646 		convertTo( ::getCppuType( (const Sequence< sal_Int16 > *)0 ), rVal, rBlock._toSeqINT16 );
647 		convertTo( ::getCppuType( (const Sequence< Any > *)0 ), rVal, rBlock._toSeqAny );
648 
649 		convertTo( ::getVoidCppuType(), rVal, sal_True ); // anything converts to void
650 	}
651 	s_xConverter.clear();
652 
653 	delete [] pTestBlocks;
654 
655 	Any aRet;
656 	aRet = xConverter->convertTo( Any( &xMgr, ::getCppuType( (const Reference< XMultiServiceFactory > *)0 ) ),
657 								  ::getCppuType( (const Reference< XServiceInfo > *)0 ) );
658 	aRet = xConverter->convertTo( aRet, ::getCppuType( (const Reference< XMultiServiceFactory > *)0 ) );
659 	aRet = xConverter->convertTo( aRet, ::getCppuType( (const Reference< XServiceInfo > *)0 ) );
660 	aRet <<= SAL_CONST_INT64(0x7fffffffffffffff);
661 	aRet = xConverter->convertTo( aRet, ::getCppuType( (const sal_uInt64 *)0 ) );
662 	OSL_ASSERT( *(const sal_uInt64 *)aRet.getValue() == SAL_CONST_UINT64(0x7fffffffffffffff) );
663 	aRet <<= SAL_CONST_UINT64(0xffffffffffffffff);
664 	aRet = xConverter->convertTo( aRet, ::getCppuType( (const sal_uInt64 *)0 ) );
665 	OSL_ASSERT( *(const sal_uInt64 *)aRet.getValue() == SAL_CONST_UINT64(0xffffffffffffffff) );
666 	aRet <<= SAL_CONST_INT64(-1);
667 	aRet = xConverter->convertTo( aRet, ::getCppuType( (const sal_Int8 *)0 ) );
668 	OSL_ASSERT( *(const sal_Int8 *)aRet.getValue() == (-1) );
669 	printf( "test_Conversion(): end.\n" );
670 }
671 
672 SAL_IMPLEMENT_MAIN()
673 {
674 	Reference< XMultiServiceFactory > xMgr( createRegistryServiceFactory( OUString::createFromAscii("stoctest.rdb") ) );
675 
676 	try
677 	{
678 		Reference< XImplementationRegistration > xImplReg(
679 			xMgr->createInstance( OUString::createFromAscii("com.sun.star.registry.ImplementationRegistration") ), UNO_QUERY );
680 		OSL_ENSURE( xImplReg.is(), "### no impl reg!" );
681 
682 		OUString aLibName(
683             RTL_CONSTASCII_USTRINGPARAM("stocservices.uno" SAL_DLLEXTENSION) );
684 		xImplReg->registerImplementation(
685 			OUString::createFromAscii("com.sun.star.loader.SharedLibrary"),
686 			aLibName, Reference< XSimpleRegistry >() );
687 
688 		test_Conversion( xMgr );
689 	}
690 	catch (Exception & rExc)
691 	{
692 		OSL_ENSURE( sal_False, "### exception occured!" );
693 		OString aMsg( OUStringToOString( rExc.Message, RTL_TEXTENCODING_ASCII_US ) );
694 		OSL_TRACE( "### exception occured: " );
695 		OSL_TRACE( aMsg.getStr() );
696 		OSL_TRACE( "\n" );
697 	}
698 
699 	Reference< XComponent >( xMgr, UNO_QUERY )->dispose();
700 	return 0;
701 }
702