summaryrefslogtreecommitdiff
path: root/javaunohelper
diff options
context:
space:
mode:
authorRobert Antoni Buj i Gelonch <robert.buj@gmail.com>2014-09-24 13:57:50 +0200
committerDavid Ostrovsky <david@ostrovsky.org>2014-09-24 22:06:18 +0000
commitf6001fb30c516ec6da39b0ca4058f8b28058df1f (patch)
tree057345820f29481535fef2b70129bec4438585a4 /javaunohelper
parent647f83afb618acbf75c8c6f0a4531bd1e76d8a7e (diff)
javaunohelper: WeakBase_Test & MultiTypeInterfaceContainer_Test -> JUnit
Integrate WeakBase_Test and MultiTypeInterfaceContainer_Test in juh tests. Remove unused import in InterfaceContainer_Test. Remove getImplementationId() test in WeakBase_Test. Deprecated as of the commit: 90b27c9493f4225e1612364b5813971b45b681a6 $ make JunitTest_juh Change-Id: I1205c001e7f15bc5a28289051194fb225e114f13 Reviewed-on: https://gerrit.libreoffice.org/11630 Reviewed-by: David Ostrovsky <david@ostrovsky.org> Tested-by: David Ostrovsky <david@ostrovsky.org>
Diffstat (limited to 'javaunohelper')
-rw-r--r--javaunohelper/JunitTest_juh.mk4
-rw-r--r--javaunohelper/test/com/sun/star/lib/uno/helper/InterfaceContainer_Test.java1
-rw-r--r--javaunohelper/test/com/sun/star/lib/uno/helper/MultiTypeInterfaceContainer_Test.java167
-rw-r--r--javaunohelper/test/com/sun/star/lib/uno/helper/WeakBase_Test.java147
4 files changed, 100 insertions, 219 deletions
diff --git a/javaunohelper/JunitTest_juh.mk b/javaunohelper/JunitTest_juh.mk
index 3ba2f4ef4fb4..0aaaa3a3a50c 100644
--- a/javaunohelper/JunitTest_juh.mk
+++ b/javaunohelper/JunitTest_juh.mk
@@ -35,13 +35,17 @@ $(eval $(call gb_JunitTest_add_sourcefiles,juh,\
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/InterfaceContainer_Test \
+ javaunohelper/test/com/sun/star/lib/uno/helper/MultiTypeInterfaceContainer_Test \
javaunohelper/test/com/sun/star/lib/uno/helper/ProxyProvider \
+ javaunohelper/test/com/sun/star/lib/uno/helper/WeakBase_Test \
))
$(eval $(call gb_JunitTest_add_classes,juh,\
com.sun.star.comp.helper.ComponentContext_Test \
com.sun.star.lib.uno.helper.ComponentBase_Test \
com.sun.star.lib.uno.helper.InterfaceContainer_Test \
+ com.sun.star.lib.uno.helper.MultiTypeInterfaceContainer_Test \
+ com.sun.star.lib.uno.helper.WeakBase_Test \
))
# vim:set noet sw=4 ts=4:
diff --git a/javaunohelper/test/com/sun/star/lib/uno/helper/InterfaceContainer_Test.java b/javaunohelper/test/com/sun/star/lib/uno/helper/InterfaceContainer_Test.java
index c98ceaba03be..7459fae4085a 100644
--- a/javaunohelper/test/com/sun/star/lib/uno/helper/InterfaceContainer_Test.java
+++ b/javaunohelper/test/com/sun/star/lib/uno/helper/InterfaceContainer_Test.java
@@ -40,7 +40,6 @@ import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import org.junit.Before;
import org.junit.Test;
-import org.junit.rules.ExpectedException;
public class InterfaceContainer_Test
{
diff --git a/javaunohelper/test/com/sun/star/lib/uno/helper/MultiTypeInterfaceContainer_Test.java b/javaunohelper/test/com/sun/star/lib/uno/helper/MultiTypeInterfaceContainer_Test.java
index 6f805d574b43..c483a043138d 100644
--- a/javaunohelper/test/com/sun/star/lib/uno/helper/MultiTypeInterfaceContainer_Test.java
+++ b/javaunohelper/test/com/sun/star/lib/uno/helper/MultiTypeInterfaceContainer_Test.java
@@ -30,6 +30,12 @@ import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import org.junit.Before;
+import org.junit.Test;
+
public class MultiTypeInterfaceContainer_Test
{
private static final Logger logger = Logger.getLogger(MultiTypeInterfaceContainer_Test.class.getName());
@@ -47,8 +53,8 @@ public class MultiTypeInterfaceContainer_Test
//contains original object + proxies + null value
List<Object> list3;
- /** Creates a new instance of MultiTypeInterfaceContainer_Test */
- public MultiTypeInterfaceContainer_Test()
+ /** Class variables are initialized before each Test method */
+ @Before public void setUp() throws Exception
{
obj1= new AWeakBase();
obj2= new AWeakBase();
@@ -58,17 +64,25 @@ public class MultiTypeInterfaceContainer_Test
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);
list1= new ArrayList<Object>();
list1.add(obj1);
list1.add(obj2);
list1.add(obj3);
+
list2= new ArrayList<Object>();
list2.add(obj1);
list2.add(proxyObj2TypeProv);
list2.add(proxyObj3TypeProv);
+
list3= new ArrayList<Object>();
list3.add(obj1);
list3.add(null);
@@ -76,25 +90,26 @@ public class MultiTypeInterfaceContainer_Test
list3.add(proxyObj3Weak1);
}
- public boolean addInterface()
+ @Test public void addInterface() throws Exception
{
logger.log(Level.INFO, "Testing MultiTypeInterfaceContainer.addInterface");
MultiTypeInterfaceContainer cont= new MultiTypeInterfaceContainer();
- boolean r[]= new boolean[200];
- int i= 0;
int ci= 0;
ci= cont.addInterface(new Type(XInterface.class), obj1);
ci= cont.addInterface(new Type(XInterface.class), obj2);
ci= cont.addInterface(new Type(XInterface.class), obj3);
- r[i++]= ci == 3;
+ assertEquals(ci, 3);
+
ci= cont.addInterface(new Type(XWeak.class), obj1);
ci= cont.addInterface(new Type(XWeak.class), obj2);
- r[i++]= ci ==2;
+ assertEquals(ci, 2);
+
ci= cont.addInterface(null,obj1);
- r[i++]= ci == 1;
+ assertEquals(ci, 1);
+
ci= cont.addInterface(new Type(XTypeProvider.class), null);
- r[i++]= ci == 0;
+ assertEquals(ci, 0);
cont= new MultiTypeInterfaceContainer();
AWeakBase[] arObj= new AWeakBase[100];
@@ -107,22 +122,14 @@ public class MultiTypeInterfaceContainer_Test
for (int c=0; c < 100; c++)
{
ci= cont.removeInterface(new Type(XInterface.class), arObj[c]);
- r[i++]= ci == 100 -c -1;
-
+ assertEquals(ci, 100 -c -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 boolean getContainedTypes()
+ @Test public void getContainedTypes() throws Exception
{
logger.log(Level.INFO, "Testing MultiTypeInterfaceContainer.getContainedTypes");
MultiTypeInterfaceContainer cont= new MultiTypeInterfaceContainer();
- boolean r[]= new boolean[50];
- int i= 0;
cont.addInterface(new Type(XInterface.class), obj1);
cont.addInterface(new Type(XWeak.class), obj1);
@@ -133,39 +140,32 @@ public class MultiTypeInterfaceContainer_Test
cont.addInterface(XSingleComponentFactory.class, obj1);
Type[] types= cont.getContainedTypes();
// 3 types and no XTypeProvider
- r[i++]= types.length == 5;
+ assertEquals(types.length, 5);
for (int c= 0; c < types.length; c++)
{
+ boolean result= false;
if (types[c] == null)
- r[i++]= true;
- else if(types[c].equals( new Type(XTypeProvider.class)))
- r[i++]= false;
- else if(types[c].equals(new Type(XInterface.class)))
- r[i++]= true;
+ result= true;
+ else if (types[c].equals(new Type(XTypeProvider.class)))
+ result= false;
+ else if (types[c].equals(new Type(XInterface.class)))
+ result= true;
else if (types[c].equals(new Type(XWeak.class)))
- r[i++]= true;
+ result= true;
else if (types[c].equals(new Type()))
- r[i++]= true;
+ result= true;
else if (types[c].equals(new Type( aObj.getClass())))
- r[i++]= true;
+ result= true;
else if (types[c].equals(new Type(XSingleComponentFactory.class)))
- r[i++]= true;
- else
- r[i++]= false;
+ result= true;
+ assertTrue(result);
}
- boolean bOk= true;
- for (int c= 0; c < i; c++)
- bOk= bOk && r[c];
- logger.log(Level.INFO, bOk ? "Ok" : "Failed");
- return bOk;
}
- public boolean getContainer()
+ @Test public void getContainer() throws Exception
{
logger.log(Level.INFO, "Testing MultiTypeInterfaceContainer.getContainedTypes");
MultiTypeInterfaceContainer cont= new MultiTypeInterfaceContainer();
- boolean r[]= new boolean[50];
- int i= 0;
cont.addInterface(new Type(XInterface.class), obj1);
cont.addInterface(new Type(XInterface.class), obj2);
@@ -177,61 +177,45 @@ public class MultiTypeInterfaceContainer_Test
InterfaceContainer icont= null;
icont= cont.getContainer( new Type(XTypeProvider.class));
- r[i++]= icont.size() == 0;
+ assertEquals(icont.size(), 0);
icont= cont.getContainer(new Type(XWeak.class));
- r[i++]= icont.size() == 2;
+ assertEquals(icont.size(), 2);
icont= cont.getContainer(null);
- r[i++]= icont.size() == 1;
-
- boolean bOk= true;
- for (int c= 0; c < i; c++)
- bOk= bOk && r[c];
- logger.log(Level.INFO, bOk ? "Ok" : "Failed");
- return bOk;
+ assertEquals(icont.size(), 1);
}
- public boolean removeInterface()
+ @Test public void removeInterface() throws Exception
{
logger.log(Level.INFO, "Testing MultiTypeInterfaceContainer.removeInterface");
MultiTypeInterfaceContainer cont= new MultiTypeInterfaceContainer();
- boolean r[]= new boolean[50];
- int i= 0;
int count= 0;
count= cont.removeInterface( new Type(XTypeProvider.class), obj1);
- r[i++]= count == 0;
+ assertEquals(count, 0);
count= cont.removeInterface( new Type(XTypeProvider.class), null);
- r[i++]= count == 0;
+ assertEquals(count, 0);
count= cont.removeInterface(null, obj2);
- r[i++]= count == 0;
+ assertEquals(count, 0);
cont.addInterface(new Type(XInterface.class), obj1);
cont.addInterface(null, obj1);
count= cont.removeInterface(null, obj2);
// count must still be 1
- r[i++]= count == 1;
+ assertEquals(count, 1);
count= cont.removeInterface(null, obj1);
- r[i++]= count == 0;
+ assertEquals(count, 0);
count= cont.removeInterface(new Type(XInterface.class), obj1);
- r[i++]= count == 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(count, 0);
}
- public boolean clear()
+ @Test public void clear() throws Exception
{
logger.log(Level.INFO, "Testing MultiTypeInterfaceContainer.clear");
MultiTypeInterfaceContainer cont= new MultiTypeInterfaceContainer();
- boolean r[]= new boolean[50];
- int i= 0;
cont.clear();
Type[] types= cont.getContainedTypes();
- r[i++]= types.length == 0;
+ assertEquals(types.length, 0);
cont.addInterface(new Type(XInterface.class), obj1);
cont.addInterface(new Type(XInterface.class), obj2);
cont.addInterface(new Type(XInterface.class), obj3);
@@ -240,24 +224,17 @@ public class MultiTypeInterfaceContainer_Test
cont.addInterface(null, obj1);
cont.addInterface(new Type(XTypeProvider.class), null);
types= cont.getContainedTypes();
- r[i++]= types.length == 3;
+ assertEquals(types.length, 3);
cont.clear();
types= cont.getContainedTypes();
- r[i++]= types.length == 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(types.length, 0);
}
- public boolean disposeAndClear()
+ @Test public void disposeAndClear() throws Exception
{
logger.log(Level.INFO, "Testing MultiTypeInterfaceContainer.disposeAndClear");
MultiTypeInterfaceContainer cont= new MultiTypeInterfaceContainer();
- boolean r[]= new boolean[50];
- int i= 0;
+
obj1.nDisposingCalled= 0;
obj2.nDisposingCalled= 0;
obj3.nDisposingCalled= 0;
@@ -270,36 +247,10 @@ public class MultiTypeInterfaceContainer_Test
cont.addInterface(new Type(XTypeProvider.class), obj1);
cont.disposeAndClear(new com.sun.star.lang.EventObject("blabla"));
- r[i++]= obj1.nDisposingCalled == 3;
- r[i++]= obj2.nDisposingCalled == 2;
- r[i++]= obj3.nDisposingCalled == 1;
+ assertEquals(obj1.nDisposingCalled, 3);
+ assertEquals(obj2.nDisposingCalled, 2);
+ assertEquals(obj3.nDisposingCalled, 1);
Type[] types= cont.getContainedTypes();
- r[i++]= types.length == 0;
-
- 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)
- {
- MultiTypeInterfaceContainer_Test test= new MultiTypeInterfaceContainer_Test();
- boolean r[]= new boolean[50];
- int i= 0;
- r[i++]= test.addInterface();
- r[i++]= test.getContainedTypes();
- r[i++]= test.getContainer();
- r[i++]= test.removeInterface();
- r[i++]= test.clear();
- r[i++]= test.disposeAndClear();
- boolean bOk= true;
- for (int c= 0; c < i; c++)
- bOk= bOk && r[c];
- logger.log(Level.INFO, "Test finished.");
- logger.log(Level.INFO, bOk ? "No errors." : "Errors occurred!!!");
- System.exit( bOk ? 0: -1 );
+ assertEquals(types.length, 0);
}
} \ No newline at end of file
diff --git a/javaunohelper/test/com/sun/star/lib/uno/helper/WeakBase_Test.java b/javaunohelper/test/com/sun/star/lib/uno/helper/WeakBase_Test.java
index db86e57c4f72..ef9fdbf8e0bd 100644
--- a/javaunohelper/test/com/sun/star/lib/uno/helper/WeakBase_Test.java
+++ b/javaunohelper/test/com/sun/star/lib/uno/helper/WeakBase_Test.java
@@ -18,120 +18,78 @@
package com.sun.star.lib.uno.helper;
-import com.sun.star.uno.Type;
import com.sun.star.bridge.XBridgeSupplier2;
-import com.sun.star.uno.XReference;
-import com.sun.star.uno.XWeak;
import com.sun.star.lang.XTypeProvider;
import com.sun.star.uno.XAdapter;
+import com.sun.star.uno.Type;
+import com.sun.star.uno.XReference;
+import com.sun.star.uno.XWeak;
import java.util.logging.Level;
import java.util.logging.Logger;
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+import org.junit.Test;
+
public class WeakBase_Test
{
private static final Logger logger = Logger.getLogger(WeakBase_Test.class.getName());
- public boolean getTypes()
+ @Test public void getTypes() throws Exception
{
logger.log(Level.INFO, "Testing WeakBase.getTypes");
- boolean[] r= new boolean[50];
- int i= 0;
-
SomeClass comp= new SomeClass();
+
Type[] types= comp.getTypes(); //XWeak,XTypeProvider,XReference,XBridgeSupplier2
- r[i++]= types.length == 4;
+ assertEquals(types.length, 4);
for (int c= 0; c < types.length; c++)
{
+ boolean result= false;
if (types[c].equals( new Type( XWeak.class)))
- r[i++]= true;
+ result= true;
else if (types[c].equals(new Type(XTypeProvider.class)))
- r[i++]= true;
+ result= true;
else if (types[c].equals(new Type(XReference.class)))
- r[i++]= true;
+ result= true;
else if (types[c].equals(new Type(XBridgeSupplier2.class)))
- r[i++]= true;
- else
- r[i++]= false;
-
+ result= true;
+ assertTrue(result);
}
Foo1 f1= new Foo1();
Foo1 f2= new Foo1();
Type[] t1= f1.getTypes();
Type[] t2= f2.getTypes();
- r[i++]= t1.equals(t2);
- Foo2 f3= new Foo2();
- boolean bOk= true;
- for (int c= 0; c < i; c++)
- bOk= bOk && r[c];
- logger.log(Level.INFO, bOk ? "Ok" : "Failed");
- return bOk;
- }
-
- public boolean getImplementationId()
- {
- logger.log(Level.INFO, "Testing WeakBase.getImplementationId");
- boolean[] r= new boolean[50];
- int i= 0;
-
- SomeClass comp= new SomeClass();
- // byte 0 - 3 contain hashcode and the remaining bytes represent the classname
- byte [] ar= comp.getImplementationId();
-
- StringBuffer buff= new StringBuffer();
- for (int c= 0; c < ar.length - 4; c++){
- buff.append((char) ar[4 + c]);
- }
- String retStr= buff.toString();
- r[i++]= retStr.equals("com.sun.star.lib.uno.helper.SomeClass");
-
- Foo1 f1= new Foo1();
- Foo1 f2= new Foo1();
- r[i++]= f1.getImplementationId().equals(f2.getImplementationId());
+ assertArrayEquals(t1, t2);
Foo2 f3= new Foo2();
- r[i++]= ! f1.getImplementationId().equals(f3.getImplementationId());
- Foo3 f4= new Foo3();
- r[i++]= ! f1.getImplementationId().equals(f4.getImplementationId());
- boolean bOk= true;
- for (int c= 0; c < i; c++)
- bOk= bOk && r[c];
- logger.log(Level.INFO, bOk ? "Ok" : "Failed");
- return bOk;
}
- public boolean queryAdapter()
+ @Test public void queryAdapter() throws Exception
{
logger.log(Level.INFO, "Testing WeakBase.queryAdapter, XAdapter tests");
- boolean[] r= new boolean[50];
- int i= 0;
-
SomeClass comp= new SomeClass();
+
XAdapter adapter= comp.queryAdapter();
MyRef aRef1= new MyRef();
MyRef aRef2= new MyRef();
adapter.addReference(aRef1);
adapter.addReference(aRef2);
- r[i++]= adapter.queryAdapted() == comp;
+ assertSame(adapter.queryAdapted(), comp);
comp= null;
- logger.log(Level.FINE, "Wait 5 sec");
- for(int c= 0; c < 50; c++)
- {
- try
- {
- Thread.sleep(100);
- System.gc();
- System.runFinalization();
- }catch (InterruptedException ie)
- {
- }
- }
-
- r[i++]= aRef1.nDisposeCalled == 1;
- r[i++]= aRef2.nDisposeCalled == 1;
- r[i++]= adapter.queryAdapted() == null;
+ logger.log(Level.FINE, "Wait 51ms (-XX:MaxGCPauseMillis=50)");
+ System.gc();
+ System.runFinalization();
+ Thread.sleep(51);
+
+ assertEquals(aRef1.nDisposeCalled, 1);
+ assertEquals(aRef2.nDisposeCalled, 1);
+ assertNull(adapter.queryAdapted());
adapter.removeReference(aRef1); // should not do any harm
adapter.removeReference(aRef2);
@@ -144,45 +102,14 @@ public class WeakBase_Test
adapter.addReference(aRef2);
adapter.removeReference(aRef1);
- logger.log(Level.FINE, "Wait 5 sec");
+ logger.log(Level.FINE, "Wait 51ms (-XX:MaxGCPauseMillis=50)");
comp= null;
- for(int c= 0; c < 50; c++)
- {
- try
- {
- Thread.sleep(100);
- System.gc();
- System.runFinalization();
- }catch (InterruptedException ie)
- {
- }
- }
- r[i++]= aRef1.nDisposeCalled == 0;
- r[i++]= aRef2.nDisposeCalled == 1;
-
- boolean bOk= true;
- for (int c= 0; c < i; c++)
- bOk= bOk && r[c];
- logger.log(Level.INFO, bOk ? "Ok" : "Failed");
- return bOk;
+ System.gc();
+ System.runFinalization();
+ Thread.sleep(51);
+ assertEquals(aRef1.nDisposeCalled, 0);
+ assertEquals(aRef2.nDisposeCalled, 1);
}
-
- public static void main(String[] args)
- {
- WeakBase_Test test= new WeakBase_Test();
- boolean r[]= new boolean[50];
- int i= 0;
- r[i++]= test.getTypes();
- r[i++]= test.getImplementationId();
- r[i++]= test.queryAdapter();
-
- 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 );
- }
-
}
interface Aint