1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir #include "sal/config.h" 29*cdf0e10cSrcweir 30*cdf0e10cSrcweir #include <cstddef> 31*cdf0e10cSrcweir #include <functional> 32*cdf0e10cSrcweir #include <memory> 33*cdf0e10cSrcweir #include <new> 34*cdf0e10cSrcweir #include <hash_map> 35*cdf0e10cSrcweir 36*cdf0e10cSrcweir #include "com/sun/star/lang/XMain.hpp" 37*cdf0e10cSrcweir #include "com/sun/star/lang/XMultiComponentFactory.hpp" 38*cdf0e10cSrcweir #include "com/sun/star/uno/Exception.hpp" 39*cdf0e10cSrcweir #include "com/sun/star/uno/Reference.hxx" 40*cdf0e10cSrcweir #include "com/sun/star/uno/RuntimeException.hpp" 41*cdf0e10cSrcweir #include "com/sun/star/uno/Sequence.hxx" 42*cdf0e10cSrcweir #include "com/sun/star/uno/XComponentContext.hpp" 43*cdf0e10cSrcweir #include "com/sun/star/uno/XInterface.hpp" 44*cdf0e10cSrcweir #include "cppuhelper/factory.hxx" 45*cdf0e10cSrcweir #include "cppuhelper/implbase1.hxx" 46*cdf0e10cSrcweir #include "cppuhelper/implementationentry.hxx" 47*cdf0e10cSrcweir #include "cppuhelper/interfacecontainer.hxx" 48*cdf0e10cSrcweir #include "cppuhelper/unourl.hxx" 49*cdf0e10cSrcweir #include "cppuhelper/weak.hxx" 50*cdf0e10cSrcweir #include "osl/mutex.hxx" 51*cdf0e10cSrcweir #include "osl/thread.h" 52*cdf0e10cSrcweir #include "rtl/malformeduriexception.hxx" 53*cdf0e10cSrcweir #include "rtl/string.h" 54*cdf0e10cSrcweir #include "rtl/ustrbuf.hxx" 55*cdf0e10cSrcweir #include "rtl/ustring.h" 56*cdf0e10cSrcweir #include "rtl/ustring.hxx" 57*cdf0e10cSrcweir #include "sal/types.h" 58*cdf0e10cSrcweir #include "salhelper/simplereferenceobject.hxx" 59*cdf0e10cSrcweir #include "uno/current_context.hxx" 60*cdf0e10cSrcweir #include "uno/environment.h" 61*cdf0e10cSrcweir #include "uno/lbnames.h" 62*cdf0e10cSrcweir 63*cdf0e10cSrcweir #include "test/types/CppTest.hpp" 64*cdf0e10cSrcweir #include "test/types/JavaTest.hpp" 65*cdf0e10cSrcweir #include "test/types/TestException.hpp" 66*cdf0e10cSrcweir #include "test/types/XTest.hpp" 67*cdf0e10cSrcweir 68*cdf0e10cSrcweir namespace css = ::com::sun::star; 69*cdf0e10cSrcweir 70*cdf0e10cSrcweir namespace { 71*cdf0e10cSrcweir 72*cdf0e10cSrcweir class Service: public ::cppu::WeakImplHelper1< ::css::lang::XMain > { 73*cdf0e10cSrcweir public: 74*cdf0e10cSrcweir explicit Service( 75*cdf0e10cSrcweir ::css::uno::Reference< ::css::uno::XComponentContext > const & context): 76*cdf0e10cSrcweir context_(context) {} 77*cdf0e10cSrcweir 78*cdf0e10cSrcweir virtual ::sal_Int32 SAL_CALL run( 79*cdf0e10cSrcweir ::css::uno::Sequence< ::rtl::OUString > const &) 80*cdf0e10cSrcweir throw (::css::uno::RuntimeException); 81*cdf0e10cSrcweir 82*cdf0e10cSrcweir private: 83*cdf0e10cSrcweir Service(Service &); // not defined 84*cdf0e10cSrcweir void operator =(Service &); // not defined 85*cdf0e10cSrcweir 86*cdf0e10cSrcweir virtual ~Service() {} 87*cdf0e10cSrcweir 88*cdf0e10cSrcweir void test( 89*cdf0e10cSrcweir ::css::uno::Reference< test::types::XTest > const & test, 90*cdf0e10cSrcweir ::rtl::OUString const & name); 91*cdf0e10cSrcweir 92*cdf0e10cSrcweir ::css::uno::Reference< ::css::uno::XComponentContext > context_; 93*cdf0e10cSrcweir }; 94*cdf0e10cSrcweir 95*cdf0e10cSrcweir ::sal_Int32 Service::run(::css::uno::Sequence< ::rtl::OUString > const &) 96*cdf0e10cSrcweir throw (::css::uno::RuntimeException) 97*cdf0e10cSrcweir { 98*cdf0e10cSrcweir osl_getThreadIdentifier(0); // check for sal 99*cdf0e10cSrcweir (new salhelper::SimpleReferenceObject)->release(); // check for salhelper 100*cdf0e10cSrcweir css::uno::getCurrentContext(); // check for cppu 101*cdf0e10cSrcweir try { // check for cppuhelper 102*cdf0e10cSrcweir std::auto_ptr< cppu::UnoUrl > dummy(new cppu::UnoUrl(rtl::OUString())); 103*cdf0e10cSrcweir } catch (rtl::MalformedUriException &) {} 104*cdf0e10cSrcweir { // check for stlport 105*cdf0e10cSrcweir osl::Mutex m; 106*cdf0e10cSrcweir std::auto_ptr< cppu::OMultiTypeInterfaceContainerHelperVar< 107*cdf0e10cSrcweir int, std::hash< int >, std::equal_to< int > > > dummy( 108*cdf0e10cSrcweir new cppu::OMultiTypeInterfaceContainerHelperVar< 109*cdf0e10cSrcweir int, std::hash< int >, std::equal_to< int > >(m)); 110*cdf0e10cSrcweir } 111*cdf0e10cSrcweir static char const * const services[] = { 112*cdf0e10cSrcweir "com.sun.star.beans.Introspection", 113*cdf0e10cSrcweir "com.sun.star.bridge.Bridge", 114*cdf0e10cSrcweir "com.sun.star.bridge.BridgeFactory", 115*cdf0e10cSrcweir "com.sun.star.bridge.IiopBridge", 116*cdf0e10cSrcweir "com.sun.star.bridge.UnoUrlResolver", 117*cdf0e10cSrcweir "com.sun.star.bridge.UrpBridge", 118*cdf0e10cSrcweir "com.sun.star.connection.Acceptor", 119*cdf0e10cSrcweir "com.sun.star.connection.Connector", 120*cdf0e10cSrcweir "com.sun.star.io.DataInputStream", 121*cdf0e10cSrcweir "com.sun.star.io.DataOutputStream", 122*cdf0e10cSrcweir "com.sun.star.io.MarkableInputStream", 123*cdf0e10cSrcweir "com.sun.star.io.MarkableOutputStream", 124*cdf0e10cSrcweir "com.sun.star.io.ObjectInputStream", 125*cdf0e10cSrcweir "com.sun.star.io.ObjectOutputStream", 126*cdf0e10cSrcweir "com.sun.star.io.Pipe", 127*cdf0e10cSrcweir "com.sun.star.io.Pump", 128*cdf0e10cSrcweir "com.sun.star.io.TextInputStream", 129*cdf0e10cSrcweir "com.sun.star.io.TextOutputStream", 130*cdf0e10cSrcweir "com.sun.star.java.JavaVirtualMachine", 131*cdf0e10cSrcweir "com.sun.star.lang.MultiServiceFactory", 132*cdf0e10cSrcweir "com.sun.star.lang.RegistryServiceManager", 133*cdf0e10cSrcweir "com.sun.star.lang.ServiceManager", 134*cdf0e10cSrcweir "com.sun.star.loader.Java", 135*cdf0e10cSrcweir "com.sun.star.loader.Java2", 136*cdf0e10cSrcweir "com.sun.star.loader.SharedLibrary", 137*cdf0e10cSrcweir "com.sun.star.reflection.CoreReflection", 138*cdf0e10cSrcweir "com.sun.star.reflection.ProxyFactory", 139*cdf0e10cSrcweir "com.sun.star.reflection.TypeDescriptionManager", 140*cdf0e10cSrcweir "com.sun.star.reflection.TypeDescriptionProvider", 141*cdf0e10cSrcweir "com.sun.star.registry.ImplementationRegistration", 142*cdf0e10cSrcweir "com.sun.star.registry.NestedRegistry", 143*cdf0e10cSrcweir "com.sun.star.registry.SimpleRegistry", 144*cdf0e10cSrcweir "com.sun.star.script.Converter", 145*cdf0e10cSrcweir "com.sun.star.script.Invocation", 146*cdf0e10cSrcweir "com.sun.star.script.InvocationAdapterFactory", 147*cdf0e10cSrcweir "com.sun.star.security.AccessController", 148*cdf0e10cSrcweir "com.sun.star.security.Policy", 149*cdf0e10cSrcweir "com.sun.star.uno.NamingService", 150*cdf0e10cSrcweir "com.sun.star.uri.ExternalUriReferenceTranslator", 151*cdf0e10cSrcweir "com.sun.star.uri.UriReferenceFactory", 152*cdf0e10cSrcweir "com.sun.star.uri.UriSchemeParser_vndDOTsunDOTstarDOTscript", 153*cdf0e10cSrcweir "com.sun.star.uri.VndSunStarPkgUrlReferenceFactory" 154*cdf0e10cSrcweir // "com.sun.star.beans.PropertyBag", 155*cdf0e10cSrcweir // "com.sun.star.beans.PropertySet", 156*cdf0e10cSrcweir // "com.sun.star.bridge.OleApplicationRegistration", 157*cdf0e10cSrcweir // "com.sun.star.bridge.OleBridgeSupplier", 158*cdf0e10cSrcweir // "com.sun.star.bridge.OleBridgeSupplier2", 159*cdf0e10cSrcweir // "com.sun.star.bridge.OleBridgeSupplierVar1", 160*cdf0e10cSrcweir // "com.sun.star.bridge.OleObjectFactory", 161*cdf0e10cSrcweir // "com.sun.star.bridge.oleautomation.ApplicationRegistration", 162*cdf0e10cSrcweir // "com.sun.star.bridge.oleautomation.BridgeSupplier", 163*cdf0e10cSrcweir // "com.sun.star.bridge.oleautomation.Factory", 164*cdf0e10cSrcweir // "com.sun.star.loader.Dynamic", 165*cdf0e10cSrcweir // "com.sun.star.registry.DefaultRegistry", 166*cdf0e10cSrcweir // "com.sun.star.script.AllListenerAdapter", 167*cdf0e10cSrcweir // "com.sun.star.script.Engine", 168*cdf0e10cSrcweir // "com.sun.star.script.JavaScript", 169*cdf0e10cSrcweir // "com.sun.star.test.TestFactory", 170*cdf0e10cSrcweir // "com.sun.star.util.BootstrapMacroExpander", 171*cdf0e10cSrcweir // "com.sun.star.util.MacroExpander", 172*cdf0e10cSrcweir // "com.sun.star.util.logging.Logger", 173*cdf0e10cSrcweir // "com.sun.star.util.logging.LoggerRemote" 174*cdf0e10cSrcweir }; 175*cdf0e10cSrcweir ::css::uno::Reference< ::css::lang::XMultiComponentFactory > manager( 176*cdf0e10cSrcweir context_->getServiceManager()); 177*cdf0e10cSrcweir if (!manager.is()) { 178*cdf0e10cSrcweir throw ::css::uno::RuntimeException( 179*cdf0e10cSrcweir ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("no service manager")), 180*cdf0e10cSrcweir static_cast< ::cppu::OWeakObject * >(this)); 181*cdf0e10cSrcweir } 182*cdf0e10cSrcweir for (::std::size_t i = 0; i < sizeof services / sizeof services[0]; ++i) { 183*cdf0e10cSrcweir ::css::uno::Reference< ::css::uno::XInterface > instance; 184*cdf0e10cSrcweir try { 185*cdf0e10cSrcweir instance = manager->createInstanceWithContext( 186*cdf0e10cSrcweir ::rtl::OUString::createFromAscii(services[i]), context_); 187*cdf0e10cSrcweir } catch (::css::uno::RuntimeException &) { 188*cdf0e10cSrcweir throw; 189*cdf0e10cSrcweir } catch (::css::uno::Exception &) { 190*cdf0e10cSrcweir throw ::css::uno::RuntimeException( 191*cdf0e10cSrcweir ::rtl::OUString( 192*cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM("error creating instance")), 193*cdf0e10cSrcweir static_cast< ::cppu::OWeakObject * >(this)); 194*cdf0e10cSrcweir } 195*cdf0e10cSrcweir if (!instance.is()) { 196*cdf0e10cSrcweir throw ::css::uno::RuntimeException( 197*cdf0e10cSrcweir ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("no instance")), 198*cdf0e10cSrcweir static_cast< ::cppu::OWeakObject * >(this)); 199*cdf0e10cSrcweir } 200*cdf0e10cSrcweir } 201*cdf0e10cSrcweir static char const * const singletons[] = { 202*cdf0e10cSrcweir "com.sun.star.util.theMacroExpander" }; 203*cdf0e10cSrcweir for (::std::size_t i = 0; i < sizeof singletons / sizeof singletons[0]; ++i) 204*cdf0e10cSrcweir { 205*cdf0e10cSrcweir ::rtl::OUStringBuffer b; 206*cdf0e10cSrcweir b.appendAscii(RTL_CONSTASCII_STRINGPARAM("/singletons/")); 207*cdf0e10cSrcweir b.appendAscii(singletons[i]); 208*cdf0e10cSrcweir ::css::uno::Reference< ::css::uno::XInterface > instance( 209*cdf0e10cSrcweir context_->getValueByName(b.makeStringAndClear()), 210*cdf0e10cSrcweir ::css::uno::UNO_QUERY_THROW); 211*cdf0e10cSrcweir } 212*cdf0e10cSrcweir test( 213*cdf0e10cSrcweir ::test::types::CppTest::create(context_), 214*cdf0e10cSrcweir ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("test.types.CppTest"))); 215*cdf0e10cSrcweir test( 216*cdf0e10cSrcweir ::test::types::JavaTest::create(context_), 217*cdf0e10cSrcweir ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("test.types.JavaTest"))); 218*cdf0e10cSrcweir return 0; 219*cdf0e10cSrcweir } 220*cdf0e10cSrcweir 221*cdf0e10cSrcweir void Service::test( 222*cdf0e10cSrcweir ::css::uno::Reference< test::types::XTest > const & test, 223*cdf0e10cSrcweir ::rtl::OUString const & name) 224*cdf0e10cSrcweir { 225*cdf0e10cSrcweir bool ok = false; 226*cdf0e10cSrcweir try { 227*cdf0e10cSrcweir test->throwException(); 228*cdf0e10cSrcweir } catch (::test::types::TestException &) { 229*cdf0e10cSrcweir ok = true; 230*cdf0e10cSrcweir } 231*cdf0e10cSrcweir if (!ok) { 232*cdf0e10cSrcweir throw ::css::uno::RuntimeException( 233*cdf0e10cSrcweir (name 234*cdf0e10cSrcweir + ::rtl::OUString( 235*cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM(".throwException failed"))), 236*cdf0e10cSrcweir static_cast< ::cppu::OWeakObject * >(this)); 237*cdf0e10cSrcweir } 238*cdf0e10cSrcweir } 239*cdf0e10cSrcweir 240*cdf0e10cSrcweir namespace CppMain { 241*cdf0e10cSrcweir 242*cdf0e10cSrcweir ::css::uno::Reference< ::css::uno::XInterface > create( 243*cdf0e10cSrcweir ::css::uno::Reference< ::css::uno::XComponentContext > const & context) 244*cdf0e10cSrcweir SAL_THROW((::css::uno::Exception)) 245*cdf0e10cSrcweir { 246*cdf0e10cSrcweir try { 247*cdf0e10cSrcweir return static_cast< ::cppu::OWeakObject * >(new Service(context)); 248*cdf0e10cSrcweir } catch (::std::bad_alloc &) { 249*cdf0e10cSrcweir throw ::css::uno::RuntimeException( 250*cdf0e10cSrcweir ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("std::bad_alloc")), 251*cdf0e10cSrcweir ::css::uno::Reference< ::css::uno::XInterface >()); 252*cdf0e10cSrcweir } 253*cdf0e10cSrcweir } 254*cdf0e10cSrcweir 255*cdf0e10cSrcweir ::rtl::OUString getImplementationName() { 256*cdf0e10cSrcweir return ::rtl::OUString( 257*cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM("test.cpp.cppmain.Component")); 258*cdf0e10cSrcweir } 259*cdf0e10cSrcweir 260*cdf0e10cSrcweir ::css::uno::Sequence< ::rtl::OUString > getSupportedServiceNames() { 261*cdf0e10cSrcweir return ::css::uno::Sequence< ::rtl::OUString >(); 262*cdf0e10cSrcweir } 263*cdf0e10cSrcweir 264*cdf0e10cSrcweir } 265*cdf0e10cSrcweir 266*cdf0e10cSrcweir ::cppu::ImplementationEntry entries[] = { 267*cdf0e10cSrcweir { CppMain::create, CppMain::getImplementationName, 268*cdf0e10cSrcweir CppMain::getSupportedServiceNames, ::cppu::createSingleComponentFactory, 269*cdf0e10cSrcweir 0, 0 }, 270*cdf0e10cSrcweir { 0, 0, 0, 0, 0, 0 } }; 271*cdf0e10cSrcweir 272*cdf0e10cSrcweir } 273*cdf0e10cSrcweir 274*cdf0e10cSrcweir extern "C" ::sal_Bool SAL_CALL component_writeInfo( 275*cdf0e10cSrcweir void * serviceManager, void * registryKey) 276*cdf0e10cSrcweir { 277*cdf0e10cSrcweir return ::cppu::component_writeInfoHelper( 278*cdf0e10cSrcweir serviceManager, registryKey, entries); 279*cdf0e10cSrcweir } 280*cdf0e10cSrcweir 281*cdf0e10cSrcweir extern "C" void * SAL_CALL component_getFactory( 282*cdf0e10cSrcweir char const * implName, void * serviceManager, void * registryKey) 283*cdf0e10cSrcweir { 284*cdf0e10cSrcweir return ::cppu::component_getFactoryHelper( 285*cdf0e10cSrcweir implName, serviceManager, registryKey, entries); 286*cdf0e10cSrcweir } 287*cdf0e10cSrcweir 288*cdf0e10cSrcweir extern "C" void SAL_CALL component_getImplementationEnvironment( 289*cdf0e10cSrcweir char const ** envTypeName, ::uno_Environment **) 290*cdf0e10cSrcweir { 291*cdf0e10cSrcweir *envTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME; 292*cdf0e10cSrcweir } 293