1*9d7e27acSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*9d7e27acSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*9d7e27acSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*9d7e27acSAndrew Rist * distributed with this work for additional information 6*9d7e27acSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*9d7e27acSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*9d7e27acSAndrew Rist * "License"); you may not use this file except in compliance 9*9d7e27acSAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*9d7e27acSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*9d7e27acSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*9d7e27acSAndrew Rist * software distributed under the License is distributed on an 15*9d7e27acSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*9d7e27acSAndrew Rist * KIND, either express or implied. See the License for the 17*9d7e27acSAndrew Rist * specific language governing permissions and limitations 18*9d7e27acSAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*9d7e27acSAndrew Rist *************************************************************/ 21*9d7e27acSAndrew Rist 22*9d7e27acSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #include "sal/main.h" 25cdf0e10cSrcweir #include <cppuhelper/shlib.hxx> 26cdf0e10cSrcweir #include <cppuhelper/implbase1.hxx> 27cdf0e10cSrcweir #include <cppu/EnvDcp.hxx> 28cdf0e10cSrcweir 29cdf0e10cSrcweir #include "../testcmp/TestComponent.hxx" 30cdf0e10cSrcweir 31cdf0e10cSrcweir #include <iostream> 32cdf0e10cSrcweir #include <cstring> 33cdf0e10cSrcweir 34cdf0e10cSrcweir #ifndef SAL_DLLPREFIX 35cdf0e10cSrcweir # define SAL_DLLPREFIX "" 36cdf0e10cSrcweir #endif 37cdf0e10cSrcweir 38cdf0e10cSrcweir 39cdf0e10cSrcweir using namespace ::com::sun::star; 40cdf0e10cSrcweir 41cdf0e10cSrcweir 42cdf0e10cSrcweir class MyKey : public cppu::WeakImplHelper1<registry::XRegistryKey> 43cdf0e10cSrcweir 44cdf0e10cSrcweir { 45cdf0e10cSrcweir public: 46cdf0e10cSrcweir virtual rtl::OUString SAL_CALL getKeyName() throw (uno::RuntimeException) { return rtl::OUString(); }; 47cdf0e10cSrcweir 48cdf0e10cSrcweir // Methods 49cdf0e10cSrcweir virtual sal_Bool SAL_CALL isReadOnly( ) throw (registry::InvalidRegistryException, uno::RuntimeException) {return sal_False;}; 50cdf0e10cSrcweir virtual sal_Bool SAL_CALL isValid( ) throw (uno::RuntimeException) {return sal_False;}; 51cdf0e10cSrcweir virtual registry::RegistryKeyType SAL_CALL getKeyType( const rtl::OUString& /*rKeyName*/ ) throw (registry::InvalidRegistryException, uno::RuntimeException) {return registry::RegistryKeyType_KEY;}; 52cdf0e10cSrcweir virtual registry::RegistryValueType SAL_CALL getValueType( ) throw (registry::InvalidRegistryException, uno::RuntimeException) {return registry::RegistryValueType_NOT_DEFINED;}; 53cdf0e10cSrcweir virtual sal_Int32 SAL_CALL getLongValue( ) throw (registry::InvalidRegistryException, registry::InvalidValueException, uno::RuntimeException) {return 0;}; 54cdf0e10cSrcweir virtual void SAL_CALL setLongValue( sal_Int32 /*value*/ ) throw (registry::InvalidRegistryException, uno::RuntimeException) {}; 55cdf0e10cSrcweir virtual uno::Sequence< sal_Int32 > SAL_CALL getLongListValue( ) throw (registry::InvalidRegistryException, registry::InvalidValueException, uno::RuntimeException) { return uno::Sequence<sal_Int32>(); }; 56cdf0e10cSrcweir virtual void SAL_CALL setLongListValue( const uno::Sequence< sal_Int32 >& /*seqValue*/ ) throw (registry::InvalidRegistryException, uno::RuntimeException) {}; 57cdf0e10cSrcweir virtual rtl::OUString SAL_CALL getAsciiValue( ) throw (registry::InvalidRegistryException, registry::InvalidValueException, uno::RuntimeException) {return rtl::OUString();}; 58cdf0e10cSrcweir virtual void SAL_CALL setAsciiValue( const rtl::OUString& /*value*/ ) throw (registry::InvalidRegistryException, uno::RuntimeException) {}; 59cdf0e10cSrcweir virtual uno::Sequence< rtl::OUString > SAL_CALL getAsciiListValue( ) throw (registry::InvalidRegistryException, registry::InvalidValueException, uno::RuntimeException) {return uno::Sequence<rtl::OUString>();}; 60cdf0e10cSrcweir virtual void SAL_CALL setAsciiListValue( const uno::Sequence< rtl::OUString >& /*seqValue*/ ) throw (registry::InvalidRegistryException, uno::RuntimeException) {}; 61cdf0e10cSrcweir virtual rtl::OUString SAL_CALL getStringValue( ) throw (registry::InvalidRegistryException, registry::InvalidValueException, uno::RuntimeException) {return rtl::OUString();}; 62cdf0e10cSrcweir virtual void SAL_CALL setStringValue( const rtl::OUString& /*value*/ ) throw (registry::InvalidRegistryException, uno::RuntimeException) {}; 63cdf0e10cSrcweir virtual uno::Sequence< rtl::OUString > SAL_CALL getStringListValue( ) throw (registry::InvalidRegistryException, registry::InvalidValueException, uno::RuntimeException) {return uno::Sequence<rtl::OUString>();}; 64cdf0e10cSrcweir virtual void SAL_CALL setStringListValue( const uno::Sequence< rtl::OUString >& /*seqValue*/ ) throw (registry::InvalidRegistryException, uno::RuntimeException) {}; 65cdf0e10cSrcweir virtual uno::Sequence< sal_Int8 > SAL_CALL getBinaryValue( ) throw (registry::InvalidRegistryException, registry::InvalidValueException, uno::RuntimeException) {return uno::Sequence<sal_Int8>();}; 66cdf0e10cSrcweir virtual void SAL_CALL setBinaryValue( const uno::Sequence< sal_Int8 >& /*value*/ ) throw (registry::InvalidRegistryException, uno::RuntimeException) {}; 67cdf0e10cSrcweir virtual uno::Reference< registry::XRegistryKey > SAL_CALL openKey( const rtl::OUString& /*aKeyName*/ ) throw (registry::InvalidRegistryException, uno::RuntimeException) {return uno::Reference<registry::XRegistryKey>();}; 68cdf0e10cSrcweir virtual uno::Reference< registry::XRegistryKey > SAL_CALL createKey( const rtl::OUString& /*aKeyName*/ ) throw (registry::InvalidRegistryException, uno::RuntimeException) {return uno::Reference<registry::XRegistryKey>();}; 69cdf0e10cSrcweir virtual void SAL_CALL closeKey( ) throw (registry::InvalidRegistryException, uno::RuntimeException) {}; 70cdf0e10cSrcweir virtual void SAL_CALL deleteKey( const rtl::OUString& /*rKeyName*/ ) throw (registry::InvalidRegistryException, uno::RuntimeException) {}; 71cdf0e10cSrcweir virtual uno::Sequence< uno::Reference< registry::XRegistryKey > > SAL_CALL openKeys( ) throw (registry::InvalidRegistryException, uno::RuntimeException) {return uno::Sequence<uno::Reference<registry::XRegistryKey> >();}; 72cdf0e10cSrcweir virtual uno::Sequence< rtl::OUString > SAL_CALL getKeyNames( ) throw (registry::InvalidRegistryException, uno::RuntimeException) {return uno::Sequence<rtl::OUString>();}; 73cdf0e10cSrcweir virtual sal_Bool SAL_CALL createLink( const rtl::OUString& /*aLinkName*/, const rtl::OUString& /*aLinkTarget*/ ) throw (registry::InvalidRegistryException, uno::RuntimeException) {return sal_False;}; 74cdf0e10cSrcweir virtual void SAL_CALL deleteLink( const rtl::OUString& /*rLinkName*/ ) throw (registry::InvalidRegistryException, uno::RuntimeException) {}; 75cdf0e10cSrcweir virtual rtl::OUString SAL_CALL getLinkTarget( const rtl::OUString& /*rLinkName*/ ) throw (registry::InvalidRegistryException, uno::RuntimeException) {return rtl::OUString();}; 76cdf0e10cSrcweir virtual rtl::OUString SAL_CALL getResolvedName( const rtl::OUString& /*aKeyName*/ ) throw (registry::InvalidRegistryException, uno::RuntimeException) {return rtl::OUString();}; 77cdf0e10cSrcweir }; 78cdf0e10cSrcweir 79cdf0e10cSrcweir 80cdf0e10cSrcweir 81cdf0e10cSrcweir static rtl::OUString s_test__cppu_loadSharedLibComponentFactory(char const * pServicePurpose) 82cdf0e10cSrcweir { 83cdf0e10cSrcweir rtl::OUString result; 84cdf0e10cSrcweir 85cdf0e10cSrcweir rtl::OUString servicePurpose = rtl::OUString(pServicePurpose, 86cdf0e10cSrcweir rtl_str_getLength(pServicePurpose), 87cdf0e10cSrcweir RTL_TEXTENCODING_ASCII_US); 88cdf0e10cSrcweir 89cdf0e10cSrcweir result += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\ts_test__cppu_loadSharedLibComponentFactory ")); 90cdf0e10cSrcweir result += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("(\"")); 91cdf0e10cSrcweir result += servicePurpose; 92cdf0e10cSrcweir result += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\") - ")); 93cdf0e10cSrcweir 94cdf0e10cSrcweir try { 95cdf0e10cSrcweir uno::Reference<uno::XInterface> xObject( 96cdf0e10cSrcweir cppu::loadSharedLibComponentFactory( 97cdf0e10cSrcweir rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SAL_DLLPREFIX "TestComponent.uno" SAL_DLLEXTENSION)), 98cdf0e10cSrcweir rtl::OUString(), 99cdf0e10cSrcweir rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("impl.test.TestComponent")) + servicePurpose, 100cdf0e10cSrcweir uno::Reference<lang::XMultiServiceFactory>(), 101cdf0e10cSrcweir uno::Reference<registry::XRegistryKey>()) 102cdf0e10cSrcweir ); 103cdf0e10cSrcweir 104cdf0e10cSrcweir rtl::OUString envDcp_purpose(cppu::EnvDcp::getPurpose(g_envDcp)); 105cdf0e10cSrcweir if (envDcp_purpose == servicePurpose) 106cdf0e10cSrcweir result += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("passed\n")); 107cdf0e10cSrcweir 108cdf0e10cSrcweir else 109cdf0e10cSrcweir { 110cdf0e10cSrcweir result += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FAILED - got: \"")); 111cdf0e10cSrcweir result += envDcp_purpose; 112cdf0e10cSrcweir result += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\"\n")); 113cdf0e10cSrcweir } 114cdf0e10cSrcweir } 115cdf0e10cSrcweir catch(uno::Exception & exception) { 116cdf0e10cSrcweir result += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FAILED - got: \"")); 117cdf0e10cSrcweir result += exception.Message; 118cdf0e10cSrcweir result += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\"\n")); 119cdf0e10cSrcweir } 120cdf0e10cSrcweir 121cdf0e10cSrcweir return result; 122cdf0e10cSrcweir } 123cdf0e10cSrcweir 124cdf0e10cSrcweir static rtl::OUString s_test__cppu_writeSharedLibComponentInfo(char const * pServicePurpose) 125cdf0e10cSrcweir { 126cdf0e10cSrcweir rtl::OUString result; 127cdf0e10cSrcweir 128cdf0e10cSrcweir rtl::OUString servicePurpose = rtl::OUString(pServicePurpose, 129cdf0e10cSrcweir rtl_str_getLength(pServicePurpose), 130cdf0e10cSrcweir RTL_TEXTENCODING_ASCII_US); 131cdf0e10cSrcweir 132cdf0e10cSrcweir result += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\ts_test__cppu_writeSharedLibComponentInfo ")); 133cdf0e10cSrcweir result += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("(\"")); 134cdf0e10cSrcweir result += servicePurpose; 135cdf0e10cSrcweir result += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\") - ")); 136cdf0e10cSrcweir 137cdf0e10cSrcweir char buff[256]; 138cdf0e10cSrcweir strcpy(buff, "TestComponent.uno="); 139cdf0e10cSrcweir strcat(buff, pServicePurpose); 140cdf0e10cSrcweir 141cdf0e10cSrcweir putenv(buff); 142cdf0e10cSrcweir 143cdf0e10cSrcweir try { 144cdf0e10cSrcweir cppu::writeSharedLibComponentInfo( 145cdf0e10cSrcweir rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SAL_DLLPREFIX "TestComponent.uno" SAL_DLLEXTENSION)), 146cdf0e10cSrcweir rtl::OUString(), 147cdf0e10cSrcweir uno::Reference<lang::XMultiServiceFactory>(), 148cdf0e10cSrcweir uno::Reference<registry::XRegistryKey>(new MyKey) 149cdf0e10cSrcweir ); 150cdf0e10cSrcweir 151cdf0e10cSrcweir rtl::OUString envDcp_purpose(cppu::EnvDcp::getPurpose(g_envDcp)); 152cdf0e10cSrcweir if (envDcp_purpose == servicePurpose) 153cdf0e10cSrcweir result += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("passed\n")); 154cdf0e10cSrcweir 155cdf0e10cSrcweir else 156cdf0e10cSrcweir { 157cdf0e10cSrcweir result += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FAILED - got: \"")); 158cdf0e10cSrcweir result += envDcp_purpose; 159cdf0e10cSrcweir result += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\"\n")); 160cdf0e10cSrcweir } 161cdf0e10cSrcweir } 162cdf0e10cSrcweir catch(uno::Exception & exception) { 163cdf0e10cSrcweir result += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FAILED - got: \"")); 164cdf0e10cSrcweir result += exception.Message; 165cdf0e10cSrcweir result += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\"\n")); 166cdf0e10cSrcweir } 167cdf0e10cSrcweir 168cdf0e10cSrcweir return result; 169cdf0e10cSrcweir } 170cdf0e10cSrcweir 171cdf0e10cSrcweir 172cdf0e10cSrcweir SAL_IMPLEMENT_MAIN_WITH_ARGS(/*argc*/, argv) 173cdf0e10cSrcweir { 174cdf0e10cSrcweir int result = 0; 175cdf0e10cSrcweir 176cdf0e10cSrcweir rtl::OUString message; 177cdf0e10cSrcweir 178cdf0e10cSrcweir message += rtl::OUString(argv[0], rtl_str_getLength(argv[0]), RTL_TEXTENCODING_ASCII_US); 179cdf0e10cSrcweir message += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\n")); 180cdf0e10cSrcweir 181cdf0e10cSrcweir message += s_test__cppu_loadSharedLibComponentFactory(":unsafe"); 182cdf0e10cSrcweir message += s_test__cppu_loadSharedLibComponentFactory(":affine"); 183cdf0e10cSrcweir message += s_test__cppu_loadSharedLibComponentFactory(""); 184cdf0e10cSrcweir 185cdf0e10cSrcweir message += s_test__cppu_writeSharedLibComponentInfo(":unsafe"); 186cdf0e10cSrcweir message += s_test__cppu_writeSharedLibComponentInfo(":affine"); 187cdf0e10cSrcweir message += s_test__cppu_writeSharedLibComponentInfo(""); 188cdf0e10cSrcweir 189cdf0e10cSrcweir if (message.indexOf(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FAILED"))) == -1) 190cdf0e10cSrcweir message += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("TESTS PASSED\n")); 191cdf0e10cSrcweir 192cdf0e10cSrcweir else 193cdf0e10cSrcweir { 194cdf0e10cSrcweir message += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("TESTS _NOT_ PASSED\n")); 195cdf0e10cSrcweir result = -1; 196cdf0e10cSrcweir } 197cdf0e10cSrcweir 198cdf0e10cSrcweir std::cout << rtl::OUStringToOString(message, RTL_TEXTENCODING_ASCII_US).getStr(); 199cdf0e10cSrcweir 200cdf0e10cSrcweir return result; 201cdf0e10cSrcweir } 202