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 org.junit.Test;
27 import static org.junit.Assert.*;
28 
29 public final class Type_Test {
30     @Test
testZClass()31     public void testZClass() {
32         assertTrue("VOID", new Type("void").getZClass() == void.class);
33         assertTrue("BOOLEAN", new Type("boolean").getZClass() == boolean.class);
34         assertTrue("BYTE", new Type("byte").getZClass() == byte.class);
35         assertTrue("SHORT", new Type("short").getZClass() == short.class);
36         assertTrue("UNSIGNED SHORT",
37                new Type("unsigned short").getZClass() == short.class);
38         assertTrue("LONG", new Type("long").getZClass() == int.class);
39         assertTrue("UNSIGNED LONG",
40                new Type("unsigned long").getZClass() == int.class);
41         assertTrue("HYPER", new Type("hyper").getZClass() == long.class);
42         assertTrue("UNSIGNED HYPER",
43                new Type("unsigned hyper").getZClass() == long.class);
44         assertTrue("FLOAT", new Type("float").getZClass() == float.class);
45         assertTrue("DOUBLE", new Type("double").getZClass() == double.class);
46         assertTrue("CHAR", new Type("char").getZClass() == char.class);
47         assertTrue("STRING", new Type("string").getZClass() == String.class);
48         assertTrue("TYPE", new Type("type").getZClass() == Type.class);
49         assertTrue("ANY", new Type("any").getZClass() == Object.class);
50         assertTrue("sequence of BOOLEAN",
51                new Type("[]boolean", TypeClass.SEQUENCE).getZClass()
52                == boolean[].class);
53         assertTrue("sequence of sequence of XComponentContext",
54                new Type("[][]com.sun.star.uno.XComponentContext",
55                         TypeClass.SEQUENCE).getZClass()
56                == XComponentContext[][].class);
57         assertTrue("enum TypeClass",
58                new Type("com.sun.star.uno.TypeClass",
59                         TypeClass.ENUM).getZClass() == TypeClass.class);
60         assertTrue("struct Uik",
61                new Type("com.sun.star.uno.Uik", TypeClass.STRUCT).getZClass()
62                == Uik.class);
63         assertTrue("exception Exception",
64                new Type("com.sun.star.uno.Exception",
65                         TypeClass.EXCEPTION).getZClass()
66                == com.sun.star.uno.Exception.class);
67         assertTrue("exception RuntimeException",
68                new Type("com.sun.star.uno.RuntimeException",
69                         TypeClass.EXCEPTION).getZClass()
70                == com.sun.star.uno.RuntimeException.class);
71         assertTrue("exception DeploymentException",
72                new Type("com.sun.star.uno.DeploymentException",
73                         TypeClass.EXCEPTION).getZClass()
74                == DeploymentException.class);
75         assertTrue("interface XInterface",
76                new Type("com.sun.star.uno.XInterface",
77                         TypeClass.INTERFACE).getZClass() == XInterface.class);
78         assertTrue("interface XComponentContext",
79                new Type("com.sun.star.uno.XComponentContext",
80                         TypeClass.INTERFACE).getZClass()
81                == XComponentContext.class);
82 
83         assertTrue(new Type(boolean.class).getZClass() == boolean.class);
84         assertTrue(new Type(Boolean.class).getZClass() == boolean.class);
85         assertTrue(new Type(boolean[].class).getZClass() == boolean[].class);
86         assertTrue(new Type(Boolean[].class).getZClass() == boolean[].class);
87     }
88 
89     @Test
testIsSupertypeOf()90     public void testIsSupertypeOf() {
91         Type ifc = new Type(com.sun.star.uno.XInterface.class);
92         Type ctx = new Type(com.sun.star.uno.XComponentContext.class);
93         Type exc = new Type(com.sun.star.uno.RuntimeException.class);
94         assertTrue("LONG :> LONG", Type.LONG.isSupertypeOf(Type.LONG));
95         assertTrue("not ANY :> XInterface", !Type.ANY.isSupertypeOf(ifc));
96         assertTrue("ANY :> ANY", Type.ANY.isSupertypeOf(Type.ANY));
97         assertTrue("not ANY :> LONG", !Type.ANY.isSupertypeOf(Type.LONG));
98         assertTrue("not XInterface :> ANY", !ifc.isSupertypeOf(Type.ANY));
99         assertTrue("XInterface :> XInterface", ifc.isSupertypeOf(ifc));
100         assertTrue("XInterface :> XComponentContext", ifc.isSupertypeOf(ctx));
101         assertTrue("not XComponentContext :> XInterface", !ctx.isSupertypeOf(ifc));
102         assertTrue("XComponentContext :> XComponentContext",
103                ctx.isSupertypeOf(ctx));
104         assertTrue("not XInterface :> RuntimeException", !ifc.isSupertypeOf(exc));
105     }
106 }
107