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 test.codemaker.javamaker.java15;
25 
26 import com.sun.star.lang.XMultiComponentFactory;
27 import com.sun.star.uno.DeploymentException;
28 import com.sun.star.uno.XComponentContext;
29 import org.junit.Test;
30 
31 import static org.junit.Assert.*;
32 
33 public final class Java15Javamaker_Test {
34     @Test
testPlainPolyStruct()35     public void testPlainPolyStruct() {
36         PolyStruct s = new PolyStruct();
37         assertTrue(s.member1 == null);
38         assertTrue(s.member2 == 0);
39         s = new PolyStruct("ABC", 5);
40         assertTrue(s.member1.equals("ABC"));
41         assertTrue(s.member2 == 5);
42     }
43 
44     @Test
testBooleanPolyStruct()45     public void testBooleanPolyStruct() {
46         PolyStruct<Boolean,Object> s = new PolyStruct<Boolean,Object>();
47         assertTrue(s.member1 == null);
48         assertTrue(s.member2 == 0);
49         s = new PolyStruct<Boolean,Object>(true, 5);
50         assertTrue(s.member1 == true);
51         assertTrue(s.member2 == 5);
52     }
53 
54     @Test
testStruct()55     public void testStruct() {
56         Struct s = new Struct();
57         assertTrue(s.member.member1 == null);
58         assertTrue(s.member.member2 == 0);
59         s = new Struct(
60             new PolyStruct<PolyStruct<boolean[], Object>, Integer>(
61                 new PolyStruct<boolean[], Object>(new boolean[] { true }, 3),
62                 4));
63         assertTrue(s.member.member1.member1.length == 1);
64         assertTrue(s.member.member1.member1[0] == true);
65         assertTrue(s.member.member1.member2 == 3);
66         assertTrue(s.member.member2 == 4);
67     }
68 
69     @Test
testService()70     public void testService() {
71         XComponentContext context = new XComponentContext() {
72                 public Object getValueByName(String name) {
73                     return null;
74                 }
75 
76                 public XMultiComponentFactory getServiceManager() {
77                     return null;
78                 }
79             };
80         try {
81             Service.create(context);
82             fail();
83         } catch (DeploymentException e) {}
84         try {
85             Service.create(
86                 context, false, (byte) 1, (short) 2, Integer.valueOf(4));
87             fail();
88         } catch (DeploymentException e) {}
89     }
90 
91     private static final class Ifc implements XIfc {
f1(PolyStruct<Integer, Integer> arg)92         public void f1(PolyStruct<Integer, Integer> arg) {}
93 
f2(PolyStruct<Object, Object> arg)94         public void f2(PolyStruct<Object, Object> arg) {}
95     }
96 }
97