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