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/main.h" 29*cdf0e10cSrcweir #include <cppuhelper/shlib.hxx> 30*cdf0e10cSrcweir #include <cppuhelper/implbase1.hxx> 31*cdf0e10cSrcweir #include <cppu/EnvDcp.hxx> 32*cdf0e10cSrcweir 33*cdf0e10cSrcweir #include "../testcmp/TestComponent.hxx" 34*cdf0e10cSrcweir 35*cdf0e10cSrcweir #include <iostream> 36*cdf0e10cSrcweir #include <cstring> 37*cdf0e10cSrcweir 38*cdf0e10cSrcweir #ifndef SAL_DLLPREFIX 39*cdf0e10cSrcweir # define SAL_DLLPREFIX "" 40*cdf0e10cSrcweir #endif 41*cdf0e10cSrcweir 42*cdf0e10cSrcweir 43*cdf0e10cSrcweir using namespace ::com::sun::star; 44*cdf0e10cSrcweir 45*cdf0e10cSrcweir 46*cdf0e10cSrcweir class MyKey : public cppu::WeakImplHelper1<registry::XRegistryKey> 47*cdf0e10cSrcweir 48*cdf0e10cSrcweir { 49*cdf0e10cSrcweir public: 50*cdf0e10cSrcweir virtual rtl::OUString SAL_CALL getKeyName() throw (uno::RuntimeException) { return rtl::OUString(); }; 51*cdf0e10cSrcweir 52*cdf0e10cSrcweir // Methods 53*cdf0e10cSrcweir virtual sal_Bool SAL_CALL isReadOnly( ) throw (registry::InvalidRegistryException, uno::RuntimeException) {return sal_False;}; 54*cdf0e10cSrcweir virtual sal_Bool SAL_CALL isValid( ) throw (uno::RuntimeException) {return sal_False;}; 55*cdf0e10cSrcweir virtual registry::RegistryKeyType SAL_CALL getKeyType( const rtl::OUString& /*rKeyName*/ ) throw (registry::InvalidRegistryException, uno::RuntimeException) {return registry::RegistryKeyType_KEY;}; 56*cdf0e10cSrcweir virtual registry::RegistryValueType SAL_CALL getValueType( ) throw (registry::InvalidRegistryException, uno::RuntimeException) {return registry::RegistryValueType_NOT_DEFINED;}; 57*cdf0e10cSrcweir virtual sal_Int32 SAL_CALL getLongValue( ) throw (registry::InvalidRegistryException, registry::InvalidValueException, uno::RuntimeException) {return 0;}; 58*cdf0e10cSrcweir virtual void SAL_CALL setLongValue( sal_Int32 /*value*/ ) throw (registry::InvalidRegistryException, uno::RuntimeException) {}; 59*cdf0e10cSrcweir virtual uno::Sequence< sal_Int32 > SAL_CALL getLongListValue( ) throw (registry::InvalidRegistryException, registry::InvalidValueException, uno::RuntimeException) { return uno::Sequence<sal_Int32>(); }; 60*cdf0e10cSrcweir virtual void SAL_CALL setLongListValue( const uno::Sequence< sal_Int32 >& /*seqValue*/ ) throw (registry::InvalidRegistryException, uno::RuntimeException) {}; 61*cdf0e10cSrcweir virtual rtl::OUString SAL_CALL getAsciiValue( ) throw (registry::InvalidRegistryException, registry::InvalidValueException, uno::RuntimeException) {return rtl::OUString();}; 62*cdf0e10cSrcweir virtual void SAL_CALL setAsciiValue( const rtl::OUString& /*value*/ ) throw (registry::InvalidRegistryException, uno::RuntimeException) {}; 63*cdf0e10cSrcweir virtual uno::Sequence< rtl::OUString > SAL_CALL getAsciiListValue( ) throw (registry::InvalidRegistryException, registry::InvalidValueException, uno::RuntimeException) {return uno::Sequence<rtl::OUString>();}; 64*cdf0e10cSrcweir virtual void SAL_CALL setAsciiListValue( const uno::Sequence< rtl::OUString >& /*seqValue*/ ) throw (registry::InvalidRegistryException, uno::RuntimeException) {}; 65*cdf0e10cSrcweir virtual rtl::OUString SAL_CALL getStringValue( ) throw (registry::InvalidRegistryException, registry::InvalidValueException, uno::RuntimeException) {return rtl::OUString();}; 66*cdf0e10cSrcweir virtual void SAL_CALL setStringValue( const rtl::OUString& /*value*/ ) throw (registry::InvalidRegistryException, uno::RuntimeException) {}; 67*cdf0e10cSrcweir virtual uno::Sequence< rtl::OUString > SAL_CALL getStringListValue( ) throw (registry::InvalidRegistryException, registry::InvalidValueException, uno::RuntimeException) {return uno::Sequence<rtl::OUString>();}; 68*cdf0e10cSrcweir virtual void SAL_CALL setStringListValue( const uno::Sequence< rtl::OUString >& /*seqValue*/ ) throw (registry::InvalidRegistryException, uno::RuntimeException) {}; 69*cdf0e10cSrcweir virtual uno::Sequence< sal_Int8 > SAL_CALL getBinaryValue( ) throw (registry::InvalidRegistryException, registry::InvalidValueException, uno::RuntimeException) {return uno::Sequence<sal_Int8>();}; 70*cdf0e10cSrcweir virtual void SAL_CALL setBinaryValue( const uno::Sequence< sal_Int8 >& /*value*/ ) throw (registry::InvalidRegistryException, uno::RuntimeException) {}; 71*cdf0e10cSrcweir virtual uno::Reference< registry::XRegistryKey > SAL_CALL openKey( const rtl::OUString& /*aKeyName*/ ) throw (registry::InvalidRegistryException, uno::RuntimeException) {return uno::Reference<registry::XRegistryKey>();}; 72*cdf0e10cSrcweir virtual uno::Reference< registry::XRegistryKey > SAL_CALL createKey( const rtl::OUString& /*aKeyName*/ ) throw (registry::InvalidRegistryException, uno::RuntimeException) {return uno::Reference<registry::XRegistryKey>();}; 73*cdf0e10cSrcweir virtual void SAL_CALL closeKey( ) throw (registry::InvalidRegistryException, uno::RuntimeException) {}; 74*cdf0e10cSrcweir virtual void SAL_CALL deleteKey( const rtl::OUString& /*rKeyName*/ ) throw (registry::InvalidRegistryException, uno::RuntimeException) {}; 75*cdf0e10cSrcweir virtual uno::Sequence< uno::Reference< registry::XRegistryKey > > SAL_CALL openKeys( ) throw (registry::InvalidRegistryException, uno::RuntimeException) {return uno::Sequence<uno::Reference<registry::XRegistryKey> >();}; 76*cdf0e10cSrcweir virtual uno::Sequence< rtl::OUString > SAL_CALL getKeyNames( ) throw (registry::InvalidRegistryException, uno::RuntimeException) {return uno::Sequence<rtl::OUString>();}; 77*cdf0e10cSrcweir virtual sal_Bool SAL_CALL createLink( const rtl::OUString& /*aLinkName*/, const rtl::OUString& /*aLinkTarget*/ ) throw (registry::InvalidRegistryException, uno::RuntimeException) {return sal_False;}; 78*cdf0e10cSrcweir virtual void SAL_CALL deleteLink( const rtl::OUString& /*rLinkName*/ ) throw (registry::InvalidRegistryException, uno::RuntimeException) {}; 79*cdf0e10cSrcweir virtual rtl::OUString SAL_CALL getLinkTarget( const rtl::OUString& /*rLinkName*/ ) throw (registry::InvalidRegistryException, uno::RuntimeException) {return rtl::OUString();}; 80*cdf0e10cSrcweir virtual rtl::OUString SAL_CALL getResolvedName( const rtl::OUString& /*aKeyName*/ ) throw (registry::InvalidRegistryException, uno::RuntimeException) {return rtl::OUString();}; 81*cdf0e10cSrcweir }; 82*cdf0e10cSrcweir 83*cdf0e10cSrcweir 84*cdf0e10cSrcweir 85*cdf0e10cSrcweir static rtl::OUString s_test__cppu_loadSharedLibComponentFactory(char const * pServicePurpose) 86*cdf0e10cSrcweir { 87*cdf0e10cSrcweir rtl::OUString result; 88*cdf0e10cSrcweir 89*cdf0e10cSrcweir rtl::OUString servicePurpose = rtl::OUString(pServicePurpose, 90*cdf0e10cSrcweir rtl_str_getLength(pServicePurpose), 91*cdf0e10cSrcweir RTL_TEXTENCODING_ASCII_US); 92*cdf0e10cSrcweir 93*cdf0e10cSrcweir result += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\ts_test__cppu_loadSharedLibComponentFactory ")); 94*cdf0e10cSrcweir result += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("(\"")); 95*cdf0e10cSrcweir result += servicePurpose; 96*cdf0e10cSrcweir result += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\") - ")); 97*cdf0e10cSrcweir 98*cdf0e10cSrcweir try { 99*cdf0e10cSrcweir uno::Reference<uno::XInterface> xObject( 100*cdf0e10cSrcweir cppu::loadSharedLibComponentFactory( 101*cdf0e10cSrcweir rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SAL_DLLPREFIX "TestComponent.uno" SAL_DLLEXTENSION)), 102*cdf0e10cSrcweir rtl::OUString(), 103*cdf0e10cSrcweir rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("impl.test.TestComponent")) + servicePurpose, 104*cdf0e10cSrcweir uno::Reference<lang::XMultiServiceFactory>(), 105*cdf0e10cSrcweir uno::Reference<registry::XRegistryKey>()) 106*cdf0e10cSrcweir ); 107*cdf0e10cSrcweir 108*cdf0e10cSrcweir rtl::OUString envDcp_purpose(cppu::EnvDcp::getPurpose(g_envDcp)); 109*cdf0e10cSrcweir if (envDcp_purpose == servicePurpose) 110*cdf0e10cSrcweir result += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("passed\n")); 111*cdf0e10cSrcweir 112*cdf0e10cSrcweir else 113*cdf0e10cSrcweir { 114*cdf0e10cSrcweir result += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FAILED - got: \"")); 115*cdf0e10cSrcweir result += envDcp_purpose; 116*cdf0e10cSrcweir result += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\"\n")); 117*cdf0e10cSrcweir } 118*cdf0e10cSrcweir } 119*cdf0e10cSrcweir catch(uno::Exception & exception) { 120*cdf0e10cSrcweir result += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FAILED - got: \"")); 121*cdf0e10cSrcweir result += exception.Message; 122*cdf0e10cSrcweir result += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\"\n")); 123*cdf0e10cSrcweir } 124*cdf0e10cSrcweir 125*cdf0e10cSrcweir return result; 126*cdf0e10cSrcweir } 127*cdf0e10cSrcweir 128*cdf0e10cSrcweir static rtl::OUString s_test__cppu_writeSharedLibComponentInfo(char const * pServicePurpose) 129*cdf0e10cSrcweir { 130*cdf0e10cSrcweir rtl::OUString result; 131*cdf0e10cSrcweir 132*cdf0e10cSrcweir rtl::OUString servicePurpose = rtl::OUString(pServicePurpose, 133*cdf0e10cSrcweir rtl_str_getLength(pServicePurpose), 134*cdf0e10cSrcweir RTL_TEXTENCODING_ASCII_US); 135*cdf0e10cSrcweir 136*cdf0e10cSrcweir result += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\ts_test__cppu_writeSharedLibComponentInfo ")); 137*cdf0e10cSrcweir result += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("(\"")); 138*cdf0e10cSrcweir result += servicePurpose; 139*cdf0e10cSrcweir result += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\") - ")); 140*cdf0e10cSrcweir 141*cdf0e10cSrcweir char buff[256]; 142*cdf0e10cSrcweir strcpy(buff, "TestComponent.uno="); 143*cdf0e10cSrcweir strcat(buff, pServicePurpose); 144*cdf0e10cSrcweir 145*cdf0e10cSrcweir putenv(buff); 146*cdf0e10cSrcweir 147*cdf0e10cSrcweir try { 148*cdf0e10cSrcweir cppu::writeSharedLibComponentInfo( 149*cdf0e10cSrcweir rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SAL_DLLPREFIX "TestComponent.uno" SAL_DLLEXTENSION)), 150*cdf0e10cSrcweir rtl::OUString(), 151*cdf0e10cSrcweir uno::Reference<lang::XMultiServiceFactory>(), 152*cdf0e10cSrcweir uno::Reference<registry::XRegistryKey>(new MyKey) 153*cdf0e10cSrcweir ); 154*cdf0e10cSrcweir 155*cdf0e10cSrcweir rtl::OUString envDcp_purpose(cppu::EnvDcp::getPurpose(g_envDcp)); 156*cdf0e10cSrcweir if (envDcp_purpose == servicePurpose) 157*cdf0e10cSrcweir result += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("passed\n")); 158*cdf0e10cSrcweir 159*cdf0e10cSrcweir else 160*cdf0e10cSrcweir { 161*cdf0e10cSrcweir result += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FAILED - got: \"")); 162*cdf0e10cSrcweir result += envDcp_purpose; 163*cdf0e10cSrcweir result += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\"\n")); 164*cdf0e10cSrcweir } 165*cdf0e10cSrcweir } 166*cdf0e10cSrcweir catch(uno::Exception & exception) { 167*cdf0e10cSrcweir result += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FAILED - got: \"")); 168*cdf0e10cSrcweir result += exception.Message; 169*cdf0e10cSrcweir result += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\"\n")); 170*cdf0e10cSrcweir } 171*cdf0e10cSrcweir 172*cdf0e10cSrcweir return result; 173*cdf0e10cSrcweir } 174*cdf0e10cSrcweir 175*cdf0e10cSrcweir 176*cdf0e10cSrcweir SAL_IMPLEMENT_MAIN_WITH_ARGS(/*argc*/, argv) 177*cdf0e10cSrcweir { 178*cdf0e10cSrcweir int result = 0; 179*cdf0e10cSrcweir 180*cdf0e10cSrcweir rtl::OUString message; 181*cdf0e10cSrcweir 182*cdf0e10cSrcweir message += rtl::OUString(argv[0], rtl_str_getLength(argv[0]), RTL_TEXTENCODING_ASCII_US); 183*cdf0e10cSrcweir message += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\n")); 184*cdf0e10cSrcweir 185*cdf0e10cSrcweir message += s_test__cppu_loadSharedLibComponentFactory(":unsafe"); 186*cdf0e10cSrcweir message += s_test__cppu_loadSharedLibComponentFactory(":affine"); 187*cdf0e10cSrcweir message += s_test__cppu_loadSharedLibComponentFactory(""); 188*cdf0e10cSrcweir 189*cdf0e10cSrcweir message += s_test__cppu_writeSharedLibComponentInfo(":unsafe"); 190*cdf0e10cSrcweir message += s_test__cppu_writeSharedLibComponentInfo(":affine"); 191*cdf0e10cSrcweir message += s_test__cppu_writeSharedLibComponentInfo(""); 192*cdf0e10cSrcweir 193*cdf0e10cSrcweir if (message.indexOf(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FAILED"))) == -1) 194*cdf0e10cSrcweir message += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("TESTS PASSED\n")); 195*cdf0e10cSrcweir 196*cdf0e10cSrcweir else 197*cdf0e10cSrcweir { 198*cdf0e10cSrcweir message += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("TESTS _NOT_ PASSED\n")); 199*cdf0e10cSrcweir result = -1; 200*cdf0e10cSrcweir } 201*cdf0e10cSrcweir 202*cdf0e10cSrcweir std::cout << rtl::OUStringToOString(message, RTL_TEXTENCODING_ASCII_US).getStr(); 203*cdf0e10cSrcweir 204*cdf0e10cSrcweir return result; 205*cdf0e10cSrcweir } 206