Update ooo320-m1
[ooovba.git] / javaunohelper / test / com / sun / star / lib / uno / helper / ComponentBase_Test.java
blob3ece2464fabc4e55242533576873ba73b8734c76
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: ComponentBase_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;
32 import com.sun.star.uno.XWeak;
33 import com.sun.star.lang.XTypeProvider;
34 import com.sun.star.uno.UnoRuntime;
35 import com.sun.star.lang.XEventListener;
37 public class ComponentBase_Test
39 AWeakBase obj1, obj2, obj3;
40 Object proxyObj1Weak1;
41 Object proxyObj3Weak1;
42 Object proxyObj3Weak2;
43 Object proxyObj3TypeProv;
44 Object proxyObj2TypeProv;
46 /** Creates a new instance of ComponentBase_Test */
47 public ComponentBase_Test()
49 obj1= new AWeakBase();
50 obj2= new AWeakBase();
51 obj3= new AWeakBase();
52 proxyObj1Weak1= ProxyProvider.createProxy(obj1, XWeak.class);
53 proxyObj3Weak1= ProxyProvider.createProxy(obj3, XWeak.class);
54 proxyObj3Weak2= ProxyProvider.createProxy(obj3, XWeak.class);
55 proxyObj2TypeProv= ProxyProvider.createProxy(obj2, XTypeProvider.class);
56 proxyObj3TypeProv= ProxyProvider.createProxy(obj3, XTypeProvider.class);
59 public boolean dispose()
61 System.out.println("Testing ComponentBase");
62 ComponentBase comp= new ComponentBase();
63 boolean r[]= new boolean[50];
64 int i= 0;
65 // addEventListener
67 comp.addEventListener(obj1);
68 comp.addEventListener(obj2);
69 comp.addEventListener(obj3);
70 comp.addEventListener(UnoRuntime.queryInterface(XEventListener.class, proxyObj1Weak1));
71 comp.addEventListener(UnoRuntime.queryInterface(XEventListener.class, proxyObj3Weak2));
72 comp.addEventListener(UnoRuntime.queryInterface(XEventListener.class, proxyObj3TypeProv));
73 obj1.nDisposingCalled = 0;
74 obj2.nDisposingCalled = 0;
75 obj3.nDisposingCalled = 0;
77 comp.dispose();
78 r[i++]= obj1.nDisposingCalled == 1;
79 r[i++]= obj2.nDisposingCalled == 1;
80 r[i++]= obj3.nDisposingCalled == 1;
81 // adding a listener after dispose, causes a immediate call to the listerner
82 obj1.nDisposingCalled= 0;
83 comp.addEventListener(obj1);
84 r[i++]= obj1.nDisposingCalled == 1;
85 //calling dispose again must not notify the listeners again
86 obj1.nDisposingCalled= 0;
87 obj2.nDisposingCalled= 0;
88 obj3.nDisposingCalled= 0;
89 comp.dispose(); // allready disposed;
90 r[i++]= obj1.nDisposingCalled == 0;
92 boolean bOk= true;
93 for (int c= 0; c < i; c++)
94 bOk= bOk && r[c];
95 if (bOk == false)
96 System.out.println("Failed");
97 else
98 System.out.println("Ok");
99 return bOk;
102 public boolean test_finalize()
104 System.out.println("Testing ComponentBase");
105 ComponentBase comp= new ComponentBase();
106 boolean r[]= new boolean[50];
107 int i= 0;
108 obj1.nDisposingCalled = 0;
109 comp.addEventListener(obj1);
111 comp= null;
112 System.out.println("Waiting 10s");
113 for(int c= 0; c < 100; c++)
117 Thread.currentThread().sleep(100);
118 System.gc();
119 System.runFinalization();
120 }catch (InterruptedException ie)
124 r[i++]= obj1.nDisposingCalled == 1;
126 boolean bOk= true;
127 for (int c= 0; c < i; c++)
128 bOk= bOk && r[c];
129 if (bOk == false)
130 System.out.println("Failed");
131 else
132 System.out.println("Ok");
133 return bOk;
136 public static void main(String[] args)
138 ComponentBase_Test test= new ComponentBase_Test();
140 boolean r[]= new boolean[50];
141 int i= 0;
142 r[i++]= test.dispose();
143 r[i++]= test.test_finalize();
145 boolean bOk= true;
146 for (int c= 0; c < i; c++)
147 bOk= bOk && r[c];
148 if (bOk == false)
149 System.out.println("Errors occured!");
150 else
151 System.out.println("No errors.");