update dev300-m58
[ooovba.git] / stoc / test / excomp / excomp.cxx
blob2c36d7fb6b065255fcb054664358218e0bf00430
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
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"
34 #include <stdio.h>
35 #include <stdlib.h>
36 #include <string.h>
38 #include <sal/main.h>
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;
55 using namespace cppu;
56 using namespace rtl;
58 #if OSL_DEBUG_LEVEL > 0
59 #define TEST_ENSHURE(c, m) OSL_ENSURE(c, m)
60 #else
61 #define TEST_ENSHURE(c, m) OSL_VERIFY(c)
62 #endif
64 OUString getExePath()
66 OUString exe;
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);
72 #else
73 exe = exe.copy(0, exe.getLength() - 6);
74 #endif
75 return exe;
78 SAL_IMPLEMENT_MAIN()
80 #ifdef UNX
81 OUString compName1(RTL_CONSTASCII_USTRINGPARAM("libexcomp1.so"));
82 OUString compName2(RTL_CONSTASCII_USTRINGPARAM("libexcomp2.so"));
83 #else
84 OUString compName1(RTL_CONSTASCII_USTRINGPARAM("excomp1"));
85 OUString compName2(RTL_CONSTASCII_USTRINGPARAM("excomp2"));
86 #endif
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"),
107 compName1,
108 Reference< XSimpleRegistry >() );
109 xImpReg->registerImplementation(OUString::createFromAscii("com.sun.star.loader.SharedLibrary"),
110 compName2,
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")),
119 UNO_QUERY);
120 TEST_ENSHURE( xTest1.is(), "excomp error 2" );
121 Reference< XTest > xTest2( xSMgr->createInstance(OUString::createFromAscii("example.ExampleComponent2")),
122 UNO_QUERY);
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();
136 return(0);