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 com.sun.star.lib.uno.helper; 25 26 import com.sun.star.uno.XInterface; 27 import java.util.Iterator; 28 import java.util.ListIterator; 29 import com.sun.star.uno.Type; 30 import com.sun.star.uno.XWeak; 31 import com.sun.star.lang.XTypeProvider; 32 import com.sun.star.lang.XEventListener; 33 import java.util.ArrayList; 34 import com.sun.star.lang.XMultiComponentFactory; 35 import com.sun.star.uno.XComponentContext; 36 import com.sun.star.comp.helper.Bootstrap; 37 import com.sun.star.bridge.XUnoUrlResolver; 38 import com.sun.star.uno.UnoRuntime; 39 import com.sun.star.lang.XMultiServiceFactory; 40 import com.sun.star.lang.XSingleServiceFactory; 41 import com.sun.star.uno.IQueryInterface; 42 //import com.sun.star.lib.uno.environments.java.IRequester; 43 import com.sun.star.bridge.XBridge; 44 //import com.sun.star.lib.uno.environments.java.Proxy; 45 import com.sun.star.lib.uno.environments.java.java_environment; 46 import com.sun.star.lib.uno.typedesc.TypeDescription; 47 import java.util.HashMap; 48 import java.util.List; 49 import java.util.NoSuchElementException; 50 51 public class InterfaceContainer_Test 52 { 53 java_environment env= new java_environment(null); 54 /** Creates a new instance of InterfaceContainerTest */ 55 AWeakBase obj1,obj2,obj3,obj4; 56 Object proxyObj1Weak1; 57 Object proxyObj3Weak1; 58 Object proxyObj3Weak2; 59 Object proxyObj3TypeProv; 60 Object proxyObj2TypeProv; 61 //contains original objects 62 List list1; 63 //contains original objects + proxies 64 List list2; 65 //contains original object + proxies + null value 66 List list3; 67 InterfaceContainer_Test()68 public InterfaceContainer_Test() 69 { 70 obj1= new AWeakBase(); 71 obj2= new AWeakBase(); 72 obj3= new AWeakBase(); 73 obj4= new AWeakBase(); 74 proxyObj1Weak1= ProxyProvider.createProxy(obj1, XWeak.class); 75 proxyObj3Weak1= ProxyProvider.createProxy(obj3, XWeak.class); 76 proxyObj3Weak2= ProxyProvider.createProxy(obj3, XWeak.class); 77 proxyObj2TypeProv= ProxyProvider.createProxy(obj2, XTypeProvider.class); 78 proxyObj3TypeProv= ProxyProvider.createProxy(obj3, XTypeProvider.class); 79 80 list1= new ArrayList(); 81 list1.add(obj1); 82 list1.add(obj2); 83 list1.add(obj3); 84 list2= new ArrayList(); 85 list2.add(obj1); 86 list2.add(proxyObj2TypeProv); 87 list2.add(proxyObj3TypeProv); 88 list3= new ArrayList(); 89 list3.add(obj1); 90 list3.add(null); 91 list3.add(proxyObj2TypeProv); 92 list3.add(proxyObj3Weak1); 93 } 94 95 /** Tests add(object), size(), clear(); 96 */ add()97 public boolean add() 98 { 99 System.out.println("Testing List.add(Object), List.size(), List.clear(), List.isEmpty()"); 100 InterfaceContainer cont= new InterfaceContainer(); 101 boolean r[]= new boolean[50]; 102 int i= 0; 103 104 r[i++]= cont.size() == 0; 105 r[i++]= cont.add(obj1); 106 r[i++]= cont.size() == 1; 107 r[i++]= cont.add(obj1); // add the same object again 108 r[i++]= cont.size() == 2; 109 r[i++]= cont.add(proxyObj3TypeProv); 110 r[i++]= cont.size() == 3; 111 r[i++]= cont.isEmpty() ? false: true; 112 cont.clear(); 113 r[i++]= cont.size() == 0; 114 r[i++]= cont.isEmpty(); 115 116 boolean bOk= true; 117 for (int c= 0; c < i; c++) 118 bOk= bOk && r[c]; 119 if (bOk == false) 120 System.out.println("Failed"); 121 else 122 System.out.println("Ok"); 123 return bOk; 124 } 125 126 /**Tests list.addAll(Collection c), list.addAll(int index, Collection c) 127 */ listConstructors()128 public boolean listConstructors() 129 { 130 System.out.println("Testing Constructors of InterfaceContainer"); 131 boolean r[]= new boolean[50]; 132 int i= 0; 133 InterfaceContainer cont= new InterfaceContainer(100); 134 135 r[i++]= cont.elementData.length == 100; 136 boolean bOk= true; 137 for (int c= 0; c < i; c++) 138 bOk= bOk && r[c]; 139 if (bOk == false) 140 System.out.println("Failed"); 141 else 142 System.out.println("Ok"); 143 return bOk; 144 } trimToSize()145 public boolean trimToSize() 146 { 147 System.out.println("Testing InterfaceContainer.trimToSize"); 148 InterfaceContainer cont= new InterfaceContainer(100); 149 boolean r[]= new boolean[50]; 150 int i= 0; 151 cont.trimToSize(); 152 r[i++]= cont.isEmpty(); 153 cont= new InterfaceContainer(10); 154 cont.addAll(list1); 155 cont.trimToSize(); 156 r[i++]= cont.elementData.length == list1.size(); 157 boolean bOk= true; 158 for (int c= 0; c < i; c++) 159 bOk= bOk && r[c]; 160 if (bOk == false) 161 System.out.println("Failed"); 162 else 163 System.out.println("Ok"); 164 return bOk; 165 } ensureCapacity()166 public boolean ensureCapacity() 167 { 168 System.out.println("Testing InterfaceContainer.ensureCapacity"); 169 InterfaceContainer cont= new InterfaceContainer(10); 170 boolean r[]= new boolean[50]; 171 int i= 0; 172 173 cont.ensureCapacity(9); 174 r[i++]= cont.elementData.length >= 9; 175 cont.ensureCapacity(11); 176 r[i++]= cont.elementData.length >= 11; 177 boolean bOk= true; 178 for (int c= 0; c < i; c++) 179 bOk= bOk && r[c]; 180 if (bOk == false) 181 System.out.println("Failed"); 182 else 183 System.out.println("Ok"); 184 return bOk; 185 } 186 addAll()187 public boolean addAll() 188 { 189 System.out.println("Testing List.addAll(Collection c), List.addAll(int index, Collection c)"); 190 InterfaceContainer cont= new InterfaceContainer(); 191 boolean r[]= new boolean[50]; 192 int i= 0; 193 194 r[i++]= cont.addAll(list1); 195 r[i++]= cont.size() == list1.size(); 196 for (int c= 0; c < cont.size(); c++) 197 { 198 r[i++]= list1.get(c) == cont.get(c); 199 } 200 cont.add(obj1); 201 r[i++]= cont.addAll(1, list2); 202 r[i++]= cont.get(0) == list1.get(0); 203 r[i++]= cont.get(1) == list2.get(0); 204 r[i++]= cont.get(2) == list2.get(1); 205 r[i++]= cont.get(3) == list2.get(2); 206 r[i++]= cont.get(4) == list1.get(1); 207 r[i++]= cont.get(5) == list1.get(2); 208 r[i++]= cont.get(6) == obj1; 209 cont.clear(); 210 cont.addAll(list3); 211 // the null element in list3 at index 1 is not added to cont 212 r[i++]= cont.get(0) == list3.get(0); 213 r[i++]= cont.get(1) == list3.get(2); 214 r[i++]= cont.get(2) == list3.get(3); 215 216 boolean bOk= true; 217 for (int c= 0; c < i; c++) 218 bOk= bOk && r[c]; 219 if (bOk == false) 220 System.out.println("Failed"); 221 else 222 System.out.println("Ok"); 223 return bOk; 224 } 225 226 /** Tests List.add(int index, Object element), List.get(int index) 227 */ get()228 public boolean get() 229 { 230 System.out.println("Testing List.add(int index, Object element), List.get(int index)"); 231 InterfaceContainer cont= new InterfaceContainer(); 232 boolean r[]= new boolean[50]; 233 int i= 0; 234 235 cont.add(0, obj1); 236 cont.add(1, obj2); 237 cont.add(1, proxyObj3Weak1); 238 cont.add(3, obj3); 239 r[i++]= cont.get(0) == obj1; 240 r[i++]= cont.get(1) == proxyObj3Weak1; 241 r[i++]= cont.get(2) == obj2; 242 r[i++]= cont.get(3) == obj3; 243 try 244 { 245 cont.add(5, obj1); 246 }catch( java.lang.Exception e) 247 { 248 r[i++]= true; 249 } 250 251 boolean bOk= true; 252 for (int c= 0; c < i; c++) 253 bOk= bOk && r[c]; 254 if (bOk == false) 255 System.out.println("Failed"); 256 else 257 System.out.println("Ok"); 258 return bOk; 259 } 260 /** Tests List.contains 261 */ contains()262 public boolean contains() 263 { 264 System.out.println("Testing List.contains()"); 265 InterfaceContainer cont= new InterfaceContainer(); 266 boolean r[]= new boolean[50]; 267 int i= 0; 268 269 r[i++]= cont.contains(obj1) ? false : true; // nothing in the list 270 cont.add(obj1); 271 cont.add(proxyObj2TypeProv); 272 cont.add(proxyObj3TypeProv); 273 r[i++]= cont.contains(obj1); 274 r[i++]= cont.contains(obj2); 275 r[i++]= cont.contains(proxyObj3Weak1); 276 r[i++]= cont.contains(proxyObj3Weak2); 277 r[i++]= cont.contains(proxyObj1Weak1); 278 r[i++]= cont.contains(obj3); 279 r[i++]= cont.contains(null) ? false : true; 280 281 boolean bOk= true; 282 for (int c= 0; c < i; c++) 283 bOk= bOk && r[c]; 284 if ( ! bOk ) 285 System.out.println("Failed"); 286 else 287 System.out.println("Ok"); 288 return bOk; 289 } 290 /** Tests List.containsAll 291 */ containsAll()292 public boolean containsAll() 293 { 294 System.out.println("Testing List.containsAll"); 295 InterfaceContainer cont= new InterfaceContainer(); 296 boolean r[]= new boolean[50]; 297 int i= 0; 298 cont.addAll(list1); 299 r[i++]= cont.containsAll(list1); 300 cont.clear(); 301 cont.addAll(list2); 302 r[i++]= cont.containsAll(list2); 303 cont.clear(); 304 cont.addAll(list3); // the null element in list3 is not added to cont 305 r[i++]= cont.containsAll(list3) ? false : true; 306 cont.clear(); 307 for( int x= 0; x < 6; x++) 308 cont.add(obj4); 309 r[i++]= cont.contains(list1) ? false : true; 310 cont.add(1, list1.get(0)); 311 cont.add(3, list1.get(1)); 312 cont.add(5, list1.get(2)); 313 r[i++]= cont.contains(list1) ? false : true; 314 315 boolean bOk= true; 316 for (int c= 0; c < i; c++) 317 bOk= bOk && r[c]; 318 if ( ! bOk ) 319 System.out.println("Failed"); 320 else 321 System.out.println("Ok"); 322 return bOk; 323 } 324 /** Tests List.indexOf, List.lastIndexOf 325 */ indexOf()326 public boolean indexOf() 327 { 328 System.out.println("Testing List.indexOf(Object element), List.lastIndexOf(Object element)"); 329 InterfaceContainer cont= new InterfaceContainer(); 330 boolean r[]= new boolean[50]; 331 int i= 0; 332 cont.addAll(list1); 333 cont.addAll(list1); 334 r[i++]= cont.indexOf(obj3) == 2; 335 r[i++]= cont.lastIndexOf(obj3) == 5; 336 cont.clear(); 337 cont.addAll(list2); 338 cont.addAll(list2); 339 r[i++]= cont.indexOf(proxyObj3Weak1) == 2; 340 r[i++]= cont.lastIndexOf(proxyObj3Weak2) == 5; 341 342 boolean bOk= true; 343 for (int c= 0; c < i; c++) 344 bOk= bOk && r[c]; 345 if ( ! bOk ) 346 System.out.println("Failed"); 347 else 348 System.out.println("Ok"); 349 return bOk; 350 } 351 352 /** Tests List.remove(int index), List.remove(Object element), List.removeAll(Collection c) 353 */ remove()354 public boolean remove() 355 { 356 System.out.println("Testing List.remove(int index), List.remove(Object element), List.removeAll(Collection c)"); 357 InterfaceContainer cont= new InterfaceContainer(); 358 boolean r[]= new boolean[50]; 359 int i= 0; 360 361 cont.addAll(list2); 362 r[i++]= proxyObj2TypeProv.equals(cont.remove(1)); 363 r[i++]= cont.size() == 2; 364 cont.clear(); 365 cont.addAll(list2); 366 r[i++]= cont.remove(obj1); 367 r[i++]= cont.remove(proxyObj2TypeProv); 368 r[i++]= cont.remove(proxyObj3Weak2); 369 r[i++]= cont.isEmpty(); 370 cont.clear(); 371 cont.addAll(list3); 372 r[i++]= cont.removeAll(list3); 373 r[i++]= cont.isEmpty(); 374 cont.addAll(list2); 375 376 List list= new ArrayList(); 377 list.add(list2.get(0)); 378 list.add(list2.get(1)); 379 list.add(proxyObj3Weak2); 380 r[i++]= cont.removeAll(list); 381 r[i++]= cont.isEmpty(); 382 383 boolean bOk= true; 384 for (int c= 0; c < i; c++) 385 bOk= bOk && r[c]; 386 if ( ! bOk ) 387 System.out.println("Failed"); 388 else 389 System.out.println("Ok"); 390 return bOk; 391 } 392 393 /** Tests List.retainAll 394 */ retainAll()395 public boolean retainAll() 396 { 397 System.out.println("Testing List.retainAll(Collection c)"); 398 InterfaceContainer cont= new InterfaceContainer(); 399 boolean r[]= new boolean[50]; 400 int i= 0; 401 402 cont.addAll(list1); //obj1, obj2, obj3 403 cont.addAll(list2); //obj1, proxyObj2TypeProv, proxyObj3TypeProv 404 List list = new ArrayList(); 405 list.add(obj1); 406 list.add(proxyObj3Weak1); 407 408 r[i++]= cont.retainAll(list); 409 r[i++]= cont.get(0) == obj1; 410 r[i++]= cont.get(1) == obj3; 411 r[i++]= cont.get(2) == obj1; 412 r[i++]= cont.get(3) == proxyObj3TypeProv; 413 r[i++]= 4 == cont.size(); 414 415 boolean bOk= true; 416 for (int c= 0; c < i; c++) 417 bOk= bOk && r[c]; 418 if ( ! bOk ) 419 System.out.println("Failed"); 420 else 421 System.out.println("Ok"); 422 return bOk; 423 } 424 425 /** Tests List.set(int index, Object element) 426 **/ set()427 public boolean set() 428 { 429 System.out.println("Testing List.set(int index, Object element)"); 430 boolean r[]= new boolean[50]; 431 int i= 0; 432 InterfaceContainer cont= new InterfaceContainer(); 433 cont.addAll(list2); 434 Object o1= cont.set(0, obj3); 435 Object o2= cont.set(2, proxyObj3Weak1); 436 r[i++]= o1 == list2.get(0); 437 r[i++]= o2 == list2.get(2); 438 r[i++]= cont.get(0) == obj3; 439 r[i++]= cont.get(2) == proxyObj3Weak1; 440 441 boolean bOk= true; 442 for (int c= 0; c < i; c++) 443 bOk= bOk && r[c]; 444 if ( ! bOk ) 445 System.out.println("Failed"); 446 else 447 System.out.println("Ok"); 448 return bOk; 449 } 450 451 /** Tests List.toArray(), List.toArray(Object[] a) 452 */ toArray()453 public boolean toArray() 454 { 455 System.out.println("Testing List.toArray(), List.toArray(Object[] a)"); 456 InterfaceContainer cont= new InterfaceContainer(); 457 boolean r[]= new boolean[50]; 458 int i= 0; 459 460 cont.addAll(list1); 461 Object[] ar= cont.toArray(); 462 Object[] arOrig= list1.toArray(); 463 r[i++]= ar.length == arOrig.length; 464 465 r[i]= true; 466 for (int c= 0; c < ar.length; c++) 467 r[i]= r[i] && ar[c] == arOrig[c]; 468 469 i++; 470 XWeak[] arWeak= new XWeak[3]; 471 XWeak[] arWeak2= (XWeak[])cont.toArray(arWeak); 472 r[i++]= ar.length == arWeak2.length; 473 r[i]= true; 474 for (int c= 0; c < ar.length; c++) 475 r[i]= r[i] && ar[c] == arWeak2[c]; 476 477 i++; 478 479 boolean bOk= true; 480 for (int c= 0; c < i; c++) 481 bOk= bOk && r[c]; 482 if ( ! bOk ) 483 System.out.println("Failed"); 484 else 485 System.out.println("Ok"); 486 return bOk; 487 } 488 Iterator_next()489 public boolean Iterator_next() 490 { 491 System.out.println("Testing InterfaceContainer.iterator, Iterator.next()"); 492 InterfaceContainer cont= new InterfaceContainer(); 493 boolean r[]= new boolean[50]; 494 int i= 0; 495 496 cont.addAll(list1); 497 Iterator it= cont.iterator(); 498 r[i++]= it.next() == list1.get(0); 499 r[i++]= it.next() == list1.get(1); 500 r[i++]= it.next() == list1.get(2); 501 try 502 { 503 it.next(); 504 }catch(java.util.NoSuchElementException ne) 505 { 506 r[i++]= true; 507 }catch(Exception e) 508 { 509 r[i++]= false; 510 } 511 512 boolean bOk= true; 513 for (int c= 0; c < i; c++) 514 bOk= bOk && r[c]; 515 if ( ! bOk ) 516 System.out.println("Failed"); 517 else 518 System.out.println("Ok"); 519 return bOk; 520 } 521 Iterator_hasNext()522 public boolean Iterator_hasNext() 523 { 524 System.out.println("Testing, Iterator.next()"); 525 InterfaceContainer cont= new InterfaceContainer(); 526 boolean r[]= new boolean[50]; 527 int i= 0; 528 529 Iterator it= cont.iterator(); 530 r[i++]= ! it.hasNext(); 531 cont.addAll(list1); 532 it= cont.iterator(); 533 r[i++]= it.hasNext(); 534 it.next(); 535 r[i++]= it.hasNext(); 536 it.next(); 537 r[i++]= it.hasNext(); 538 it.next(); 539 r[i++]= ! it.hasNext(); 540 541 boolean bOk= true; 542 for (int c= 0; c < i; c++) 543 bOk= bOk && r[c]; 544 if ( ! bOk ) 545 System.out.println("Failed"); 546 else 547 System.out.println("Ok"); 548 return bOk; 549 } 550 Iterator_remove()551 public boolean Iterator_remove() 552 { 553 System.out.println("Testing, Iterator.remove()"); 554 InterfaceContainer cont= new InterfaceContainer(); 555 boolean r[]= new boolean[50]; 556 int i= 0; 557 558 Iterator it= cont.iterator(); 559 try 560 { 561 it.remove(); 562 } 563 catch( IllegalStateException ie) 564 { 565 r[i++]= true; 566 } 567 catch(java.lang.Exception e) 568 { 569 r[i++]= false; 570 } 571 cont.add(obj1); 572 it= cont.iterator(); 573 it.next(); 574 it.remove(); 575 r[i++]= cont.isEmpty(); 576 try 577 { 578 it.remove(); 579 } 580 catch (IllegalStateException ie) 581 { 582 r[i++]= true; 583 } 584 catch (Exception e) 585 { 586 r[i++]= false; 587 } 588 cont.clear(); 589 cont.addAll(list1); 590 it= cont.iterator(); 591 while (it.hasNext()) 592 { 593 it.next(); 594 it.remove(); 595 } 596 r[i++]= cont.isEmpty(); 597 598 // 2 iterators, remove must not impair the other iterator 599 cont.clear(); 600 cont.addAll(list1); 601 int size= cont.size(); 602 it= cont.iterator(); 603 Iterator it2= cont.iterator(); 604 while (it.hasNext()) 605 { 606 it.next(); 607 it.remove(); 608 } 609 try 610 { 611 for( int c= 0; c < size; c++) 612 it2.next(); 613 r[i++]= true; 614 } 615 catch(Exception e) 616 { 617 r[i++]= false; 618 } 619 r[i++]= cont.size() == 0; 620 621 boolean bOk= true; 622 for (int c= 0; c < i; c++) 623 bOk= bOk && r[c]; 624 if ( ! bOk ) 625 System.out.println("Failed"); 626 else 627 System.out.println("Ok"); 628 return bOk; 629 } ListIterator_next()630 public boolean ListIterator_next() 631 { 632 System.out.println("Testing InterfaceContainer.listIerator, ListIterator.next()"); 633 InterfaceContainer cont= new InterfaceContainer(); 634 boolean r[]= new boolean[50]; 635 int i= 0; 636 637 cont.addAll(list1); 638 Iterator it= cont.listIterator(); 639 r[i++]= it.next() == list1.get(0); 640 r[i++]= it.next() == list1.get(1); 641 r[i++]= it.next() == list1.get(2); 642 try 643 { 644 it.next(); 645 }catch(java.util.NoSuchElementException ne) 646 { 647 r[i++]= true; 648 }catch(Exception e) 649 { 650 r[i++]= false; 651 } 652 653 boolean bOk= true; 654 for (int c= 0; c < i; c++) 655 bOk= bOk && r[c]; 656 if ( ! bOk ) 657 System.out.println("Failed"); 658 else 659 System.out.println("Ok"); 660 return bOk; 661 } 662 ListIterator_hasNext()663 public boolean ListIterator_hasNext() 664 { 665 System.out.println("Testing ListIterator.hasNext()"); 666 InterfaceContainer cont= new InterfaceContainer(); 667 boolean r[]= new boolean[50]; 668 int i= 0; 669 670 Iterator it= cont.listIterator(); 671 r[i++]= ! it.hasNext(); 672 cont.addAll(list1); 673 it= cont.listIterator(); 674 r[i++]= it.hasNext(); 675 it.next(); 676 r[i++]= it.hasNext(); 677 it.next(); 678 r[i++]= it.hasNext(); 679 it.next(); 680 r[i++]= ! it.hasNext(); 681 682 boolean bOk= true; 683 for (int c= 0; c < i; c++) 684 bOk= bOk && r[c]; 685 if ( ! bOk ) 686 System.out.println("Failed"); 687 else 688 System.out.println("Ok"); 689 return bOk; 690 } 691 ListIterator_remove()692 public boolean ListIterator_remove() 693 { 694 System.out.println("Testing ListIterator.remove()"); 695 InterfaceContainer cont= new InterfaceContainer(); 696 boolean r[]= new boolean[50]; 697 int i= 0; 698 699 ListIterator it= cont.listIterator(); 700 try 701 { 702 it.remove(); 703 } 704 catch( IllegalStateException ie) 705 { 706 r[i++]= true; 707 } 708 catch(java.lang.Exception e) 709 { 710 r[i++]= false; 711 } 712 cont.add(obj1); 713 it= cont.listIterator(); 714 it.next(); 715 it.remove(); 716 r[i++]= cont.isEmpty(); 717 try 718 { 719 it.remove(); 720 } 721 catch (IllegalStateException ie) 722 { 723 r[i++]= true; 724 } 725 catch (Exception e) 726 { 727 r[i++]= false; 728 } 729 cont.clear(); 730 cont.addAll(list1); 731 it= cont.listIterator(); 732 while (it.hasNext()) 733 { 734 it.next(); 735 it.remove(); 736 } 737 r[i++]= cont.isEmpty(); 738 739 // 2 iterators, remove must not impair the other iterator 740 cont.clear(); 741 cont.addAll(list1); 742 int size= cont.size(); 743 it= cont.listIterator(); 744 Iterator it2= cont.listIterator(); 745 while (it.hasNext()) 746 { 747 it.next(); 748 it.remove(); 749 } 750 try 751 { 752 for( int c= 0; c < size; c++) 753 it2.next(); 754 r[i++]= true; 755 } 756 catch(Exception e) 757 { 758 r[i++]= false; 759 } 760 r[i++]= cont.size() == 0; 761 762 boolean bOk= true; 763 for (int c= 0; c < i; c++) 764 bOk= bOk && r[c]; 765 if ( ! bOk ) 766 System.out.println("Failed"); 767 else 768 System.out.println("Ok"); 769 return bOk; 770 } 771 ListIterator_hasPrevious()772 public boolean ListIterator_hasPrevious() 773 { 774 System.out.println("Testing ListIterator.hasPrevious()"); 775 InterfaceContainer cont= new InterfaceContainer(); 776 boolean r[]= new boolean[50]; 777 int i= 0; 778 779 ListIterator it= cont.listIterator(); 780 r[i++]= ! it.hasPrevious(); 781 cont.addAll(list1); 782 it= cont.listIterator(); 783 while (it.hasNext()) 784 { 785 it.next(); 786 r[i++]= it.hasPrevious(); 787 } 788 789 boolean bOk= true; 790 for (int c= 0; c < i; c++) 791 bOk= bOk && r[c]; 792 if ( ! bOk ) 793 System.out.println("Failed"); 794 else 795 System.out.println("Ok"); 796 return bOk; 797 } 798 ListIterator_previous()799 public boolean ListIterator_previous() 800 { 801 System.out.println("Testing ListIterator.previous()"); 802 InterfaceContainer cont= new InterfaceContainer(); 803 boolean r[]= new boolean[50]; 804 int i= 0; 805 boolean bOk= true; 806 807 cont.addAll(list1); 808 // go to the end of our list and list1 809 ListIterator it= cont.listIterator(); 810 while (it.hasNext()) 811 it.next(); 812 ListIterator it_list1= list1.listIterator(); 813 while (it_list1.hasNext()) 814 it_list1.next(); 815 816 while (it.hasPrevious()) 817 { 818 r[i++]= it.previous() == it_list1.previous(); 819 } 820 try 821 { 822 it.previous(); 823 r[i++]= false; 824 } 825 catch (java.util.NoSuchElementException e) 826 { 827 r[i++]=true; 828 } 829 830 for (int c= 0; c < i; c++) 831 bOk= bOk && r[c]; 832 if ( ! bOk ) 833 System.out.println("Failed"); 834 else 835 System.out.println("Ok"); 836 return bOk; 837 } 838 ListIterator_nextIndex()839 public boolean ListIterator_nextIndex() 840 { 841 System.out.println("Testing ListIterator.nextIndex()"); 842 InterfaceContainer cont= new InterfaceContainer(); 843 boolean r[]= new boolean[50]; 844 int i= 0; 845 boolean bOk= true; 846 847 ListIterator it= cont.listIterator(); 848 cont.addAll(list1); 849 it= cont.listIterator(); 850 r[i++]= it.nextIndex() == 0; 851 it.next(); 852 r[i++]= it.nextIndex() == 1; 853 it.next(); 854 r[i++]= it.nextIndex() == 2; 855 856 for (int c= 0; c < i; c++) 857 bOk= bOk && r[c]; 858 if ( ! bOk ) 859 System.out.println("Failed"); 860 else 861 System.out.println("Ok"); 862 return bOk; 863 } ListIterator_previousIndex()864 public boolean ListIterator_previousIndex() 865 { 866 System.out.println("Testing ListIterator.previousIndex()"); 867 InterfaceContainer cont= new InterfaceContainer(); 868 boolean r[]= new boolean[50]; 869 int i= 0; 870 boolean bOk= true; 871 872 ListIterator it= cont.listIterator(); 873 cont.addAll(list1); 874 it= cont.listIterator(); 875 while (it.hasNext()) 876 it.next(); 877 878 r[i++]= it.previousIndex() == 2; 879 it.previous(); 880 r[i++]= it.previousIndex() == 1; 881 it.previous(); 882 r[i++]= it.previousIndex() == 0; 883 it.previous(); 884 885 for (int c= 0; c < i; c++) 886 bOk= bOk && r[c]; 887 if ( ! bOk ) 888 System.out.println("Failed"); 889 else 890 System.out.println("Ok"); 891 return bOk; 892 } ListIterator_add()893 public boolean ListIterator_add() 894 { 895 System.out.println("Testing ListIterator.add()"); 896 InterfaceContainer cont= new InterfaceContainer(); 897 boolean r[]= new boolean[50]; 898 int i= 0; 899 boolean bOk= true; 900 901 ListIterator it= cont.listIterator(); 902 it.add(obj1); 903 r[i++]= cont.size() == 1; 904 it.add(obj2); 905 r[i++]= cont.size() == 2; 906 it.add(obj3); 907 r[i++]= it.previous() == obj3; 908 r[i++]= it.previous() == obj2; 909 r[i++]= it.previous() == obj1; 910 911 for (int c= 0; c < i; c++) 912 bOk= bOk && r[c]; 913 if ( ! bOk ) 914 System.out.println("Failed"); 915 else 916 System.out.println("Ok"); 917 return bOk; 918 } 919 disposeAndClear()920 public boolean disposeAndClear() 921 { 922 System.out.println("Testing InterfaceContainer.disposeAndClear"); 923 InterfaceContainer cont= new InterfaceContainer(10); 924 boolean r[]= new boolean[50]; 925 int i= 0; 926 927 cont.add(obj1); 928 cont.add(obj2); 929 cont.add(obj3); 930 cont.add(proxyObj1Weak1); 931 cont.add(proxyObj3TypeProv); 932 System.out.println("Two proxies are called. Check the output:"); 933 cont.disposeAndClear(new com.sun.star.lang.EventObject()); 934 r[i++]= obj1.nDisposingCalled == 1; 935 r[i++]= obj2.nDisposingCalled == 1; 936 r[i++]= obj3.nDisposingCalled == 1; 937 boolean bOk= true; 938 for (int c= 0; c < i; c++) 939 bOk= bOk && r[c]; 940 if (bOk == false) 941 System.out.println("Failed"); 942 else 943 System.out.println("Ok"); 944 return bOk; 945 } 946 947 main(String[] args)948 public static void main(String[] args) 949 { 950 InterfaceContainer_Test test= new InterfaceContainer_Test(); 951 boolean r[]= new boolean[50]; 952 int i= 0; 953 r[i++]= test.listConstructors(); 954 r[i++]= test.trimToSize(); 955 r[i++]= test.ensureCapacity(); 956 r[i++]= test.add(); 957 r[i++]= test.indexOf(); 958 r[i++]= test.contains(); 959 r[i++]= test.containsAll(); 960 r[i++]= test.get(); 961 r[i++]= test.addAll(); 962 r[i++]= test.remove(); 963 r[i++]= test.retainAll(); 964 r[i++]= test.set(); 965 r[i++]= test.toArray(); 966 r[i++]= test.Iterator_next(); 967 r[i++]= test.Iterator_hasNext(); 968 r[i++]= test.Iterator_remove(); 969 r[i++]= test.ListIterator_next(); 970 r[i++]= test.ListIterator_hasNext(); 971 r[i++]= test.ListIterator_remove(); 972 r[i++]= test.ListIterator_hasPrevious(); 973 r[i++]= test.ListIterator_previous(); 974 r[i++]= test.ListIterator_nextIndex(); 975 r[i++]= test.ListIterator_previousIndex(); 976 r[i++]= test.ListIterator_add(); 977 r[i++]= test.disposeAndClear(); 978 boolean bOk= true; 979 for (int c= 0; c < i; c++) 980 bOk= bOk && r[c]; 981 if ( ! bOk ) 982 System.out.println("Test finished.\nErrors occurred!!!"); 983 else 984 System.out.println("Test finished. \nNo errors."); 985 986 } 987 988 } 989