1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_stoc.hxx" 30 31 #include <stdio.h> 32 #include <stdlib.h> 33 #include <string.h> 34 35 #include <sal/main.h> 36 #include <osl/diagnose.h> 37 #include <osl/process.h> 38 39 #include <example/XTest.hpp> 40 #include <com/sun/star/lang/XServiceInfo.hpp> 41 #include <com/sun/star/lang/XSingleServiceFactory.hpp> 42 #include <com/sun/star/registry/XImplementationRegistration.hpp> 43 #include <com/sun/star/lang/XComponent.hpp> 44 #include <cppuhelper/factory.hxx> 45 #include <cppuhelper/servicefactory.hxx> 46 47 48 using namespace com::sun::star::uno; 49 using namespace com::sun::star::registry; 50 using namespace com::sun::star::lang; 51 using namespace example; 52 using namespace cppu; 53 using namespace rtl; 54 55 #if OSL_DEBUG_LEVEL > 0 56 #define TEST_ENSHURE(c, m) OSL_ENSURE(c, m) 57 #else 58 #define TEST_ENSHURE(c, m) OSL_VERIFY(c) 59 #endif 60 61 OUString getExePath() 62 { 63 OUString exe; 64 65 OSL_VERIFY(osl_getExecutableFile( &exe.pData) == osl_Process_E_None); 66 67 #if defined(WIN32) || defined(__OS2__) || defined(WNT) 68 exe = exe.copy(0, exe.getLength() - 10); 69 #else 70 exe = exe.copy(0, exe.getLength() - 6); 71 #endif 72 return exe; 73 } 74 75 SAL_IMPLEMENT_MAIN() 76 { 77 #ifdef UNX 78 OUString compName1(RTL_CONSTASCII_USTRINGPARAM("libexcomp1.so")); 79 OUString compName2(RTL_CONSTASCII_USTRINGPARAM("libexcomp2.so")); 80 #else 81 OUString compName1(RTL_CONSTASCII_USTRINGPARAM("excomp1")); 82 OUString compName2(RTL_CONSTASCII_USTRINGPARAM("excomp2")); 83 #endif 84 85 OUString exePath( getExePath() ); 86 OUString excompRdb(exePath); 87 88 excompRdb += OUString::createFromAscii("excomp.rdb"); 89 90 Reference< XMultiServiceFactory > xSMgr = ::cppu::createRegistryServiceFactory( excompRdb ); 91 TEST_ENSHURE( xSMgr.is(), "excomp error 0" ); 92 93 typelib_TypeDescription* pTypeDesc = NULL; 94 OUString sType = OUString::createFromAscii("com.sun.star.text.XTextDocument"); 95 typelib_typedescription_getByName( &pTypeDesc, sType.pData); 96 // typelib_InterfaceTypeDescription* pInterDesc = (typelib_InterfaceTypeDescription*)pTypeDesc; 97 98 Reference< XInterface > xIFace = xSMgr->createInstance(OUString::createFromAscii("com.sun.star.registry.ImplementationRegistration")); 99 Reference< XImplementationRegistration > xImpReg( xIFace, UNO_QUERY); 100 TEST_ENSHURE( xImpReg.is(), "excomp error 1" ); 101 try 102 { 103 xImpReg->registerImplementation(OUString::createFromAscii("com.sun.star.loader.SharedLibrary"), 104 compName1, 105 Reference< XSimpleRegistry >() ); 106 xImpReg->registerImplementation(OUString::createFromAscii("com.sun.star.loader.SharedLibrary"), 107 compName2, 108 Reference< XSimpleRegistry >() ); 109 } 110 catch( CannotRegisterImplementationException& e) 111 { 112 TEST_ENSHURE( e.Message.getLength(), OUStringToOString(e.Message, RTL_TEXTENCODING_ASCII_US).getStr() ); 113 } 114 115 Reference< XTest > xTest1( xSMgr->createInstance(OUString::createFromAscii("example.ExampleComponent1")), 116 UNO_QUERY); 117 TEST_ENSHURE( xTest1.is(), "excomp error 2" ); 118 Reference< XTest > xTest2( xSMgr->createInstance(OUString::createFromAscii("example.ExampleComponent2")), 119 UNO_QUERY); 120 TEST_ENSHURE( xTest2.is(), "excomp error 3" ); 121 122 OUString m1 = xTest1->getMessage(); 123 OUString m2 = xTest2->getMessage(); 124 125 fprintf(stdout, "ExampleComponent1, Message = \"%s\"\n", OUStringToOString(m1, RTL_TEXTENCODING_ASCII_US).getStr()); 126 fprintf(stdout, "ExampleComponent2, Message = \"%s\"\n", OUStringToOString(m2, RTL_TEXTENCODING_ASCII_US).getStr()); 127 128 xImpReg->revokeImplementation(compName1, Reference< XSimpleRegistry >() ); 129 xImpReg->revokeImplementation(compName2, Reference< XSimpleRegistry >() ); 130 131 Reference< XComponent >( xSMgr, UNO_QUERY )->dispose(); 132 133 return(0); 134 } 135 136 137