summaryrefslogtreecommitdiff
path: root/javaunohelper
diff options
context:
space:
mode:
authorRobert Antoni Buj i Gelonch <robert.buj@gmail.com>2014-09-22 16:31:56 +0200
committerDavid Ostrovsky <David.Ostrovsky@gmx.de>2014-09-23 19:29:38 +0000
commit2d8348d298185cad7d2b6aec40e8e44f95be1b7a (patch)
tree19ffdcdb34a75c19ae691dddb4bbb24a374fcc09 /javaunohelper
parented01da53ff04b1cfd6708e12f26d06cb9288a61f (diff)
javaunohelper: migrate ComponentBase_Test to JUnit
Use -XX:MaxGCPauseMillis=50 in conjunction with Thread.sleep(51) to wait 51ms after a GC call, instead of waiting 10s. http://docs.oracle.com/javase/1.5.0/docs/guide/vm/gc-ergonomics.html $ make JunitTest_juh Change-Id: Id2cdada0e493fd450aab5dbec164502e0173857f Reviewed-on: https://gerrit.libreoffice.org/11593 Reviewed-by: David Ostrovsky <David.Ostrovsky@gmx.de> Tested-by: David Ostrovsky <David.Ostrovsky@gmx.de>
Diffstat (limited to 'javaunohelper')
-rw-r--r--javaunohelper/JunitTest_juh.mk45
-rw-r--r--javaunohelper/JunitTest_juh_ComponentContext.mk31
-rw-r--r--javaunohelper/Module_javaunohelper.mk2
-rw-r--r--javaunohelper/test/com/sun/star/lib/uno/helper/ComponentBase_Test.java84
4 files changed, 74 insertions, 88 deletions
diff --git a/javaunohelper/JunitTest_juh.mk b/javaunohelper/JunitTest_juh.mk
new file mode 100644
index 000000000000..4bbd3f8e49d9
--- /dev/null
+++ b/javaunohelper/JunitTest_juh.mk
@@ -0,0 +1,45 @@
+# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
+#
+# This file is part of the LibreOffice project.
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+
+$(eval $(call gb_JunitTest_JunitTest,juh))
+
+$(eval $(call gb_JunitTest_set_defs,juh,\
+ $$(DEFS) \
+ -XX:MaxGCPauseMillis=50 \
+))
+
+$(eval $(call gb_JunitTest_use_jars,juh,\
+ ridl \
+ jurt \
+))
+
+$(eval $(call gb_JunitTest_use_jar_classset,juh,ridljar))
+
+$(eval $(call gb_JunitTest_add_sourcefiles,juh,\
+ javaunohelper/com/sun/star/comp/helper/Bootstrap \
+ javaunohelper/com/sun/star/comp/helper/BootstrapException \
+ javaunohelper/com/sun/star/comp/helper/ComponentContext \
+ javaunohelper/com/sun/star/comp/helper/ComponentContextEntry \
+ javaunohelper/com/sun/star/lib/uno/helper/ComponentBase \
+ javaunohelper/com/sun/star/lib/uno/helper/InterfaceContainer \
+ javaunohelper/com/sun/star/lib/uno/helper/MultiTypeInterfaceContainer \
+ javaunohelper/com/sun/star/lib/uno/helper/WeakAdapter \
+ javaunohelper/com/sun/star/lib/uno/helper/WeakBase \
+ javaunohelper/test/com/sun/star/comp/helper/ComponentContext_Test \
+ javaunohelper/test/com/sun/star/lib/uno/helper/AWeakBase \
+ javaunohelper/test/com/sun/star/lib/uno/helper/ComponentBase_Test \
+ javaunohelper/test/com/sun/star/lib/uno/helper/ProxyProvider \
+))
+
+$(eval $(call gb_JunitTest_add_classes,juh,\
+ com.sun.star.comp.helper.ComponentContext_Test \
+ com.sun.star.lib.uno.helper.ComponentBase_Test \
+))
+
+# vim:set noet sw=4 ts=4:
diff --git a/javaunohelper/JunitTest_juh_ComponentContext.mk b/javaunohelper/JunitTest_juh_ComponentContext.mk
deleted file mode 100644
index 11355e39dd9b..000000000000
--- a/javaunohelper/JunitTest_juh_ComponentContext.mk
+++ /dev/null
@@ -1,31 +0,0 @@
-# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
-#
-# This file is part of the LibreOffice project.
-#
-# This Source Code Form is subject to the terms of the Mozilla Public
-# License, v. 2.0. If a copy of the MPL was not distributed with this
-# file, You can obtain one at http://mozilla.org/MPL/2.0/.
-#
-
-$(eval $(call gb_JunitTest_JunitTest,juh_ComponentContext))
-
-$(eval $(call gb_JunitTest_use_jars,juh_ComponentContext,\
- ridl \
- jurt \
-))
-
-$(eval $(call gb_JunitTest_use_jar_classset,juh_ComponentContext,ridljar))
-
-$(eval $(call gb_JunitTest_add_sourcefiles,juh_ComponentContext,\
- javaunohelper/com/sun/star/comp/helper/Bootstrap \
- javaunohelper/com/sun/star/comp/helper/BootstrapException \
- javaunohelper/com/sun/star/comp/helper/ComponentContext \
- javaunohelper/com/sun/star/comp/helper/ComponentContextEntry \
- javaunohelper/test/com/sun/star/comp/helper/ComponentContext_Test \
-))
-
-$(eval $(call gb_JunitTest_add_classes,juh_ComponentContext,\
- com.sun.star.comp.helper.ComponentContext_Test \
-))
-
-# vim:set noet sw=4 ts=4:
diff --git a/javaunohelper/Module_javaunohelper.mk b/javaunohelper/Module_javaunohelper.mk
index 8a2e653ff8db..daafedaeeae6 100644
--- a/javaunohelper/Module_javaunohelper.mk
+++ b/javaunohelper/Module_javaunohelper.mk
@@ -17,7 +17,7 @@ $(eval $(call gb_Module_add_targets,javaunohelper,\
))
$(eval $(call gb_Module_add_subsequentcheck_targets,javaunohelper,\
- JunitTest_juh_ComponentContext \
+ JunitTest_juh \
))
ifneq ($(DISABLE_DYNLOADING),TRUE)
diff --git a/javaunohelper/test/com/sun/star/lib/uno/helper/ComponentBase_Test.java b/javaunohelper/test/com/sun/star/lib/uno/helper/ComponentBase_Test.java
index 7bf048415933..89ab9ddc547e 100644
--- a/javaunohelper/test/com/sun/star/lib/uno/helper/ComponentBase_Test.java
+++ b/javaunohelper/test/com/sun/star/lib/uno/helper/ComponentBase_Test.java
@@ -26,6 +26,11 @@ import com.sun.star.lang.XEventListener;
import java.util.logging.Level;
import java.util.logging.Logger;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import org.junit.Before;
+import org.junit.Test;
+
public class ComponentBase_Test
{
private static final Logger logger = Logger.getLogger(ComponentBase_Test.class.getName());
@@ -36,25 +41,30 @@ public class ComponentBase_Test
Object proxyObj3TypeProv;
Object proxyObj2TypeProv;
- /** Creates a new instance of ComponentBase_Test */
- public ComponentBase_Test()
+ /** Class variables are initialized before each Test method */
+ @Before public void setUp() throws Exception
{
obj1= new AWeakBase();
obj2= new AWeakBase();
obj3= new AWeakBase();
+
proxyObj1Weak1= ProxyProvider.createProxy(obj1, XWeak.class);
proxyObj3Weak1= ProxyProvider.createProxy(obj3, XWeak.class);
proxyObj3Weak2= ProxyProvider.createProxy(obj3, XWeak.class);
+ assertNotNull(proxyObj1Weak1);
+ assertNotNull(proxyObj3Weak1);
+ assertNotNull(proxyObj3Weak2);
+
proxyObj2TypeProv= ProxyProvider.createProxy(obj2, XTypeProvider.class);
proxyObj3TypeProv= ProxyProvider.createProxy(obj3, XTypeProvider.class);
+ assertNotNull(proxyObj2TypeProv);
+ assertNotNull(proxyObj3TypeProv);
}
- public boolean dispose()
+ @Test public void test_dispose() throws Exception
{
- logger.log(Level.INFO, "Testing ComponentBase");
+ logger.log(Level.INFO, "Testing ComponentBase: test_dispose()");
ComponentBase comp= new ComponentBase();
- boolean r[]= new boolean[50];
- int i= 0;
logger.log(Level.FINE, "addEventListener");
comp.addEventListener(obj1);
@@ -68,73 +78,35 @@ public class ComponentBase_Test
obj3.nDisposingCalled = 0;
comp.dispose();
- r[i++]= obj1.nDisposingCalled == 1;
- r[i++]= obj2.nDisposingCalled == 1;
- r[i++]= obj3.nDisposingCalled == 1;
+ assertEquals(obj1.nDisposingCalled, 1);
+ assertEquals(obj2.nDisposingCalled, 1);
+ assertEquals(obj3.nDisposingCalled, 1);
logger.log(Level.FINE, "Adding a listener after dispose, causes a immediate call to the listerner.");
obj1.nDisposingCalled= 0;
comp.addEventListener(obj1);
- r[i++]= obj1.nDisposingCalled == 1;
+ assertEquals(obj1.nDisposingCalled, 1);
logger.log(Level.FINE, "Calling dispose again must not notify the listeners again.");
obj1.nDisposingCalled= 0;
obj2.nDisposingCalled= 0;
obj3.nDisposingCalled= 0;
comp.dispose(); // already disposed;
- r[i++]= obj1.nDisposingCalled == 0;
-
- boolean bOk= true;
- for (int c= 0; c < i; c++)
- bOk= bOk && r[c];
- logger.log(Level.INFO, bOk ? "Ok" : "Failed");
- return bOk;
+ assertEquals(obj1.nDisposingCalled, 0);
}
- public boolean test_finalize()
+ @Test public void test_finalize() throws Exception
{
- logger.log(Level.INFO, "Testing ComponentBase");
+ logger.log(Level.INFO, "Testing ComponentBase: test_finalize()");
ComponentBase comp= new ComponentBase();
- boolean r[]= new boolean[50];
- int i= 0;
obj1.nDisposingCalled = 0;
comp.addEventListener(obj1);
comp= null;
- logger.log(Level.FINE, "Waiting 10s");
- for(int c= 0; c < 100; c++)
- {
- try
- {
- Thread.sleep(100);
- System.gc();
- System.runFinalization();
- }catch (InterruptedException ie)
- {
- }
- }
- r[i++]= obj1.nDisposingCalled == 1;
-
- boolean bOk= true;
- for (int c= 0; c < i; c++)
- bOk= bOk && r[c];
- logger.log(Level.INFO, bOk ? "Ok" : "Failed");
- return bOk;
- }
-
- public static void main(String[] args)
- {
- ComponentBase_Test test= new ComponentBase_Test();
-
- boolean r[]= new boolean[50];
- int i= 0;
- r[i++]= test.dispose();
- r[i++]= test.test_finalize();
-
- boolean bOk= true;
- for (int c= 0; c < i; c++)
- bOk= bOk && r[c];
- logger.log(Level.INFO, bOk ? "No errors." : "Errors occurred!");
- System.exit( bOk ? 0: -1 );
+ System.gc();
+ System.runFinalization();
+ logger.log(Level.FINE, "Waiting 51ms (-XX:MaxGCPauseMillis=50)");
+ Thread.sleep(51);
+ assertEquals(obj1.nDisposingCalled, 1);
}
} \ No newline at end of file