diff options
author | Rüdiger Timm <rt@openoffice.org> | 2006-12-01 13:56:28 +0000 |
---|---|---|
committer | Rüdiger Timm <rt@openoffice.org> | 2006-12-01 13:56:28 +0000 |
commit | 9daf39d9bb172d2be1e7c4839749c20301bd20b8 (patch) | |
tree | d08593afd340862aae800ae04b7e90f024b2f4c3 /jurt | |
parent | 92d1fdb68227bf37340507d35d91f347a5e3f54c (diff) |
INTEGRATION: CWS sb23 (1.2.26); FILE MERGED
2006/08/18 16:29:49 sb 1.2.26.5: RESYNC: (1.2-1.3); FILE MERGED
2005/03/14 10:55:39 sb 1.2.26.4: #i35277# Further cleanup.
2005/03/08 14:29:13 sb 1.2.26.3: #i35277# More cleanup.
2005/02/18 09:21:53 sb 1.2.26.2: #i35277# More cleanup; functionality moved from java_remote_bridge to urp, so that urp can autonomously handle protocol property requests.
2005/02/16 16:54:45 sb 1.2.26.1: #i35277# More cleanup.
Diffstat (limited to 'jurt')
-rw-r--r-- | jurt/test/com/sun/star/lib/uno/protocols/urp/Protocol_Test.java | 425 |
1 files changed, 196 insertions, 229 deletions
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 index d4895c6b87bc..40f307ab6139 100644 --- 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 @@ -4,9 +4,9 @@ * * $RCSfile: Protocol_Test.java,v $ * - * $Revision: 1.3 $ + * $Revision: 1.4 $ * - * last change: $Author: rt $ $Date: 2005-09-07 19:15:15 $ + * last change: $Author: rt $ $Date: 2006-12-01 14:56:28 $ * * The Contents of this file are made available subject to * the terms of GNU Lesser General Public License Version 2.1. @@ -34,7 +34,7 @@ ************************************************************************/ package com.sun.star.lib.uno.protocols.urp; -import com.sun.star.lib.uno.environments.remote.IMessage; +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; @@ -43,257 +43,180 @@ import com.sun.star.uno.IBridge; import com.sun.star.uno.Type; import com.sun.star.uno.XInterface; import complexlib.ComplexTestCase; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.DataOutputStream; -import java.lang.reflect.Constructor; +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 getTestObjectName() { - return getClass().getName(); - } - public String[] getTestMethodNames() { return new String[] { "test" }; } public void test() throws Exception { - String protocolDescription = "urp"; - - IBridge iBrige = new TestBridge(); - - Class protocol_class = Class.forName("com.sun.star.lib.uno.protocols." + protocolDescription + "." + protocolDescription); - Constructor protocol_constructor = protocol_class.getConstructor(new Class[] {IBridge.class}); - -// XInstanceProvider xInstanceProvider = new InstanceProvider(); - IProtocol iSender = (IProtocol)protocol_constructor.newInstance(new Object[]{iBrige}); - IProtocol iReciever = (IProtocol)protocol_constructor.newInstance(new Object[]{iBrige}); - - - + 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)iBrige.mapInterfaceTo(testObject, new Type(XInterface.class)); - - testCall(iSender, iReciever, oId); - testCallWithInParameter(iSender, iReciever, oId); - testCallWithOutParameter(iSender, iReciever, oId); - testCallWithInOutParameter(iSender, iReciever, oId); - testCallWithResult(iSender, iReciever, oId); - testCallWhichRaisesException(iSender, iReciever, oId); - testCallWithIn_Out_InOut_Paramters_and_result(iSender, iReciever, oId); - testCallWhichReturnsAny(iSender, iReciever, oId); + 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); } - static ByteArrayInputStream sendRequest(IProtocol sender, - String oid, - TypeDescription typeDescription, - String operation, - ThreadId threadId, - Object params[], - Boolean synchron[], - Boolean mustReply[]) throws Exception + public void testCall( + Endpoint iSender, Endpoint iReceiver, String oId) throws Exception { - sender.writeRequest(oid, typeDescription, operation, threadId, params, synchron, mustReply); - - ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); - DataOutputStream dataOutputStream = new DataOutputStream(byteArrayOutputStream); - - sender.flush(dataOutputStream); - - return new ByteArrayInputStream(byteArrayOutputStream.toByteArray()); - } - - static ByteArrayInputStream sendReply(IProtocol sender, boolean exception, ThreadId threadId, Object result) throws Exception { - sender.writeReply(exception, - threadId, - result); - - - ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); - DataOutputStream dataOutputStream = new DataOutputStream(byteArrayOutputStream); - - sender.flush(dataOutputStream); - - return new ByteArrayInputStream(byteArrayOutputStream.toByteArray()); - } - - static IMessage receiveMessage(IProtocol receiver, ByteArrayInputStream byteArrayInputStream) throws Exception { - return receiver.readMessage(byteArrayInputStream); - } - - public void testCall(IProtocol iSender, IProtocol iReciever, String oId) throws Exception { // send an ordinary request - IMessage iMessage = receiveMessage(iReciever, sendRequest(iSender, - oId, - TypeDescription.getTypeDescription(TestXInterface.class), - "method", - new ThreadId(new byte[]{0, 1}), - new Object[0], - new Boolean[1], - new Boolean[1])); - iMessage.getData(new Object[1][]); + iSender.writeRequest( + oId, TypeDescription.getTypeDescription(TestXInterface.class), + "method", new ThreadId(new byte[] { 0, 1 }), new Object[0]); + iReceiver.readMessage(); // send a reply - iMessage = receiveMessage(iSender, sendReply(iReciever, - false, - new ThreadId(new byte[]{0, 1}), - null)); - iMessage.getData(new Object[1][]); + iReceiver.writeReply(false, new ThreadId(new byte[] { 0, 1 }), null); + iSender.readMessage(); } - public void testCallWithInParameter(IProtocol iSender, IProtocol iReciever, String oId) throws Exception { + public void testCallWithInParameter( + Endpoint iSender, Endpoint iReceiver, String oId) throws Exception + { // send an ordinary request - IMessage iMessage = receiveMessage(iReciever, sendRequest(iSender, - oId, - TypeDescription.getTypeDescription(TestXInterface.class), - "methodWithInParameter", - new ThreadId(new byte[]{0, 1}), - new Object[]{"hallo"}, - new Boolean[1], - new Boolean[1])); - Object t_params[][] = new Object[1][]; - iMessage.getData(t_params); - assure("", "hallo".equals((String)t_params[0][0])); + 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 - iMessage = receiveMessage(iSender, sendReply(iReciever, - false, - new ThreadId(new byte[]{0, 1}), - null)); - iMessage.getData(new Object[1][]); + iReceiver.writeReply(false, new ThreadId(new byte[] { 0, 1 }), null); + iMessage = iSender.readMessage(); } - public void testCallWithOutParameter(IProtocol iSender, IProtocol iReciever, String oId) throws Exception { + public void testCallWithOutParameter( + Endpoint iSender, Endpoint iReceiver, String oId) throws Exception + { Object params[] = new Object[]{new String[1]}; - IMessage iMessage = receiveMessage(iReciever, sendRequest(iSender, - oId, - TypeDescription.getTypeDescription(TestXInterface.class), - "methodWithOutParameter", - new ThreadId(new byte[]{0, 1}), - params, - new Boolean[1], - new Boolean[1])); + iSender.writeRequest( + oId, TypeDescription.getTypeDescription(TestXInterface.class), + "methodWithOutParameter", new ThreadId(new byte[] { 0, 1 }), + params); + Message iMessage = iReceiver.readMessage(); - Object t_params[][] = new Object[1][]; - iMessage.getData(t_params); - ((String [])t_params[0][0])[0] = "testString"; + Object[] t_params = iMessage.getArguments(); + ((String [])t_params[0])[0] = "testString"; // send an exception as reply - iMessage = receiveMessage(iSender, sendReply(iReciever, - false, - new ThreadId(new byte[]{0, 1}), - null)); - - iMessage.getData(new Object[1][]); + iReceiver.writeReply(false, new ThreadId(new byte[] { 0, 1 }), null); + iSender.readMessage(); assure("", "testString".equals(((String [])params[0])[0])); } - public void testCallWithInOutParameter(IProtocol iSender, IProtocol iReciever, String oId) throws Exception { + public void testCallWithInOutParameter( + Endpoint iSender, Endpoint iReceiver, String oId) throws Exception + { Object params[] = new Object[]{new String[]{"inString"}}; - IMessage iMessage = receiveMessage(iReciever, sendRequest(iSender, - oId, - TypeDescription.getTypeDescription(TestXInterface.class), - "methodWithInOutParameter", - new ThreadId(new byte[]{0, 1}), - params, - new Boolean[1], - new Boolean[1])); + iSender.writeRequest( + oId, TypeDescription.getTypeDescription(TestXInterface.class), + "methodWithInOutParameter", new ThreadId(new byte[] { 0, 1 }), + params); + Message iMessage = iReceiver.readMessage(); - Object t_params[][] = new Object[1][]; - iMessage.getData(t_params); - assure("", "inString".equals(((String [])t_params[0][0])[0])); + Object[] t_params = iMessage.getArguments(); + assure("", "inString".equals(((String [])t_params[0])[0])); // provide reply - ((String [])t_params[0][0])[0] = "outString"; + ((String [])t_params[0])[0] = "outString"; // send an exception as reply - iMessage = receiveMessage(iSender, sendReply(iReciever, - false, - new ThreadId(new byte[]{0, 1}), - null)); - - iMessage.getData(new Object[1][]); + iReceiver.writeReply(false, new ThreadId(new byte[] { 0, 1 }), null); + iSender.readMessage(); assure("", "outString".equals(((String [])params[0])[0])); } - public void testCallWithResult(IProtocol iSender, IProtocol iReciever, String oId) throws Exception { + public void testCallWithResult( + Endpoint iSender, Endpoint iReceiver, String oId) throws Exception + { // send an ordinary request - IMessage iMessage = receiveMessage(iReciever, sendRequest(iSender, - oId, - TypeDescription.getTypeDescription(TestXInterface.class), - "methodWithResult", - new ThreadId(new byte[]{0, 1}), - new Object[0], - new Boolean[1], - new Boolean[1])); - iMessage.getData(new Object[1][]); + iSender.writeRequest( + oId, TypeDescription.getTypeDescription(TestXInterface.class), + "methodWithResult", new ThreadId(new byte[] { 0, 1 }), + new Object[0]); + iReceiver.readMessage(); // send a reply - iMessage = receiveMessage(iSender, sendReply(iReciever, - false, - new ThreadId(new byte[]{0, 1}), - "resultString")); - Object result = iMessage.getData(new Object[1][]); + 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(IProtocol iSender, IProtocol iReciever, String oId) throws Exception { + public void testCallWhichRaisesException( + Endpoint iSender, Endpoint iReceiver, String oId) throws Exception + { // send a second request - IMessage iMessage = receiveMessage(iReciever, sendRequest(iSender, - oId, - TypeDescription.getTypeDescription(TestXInterface.class), - "method", - new ThreadId(new byte[]{0, 1}), - new Object[0], - new Boolean[1], - new Boolean[1])); - iMessage.getData(new Object[1][]); + iSender.writeRequest( + oId, TypeDescription.getTypeDescription(TestXInterface.class), + "method", new ThreadId(new byte[] { 0, 1 }), new Object[0]); + iReceiver.readMessage(); // send an exception as reply - iMessage = receiveMessage(iSender, sendReply(iReciever, - true, - new ThreadId(new byte[]{0, 1}), - new com.sun.star.uno.RuntimeException("test the exception"))); + 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.getData(new Object[1][]); + Object result = iMessage.getResult(); assure("", result instanceof com.sun.star.uno.RuntimeException); } - public void testCallWithIn_Out_InOut_Paramters_and_result(IProtocol iSender, IProtocol iReciever, String oId) throws Exception { + 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"}}; - IMessage iMessage = receiveMessage(iReciever, sendRequest(iSender, - oId, - TypeDescription.getTypeDescription(TestXInterface.class), - "MethodWithIn_Out_InOut_Paramters_and_result", - new ThreadId(new byte[]{0, 1}), - params, - new Boolean[1], - new Boolean[1])); + 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[][] = new Object[1][]; - iMessage.getData(t_params); + Object[] t_params = iMessage.getArguments(); - assure("", "hallo".equals((String)t_params[0][0])); + assure("", "hallo".equals((String)t_params[0])); - assure("", "inOutString".equals(((String [])t_params[0][2])[0])); + assure("", "inOutString".equals(((String [])t_params[2])[0])); - ((String [])t_params[0][1])[0] = "outString"; - ((String [])t_params[0][2])[0] = "inOutString_res"; + ((String [])t_params[1])[0] = "outString"; + ((String [])t_params[2])[0] = "inOutString_res"; // send an exception as reply - iMessage = receiveMessage(iSender, sendReply(iReciever, - false, - new ThreadId(new byte[]{0, 1}), - "resultString")); + iReceiver.writeReply( + false, new ThreadId(new byte[] { 0, 1 }), "resultString"); + iMessage = iSender.readMessage(); - Object result = iMessage.getData(new Object[1][]); + Object result = iMessage.getResult(); assure("", "outString".equals(((String [])params[1])[0])); assure("", "inOutString_res".equals(((String [])params[2])[0])); @@ -301,58 +224,102 @@ public final class Protocol_Test extends ComplexTestCase { assure("", "resultString".equals(result)); } - public void testCallWhichReturnsAny(IProtocol iSender, IProtocol iReciever, String oId) throws Exception { + public void testCallWhichReturnsAny( + Endpoint iSender, Endpoint iReceiver, String oId) throws Exception + { // send an ordinary request - IMessage iMessage = receiveMessage(iReciever, sendRequest(iSender, - oId, - TypeDescription.getTypeDescription(TestXInterface.class), - "returnAny", - new ThreadId(new byte[]{0, 1}), - null, - new Boolean[1], - new Boolean[1])); + iSender.writeRequest( + oId, TypeDescription.getTypeDescription(TestXInterface.class), + "returnAny", new ThreadId(new byte[] { 0, 1 }), null); + iReceiver.readMessage(); // send a reply - iMessage = receiveMessage(iSender, sendReply(iReciever, - false, - new ThreadId(new byte[]{0, 1}), - new Any(Void.class, null))); - Object result = iMessage.getData(new Object[1][]); + 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 - iMessage = receiveMessage(iReciever, sendRequest(iSender, - oId, - TypeDescription.getTypeDescription(TestXInterface.class), - "returnAny", - new ThreadId(new byte[]{0, 1}), - null, - new Boolean[1], - new Boolean[1])); + iSender.writeRequest( + oId, TypeDescription.getTypeDescription(TestXInterface.class), + "returnAny", new ThreadId(new byte[] { 0, 1 }), null); + iReceiver.readMessage(); // send a reply - iMessage = receiveMessage(iSender, sendReply(iReciever, - false, - new ThreadId(new byte[]{0, 1}), - new Any(XInterface.class, null))); - result = iMessage.getData(new Object[1][]); + 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 - iMessage = receiveMessage(iReciever, sendRequest(iSender, - oId, - TypeDescription.getTypeDescription(TestXInterface.class), - "returnAny", - new ThreadId(new byte[]{0, 1}), - null, - new Boolean[1], - new Boolean[1])); + iSender.writeRequest( + oId, TypeDescription.getTypeDescription(TestXInterface.class), + "returnAny", new ThreadId(new byte[] { 0, 1 }), null); + iReceiver.readMessage(); // send a reply - iMessage = receiveMessage(iSender, sendReply(iReciever, - false, - new ThreadId(new byte[]{0, 1}), - new Integer(501))); - result = iMessage.getData(new Object[1][]); + 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(); + } } |