1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: excomp.cxx,v $
10 * $Revision: 1.8.16.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_stoc.hxx"
39 #include <osl/diagnose.h>
40 #include <osl/process.h>
42 #include <example/XTest.hpp>
43 #include <com/sun/star/lang/XServiceInfo.hpp>
44 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
45 #include <com/sun/star/registry/XImplementationRegistration.hpp>
46 #include <com/sun/star/lang/XComponent.hpp>
47 #include <cppuhelper/factory.hxx>
48 #include <cppuhelper/servicefactory.hxx>
51 using namespace com::sun::star::uno
;
52 using namespace com::sun::star::registry
;
53 using namespace com::sun::star::lang
;
54 using namespace example
;
58 #if OSL_DEBUG_LEVEL > 0
59 #define TEST_ENSHURE(c, m) OSL_ENSURE(c, m)
61 #define TEST_ENSHURE(c, m) OSL_VERIFY(c)
68 OSL_VERIFY(osl_getExecutableFile( &exe
.pData
) == osl_Process_E_None
);
70 #if defined(WIN32) || defined(__OS2__) || defined(WNT)
71 exe
= exe
.copy(0, exe
.getLength() - 10);
73 exe
= exe
.copy(0, exe
.getLength() - 6);
81 OUString
compName1(RTL_CONSTASCII_USTRINGPARAM("libexcomp1.so"));
82 OUString
compName2(RTL_CONSTASCII_USTRINGPARAM("libexcomp2.so"));
84 OUString
compName1(RTL_CONSTASCII_USTRINGPARAM("excomp1"));
85 OUString
compName2(RTL_CONSTASCII_USTRINGPARAM("excomp2"));
88 OUString
exePath( getExePath() );
89 OUString
excompRdb(exePath
);
91 excompRdb
+= OUString::createFromAscii("excomp.rdb");
93 Reference
< XMultiServiceFactory
> xSMgr
= ::cppu::createRegistryServiceFactory( excompRdb
);
94 TEST_ENSHURE( xSMgr
.is(), "excomp error 0" );
96 typelib_TypeDescription
* pTypeDesc
= NULL
;
97 OUString sType
= OUString::createFromAscii("com.sun.star.text.XTextDocument");
98 typelib_typedescription_getByName( &pTypeDesc
, sType
.pData
);
99 // typelib_InterfaceTypeDescription* pInterDesc = (typelib_InterfaceTypeDescription*)pTypeDesc;
101 Reference
< XInterface
> xIFace
= xSMgr
->createInstance(OUString::createFromAscii("com.sun.star.registry.ImplementationRegistration"));
102 Reference
< XImplementationRegistration
> xImpReg( xIFace
, UNO_QUERY
);
103 TEST_ENSHURE( xImpReg
.is(), "excomp error 1" );
106 xImpReg
->registerImplementation(OUString::createFromAscii("com.sun.star.loader.SharedLibrary"),
108 Reference
< XSimpleRegistry
>() );
109 xImpReg
->registerImplementation(OUString::createFromAscii("com.sun.star.loader.SharedLibrary"),
111 Reference
< XSimpleRegistry
>() );
113 catch( CannotRegisterImplementationException
& e
)
115 TEST_ENSHURE( e
.Message
.getLength(), OUStringToOString(e
.Message
, RTL_TEXTENCODING_ASCII_US
).getStr() );
118 Reference
< XTest
> xTest1( xSMgr
->createInstance(OUString::createFromAscii("example.ExampleComponent1")),
120 TEST_ENSHURE( xTest1
.is(), "excomp error 2" );
121 Reference
< XTest
> xTest2( xSMgr
->createInstance(OUString::createFromAscii("example.ExampleComponent2")),
123 TEST_ENSHURE( xTest2
.is(), "excomp error 3" );
125 OUString m1
= xTest1
->getMessage();
126 OUString m2
= xTest2
->getMessage();
128 fprintf(stdout
, "ExampleComponent1, Message = \"%s\"\n", OUStringToOString(m1
, RTL_TEXTENCODING_ASCII_US
).getStr());
129 fprintf(stdout
, "ExampleComponent2, Message = \"%s\"\n", OUStringToOString(m2
, RTL_TEXTENCODING_ASCII_US
).getStr());
131 xImpReg
->revokeImplementation(compName1
, Reference
< XSimpleRegistry
>() );
132 xImpReg
->revokeImplementation(compName2
, Reference
< XSimpleRegistry
>() );
134 Reference
< XComponent
>( xSMgr
, UNO_QUERY
)->dispose();