1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 package com.sun.star.uno; 25 26 import complexlib.ComplexTestCase; 27 28 public final class Type_Test extends ComplexTestCase { getTestMethodNames()29 public String[] getTestMethodNames() { 30 return new String[] { "testZClass", "testIsSupertypeOf" }; 31 } 32 testZClass()33 public void testZClass() { 34 assure("VOID", new Type("void").getZClass() == void.class); 35 assure("BOOLEAN", new Type("boolean").getZClass() == boolean.class); 36 assure("BYTE", new Type("byte").getZClass() == byte.class); 37 assure("SHORT", new Type("short").getZClass() == short.class); 38 assure("UNSIGNED SHORT", 39 new Type("unsigned short").getZClass() == short.class); 40 assure("LONG", new Type("long").getZClass() == int.class); 41 assure("UNSIGNED LONG", 42 new Type("unsigned long").getZClass() == int.class); 43 assure("HYPER", new Type("hyper").getZClass() == long.class); 44 assure("UNSIGNED HYPER", 45 new Type("unsigned hyper").getZClass() == long.class); 46 assure("FLOAT", new Type("float").getZClass() == float.class); 47 assure("DOUBLE", new Type("double").getZClass() == double.class); 48 assure("CHAR", new Type("char").getZClass() == char.class); 49 assure("STRING", new Type("string").getZClass() == String.class); 50 assure("TYPE", new Type("type").getZClass() == Type.class); 51 assure("ANY", new Type("any").getZClass() == Object.class); 52 assure("sequence of BOOLEAN", 53 new Type("[]boolean", TypeClass.SEQUENCE).getZClass() 54 == boolean[].class); 55 assure("sequence of sequence of XComponentContext", 56 new Type("[][]com.sun.star.uno.XComponentContext", 57 TypeClass.SEQUENCE).getZClass() 58 == XComponentContext[][].class); 59 assure("enum TypeClass", 60 new Type("com.sun.star.uno.TypeClass", 61 TypeClass.ENUM).getZClass() == TypeClass.class); 62 assure("struct Uik", 63 new Type("com.sun.star.uno.Uik", TypeClass.STRUCT).getZClass() 64 == Uik.class); 65 assure("exception Exception", 66 new Type("com.sun.star.uno.Exception", 67 TypeClass.EXCEPTION).getZClass() 68 == com.sun.star.uno.Exception.class); 69 assure("exception RuntimeException", 70 new Type("com.sun.star.uno.RuntimeException", 71 TypeClass.EXCEPTION).getZClass() 72 == com.sun.star.uno.RuntimeException.class); 73 assure("exception DeploymentException", 74 new Type("com.sun.star.uno.DeploymentException", 75 TypeClass.EXCEPTION).getZClass() 76 == DeploymentException.class); 77 assure("interface XInterface", 78 new Type("com.sun.star.uno.XInterface", 79 TypeClass.INTERFACE).getZClass() == XInterface.class); 80 assure("interface XComponentContext", 81 new Type("com.sun.star.uno.XComponentContext", 82 TypeClass.INTERFACE).getZClass() 83 == XComponentContext.class); 84 85 assure(new Type(boolean.class).getZClass() == boolean.class); 86 assure(new Type(Boolean.class).getZClass() == boolean.class); 87 assure(new Type(boolean[].class).getZClass() == boolean[].class); 88 assure(new Type(Boolean[].class).getZClass() == boolean[].class); 89 } 90 testIsSupertypeOf()91 public void testIsSupertypeOf() { 92 Type ifc = new Type(com.sun.star.uno.XInterface.class); 93 Type ctx = new Type(com.sun.star.uno.XComponentContext.class); 94 Type exc = new Type(com.sun.star.uno.RuntimeException.class); 95 assure("LONG :> LONG", Type.LONG.isSupertypeOf(Type.LONG)); 96 assure("not ANY :> XInterface", !Type.ANY.isSupertypeOf(ifc)); 97 assure("ANY :> ANY", Type.ANY.isSupertypeOf(Type.ANY)); 98 assure("not ANY :> LONG", !Type.ANY.isSupertypeOf(Type.LONG)); 99 assure("not XInterface :> ANY", !ifc.isSupertypeOf(Type.ANY)); 100 assure("XInterface :> XInterface", ifc.isSupertypeOf(ifc)); 101 assure("XInterface :> XComponentContext", ifc.isSupertypeOf(ctx)); 102 assure("not XComponentContext :> XInterface", !ctx.isSupertypeOf(ifc)); 103 assure("XComponentContext :> XComponentContext", 104 ctx.isSupertypeOf(ctx)); 105 assure("not XInterface :> RuntimeException", !ifc.isSupertypeOf(exc)); 106 } 107 } 108