diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:06:44 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:06:44 +0000 |
commit | ed5640d8b587fbcfed7dd7967f3de04b37a76f26 (patch) | |
tree | 7a5f7c6c9d02226d7471cb3cc8fbbf631b415303 /testtools/source/servicetests | |
parent | Initial commit. (diff) | |
download | libreoffice-upstream.tar.xz libreoffice-upstream.zip |
Adding upstream version 4:7.4.7.upstream/4%7.4.7upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | testtools/source/servicetests/LocalServiceTest.java | 45 | ||||
-rw-r--r-- | testtools/source/servicetests/RemoteServiceTest.java | 113 | ||||
-rw-r--r-- | testtools/source/servicetests/TestBase.java | 80 | ||||
-rw-r--r-- | testtools/source/servicetests/TestService.java | 127 | ||||
-rw-r--r-- | testtools/source/servicetests/TestService1.idl | 49 | ||||
-rw-r--r-- | testtools/source/servicetests/TestService2.idl | 41 | ||||
-rw-r--r-- | testtools/source/servicetests/XTestService1.idl | 35 | ||||
-rw-r--r-- | testtools/source/servicetests/XTestService2.idl | 35 | ||||
-rw-r--r-- | testtools/source/servicetests/XTestService3.idl | 35 | ||||
-rw-r--r-- | testtools/source/servicetests/XTestService4.idl | 35 | ||||
-rw-r--r-- | testtools/source/servicetests/makefile.mk | 35 |
11 files changed, 630 insertions, 0 deletions
diff --git a/testtools/source/servicetests/LocalServiceTest.java b/testtools/source/servicetests/LocalServiceTest.java new file mode 100644 index 000000000..ee890faa4 --- /dev/null +++ b/testtools/source/servicetests/LocalServiceTest.java @@ -0,0 +1,45 @@ +/* + * 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 servicetests; + +import com.sun.star.comp.helper.Bootstrap; +import com.sun.star.container.XSet; +import com.sun.star.lang.XMultiComponentFactory; +import com.sun.star.uno.UnoRuntime; +import com.sun.star.uno.XComponentContext; + +public final class LocalServiceTest extends TestBase { + @Override + protected TestServiceFactory getTestServiceFactory() throws Exception { + return new TestServiceFactory() { + public Object get() throws Exception { + XComponentContext context + = Bootstrap.createInitialComponentContext(null); + XMultiComponentFactory serviceManager + = context.getServiceManager(); + UnoRuntime.queryInterface(XSet.class, serviceManager). + insert(new TestService()); + return serviceManager.createInstanceWithContext( + "testtools.servicetests.TestService2", context); + } + + public void dispose() throws Exception {} + }; + } +} diff --git a/testtools/source/servicetests/RemoteServiceTest.java b/testtools/source/servicetests/RemoteServiceTest.java new file mode 100644 index 000000000..e63048bf6 --- /dev/null +++ b/testtools/source/servicetests/RemoteServiceTest.java @@ -0,0 +1,113 @@ +/* + * 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 servicetests; + +import com.sun.star.bridge.XBridgeFactory; +import com.sun.star.bridge.XInstanceProvider; +import com.sun.star.bridge.XUnoUrlResolver; +import com.sun.star.bridge.UnoUrlResolver; +import com.sun.star.comp.helper.Bootstrap; +import com.sun.star.connection.Acceptor; +import com.sun.star.connection.XConnection; +import com.sun.star.container.XSet; +import com.sun.star.lang.XMultiComponentFactory; +import com.sun.star.uno.UnoRuntime; +import com.sun.star.uno.XComponentContext; +import java.io.BufferedReader; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.PrintStream; + +public final class RemoteServiceTest extends TestBase { + @Override + protected TestServiceFactory getTestServiceFactory() throws Exception { + final Process p = Runtime.getRuntime().exec(new String[] { + "java", "-classpath", System.getProperty("java.class.path"), + Server.class.getName() }); + pipe(p.getInputStream(), System.out, "CO> "); + pipe(p.getErrorStream(), System.err, "CE> "); + Thread.sleep(5000); // wait for server to start accepting + return new TestServiceFactory() { + public Object get() throws Exception { + XUnoUrlResolver resolver = UnoUrlResolver.create(Bootstrap.createInitialComponentContext(null)); + String sUrl = "uno:" + CONNECTION_DESCRIPTION + ";" + + PROTOCOL_DESCRIPTION + + ";testtools.servicetests.TestService2"; + return resolver.resolve(sUrl); + } + + public void dispose() throws Exception { + p.waitFor(); + } + }; + } + + public static final class Server { + public static void main(String[] arguments) throws Exception { + XComponentContext context + = Bootstrap.createInitialComponentContext(null); + XMultiComponentFactory serviceManager + = context.getServiceManager(); + UnoRuntime.queryInterface(XSet.class, serviceManager). + insert(new TestService()); + final Object instance = serviceManager.createInstanceWithContext( + "testtools.servicetests.TestService2", context); + XBridgeFactory bridgeFactory + = UnoRuntime.queryInterface( + XBridgeFactory.class, + serviceManager.createInstanceWithContext( + "com.sun.star.bridge.BridgeFactory", context)); + XConnection connection = Acceptor.create(context).accept( + CONNECTION_DESCRIPTION); + bridgeFactory.createBridge( + "", PROTOCOL_DESCRIPTION, connection, + new XInstanceProvider() { + public Object getInstance(String instanceName) { + return instance; + } + }); + } + } + + private void pipe(final InputStream in, final PrintStream out, + final String prefix) { + new Thread("Pipe: " + prefix) { + @Override + public void run() { + BufferedReader r + = new BufferedReader(new InputStreamReader(in)); + try { + for (;;) { + String s = r.readLine(); + if (s == null) { + break; + } + out.println(prefix + s); + } + } catch (java.io.IOException e) { + e.printStackTrace(System.err); + } + } + }.start(); + } + + private static final String CONNECTION_DESCRIPTION + = "socket,host=localhost,port=12345"; + private static final String PROTOCOL_DESCRIPTION = "urp"; +} diff --git a/testtools/source/servicetests/TestBase.java b/testtools/source/servicetests/TestBase.java new file mode 100644 index 000000000..20532ff4d --- /dev/null +++ b/testtools/source/servicetests/TestBase.java @@ -0,0 +1,80 @@ +/* + * 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 servicetests; + +import com.sun.star.uno.UnoRuntime; +import complexlib.ComplexTestCase; +import util.WaitUnreachable; + +public abstract class TestBase extends ComplexTestCase { + @Override + public final String[] getTestMethodNames() { + return new String[] { "test" }; + } + + public final void test() throws Exception { + TestServiceFactory factory = getTestServiceFactory(); + TestService2 t = UnoRuntime.queryInterface( + TestService2.class, factory.get()); + assure(t != null); + assure(UnoRuntime.queryInterface(TestService1.class, t) == t); + assure(UnoRuntime.queryInterface(XTestService1.class, t) == t); + assure(UnoRuntime.queryInterface(XTestService2.class, t) == t); + assure(t.fn1() == 1); + assure(t.getProp1() == 1); + t.setProp1(0); + assure(t.getProp1() == 0); + assure(t.getProp2() == 2); + assure(t.getProp3Long() == 3); + assure(t.getProp4Long() == 4); + assure(t.getProp5Long() == 5); + assure(t.getProp6() == 6); + t.setProp6(0); + assure(t.getProp6() == 0); + assure(t.getProp7() == 7); + t.setProp7(0); + assure(t.getProp7() == 0); + assure(t.getProp8Long() == 8); + t.setProp8Long(0); + assure(t.getProp8Long() == 0); + assure(t.fn2() == 2); + XTestService3 t3 = UnoRuntime.queryInterface(XTestService3.class, t); + assure(t3 != null); + assure(t3.fn3() == 3); + XTestService4 t4 = UnoRuntime.queryInterface(XTestService4.class, t); + assure(t4 == null); + WaitUnreachable u = new WaitUnreachable(t); + t = null; + WaitUnreachable.ensureFinalization(t3); + t3 = null; + WaitUnreachable.ensureFinalization(t4); + t4 = null; + u.waitUnreachable(); + factory.dispose(); + } + + protected abstract TestServiceFactory getTestServiceFactory() + throws Exception; + + protected interface TestServiceFactory { + Object get() throws Exception; + + void dispose() throws Exception; + } +} diff --git a/testtools/source/servicetests/TestService.java b/testtools/source/servicetests/TestService.java new file mode 100644 index 000000000..a825f0df1 --- /dev/null +++ b/testtools/source/servicetests/TestService.java @@ -0,0 +1,127 @@ +/* + * 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 servicetests; + +import com.sun.star.lang.NoSupportException; +import com.sun.star.lang.XServiceInfo; +import com.sun.star.lang.XSingleComponentFactory; +/*import com.sun.star.uno.OptionalPropertyException;*/ +/*import com.sun.star.uno.VoidPropertyException;*/ +import com.sun.star.uno.XComponentContext; + +public final class TestService implements XServiceInfo, XSingleComponentFactory +{ + public String getImplementationName() { + return getClass().getName(); + } + + public boolean supportsService(String serviceName) { + return serviceName.equals(SERVICE_NAME); + } + + public String[] getSupportedServiceNames() { + return new String[] { SERVICE_NAME }; + } + + public Object createInstanceWithContext(XComponentContext context) + throws com.sun.star.uno.Exception + { + return new Service(); + } + + public Object createInstanceWithArgumentsAndContext( + Object[] arguments, XComponentContext context) + throws com.sun.star.uno.Exception + { + throw new NoSupportException( + "createInstanceWithArgumentsAndContext", this); + } + + private static final class Service implements TestService2, XTestService3 { + public int fn1() { + return 1; + } + + public int getProp1() { + return prop1; + } + + public void setProp1(int value) { + prop1 = value; + } + + public int getProp2() { + return 2; + } + + public int getProp3Long(){ + return 3; + } + public int getProp4Long(){ + return 4; + } + + public int getProp5Long() + { + return 5; + } + + public int getProp6() { + return prop6.intValue(); + } + + public void setProp6(int value) { + prop6 = Integer.valueOf(value); + } + + public int getProp7() + { + return prop7.intValue(); + } + + public void setProp7(int value) { + prop7 = Integer.valueOf(value); + } + + public int getProp8Long() { + return prop8; + } + + public void setProp8Long(int value) + { + prop8 = value; + } + + public int fn2() { + return 2; + } + + public int fn3() { + return 3; + } + + private int prop1 = 1; + private Integer prop6 = Integer.valueOf(6); + private Integer prop7 = Integer.valueOf(7); + private int prop8 = 8; + } + + private static final String SERVICE_NAME + = "testtools.servicetests.TestService2"; +} diff --git a/testtools/source/servicetests/TestService1.idl b/testtools/source/servicetests/TestService1.idl new file mode 100644 index 000000000..386b62e58 --- /dev/null +++ b/testtools/source/servicetests/TestService1.idl @@ -0,0 +1,49 @@ +/* -*- 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 . + */ + +#ifndef __testtools_servicetests_TestService1_idl__ +#define __testtools_servicetests_TestService1_idl__ + +#include <XTestService1.idl> + +module servicetests { + +interface TestService1 { + interface XTestService1; + [attribute] long Prop1; + [attribute, readonly] long Prop2; + /*[attribute, readonly, maybevoid] long Prop3Void;*/ + [attribute, readonly/*, maybevoid*/] long Prop3Long; + /*[attribute, readonly, optional] long Prop4None;*/ + [attribute, readonly/*, optional*/] long Prop4Long; + /*[attribute, readonly, maybevoid, optional] long Prop5None;*/ + /*[attribute, readonly, maybevoid, optional] long Prop5Void;*/ + [attribute, readonly/*, maybevoid, optional*/] long Prop5Long; + [attribute/*, maybevoid*/] long Prop6; + /*[attribute, maybevoid, optional] long Prop7None;*/ + [attribute/*, maybevoid, optional*/] long Prop7; + /*[attribute, optional] long Prop8None;*/ + [attribute/*, optional*/] long Prop8Long; +}; + +}; + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/testtools/source/servicetests/TestService2.idl b/testtools/source/servicetests/TestService2.idl new file mode 100644 index 000000000..dc06f5c45 --- /dev/null +++ b/testtools/source/servicetests/TestService2.idl @@ -0,0 +1,41 @@ +/* -*- 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 . + */ + +#ifndef __testtools_servicetests_TestService2_idl__ +#define __testtools_servicetests_TestService2_idl__ + +#include <TestService1.idl> +#include <XTestService2.idl> +#include <XTestService3.idl> +#include <XTestService4.idl> + +module servicetests { + +interface TestService2 { + interface TestService1; + interface XTestService2; + /*[optional] interface XTestService3;*/ + /*[optional] interface XTestService4;*/ +}; + +}; + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/testtools/source/servicetests/XTestService1.idl b/testtools/source/servicetests/XTestService1.idl new file mode 100644 index 000000000..9e0d80295 --- /dev/null +++ b/testtools/source/servicetests/XTestService1.idl @@ -0,0 +1,35 @@ +/* -*- 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 . + */ + +#ifndef __testtools_servicetests_XTestService1_idl__ +#define __testtools_servicetests_XTestService1_idl__ + +#include <com/sun/star/uno/XInterface.idl> + +module servicetests { + +interface XTestService1: com::sun::star::uno::XInterface { + long fn1(); +}; + +}; + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/testtools/source/servicetests/XTestService2.idl b/testtools/source/servicetests/XTestService2.idl new file mode 100644 index 000000000..98f48b49b --- /dev/null +++ b/testtools/source/servicetests/XTestService2.idl @@ -0,0 +1,35 @@ +/* -*- 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 . + */ + +#ifndef __testtools_servicetests_XTestService2_idl__ +#define __testtools_servicetests_XTestService2_idl__ + +#include <com/sun/star/uno/XInterface.idl> + +module servicetests { + +interface XTestService2: com::sun::star::uno::XInterface { + long fn2(); +}; + +}; + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/testtools/source/servicetests/XTestService3.idl b/testtools/source/servicetests/XTestService3.idl new file mode 100644 index 000000000..493426542 --- /dev/null +++ b/testtools/source/servicetests/XTestService3.idl @@ -0,0 +1,35 @@ +/* -*- 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 . + */ + +#ifndef __testtools_servicetests_XTestService3_idl__ +#define __testtools_servicetests_XTestService3_idl__ + +#include <com/sun/star/uno/XInterface.idl> + +module servicetests { + +interface XTestService3: com::sun::star::uno::XInterface { + long fn3(); +}; + +}; + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/testtools/source/servicetests/XTestService4.idl b/testtools/source/servicetests/XTestService4.idl new file mode 100644 index 000000000..f2d7e5b9b --- /dev/null +++ b/testtools/source/servicetests/XTestService4.idl @@ -0,0 +1,35 @@ +/* -*- 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 . + */ + +#ifndef __testtools_servicetests_XTestService4_idl__ +#define __testtools_servicetests_XTestService4_idl__ + +#include <com/sun/star/uno/XInterface.idl> + +module servicetests { + +interface XTestService4: com::sun::star::uno::XInterface { + long fn4(); +}; + +}; + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/testtools/source/servicetests/makefile.mk b/testtools/source/servicetests/makefile.mk new file mode 100644 index 000000000..fd59d8415 --- /dev/null +++ b/testtools/source/servicetests/makefile.mk @@ -0,0 +1,35 @@ +# +# 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 . +# + +PRJ := ..$/.. +PRJNAME := testtools +TARGET := testtools_servicetests + +PACKAGE := servicetests +JAVATESTFILES := LocalServiceTest.java RemoteServiceTest.java +JAVAFILES := TestBase.java TestService.java +IDLTESTFILES := \ + TestService1.idl \ + TestService2.idl \ + XTestService1.idl \ + XTestService2.idl \ + XTestService3.idl \ + XTestService4.idl +JARFILES := juh.jar jurt.jar ridl.jar + +.INCLUDE: javaunittest.mk |