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