diff options
author | Samuel Mehrbrodt <Samuel.Mehrbrodt@cib.de> | 2020-02-06 08:40:43 +0100 |
---|---|---|
committer | Samuel Mehrbrodt <Samuel.Mehrbrodt@cib.de> | 2020-02-10 09:48:05 +0100 |
commit | faa59a82cebd69ba4d5b665f00983b9d374ac15c (patch) | |
tree | f0fdc147ad79d2926f04700eb552e1f9fad4525a /jurt | |
parent | 57eee86bab2efd63b7eec9d73a86b1cc0422de29 (diff) |
Cleanup: Move unit tests to ridljar
Follow-up cleanup for ae855bf48163ff64d94cfc34aff8e37abdb5518d
Change-Id: Ibec2fe89d70d6001af7d75c5eb4081b5b2af30e6
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/88073
Tested-by: Jenkins
Reviewed-by: Samuel Mehrbrodt <Samuel.Mehrbrodt@cib.de>
Diffstat (limited to 'jurt')
34 files changed, 0 insertions, 4181 deletions
diff --git a/jurt/CustomTarget_test_urp.mk b/jurt/CustomTarget_test_urp.mk deleted file mode 100644 index ce2fa371e89c..000000000000 --- a/jurt/CustomTarget_test_urp.mk +++ /dev/null @@ -1,26 +0,0 @@ -# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*- -# -# This file is part of the LibreOffice project. -# -# This Source Code Form is subject to the terms of the Mozilla Public -# License, v. 2.0. If a copy of the MPL was not distributed with this -# file, You can obtain one at http://mozilla.org/MPL/2.0/. -# - -$(eval $(call gb_CustomTarget_CustomTarget,jurt/test/com/sun/star/lib/uno/protocols/urp)) - -jurt_TESTURP := $(call gb_CustomTarget_get_workdir,jurt/test/com/sun/star/lib/uno/protocols/urp) - -$(call gb_CustomTarget_get_target,jurt/test/com/sun/star/lib/uno/protocols/urp) : $(jurt_TESTURP)/done - -$(jurt_TESTURP)/done : \ - $(call gb_UnoApiTarget_get_target,test_urp) \ - $(call gb_UnoApi_get_target,udkapi) \ - $(call gb_Executable_get_runtime_dependencies,javamaker) - $(call gb_Output_announce,$(subst $(WORKDIR)/,,$@),$(true),JVM,1) - rm -rf $(jurt_TESTURP) && \ - $(call gb_Helper_execute,javamaker -O$(jurt_TESTURP) -nD $< \ - -X$(call gb_UnoApi_get_target,udkapi)) && \ - touch $@ - -# vim:set shiftwidth=4 tabstop=4 noexpandtab: diff --git a/jurt/InternalUnoApi_test_urp.mk b/jurt/InternalUnoApi_test_urp.mk deleted file mode 100644 index 637ce1b606e3..000000000000 --- a/jurt/InternalUnoApi_test_urp.mk +++ /dev/null @@ -1,16 +0,0 @@ -# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*- -# -# This file is part of the LibreOffice project. -# -# This Source Code Form is subject to the terms of the Mozilla Public -# License, v. 2.0. If a copy of the MPL was not distributed with this -# file, You can obtain one at http://mozilla.org/MPL/2.0/. -# - -$(eval $(call gb_InternalUnoApi_InternalUnoApi,test_urp,jurt/test/com/sun/star/lib/uno/protocols/urp/interfaces.idl)) - -$(eval $(call gb_InternalUnoApi_use_api,test_urp,\ - udkapi \ -)) - -# vim: set noet sw=4 ts=4: diff --git a/jurt/JunitTest_bridgefactory.mk b/jurt/JunitTest_bridgefactory.mk deleted file mode 100644 index 67ad789bb26e..000000000000 --- a/jurt/JunitTest_bridgefactory.mk +++ /dev/null @@ -1,28 +0,0 @@ -# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*- -# -# This file is part of the LibreOffice project. -# -# This Source Code Form is subject to the terms of the Mozilla Public -# License, v. 2.0. If a copy of the MPL was not distributed with this -# file, You can obtain one at http://mozilla.org/MPL/2.0/. -# - -$(eval $(call gb_JunitTest_JunitTest,jurt_bridgefactory)) - -$(eval $(call gb_Jar_use_customtargets,jurt_bridgefactory, \ - ridljar/javamaker \ -)) - -$(eval $(call gb_JunitTest_use_jar_classset,jurt_bridgefactory,ridl)) - -$(eval $(call gb_JunitTest_add_classpath,jurt_bridgefactory,$(call gb_CustomTarget_get_workdir,ridljar/javamaker))) - -$(eval $(call gb_JunitTest_add_sourcefiles,jurt_bridgefactory,\ - jurt/test/com/sun/star/comp/bridgefactory/BridgeFactory_Test \ -)) - -$(eval $(call gb_JunitTest_add_classes,jurt_bridgefactory,\ - com.sun.star.comp.bridgefactory.BridgeFactory_Test \ -)) - -# vim:set noet sw=4 ts=4: diff --git a/jurt/JunitTest_connections.mk b/jurt/JunitTest_connections.mk deleted file mode 100644 index b5528121fab4..000000000000 --- a/jurt/JunitTest_connections.mk +++ /dev/null @@ -1,28 +0,0 @@ -# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*- -# -# This file is part of the LibreOffice project. -# -# This Source Code Form is subject to the terms of the Mozilla Public -# License, v. 2.0. If a copy of the MPL was not distributed with this -# file, You can obtain one at http://mozilla.org/MPL/2.0/. -# - -$(eval $(call gb_JunitTest_JunitTest,jurt_connections)) - -$(eval $(call gb_Jar_use_customtargets,jurt_connections, \ - ridljar/javamaker \ -)) - -$(eval $(call gb_JunitTest_use_jar_classset,jurt_connections,ridl)) - -$(eval $(call gb_JunitTest_add_classpath,jurt_connections,$(call gb_CustomTarget_get_workdir,ridljar/javamaker))) - -$(eval $(call gb_JunitTest_add_sourcefiles,jurt_connections,\ - jurt/test/com/sun/star/comp/connections/PipedConnection_Test \ -)) - -$(eval $(call gb_JunitTest_add_classes,jurt_connections,\ - com.sun.star.comp.connections.PipedConnection_Test \ -)) - -# vim:set noet sw=4 ts=4: diff --git a/jurt/JunitTest_java.mk b/jurt/JunitTest_java.mk deleted file mode 100644 index 715bc1b5fdab..000000000000 --- a/jurt/JunitTest_java.mk +++ /dev/null @@ -1,28 +0,0 @@ -# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*- -# -# This file is part of the LibreOffice project. -# -# This Source Code Form is subject to the terms of the Mozilla Public -# License, v. 2.0. If a copy of the MPL was not distributed with this -# file, You can obtain one at http://mozilla.org/MPL/2.0/. -# - -$(eval $(call gb_JunitTest_JunitTest,jurt_java)) - -$(eval $(call gb_Jar_use_customtargets,jurt_java, \ - ridljar/javamaker \ -)) - -$(eval $(call gb_JunitTest_use_jar_classset,jurt_java,ridl)) - -$(eval $(call gb_JunitTest_add_classpath,jurt_java,$(call gb_CustomTarget_get_workdir,ridljar/javamaker))) - -$(eval $(call gb_JunitTest_add_sourcefiles,jurt_java,\ - jurt/test/com/sun/star/lib/uno/environments/java/java_environment_Test \ -)) - -$(eval $(call gb_JunitTest_add_classes,jurt_java,\ - com.sun.star.lib.uno.environments.java.java_environment_Test \ -)) - -# vim:set noet sw=4 ts=4: diff --git a/jurt/JunitTest_java_remote.mk b/jurt/JunitTest_java_remote.mk deleted file mode 100644 index d96a6306fa88..000000000000 --- a/jurt/JunitTest_java_remote.mk +++ /dev/null @@ -1,36 +0,0 @@ -# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*- -# -# This file is part of the LibreOffice project. -# -# This Source Code Form is subject to the terms of the Mozilla Public -# License, v. 2.0. If a copy of the MPL was not distributed with this -# file, You can obtain one at http://mozilla.org/MPL/2.0/. -# - -$(eval $(call gb_JunitTest_JunitTest,jurt_java_remote)) - -$(eval $(call gb_JunitTest_use_jars,jurt_java_remote,\ - OOoRunner \ -)) - -$(eval $(call gb_Jar_use_customtargets,jurt_java_remote, \ - ridljar/javamaker \ -)) - -$(eval $(call gb_JunitTest_use_jar_classset,jurt_java_remote,ridl)) - -$(eval $(call gb_JunitTest_add_classpath,jurt_java_remote,$(call gb_CustomTarget_get_workdir,ridljar/javamaker))) - -$(eval $(call gb_JunitTest_add_sourcefiles,jurt_java_remote,\ - jurt/test/com/sun/star/lib/uno/bridges/java_remote/BridgedObject_Test \ - jurt/test/com/sun/star/lib/uno/bridges/java_remote/ProxyFactory_Test \ - jurt/test/com/sun/star/lib/uno/bridges/java_remote/java_remote_bridge_Test \ -)) - -$(eval $(call gb_JunitTest_add_classes,jurt_java_remote,\ - com.sun.star.lib.uno.bridges.java_remote.BridgedObject_Test \ - com.sun.star.lib.uno.bridges.java_remote.ProxyFactory_Test \ - com.sun.star.lib.uno.bridges.java_remote.java_remote_bridge_Test \ -)) - -# vim:set noet sw=4 ts=4: diff --git a/jurt/JunitTest_remote.mk b/jurt/JunitTest_remote.mk deleted file mode 100644 index 1333076a1cbc..000000000000 --- a/jurt/JunitTest_remote.mk +++ /dev/null @@ -1,37 +0,0 @@ -# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*- -# -# This file is part of the LibreOffice project. -# -# This Source Code Form is subject to the terms of the Mozilla Public -# License, v. 2.0. If a copy of the MPL was not distributed with this -# file, You can obtain one at http://mozilla.org/MPL/2.0/. -# - -$(eval $(call gb_JunitTest_JunitTest,jurt_remote)) - -$(eval $(call gb_Jar_use_customtargets,jurt_remote, \ - ridljar/javamaker \ -)) - -$(eval $(call gb_JunitTest_use_jar_classset,jurt_remote,ridl)) - -$(eval $(call gb_JunitTest_add_classpath,jurt_remote,$(call gb_CustomTarget_get_workdir,ridljar/javamaker))) - -$(eval $(call gb_JunitTest_add_sourcefiles,jurt_remote,\ - jurt/test/com/sun/star/lib/uno/environments/remote/JavaThreadPoolFactory_Test \ - jurt/test/com/sun/star/lib/uno/environments/remote/JobQueue_Test \ - jurt/test/com/sun/star/lib/uno/environments/remote/TestIWorkAt \ - jurt/test/com/sun/star/lib/uno/environments/remote/TestReceiver \ - jurt/test/com/sun/star/lib/uno/environments/remote/TestWorkAt \ - jurt/test/com/sun/star/lib/uno/environments/remote/ThreadId_Test \ - jurt/test/com/sun/star/lib/uno/environments/remote/ThreadPool_Test \ -)) - -$(eval $(call gb_JunitTest_add_classes,jurt_remote,\ - com.sun.star.lib.uno.environments.remote.JavaThreadPoolFactory_Test \ - com.sun.star.lib.uno.environments.remote.JobQueue_Test \ - com.sun.star.lib.uno.environments.remote.ThreadId_Test \ - com.sun.star.lib.uno.environments.remote.ThreadPool_Test \ -)) - -# vim:set noet sw=4 ts=4: diff --git a/jurt/JunitTest_uno.mk b/jurt/JunitTest_uno.mk deleted file mode 100644 index 1edfbf70174a..000000000000 --- a/jurt/JunitTest_uno.mk +++ /dev/null @@ -1,29 +0,0 @@ -# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*- -# -# This file is part of the LibreOffice project. -# -# This Source Code Form is subject to the terms of the Mozilla Public -# License, v. 2.0. If a copy of the MPL was not distributed with this -# file, You can obtain one at http://mozilla.org/MPL/2.0/. -# - -$(eval $(call gb_JunitTest_JunitTest,jurt_uno)) - -$(eval $(call gb_JunitTest_use_jars,jurt_uno,\ - OOoRunner \ - ridl \ -)) - -$(eval $(call gb_JunitTest_add_sourcefiles,jurt_uno,\ - jurt/test/com/sun/star/uno/AnyConverter_Test \ - jurt/test/com/sun/star/uno/UnoRuntime_EnvironmentTest \ - jurt/test/com/sun/star/uno/WeakReference_Test \ -)) - -$(eval $(call gb_JunitTest_add_classes,jurt_uno,\ - com.sun.star.uno.AnyConverter_Test \ - com.sun.star.uno.UnoRuntime_EnvironmentTest \ - com.sun.star.uno.WeakReference_Test \ -)) - -# vim:set noet sw=4 ts=4: diff --git a/jurt/JunitTest_urp.mk b/jurt/JunitTest_urp.mk deleted file mode 100644 index fff2bc54230c..000000000000 --- a/jurt/JunitTest_urp.mk +++ /dev/null @@ -1,35 +0,0 @@ -# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*- -# -# This file is part of the LibreOffice project. -# -# This Source Code Form is subject to the terms of the Mozilla Public -# License, v. 2.0. If a copy of the MPL was not distributed with this -# file, You can obtain one at http://mozilla.org/MPL/2.0/. -# - -$(eval $(call gb_JunitTest_JunitTest,jurt_urp)) - -$(eval $(call gb_JunitTest_use_customtargets,jurt_urp,\ - jurt/test/com/sun/star/lib/uno/protocols/urp \ - ridljar/javamaker \ -)) - -$(eval $(call gb_JunitTest_use_jar_classset,jurt_urp,ridl)) - -$(eval $(call gb_JunitTest_add_classpath,jurt_urp,$(call gb_CustomTarget_get_workdir,ridljar/javamaker))) - -$(eval $(call gb_JunitTest_add_sourcefiles,jurt_urp,\ - jurt/test/com/sun/star/lib/uno/protocols/urp/Cache_Test \ - jurt/test/com/sun/star/lib/uno/protocols/urp/Marshaling_Test \ - jurt/test/com/sun/star/lib/uno/protocols/urp/Protocol_Test \ - jurt/test/com/sun/star/lib/uno/protocols/urp/TestBridge \ - jurt/test/com/sun/star/lib/uno/protocols/urp/TestObject \ -)) - -$(eval $(call gb_JunitTest_add_classes,jurt_urp,\ - com.sun.star.lib.uno.protocols.urp.Cache_Test \ - com.sun.star.lib.uno.protocols.urp.Marshaling_Test \ - com.sun.star.lib.uno.protocols.urp.Protocol_Test \ -)) - -# vim:set noet sw=4 ts=4: diff --git a/jurt/JunitTest_util.mk b/jurt/JunitTest_util.mk deleted file mode 100644 index 72f1d29c10f2..000000000000 --- a/jurt/JunitTest_util.mk +++ /dev/null @@ -1,24 +0,0 @@ -# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*- -# -# This file is part of the LibreOffice project. -# -# This Source Code Form is subject to the terms of the Mozilla Public -# License, v. 2.0. If a copy of the MPL was not distributed with this -# file, You can obtain one at http://mozilla.org/MPL/2.0/. -# - -$(eval $(call gb_JunitTest_JunitTest,jurt_util)) - -$(eval $(call gb_JunitTest_use_jars,jurt_util,\ - ridl \ -)) - -$(eval $(call gb_JunitTest_add_sourcefiles,jurt_util,\ - jurt/test/com/sun/star/lib/util/NativeLibraryLoader_Test \ -)) - -$(eval $(call gb_JunitTest_add_classes,jurt_util,\ - com.sun.star.lib.util.NativeLibraryLoader_Test \ -)) - -# vim:set noet sw=4 ts=4: diff --git a/jurt/Module_jurt.mk b/jurt/Module_jurt.mk index 89fb3973c687..1c0d5baa9483 100644 --- a/jurt/Module_jurt.mk +++ b/jurt/Module_jurt.mk @@ -22,19 +22,6 @@ $(eval $(call gb_Module_add_targets,jurt,\ )) endif -$(eval $(call gb_Module_add_subsequentcheck_targets,jurt,\ - CustomTarget_test_urp \ - InternalUnoApi_test_urp \ - JunitTest_bridgefactory \ - JunitTest_connections \ - JunitTest_java \ - JunitTest_java_remote \ - JunitTest_remote \ - JunitTest_uno \ - JunitTest_urp \ - JunitTest_util \ -)) - endif # vim:set noet sw=4 ts=4: diff --git a/jurt/test/com/sun/star/comp/bridgefactory/BridgeFactory_Test.java b/jurt/test/com/sun/star/comp/bridgefactory/BridgeFactory_Test.java deleted file mode 100644 index 965653bf76df..000000000000 --- a/jurt/test/com/sun/star/comp/bridgefactory/BridgeFactory_Test.java +++ /dev/null @@ -1,92 +0,0 @@ -/* -*- 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.comp.bridgefactory; - -import com.sun.star.bridge.BridgeExistsException; -import com.sun.star.bridge.XBridge; -import com.sun.star.comp.connections.PipedConnection; -import com.sun.star.lang.XComponent; -import com.sun.star.uno.UnoRuntime; -import org.junit.Test; -import static org.junit.Assert.*; - -public final class BridgeFactory_Test { - @Test public void test() throws Exception { - PipedConnection rightSide = new PipedConnection(new Object[0]); - PipedConnection leftSide = new PipedConnection(new Object[]{rightSide}); - - BridgeFactory bridgeFactory = new BridgeFactory(); // create the needed bridgeFactory - - // create a bridge - XBridge xBridge = bridgeFactory.createBridge("testbridge", "urp", leftSide, null); - - // test that we get the same bridge - assertTrue( - UnoRuntime.areSame( - xBridge, bridgeFactory.getBridge("testbridge"))); - - // test that we can not create another bridge with same name - try { - bridgeFactory.createBridge("testbridge", "urp", leftSide, null); - - fail(); - } - catch(BridgeExistsException bridgeExistsException) { - } - - - // test getExistingBridges - XBridge xBridges[] = bridgeFactory.getExistingBridges(); - assertTrue(UnoRuntime.areSame(xBridge, xBridges[0])); - - // dispose the bridge - XComponent xComponent = UnoRuntime.queryInterface(XComponent.class, xBridge); - xComponent.dispose(); - - - // test that the bridge has been removed - assertTrue(bridgeFactory.getBridge("testbridge") == null); - - - - rightSide = new PipedConnection(new Object[0]); - leftSide = new PipedConnection(new Object[]{rightSide}); - - - // test that we really get a new bridge - XBridge xBridge_new = bridgeFactory.createBridge("testbridge", "urp", leftSide, null); - assertFalse(UnoRuntime.areSame(xBridge, xBridge_new)); - - for(int i = 0; i <10000; ++ i) { - Object x[] = new Object[100]; - } - - // test getExistingBridges - xBridges = bridgeFactory.getExistingBridges(); - assertEquals(1, xBridges.length); - assertTrue(UnoRuntime.areSame(xBridge_new, xBridges[0])); - - // dispose the new bridge - XComponent xComponent_new = UnoRuntime.queryInterface(XComponent.class, xBridge_new); - xComponent_new.dispose(); - } -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/jurt/test/com/sun/star/comp/connections/PipedConnection_Test.java b/jurt/test/com/sun/star/comp/connections/PipedConnection_Test.java deleted file mode 100644 index 6cfef789d9ab..000000000000 --- a/jurt/test/com/sun/star/comp/connections/PipedConnection_Test.java +++ /dev/null @@ -1,104 +0,0 @@ -/* -*- 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.comp.connections; - -import com.sun.star.io.IOException; -import org.junit.Test; -import static org.junit.Assert.*; - -public final class PipedConnection_Test { - private static final int ROUNDS = 2000; - - @Test public void test() throws Exception { - PipedConnection rightSide = new PipedConnection(new Object[0]); - PipedConnection leftSide = new PipedConnection(new Object[]{rightSide}); - - Reader reader = new Reader(rightSide); - Writer writer = new Writer(leftSide); - - reader.start(); - writer.start(); - - writer.join(); - reader.join(); - - assertTrue(writer._state); - assertTrue(reader._state); - assertEquals(ROUNDS, reader._rounds); - } - - private static class Reader extends Thread { - PipedConnection _pipedConnection; - boolean _state = false; - int _rounds = 0; - - Reader(PipedConnection pipedConnection) { - _pipedConnection = pipedConnection; - } - - @Override - public void run() { - try { - for (byte v = 0;; v++) { - byte[][] b = new byte[1][]; - int n = _pipedConnection.read(b, 1); - if (n == 0) { - break; - } - assertEquals(1, n); - assertEquals(1, b[0].length); - assertEquals(v, b[0][0]); - ++_rounds; - } - _pipedConnection.close(); - _state = true; - } catch (IOException e) { - throw new RuntimeException(e); - } - } - } - - private static class Writer extends Thread { - PipedConnection _pipedConnection; - boolean _state = false; - - Writer(PipedConnection pipedConnection) { - _pipedConnection = pipedConnection; - } - - @Override - public void run() { - try { - byte v = 0; - for (int i = 0; i != ROUNDS; ++i) { - byte[] b = new byte[] { v++ }; - _pipedConnection.write(b); - _pipedConnection.flush(); - } - _pipedConnection.close(); - _state = true; - } catch (IOException e) { - throw new RuntimeException(e); - } - } - } -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/jurt/test/com/sun/star/lib/uno/bridges/java_remote/BridgedObject_Test.java b/jurt/test/com/sun/star/lib/uno/bridges/java_remote/BridgedObject_Test.java deleted file mode 100644 index e7dc9c0e19c9..000000000000 --- a/jurt/test/com/sun/star/lib/uno/bridges/java_remote/BridgedObject_Test.java +++ /dev/null @@ -1,64 +0,0 @@ -/* -*- 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.bridges.java_remote; - -import com.sun.star.bridge.XBridge; -import com.sun.star.uno.Type; -import com.sun.star.uno.XInterface; -import org.junit.Test; -import static org.junit.Assert.*; - -public final class BridgedObject_Test { - @Test public void test() { - RequestHandler handler = new RequestHandler() { - public Object sendRequest( - String oid, Type type, String operation, Object[] args) - { - return null; - } - }; - XBridge bridge1 = new TestBridge(); - ProxyFactory factory1 = new ProxyFactory(handler, bridge1); - XBridge bridge2 = new TestBridge(); - ProxyFactory factory2 = new ProxyFactory(handler, bridge2); - Object object0 = new Object(); - Object object1 = factory1.create("", new Type(XInterface.class)); - Object object2 = factory2.create("", new Type(XInterface.class)); - assertNull(BridgedObject.getBridge(object0)); - assertSame(bridge1, BridgedObject.getBridge(object1)); - assertSame(bridge2, BridgedObject.getBridge(object2)); - } - - private static final class TestBridge implements XBridge { - public Object getInstance(String instanceName) { - return null; - } - - public String getName() { - return null; - } - - public String getDescription() { - return null; - } - } -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/jurt/test/com/sun/star/lib/uno/bridges/java_remote/ProxyFactory_Test.java b/jurt/test/com/sun/star/lib/uno/bridges/java_remote/ProxyFactory_Test.java deleted file mode 100644 index 45fc02f89989..000000000000 --- a/jurt/test/com/sun/star/lib/uno/bridges/java_remote/ProxyFactory_Test.java +++ /dev/null @@ -1,131 +0,0 @@ -/* -*- 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.bridges.java_remote; - -import com.sun.star.uno.IQueryInterface; -import com.sun.star.uno.MappingException; -import com.sun.star.uno.Type; -import com.sun.star.uno.UnoRuntime; -import com.sun.star.uno.XInterface; -import com.sun.star.uno.XNamingService; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.lang.reflect.UndeclaredThrowableException; -import org.junit.Test; -import static org.junit.Assert.*; - -public final class ProxyFactory_Test { - @Test public void testQueryInterface() { - TestRequestHandler handler = new TestRequestHandler(); - Type type = new Type(XNamingService.class); - Object proxy = new ProxyFactory(handler, null).create("TestOID", type); - assertSame(proxy, ((IQueryInterface) proxy).queryInterface(type)); - assertSame(proxy, UnoRuntime.queryInterface(type, proxy)); - } - - @Test public void testExceptionHandling() throws Exception { - TestRequestHandler handler = new TestRequestHandler(); - Object proxy = new ProxyFactory(handler, null).create( - "TestOID", new Type(XNamingService.class)); - testExceptions( - handler, - proxy.getClass().getMethod("queryInterface", - new Class[] { Type.class }), - proxy, new Object[] { new Type(XInterface.class) }, - new Class[] { null, MappingException.class, - com.sun.star.uno.RuntimeException.class, - UndeclaredThrowableException.class, - NullPointerException.class, - UndeclaredThrowableException.class }); - testExceptions( - handler, - proxy.getClass().getMethod("getRegisteredObject", - new Class[] { String.class }), - proxy, new Object[] { "TestName" }, - new Class[] { null, MappingException.class, - com.sun.star.uno.RuntimeException.class, - com.sun.star.uno.Exception.class, - NullPointerException.class, Exception.class }); - } - - private void testExceptions(TestRequestHandler handler, Method method, - Object obj, Object[] args, Class<?>[] exceptions) - throws Exception - { - for (int i = 0; i < exceptions.length; ++i) { - handler.setModus(i); - testExceptionType(method, obj, args, exceptions[i]); - } - } - - private void testExceptionType(Method method, Object obj, Object[] args, - Class<?> exception) throws Exception { - try { - method.invoke(obj, args); - assertNull(exception); - } catch (InvocationTargetException e) { - assertNotNull(exception); - assertTrue(exception.isInstance(e.getTargetException())); - // TODO check stack trace - } - } - - private static final class TestRequestHandler implements RequestHandler { - public Object sendRequest(String oid, Type type, String operation, - Object[] args) - throws Throwable - { - if (operation.equals("release")) { - return null; - } - int m; - synchronized (lock) { - m = modus; - } - switch (m) { - case 0: - return operation.equals("getInstance") ? "TestResult" : null; - case 1: - // TODO What is this test, with an obviously obsoleted - // MappingException, good for? - throw new MappingException(); - case 2: - throw new com.sun.star.uno.RuntimeException(); - case 3: - throw new com.sun.star.uno.Exception(); - case 4: - throw new NullPointerException(); - default: - throw new Throwable(); - } - } - - public void setModus(int modus) { - synchronized (lock) { - this.modus = modus; - } - } - - private final Object lock = new Object(); - private int modus = 0; - } -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/jurt/test/com/sun/star/lib/uno/bridges/java_remote/java_remote_bridge_Test.java b/jurt/test/com/sun/star/lib/uno/bridges/java_remote/java_remote_bridge_Test.java deleted file mode 100644 index 53e150527187..000000000000 --- a/jurt/test/com/sun/star/lib/uno/bridges/java_remote/java_remote_bridge_Test.java +++ /dev/null @@ -1,239 +0,0 @@ -/* -*- 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.bridges.java_remote; - -import com.sun.star.bridge.XBridge; -import com.sun.star.bridge.XInstanceProvider; -import com.sun.star.comp.connections.PipedConnection; -import com.sun.star.connection.XConnection; -import com.sun.star.container.NoSuchElementException; -import com.sun.star.lib.uno.environments.java.java_environment; -import com.sun.star.lib.uno.typeinfo.MethodTypeInfo; -import com.sun.star.lib.uno.typeinfo.TypeInfo; -import com.sun.star.uno.IQueryInterface; -import com.sun.star.uno.Type; -import com.sun.star.uno.UnoRuntime; -import com.sun.star.uno.XInterface; -import org.junit.Test; -import util.WaitUnreachable; -import static org.junit.Assert.*; - -public final class java_remote_bridge_Test { - @Test public void test() throws Exception { - String protocol = "urp"; - - XConnection connectionA = new PipedConnection(new Object[0]); - XConnection connectionB = new PipedConnection( - new Object[] { connectionA }); - java_remote_bridge bridgeA = new java_remote_bridge( - new java_environment(null), null, - new Object[] { protocol, connectionA, new TestInstanceProvider() }); - java_remote_bridge bridgeB = new java_remote_bridge( - new java_environment(null), null, - new Object[] { protocol, connectionB, null }); - - testGetInstance(bridgeA, bridgeB); - testLifeCycle(bridgeA, bridgeB); - } - - private void testGetInstance(XBridge bridgeA, XBridge bridgeB) { - assertNull(bridgeB.getInstance(TestInstanceProvider.NAME_NULL)); - - try { - bridgeB.getInstance(TestInstanceProvider.NAME_RUNTIME_EXCEPTION); - fail("throw RuntimeException"); - } catch (com.sun.star.uno.RuntimeException e) { - assertTrue( - e.getMessage().indexOf( - TestInstanceProvider.NAME_RUNTIME_EXCEPTION) - != -1); - } - - try { - bridgeB.getInstance( - TestInstanceProvider.NAME_NO_SUCH_ELEMENT_EXCEPTION); - fail("throw NoSuchElementException"); - } catch (com.sun.star.uno.RuntimeException e) { - assertTrue( - e.getMessage().indexOf( - TestInstanceProvider.NAME_NO_SUCH_ELEMENT_EXCEPTION) - != -1); - } - - try { - bridgeA.getInstance(TestInstanceProvider.NAME_ANYTHING); - fail("no instance provider"); - } catch (com.sun.star.uno.RuntimeException e) { - assertTrue(e.getMessage().startsWith("unknown OID ")); - } - } - - private void testLifeCycle(java_remote_bridge bridgeA, - java_remote_bridge bridgeB) - throws InterruptedException - { - // Repeatedly, objects are mapped from bridgeA to bridgeB, where proxies - // for those objects (for the XInterface and TestInterface facets) are - // created. The proxies at bridgeB keep both bridges alive; after those - // proxies have been garbage-collected, both bridges should be disposed. - // It does not work to map a local object from bridgeA to bridgeB, as - // bridgeB would find this object as a local one, too (via the shared, - // static localObjects Registry in java_environment): bridgeB would not - // create a proxy, would rather send back a "release" to bridgeA, and - // both bridges would be disposed while the first object is being - // mapped. Therefore, a HACK is used to install TestProxy objects - // (which behave as if they got mapped in to bridgeA from somewhere - // else) at bridgeA and map those. - - final int COUNT = 100; - XInterface[] proxyBXInterface = new XInterface[COUNT]; - TestInterface[] proxyBTestInterface = new TestInterface[COUNT]; - for (int i = 0; i < COUNT; ++i) { - String name = "TestOID" + i; - Object proxyA = new TestProxy(name); - bridgeA.getSourceEnvironment().registerInterface( - proxyA, new String[] { name }, new Type(XInterface.class)); - - proxyBXInterface[i] = (XInterface) bridgeB.getInstance(name); - - // map object: - proxyBTestInterface[i] = UnoRuntime.queryInterface( - TestInterface.class, proxyBXInterface[i]); - proxyBTestInterface[i].function(); - - // remap object once: - TestInterface remapped = UnoRuntime.queryInterface( - TestInterface.class, proxyBXInterface[i]); - remapped.function(); - - // remap object twice: - remapped = UnoRuntime.queryInterface( - TestInterface.class, proxyBXInterface[i]); - remapped.function(); - } - - assertEquals(3 * COUNT, TestProxy.getCount()); - - // The following checks rely on the implementation detail that mapping - // different facets of a UNO object (XInterface and TestInterface) leads - // to different proxies: - - assertEquals("bridge A life count", 2 * COUNT, bridgeA.getLifeCount()); - assertEquals("bridge B life count", 2 * COUNT, bridgeB.getLifeCount()); -/*TODO: below test fails with "expected:<200> but was:<204>": - assertEquals("proxy count", 2 * COUNT, ProxyFactory.getDebugCount()); -*/ - - System.out.println("waiting for proxies to become unreachable:"); - for (int i = 0; i < COUNT; ++i) { - WaitUnreachable u1 = new WaitUnreachable(proxyBXInterface[i]); - WaitUnreachable u2 = new WaitUnreachable(proxyBTestInterface[i]); - proxyBXInterface[i] = null; - proxyBTestInterface[i] = null; - u1.waitUnreachable(); - u2.waitUnreachable(); - } - // For whatever strange reason, this sleep seems to be necessary to - // reliably ensure that even the last proxy's finalization is over - // before the following assert is executed: - Thread.sleep(1000); - - assertEquals("proxy count", 0, ProxyFactory.getDebugCount()); - - System.out.println("waiting for pending messages to be done"); - while (bridgeA.getLifeCount() != 0 || bridgeB.getLifeCount() != 0) { - Thread.sleep(100); - } - - assertEquals("Zero bridge A life count", 0, bridgeA.getLifeCount()); - assertEquals("Zero bridge B life count", 0, bridgeB.getLifeCount()); - assertEquals("Zero proxy count", 0, ProxyFactory.getDebugCount()); - } - - public interface TestInterface extends XInterface { - void function(); - - TypeInfo[] UNOTYPEINFO = new TypeInfo[] { - new MethodTypeInfo("function", 0, 0) }; - } - - private static final class TestInstanceProvider - implements XInstanceProvider - { - public Object getInstance(String name) throws NoSuchElementException { - if (name.equals(NAME_NULL)) { - return null; - } else if (name.equals(NAME_RUNTIME_EXCEPTION)) { - throw new com.sun.star.uno.RuntimeException( - getClass().getName() + ", throwing: " + name); - } else if (name.equals(NAME_NO_SUCH_ELEMENT_EXCEPTION)) { - throw new NoSuchElementException( - getClass().getName() + ", throwing: " + name); - } else { - throw new IllegalStateException(); - } - } - - public static final String NAME_NULL = "return null"; - public static final String NAME_RUNTIME_EXCEPTION - = "throw RuntimeException"; - public static final String NAME_NO_SUCH_ELEMENT_EXCEPTION - = "throw NoSuchElementException"; - public static final String NAME_ANYTHING = "anything"; - } - - private static final class TestProxy - implements com.sun.star.lib.uno.Proxy, IQueryInterface, - TestInterface - { - public TestProxy(String oid) { - this.oid = oid; - } - - public Object queryInterface(Type type) { - // type should be either XInterface or TestInterface... - return this; - } - - public boolean isSame(Object object) { - return object instanceof TestProxy - && oid.equals(((TestProxy) object).oid); - } - - public String getOid() { - return oid; - } - - public void function() { - synchronized (getClass()) { - ++count; - } - } - - public static synchronized int getCount() { - return count; - } - - private final String oid; - - private static int count = 0; - } -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/jurt/test/com/sun/star/lib/uno/environments/java/java_environment_Test.java b/jurt/test/com/sun/star/lib/uno/environments/java/java_environment_Test.java deleted file mode 100644 index 9381e2af437c..000000000000 --- a/jurt/test/com/sun/star/lib/uno/environments/java/java_environment_Test.java +++ /dev/null @@ -1,55 +0,0 @@ -/* -*- 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.environments.java; - -import com.sun.star.uno.Type; -import com.sun.star.uno.XInterface; -import org.junit.Test; -import static org.junit.Assert.*; - -public final class java_environment_Test { - @Test public void test() { - java_environment env = new java_environment(null); - - Object obj = Integer.valueOf(3); - String[] oid = new String[1]; - - Object obj2 = env.registerInterface(obj, oid, - new Type(XInterface.class)); - Object obj3 = env.registerInterface(obj, oid, - new Type(XInterface.class)); - // Register ordinary interface twice: - assertSame(obj, obj2); - assertSame(obj, obj3); - - // Ask for registered interface: - assertSame( - obj, - env.getRegisteredInterface(oid[0], new Type(XInterface.class))); - - env.revokeInterface(oid[0], new Type(XInterface.class)); - env.revokeInterface(oid[0], new Type(XInterface.class)); - // Revoke interface: - assertNull( - env.getRegisteredInterface(oid[0], new Type(XInterface.class))); - } -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/jurt/test/com/sun/star/lib/uno/environments/remote/JavaThreadPoolFactory_Test.java b/jurt/test/com/sun/star/lib/uno/environments/remote/JavaThreadPoolFactory_Test.java deleted file mode 100644 index 2d2264f06060..000000000000 --- a/jurt/test/com/sun/star/lib/uno/environments/remote/JavaThreadPoolFactory_Test.java +++ /dev/null @@ -1,48 +0,0 @@ -/* -*- 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.environments.remote; - -import org.junit.Test; -import static org.junit.Assert.*; - -public final class JavaThreadPoolFactory_Test { - @Test public void test() throws InterruptedException { - ThreadId i1 = JavaThreadPoolFactory.getThreadId(); - assertEquals(i1, JavaThreadPoolFactory.getThreadId()); - final ThreadId[] i2 = new ThreadId[1]; - new Thread() { - @Override - public void run() { - synchronized (i2) { - i2[0] = JavaThreadPoolFactory.getThreadId(); - i2.notify(); - } - } - }.start(); - synchronized (i2) { - while (i2[0] == null) { - i2.wait(); - } - } - assertFalse(i1.equals(i2[0])); - } -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/jurt/test/com/sun/star/lib/uno/environments/remote/JobQueue_Test.java b/jurt/test/com/sun/star/lib/uno/environments/remote/JobQueue_Test.java deleted file mode 100644 index a63c9c7ed6ba..000000000000 --- a/jurt/test/com/sun/star/lib/uno/environments/remote/JobQueue_Test.java +++ /dev/null @@ -1,263 +0,0 @@ -/* -*- 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.environments.remote; - -import com.sun.star.lib.uno.typedesc.TypeDescription; -import org.junit.Test; -import static org.junit.Assert.*; - -public final class JobQueue_Test { - @Test public void testThreadLeavesJobQueueOnDispose0() - throws InterruptedException - { - testThreadLeavesJobQueueOnDispose(0); - } - - @Test public void testThreadLeavesJobQueueOnDispose5000() - throws InterruptedException - { - testThreadLeavesJobQueueOnDispose(5000); - } - - private void testThreadLeavesJobQueueOnDispose(int waitTime) - throws InterruptedException - { - TestThread t = new TestThread(waitTime); - t.waitToStart(); - String msg = "xcxxxxxxxx"; - t._jobQueue.dispose(t._disposeId, new RuntimeException (msg)); - t.waitToTerminate(); -/*TODO: below test fails with "expected:<xcxxxxxxxx> but was:<null>": - assertEquals(msg, t._message); -*/ - } - - @Test public void testThreadLeavesJobQueueOnReply0() - throws InterruptedException - { - testThreadLeavesJobQueueOnReply(0); - } - - @Test public void testThreadLeavesJobQueueOnReply5000() - throws InterruptedException - { - testThreadLeavesJobQueueOnReply(5000); - } - - private void testThreadLeavesJobQueueOnReply(int waitTime) - throws InterruptedException - { - TestThread t = new TestThread(waitTime); - t.waitToStart(); - // put reply job: - t._jobQueue.putJob( - new Job(null, __iReceiver, - new Message( - null, false, "oid", __workAt_td, null, false, null, - false, null, null)), - null); - t.waitToTerminate(); - assertTrue(true); // TODO! ??? - } - - @Test public void testStaticThreadExecutesJobs0() - throws InterruptedException - { - testStaticThreadExecutesJobs(0); - } - - @Test public void testStaticThreadExecutesJobs5000() - throws InterruptedException - { - testStaticThreadExecutesJobs(5000); - } - - private void testStaticThreadExecutesJobs(int waitTime) - throws InterruptedException - { - TestThread t = new TestThread(waitTime); - t.waitToStart(); - testExecuteJobs(t._jobQueue); - t._jobQueue.dispose(t._disposeId, - new RuntimeException("xxxxxxxxxxxxx")); - t.waitToTerminate(); - } - - @Test public void testDynamicThreadExecutesJob() throws InterruptedException - { - testExecuteJobs( - new JobQueue( - __javaThreadPoolFactory, ThreadId.createFresh(), true)); - } - - @Test public void testStaticThreadExecutesAsyncs() - throws InterruptedException - { - TestThread t = new TestThread(); - JobQueue async_jobQueue = new JobQueue(__javaThreadPoolFactory, - t._threadId); - assertEquals(1, async_jobQueue._ref_count); - t._jobQueue = __javaThreadPoolFactory.getJobQueue(t._threadId); - assertEquals(1, t._jobQueue._ref_count); - t.waitToStart(); - TestWorkAt workAt = new TestWorkAt(); - testAsyncJobQueue(workAt, async_jobQueue, t._threadId); - t._jobQueue.dispose(t._disposeId, - new RuntimeException("xxxxxxxxxxxxx")); - t.waitToTerminate(); - assertEquals(TestWorkAt.MESSAGES, workAt._async_counter); - assertEquals(TestWorkAt.MESSAGES, workAt._sync_counter); - } - - @Test public void testDynamicThreadExecutesAsyncs() - throws InterruptedException - { - ThreadId threadId = ThreadId.createFresh(); - JobQueue async_jobQueue = new JobQueue(__javaThreadPoolFactory, - threadId); - TestWorkAt workAt = new TestWorkAt(); - testAsyncJobQueue(workAt, async_jobQueue, threadId); - assertEquals(TestWorkAt.MESSAGES, workAt._async_counter); - assertEquals(TestWorkAt.MESSAGES, workAt._sync_counter); - } - - private void testExecuteJobs(JobQueue jobQueue) throws InterruptedException - { - TestWorkAt workAt = new TestWorkAt(); - testSendRequests(workAt, "increment", jobQueue); - synchronized (workAt) { - jobQueue.putJob(new Job(workAt, __iReceiver, - new Message( - null, true, "oid", __workAt_td, - __workAt_td.getMethodDescription( - "notifyme"), - true, null, false, null, null)), - null); - while (!workAt._notified) { - workAt.wait(); - } - } - assertEquals(TestWorkAt.MESSAGES, workAt._counter); - } - - private void testAsyncJobQueue(TestWorkAt workAt, JobQueue async_jobQueue, - ThreadId threadId) - throws InterruptedException - { - // put slow async calls first, followed by fast sync calls: - testSendRequests(workAt, "asyncCall", async_jobQueue); - testSendRequests(workAt, "syncCall", - __javaThreadPoolFactory.getJobQueue(threadId)); - synchronized (workAt) { - async_jobQueue._sync_jobQueue.putJob( - new Job(workAt, __iReceiver, - new Message( - null, true, "oid", __workAt_td, - __workAt_td.getMethodDescription("notifyme"), - true, null, false, null, null)), - null); - while (!workAt._notified) { - workAt.wait(); - } - } - assertTrue(workAt.passedAsyncTest()); - } - - private void testSendRequests(TestWorkAt workAt, String operation, - JobQueue jobQueue) { - Message iMessage = new Message( - null, true, "oid", __workAt_td, - __workAt_td.getMethodDescription(operation), - true, null, false, null, null); - for (int i = 0; i < TestWorkAt.MESSAGES; ++ i) { - Thread.yield(); // force scheduling - jobQueue.putJob(new Job(workAt, __iReceiver, iMessage), - new Object()); - } - } - - private static final class TestThread extends Thread { - public final ThreadId _threadId = JavaThreadPoolFactory.getThreadId(); - public final Object _disposeId = new Object(); - public JobQueue _jobQueue = null; - - public TestThread(int waitTime) { - this.waitTime = waitTime; - _jobQueue = new JobQueue(__javaThreadPoolFactory, _threadId, false); - } - - public TestThread() { - waitTime = 0; - } - - @Override - public void run() { - synchronized (lock) { - state = STATE_STARTED; - lock.notifyAll(); - } - try { - if (waitTime != 0) { - Thread.sleep(waitTime); - } - _jobQueue.enter(_disposeId); - } catch (Throwable e) { - } - synchronized (lock) { - state = STATE_DONE; - lock.notifyAll(); - } - } - - public void waitToStart() throws InterruptedException { - start(); - synchronized (lock) { - while (state == STATE_INITIAL) { - lock.wait(); - } - } - } - - public void waitToTerminate() throws InterruptedException { - synchronized (lock) { - while (state != STATE_DONE) { - lock.wait(); - } - } - join(); - } - - private final int waitTime; - - private final Object lock = new Object(); - private int state = STATE_INITIAL; - private static final int STATE_INITIAL = 0; - private static final int STATE_STARTED = 1; - private static final int STATE_DONE = 2; - } - - private static final JavaThreadPoolFactory __javaThreadPoolFactory - = new JavaThreadPoolFactory(); - private static final IReceiver __iReceiver = new TestReceiver(); - private static final TypeDescription __workAt_td - = TypeDescription.getTypeDescription(TestIWorkAt.class); -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/jurt/test/com/sun/star/lib/uno/environments/remote/TestIWorkAt.java b/jurt/test/com/sun/star/lib/uno/environments/remote/TestIWorkAt.java deleted file mode 100644 index 7bb71a80e970..000000000000 --- a/jurt/test/com/sun/star/lib/uno/environments/remote/TestIWorkAt.java +++ /dev/null @@ -1,43 +0,0 @@ -/* -*- 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.environments.remote; - - -import com.sun.star.lib.uno.typeinfo.MethodTypeInfo; -import com.sun.star.lib.uno.typeinfo.TypeInfo; -import com.sun.star.uno.XInterface; - -public interface TestIWorkAt extends XInterface { - void syncCall() throws Throwable ; - void asyncCall() throws Throwable ; - - void increment() throws Throwable; - - void notifyme(); - - TypeInfo UNOTYPEINFO[] = { - new MethodTypeInfo("increment", 0, 0), - new MethodTypeInfo("notifyme", 1, 0), - new MethodTypeInfo("syncCall", 2, 0), - new MethodTypeInfo("asyncCall", 3, 0) - }; -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/jurt/test/com/sun/star/lib/uno/environments/remote/TestReceiver.java b/jurt/test/com/sun/star/lib/uno/environments/remote/TestReceiver.java deleted file mode 100644 index 6c8f36885752..000000000000 --- a/jurt/test/com/sun/star/lib/uno/environments/remote/TestReceiver.java +++ /dev/null @@ -1,27 +0,0 @@ -/* -*- 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.environments.remote; - -final class TestReceiver implements IReceiver { - public void sendReply(boolean exception, ThreadId threadId, Object result) { - } -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/jurt/test/com/sun/star/lib/uno/environments/remote/TestWorkAt.java b/jurt/test/com/sun/star/lib/uno/environments/remote/TestWorkAt.java deleted file mode 100644 index 93297815cb9e..000000000000 --- a/jurt/test/com/sun/star/lib/uno/environments/remote/TestWorkAt.java +++ /dev/null @@ -1,81 +0,0 @@ -/* -*- 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.environments.remote; - -import static org.junit.Assert.*; - -class TestWorkAt implements TestIWorkAt { - /** - * When set to true, enables various debugging output. - */ - private static final boolean DEBUG = false; - - static final int MESSAGES = 35; - - - int _counter; - - int _sync_counter; - int _async_counter; - - private boolean _passedAsync = true; - boolean _notified = false; - - public synchronized void syncCall() throws Throwable { - ++ _sync_counter; - - // at least in currently run tests this should never fire, so don't - // defer the check until passedAsyncTest and assert here - assertEquals(MESSAGES, _async_counter); - if(_async_counter != MESSAGES) - _passedAsync = false; - - if(DEBUG) System.err.println("syncCall:" + _sync_counter + " " + _passedAsync + " " + Thread.currentThread()); - } - - public synchronized void asyncCall() throws Throwable { - ++ _async_counter; - - if(DEBUG) System.err.println("asyncCall:" + _async_counter + " " + Thread.currentThread()); - } - - public synchronized void increment() throws Throwable { - if(DEBUG) System.err.println("increment - " + Thread.currentThread()); - - ++ _counter; - notifyAll(); - } - - public synchronized void notifyme() { - if(DEBUG) System.err.println("\t\t\tnotifying me" + Thread.currentThread()); - - notifyAll(); - - _notified = true; - } - - public synchronized boolean passedAsyncTest() { - assertEquals(MESSAGES, _sync_counter); - assertTrue(_passedAsync); - return _passedAsync && (_sync_counter == MESSAGES); - } -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/jurt/test/com/sun/star/lib/uno/environments/remote/ThreadId_Test.java b/jurt/test/com/sun/star/lib/uno/environments/remote/ThreadId_Test.java deleted file mode 100644 index 8ee7f4a4c264..000000000000 --- a/jurt/test/com/sun/star/lib/uno/environments/remote/ThreadId_Test.java +++ /dev/null @@ -1,57 +0,0 @@ -/* -*- 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.environments.remote; - -import java.util.Arrays; -import org.junit.Test; -import static org.junit.Assert.*; - -public final class ThreadId_Test { - @Test public void test() { - ThreadId i1 = ThreadId.createFresh(); - assertTrue(i1.equals(i1)); - assertFalse(i1.equals(null)); - assertFalse(i1.equals(new Object())); - assertEquals(i1.hashCode(), i1.hashCode()); - byte[] i1bytes = i1.getBytes(); - assertNotNull(i1bytes); - assertTrue(i1bytes.length >= 5); - assertEquals('j', i1bytes[0]); - assertEquals('a', i1bytes[1]); - assertEquals('v', i1bytes[2]); - assertEquals('a', i1bytes[3]); - assertEquals(':', i1bytes[4]); - assertArrayEquals(i1bytes, i1.getBytes()); - - ThreadId i2 = ThreadId.createFresh(); - assertFalse(i1.equals(i2)); - assertFalse(i2.equals(i1)); - assertFalse(Arrays.equals(i1bytes, i2.getBytes())); - - ThreadId i3 = new ThreadId(i1bytes); - assertTrue(i3.equals(i1)); - assertFalse(i3.equals(i2)); - assertTrue(i1.equals(i3)); - assertEquals(i1.hashCode(), i3.hashCode()); - assertArrayEquals(i1bytes, i3.getBytes()); - } -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/jurt/test/com/sun/star/lib/uno/environments/remote/ThreadPool_Test.java b/jurt/test/com/sun/star/lib/uno/environments/remote/ThreadPool_Test.java deleted file mode 100644 index 7da68db23f0e..000000000000 --- a/jurt/test/com/sun/star/lib/uno/environments/remote/ThreadPool_Test.java +++ /dev/null @@ -1,437 +0,0 @@ -/* -*- 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.environments.remote; - -import com.sun.star.lib.uno.typedesc.MethodDescription; -import com.sun.star.lib.uno.typedesc.TypeDescription; -import org.junit.Test; -import static org.junit.Assert.*; - -public class ThreadPool_Test { - @Test public void testDispose() throws InterruptedException { - IThreadPool iThreadPool = ThreadPoolManager.create(); - TestThread testThread = new TestThread(iThreadPool); - - ThreadId threadId = null; - - // start the test thread - synchronized(testThread) { - testThread.start(); - - testThread.wait(); - - threadId = testThread._threadId; - - // let the thread attach and enter the threadpool - testThread.notifyAll(); - } - - String message = "blabla"; - - // terminate the test thread - synchronized(testThread) { - // put reply job - iThreadPool.dispose(new RuntimeException(message)); - - testThread.wait(); - } - - testThread.join(); - -/*TODO: below test fails with "expected:<blabla> but was:<null>": - assertEquals(message, testThread._message); -*/ - } - - @Test public void testThreadAsync() throws InterruptedException { - TestWorkAt workAt = new TestWorkAt(); - - ThreadId threadId = ThreadId.createFresh(); - - // queue asyncs - for(int i = 0; i < TestWorkAt.MESSAGES; ++ i) { - Thread.yield(); // force scheduling - putJob(workAt, false, threadId, "increment"); - } - - synchronized(workAt) { - putJob(workAt, false, threadId, "notifyme"); - - while(!workAt._notified) { - workAt.wait(); - } - } - - assertEquals(TestWorkAt.MESSAGES, workAt._counter); - } - - @Test public void testDynamicThreadSync() throws InterruptedException { - TestWorkAt workAt = new TestWorkAt(); - - ThreadId threadId = ThreadId.createFresh(); - - // queue asyncs - for(int i = 0; i < TestWorkAt.MESSAGES; ++ i) { - Thread.yield(); // force scheduling - putJob(workAt, true, threadId, "increment"); - } - - synchronized(workAt) { - putJob(workAt, true, threadId, "notifyme"); - - while(!workAt._notified) { - workAt.wait(); - } - } - - assertEquals(TestWorkAt.MESSAGES, workAt._counter); - } - - @Test public void testStaticThreadSync() throws InterruptedException { - TestWorkAt workAt = new TestWorkAt(); - - TestThread testThread = new TestThread(); - - ThreadId threadId = null; - - // start the test thread - synchronized(testThread) { - testThread.start(); - - testThread.wait(); - - threadId = testThread._threadId; - - // let the thread attach and enter the threadpool - testThread.notifyAll(); - } - - // queue syncs - for(int i = 0; i < TestWorkAt.MESSAGES; ++ i) { - Thread.yield(); // force scheduling - putJob(workAt, true, threadId, "increment"); - } - - // terminate the test thread - synchronized(testThread) { - // put reply job - putJob(workAt, true, threadId, null); - - testThread.wait(); - } - - testThread.join(); - - assertEquals(TestWorkAt.MESSAGES, workAt._counter); - } - - @Test public void testDynamicThreadAsyncSyncOrder() - throws InterruptedException - { - TestWorkAt workAt = new TestWorkAt(); - - ThreadId threadId = ThreadId.createFresh(); - - // queue asyncs - for(int i = 0; i < TestWorkAt.MESSAGES; ++ i) { - Thread.yield(); // force scheduling - putJob(workAt, false, threadId, "asyncCall"); - } - - // queue syncs - for(int i = 0; i < TestWorkAt.MESSAGES; ++ i) { - Thread.yield(); // force scheduling - putJob(workAt, true, threadId, "syncCall"); - } - - synchronized(workAt) { - putJob(workAt, true, threadId, "notifyme"); - - while(!workAt._notified) { - workAt.wait(); - } - } - - assertTrue(workAt.passedAsyncTest()); - } - - @Test public void testStaticThreadAsyncSyncOrder() - throws InterruptedException - { - TestWorkAt workAt = new TestWorkAt(); - - TestThread testThread = new TestThread(); - - // start the test thread - synchronized(testThread) { - testThread.start(); - - testThread.wait(); - } - - ThreadId threadId = testThread._threadId; - - // queue asyncs - for(int i = 0; i < TestWorkAt.MESSAGES; ++ i) { - Thread.yield(); // force scheduling - putJob(workAt, false, threadId, "asyncCall"); - } - - // let the thread attach and enter the threadpool - synchronized(testThread) { - testThread.notifyAll(); - } - - // queue syncs - for(int i = 0; i < TestWorkAt.MESSAGES; ++ i) { - Thread.yield(); // force scheduling - putJob(workAt, true, threadId, "syncCall"); - } - - // terminate the test thread - synchronized(testThread) { - // put reply job - putJob(workAt, true, threadId, null); - - testThread.wait(); - } - - testThread.join(); - - assertTrue(workAt.passedAsyncTest()); - } - - @Test public void testStress() throws InterruptedException { - TestWorkAt workAt = new TestWorkAt(); - for (int i = 0; i < TestWorkAt.MESSAGES; ++i) { - Thread.yield(); // force scheduling - ThreadId threadID = ThreadId.createFresh(); - putJob(workAt, true, threadID, "increment"); - putJob(workAt, false, threadID, "increment"); - } - synchronized (workAt) { - while (workAt._counter < 2 * TestWorkAt.MESSAGES) { - workAt.wait(); - } - } - - abstract class Stress extends Thread { - private Stress(int count) { - this.count = count; - } - - @Override - public void run() { - try { - for (int i = 0; i < count; ++i) { - runTest(); - } - } catch (Throwable e) { - e.printStackTrace(System.err); - } - } - - protected abstract void runTest() throws InterruptedException; - - private final int count; - } - - Stress stress1 = new Stress(50) { - @Override - protected void runTest() throws InterruptedException { - testThreadAsync(); - } - }; - stress1.start(); - - Stress stress2 = new Stress(50) { - @Override - protected void runTest() throws InterruptedException { - testDynamicThreadSync(); - } - }; - stress2.start(); - - Stress stress3 = new Stress(50) { - @Override - protected void runTest() throws InterruptedException { - testStaticThreadSync(); - } - }; - stress3.start(); - - Stress stress4 = new Stress(50) { - @Override - protected void runTest() throws InterruptedException { - testDynamicThreadAsyncSyncOrder(); - } - }; - stress4.start(); - - Stress stress5 = new Stress(50) { - @Override - protected void runTest() throws InterruptedException { - testStaticThreadAsyncSyncOrder(); - } - }; - stress5.start(); - - Stress stress6 = new Stress(500) { - @Override - protected void runTest() throws InterruptedException { - testDispose(); - } - }; - stress6.start(); - - stress1.join(); - stress2.join(); - stress3.join(); - stress4.join(); - stress5.join(); - stress6.join(); - } - - @Test public void testAsyncSync() throws InterruptedException { - TestWorkAt workAt = new TestWorkAt(); - ThreadId threadId = ThreadId.createFresh(); - MyWorkAt myWorkAt = new MyWorkAt( workAt ); - - // queue asyncs - for(int i = 0; i < TestWorkAt.MESSAGES; ++ i) { - if( i == 2 ) - { - putJob( myWorkAt, false , threadId, "asyncCall" ); - } - putJob(workAt, false, threadId, "asyncCall"); - } - - synchronized(workAt) { - putJob(workAt, false, threadId, "notifyme"); - - while(!workAt._notified) { - workAt.wait(); - } - } - - assertEquals(TestWorkAt.MESSAGES, workAt._async_counter); - assertTrue(myWorkAt._success); - } - - private static void putJob(TestIWorkAt iWorkAt, boolean synchron, - ThreadId threadId, String operation) { - __iThreadPool.putJob( - new Job(iWorkAt, __iReceiver, - new Message( - threadId, operation != null, "oid", __workAt_td, - (operation == null - ? null - : ((MethodDescription) - __workAt_td.getMethodDescription(operation))), - synchron, null, false, null, null))); - } - - private static final class TestThread extends Thread { - ThreadId _threadId; - IThreadPool _iThreadPool; - - TestThread() { - this(__iThreadPool); - } - - TestThread(IThreadPool iThreadPool) { - _iThreadPool = iThreadPool; - } - - @Override - public void run() { - _threadId = _iThreadPool.getThreadId(); - - - try { - synchronized(this) { - // notify that we are running - notify(); - - _iThreadPool.attach(); - - // wait until we should continue - wait(); - } - - _iThreadPool.enter(); - } - catch(Throwable throwable) { - } - - _iThreadPool.detach(); - - synchronized(this) { - // notify the listeners that we are dying - notifyAll(); - } - } - } - - private static final class MyWorkAt implements TestIWorkAt { - public MyWorkAt( TestWorkAt async_WorkAt ) { - _async_WorkAt = async_WorkAt; - } - - public void syncCall() throws Throwable - { - Message iMessage = new Message( - __iThreadPool.getThreadId(), false, "oid", __workAt_td, null, - false, null, false, null, null); - - // marshal reply - ThreadPool_Test.__iThreadPool.putJob( - new Job(this, ThreadPool_Test. __iReceiver, iMessage)); - } - - public void asyncCall() throws Throwable { - for (int i = 0 ; i < 5 ; ++i) { - ThreadPool_Test.__iThreadPool.attach(); - ThreadPool_Test.putJob(this, true, __iThreadPool.getThreadId(), - "syncCall"); - // wait for reply - ThreadPool_Test.__iThreadPool.enter(); - ThreadPool_Test.__iThreadPool.detach(); - } - // async must have waited for this call - _success = _async_WorkAt._async_counter == 2; - } - - public void increment() throws Throwable {} - - public void notifyme() {} - - public boolean _success = false; - - private final TestWorkAt _async_WorkAt; - } - - private static final IThreadPool __iThreadPool = ThreadPoolManager.create(); - private static final IReceiver __iReceiver = new TestReceiver(); - private static final TypeDescription __workAt_td - = TypeDescription.getTypeDescription(TestIWorkAt.class); -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ 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 deleted file mode 100644 index a7d93733d79c..000000000000 --- a/jurt/test/com/sun/star/lib/uno/protocols/urp/Cache_Test.java +++ /dev/null @@ -1,134 +0,0 @@ -/* -*- 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/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 deleted file mode 100644 index 5cf5f73e6554..000000000000 --- a/jurt/test/com/sun/star/lib/uno/protocols/urp/Marshaling_Test.java +++ /dev/null @@ -1,353 +0,0 @@ -/* -*- 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/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 deleted file mode 100644 index cda58aad8f62..000000000000 --- a/jurt/test/com/sun/star/lib/uno/protocols/urp/Protocol_Test.java +++ /dev/null @@ -1,311 +0,0 @@ -/* -*- 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/jurt/test/com/sun/star/lib/uno/protocols/urp/TestBridge.java b/jurt/test/com/sun/star/lib/uno/protocols/urp/TestBridge.java deleted file mode 100644 index acd1b3948de7..000000000000 --- a/jurt/test/com/sun/star/lib/uno/protocols/urp/TestBridge.java +++ /dev/null @@ -1,106 +0,0 @@ -/* -*- 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/jurt/test/com/sun/star/lib/uno/protocols/urp/TestObject.java b/jurt/test/com/sun/star/lib/uno/protocols/urp/TestObject.java deleted file mode 100644 index f36710e1d232..000000000000 --- a/jurt/test/com/sun/star/lib/uno/protocols/urp/TestObject.java +++ /dev/null @@ -1,63 +0,0 @@ -/* -*- 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/jurt/test/com/sun/star/lib/uno/protocols/urp/interfaces.idl b/jurt/test/com/sun/star/lib/uno/protocols/urp/interfaces.idl deleted file mode 100644 index 4ea1c8ebc2f8..000000000000 --- a/jurt/test/com/sun/star/lib/uno/protocols/urp/interfaces.idl +++ /dev/null @@ -1,101 +0,0 @@ -/* -*- 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: */ diff --git a/jurt/test/com/sun/star/lib/util/NativeLibraryLoader_Test.java b/jurt/test/com/sun/star/lib/util/NativeLibraryLoader_Test.java deleted file mode 100644 index e4101f2dd713..000000000000 --- a/jurt/test/com/sun/star/lib/util/NativeLibraryLoader_Test.java +++ /dev/null @@ -1,76 +0,0 @@ -/* -*- 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.util; - -import java.io.File; -import java.net.MalformedURLException; -import java.net.URL; -import org.junit.Test; -import static org.junit.Assert.*; - -public final class NativeLibraryLoader_Test { - @Test public void testEncoded() throws MalformedURLException { - File dir = new File(System.getProperty("user.dir")); - File subdir = new File(dir, "with space"); - File file1 = new File(subdir, "file"); - - String fileUrl = dir.toURI().toURL().toString(); - if (!fileUrl.endsWith("/")) { - fileUrl += "/"; - } - fileUrl += "with%20space/file"; - final URL url = new URL(fileUrl); - - File file2 = NativeLibraryLoader.getResource( - new ClassLoader() { - @Override - public URL getResource(String name) { - return url; - } - }, - "dummy"); - assertEquals("Files are equal", file1, file2); - } - - @Test public void testUnencoded() throws MalformedURLException { - File dir = new File(System.getProperty("user.dir")); - File subdir = new File(dir, "with space"); - File file1 = new File(subdir, "file"); - - String fileUrl = dir.toURI().toURL().toString(); - if (!fileUrl.endsWith("/")) { - fileUrl += "/"; - } - fileUrl += "with space/file"; - final URL url = new URL(fileUrl); - - File file2 = NativeLibraryLoader.getResource( - new ClassLoader() { - @Override - public URL getResource(String name) { - return url; - } - }, - "dummy"); - assertEquals("Files are equal", file1, file2); - } -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/jurt/test/com/sun/star/uno/AnyConverter_Test.java b/jurt/test/com/sun/star/uno/AnyConverter_Test.java deleted file mode 100644 index faa955a96582..000000000000 --- a/jurt/test/com/sun/star/uno/AnyConverter_Test.java +++ /dev/null @@ -1,904 +0,0 @@ -/* -*- 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.uno; - -import com.sun.star.lang.XTypeProvider; -import static org.junit.Assert.*; -import org.junit.Before; -import org.junit.Test; - -public final class AnyConverter_Test { - Any anyBool; - Any anyChar; - Any anyByte; - Any anyShort; - Any anyInt; - Any anyLong; - Any anyFloat; - Any anyDouble; - Any anyStr; - Any anyType; - Any anyArByte; - Any anyVoid; - Any anyXTypeProvider; - - Boolean aBool; - Character aChar; - Byte aByte; - Short aShort; - Integer aInt; - Long aLong; - Float aFloat; - Double aDouble; - Object aObj; - String aStr; - Type aType; - byte[] arByte; - - /** Class variables are initialized before each Test method */ - @Before public void setUp() - { - aBool= Boolean.TRUE; - aChar= new Character('A'); - aByte= Byte.valueOf((byte) 111); - aShort= Short.valueOf((short) 11111); - aInt= Integer.valueOf( 1111111); - aLong= Long.valueOf( 0xffffffff); - aFloat= new Float( 3.14); - aDouble= new Double( 3.145); - aObj= new ATypeProvider(); - aStr= "I am a string"; - aType= new Type(String.class); - arByte= new byte[] {1,2,3}; - - anyVoid= new Any(new Type(void.class), null); - anyBool= new Any(new Type(Boolean.TYPE), aBool); - anyChar= new Any(new Type(Character.TYPE), aChar); - anyByte= new Any(new Type(Byte.TYPE), aByte); - anyShort= new Any(new Type(Short.TYPE), aShort); - anyInt= new Any(new Type(Integer.TYPE), aInt); - anyLong= new Any(new Type(Long.TYPE), aLong); - anyFloat= new Any(new Type(Float.TYPE), aFloat); - anyDouble= new Any(new Type(Double.TYPE), aDouble); - anyStr= new Any(new Type(String.class), aStr); - anyType= new Any(new Type(Type.class), aType); - anyArByte= new Any(new Type(byte[].class), arByte); - anyXTypeProvider= new Any(new Type(XTypeProvider.class), aObj); - } - - @Test public void test_toBoolean() - throws com.sun.star.lang.IllegalArgumentException - { - // must work - boolean b= AnyConverter.toBoolean(aBool); - assertEquals(b, aBool.booleanValue()); - b= AnyConverter.toBoolean(anyBool); - assertEquals(b, ((Boolean)anyBool.getObject()).booleanValue()); - - // must fail - try { AnyConverter.toBoolean(aChar); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toBoolean(anyChar); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toBoolean(aByte); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toBoolean(anyByte); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toBoolean(aShort); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toBoolean(anyShort); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toBoolean(aInt); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toBoolean(anyInt); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toBoolean(aLong); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toBoolean(anyLong); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toBoolean(aFloat); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toBoolean(anyFloat); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toBoolean(aDouble); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toBoolean(anyDouble); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toBoolean(aObj); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toBoolean(aStr); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toBoolean(anyStr); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toBoolean(aType); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toBoolean(anyType); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toBoolean(anyVoid); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toBoolean(arByte); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toBoolean(anyArByte); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - } - - @Test public void test_toChar() - throws com.sun.star.lang.IllegalArgumentException - { - // must work - char b= AnyConverter.toChar(aChar); - assertEquals(b, aChar.charValue()); - b= AnyConverter.toChar(anyChar); - assertEquals(b, ((Character)anyChar.getObject()).charValue()); - - // must fail - try { AnyConverter.toChar(aBool); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toChar(anyBool); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toChar(aByte); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toChar(anyByte); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toChar(aShort); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toChar(anyShort); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toChar(aInt); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toChar(anyInt); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toChar(aLong); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toChar(anyLong); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toChar(aFloat); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toChar(anyFloat); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toChar(aDouble); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toChar(anyDouble); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toChar(aObj); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toChar(aStr); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toChar(anyStr); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toChar(aType); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toChar(anyType); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toChar(anyVoid); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toChar(arByte); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toChar(anyArByte); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - } - - @Test public void test_toByte() - throws com.sun.star.lang.IllegalArgumentException - { - // must work - byte val= AnyConverter.toByte(aByte); - assertEquals(val, aByte.byteValue()); - val= AnyConverter.toByte(anyByte); - assertEquals(val, ((Byte)anyByte.getObject()).byteValue()); - - // must fail - try { AnyConverter.toByte(aChar); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toByte(anyChar); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toByte(aShort); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toByte(anyShort); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toByte(aInt); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toByte(anyInt); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toByte(aLong); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toByte(anyLong); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toByte(aFloat); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toByte(anyFloat); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toByte(aDouble); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toByte(anyDouble); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toByte(aObj); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toByte(aStr); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toByte(anyStr); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toByte(aType); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toByte(anyType); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toByte(anyVoid); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toByte(arByte); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toByte(anyArByte); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - } - - @Test public void test_toShort() - throws com.sun.star.lang.IllegalArgumentException - { - // must work - short sh= AnyConverter.toShort(aByte); - assertEquals(sh, aByte.byteValue()); - sh= AnyConverter.toShort(aShort); - assertEquals(sh, aShort.shortValue()); - sh= AnyConverter.toShort(anyByte); - assertEquals(sh, ((Byte)anyByte.getObject()).byteValue()); - sh= AnyConverter.toShort(anyShort); - assertEquals(sh, ((Short) anyShort.getObject()).shortValue()); - Any a = new Any( Type.UNSIGNED_SHORT, Short.valueOf((short)5) ); - assertEquals(5, AnyConverter.toUnsignedShort( a )); - - // must fail - try { AnyConverter.toShort(a); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toUnsignedShort(anyShort); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toChar(aBool); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toChar(anyBool); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toShort(aChar); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toShort(anyChar); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toShort(aBool); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toShort(anyBool); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toShort(aInt); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toShort(anyInt); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toShort(aLong); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toShort(anyLong); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toShort(aFloat); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toShort(anyFloat); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toShort(aDouble); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toShort(anyDouble); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toShort(aObj); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toShort(aStr); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toShort(anyStr); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toShort(aType); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toShort(anyType); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toShort(anyVoid); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toShort(arByte); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toShort(anyArByte); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - } - - @Test public void test_toInt() - throws com.sun.star.lang.IllegalArgumentException - { - // must work - int val= AnyConverter.toInt(aByte); - assertEquals(val, aByte.byteValue()); - val= AnyConverter.toInt(aShort); - assertEquals(val, aShort.shortValue()); - val= AnyConverter.toInt(aInt); - assertEquals(val, aInt.intValue()); - val= AnyConverter.toInt(anyByte); - assertEquals(val, ((Byte)anyByte.getObject()).byteValue()); - val= AnyConverter.toInt(anyShort); - assertEquals(val, ((Short) anyShort.getObject()).shortValue()); - val= AnyConverter.toInt(anyInt); - assertEquals(val, ((Integer) anyInt.getObject()).intValue()); - Any a = new Any( Type.UNSIGNED_SHORT, Short.valueOf((short)5) ); - assertEquals(5, AnyConverter.toInt(a)); - assertEquals(5, AnyConverter.toUnsignedInt(a)); - a = new Any( Type.UNSIGNED_LONG, Integer.valueOf(5) ); - assertEquals(5, AnyConverter.toUnsignedInt(a)); - - // must fail - try { AnyConverter.toUnsignedInt(anyInt); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toInt(a); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toUnsignedInt(anyShort); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toInt(aChar); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toInt(anyChar); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toInt(aBool); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toInt(anyBool); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toInt(aLong); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toInt(anyLong); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toInt(aFloat); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toInt(anyFloat); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toInt(aDouble); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toInt(anyDouble); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toInt(aObj); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toInt(aStr); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toInt(anyStr); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toInt(aType); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toInt(anyType); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toInt(anyVoid); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toInt(arByte); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toInt(anyArByte); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - } - - @Test public void test_toLong() - throws com.sun.star.lang.IllegalArgumentException - { - // must work - long val= AnyConverter.toLong(aByte); - assertEquals(val, aByte.byteValue()); - val= AnyConverter.toLong(aShort); - assertEquals(val, aShort.shortValue()); - val= AnyConverter.toLong(aInt); - assertEquals(val, aInt.intValue()); - val= AnyConverter.toLong(aLong); - assertEquals(val, aLong.longValue()); - val= AnyConverter.toLong(anyByte); - assertEquals(val, ((Byte)anyByte.getObject()).byteValue()); - val= AnyConverter.toLong(anyShort); - assertEquals(val, ((Short) anyShort.getObject()).shortValue()); - val= AnyConverter.toLong(anyInt); - assertEquals(val, ((Integer) anyInt.getObject()).intValue()); - val= AnyConverter.toLong(anyLong); - assertEquals(val, ((Long) anyLong.getObject()).longValue()); - Any a = new Any( Type.UNSIGNED_SHORT, Short.valueOf((short)5) ); - assertEquals(5, AnyConverter.toLong(a)); - assertEquals(5, AnyConverter.toUnsignedLong(a)); - a = new Any( Type.UNSIGNED_LONG, Integer.valueOf(5) ); - assertEquals(5, AnyConverter.toUnsignedLong(a)); - assertEquals(5, AnyConverter.toLong(a)); - a = new Any( Type.UNSIGNED_HYPER, Long.valueOf(5) ); - assertEquals(5, AnyConverter.toUnsignedLong(a)); - - // must fail - try { AnyConverter.toUnsignedLong(anyShort); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toUnsignedLong(anyInt); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toLong(a); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toUnsignedLong(anyLong); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toLong(aChar); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toLong(anyChar); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toLong(aBool); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toLong(anyBool); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toLong(aFloat); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toLong(anyFloat); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toLong(aDouble); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toLong(anyDouble); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toLong(aObj); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toLong(aStr); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toLong(anyStr); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toLong(aType); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toLong(anyType); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toLong(anyVoid); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toLong(arByte); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toLong(anyArByte); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - } - - @Test public void test_toFloat() - throws com.sun.star.lang.IllegalArgumentException - { - // must work - float val= AnyConverter.toFloat(aByte); - assertEquals(val, aByte.byteValue(), 0); // 111 = 111.0 - val= AnyConverter.toFloat(anyByte); - assertEquals(val, ((Byte)anyByte.getObject()).byteValue(), 0); - val= AnyConverter.toFloat(aShort); - assertEquals(val, aShort.shortValue(), 0); //11111 = 11111.0 - val= AnyConverter.toFloat(anyShort); - assertEquals(val, ((Short) anyShort.getObject()).shortValue(), 0); - val= AnyConverter.toFloat(aFloat); - assertEquals(val, aFloat.floatValue(), 0); - val= AnyConverter.toFloat(anyFloat); - assertEquals(val, ((Float) anyFloat.getObject()).floatValue(), 0); - - // must fail - try { AnyConverter.toFloat(aChar); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toFloat(anyChar); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toFloat(aBool); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toFloat(anyBool); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toFloat(aInt); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toFloat(anyInt); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toFloat(aLong); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toFloat(anyLong); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toFloat(aDouble); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toFloat(anyDouble); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toFloat(aObj); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toFloat(aStr); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toFloat(anyStr); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toFloat(aType); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toFloat(anyType); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toFloat(anyVoid); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toFloat(arByte); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toFloat(anyArByte); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - } - - @Test public void test_toDouble() - throws com.sun.star.lang.IllegalArgumentException - { - // must work - double val= AnyConverter.toDouble(aByte); - assertEquals(val, aByte.byteValue(), 0); // 111 = 111.0 - val= AnyConverter.toDouble(anyByte); - assertEquals(val, ((Byte)anyByte.getObject()).byteValue(), 0); - val= AnyConverter.toDouble(aShort); - assertEquals(val, aShort.shortValue(), 0); //11111 = 11111.0 - val= AnyConverter.toDouble(anyShort); - assertEquals(val, ((Short) anyShort.getObject()).shortValue(), 0); - val= AnyConverter.toDouble(aInt); - assertEquals(val, aInt.intValue(), 0); - val= AnyConverter.toDouble(anyInt); - assertEquals(val, ((Integer) anyInt.getObject()).intValue(), 0); - val= AnyConverter.toDouble(aFloat); - assertEquals(val, aFloat.floatValue(), 0); - val= AnyConverter.toDouble(anyFloat); - float float1= ((Float) anyFloat.getObject()).floatValue(); - assertTrue(val <= (float1 + 0.1) || val >= (float1 - 0.1)); - val= AnyConverter.toDouble(aDouble); - assertEquals(val, aDouble.doubleValue(), 0); - val= AnyConverter.toDouble(anyDouble); - assertEquals(val, ((Double) anyDouble.getObject()).doubleValue(), 0); - - // must fail - try { AnyConverter.toDouble(aChar); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toDouble(anyChar); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toDouble(aBool); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toDouble(anyBool); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toDouble(aLong); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toDouble(anyLong); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toDouble(aObj); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toDouble(aStr); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toDouble(anyStr); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toDouble(aType); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toDouble(anyType); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toDouble(anyVoid); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toDouble(arByte); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toDouble(anyArByte); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - } - - @Test public void test_toObject() - throws com.sun.star.lang.IllegalArgumentException - { - // must work - Type _type= new Type(XTypeProvider.class); - Object val= AnyConverter.toObject(_type, aObj); - assertTrue(UnoRuntime.areSame(val, aObj)); - val= AnyConverter.toObject( - _type, new Any( new Type(XTypeProvider.class), null)); - assertNull(val); - - // structs, exceptions - com.sun.star.lang.IllegalArgumentException exc = - new com.sun.star.lang.IllegalArgumentException(); - Any any_exc = new Any( - new Type("com.sun.star.lang.IllegalArgumentException", - TypeClass.EXCEPTION), exc); - assertEquals( - exc, - AnyConverter.toObject( - new Type(com.sun.star.lang.IllegalArgumentException.class), - any_exc)); - assertEquals( - exc, - AnyConverter.toObject( - new Type(com.sun.star.uno.RuntimeException.class), any_exc)); - try { - AnyConverter.toObject( - new Type(com.sun.star.uno.Exception.class), any_exc); - fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - any_exc = new Any(com.sun.star.lang.IllegalArgumentException.class, - exc); - assertEquals( - exc, - AnyConverter.toObject( - new Type(com.sun.star.lang.IllegalArgumentException.class), - any_exc)); - assertEquals( - exc, - AnyConverter.toObject( - new Type(com.sun.star.uno.RuntimeException.class), any_exc)); - try { - AnyConverter.toObject( - new Type(com.sun.star.uno.Exception.class), any_exc); - fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - - // must fail - try { AnyConverter.toObject(_type, aType); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toObject(_type, anyType); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toObject(_type, anyVoid); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toObject(_type, new Object()); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - } - - @Test public void test_toString() - throws com.sun.star.lang.IllegalArgumentException - { - // must work - String val= AnyConverter.toString(aStr); - assertEquals(val, aStr); - val= AnyConverter.toString(anyStr); - assertEquals(val, anyStr.getObject()); - - // must fail - try { AnyConverter.toString(aBool); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toString(anyBool); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toString(aChar); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toString(anyChar); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toString(aByte); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toString(anyByte); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toString(aShort); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toString(anyShort); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toString(aInt); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toString(anyInt); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toString(aLong); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toString(anyLong); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toString(aFloat); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toString(anyFloat); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toString(aDouble); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toString(anyDouble); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toString(aObj); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toString(aType); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toString(anyType); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toString(anyVoid); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toString(arByte); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toString(anyArByte); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - } - - @Test public void test_toType() - throws com.sun.star.lang.IllegalArgumentException - { - // must work - Type val= AnyConverter.toType(aType); - assertSame(val, aType); - val= AnyConverter.toType(anyType); - assertSame(val, anyType.getObject()); - - // must fail - try { AnyConverter.toType(aBool); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toType(anyBool); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toType(aChar); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toType(anyChar); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toType(aByte); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toType(anyByte); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toType(aShort); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toType(anyShort); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toType(aInt); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toType(anyInt); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toType(aLong); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toType(anyLong); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toType(aFloat); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toType(anyFloat); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toType(aDouble); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toType(anyDouble); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toType(aObj); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toType(aStr); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toType(anyStr); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toType(anyVoid); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toType(arByte); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toType(anyArByte); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - } - - @Test public void test_toArray() - throws com.sun.star.lang.IllegalArgumentException - { - // must work - Object val= AnyConverter.toArray(arByte); - assertSame(val, arByte); - val= AnyConverter.toArray(anyArByte); - assertSame(val, anyArByte.getObject()); - - // must fail - try { AnyConverter.toType(aBool); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toType(anyBool); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toType(aChar); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toType(anyChar); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toType(aByte); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toType(anyByte); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toType(aShort); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toType(anyShort); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toType(aInt); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toType(anyInt); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toType(aLong); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toType(anyLong); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toType(aFloat); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toType(anyFloat); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toType(aDouble); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toType(anyDouble); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toType(aObj); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toType(aStr); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toType(anyStr); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toType(anyVoid); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toType(arByte); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - try { AnyConverter.toType(anyArByte); fail(); - } catch (com.sun.star.lang.IllegalArgumentException ie) {} - } - - @Test public void test_isBoolean() { - assertTrue(AnyConverter.isBoolean(aBool)); - assertTrue(AnyConverter.isBoolean(anyBool)); - assertFalse(AnyConverter.isBoolean(aChar)); - } - - @Test public void test_isChar() { - assertTrue(AnyConverter.isChar(aChar)); - assertTrue(AnyConverter.isChar(anyChar)); - assertFalse(AnyConverter.isChar(aBool)); - } - - @Test public void test_isByte() { - assertTrue(AnyConverter.isByte(aByte)); - assertTrue(AnyConverter.isByte(anyByte)); - assertFalse(AnyConverter.isByte(aBool)); - } - - @Test public void test_isShort() { - assertTrue(AnyConverter.isShort(aShort)); - assertTrue(AnyConverter.isShort(anyShort)); - assertEquals(Type.SHORT, AnyConverter.getType(anyShort)); - Any a = new Any( Type.UNSIGNED_SHORT, Short.valueOf((short)5) ); - assertEquals(Type.UNSIGNED_SHORT, AnyConverter.getType(a)); - assertFalse(AnyConverter.isShort(a)); - assertFalse(Type.SHORT.equals(AnyConverter.getType(a))); - assertFalse(AnyConverter.isShort(aBool)); - } - - @Test public void test_isInt() { - assertTrue(AnyConverter.isInt(aInt)); - assertTrue(AnyConverter.isInt(anyInt)); - assertEquals(Type.LONG, AnyConverter.getType(anyInt)); - Any a = new Any(Type.UNSIGNED_LONG, Integer.valueOf(5)); - assertEquals(Type.UNSIGNED_LONG, AnyConverter.getType(a)); - assertFalse(AnyConverter.isInt(a)); - assertFalse(Type.LONG.equals(AnyConverter.getType(a))); - assertFalse(AnyConverter.isInt(aBool)); - } - - @Test public void test_isLong() { - assertTrue(AnyConverter.isLong(aLong)); - assertTrue(AnyConverter.isLong(anyLong)); - assertEquals(Type.HYPER, AnyConverter.getType(anyLong)); - Any a = new Any( Type.UNSIGNED_HYPER, Long.valueOf(5) ); - assertEquals(Type.UNSIGNED_HYPER, AnyConverter.getType(a)); - assertFalse(AnyConverter.isLong(a)); - assertFalse(Type.HYPER.equals( AnyConverter.getType(a) )); - assertFalse(AnyConverter.isLong(aBool)); - } - - @Test public void test_isFloat() { - assertTrue(AnyConverter.isFloat(aFloat)); - assertTrue(AnyConverter.isFloat(anyFloat)); - assertFalse(AnyConverter.isFloat(aDouble)); - } - - @Test public void test_isDouble() { - assertTrue(AnyConverter.isDouble(aDouble)); - assertTrue(AnyConverter.isDouble(anyDouble)); - assertFalse(AnyConverter.isDouble(aFloat)); - } - - @Test public void test_isObject() { - assertTrue(AnyConverter.isObject(aObj)); - assertTrue(AnyConverter.isObject( new Any( XInterface.class, null))); - assertFalse(AnyConverter.isObject(new Object())); - } - - @Test public void test_isString() { - assertTrue(AnyConverter.isString(aStr)); - assertTrue(AnyConverter.isString(anyStr)); - assertFalse(AnyConverter.isString(new Object())); - } - - @Test public void test_isType() { - assertTrue(AnyConverter.isType(aType)); - assertTrue(AnyConverter.isType(anyType)); - assertFalse(AnyConverter.isType(new Object())); - } - - @Test public void test_isArray() { - assertTrue(AnyConverter.isArray(arByte)); - assertTrue(AnyConverter.isArray(anyArByte)); - assertFalse(AnyConverter.isArray(new Object())); - } - - @Test public void test_isVoid() { - assertTrue(AnyConverter.isVoid(anyVoid)); - assertFalse(AnyConverter.isVoid(new Object())); - } -} - - -class ATypeProvider implements com.sun.star.lang.XTypeProvider -{ - - public byte[] getImplementationId() - { - return new byte[0]; - } - - public com.sun.star.uno.Type[] getTypes() - { - return new Type[]{new Type(XTypeProvider.class)}; - } - -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/jurt/test/com/sun/star/uno/UnoRuntime_EnvironmentTest.java b/jurt/test/com/sun/star/uno/UnoRuntime_EnvironmentTest.java deleted file mode 100644 index b10adf12e650..000000000000 --- a/jurt/test/com/sun/star/uno/UnoRuntime_EnvironmentTest.java +++ /dev/null @@ -1,85 +0,0 @@ -/* -*- 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.uno; - -import com.sun.star.comp.connections.PipedConnection; -import org.junit.Test; -import util.WaitUnreachable; -import static org.junit.Assert.*; - -public final class UnoRuntime_EnvironmentTest { - @Test public void test_getEnvironment() throws java.lang.Exception { - Object o1 = new Object(); - Object o2 = new Object(); - - // get two environments with different contexts - WaitUnreachable java_environment1 = new WaitUnreachable( - UnoRuntime.getEnvironment("java", o1)); - WaitUnreachable java_environment2 = new WaitUnreachable( - UnoRuntime.getEnvironment("java", o2)); - - // ensure that the environments are different - assertNotSame(java_environment1.get(), java_environment2.get()); - - // test if we get the same environment when we reget it - assertTrue( - UnoRuntime.areSame( - java_environment1.get(), - UnoRuntime.getEnvironment("java", o1))); - assertTrue( - UnoRuntime.areSame( - java_environment2.get(), - UnoRuntime.getEnvironment("java", o2))); - - // drop the environments and wait until they are gc - java_environment1.waitUnreachable(); - java_environment2.waitUnreachable(); - } - - @Test public void test_getBridge() throws java.lang.Exception { - PipedConnection conn = new PipedConnection(new Object[0]); - new PipedConnection(new Object[] { conn }); - - // get a bridge - IBridge iBridge = UnoRuntime.getBridgeByName( - "java", null, "remote", "testname", - new Object[] { "urp", conn, null }); - - // reget the bridge, it must be the same as above - IBridge iBridge_tmp = UnoRuntime.getBridgeByName( - "java", null, "remote", "testname", - new Object[] { "urp", conn, null }); - assertTrue(UnoRuntime.areSame(iBridge_tmp, iBridge)); - - // dispose the bridge, this removes the entry from the runtime - iBridge.dispose(); - - conn = new PipedConnection(new Object[0]); - new PipedConnection(new Object[] { conn }); - - // reget the bridge, it must be a different one - iBridge_tmp = UnoRuntime.getBridgeByName( - "java", null, "remote", "testname", - new Object[]{ "urp", conn, null }); - assertFalse(UnoRuntime.areSame(iBridge_tmp, iBridge)); - } -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/jurt/test/com/sun/star/uno/WeakReference_Test.java b/jurt/test/com/sun/star/uno/WeakReference_Test.java deleted file mode 100644 index 960c05dad477..000000000000 --- a/jurt/test/com/sun/star/uno/WeakReference_Test.java +++ /dev/null @@ -1,107 +0,0 @@ -/* -*- 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.uno; - -import java.util.ArrayList; -import java.util.Iterator; -import org.junit.Test; -import util.WaitUnreachable; -import static org.junit.Assert.*; - -public final class WeakReference_Test { - @Test public void test() { - Object o = new MockWeak(); - WeakReference r1 = new WeakReference(o); - WeakReference r2 = new WeakReference(r1); - assertSame(o, r1.get()); - assertSame(o, r2.get()); - WaitUnreachable u = new WaitUnreachable(o); - o = null; - u.waitUnreachable(); - assertNull("a3", r1.get()); - assertNull("a4", r2.get()); - } - - private static final class MockWeak implements XWeak { - public XAdapter queryAdapter() { - return adapter; - } - - @Override - protected void finalize() throws Throwable { - adapter.dispose(); - super.finalize(); - } - - private static final class Adapter implements XAdapter { - public Adapter(Object obj) { - ref = new java.lang.ref.WeakReference<Object>(obj); - } - - public Object queryAdapted() { - return ref.get(); - } - - public void addReference(XReference ref) { - synchronized (this) { - if (listeners != null) { - listeners.add(ref); - return; - } - } - ref.dispose(); - } - - public synchronized void removeReference(XReference ref) { - if (listeners != null) { - listeners.remove(ref); - } - } - - public void dispose() { - ArrayList<XReference> l; - synchronized (this){ - l = listeners; - listeners = null; - } - if (l != null) { - java.lang.RuntimeException ex = null; - for (Iterator<XReference> i = l.iterator(); i.hasNext();) { - try { - i.next().dispose(); - } catch (java.lang.RuntimeException e) { - ex = e; - } - } - if (ex != null) { - throw ex; - } - } - } - - private final java.lang.ref.WeakReference<Object> ref; - private ArrayList<XReference> listeners = new ArrayList<XReference>(); - } - - private final Adapter adapter = new Adapter(this); - } -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |