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