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