/* -*- 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 #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using namespace cppu; using namespace com::sun::star::uno; using namespace com::sun::star::lang; using namespace com::sun::star::registry; using namespace com::sun::star::java; using ::rtl::OUString; using ::rtl::OUStringToOString; using ::rtl::OString; sal_Bool testJavaVM(const Reference< XMultiServiceFactory > & xMgr ) { OUString sVMService( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.java.JavaVirtualMachine")); Reference xXInt= xMgr->createInstance(sVMService); if( ! xXInt.is()) return sal_False; Reference xVM( xXInt, UNO_QUERY); if( ! xVM.is()) return sal_False; Reference xreg11(xVM, UNO_QUERY); if( ! xreg11.is()) return sal_False; sal_Int8 arId[16]; rtl_getGlobalProcessId((sal_uInt8*) arId); Any anyVM = xVM->getJavaVM( Sequence(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) { OSL_TRACE( "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 xreg= createSimpleRegistry(); xreg->open( OUString( RTL_CONSTASCII_USTRINGPARAM("applicat.rdb")), sal_False, sal_False ); Reference< XComponentContext > context= bootstrap_InitialComponentContext(xreg); Reference fac= context->getServiceManager(); Reference xMgr( fac, UNO_QUERY); sal_Bool bSucc = sal_False; try { OUString sImplReg(RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.registry.ImplementationRegistration")); Reference xImplReg( xMgr->createInstance( sImplReg ), UNO_QUERY ); OSL_ENSURE( xImplReg.is(), "### no impl reg!" ); OUString sLibLoader( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.loader.SharedLibrary")); OUString sJenLib( RTL_CONSTASCII_USTRINGPARAM( "javavm.uno" SAL_DLLEXTENSION ) ); xImplReg->registerImplementation( sLibLoader, sJenLib, Reference< XSimpleRegistry >() ); bSucc = testJavaVM( xMgr ); } catch (const Exception & rExc) { OSL_FAIL( "### exception occurred!" ); OString aMsg( OUStringToOString( rExc.Message, RTL_TEXTENCODING_ASCII_US ) ); OSL_TRACE( "### exception occurred: " ); OSL_TRACE( "%s", aMsg.getStr() ); OSL_TRACE( "\n" ); } 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: */