1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 package test.codemaker.javamaker.java15;
29 
30 import com.sun.star.lang.XMultiComponentFactory;
31 import com.sun.star.uno.DeploymentException;
32 import com.sun.star.uno.XComponentContext;
33 import complexlib.ComplexTestCase;
34 
35 public final class Test extends ComplexTestCase {
36     public String[] getTestMethodNames() {
37         return new String[] {
38             "testPlainPolyStruct", "testBooleanPolyStruct", "testStruct",
39             "testService" };
40     }
41 
42     public void testPlainPolyStruct() {
43         PolyStruct s = new PolyStruct();
44         assure(s.member1 == null);
45         assure(s.member2 == 0);
46         s = new PolyStruct("ABC", 5);
47         assure(s.member1.equals("ABC"));
48         assure(s.member2 == 5);
49     }
50 
51     public void testBooleanPolyStruct() {
52         PolyStruct<Boolean,Object> s = new PolyStruct<Boolean,Object>();
53         assure(s.member1 == null);
54         assure(s.member2 == 0);
55         s = new PolyStruct<Boolean,Object>(true, 5);
56         assure(s.member1 == true);
57         assure(s.member2 == 5);
58     }
59 
60     public void testStruct() {
61         Struct s = new Struct();
62         assure(s.member.member1 == null);
63         assure(s.member.member2 == 0);
64         s = new Struct(
65             new PolyStruct<PolyStruct<boolean[], Object>, Integer>(
66                 new PolyStruct<boolean[], Object>(new boolean[] { true }, 3),
67                 4));
68         assure(s.member.member1.member1.length == 1);
69         assure(s.member.member1.member1[0] == true);
70         assure(s.member.member1.member2 == 3);
71         assure(s.member.member2 == 4);
72     }
73 
74     public void testService() {
75         XComponentContext context = new XComponentContext() {
76                 public Object getValueByName(String name) {
77                     return null;
78                 }
79 
80                 public XMultiComponentFactory getServiceManager() {
81                     return null;
82                 }
83             };
84         try {
85             Service.create(context);
86             failed();
87         } catch (DeploymentException e) {}
88         try {
89             Service.create(
90                 context, false, (byte) 1, (short) 2, Integer.valueOf(4));
91             failed();
92         } catch (DeploymentException e) {}
93     }
94 
95     private static final class Ifc implements XIfc {
96         public void f1(PolyStruct<Integer, Integer> arg) {}
97 
98         public void f2(PolyStruct<Object, Object> arg) {}
99     }
100 }
101