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 testtools.servicetests;
25 
26 import com.sun.star.uno.UnoRuntime;
27 import complexlib.ComplexTestCase;
28 import util.WaitUnreachable;
29 
30 public abstract class TestBase extends ComplexTestCase {
getTestMethodNames()31     public final String[] getTestMethodNames() {
32         return new String[] { "test" };
33     }
34 
test()35     public final void test() throws Exception {
36         TestServiceFactory factory = getTestServiceFactory();
37         TestService2 t = UnoRuntime.queryInterface(
38             TestService2.class, factory.get());
39         assure(t != null);
40         assure(UnoRuntime.queryInterface(TestService1.class, t) == t);
41         assure(UnoRuntime.queryInterface(XTestService1.class, t) == t);
42         assure(UnoRuntime.queryInterface(XTestService2.class, t) == t);
43         assure(t.fn1() == 1);
44         assure(t.getProp1() == 1);
45         t.setProp1(0);
46         assure(t.getProp1() == 0);
47         assure(t.getProp2() == 2);
48         /*try {
49             t.getProp3Void();
50             failed();
51         } catch (VoidPropertyException e) {
52         }*/
53         assure(t.getProp3Long() == 3);
54         /*try {
55             t.getProp4None();
56             failed();
57         } catch (OptionalPropertyException e) {
58         }*/
59         assure(t.getProp4Long() == 4);
60         /*try {
61             t.getProp5None();
62             failed();
63         } catch (OptionalPropertyException e) {
64         }
65         try {
66             t.getProp5Void();
67             failed();
68         } catch (VoidPropertyException e) {
69         }*/
70         assure(t.getProp5Long() == 5);
71         assure(t.getProp6() == 6);
72         /*t.clearProp6();
73         try {
74             t.getProp6();
75             failed();
76         } catch (VoidPropertyException e) {
77         }*/
78         t.setProp6(0);
79         assure(t.getProp6() == 0);
80         /*try {
81             t.getProp7None();
82             failed();
83         } catch (OptionalPropertyException e) {
84         }
85         try {
86             t.setProp7None(0);
87             failed();
88         } catch (OptionalPropertyException e) {
89         }
90         try {
91             t.clearProp7None();
92             failed();
93         } catch (OptionalPropertyException e) {
94         }*/
95         assure(t.getProp7() == 7);
96         /*t.clearProp7();
97         try {
98             t.getProp7();
99             failed();
100         } catch (VoidPropertyException e) {
101         }*/
102         t.setProp7(0);
103         assure(t.getProp7() == 0);
104         /*try {
105             t.getProp8None();
106             failed();
107         } catch (OptionalPropertyException e) {
108         }
109         try {
110             t.setProp8None(0);
111             failed();
112         } catch (OptionalPropertyException e) {
113         }*/
114         assure(t.getProp8Long() == 8);
115         t.setProp8Long(0);
116         assure(t.getProp8Long() == 0);
117         assure(t.fn2() == 2);
118         XTestService3 t3 = UnoRuntime.queryInterface(XTestService3.class, t);
119         assure(t3 != null);
120         assure(t3.fn3() == 3);
121         XTestService4 t4 = UnoRuntime.queryInterface(XTestService4.class, t);
122         assure(t4 == null);
123         WaitUnreachable u = new WaitUnreachable(t);
124         t = null;
125         WaitUnreachable.ensureFinalization(t3);
126         t3 = null;
127         WaitUnreachable.ensureFinalization(t4);
128         t4 = null;
129         u.waitUnreachable();
130         factory.dispose();
131     }
132 
getTestServiceFactory()133     protected abstract TestServiceFactory getTestServiceFactory()
134         throws Exception;
135 
136     protected interface TestServiceFactory {
get()137         Object get() throws Exception;
138 
dispose()139         void dispose() throws Exception;
140     }
141 }
142