diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-15 05:54:39 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-15 05:54:39 +0000 |
commit | 267c6f2ac71f92999e969232431ba04678e7437e (patch) | |
tree | 358c9467650e1d0a1d7227a21dac2e3d08b622b2 /stoc/test/javavm | |
parent | Initial commit. (diff) | |
download | libreoffice-267c6f2ac71f92999e969232431ba04678e7437e.tar.xz libreoffice-267c6f2ac71f92999e969232431ba04678e7437e.zip |
Adding upstream version 4:24.2.0.upstream/4%24.2.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'stoc/test/javavm')
-rw-r--r-- | stoc/test/javavm/jvm_interaction/interactionhandler.cxx | 186 | ||||
-rw-r--r-- | stoc/test/javavm/jvm_interaction/makefile.mk | 71 | ||||
-rw-r--r-- | stoc/test/javavm/makefile.mk | 59 | ||||
-rw-r--r-- | stoc/test/javavm/testapplet/TestApplet.html | 19 | ||||
-rw-r--r-- | stoc/test/javavm/testapplet/TestApplet.java | 53 | ||||
-rw-r--r-- | stoc/test/javavm/testapplet/makefile.mk | 43 | ||||
-rw-r--r-- | stoc/test/javavm/testcomponent/TestComponent.java | 129 | ||||
-rw-r--r-- | stoc/test/javavm/testcomponent/makefile.mk | 45 | ||||
-rw-r--r-- | stoc/test/javavm/testcomponent/manifest | 1 | ||||
-rw-r--r-- | stoc/test/javavm/testjavavm.cxx | 151 | ||||
-rw-r--r-- | stoc/test/javavm/testjavavm.java | 30 |
11 files changed, 787 insertions, 0 deletions
diff --git a/stoc/test/javavm/jvm_interaction/interactionhandler.cxx b/stoc/test/javavm/jvm_interaction/interactionhandler.cxx new file mode 100644 index 0000000000..f1c4baf863 --- /dev/null +++ b/stoc/test/javavm/jvm_interaction/interactionhandler.cxx @@ -0,0 +1,186 @@ +/* -*- 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 <jni.h> + +#include <stdio.h> +#include <sal/main.h> +#include <rtl/process.h> + +#include <cppuhelper/servicefactory.hxx> +#include <cppuhelper/weak.hxx> +#include <cppuhelper/bootstrap.hxx> +#include <osl/thread.h> + +#include <com/sun/star/registry/XSimpleRegistry.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/lang/XMultiComponentFactory.hpp> +#include <com/sun/star/java/XJavaVM.hpp> +#include <com/sun/star/registry/XImplementationRegistration.hpp> +#include <com/sun/star/java/XJavaThreadRegister_11.hpp> + +#include <com/sun/star/uno/XCurrentContext.hpp> +#include <com/sun/star/task/XInteractionHandler.hpp> +#include <com/sun/star/task/XInteractionRequest.hpp> +#include <com/sun/star/task/XInteractionContinuation.hpp> +#include <com/sun/star/task/XInteractionAbort.hpp> +#include <com/sun/star/task/XInteractionRetry.hpp> +#include <com/sun/star/java/JavaNotConfiguredException.hpp> +#include <com/sun/star/java/MissingJavaRuntimeException.hpp> +#include <com/sun/star/java/JavaDisabledException.hpp> +#include <com/sun/star/java/JavaVMCreationFailureException.hpp> +#include <cppuhelper/implbase.hxx> +#include <uno/current_context.hxx> + +using namespace cppu; +using namespace css::uno; +using namespace css::lang; +using namespace css::registry; +using namespace css::java; +using namespace css::task; + + +#define INTERACTION_HANDLER_NAME "java-vm.interaction-handler" + +class Context: public WeakImplHelper<XCurrentContext> +{ + virtual Any SAL_CALL getValueByName( const OUString& Name ) throw (RuntimeException); +}; + +class InteractionHandler: public WeakImplHelper<XInteractionHandler> +{ + virtual void SAL_CALL handle( const Reference< XInteractionRequest >& Request ) + throw (RuntimeException); +}; + +Any SAL_CALL Context::getValueByName( const OUString& Name) throw (RuntimeException) +{ + Any retVal; + if( Name.equals( INTERACTION_HANDLER_NAME)) + { + Reference<XInteractionHandler> handler(new InteractionHandler()); + retVal <<= handler; + } + return retVal; +} + +void SAL_CALL InteractionHandler::handle( const Reference< XInteractionRequest >& Request ) + throw (RuntimeException) +{ + Any anyExc= Request->getRequest(); + Sequence<Reference< XInteractionContinuation> >seqCont= Request->getContinuations(); + + Reference<XInteractionAbort> abort; + Reference<XInteractionRetry> retry; + + for (sal_Int32 i= 0; i < seqCont.getLength(); i++) + { + abort.set( seqCont[i], UNO_QUERY ); + if(abort.is()) + break; + } + for (sal_Int32 i= 0; i < seqCont.getLength(); i++) + { + retry.set( seqCont[i], UNO_QUERY ); + if(retry.is()) + break; + } + + static int cRetry= 0; + + if( cRetry++ == 5) + { + if( abort.is()) + abort->select(); + return; + } + if( retry.is()) + retry->select(); +} + +sal_Bool test1(const Reference< XMultiServiceFactory > & xMgr ) +{ + sal_Bool retVal= sal_True; + setCurrentContext(Reference<XCurrentContext>(new Context()); + + OUString sVMService("com.sun.star.java.JavaVirtualMachine"); + Reference<XInterface> xXInt= xMgr->createInstance(sVMService); + if( ! xXInt.is()) + return sal_False; + Reference<XJavaVM> xVM( xXInt, UNO_QUERY); + if( ! xVM.is()) + return sal_False; + + + sal_Int8 arId[16]; + rtl_getGlobalProcessId((sal_uInt8*) arId); + + Any anyVM; + try + { + anyVM = xVM->getJavaVM( Sequence<sal_Int8>(arId, 16)); + } + catch (const JavaNotConfiguredException& e) + { + OString msg= OUStringToOString(e.Message, osl_getThreadTextEncoding()); + printf("JavaNotConfiguredException: %s\n", msg.getStr()); + } + catch (const JavaVMCreationFailureException& e) + { + OString msg= OUStringToOString(e.Message, osl_getThreadTextEncoding()); + printf("JavaVMCreationFailureException: %s\n", msg.getStr()); + } + catch (const MissingJavaRuntimeException& e) + { + OString msg= OUStringToOString(e.Message, osl_getThreadTextEncoding()); + printf("MissingJavaRuntimeException: %s\n", msg.getStr()); + } + catch (const JavaDisabledException& e) + { + OString msg= OUStringToOString(e.Message, osl_getThreadTextEncoding()); + printf("JavaDisabledException: %s\n", msg.getStr()); + } + catch (const RuntimeException & e) + { + OString msg= OUStringToOString(e.Message, osl_getThreadTextEncoding()); + printf("###RuntimeException: %s\n", msg.getStr()); + retVal= sal_False; + } + return retVal; +} + +SAL_IMPLEMENT_MAIN() +{ + Reference<XSimpleRegistry> xreg= createSimpleRegistry(); + xreg->open( OUString("applicat.rdb"), + sal_False, sal_False ); + + Reference< XComponentContext > context= bootstrap_InitialComponentContext(xreg); + Reference<XMultiComponentFactory> fac= context->getServiceManager(); + Reference<XMultiServiceFactory> xMgr( fac, UNO_QUERY); + + sal_Bool bSucc = test1(xMgr); + Reference< XComponent > xCompContext( context, UNO_QUERY ); + xCompContext->dispose(); + return (bSucc ? 0 : -1); +} + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/stoc/test/javavm/jvm_interaction/makefile.mk b/stoc/test/javavm/jvm_interaction/makefile.mk new file mode 100644 index 0000000000..c9c1084a52 --- /dev/null +++ b/stoc/test/javavm/jvm_interaction/makefile.mk @@ -0,0 +1,71 @@ +# +# 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=..$/..$/.. +TARGET= jvminteraction +PRJNAME= stoc +TARGET6= $(TARGET) +TARGETTYPE= CUI +LIBTARGET= NO +ENABLE_EXCEPTIONS=TRUE + +UNOUCRDEP= $(SOLARBINDIR)$/udkapi.rdb +UNOUCRRDB= $(SOLARBINDIR)$/udkapi.rdb +UNOUCROUT= $(OUT)$/inc$ +INCPRE+= $(OUT)$/inc$ + + + +# --- Settings ----------------------------------------------------- +.INCLUDE : settings.mk + +# --- Application 6 - testjavavm ------------------------------------ + +UNOTYPES= com.sun.star.lang.XMultiComponentFactory \ + com.sun.star.uno.XWeak \ + com.sun.star.java.XJavaVM \ + com.sun.star.java.XJavaThreadRegister_11 \ + com.sun.star.java.JavaNotConfiguredException \ + com.sun.star.java.MissingJavaRuntimeException \ + com.sun.star.java.JavaDisabledException \ + com.sun.star.java.JavaVMCreationFailureException \ + com.sun.star.registry.XSimpleRegistry \ + com.sun.star.lang.XComponent \ + com.sun.star.registry.XImplementationRegistration \ + com.sun.star.lang.XSingleServiceFactory \ + com.sun.star.uno.TypeClass \ + com.sun.star.lang.XMultiServiceFactory \ + com.sun.star.uno.XCurrentContext \ + com.sun.star.task.XInteractionHandler \ + com.sun.star.task.XInteractionRequest \ + com.sun.star.task.XInteractionContinuation \ + com.sun.star.task.XInteractionAbort \ + com.sun.star.task.XInteractionRetry \ + + +APP6TARGET= $(TARGET6) +APP6OBJS = $(OBJ)$/interactionhandler.obj +APP6STDLIBS= \ + $(CPPULIB) \ + $(CPPUHELPERLIB) \ + $(SALHELPERLIB) \ + $(SALLIB) + +# --- Target ------------------------------------------------ + +.INCLUDE : target.mk + diff --git a/stoc/test/javavm/makefile.mk b/stoc/test/javavm/makefile.mk new file mode 100644 index 0000000000..eb0ffb7619 --- /dev/null +++ b/stoc/test/javavm/makefile.mk @@ -0,0 +1,59 @@ +# +# 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=..$/.. +TARGET= testjavavm +PRJNAME= stoc +TARGET6= testjavavm +TARGETTYPE= CUI +LIBTARGET= NO +ENABLE_EXCEPTIONS=TRUE + +UNOUCRDEP= $(SOLARBINDIR)$/udkapi.rdb +UNOUCRRDB= $(SOLARBINDIR)$/udkapi.rdb +UNOUCROUT= $(OUT)$/inc$ +INCPRE+= $(OUT)$/inc$ + +# --- Settings ----------------------------------------------------- + +.INCLUDE : settings.mk + +# --- Application 6 - testjavavm ------------------------------------ + +UNOTYPES= com.sun.star.lang.XMultiComponentFactory \ + com.sun.star.uno.XWeak \ + com.sun.star.java.XJavaVM \ + com.sun.star.java.XJavaThreadRegister_11 \ + com.sun.star.registry.XSimpleRegistry \ + com.sun.star.lang.XComponent \ + com.sun.star.registry.XImplementationRegistration \ + com.sun.star.lang.XSingleServiceFactory \ + com.sun.star.uno.TypeClass \ + com.sun.star.lang.XMultiServiceFactory + +APP6TARGET= $(TARGET6) +APP6OBJS = $(OBJ)$/testjavavm.obj +APP6STDLIBS= \ + $(CPPULIB) \ + $(CPPUHELPERLIB) \ + $(SALHELPERLIB) \ + $(SALLIB) + +# --- Target ------------------------------------------------ + +.INCLUDE : target.mk + diff --git a/stoc/test/javavm/testapplet/TestApplet.html b/stoc/test/javavm/testapplet/TestApplet.html new file mode 100644 index 0000000000..e83d2ffe7d --- /dev/null +++ b/stoc/test/javavm/testapplet/TestApplet.html @@ -0,0 +1,19 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN"> +<HTML> +<HEAD> + <META HTTP-EQUIV="CONTENT-TYPE" CONTENT="text/html; charset=windows-1252"> + <TITLE>A Clock (1.1)</TITLE> + <META NAME="GENERATOR" CONTENT="StarOffice 6.0 (Win32)"> + <META NAME="CREATED" CONTENT="20011119;12262427"> + <META NAME="CHANGED" CONTENT="16010101;0"> +</HEAD> +<BODY LANG="de-DE"> +<H1>TestApplet</H1> +<HR> +<P> +<APPLET CODE="TestApplet.class" ALIGN=BOTTOM WIDTH=170 HEIGHT=150> +</APPLET> +</P> + +</BODY> +</HTML>
\ No newline at end of file diff --git a/stoc/test/javavm/testapplet/TestApplet.java b/stoc/test/javavm/testapplet/TestApplet.java new file mode 100644 index 0000000000..e271f4dd1f --- /dev/null +++ b/stoc/test/javavm/testapplet/TestApplet.java @@ -0,0 +1,53 @@ +/* + * 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 . + */ + +import java.awt.Color; +import java.io.File; +import java.io.IOException; +import java.net.URL; +import java.net.MalformedURLException; + +public class TestApplet extends java.applet.Applet { + + /** Initialization method that will be called after the applet is loaded + * into the browser. + */ + @Override + public void init () { + setBackground( Color.green); + resize( 300, 300); + + // Security tests. + File f= new File("d:\\temp\\javasecurity.txt"); + try { + f.createNewFile(); + + // local connection + URL url= new URL("http://localhost:8080/index.html"); + url.openStream(); + // remote connection + url= new URL("http://www.w3.org/index.html"); + url.openStream(); + }catch( MalformedURLException mue) { + }catch( IOException e) { + String s= e.getMessage(); + System.out.println(s); + } + + } +} diff --git a/stoc/test/javavm/testapplet/makefile.mk b/stoc/test/javavm/testapplet/makefile.mk new file mode 100644 index 0000000000..c2b5a2001f --- /dev/null +++ b/stoc/test/javavm/testapplet/makefile.mk @@ -0,0 +1,43 @@ +# +# 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 = testapplet +PACKAGE = +TARGET = TestApplet + +# --- Settings ----------------------------------------------------- + +.INCLUDE : settings.mk + +# Files -------------------------------------------------------- + +JARFILES = ridl.jar jurt.jar unoil.jar + +JAVAFILES= $(subst,$(CLASSDIR)$/$(PACKAGE)$/, $(subst,.class,.java $(JAVACLASSFILES))) + + +JAVACLASSFILES= \ + $(CLASSDIR)$/$(PACKAGE)$/TestApplet.class + +JARCLASSDIRS= . + +# --- Targets ------------------------------------------------------ + +.INCLUDE : target.mk diff --git a/stoc/test/javavm/testcomponent/TestComponent.java b/stoc/test/javavm/testcomponent/TestComponent.java new file mode 100644 index 0000000000..d976323c5f --- /dev/null +++ b/stoc/test/javavm/testcomponent/TestComponent.java @@ -0,0 +1,129 @@ +/* + * 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 . + */ + +import com.sun.star.comp.loader.FactoryHelper; +import com.sun.star.lang.*; +import com.sun.star.uno.*; +import com.sun.star.registry.XRegistryKey; +import java.io.*; +import java.net.*; + + +/** This component implements XTypeProvider for use with StarBasic. + * The XServiceInfo is implemented to have an interface in which we can put some + * code just for the sake of debugging. + * + * To debug with JPDA (jdk 1.3), put these lines in the java.ini within the [Java] section: + * -Xdebug + * -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=y + * + * When the Virtual Machine service is instantiated it will block until the debugger + * attaches to it on port 8000. You can chose a different port. You attach to the VM using + * jdb by + * + * jdb -connect com.sun.jdi.SocketAttach:hostname=myhost,port=8000 + * + * myhost is the hostname where the VM is running. +*/ +public class TestComponent implements XServiceInfo, XTypeProvider +{ + public static final String __serviceName="JavaTestComponent"; + + // XTypeProvider + public com.sun.star.uno.Type[] getTypes( ) + { + Type[] retValue= new Type[2]; + retValue[0]= new Type( XServiceInfo.class); + retValue[1]= new Type( XTypeProvider.class); + return retValue; + } + // XTypeProvider + public byte[] getImplementationId( ) + { + return new byte[0]; + } + + + // XServiceName + public String getImplementationName( ) + { + // the functions are for debugging + + // Test security settings + File f= new File("c:/temp/javasecurity.txt"); + try { + f.createNewFile(); + + // local connection + URL url= new URL("http://localhost:8080/index.html"); + url.openStream(); + // remote connection + url= new URL("http://www.w3.org/index.html"); + url.openStream(); + }catch( MalformedURLException mue) { + }catch( IOException e) { + String s= e.getMessage(); + System.out.println(s); + } + + return __serviceName; + } + // XServiceName + public boolean supportsService( /*IN*/String ServiceName ) + { + + return false; + } + + //XServiceName + public String[] getSupportedServiceNames( ) + { + String[] retValue= new String[0]; + return retValue; + } + + public static XSingleServiceFactory __getServiceFactory(String implName, + XMultiServiceFactory multiFactory, + XRegistryKey regKey) + { + XSingleServiceFactory xSingleServiceFactory = null; + + if (implName.equals( TestComponent.class.getName()) ) + xSingleServiceFactory = FactoryHelper.getServiceFactory( TestComponent.class, + TestComponent.__serviceName, + multiFactory, + regKey); + + return xSingleServiceFactory; + } + + /** + * Writes the service information into the given registry key. + * This method is called by the <code>JavaLoader</code> + * <p> + * @return returns true if the operation succeeded + * @param regKey the registryKey + * @see com.sun.star.comp.loader.JavaLoader + */ + public static boolean __writeRegistryServiceInfo(XRegistryKey regKey) + { + return FactoryHelper.writeRegistryServiceInfo( TestComponent.class.getName(), + TestComponent.__serviceName, regKey); + } + +} diff --git a/stoc/test/javavm/testcomponent/makefile.mk b/stoc/test/javavm/testcomponent/makefile.mk new file mode 100644 index 0000000000..89ae042adc --- /dev/null +++ b/stoc/test/javavm/testcomponent/makefile.mk @@ -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 . +# + +PRJ=..$/..$/.. + +PRJNAME = testcomponent +PACKAGE = +TARGET = JavaTestComponent + +# --- Settings ----------------------------------------------------- + +.INCLUDE : settings.mk + +# Files -------------------------------------------------------- + +JARFILES = ridl.jar jurt.jar unoil.jar + +CUSTOMMANIFESTFILE= manifest + +JARTARGET = $(TARGET).jar + +JAVAFILES= \ + TestComponent.java + + +JAVACLASSFILES = $(foreach,i,$(JAVAFILES) $(CLASSDIR)$/$(PACKAGE)$/$(i:b).class) + +# --- Targets ------------------------------------------------------ + +.INCLUDE : target.mk diff --git a/stoc/test/javavm/testcomponent/manifest b/stoc/test/javavm/testcomponent/manifest new file mode 100644 index 0000000000..1763d7bb95 --- /dev/null +++ b/stoc/test/javavm/testcomponent/manifest @@ -0,0 +1 @@ +RegistrationClassName: TestComponent diff --git a/stoc/test/javavm/testjavavm.cxx b/stoc/test/javavm/testjavavm.cxx new file mode 100644 index 0000000000..0e243f62d3 --- /dev/null +++ b/stoc/test/javavm/testjavavm.cxx @@ -0,0 +1,151 @@ +/* -*- 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 <jni.h> + +#include <stdio.h> +#include <sal/main.h> +#include <sal/log.hxx> +#include <rtl/process.h> + +#include <cppuhelper/servicefactory.hxx> +#include <cppuhelper/weak.hxx> +#include <cppuhelper/bootstrap.hxx> + +#include <com/sun/star/registry/XSimpleRegistry.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/lang/XMultiComponentFactory.hpp> +#include <com/sun/star/java/XJavaVM.hpp> +#include <com/sun/star/registry/XImplementationRegistration.hpp> +#include <com/sun/star/java/XJavaThreadRegister_11.hpp> + +using namespace cppu; +using namespace css::uno; +using namespace css::lang; +using namespace css::registry; +using namespace css::java; + + +sal_Bool testJavaVM(const Reference< XMultiServiceFactory > & xMgr ) +{ + + OUString sVMService("com.sun.star.java.JavaVirtualMachine"); + Reference<XInterface> xXInt= xMgr->createInstance(sVMService); + if( ! xXInt.is()) + return sal_False; + Reference<XJavaVM> xVM( xXInt, UNO_QUERY); + if( ! xVM.is()) + return sal_False; + Reference<XJavaThreadRegister_11> xreg11(xVM, UNO_QUERY); + if( ! xreg11.is()) + return sal_False; + + + sal_Int8 arId[16]; + rtl_getGlobalProcessId((sal_uInt8*) arId); + Any anyVM = xVM->getJavaVM( Sequence<sal_Int8>(arId, 16)); + if ( ! anyVM.hasValue()) + { + OSL_FAIL("could not get Java VM"); + return sal_False; + } + + sal_Bool b= xreg11->isThreadAttached(); + xreg11->registerThread(); + b= xreg11->isThreadAttached(); + xreg11->revokeThread(); + b= xreg11->isThreadAttached(); + + + b= xVM->isVMEnabled(); + b= xVM->isVMStarted(); + + + b= xVM->isVMEnabled(); + b= xVM->isVMStarted(); + + + JavaVM* _jvm= *(JavaVM**) anyVM.getValue(); + JNIEnv *p_env; + if( _jvm->AttachCurrentThread((void**) &p_env, 0)) + return sal_False; + + jclass cls = p_env->FindClass( "TestJavaVM"); + if (cls == 0) { + SAL_WARN("stoc", "Can't find Prog class"); + exit(1); + } + + jmethodID id = p_env->GetStaticMethodID( cls, "getInt", "()I"); + if( id) + { + p_env->CallStaticIntMethod(cls, id); + } + + if( p_env->ExceptionOccurred()){ + p_env->ExceptionDescribe(); + p_env->ExceptionClear(); + } + + + _jvm->DetachCurrentThread(); + return sal_True; +} + +SAL_IMPLEMENT_MAIN() +{ + Reference<XSimpleRegistry> xreg= createSimpleRegistry(); + xreg->open( OUString("applicat.rdb"), + sal_False, sal_False ); + + Reference< XComponentContext > context= bootstrap_InitialComponentContext(xreg); + Reference<XMultiComponentFactory> fac= context->getServiceManager(); + Reference<XMultiServiceFactory> xMgr( fac, UNO_QUERY); + + sal_Bool bSucc = sal_False; + try + { + OUString sImplReg( + "com.sun.star.registry.ImplementationRegistration"); + Reference<css::registry::XImplementationRegistration> xImplReg( + xMgr->createInstance( sImplReg ), UNO_QUERY ); + OSL_ENSURE( xImplReg.is(), "### no impl reg!" ); + + + OUString sLibLoader("com.sun.star.loader.SharedLibrary"); + OUString sJenLib( "javavm.uno" SAL_DLLEXTENSION ); + xImplReg->registerImplementation( + sLibLoader, sJenLib, Reference< XSimpleRegistry >() ); + + bSucc = testJavaVM( xMgr ); + } + catch (const Exception & rExc) + { + DBG_UNHANDLED_EXCEPTION("stoc", "### exception occurred: " << rExc ); + } + + Reference< XComponent > xCompContext( context, UNO_QUERY ); + xCompContext->dispose(); + printf("javavm %s", bSucc ? "succeeded" : "failed"); + return (bSucc ? 0 : -1); +} + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/stoc/test/javavm/testjavavm.java b/stoc/test/javavm/testjavavm.java new file mode 100644 index 0000000000..9309843b08 --- /dev/null +++ b/stoc/test/javavm/testjavavm.java @@ -0,0 +1,30 @@ +/* + * 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 . + */ + +class TestJavaVM +{ + public static int getInt() + { + return 100; + } + + public static void main( String args[]) + { + System.out.println("Hello World"); + } +} |