xref: /aoo41x/main/codemaker/test/javamaker/Test.java (revision 6cb2fd03)
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;
25 
26 import com.sun.star.comp.helper.Bootstrap;
27 import com.sun.star.lang.XEventListener;
28 import com.sun.star.uno.Any;
29 import com.sun.star.uno.DeploymentException;
30 import com.sun.star.uno.Type;
31 import com.sun.star.uno.XComponentContext;
32 import com.sun.star.uno.XNamingService;
33 import complexlib.ComplexTestCase;
34 import java.util.EventListener;
35 import test.codemaker.javamaker.Enum1;
36 import test.codemaker.javamaker.Enum2;
37 import test.codemaker.javamaker.PolyStruct;
38 import test.codemaker.javamaker.S2;
39 import test.codemaker.javamaker.Struct2;
40 import test.codemaker.javamaker.services.service_abstract;
41 import test.codemaker.javamaker.services.service_assert;
42 import test.codemaker.javamaker.services.service_break;
43 import test.codemaker.javamaker.services.service_catch;
44 import test.codemaker.javamaker.services.service_class;
45 import test.codemaker.javamaker.services.service_continue;
46 import test.codemaker.javamaker.services.service_do;
47 import test.codemaker.javamaker.services.service_else;
48 import test.codemaker.javamaker.services.service_extends;
49 import test.codemaker.javamaker.services.service_final;
50 import test.codemaker.javamaker.services.service_finally;
51 import test.codemaker.javamaker.services.service_for;
52 import test.codemaker.javamaker.services.service_goto;
53 import test.codemaker.javamaker.services.service_if;
54 import test.codemaker.javamaker.services.service_implements;
55 import test.codemaker.javamaker.services.service_import;
56 import test.codemaker.javamaker.services.service_instanceof;
57 import test.codemaker.javamaker.services.service_int;
58 import test.codemaker.javamaker.services.service_native;
59 import test.codemaker.javamaker.services.service_new;
60 import test.codemaker.javamaker.services.service_package;
61 import test.codemaker.javamaker.services.service_private;
62 import test.codemaker.javamaker.services.service_protected;
63 import test.codemaker.javamaker.services.service_public;
64 import test.codemaker.javamaker.services.service_return;
65 import test.codemaker.javamaker.services.service_static;
66 import test.codemaker.javamaker.services.service_strictfp;
67 import test.codemaker.javamaker.services.service_super;
68 import test.codemaker.javamaker.services.service_synchronized;
69 import test.codemaker.javamaker.services.service_this;
70 import test.codemaker.javamaker.services.service_throw;
71 import test.codemaker.javamaker.services.service_throws;
72 import test.codemaker.javamaker.services.service_try;
73 import test.codemaker.javamaker.services.service_volatile;
74 import test.codemaker.javamaker.services.service_while;
75 import test.codemaker.javamaker.singleton_abstract;
76 
77 public final class Test extends ComplexTestCase {
getTestMethodNames()78     public String[] getTestMethodNames() {
79         return new String[] {
80             "testEnum1", "testEnum2", "testPolyStruct", "testEmptyStruct2",
81             "testFullStruct2", "testXEventListener", "testS1", "testS2",
82             "testKeywordServices", "testSingletons" };
83     }
84 
before()85     public void before() throws Exception {
86         context = Bootstrap.createInitialComponentContext(null);
87     }
88 
testEnum1()89     public void testEnum1() {
90         assure(Enum1.VALUE1.getValue() == -100);
91         assure(Enum1.VALUE2.getValue() == 100);
92         assure(Enum1.VALUE1_value == -100);
93         assure(Enum1.VALUE2_value == 100);
94         assure(Enum1.getDefault() == Enum1.VALUE1);
95         assure(Enum1.fromInt(-101) == null);
96         assure(Enum1.fromInt(-100) == Enum1.VALUE1);
97         assure(Enum1.fromInt(-99) == null);
98         assure(Enum1.fromInt(0) == null);
99         assure(Enum1.fromInt(99) == null);
100         assure(Enum1.fromInt(100) == Enum1.VALUE2);
101         assure(Enum1.fromInt(101) == null);
102     }
103 
testEnum2()104     public void testEnum2() {
105         assure(Enum2.VALUE0.getValue() == 0);
106         assure(Enum2.VALUE1.getValue() == 1);
107         assure(Enum2.VALUE2.getValue() == 2);
108         assure(Enum2.VALUE4.getValue() == 4);
109         assure(Enum2.VALUE0_value == 0);
110         assure(Enum2.VALUE1_value == 1);
111         assure(Enum2.VALUE2_value == 2);
112         assure(Enum2.VALUE4_value == 4);
113         assure(Enum2.getDefault() == Enum2.VALUE0);
114         assure(Enum2.fromInt(-1) == null);
115         assure(Enum2.fromInt(0) == Enum2.VALUE0);
116         assure(Enum2.fromInt(1) == Enum2.VALUE1);
117         assure(Enum2.fromInt(2) == Enum2.VALUE2);
118         assure(Enum2.fromInt(3) == null);
119         assure(Enum2.fromInt(4) == Enum2.VALUE4);
120         assure(Enum2.fromInt(5) == null);
121     }
122 
testPolyStruct()123     public void testPolyStruct() {
124         PolyStruct s = new PolyStruct();
125         assure(s.member1 == null);
126         assure(s.member2 == 0);
127         s = new PolyStruct("ABC", 5);
128         assure(s.member1.equals("ABC"));
129         assure(s.member2 == 5);
130     }
131 
testEmptyStruct2()132     public void testEmptyStruct2() {
133         Struct2 s = new Struct2();
134         assure(s.p1 == false);
135         assure(s.p2 == 0);
136         assure(s.p3 == 0);
137         assure(s.p4 == 0);
138         assure(s.p5 == 0);
139         assure(s.p6 == 0);
140         assure(s.p7 == 0L);
141         assure(s.p8 == 0L);
142         assure(s.p9 == 0.0f);
143         assure(s.p10 == 0.0);
144         assure(s.p11 == '\u0000');
145         assure(s.p12.equals(""));
146         assure(s.p13.equals(Type.VOID));
147         assure(s.p14.equals(Any.VOID));
148         assure(s.p15 == Enum2.VALUE0);
149         assure(s.p16.member1 == 0);
150         assure(s.p17 == null);
151         assure(s.p18 == null);
152         assure(s.t1 == false);
153         assure(s.t2 == 0);
154         assure(s.t3 == 0);
155         assure(s.t4 == 0);
156         assure(s.t5 == 0);
157         assure(s.t6 == 0);
158         assure(s.t7 == 0L);
159         assure(s.t8 == 0L);
160         assure(s.t9 == 0.0f);
161         assure(s.t10 == 0.0);
162         assure(s.t11 == '\u0000');
163         assure(s.t12.equals(""));
164         assure(s.t13.equals(Type.VOID));
165         assure(s.t14.equals(Any.VOID));
166         assure(s.t15 == Enum2.VALUE0);
167         assure(s.t16.member1 == 0);
168         assure(s.t17 == null);
169         assure(s.t18 == null);
170         assure(s.a1.length == 0);
171         assure(s.a2.length == 0);
172         assure(s.a3.length == 0);
173         assure(s.a4.length == 0);
174         assure(s.a5.length == 0);
175         assure(s.a6.length == 0);
176         assure(s.a7.length == 0);
177         assure(s.a8.length == 0);
178         assure(s.a9.length == 0);
179         assure(s.a10.length == 0);
180         assure(s.a11.length == 0);
181         assure(s.a12.length == 0);
182         assure(s.a13.length == 0);
183         assure(s.a14.length == 0);
184         assure(s.a15.length == 0);
185         assure(s.a16.length == 0);
186         assure(s.a17.length == 0);
187         assure(s.a18.length == 0);
188         assure(s.aa1.length == 0);
189         assure(s.aa2.length == 0);
190         assure(s.aa3.length == 0);
191         assure(s.aa4.length == 0);
192         assure(s.aa5.length == 0);
193         assure(s.aa6.length == 0);
194         assure(s.aa7.length == 0);
195         assure(s.aa8.length == 0);
196         assure(s.aa9.length == 0);
197         assure(s.aa10.length == 0);
198         assure(s.aa11.length == 0);
199         assure(s.aa12.length == 0);
200         assure(s.aa13.length == 0);
201         assure(s.aa14.length == 0);
202         assure(s.aa15.length == 0);
203         assure(s.aa16.length == 0);
204         assure(s.aa17.length == 0);
205         assure(s.aa18.length == 0);
206         assure(s.at1.length == 0);
207         assure(s.at2.length == 0);
208         assure(s.at3.length == 0);
209         assure(s.at4.length == 0);
210         assure(s.at5.length == 0);
211         assure(s.at6.length == 0);
212         assure(s.at7.length == 0);
213         assure(s.at8.length == 0);
214         assure(s.at9.length == 0);
215         assure(s.at10.length == 0);
216         assure(s.at11.length == 0);
217         assure(s.at12.length == 0);
218         assure(s.at13.length == 0);
219         assure(s.at14.length == 0);
220         assure(s.at15.length == 0);
221         assure(s.at16.length == 0);
222         assure(s.at17.length == 0);
223         assure(s.at18.length == 0);
224     }
225 
testFullStruct2()226     public void testFullStruct2() {
227         //TODO:
228         Struct2 s = new Struct2(
229             true, (byte) 1, (short) 2, (short) 3, 4, 5, 6L, 7L, 0.8f, 0.9, 'A',
230             "BCD", Type.UNSIGNED_HYPER, new Integer(22), Enum2.VALUE4,
231             new Struct1(1), null, null, false, (byte) 0, (short) 0, (short) 0,
232             0, 0, 0L, 0L, 0.0f, 0.0, '\u0000', "", Type.VOID, Any.VOID,
233             Enum2.VALUE0, new Struct1(), null, null,
234             new boolean[] { false, true }, new byte[] { (byte) 1, (byte) 2 },
235             new short[0], new short[0], new int[0], new int[0],
236             new long[0], new long[0], new float[0], new double[0], new char[0],
237             new String[0], new Type[0], new Object[0], new Enum2[0],
238             new Struct1[] { new Struct1(1), new Struct1(2) }, new Object[0],
239             new XNamingService[0], new boolean[0][], new byte[0][],
240             new short[0][], new short[0][], new int[0][], new int[0][],
241             new long[0][], new long[0][], new float[0][], new double[0][],
242             new char[0][], new String[0][], new Type[0][], new Object[0][],
243             new Enum2[0][], new Struct1[0][], new Object[0][],
244             new XNamingService[0][], new boolean[0][], new byte[0][],
245             new short[0][], new short[0][], new int[0][], new int[0][],
246             new long[0][], new long[0][], new float[0][], new double[0][],
247             new char[0][], new String[0][], new Type[0][], new Object[0][],
248             new Enum2[0][], new Struct1[0][], new Object[0][],
249             new XNamingService[0][]);
250         assure(s.p1 == true);
251         assure(s.p2 == 1);
252         assure(s.p3 == 2);
253         assure(s.p4 == 3);
254         assure(s.p5 == 4);
255         assure(s.p6 == 5);
256         assure(s.p7 == 6L);
257         assure(s.p8 == 7L);
258         assure(s.p9 == 0.8f);
259         assure(s.p10 == 0.9);
260         assure(s.p11 == 'A');
261         assure(s.p12.equals("BCD"));
262         assure(s.p13.equals(Type.UNSIGNED_HYPER));
263         assure(s.p14.equals(new Integer(22)));
264         assure(s.p15 == Enum2.VALUE4);
265         assure(s.p16.member1 == 1);
266         assure(s.p17 == null);
267         assure(s.p18 == null);
268         assure(s.t1 == false);
269         assure(s.t2 == 0);
270         assure(s.t3 == 0);
271         assure(s.t4 == 0);
272         assure(s.t5 == 0);
273         assure(s.t6 == 0);
274         assure(s.t7 == 0L);
275         assure(s.t8 == 0L);
276         assure(s.t9 == 0.0f);
277         assure(s.t10 == 0.0);
278         assure(s.t11 == '\u0000');
279         assure(s.t12.equals(""));
280         assure(s.t13.equals(Type.VOID));
281         assure(s.t14.equals(Any.VOID));
282         assure(s.t15 == Enum2.VALUE0);
283         assure(s.t16.member1 == 0);
284         assure(s.t17 == null);
285         assure(s.t18 == null);
286         assure(s.a1.length == 2);
287         assure(s.a1[0] == false);
288         assure(s.a1[1] == true);
289         assure(s.a2.length == 2);
290         assure(s.a2[0] == 1);
291         assure(s.a2[1] == 2);
292         assure(s.a3.length == 0);
293         assure(s.a4.length == 0);
294         assure(s.a5.length == 0);
295         assure(s.a6.length == 0);
296         assure(s.a7.length == 0);
297         assure(s.a8.length == 0);
298         assure(s.a9.length == 0);
299         assure(s.a10.length == 0);
300         assure(s.a11.length == 0);
301         assure(s.a12.length == 0);
302         assure(s.a13.length == 0);
303         assure(s.a14.length == 0);
304         assure(s.a15.length == 0);
305         assure(s.a16.length == 2);
306         assure(s.a16[0].member1 == 1);
307         assure(s.a16[1].member1 == 2);
308         assure(s.a17.length == 0);
309         assure(s.a18.length == 0);
310         assure(s.aa1.length == 0);
311         assure(s.aa2.length == 0);
312         assure(s.aa3.length == 0);
313         assure(s.aa4.length == 0);
314         assure(s.aa5.length == 0);
315         assure(s.aa6.length == 0);
316         assure(s.aa7.length == 0);
317         assure(s.aa8.length == 0);
318         assure(s.aa9.length == 0);
319         assure(s.aa10.length == 0);
320         assure(s.aa11.length == 0);
321         assure(s.aa12.length == 0);
322         assure(s.aa13.length == 0);
323         assure(s.aa14.length == 0);
324         assure(s.aa15.length == 0);
325         assure(s.aa16.length == 0);
326         assure(s.aa17.length == 0);
327         assure(s.aa18.length == 0);
328         assure(s.at1.length == 0);
329         assure(s.at2.length == 0);
330         assure(s.at3.length == 0);
331         assure(s.at4.length == 0);
332         assure(s.at5.length == 0);
333         assure(s.at6.length == 0);
334         assure(s.at7.length == 0);
335         assure(s.at8.length == 0);
336         assure(s.at9.length == 0);
337         assure(s.at10.length == 0);
338         assure(s.at11.length == 0);
339         assure(s.at12.length == 0);
340         assure(s.at13.length == 0);
341         assure(s.at14.length == 0);
342         assure(s.at15.length == 0);
343         assure(s.at16.length == 0);
344         assure(s.at17.length == 0);
345         assure(s.at18.length == 0);
346     }
347 
testXEventListener()348     public void testXEventListener() {
349         assure(EventListener.class.isAssignableFrom(XEventListener.class));
350     }
351 
testS1()352     public void testS1() throws com.sun.star.uno.Exception {
353         //TODO:
354         try {
355             S1.create1(context);
356             failed("S1.create1");
357         } catch (DeploymentException e) {}
358         try {
359             S1.create2(context, new Any[0]);
360             failed("S1.create2");
361         } catch (com.sun.star.uno.Exception e) {}
362         try {
363             S1.create3(context, new Any[0]);
364             failed("S1.create3");
365         } catch (DeploymentException e) {}
366         try {
367             S1.create4(context, 0, 0, 0);
368             failed("S1.create4");
369         } catch (DeploymentException e) {}
370         try {
371             S1.create5(
372                 context, false, (byte) 0, (short) 0, (short) 0, 0, 0, 0L, 0L,
373                 0.0f, 0.0, '\u0000', "", Type.VOID, Any.VOID, Enum2.VALUE0,
374                 new Struct1(), null, null, false, (byte) 0, (short) 0,
375                 (short) 0, 0, 0, 0L, 0L, 0.0f, 0.0, '\u0000', "", Type.VOID,
376                 Any.VOID, Enum2.VALUE0, new Struct1(), null, null,
377                 new boolean[0], new byte[0], new short[0], new short[0],
378                 new int[0], new int[0], new long[0], new long[0], new float[0],
379                 new double[0], new char[0], new String[0], new Type[0],
380                 new Object[0], new Enum2[0], new Struct1[0], new Object[0],
381                 new XNamingService[0], new boolean[0][], new byte[0][],
382                 new short[0][], new short[0][], new int[0][], new int[0][],
383                 new long[0][], new long[0][], new float[0][], new double[0][],
384                 new char[0][], new String[0][], new Type[0][], new Object[0][],
385                 new Enum2[0][], new Struct1[0][], new Object[0][],
386                 new XNamingService[0][], new boolean[0][], new byte[0][],
387                 new short[0][], new short[0][], new int[0][], new int[0][],
388                 new long[0][], new long[0][], new float[0][], new double[0][],
389                 new char[0][], new String[0][], new Type[0][], new Object[0][],
390                 new Enum2[0][], new Struct1[0][], new Object[0][],
391                 new XNamingService[0][]);
392             failed("S1.create4");
393         } catch (DeploymentException e) {}
394     }
395 
testS2()396     public void testS2() {
397         //TODO
398     }
399 
testKeywordServices()400     public void testKeywordServices() {
401         try {
402             service_abstract.method_abstract(context, 0);
403             failed("service_abstract.method_abstract");
404         } catch (DeploymentException e) {}
405         try {
406             service_assert.method_assert(context, 0);
407             failed("service_assert.method_assert");
408         } catch (DeploymentException e) {}
409         try {
410             service_break.method_break(context, 0);
411             failed("service_break.method_break");
412         } catch (DeploymentException e) {}
413         try {
414             service_catch.method_catch(context, 0);
415             failed("service_catch.method_catch");
416         } catch (DeploymentException e) {}
417         try {
418             service_class.method_class(context, 0);
419             failed("service_class.method_class");
420         } catch (DeploymentException e) {}
421         try {
422             service_continue.method_continue(context, 0);
423             failed("service_continue.method_continue");
424         } catch (DeploymentException e) {}
425         try {
426             service_do.method_do(context, 0);
427             failed("service_do.method_do");
428         } catch (DeploymentException e) {}
429         try {
430             service_else.method_else(context, 0);
431             failed("service_else.method_else");
432         } catch (DeploymentException e) {}
433         try {
434             service_extends.method_extends(context, 0);
435             failed("service_extends.method_extends");
436         } catch (DeploymentException e) {}
437         try {
438             service_final.method_final(context, 0);
439             failed("service_final.method_final");
440         } catch (DeploymentException e) {}
441         try {
442             service_finally.method_finally(context, 0);
443             failed("service_finally.method_finally");
444         } catch (DeploymentException e) {}
445         try {
446             service_for.method_for(context, 0);
447             failed("service_for.method_for");
448         } catch (DeploymentException e) {}
449         try {
450             service_goto.method_goto(context, 0);
451             failed("service_goto.method_goto");
452         } catch (DeploymentException e) {}
453         try {
454             service_if.method_if(context, 0);
455             failed("service_if.method_if");
456         } catch (DeploymentException e) {}
457         try {
458             service_implements.method_implements(context, 0);
459             failed("service_implements.method_implements");
460         } catch (DeploymentException e) {}
461         try {
462             service_import.method_import(context, 0);
463             failed("service_import.method_import");
464         } catch (DeploymentException e) {}
465         try {
466             service_instanceof.method_instanceof(context, 0);
467             failed("service_instanceof.method_instanceof");
468         } catch (DeploymentException e) {}
469         try {
470             service_int.method_int(context, 0);
471             failed("service_int.method_int");
472         } catch (DeploymentException e) {}
473         try {
474             service_native.method_native(context, 0);
475             failed("service_native.method_native");
476         } catch (DeploymentException e) {}
477         try {
478             service_new.method_new(context, 0);
479             failed("service_new.method_new");
480         } catch (DeploymentException e) {}
481         try {
482             service_package.method_package(context, 0);
483             failed("service_package.method_package");
484         } catch (DeploymentException e) {}
485         try {
486             service_private.method_private(context, 0);
487             failed("service_private.method_private");
488         } catch (DeploymentException e) {}
489         try {
490             service_protected.method_protected(context, 0);
491             failed("service_protected.method_protected");
492         } catch (DeploymentException e) {}
493         try {
494             service_public.method_public(context, 0);
495             failed("service_public.method_public");
496         } catch (DeploymentException e) {}
497         try {
498             service_return.method_return(context, 0);
499             failed("service_return.method_return");
500         } catch (DeploymentException e) {}
501         try {
502             service_static.method_static(context, 0);
503             failed("service_static.method_static");
504         } catch (DeploymentException e) {}
505         try {
506             service_strictfp.method_strictfp(context, 0);
507             failed("service_strictfp.method_strictfp");
508         } catch (DeploymentException e) {}
509         try {
510             service_super.method_super(context, 0);
511             failed("service_super.method_super");
512         } catch (DeploymentException e) {}
513         try {
514             service_synchronized.method_synchronized(context, 0);
515             failed("service_synchronized.method_synchronized");
516         } catch (DeploymentException e) {}
517         try {
518             service_this.method_this(context, 0);
519             failed("service_this.method_this");
520         } catch (DeploymentException e) {}
521         try {
522             service_throw.method_throw(context, 0);
523             failed("service_throw.method_throw");
524         } catch (DeploymentException e) {}
525         try {
526             service_throws.method_throws(context, 0);
527             failed("service_throws.method_throws");
528         } catch (DeploymentException e) {}
529         try {
530             service_try.method_try(context, 0);
531             failed("service_try.method_try");
532         } catch (DeploymentException e) {}
533         try {
534             service_volatile.method_volatile(context, 0);
535             failed("service_volatile.method_volatile");
536         } catch (DeploymentException e) {}
537         try {
538             service_while.method_while(context, 0);
539             failed("service_while.method_while");
540         } catch (DeploymentException e) {}
541     }
542 
testSingletons()543     public void testSingletons() {
544         try {
545             S4.get(context);
546             failed("S4");
547         } catch (DeploymentException e) {}
548         try {
549             singleton_abstract.get(context);
550             failed("singleton_abstract");
551         } catch (DeploymentException e) {}
552     }
553 
554     private XComponentContext context;
555 }
556