summaryrefslogtreecommitdiff
path: root/jurt/test/com/sun/star/lib/uno/protocols/urp
diff options
context:
space:
mode:
Diffstat (limited to 'jurt/test/com/sun/star/lib/uno/protocols/urp')
-rw-r--r--jurt/test/com/sun/star/lib/uno/protocols/urp/Cache_Test.java106
-rw-r--r--jurt/test/com/sun/star/lib/uno/protocols/urp/Marshaling_Test.java369
-rw-r--r--jurt/test/com/sun/star/lib/uno/protocols/urp/Protocol_Test.java317
-rw-r--r--jurt/test/com/sun/star/lib/uno/protocols/urp/TestBridge.java115
-rw-r--r--jurt/test/com/sun/star/lib/uno/protocols/urp/TestObject.java70
-rw-r--r--jurt/test/com/sun/star/lib/uno/protocols/urp/interfaces.idl119
-rw-r--r--jurt/test/com/sun/star/lib/uno/protocols/urp/makefile.mk42
7 files changed, 1138 insertions, 0 deletions
diff --git a/jurt/test/com/sun/star/lib/uno/protocols/urp/Cache_Test.java b/jurt/test/com/sun/star/lib/uno/protocols/urp/Cache_Test.java
new file mode 100644
index 000000000000..31d3454bde48
--- /dev/null
+++ b/jurt/test/com/sun/star/lib/uno/protocols/urp/Cache_Test.java
@@ -0,0 +1,106 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+package com.sun.star.lib.uno.protocols.urp;
+
+import complexlib.ComplexTestCase;
+
+public final class Cache_Test extends ComplexTestCase {
+ public String[] getTestMethodNames() {
+ return new String[] { "test0", "test1", "test2", "test3" };
+ }
+
+ public void test0() {
+ Cache c = new Cache(0);
+ boolean[] f = new boolean[1];
+ int i;
+ i = c.add(f, "a");
+ assure("1", i == Cache.NOT_CACHED && !f[0]);
+ i = c.add(f, "a");
+ assure("2", i == Cache.NOT_CACHED && !f[0]);
+ i = c.add(f, "b");
+ assure("3", i == Cache.NOT_CACHED && !f[0]);
+ i = c.add(f, "a");
+ assure("4", i == Cache.NOT_CACHED && !f[0]);
+ }
+
+ public void test1() {
+ Cache c = new Cache(1);
+ boolean[] f = new boolean[1];
+ int i;
+ i = c.add(f, "a");
+ assure("1", i == 0 && !f[0]);
+ i = c.add(f, "a");
+ assure("2", i == 0 && f[0]);
+ i = c.add(f, "b");
+ assure("3", i == 0 && !f[0]);
+ i = c.add(f, "b");
+ assure("4", i == 0 && f[0]);
+ i = c.add(f, "a");
+ assure("5", i == 0 && !f[0]);
+ }
+
+ public void test2() {
+ Cache c = new Cache(2);
+ boolean[] f = new boolean[1];
+ int i;
+ i = c.add(f, "a");
+ assure("1", i == 0 && !f[0]);
+ i = c.add(f, "a");
+ assure("2", i == 0 && f[0]);
+ i = c.add(f, "b");
+ assure("3", i == 1 && !f[0]);
+ i = c.add(f, "b");
+ assure("4", i == 1 && f[0]);
+ i = c.add(f, "a");
+ assure("5", i == 0 && f[0]);
+ i = c.add(f, "c");
+ assure("6", i == 1 && !f[0]);
+ i = c.add(f, "b");
+ assure("7", i == 0 && !f[0]);
+ }
+
+ public void test3() {
+ Cache c = new Cache(3);
+ boolean[] f = new boolean[1];
+ int i;
+ i = c.add(f, "a");
+ assure("1", i == 0 && !f[0]);
+ i = c.add(f, "a");
+ assure("3", i == 0 && f[0]);
+ i = c.add(f, "b");
+ assure("5", i == 1 && !f[0]);
+ i = c.add(f, "a");
+ assure("3", i == 0 && f[0]);
+ i = c.add(f, "c");
+ assure("7", i == 2 && !f[0]);
+ i = c.add(f, "d");
+ assure("9", i == 1 && !f[0]);
+ i = c.add(f, "d");
+ assure("11", i == 1 && f[0]);
+ }
+}
diff --git a/jurt/test/com/sun/star/lib/uno/protocols/urp/Marshaling_Test.java b/jurt/test/com/sun/star/lib/uno/protocols/urp/Marshaling_Test.java
new file mode 100644
index 000000000000..4c01e9acc9c6
--- /dev/null
+++ b/jurt/test/com/sun/star/lib/uno/protocols/urp/Marshaling_Test.java
@@ -0,0 +1,369 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+package com.sun.star.lib.uno.protocols.urp;
+
+import com.sun.star.lib.uno.typedesc.TypeDescription;
+import com.sun.star.uno.Any;
+import com.sun.star.uno.IBridge;
+import com.sun.star.uno.Type;
+import com.sun.star.uno.TypeClass;
+import com.sun.star.uno.XInterface;
+import complexlib.ComplexTestCase;
+import java.lang.reflect.Array;
+import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
+
+public final class Marshaling_Test extends ComplexTestCase {
+ public String getTestObjectName() {
+ return getClass().getName();
+ }
+
+ public String[] getTestMethodNames() {
+ return new String[] { "test" };
+ }
+
+ public void test() throws Exception {
+ short cacheSize = (short)256;
+ TestBridge testBridge = new TestBridge();
+ Marshal marshal = new Marshal(testBridge, cacheSize);
+
+ TestObject testObject = new TestObject();
+
+ TestPrimitiveSeqStruct x = new TestPrimitiveSeqStruct();
+ x.zAny = new Object[]{new Integer(1), new Double(2) };
+
+
+ Object data[] = new Object[] {
+ new com.sun.star.uno.RuntimeException("testRuntimeException"),
+ new com.sun.star.uno.Exception("testException"),
+ new Boolean(true),
+ new Byte((byte)47),
+ new Character('k'),
+ new Double(0.12345),
+ TestEnum.B,
+ new Float(0.5678),
+ new Integer(0),
+ new Integer(128),
+ new Integer(0x0f00),
+ new Integer(0x0f0000),
+ new Integer(0x0f000000),
+ new Integer(-128),
+ new Integer(0xff00),
+ new Integer(0xff0000),
+ new Integer(0xff000000),
+ new Long(666L),
+ new Short((short)444),
+ new String("blabla"),
+ new Integer(10), // Any as object
+ new Integer(10), // Any as object
+ new Any(new Type(Integer.class), new Integer(10)), // Any as Any
+ new Any(new Type(Integer.class), new Integer(10)), // Any as Any
+ null,
+ new TestPrimitiveStruct(),
+ x, //new TestPrimitiveSeqStruct(),
+ new byte[]{1,2,3,4,5,6,7}, // primitive sequence
+ new int[]{7,6,5,4,3,2,1}, // primitive sequence
+ new Object[]{new Integer(123), new String("hallo")}, // any sequence
+ new TestPrimitiveStruct[]{new TestPrimitiveStruct(), new TestPrimitiveStruct()}, // sequence of primitive structs
+ new TestPrimitiveSeqStruct[]{new TestPrimitiveSeqStruct(), new TestPrimitiveSeqStruct()}, // sequence of primitive structs
+ new TestNestedStruct(),
+ new TestNestedSeqStruct(),
+ new Type(Void.class),
+ new Type(String.class),
+ new Type(Object.class),
+ new Type(Byte.class),
+ new Type(Integer.class),
+ new Type(Double.class),
+ new Type(Float.class),
+ new Type(Character.class),
+ new Type(Short.class),
+ new Type(Boolean.class),
+ new Type(void.class),
+ new Type(byte.class),
+ new Type(int.class),
+ new Type(double.class),
+ new Type(float.class),
+ new Type(char.class),
+ new Type(short.class),
+ new Type(boolean.class),
+ new Type(Class.forName("[Ljava.lang.String;")),
+ new Type(Class.forName("[Ljava.lang.Object;")),
+ new Type(Class.forName("[B")),
+ new Type(Class.forName("[Z")),
+ new Type("boolean"),
+ new Type("byte"),
+ new Type("char"),
+ new Type("short"),
+ new Type("long"),
+ new Type("hyper"),
+ new Type("float"),
+ new Type("double"),
+ new Type("string"),
+ new Type("void"),
+ new Type("any"),
+ new Type(
+ "com.sun.star.lib.uno.protocols.urp.TestEnum", TypeClass.ENUM),
+ new Type("[]boolean", TypeClass.SEQUENCE),
+ new Type("[][]byte", TypeClass.SEQUENCE),
+ new Type("[][][]char", TypeClass.SEQUENCE),
+ new Type("[][][][]short", TypeClass.SEQUENCE),
+ new Type("[][][][][]any", TypeClass.SEQUENCE),
+ new Type("com.sun.star.uno.XInterface", TypeClass.INTERFACE),
+ new Type("[]com.sun.star.uno.XInterface", TypeClass.SEQUENCE),
+ testObject,
+ testObject,
+ new TestInterfaceStruct(testObject, null)
+ };
+
+ TypeDescription dataTypes[] = new TypeDescription[] {
+ TypeDescription.getTypeDescription(com.sun.star.uno.RuntimeException.class),
+ TypeDescription.getTypeDescription(com.sun.star.uno.Exception.class),
+ TypeDescription.getTypeDescription(Boolean.class),
+ TypeDescription.getTypeDescription(Byte.class),
+ TypeDescription.getTypeDescription(Character.class),
+ TypeDescription.getTypeDescription(Double.class),
+ TypeDescription.getTypeDescription(TestEnum.class),
+ TypeDescription.getTypeDescription(Float.class),
+ TypeDescription.getTypeDescription(Integer.class),
+ TypeDescription.getTypeDescription(Integer.class),
+ TypeDescription.getTypeDescription(Integer.class),
+ TypeDescription.getTypeDescription(Integer.class),
+ TypeDescription.getTypeDescription(Integer.class),
+ TypeDescription.getTypeDescription(Integer.class),
+ TypeDescription.getTypeDescription(Integer.class),
+ TypeDescription.getTypeDescription(Integer.class),
+ TypeDescription.getTypeDescription(Integer.class),
+ TypeDescription.getTypeDescription(Long.class),
+ TypeDescription.getTypeDescription(Short.class),
+ TypeDescription.getTypeDescription(String.class),
+ TypeDescription.getTypeDescription(Object.class),
+ TypeDescription.getTypeDescription(Any.class),
+ TypeDescription.getTypeDescription(Any.class),
+ TypeDescription.getTypeDescription(Object.class),
+ TypeDescription.getTypeDescription(XInterface.class),
+ TypeDescription.getTypeDescription(TestPrimitiveStruct.class),
+ TypeDescription.getTypeDescription(TestPrimitiveSeqStruct.class),
+ TypeDescription.getTypeDescription(Class.forName("[B")),
+ TypeDescription.getTypeDescription(Class.forName("[I")),
+ TypeDescription.getTypeDescription(Class.forName("[Lcom.sun.star.uno.Any;")),
+ TypeDescription.getTypeDescription(
+ Class.forName(
+ "[Lcom.sun.star.lib.uno.protocols.urp."
+ + "TestPrimitiveStruct;")),
+ TypeDescription.getTypeDescription(
+ Class.forName(
+ "[Lcom.sun.star.lib.uno.protocols.urp."
+ + "TestPrimitiveSeqStruct;")),
+ TypeDescription.getTypeDescription(TestNestedStruct.class),
+ TypeDescription.getTypeDescription(TestNestedSeqStruct.class),
+ TypeDescription.getTypeDescription(Type.class),
+ TypeDescription.getTypeDescription(Type.class),
+ TypeDescription.getTypeDescription(Type.class),
+ TypeDescription.getTypeDescription(Type.class),
+ TypeDescription.getTypeDescription(Type.class),
+ TypeDescription.getTypeDescription(Type.class),
+ TypeDescription.getTypeDescription(Type.class),
+ TypeDescription.getTypeDescription(Type.class),
+ TypeDescription.getTypeDescription(Type.class),
+ TypeDescription.getTypeDescription(Type.class),
+ TypeDescription.getTypeDescription(Type.class),
+ TypeDescription.getTypeDescription(Type.class),
+ TypeDescription.getTypeDescription(Type.class),
+ TypeDescription.getTypeDescription(Type.class),
+ TypeDescription.getTypeDescription(Type.class),
+ TypeDescription.getTypeDescription(Type.class),
+ TypeDescription.getTypeDescription(Type.class),
+ TypeDescription.getTypeDescription(Type.class),
+ TypeDescription.getTypeDescription(Type.class),
+ TypeDescription.getTypeDescription(Type.class),
+ TypeDescription.getTypeDescription(Type.class),
+ TypeDescription.getTypeDescription(Type.class),
+ TypeDescription.getTypeDescription(Type.class),
+ TypeDescription.getTypeDescription(Type.class),
+ TypeDescription.getTypeDescription(Type.class),
+ TypeDescription.getTypeDescription(Type.class),
+ TypeDescription.getTypeDescription(Type.class),
+ TypeDescription.getTypeDescription(Type.class),
+ TypeDescription.getTypeDescription(Type.class),
+ TypeDescription.getTypeDescription(Type.class),
+ TypeDescription.getTypeDescription(Type.class),
+ TypeDescription.getTypeDescription(Type.class),
+ TypeDescription.getTypeDescription(Type.class),
+ TypeDescription.getTypeDescription(Type.class),
+ TypeDescription.getTypeDescription(Type.class),
+ TypeDescription.getTypeDescription(Type.class),
+ TypeDescription.getTypeDescription(Type.class),
+ TypeDescription.getTypeDescription(Type.class),
+ TypeDescription.getTypeDescription(Type.class),
+ TypeDescription.getTypeDescription(Type.class),
+ TypeDescription.getTypeDescription(Type.class),
+ TypeDescription.getTypeDescription(XInterface.class),
+ TypeDescription.getTypeDescription(XInterface.class),
+ TypeDescription.getTypeDescription(TestInterfaceStruct.class),
+ };
+
+
+ Unmarshal unmarshal = new Unmarshal(testBridge, cacheSize);
+ for(int i = 0; i < dataTypes.length; ++ i) {
+ Object op1 = data[i];
+ marshal.writeValue(dataTypes[i], data[i]);
+
+ unmarshal.reset(marshal.reset());
+
+ Object op2 = unmarshal.readValue(dataTypes[i]);
+
+ if(op1 instanceof Any)
+ op1 = ((Any)op1).getObject();
+
+ assure("", compareObjects(op1, op2));
+ }
+ }
+
+ private static boolean compareArrays(Object op1, Object op2) throws Exception {
+ boolean result = true;
+ if((op1.getClass().getComponentType() == op2.getClass().getComponentType())
+ && (Array.getLength(op1) == Array.getLength(op2)))
+ {
+ Class zClass = op1.getClass().getComponentType();
+
+ for(int i = 0; i < Array.getLength(op1); ++ i)
+ result = result & compareObjects(Array.get(op1, i), Array.get(op2, i));
+ }
+
+ return result;
+ }
+
+ private static boolean compareInterfaces(XInterface op1, XInterface op2) {
+ return op1 == op2;
+ }
+
+ private static boolean compareStructs(Class zClass, Object op1, Object op2) throws Exception {
+ boolean result = true;
+
+ Field fields[] = zClass.getFields();
+
+ for(int i = 0; i < fields.length && result; ++ i) {
+ if((fields[i].getModifiers() & (Modifier.STATIC | Modifier.TRANSIENT)) == 0) { // neither static nor transient ?
+ result = result & compareObjects(fields[i].get(op1), fields[i].get(op2));
+
+ if(!result)
+ System.err.println("blabal :" + fields[i]);
+ }
+ }
+
+ return result;
+ }
+
+ private static boolean compareStructs(Object op1, Object op2) throws Exception {
+ boolean result = true;
+
+ if(op1.getClass() != op2.getClass())
+ result = false;
+ else {
+ result = compareStructs(op1.getClass(), op1, op2);
+ }
+
+ return result;
+ }
+
+ private static boolean compareThrowable(Throwable op1, Throwable op2) throws Exception {
+ boolean result = true;
+
+ if(op1.getClass() != op2.getClass())
+ result = false;
+ else {
+ result = compareStructs(op1.getClass(), op1, op2);
+
+ result = result & op1.getMessage().equals(op2.getMessage());
+ }
+
+ return result;
+ }
+
+ private static boolean compareObjects(Object op1, Object op2) throws Exception {
+ boolean result = false;
+
+ if(op1 == op2)
+ result = true;
+
+ else if(op1.getClass().isPrimitive() && op2.getClass().isPrimitive())
+ result = op1.equals(op2);
+
+ else if(op1.getClass() == Byte.class && op2.getClass() == Byte.class)
+ result = op1.equals(op2);
+
+ else if(op1.getClass() == Type.class && op2.getClass() == Type.class)
+ result = op1.equals(op2);
+
+ else if(op1.getClass() == Boolean.class && op2.getClass() == Boolean.class)
+ result = op1.equals(op2);
+
+ else if(op1.getClass() == Short.class && op2.getClass() == Short.class)
+ result = op1.equals(op2);
+
+ else if(Throwable.class.isAssignableFrom(op1.getClass()) && Throwable.class.isAssignableFrom(op2.getClass()))
+ result = compareThrowable((Throwable)op1, (Throwable)op2);
+
+ else if(op1.getClass() == Integer.class && op2.getClass() == Integer.class)
+ result = op1.equals(op2);
+
+ else if(op1.getClass() == Character.class && op2.getClass() == Character.class)
+ result = op1.equals(op2);
+
+ else if(op1.getClass() == Long.class && op2.getClass() == Long.class)
+ result = op1.equals(op2);
+
+ else if(op1.getClass() == Void.class && op2.getClass() == Void.class)
+ result = op1.equals(op2);
+
+ else if(op1.getClass() == Float.class && op2.getClass() == Float.class)
+ result = op1.equals(op2);
+
+ else if(op1.getClass() == Double.class && op2.getClass() == Double.class)
+ result = op1.equals(op2);
+
+ else if(op1.getClass().isArray() && op2.getClass().isArray())
+ result = compareArrays(op1, op2);
+
+ else if(op1.getClass() == Void.class || op2.getClass() == void.class) // write nothing ?
+ result = true;
+
+ else if(XInterface.class.isAssignableFrom(op1.getClass()) && XInterface.class.isAssignableFrom(op2.getClass()))
+ result = compareInterfaces((XInterface)op1, (XInterface)op2);
+
+ else if(op1.getClass() == String.class && op2.getClass() == String.class) // is it a String ?
+ result = ((String)op1).equals((String)op2);
+
+ else if(op1.getClass() == Type.class && op2.getClass() == Type.class) // types?
+ result = op1.equals(op2);
+
+ else // otherwise it must be a struct
+ result = compareStructs(op1, op2);
+
+ return result;
+ }
+}
diff --git a/jurt/test/com/sun/star/lib/uno/protocols/urp/Protocol_Test.java b/jurt/test/com/sun/star/lib/uno/protocols/urp/Protocol_Test.java
new file mode 100644
index 000000000000..393720c9756d
--- /dev/null
+++ b/jurt/test/com/sun/star/lib/uno/protocols/urp/Protocol_Test.java
@@ -0,0 +1,317 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+package com.sun.star.lib.uno.protocols.urp;
+
+import com.sun.star.lib.uno.environments.remote.Message;
+import com.sun.star.lib.uno.environments.remote.IProtocol;
+import com.sun.star.lib.uno.environments.remote.ThreadId;
+import com.sun.star.lib.uno.typedesc.TypeDescription;
+import com.sun.star.uno.Any;
+import com.sun.star.uno.IBridge;
+import com.sun.star.uno.Type;
+import com.sun.star.uno.XInterface;
+import complexlib.ComplexTestCase;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.PipedInputStream;
+import java.io.PipedOutputStream;
+import java.util.LinkedList;
+
+public final class Protocol_Test extends ComplexTestCase {
+ public String[] getTestMethodNames() {
+ return new String[] { "test" };
+ }
+
+ public void test() throws Exception {
+ IBridge iBridge = new TestBridge();
+ PipedInputStream inA = new PipedInputStream();
+ PipedOutputStream outA = new PipedOutputStream(inA);
+ PipedInputStream inB = new PipedInputStream();
+ PipedOutputStream outB = new PipedOutputStream(inB);
+ Endpoint iSender = new Endpoint(iBridge, inA, outB);
+ Endpoint iReceiver = new Endpoint(iBridge, inB, outA);
+
+ TestObject testObject = new TestObject();
+ String oId = (String)iBridge.mapInterfaceTo(testObject, new Type(XInterface.class));
+
+ testCall(iSender, iReceiver, oId);
+ testCallWithInParameter(iSender, iReceiver, oId);
+ testCallWithOutParameter(iSender, iReceiver, oId);
+ testCallWithInOutParameter(iSender, iReceiver, oId);
+ testCallWithResult(iSender, iReceiver, oId);
+ testCallWhichRaisesException(iSender, iReceiver, oId);
+ testCallWithIn_Out_InOut_Paramters_and_result(iSender, iReceiver, oId);
+ testCallWhichReturnsAny(iSender, iReceiver, oId);
+ }
+
+ public void testCall(
+ Endpoint iSender, Endpoint iReceiver, String oId) throws Exception
+ {
+ // send an ordinary request
+ iSender.writeRequest(
+ oId, TypeDescription.getTypeDescription(TestXInterface.class),
+ "method", new ThreadId(new byte[] { 0, 1 }), new Object[0]);
+ iReceiver.readMessage();
+
+ // send a reply
+ iReceiver.writeReply(false, new ThreadId(new byte[] { 0, 1 }), null);
+ iSender.readMessage();
+ }
+
+ public void testCallWithInParameter(
+ Endpoint iSender, Endpoint iReceiver, String oId) throws Exception
+ {
+ // send an ordinary request
+ iSender.writeRequest(
+ oId, TypeDescription.getTypeDescription(TestXInterface.class),
+ "methodWithInParameter", new ThreadId(new byte[] { 0, 1 }),
+ new Object[] { "hallo" });
+ Message iMessage = iReceiver.readMessage();
+ Object[] t_params = iMessage.getArguments();
+ assure("", "hallo".equals((String)t_params[0]));
+
+ // send a reply
+ iReceiver.writeReply(false, new ThreadId(new byte[] { 0, 1 }), null);
+ iMessage = iSender.readMessage();
+ }
+
+ public void testCallWithOutParameter(
+ Endpoint iSender, Endpoint iReceiver, String oId) throws Exception
+ {
+ Object params[] = new Object[]{new String[1]};
+ iSender.writeRequest(
+ oId, TypeDescription.getTypeDescription(TestXInterface.class),
+ "methodWithOutParameter", new ThreadId(new byte[] { 0, 1 }),
+ params);
+ Message iMessage = iReceiver.readMessage();
+
+
+ Object[] t_params = iMessage.getArguments();
+ ((String [])t_params[0])[0] = "testString";
+
+ // send an exception as reply
+ iReceiver.writeReply(false, new ThreadId(new byte[] { 0, 1 }), null);
+ iSender.readMessage();
+
+ assure("", "testString".equals(((String [])params[0])[0]));
+ }
+
+ public void testCallWithInOutParameter(
+ Endpoint iSender, Endpoint iReceiver, String oId) throws Exception
+ {
+ Object params[] = new Object[]{new String[]{"inString"}};
+ iSender.writeRequest(
+ oId, TypeDescription.getTypeDescription(TestXInterface.class),
+ "methodWithInOutParameter", new ThreadId(new byte[] { 0, 1 }),
+ params);
+ Message iMessage = iReceiver.readMessage();
+
+
+ Object[] t_params = iMessage.getArguments();
+ assure("", "inString".equals(((String [])t_params[0])[0]));
+
+ // provide reply
+ ((String [])t_params[0])[0] = "outString";
+
+ // send an exception as reply
+ iReceiver.writeReply(false, new ThreadId(new byte[] { 0, 1 }), null);
+ iSender.readMessage();
+
+ assure("", "outString".equals(((String [])params[0])[0]));
+ }
+
+ public void testCallWithResult(
+ Endpoint iSender, Endpoint iReceiver, String oId) throws Exception
+ {
+ // send an ordinary request
+ iSender.writeRequest(
+ oId, TypeDescription.getTypeDescription(TestXInterface.class),
+ "methodWithResult", new ThreadId(new byte[] { 0, 1 }),
+ new Object[0]);
+ iReceiver.readMessage();
+
+ // send a reply
+ iReceiver.writeReply(
+ false, new ThreadId(new byte[] { 0, 1 }), "resultString");
+ Message iMessage = iSender.readMessage();
+ Object result = iMessage.getResult();
+
+ assure("", "resultString".equals(result));
+ }
+
+ public void testCallWhichRaisesException(
+ Endpoint iSender, Endpoint iReceiver, String oId) throws Exception
+ {
+ // send a second request
+ iSender.writeRequest(
+ oId, TypeDescription.getTypeDescription(TestXInterface.class),
+ "method", new ThreadId(new byte[] { 0, 1 }), new Object[0]);
+ iReceiver.readMessage();
+
+ // send an exception as reply
+ iReceiver.writeReply(
+ true, new ThreadId(new byte[] { 0, 1 }),
+ new com.sun.star.uno.RuntimeException("test the exception"));
+ Message iMessage = iSender.readMessage();
+
+ Object result = iMessage.getResult();
+
+ assure("", result instanceof com.sun.star.uno.RuntimeException);
+ }
+
+ public void testCallWithIn_Out_InOut_Paramters_and_result(
+ Endpoint iSender, Endpoint iReceiver, String oId) throws Exception
+ {
+ Object params[] = new Object[]{"hallo", new String[1], new String[]{"inOutString"}};
+ iSender.writeRequest(
+ oId, TypeDescription.getTypeDescription(TestXInterface.class),
+ "MethodWithIn_Out_InOut_Paramters_and_result",
+ new ThreadId(new byte[] { 0, 1 }), params);
+ Message iMessage = iReceiver.readMessage();
+
+ Object[] t_params = iMessage.getArguments();
+
+ assure("", "hallo".equals((String)t_params[0]));
+
+ assure("", "inOutString".equals(((String [])t_params[2])[0]));
+
+ ((String [])t_params[1])[0] = "outString";
+ ((String [])t_params[2])[0] = "inOutString_res";
+
+ // send an exception as reply
+ iReceiver.writeReply(
+ false, new ThreadId(new byte[] { 0, 1 }), "resultString");
+ iMessage = iSender.readMessage();
+
+ Object result = iMessage.getResult();
+ assure("", "outString".equals(((String [])params[1])[0]));
+
+ assure("", "inOutString_res".equals(((String [])params[2])[0]));
+
+ assure("", "resultString".equals(result));
+ }
+
+ public void testCallWhichReturnsAny(
+ Endpoint iSender, Endpoint iReceiver, String oId) throws Exception
+ {
+ // send an ordinary request
+ iSender.writeRequest(
+ oId, TypeDescription.getTypeDescription(TestXInterface.class),
+ "returnAny", new ThreadId(new byte[] { 0, 1 }), null);
+ iReceiver.readMessage();
+ // send a reply
+ iReceiver.writeReply(
+ false, new ThreadId(new byte[] { 0, 1 }), Any.VOID);
+ Message iMessage = iSender.readMessage();
+ Object result = iMessage.getResult();
+ assure("", result instanceof Any
+ && (TypeDescription.getTypeDescription(((Any) result).getType()).
+ getZClass() == void.class));
+
+ // send an ordinary request
+ iSender.writeRequest(
+ oId, TypeDescription.getTypeDescription(TestXInterface.class),
+ "returnAny", new ThreadId(new byte[] { 0, 1 }), null);
+ iReceiver.readMessage();
+ // send a reply
+ iReceiver.writeReply(
+ false, new ThreadId(new byte[] { 0, 1 }),
+ new Any(XInterface.class, null));
+ iMessage = iSender.readMessage();
+ result = iMessage.getResult();
+ assure("", result == null);
+
+ // send an ordinary request
+ iSender.writeRequest(
+ oId, TypeDescription.getTypeDescription(TestXInterface.class),
+ "returnAny", new ThreadId(new byte[] { 0, 1 }), null);
+ iReceiver.readMessage();
+ // send a reply
+ iReceiver.writeReply(
+ false, new ThreadId(new byte[] { 0, 1 }), new Integer(501));
+ iMessage = iSender.readMessage();
+ result = iMessage.getResult();
+ assure("", result.equals(new Integer(501)));
+ }
+
+ private static final class Endpoint {
+ public Endpoint(IBridge bridge, InputStream input, OutputStream output)
+ throws IOException
+ {
+ protocol = new urp(bridge, null, input, output);
+ new Thread() {
+ public void run() {
+ for (;;) {
+ Object o;
+ try {
+ o = protocol.readMessage();
+ } catch (IOException e) {
+ o = e;
+ }
+ synchronized (queue) {
+ queue.addLast(o);
+ }
+ }
+ }
+ }.start();
+ protocol.init();
+ }
+
+ public Message readMessage() throws IOException {
+ for (;;) {
+ synchronized (queue) {
+ if (!queue.isEmpty()) {
+ Object o = queue.removeFirst();
+ if (o instanceof Message) {
+ return (Message) o;
+ } else {
+ throw (IOException) o;
+ }
+ }
+ }
+ }
+ }
+
+ public boolean writeRequest(
+ String oid, TypeDescription type, String function, ThreadId tid,
+ Object[] arguments)
+ throws IOException
+ {
+ return protocol.writeRequest(oid, type, function, tid, arguments);
+ }
+
+ public void writeReply(boolean exception, ThreadId tid, Object result)
+ throws IOException
+ {
+ protocol.writeReply(exception, tid, result);
+ }
+
+ private final IProtocol protocol;
+ private final LinkedList queue = new LinkedList();
+ }
+}
diff --git a/jurt/test/com/sun/star/lib/uno/protocols/urp/TestBridge.java b/jurt/test/com/sun/star/lib/uno/protocols/urp/TestBridge.java
new file mode 100644
index 000000000000..34f864ae3085
--- /dev/null
+++ b/jurt/test/com/sun/star/lib/uno/protocols/urp/TestBridge.java
@@ -0,0 +1,115 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+package com.sun.star.lib.uno.protocols.urp;
+
+import java.io.IOException;
+
+import java.util.Hashtable;
+
+
+import com.sun.star.uno.IBridge;
+import com.sun.star.uno.IEnvironment;
+import com.sun.star.uno.Type;
+
+
+class TestBridge implements IBridge {
+ static public final boolean DEBUG = false;
+
+ Hashtable _hashtable = new Hashtable();
+
+ IEnvironment _source ;//= new com.sun.star.lib.uno.environments.java.java_environment(null);
+
+
+ class MyEnv implements IEnvironment {
+ public Object getContext() {
+ return null;
+ }
+
+ public String getName() {
+ return null;
+ }
+
+ public Object registerInterface(Object object, String oId[], Type type) {
+ return null;
+ }
+
+ public void revokeInterface(String oId, Type type) {
+ }
+
+ public Object getRegisteredInterface(String oid, Type type) {
+ Object object = _hashtable.get(oid);
+
+ if(DEBUG) System.err.println("##### " + getClass().getName() + ".getRegisteredInterface:" + oid + " " + object);
+
+ return object;
+ }
+
+ public String getRegisteredObjectIdentifier(Object object) {
+ return null;
+ }
+
+ public void list() {
+ }
+ }
+
+ TestBridge() {
+ _source = new MyEnv();
+ }
+
+ public Object mapInterfaceTo(Object object, Type type) {
+ if (object == null) {
+ return null;
+ } else {
+ String oid = ">" + object.toString() + type.toString() + "<";
+ _hashtable.put(oid, object);
+ return oid;
+ }
+ }
+
+ public Object mapInterfaceFrom(Object object, Type type) {
+ String oid = (String)object;
+
+ return _hashtable.get(oid);
+ }
+
+ public IEnvironment getSourceEnvironment() {
+ return _source;
+ }
+
+ public IEnvironment getTargetEnvironment() {
+ return null;
+ }
+
+ public void acquire() {}
+
+ public void release() {}
+
+ public void reset() throws IOException {}
+
+ public void dispose() throws InterruptedException, IOException {}
+}
+
diff --git a/jurt/test/com/sun/star/lib/uno/protocols/urp/TestObject.java b/jurt/test/com/sun/star/lib/uno/protocols/urp/TestObject.java
new file mode 100644
index 000000000000..f6be37207765
--- /dev/null
+++ b/jurt/test/com/sun/star/lib/uno/protocols/urp/TestObject.java
@@ -0,0 +1,70 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+package com.sun.star.lib.uno.protocols.urp;
+
+
+
+class TestObject implements TestXInterface {
+ public void method1( /*IN*/java.lang.Object itf ) throws com.sun.star.uno.Exception, com.sun.star.uno.RuntimeException {
+ }
+
+ public void method2( /*OUT*/java.lang.Object[] itf ) throws com.sun.star.uno.Exception, com.sun.star.uno.RuntimeException {
+ }
+
+ public void method3( /*INOUT*/java.lang.Object[] itf ) throws com.sun.star.uno.Exception, com.sun.star.uno.RuntimeException {
+ }
+
+ public Object method4( ) throws com.sun.star.uno.Exception, com.sun.star.uno.RuntimeException {
+ return null;
+ }
+
+ public Object returnAny( ) throws com.sun.star.uno.Exception, com.sun.star.uno.RuntimeException {
+ return null;
+ }
+
+
+ public void method() throws com.sun.star.uno.Exception, com.sun.star.uno.RuntimeException {
+ }
+
+ public void methodWithInParameter( /*IN*/String text ) throws com.sun.star.uno.Exception, com.sun.star.uno.RuntimeException {
+ }
+
+ public void methodWithOutParameter( /*OUT*/String[] text ) throws com.sun.star.uno.Exception, com.sun.star.uno.RuntimeException {
+ }
+
+ public void methodWithInOutParameter( /*INOUT*/String[] text ) throws com.sun.star.uno.Exception, com.sun.star.uno.RuntimeException {
+ }
+
+ public String methodWithResult( ) throws com.sun.star.uno.Exception, com.sun.star.uno.RuntimeException {
+ return "TestObject_resultString";
+ }
+
+ public String MethodWithIn_Out_InOut_Paramters_and_result( /*IN*/String text, /*OUT*/String[] outtext, /*INOUT*/String[] inouttext ) throws com.sun.star.uno.Exception, com.sun.star.uno.RuntimeException {
+ return "TestObject_resultString";
+ }
+}
+
diff --git a/jurt/test/com/sun/star/lib/uno/protocols/urp/interfaces.idl b/jurt/test/com/sun/star/lib/uno/protocols/urp/interfaces.idl
new file mode 100644
index 000000000000..1b267c434a0f
--- /dev/null
+++ b/jurt/test/com/sun/star/lib/uno/protocols/urp/interfaces.idl
@@ -0,0 +1,119 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#ifndef __com_sun_star_uno_XInterface_idl__
+#include <com/sun/star/uno/XInterface.idl>
+#endif
+
+#ifndef __com_sun_star_beans_XPropertySet_idl_
+#include <com/sun/star/beans/XPropertySet.idl>
+#endif
+
+#ifndef __com_sun_star_uno_Exception_idl__
+#include <com/sun/star/uno/Exception.idl>
+#endif
+
+#ifndef __com_sun_star_uno_Exception_idl__
+#include <com/sun/star/uno/Any.idl>
+#endif
+
+
+module com { module sun { module star { module lib { module uno {
+module protocols { module urp {
+
+ struct TestPrimitiveStruct {
+ boolean zBool;
+ short zShort;
+ unsigned short zUShort;
+ long zLong;
+ unsigned long zULong;
+ hyper zHyper;
+ unsigned hyper zUHyper;
+ float zFloat;
+ double zDouble;
+ char zChar;
+ byte zByte;
+ string zString;
+ any zAny;
+ };
+
+ struct TestPrimitiveSeqStruct {
+ sequence<boolean> zBool;
+ sequence<short> zShort;
+ sequence<unsigned short> zUShort;
+ sequence<long> zLong;
+ sequence<unsigned long> zULong;
+ sequence<hyper> zHyper;
+ sequence<unsigned hyper> zUHyper;
+ sequence<float> zFloat;
+ sequence<double> zDouble;
+ sequence<char> zChar;
+ sequence<byte> zByte;
+ sequence<string> zString;
+ sequence<any> zAny;
+ };
+
+ struct TestNestedStruct {
+ TestPrimitiveStruct primitiveStruct;
+ TestPrimitiveSeqStruct primitiveSeqStruct;
+ };
+
+ struct TestNestedSeqStruct {
+ sequence< sequence< long > > val;
+ };
+
+ interface TestXInterface : com::sun::star::uno::XInterface {
+ void method1([in] com::sun::star::uno::XInterface itf) raises( com::sun::star::uno::Exception );
+ void method2([out] com::sun::star::uno::XInterface itf) raises( com::sun::star::uno::Exception );
+ void method3([inout] com::sun::star::uno::XInterface itf) raises( com::sun::star::uno::Exception );
+ com::sun::star::uno::XInterface method4() raises( com::sun::star::uno::Exception );
+
+ any returnAny() raises( com::sun::star::uno::Exception );
+
+ void method() raises( com::sun::star::uno::Exception );
+ void methodWithInParameter([in] string text) raises( com::sun::star::uno::Exception );
+ void methodWithOutParameter([out] string text) raises( com::sun::star::uno::Exception );
+ void methodWithInOutParameter([inout] string text) raises( com::sun::star::uno::Exception );
+ string methodWithResult() raises( com::sun::star::uno::Exception );
+
+ string MethodWithIn_Out_InOut_Paramters_and_result([in] string text, [out] string outtext, [inout] string inouttext) raises( com::sun::star::uno::Exception );
+ };
+
+ struct TestInterfaceStruct
+ {
+ com::sun::star::uno::XInterface hallo;
+
+ com::sun::star::beans::XPropertySet hallo2;
+ };
+
+ enum TestEnum {
+ A = 7,
+ B = 8,
+ C = 11
+ };
+
+}; }; }; }; }; }; };
diff --git a/jurt/test/com/sun/star/lib/uno/protocols/urp/makefile.mk b/jurt/test/com/sun/star/lib/uno/protocols/urp/makefile.mk
new file mode 100644
index 000000000000..c6e66558b65d
--- /dev/null
+++ b/jurt/test/com/sun/star/lib/uno/protocols/urp/makefile.mk
@@ -0,0 +1,42 @@
+#*************************************************************************
+#
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# Copyright 2000, 2010 Oracle and/or its affiliates.
+#
+# OpenOffice.org - a multi-platform office productivity suite
+#
+# This file is part of OpenOffice.org.
+#
+# OpenOffice.org is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Lesser General Public License version 3
+# only, as published by the Free Software Foundation.
+#
+# OpenOffice.org is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Lesser General Public License version 3 for more details
+# (a copy is included in the LICENSE file that accompanied this code).
+#
+# You should have received a copy of the GNU Lesser General Public License
+# version 3 along with OpenOffice.org. If not, see
+# <http://www.openoffice.org/license.html>
+# for a copy of the LGPLv3 License.
+#
+#*************************************************************************
+PRJ := ..$/..$/..$/..$/..$/..$/..$/..
+PRJNAME := jurt
+TARGET := test_com_sun_star_lib_uno_protocols_urp
+
+PACKAGE := com$/sun$/star$/lib$/uno$/protocols$/urp
+JAVATESTFILES := \
+ Cache_Test.java \
+ Marshaling_Test.java \
+ Protocol_Test.java
+JAVAFILES := \
+ TestBridge.java \
+ TestObject.java
+JARFILES := ridl.jar
+IDLTESTFILES := interfaces.idl
+
+.INCLUDE: javaunittest.mk