diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:06:44 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:06:44 +0000 |
commit | ed5640d8b587fbcfed7dd7967f3de04b37a76f26 (patch) | |
tree | 7a5f7c6c9d02226d7471cb3cc8fbbf631b415303 /ridljar/test/com/sun/star/lib/uno/protocols | |
parent | Initial commit. (diff) | |
download | libreoffice-ed5640d8b587fbcfed7dd7967f3de04b37a76f26.tar.xz libreoffice-ed5640d8b587fbcfed7dd7967f3de04b37a76f26.zip |
Adding upstream version 4:7.4.7.upstream/4%7.4.7upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'ridljar/test/com/sun/star/lib/uno/protocols')
6 files changed, 1068 insertions, 0 deletions
diff --git a/ridljar/test/com/sun/star/lib/uno/protocols/urp/Cache_Test.java b/ridljar/test/com/sun/star/lib/uno/protocols/urp/Cache_Test.java new file mode 100644 index 000000000..a7d93733d --- /dev/null +++ b/ridljar/test/com/sun/star/lib/uno/protocols/urp/Cache_Test.java @@ -0,0 +1,134 @@ +/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * 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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +package com.sun.star.lib.uno.protocols.urp; + +import org.junit.Test; +import static org.junit.Assert.*; + +public final class Cache_Test { + @Test public void test0() { + Cache c = new Cache(0); + boolean[] f = new boolean[1]; + int i; + i = c.add(f, "a"); + assertTrue(i == Cache.NOT_CACHED && !f[0]); + i = c.add(f, "a"); + assertTrue(i == Cache.NOT_CACHED && !f[0]); + i = c.add(f, "b"); + assertTrue(i == Cache.NOT_CACHED && !f[0]); + i = c.add(f, "a"); + assertTrue(i == Cache.NOT_CACHED && !f[0]); + } + + @Test public void test1() { + Cache c = new Cache(1); + boolean[] f = new boolean[1]; + int i; + i = c.add(f, "a"); + assertTrue(i == 0 && !f[0]); + i = c.add(f, "a"); + assertTrue(i == 0 && f[0]); + i = c.add(f, "b"); + assertTrue(i == 0 && !f[0]); + i = c.add(f, "b"); + assertTrue(i == 0 && f[0]); + i = c.add(f, "a"); + assertTrue(i == 0 && !f[0]); + } + + @Test public void test2() { + Cache c = new Cache(2); + boolean[] f = new boolean[1]; + int i; + i = c.add(f, "a"); + assertTrue(i == 0 && !f[0]); + i = c.add(f, "a"); + assertTrue(i == 0 && f[0]); + i = c.add(f, "b"); + assertTrue(i == 1 && !f[0]); + i = c.add(f, "b"); + assertTrue(i == 1 && f[0]); + i = c.add(f, "a"); + assertTrue(i == 0 && f[0]); + i = c.add(f, "c"); + assertTrue(i == 1 && !f[0]); + i = c.add(f, "b"); + assertTrue(i == 0 && !f[0]); + } + + @Test public void test3() { + Cache c = new Cache(3); + boolean[] f = new boolean[1]; + int i; + i = c.add(f, "a"); + assertTrue(i == 0 && !f[0]); + i = c.add(f, "a"); + assertTrue(i == 0 && f[0]); + i = c.add(f, "b"); + assertTrue(i == 1 && !f[0]); + i = c.add(f, "a"); + assertTrue(i == 0 && f[0]); + i = c.add(f, "c"); + assertTrue(i == 2 && !f[0]); + i = c.add(f, "d"); + assertTrue(i == 1 && !f[0]); + i = c.add(f, "d"); + assertTrue(i == 1 && f[0]); + } + + @Test public void testNothingLostFromLruList() { + // Regardless in what order arbitrary values from 0, ..., 3 are inserted + // into a size-4 cache, afterwards adding -1, ..., -4 must return each + // possible index in the range from 0, ..., 3 exactly once (so their sum + // must be 6); this code systematically tests all such arbitrary ways up + // to length 8 (the code arguably violates recommendations for writing + // good tests, but actually helped track down an error in the Cache + // implementation): + int[] a = new int[8]; + for (int i = 0; i < a.length; ++i) { + for (int j = 0; j < i; ++j) { + a[j] = 0; + } + for (;;) { + Cache c = new Cache(4); + for (int k = 0; k < i; ++k) { + c.add(new boolean[1], a[k]); + } + assertEquals( + 6, + (c.add(new boolean[1], -1) + c.add(new boolean[1], -2) + + c.add(new boolean[1], -3) + c.add(new boolean[1], -4))); + int j = i - 1; + while (j >= 0 && a[j] == 3) { + --j; + } + if (j < 0) { + break; + } + ++a[j]; + for (int k = j + 1; k < i; ++k) { + a[k] = 0; + } + } + } + } +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/ridljar/test/com/sun/star/lib/uno/protocols/urp/Marshaling_Test.java b/ridljar/test/com/sun/star/lib/uno/protocols/urp/Marshaling_Test.java new file mode 100644 index 000000000..5cf5f73e6 --- /dev/null +++ b/ridljar/test/com/sun/star/lib/uno/protocols/urp/Marshaling_Test.java @@ -0,0 +1,353 @@ +/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * 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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +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.Type; +import com.sun.star.uno.TypeClass; +import com.sun.star.uno.XInterface; +import java.lang.reflect.Array; +import java.lang.reflect.Field; +import java.lang.reflect.Modifier; +import org.junit.Test; +import static org.junit.Assert.*; + +public final class Marshaling_Test { + @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[]{Integer.valueOf(1), new Double(2) }; + + + Object data[] = new Object[] { + new com.sun.star.uno.RuntimeException("testRuntimeException"), + new com.sun.star.uno.Exception("testException"), + Boolean.TRUE, + Byte.valueOf((byte)47), + new Character('k'), + new Double(0.12345), + TestEnum.B, + new Float(0.5678), + Integer.valueOf(0), + Integer.valueOf(128), + Integer.valueOf(0x0f00), + Integer.valueOf(0x0f0000), + Integer.valueOf(0x0f000000), + Integer.valueOf(-128), + Integer.valueOf(0xff00), + Integer.valueOf(0xff0000), + Integer.valueOf(0xff000000), + Long.valueOf(666L), + Short.valueOf((short)444), + "blabla", + Integer.valueOf(10), // Any as object + Integer.valueOf(10), // Any as object + new Any(new Type(Integer.class), Integer.valueOf(10)), // Any as Any + new Any(new Type(Integer.class), Integer.valueOf(10)), // Any as Any + null, + new TestPrimitiveStruct(), + x, + new byte[]{1,2,3,4,5,6,7}, // primitive sequence + new int[]{7,6,5,4,3,2,1}, // primitive sequence + new Object[]{Integer.valueOf(123), "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(); + + assertTrue(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))) + { + 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(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; + } +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/ridljar/test/com/sun/star/lib/uno/protocols/urp/Protocol_Test.java b/ridljar/test/com/sun/star/lib/uno/protocols/urp/Protocol_Test.java new file mode 100644 index 000000000..cda58aad8 --- /dev/null +++ b/ridljar/test/com/sun/star/lib/uno/protocols/urp/Protocol_Test.java @@ -0,0 +1,311 @@ +/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * 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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +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 java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.io.PipedInputStream; +import java.io.PipedOutputStream; +import java.util.LinkedList; +import org.junit.Test; +import static org.junit.Assert.*; + +public final class Protocol_Test { + @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(); + assertEquals("hallo", 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(); + + assertEquals("testString", ((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(); + assertEquals("inString", ((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(); + + assertEquals("outString", ((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(); + + assertEquals("resultString", 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(); + + assertTrue(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(); + + assertEquals("hallo", t_params[0]); + + assertEquals("inOutString", ((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(); + assertEquals("outString", ((String [])params[1])[0]); + + assertEquals("inOutString_res", ((String [])params[2])[0]); + + assertEquals("resultString", 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(); + assertTrue( + 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(); + assertNull(result); + + // 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 }), Integer.valueOf(501)); + iMessage = iSender.readMessage(); + result = iMessage.getResult(); + assertEquals(501, result); + } + + private static final class Endpoint { + public Endpoint(IBridge bridge, InputStream input, OutputStream output) + throws IOException + { + protocol = new urp(bridge, null, input, output); + new Thread() { + @Override + 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<Object> queue = new LinkedList<Object>(); + } +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/ridljar/test/com/sun/star/lib/uno/protocols/urp/TestBridge.java b/ridljar/test/com/sun/star/lib/uno/protocols/urp/TestBridge.java new file mode 100644 index 000000000..acd1b3948 --- /dev/null +++ b/ridljar/test/com/sun/star/lib/uno/protocols/urp/TestBridge.java @@ -0,0 +1,106 @@ +/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * 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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +package com.sun.star.lib.uno.protocols.urp; + +import java.io.IOException; + +import java.util.HashMap; + + +import com.sun.star.uno.IBridge; +import com.sun.star.uno.IEnvironment; +import com.sun.star.uno.Type; + + +class TestBridge implements IBridge { + private static final boolean DEBUG = false; + + private final HashMap<String,Object> _hashtable = new HashMap<String,Object>(); + + private IEnvironment _source ;//= new com.sun.star.lib.uno.environments.java.java_environment(null); + + + private 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 dispose() throws InterruptedException, IOException {} +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/ridljar/test/com/sun/star/lib/uno/protocols/urp/TestObject.java b/ridljar/test/com/sun/star/lib/uno/protocols/urp/TestObject.java new file mode 100644 index 000000000..f36710e1d --- /dev/null +++ b/ridljar/test/com/sun/star/lib/uno/protocols/urp/TestObject.java @@ -0,0 +1,63 @@ +/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * 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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +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"; + } +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/ridljar/test/com/sun/star/lib/uno/protocols/urp/interfaces.idl b/ridljar/test/com/sun/star/lib/uno/protocols/urp/interfaces.idl new file mode 100644 index 000000000..4ea1c8ebc --- /dev/null +++ b/ridljar/test/com/sun/star/lib/uno/protocols/urp/interfaces.idl @@ -0,0 +1,101 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * 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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <com/sun/star/uno/XInterface.idl> +#include <com/sun/star/beans/XPropertySet.idl> +#include <com/sun/star/uno/Exception.idl> +#include <com/sun/star/uno/Any.idl> + +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 + }; + +}; }; }; }; }; }; }; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |