Update ooo320-m1
[ooovba.git] / jurt / test / com / sun / star / uno / AnyConverter_Test.java
blob123f1d7f08288e5c8475c2c904b6bb8ddd4a3b40
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: AnyConverter_Test.java,v $
10 * $Revision: 1.7 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 package com.sun.star.uno;
33 import com.sun.star.lang.XTypeProvider;
34 import complexlib.ComplexTestCase;
36 public final class AnyConverter_Test extends ComplexTestCase {
37 public String getTestObjectName() {
38 return getClass().getName();
41 public String[] getTestMethodNames() {
42 return new String[] {
43 "test_toBoolean", "test_toChar", "test_toByte", "test_toShort",
44 "test_toInt", "test_toLong", "test_toFloat", "test_toDouble",
45 "test_toObject", "test_toString", "test_toType", "test_toArray",
46 "test_isBoolean", "test_isChar", "test_isByte", "test_isShort",
47 "test_isInt", "test_isLong", "test_isFloat", "test_isDouble",
48 "test_isObject", "test_isString", "test_isType", "test_isArray",
49 "test_isVoid" };
52 Any anyBool; //
53 Any anyChar; //
54 Any anyByte; //
55 Any anyShort; //
56 Any anyInt; //
57 Any anyLong; //
58 Any anyFloat; //
59 Any anyDouble; //
60 Any anyStr; //
61 Any anyType; //
62 Any anyArByte; //
63 Any anyVoid; //
64 Any anyXTypeProvider;
66 Boolean aBool= new Boolean(true);
67 Character aChar= new Character('A');
68 Byte aByte= new Byte((byte) 111);
69 Short aShort= new Short((short) 11111);
70 Integer aInt= new Integer( 1111111);
71 Long aLong= new Long( 0xffffffff);
72 Float aFloat= new Float( 3.14);
73 Double aDouble= new Double( 3.145);
74 Object aObj= new ATypeProvider();
75 String aStr= new String("I am a string");
76 Type aType= new Type(String.class);
77 byte[] arByte= new byte[] {1,2,3};
79 public AnyConverter_Test() {
80 anyVoid= new Any(new Type(void.class), null);
81 anyBool= new Any(new Type(Boolean.TYPE), aBool);
82 anyChar= new Any(new Type(Character.TYPE), aChar);
83 anyByte= new Any(new Type(Byte.TYPE), aByte);
84 anyShort= new Any(new Type(Short.TYPE), aShort);
85 anyInt= new Any(new Type(Integer.TYPE), aInt);
86 anyLong= new Any(new Type(Long.TYPE), aLong);
87 anyFloat= new Any(new Type(Float.TYPE), aFloat);
88 anyDouble= new Any(new Type(Double.TYPE), aDouble);
89 anyStr= new Any(new Type(String.class), aStr);
90 anyType= new Any(new Type(Type.class), aType);
91 anyArByte= new Any(new Type(byte[].class), arByte);
92 anyXTypeProvider= new Any(new Type(XTypeProvider.class), aObj);
95 public void test_toBoolean()
96 throws com.sun.star.lang.IllegalArgumentException
98 // must work
99 boolean b= AnyConverter.toBoolean(aBool);
100 assure("", b == aBool.booleanValue());
101 b= AnyConverter.toBoolean(anyBool);
102 assure("", b == ((Boolean)anyBool.getObject()).booleanValue());
104 // must fail
105 try { AnyConverter.toBoolean(aChar); failed("");
106 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
107 try { AnyConverter.toBoolean(anyChar); failed("");
108 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
109 try { AnyConverter.toBoolean(aByte); failed("");
110 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
111 try { AnyConverter.toBoolean(anyByte); failed("");
112 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
113 try { AnyConverter.toBoolean(aShort); failed("");
114 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
115 try { AnyConverter.toBoolean(anyShort); failed("");
116 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
117 try { AnyConverter.toBoolean(aInt); failed("");
118 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
119 try { AnyConverter.toBoolean(anyInt); failed("");
120 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
121 try { AnyConverter.toBoolean(aLong); failed("");
122 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
123 try { AnyConverter.toBoolean(anyLong); failed("");
124 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
125 try { AnyConverter.toBoolean(aFloat); failed("");
126 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
127 try { AnyConverter.toBoolean(anyFloat); failed("");
128 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
129 try { AnyConverter.toBoolean(aDouble); failed("");
130 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
131 try { AnyConverter.toBoolean(anyDouble); failed("");
132 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
133 try { AnyConverter.toBoolean(aObj); failed("");
134 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
135 try { AnyConverter.toBoolean(aStr); failed("");
136 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
137 try { AnyConverter.toBoolean(anyStr); failed("");
138 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
139 try { AnyConverter.toBoolean(aType); failed("");
140 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
141 try { AnyConverter.toBoolean(anyType); failed("");
142 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
143 try { AnyConverter.toBoolean(anyVoid); failed("");
144 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
145 try { AnyConverter.toBoolean(arByte); failed("");
146 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
147 try { AnyConverter.toBoolean(anyArByte); failed("");
148 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
151 public void test_toChar()
152 throws com.sun.star.lang.IllegalArgumentException
154 // must work
155 char b= AnyConverter.toChar(aChar);
156 assure("", b == aChar.charValue());
157 b= AnyConverter.toChar(anyChar);
158 assure("", b == ((Character)anyChar.getObject()).charValue());
160 // must fail
161 try { AnyConverter.toChar(aBool); failed("");
162 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
163 try { AnyConverter.toChar(anyBool); failed("");
164 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
165 try { AnyConverter.toChar(aByte); failed("");
166 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
167 try { AnyConverter.toChar(anyByte); failed("");
168 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
169 try { AnyConverter.toChar(aShort); failed("");
170 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
171 try { AnyConverter.toChar(anyShort); failed("");
172 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
173 try { AnyConverter.toChar(aInt); failed("");
174 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
175 try { AnyConverter.toChar(anyInt); failed("");
176 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
177 try { AnyConverter.toChar(aLong); failed("");
178 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
179 try { AnyConverter.toChar(anyLong); failed("");
180 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
181 try { AnyConverter.toChar(aFloat); failed("");
182 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
183 try { AnyConverter.toChar(anyFloat); failed("");
184 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
185 try { AnyConverter.toChar(aDouble); failed("");
186 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
187 try { AnyConverter.toChar(anyDouble); failed("");
188 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
189 try { AnyConverter.toChar(aObj); failed("");
190 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
191 try { AnyConverter.toChar(aStr); failed("");
192 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
193 try { AnyConverter.toChar(anyStr); failed("");
194 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
195 try { AnyConverter.toChar(aType); failed("");
196 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
197 try { AnyConverter.toChar(anyType); failed("");
198 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
199 try { AnyConverter.toChar(anyVoid); failed("");
200 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
201 try { AnyConverter.toChar(arByte); failed("");
202 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
203 try { AnyConverter.toChar(anyArByte); failed("");
204 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
207 public void test_toByte()
208 throws com.sun.star.lang.IllegalArgumentException
210 // must work
211 byte val= AnyConverter.toByte(aByte);
212 assure("", val == aByte.byteValue());
213 val= AnyConverter.toByte(anyByte);
214 assure("", val == ((Byte)anyByte.getObject()).byteValue());
216 // must fail
217 try { AnyConverter.toByte(aChar); failed("");
218 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
219 try { AnyConverter.toByte(anyChar); failed("");
220 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
221 try { AnyConverter.toByte(aShort); failed("");
222 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
223 try { AnyConverter.toByte(anyShort); failed("");
224 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
225 try { AnyConverter.toByte(aInt); failed("");
226 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
227 try { AnyConverter.toByte(anyInt); failed("");
228 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
229 try { AnyConverter.toByte(aLong); failed("");
230 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
231 try { AnyConverter.toByte(anyLong); failed("");
232 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
233 try { AnyConverter.toByte(aFloat); failed("");
234 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
235 try { AnyConverter.toByte(anyFloat); failed("");
236 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
237 try { AnyConverter.toByte(aDouble); failed("");
238 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
239 try { AnyConverter.toByte(anyDouble); failed("");
240 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
241 try { AnyConverter.toByte(aObj); failed("");
242 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
243 try { AnyConverter.toByte(aStr); failed("");
244 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
245 try { AnyConverter.toByte(anyStr); failed("");
246 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
247 try { AnyConverter.toByte(aType); failed("");
248 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
249 try { AnyConverter.toByte(anyType); failed("");
250 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
251 try { AnyConverter.toByte(anyVoid); failed("");
252 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
253 try { AnyConverter.toByte(arByte); failed("");
254 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
255 try { AnyConverter.toByte(anyArByte); failed("");
256 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
259 public void test_toShort()
260 throws com.sun.star.lang.IllegalArgumentException
262 // must work
263 short sh= AnyConverter.toShort(aByte);
264 assure("", sh == aByte.byteValue());
265 sh= AnyConverter.toShort(aShort);
266 assure("", sh == aShort.shortValue());
267 sh= AnyConverter.toShort(anyByte);
268 assure("", sh == ((Byte)anyByte.getObject()).byteValue());
269 sh= AnyConverter.toShort(anyShort);
270 assure("", sh == ((Short) anyShort.getObject()).shortValue());
271 Any a = new Any( Type.UNSIGNED_SHORT, new Short((short)5) );
272 assure("", 5 == AnyConverter.toUnsignedShort( a ));
274 // must fail
275 try { AnyConverter.toShort(a); failed("");
276 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
277 try { AnyConverter.toUnsignedShort(anyShort); failed("");
278 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
279 try { AnyConverter.toChar(aBool); failed("");
280 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
281 try { AnyConverter.toChar(anyBool); failed("");
282 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
283 try { AnyConverter.toShort(aChar); failed("");
284 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
285 try { AnyConverter.toShort(anyChar); failed("");
286 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
287 try { AnyConverter.toShort(aBool); failed("");
288 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
289 try { AnyConverter.toShort(anyBool); failed("");
290 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
291 try { AnyConverter.toShort(aInt); failed("");
292 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
293 try { AnyConverter.toShort(anyInt); failed("");
294 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
295 try { AnyConverter.toShort(aLong); failed("");
296 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
297 try { AnyConverter.toShort(anyLong); failed("");
298 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
299 try { AnyConverter.toShort(aFloat); failed("");
300 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
301 try { AnyConverter.toShort(anyFloat); failed("");
302 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
303 try { AnyConverter.toShort(aDouble); failed("");
304 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
305 try { AnyConverter.toShort(anyDouble); failed("");
306 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
307 try { AnyConverter.toShort(aObj); failed("");
308 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
309 try { AnyConverter.toShort(aStr); failed("");
310 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
311 try { AnyConverter.toShort(anyStr); failed("");
312 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
313 try { AnyConverter.toShort(aType); failed("");
314 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
315 try { AnyConverter.toShort(anyType); failed("");
316 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
317 try { AnyConverter.toShort(anyVoid); failed("");
318 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
319 try { AnyConverter.toShort(arByte); failed("");
320 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
321 try { AnyConverter.toShort(anyArByte); failed("");
322 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
325 public void test_toInt()
326 throws com.sun.star.lang.IllegalArgumentException
328 // must work
329 int val= AnyConverter.toInt(aByte);
330 assure("", val == aByte.byteValue());
331 val= AnyConverter.toInt(aShort);
332 assure("", val == aShort.shortValue());
333 val= AnyConverter.toInt(aInt);
334 assure("", val == aInt.intValue());
335 val= AnyConverter.toInt(anyByte);
336 assure("", val == ((Byte)anyByte.getObject()).byteValue());
337 val= AnyConverter.toInt(anyShort);
338 assure("", val == ((Short) anyShort.getObject()).shortValue());
339 val= AnyConverter.toInt(anyInt);
340 assure("", val == ((Integer) anyInt.getObject()).intValue());
341 Any a = new Any( Type.UNSIGNED_SHORT, new Short((short)5) );
342 assure("", 5 == AnyConverter.toInt(a));
343 assure("", 5 == AnyConverter.toUnsignedInt(a));
344 a = new Any( Type.UNSIGNED_LONG, new Integer(5) );
345 assure("", 5 == AnyConverter.toUnsignedInt(a));
347 // must fail
348 try { AnyConverter.toUnsignedInt(anyInt); failed("");
349 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
350 try { AnyConverter.toInt(a); failed("");
351 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
352 try { AnyConverter.toUnsignedInt(anyShort); failed("");
353 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
354 try { AnyConverter.toInt(aChar); failed("");
355 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
356 try { AnyConverter.toInt(anyChar); failed("");
357 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
358 try { AnyConverter.toInt(aBool); failed("");
359 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
360 try { AnyConverter.toInt(anyBool); failed("");
361 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
362 try { AnyConverter.toInt(aLong); failed("");
363 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
364 try { AnyConverter.toInt(anyLong); failed("");
365 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
366 try { AnyConverter.toInt(aFloat); failed("");
367 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
368 try { AnyConverter.toInt(anyFloat); failed("");
369 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
370 try { AnyConverter.toInt(aDouble); failed("");
371 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
372 try { AnyConverter.toInt(anyDouble); failed("");
373 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
374 try { AnyConverter.toInt(aObj); failed("");
375 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
376 try { AnyConverter.toInt(aStr); failed("");
377 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
378 try { AnyConverter.toInt(anyStr); failed("");
379 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
380 try { AnyConverter.toInt(aType); failed("");
381 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
382 try { AnyConverter.toInt(anyType); failed("");
383 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
384 try { AnyConverter.toInt(anyVoid); failed("");
385 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
386 try { AnyConverter.toInt(arByte); failed("");
387 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
388 try { AnyConverter.toInt(anyArByte); failed("");
389 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
392 public void test_toLong()
393 throws com.sun.star.lang.IllegalArgumentException
395 // must work
396 long val= AnyConverter.toLong(aByte);
397 assure("", val == aByte.byteValue());
398 val= AnyConverter.toLong(aShort);
399 assure("", val == aShort.shortValue());
400 val= AnyConverter.toLong(aInt);
401 assure("", val == aInt.intValue());
402 val= AnyConverter.toLong(aLong);
403 assure("", val == aLong.longValue());
404 val= AnyConverter.toLong(anyByte);
405 assure("", val == ((Byte)anyByte.getObject()).byteValue());
406 val= AnyConverter.toLong(anyShort);
407 assure("", val == ((Short) anyShort.getObject()).shortValue());
408 val= AnyConverter.toLong(anyInt);
409 assure("", val == ((Integer) anyInt.getObject()).intValue());
410 val= AnyConverter.toLong(anyLong);
411 assure("", val == ((Long) anyLong.getObject()).longValue());
412 Any a = new Any( Type.UNSIGNED_SHORT, new Short((short)5) );
413 assure("", 5 == AnyConverter.toLong(a));
414 assure("", 5 == AnyConverter.toUnsignedLong(a));
415 a = new Any( Type.UNSIGNED_LONG, new Integer(5) );
416 assure("", 5 == AnyConverter.toUnsignedLong(a));
417 assure("", 5 == AnyConverter.toLong(a));
418 a = new Any( Type.UNSIGNED_HYPER, new Long(5) );
419 assure("", 5 == AnyConverter.toUnsignedLong(a));
421 // must fail
422 try { AnyConverter.toUnsignedLong(anyShort); failed("");
423 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
424 try { AnyConverter.toUnsignedLong(anyInt); failed("");
425 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
426 try { AnyConverter.toLong(a); failed("");
427 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
428 try { AnyConverter.toUnsignedLong(anyLong); failed("");
429 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
430 try { AnyConverter.toLong(aChar); failed("");
431 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
432 try { AnyConverter.toLong(anyChar); failed("");
433 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
434 try { AnyConverter.toLong(aBool); failed("");
435 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
436 try { AnyConverter.toLong(anyBool); failed("");
437 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
438 try { AnyConverter.toLong(aFloat); failed("");
439 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
440 try { AnyConverter.toLong(anyFloat); failed("");
441 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
442 try { AnyConverter.toLong(aDouble); failed("");
443 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
444 try { AnyConverter.toLong(anyDouble); failed("");
445 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
446 try { AnyConverter.toLong(aObj); failed("");
447 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
448 try { AnyConverter.toLong(aStr); failed("");
449 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
450 try { AnyConverter.toLong(anyStr); failed("");
451 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
452 try { AnyConverter.toLong(aType); failed("");
453 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
454 try { AnyConverter.toLong(anyType); failed("");
455 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
456 try { AnyConverter.toLong(anyVoid); failed("");
457 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
458 try { AnyConverter.toLong(arByte); failed("");
459 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
460 try { AnyConverter.toLong(anyArByte); failed("");
461 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
464 public void test_toFloat()
465 throws com.sun.star.lang.IllegalArgumentException
467 // must work
468 float val= AnyConverter.toFloat(aByte);
469 assure("", val == aByte.byteValue()); // 111 = 111.0
470 val= AnyConverter.toFloat(anyByte);
471 assure("", val == ((Byte)anyByte.getObject()).byteValue());
472 val= AnyConverter.toFloat(aShort);
473 assure("", val == aShort.shortValue()); //11111 = 11111.0
474 val= AnyConverter.toFloat(anyShort);
475 assure("", val == ((Short) anyShort.getObject()).shortValue());
476 val= AnyConverter.toFloat(aFloat);
477 assure("", val == aFloat.floatValue());
478 val= AnyConverter.toFloat(anyFloat);
479 assure("", val == ((Float) anyFloat.getObject()).floatValue());
481 // must fail
482 try { AnyConverter.toFloat(aChar); failed("");
483 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
484 try { AnyConverter.toFloat(anyChar); failed("");
485 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
486 try { AnyConverter.toFloat(aBool); failed("");
487 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
488 try { AnyConverter.toFloat(anyBool); failed("");
489 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
490 try { AnyConverter.toFloat(aInt); failed("");
491 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
492 try { AnyConverter.toFloat(anyInt); failed("");
493 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
494 try { AnyConverter.toFloat(aLong); failed("");
495 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
496 try { AnyConverter.toFloat(anyLong); failed("");
497 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
498 try { AnyConverter.toFloat(aDouble); failed("");
499 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
500 try { AnyConverter.toFloat(anyDouble); failed("");
501 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
502 try { AnyConverter.toFloat(aObj); failed("");
503 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
504 try { AnyConverter.toFloat(aStr); failed("");
505 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
506 try { AnyConverter.toFloat(anyStr); failed("");
507 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
508 try { AnyConverter.toFloat(aType); failed("");
509 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
510 try { AnyConverter.toFloat(anyType); failed("");
511 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
512 try { AnyConverter.toFloat(anyVoid); failed("");
513 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
514 try { AnyConverter.toFloat(arByte); failed("");
515 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
516 try { AnyConverter.toFloat(anyArByte); failed("");
517 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
520 public void test_toDouble()
521 throws com.sun.star.lang.IllegalArgumentException
523 // must work
524 double val= AnyConverter.toDouble(aByte);
525 assure("", val == aByte.byteValue()); // 111 = 111.0
526 val= AnyConverter.toDouble(anyByte);
527 assure("", val == ((Byte)anyByte.getObject()).byteValue());
528 val= AnyConverter.toDouble(aShort);
529 assure("", val == aShort.shortValue()); //11111 = 11111.0
530 val= AnyConverter.toDouble(anyShort);
531 assure("", val == ((Short) anyShort.getObject()).shortValue());
532 val= AnyConverter.toDouble(aInt);
533 assure("", val == aInt.intValue());
534 val= AnyConverter.toDouble(anyInt);
535 assure("", val == ((Integer) anyInt.getObject()).intValue());
536 val= AnyConverter.toDouble(aFloat);
537 assure("", val == aFloat.floatValue());
538 val= AnyConverter.toDouble(anyFloat);
539 float float1= ((Float) anyFloat.getObject()).floatValue();
540 assure("", val <= (float1 + 0.1) || val >= (float1 - 0.1));
541 val= AnyConverter.toDouble(aDouble);
542 assure("", val == aDouble.doubleValue());
543 val= AnyConverter.toDouble(anyDouble);
544 assure("", val == ((Double) anyDouble.getObject()).doubleValue());
546 // must fail
547 try { AnyConverter.toDouble(aChar); failed("");
548 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
549 try { AnyConverter.toDouble(anyChar); failed("");
550 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
551 try { AnyConverter.toDouble(aBool); failed("");
552 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
553 try { AnyConverter.toDouble(anyBool); failed("");
554 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
555 try { AnyConverter.toDouble(aLong); failed("");
556 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
557 try { AnyConverter.toDouble(anyLong); failed("");
558 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
559 try { AnyConverter.toDouble(aObj); failed("");
560 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
561 try { AnyConverter.toDouble(aStr); failed("");
562 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
563 try { AnyConverter.toDouble(anyStr); failed("");
564 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
565 try { AnyConverter.toDouble(aType); failed("");
566 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
567 try { AnyConverter.toDouble(anyType); failed("");
568 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
569 try { AnyConverter.toDouble(anyVoid); failed("");
570 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
571 try { AnyConverter.toDouble(arByte); failed("");
572 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
573 try { AnyConverter.toDouble(anyArByte); failed("");
574 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
577 public void test_toObject()
578 throws com.sun.star.lang.IllegalArgumentException
580 // must work
581 Type _type= new Type(XTypeProvider.class);
582 Object val= AnyConverter.toObject(_type, aObj);
583 assure("", UnoRuntime.areSame(val, aObj));
584 val= AnyConverter.toObject(
585 _type, new Any( new Type(XTypeProvider.class), null));
586 assure("", val == null);
588 // structs, exceptions
589 com.sun.star.lang.IllegalArgumentException exc =
590 new com.sun.star.lang.IllegalArgumentException();
591 Any any_exc = new Any(
592 new Type("com.sun.star.lang.IllegalArgumentException",
593 TypeClass.EXCEPTION), exc);
594 assure("",
595 AnyConverter.toObject(
596 new Type(com.sun.star.lang.IllegalArgumentException.class),
597 any_exc).equals(exc));
598 assure("",
599 AnyConverter.toObject(
600 new Type(com.sun.star.uno.Exception.class), any_exc).equals(
601 exc));
602 try {
603 AnyConverter.toObject(
604 new Type(com.sun.star.uno.RuntimeException.class), any_exc);
605 failed("");
606 } catch (com.sun.star.lang.IllegalArgumentException ie) {};
607 any_exc = new Any(com.sun.star.lang.IllegalArgumentException.class,
608 exc);
609 assure("",
610 AnyConverter.toObject(
611 new Type(com.sun.star.lang.IllegalArgumentException.class),
612 any_exc).equals(exc));
613 assure("",
614 AnyConverter.toObject(new Type(com.sun.star.uno.Exception.class),
615 any_exc).equals(exc));
616 try {
617 AnyConverter.toObject(
618 new Type(com.sun.star.uno.RuntimeException.class), any_exc);
619 failed("");
620 } catch (com.sun.star.lang.IllegalArgumentException ie) {};
622 // must fail
623 try { AnyConverter.toObject(_type, aType); failed("");
624 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
625 try { AnyConverter.toObject(_type, anyType); failed("");
626 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
627 try { AnyConverter.toObject(_type, anyVoid); failed("");
628 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
629 try { AnyConverter.toObject(_type, new Object()); failed("");
630 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
633 public void test_toString()
634 throws com.sun.star.lang.IllegalArgumentException
636 // must work
637 String val= AnyConverter.toString(aStr);
638 assure("", aStr.equals(val));
639 val= AnyConverter.toString(anyStr);
640 assure("", ((String)anyStr.getObject()).equals(val));
642 // must fail
643 try { AnyConverter.toString(aBool); failed("");
644 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
645 try { AnyConverter.toString(anyBool); failed("");
646 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
647 try { AnyConverter.toString(aChar); failed("");
648 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
649 try { AnyConverter.toString(anyChar); failed("");
650 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
651 try { AnyConverter.toString(aByte); failed("");
652 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
653 try { AnyConverter.toString(anyByte); failed("");
654 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
655 try { AnyConverter.toString(aShort); failed("");
656 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
657 try { AnyConverter.toString(anyShort); failed("");
658 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
659 try { AnyConverter.toString(aInt); failed("");
660 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
661 try { AnyConverter.toString(anyInt); failed("");
662 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
663 try { AnyConverter.toString(aLong); failed("");
664 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
665 try { AnyConverter.toString(anyLong); failed("");
666 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
667 try { AnyConverter.toString(aFloat); failed("");
668 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
669 try { AnyConverter.toString(anyFloat); failed("");
670 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
671 try { AnyConverter.toString(aDouble); failed("");
672 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
673 try { AnyConverter.toString(anyDouble); failed("");
674 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
675 try { AnyConverter.toString(aObj); failed("");
676 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
677 try { AnyConverter.toString(aType); failed("");
678 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
679 try { AnyConverter.toString(anyType); failed("");
680 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
681 try { AnyConverter.toString(anyVoid); failed("");
682 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
683 try { AnyConverter.toString(arByte); failed("");
684 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
685 try { AnyConverter.toString(anyArByte); failed("");
686 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
689 public void test_toType()
690 throws com.sun.star.lang.IllegalArgumentException
692 // must work
693 Type val= AnyConverter.toType(aType);
694 assure("", val == aType);
695 val= AnyConverter.toType(anyType);
696 assure("", val == anyType.getObject());
698 // must fail
699 try { AnyConverter.toType(aBool); failed("");
700 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
701 try { AnyConverter.toType(anyBool); failed("");
702 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
703 try { AnyConverter.toType(aChar); failed("");
704 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
705 try { AnyConverter.toType(anyChar); failed("");
706 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
707 try { AnyConverter.toType(aByte); failed("");
708 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
709 try { AnyConverter.toType(anyByte); failed("");
710 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
711 try { AnyConverter.toType(aShort); failed("");
712 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
713 try { AnyConverter.toType(anyShort); failed("");
714 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
715 try { AnyConverter.toType(aInt); failed("");
716 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
717 try { AnyConverter.toType(anyInt); failed("");
718 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
719 try { AnyConverter.toType(aLong); failed("");
720 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
721 try { AnyConverter.toType(anyLong); failed("");
722 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
723 try { AnyConverter.toType(aFloat); failed("");
724 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
725 try { AnyConverter.toType(anyFloat); failed("");
726 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
727 try { AnyConverter.toType(aDouble); failed("");
728 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
729 try { AnyConverter.toType(anyDouble); failed("");
730 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
731 try { AnyConverter.toType(aObj); failed("");
732 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
733 try { AnyConverter.toType(aStr); failed("");
734 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
735 try { AnyConverter.toType(anyStr); failed("");
736 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
737 try { AnyConverter.toType(anyVoid); failed("");
738 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
739 try { AnyConverter.toType(arByte); failed("");
740 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
741 try { AnyConverter.toType(anyArByte); failed("");
742 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
745 public void test_toArray()
746 throws com.sun.star.lang.IllegalArgumentException
748 // must work
749 Object val= AnyConverter.toArray(arByte);
750 assure("", val == arByte);
751 val= AnyConverter.toArray(anyArByte);
752 assure("", val == anyArByte.getObject());
754 // must fail
755 try { AnyConverter.toType(aBool); failed("");
756 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
757 try { AnyConverter.toType(anyBool); failed("");
758 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
759 try { AnyConverter.toType(aChar); failed("");
760 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
761 try { AnyConverter.toType(anyChar); failed("");
762 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
763 try { AnyConverter.toType(aByte); failed("");
764 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
765 try { AnyConverter.toType(anyByte); failed("");
766 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
767 try { AnyConverter.toType(aShort); failed("");
768 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
769 try { AnyConverter.toType(anyShort); failed("");
770 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
771 try { AnyConverter.toType(aInt); failed("");
772 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
773 try { AnyConverter.toType(anyInt); failed("");
774 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
775 try { AnyConverter.toType(aLong); failed("");
776 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
777 try { AnyConverter.toType(anyLong); failed("");
778 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
779 try { AnyConverter.toType(aFloat); failed("");
780 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
781 try { AnyConverter.toType(anyFloat); failed("");
782 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
783 try { AnyConverter.toType(aDouble); failed("");
784 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
785 try { AnyConverter.toType(anyDouble); failed("");
786 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
787 try { AnyConverter.toType(aObj); failed("");
788 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
789 try { AnyConverter.toType(aStr); failed("");
790 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
791 try { AnyConverter.toType(anyStr); failed("");
792 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
793 try { AnyConverter.toType(anyVoid); failed("");
794 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
795 try { AnyConverter.toType(arByte); failed("");
796 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
797 try { AnyConverter.toType(anyArByte); failed("");
798 } catch (com.sun.star.lang.IllegalArgumentException ie) {}
801 public void test_isBoolean() {
802 assure("", AnyConverter.isBoolean(aBool));
803 assure("", AnyConverter.isBoolean(anyBool));
804 assure("", !AnyConverter.isBoolean(aChar));
807 public void test_isChar() {
808 assure("", AnyConverter.isChar(aChar));
809 assure("", AnyConverter.isChar(anyChar));
810 assure("", !AnyConverter.isChar(aBool));
813 public void test_isByte() {
814 assure("", AnyConverter.isByte(aByte));
815 assure("", AnyConverter.isByte(anyByte));
816 assure("", !AnyConverter.isByte(aBool));
819 public void test_isShort() {
820 assure("", AnyConverter.isShort(aShort));
821 assure("", AnyConverter.isShort(anyShort));
822 assure("", Type.SHORT.equals(AnyConverter.getType(anyShort)));
823 Any a = new Any( Type.UNSIGNED_SHORT, new Short((short)5) );
824 assure("", Type.UNSIGNED_SHORT.equals(AnyConverter.getType(a)));
825 assure("", !AnyConverter.isShort(a));
826 assure("", !Type.SHORT.equals(AnyConverter.getType(a)));
827 assure("", !AnyConverter.isShort(aBool));
830 public void test_isInt() {
831 assure("", AnyConverter.isInt(aInt));
832 assure("", AnyConverter.isInt(anyInt));
833 assure("", Type.LONG.equals(AnyConverter.getType(anyInt)));
834 Any a = new Any(Type.UNSIGNED_LONG, new Integer(5));
835 assure("", Type.UNSIGNED_LONG.equals(AnyConverter.getType(a)));
836 assure("", !AnyConverter.isInt(a));
837 assure("", !Type.LONG.equals(AnyConverter.getType(a)));
838 assure("", !AnyConverter.isInt(aBool));
841 public void test_isLong() {
842 assure("", AnyConverter.isLong(aLong));
843 assure("", AnyConverter.isLong(anyLong));
844 assure("", Type.HYPER.equals(AnyConverter.getType(anyLong)));
845 Any a = new Any( Type.UNSIGNED_HYPER, new Long(5) );
846 assure("", Type.UNSIGNED_HYPER.equals( AnyConverter.getType(a) ));
847 assure("", !AnyConverter.isLong(a));
848 assure("", !Type.HYPER.equals( AnyConverter.getType(a) ));
849 assure("", !AnyConverter.isLong(aBool));
852 public void test_isFloat() {
853 assure("", AnyConverter.isFloat(aFloat));
854 assure("", AnyConverter.isFloat(anyFloat));
855 assure("", !AnyConverter.isFloat(aDouble));
858 public void test_isDouble() {
859 assure("", AnyConverter.isDouble(aDouble));
860 assure("", AnyConverter.isDouble(anyDouble));
861 assure("", !AnyConverter.isDouble(aFloat));
864 public void test_isObject() {
865 assure("", AnyConverter.isObject(aObj));
866 assure("", AnyConverter.isObject( new Any( XInterface.class, null)));
867 assure("", !AnyConverter.isObject(new Object()));
870 public void test_isString() {
871 assure("", AnyConverter.isString(aStr));
872 assure("", AnyConverter.isString(anyStr));
873 assure("", !AnyConverter.isString(new Object()));
876 public void test_isType() {
877 assure("", AnyConverter.isType(aType));
878 assure("", AnyConverter.isType(anyType));
879 assure("", !AnyConverter.isType(new Object()));
882 public void test_isArray() {
883 assure("", AnyConverter.isArray(arByte));
884 assure("", AnyConverter.isArray(anyArByte));
885 assure("", !AnyConverter.isArray(new Object()));
888 public void test_isVoid() {
889 assure("", AnyConverter.isVoid(anyVoid));
890 assure("", !AnyConverter.isVoid(new Object()));
895 class ATypeProvider implements com.sun.star.lang.XTypeProvider
898 public byte[] getImplementationId()
900 return new byte[]{1,2,3};
903 public com.sun.star.uno.Type[] getTypes()
905 return new Type[]{new Type(XTypeProvider.class)};