xref: /aoo4110/main/stoc/test/excomp/excomp.cxx (revision b1cdbd2c)
1*b1cdbd2cSJim Jagielski /**************************************************************
2*b1cdbd2cSJim Jagielski  *
3*b1cdbd2cSJim Jagielski  * Licensed to the Apache Software Foundation (ASF) under one
4*b1cdbd2cSJim Jagielski  * or more contributor license agreements.  See the NOTICE file
5*b1cdbd2cSJim Jagielski  * distributed with this work for additional information
6*b1cdbd2cSJim Jagielski  * regarding copyright ownership.  The ASF licenses this file
7*b1cdbd2cSJim Jagielski  * to you under the Apache License, Version 2.0 (the
8*b1cdbd2cSJim Jagielski  * "License"); you may not use this file except in compliance
9*b1cdbd2cSJim Jagielski  * with the License.  You may obtain a copy of the License at
10*b1cdbd2cSJim Jagielski  *
11*b1cdbd2cSJim Jagielski  *   http://www.apache.org/licenses/LICENSE-2.0
12*b1cdbd2cSJim Jagielski  *
13*b1cdbd2cSJim Jagielski  * Unless required by applicable law or agreed to in writing,
14*b1cdbd2cSJim Jagielski  * software distributed under the License is distributed on an
15*b1cdbd2cSJim Jagielski  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*b1cdbd2cSJim Jagielski  * KIND, either express or implied.  See the License for the
17*b1cdbd2cSJim Jagielski  * specific language governing permissions and limitations
18*b1cdbd2cSJim Jagielski  * under the License.
19*b1cdbd2cSJim Jagielski  *
20*b1cdbd2cSJim Jagielski  *************************************************************/
21*b1cdbd2cSJim Jagielski 
22*b1cdbd2cSJim Jagielski 
23*b1cdbd2cSJim Jagielski 
24*b1cdbd2cSJim Jagielski // MARKER(update_precomp.py): autogen include statement, do not remove
25*b1cdbd2cSJim Jagielski #include "precompiled_stoc.hxx"
26*b1cdbd2cSJim Jagielski 
27*b1cdbd2cSJim Jagielski #include <stdio.h>
28*b1cdbd2cSJim Jagielski #include <stdlib.h>
29*b1cdbd2cSJim Jagielski #include <string.h>
30*b1cdbd2cSJim Jagielski 
31*b1cdbd2cSJim Jagielski #include <sal/main.h>
32*b1cdbd2cSJim Jagielski #include <osl/diagnose.h>
33*b1cdbd2cSJim Jagielski #include <osl/process.h>
34*b1cdbd2cSJim Jagielski 
35*b1cdbd2cSJim Jagielski #include <example/XTest.hpp>
36*b1cdbd2cSJim Jagielski #include <com/sun/star/lang/XServiceInfo.hpp>
37*b1cdbd2cSJim Jagielski #include <com/sun/star/lang/XSingleServiceFactory.hpp>
38*b1cdbd2cSJim Jagielski #include <com/sun/star/registry/XImplementationRegistration.hpp>
39*b1cdbd2cSJim Jagielski #include <com/sun/star/lang/XComponent.hpp>
40*b1cdbd2cSJim Jagielski #include <cppuhelper/factory.hxx>
41*b1cdbd2cSJim Jagielski #include <cppuhelper/servicefactory.hxx>
42*b1cdbd2cSJim Jagielski 
43*b1cdbd2cSJim Jagielski 
44*b1cdbd2cSJim Jagielski using namespace com::sun::star::uno;
45*b1cdbd2cSJim Jagielski using namespace com::sun::star::registry;
46*b1cdbd2cSJim Jagielski using namespace com::sun::star::lang;
47*b1cdbd2cSJim Jagielski using namespace example;
48*b1cdbd2cSJim Jagielski using namespace cppu;
49*b1cdbd2cSJim Jagielski using namespace rtl;
50*b1cdbd2cSJim Jagielski 
51*b1cdbd2cSJim Jagielski #if OSL_DEBUG_LEVEL > 0
52*b1cdbd2cSJim Jagielski #define TEST_ENSHURE(c, m)   OSL_ENSURE(c, m)
53*b1cdbd2cSJim Jagielski #else
54*b1cdbd2cSJim Jagielski #define TEST_ENSHURE(c, m)   OSL_VERIFY(c)
55*b1cdbd2cSJim Jagielski #endif
56*b1cdbd2cSJim Jagielski 
getExePath()57*b1cdbd2cSJim Jagielski OUString getExePath()
58*b1cdbd2cSJim Jagielski {
59*b1cdbd2cSJim Jagielski 	OUString 		exe;
60*b1cdbd2cSJim Jagielski 
61*b1cdbd2cSJim Jagielski 	OSL_VERIFY(osl_getExecutableFile( &exe.pData) == osl_Process_E_None);
62*b1cdbd2cSJim Jagielski 
63*b1cdbd2cSJim Jagielski #if defined(WIN32) || defined(__OS2__) || defined(WNT)
64*b1cdbd2cSJim Jagielski 	exe = exe.copy(0, exe.getLength() - 10);
65*b1cdbd2cSJim Jagielski #else
66*b1cdbd2cSJim Jagielski 	exe = exe.copy(0, exe.getLength() - 6);
67*b1cdbd2cSJim Jagielski #endif
68*b1cdbd2cSJim Jagielski 	return exe;
69*b1cdbd2cSJim Jagielski }
70*b1cdbd2cSJim Jagielski 
SAL_IMPLEMENT_MAIN()71*b1cdbd2cSJim Jagielski SAL_IMPLEMENT_MAIN()
72*b1cdbd2cSJim Jagielski {
73*b1cdbd2cSJim Jagielski #ifdef UNX
74*b1cdbd2cSJim Jagielski 	OUString compName1(RTL_CONSTASCII_USTRINGPARAM("libexcomp1.so"));
75*b1cdbd2cSJim Jagielski 	OUString compName2(RTL_CONSTASCII_USTRINGPARAM("libexcomp2.so"));
76*b1cdbd2cSJim Jagielski #else
77*b1cdbd2cSJim Jagielski 	OUString compName1(RTL_CONSTASCII_USTRINGPARAM("excomp1"));
78*b1cdbd2cSJim Jagielski 	OUString compName2(RTL_CONSTASCII_USTRINGPARAM("excomp2"));
79*b1cdbd2cSJim Jagielski #endif
80*b1cdbd2cSJim Jagielski 
81*b1cdbd2cSJim Jagielski 	OUString exePath( getExePath() );
82*b1cdbd2cSJim Jagielski 	OUString excompRdb(exePath);
83*b1cdbd2cSJim Jagielski 
84*b1cdbd2cSJim Jagielski 	excompRdb += OUString::createFromAscii("excomp.rdb");
85*b1cdbd2cSJim Jagielski 
86*b1cdbd2cSJim Jagielski 	Reference< XMultiServiceFactory > xSMgr  = ::cppu::createRegistryServiceFactory( excompRdb );
87*b1cdbd2cSJim Jagielski 	TEST_ENSHURE( xSMgr.is(), "excomp error 0" );
88*b1cdbd2cSJim Jagielski 
89*b1cdbd2cSJim Jagielski 	typelib_TypeDescription* pTypeDesc = NULL;
90*b1cdbd2cSJim Jagielski 	OUString sType = OUString::createFromAscii("com.sun.star.text.XTextDocument");
91*b1cdbd2cSJim Jagielski 	typelib_typedescription_getByName( &pTypeDesc, sType.pData);
92*b1cdbd2cSJim Jagielski //	typelib_InterfaceTypeDescription* pInterDesc = (typelib_InterfaceTypeDescription*)pTypeDesc;
93*b1cdbd2cSJim Jagielski 
94*b1cdbd2cSJim Jagielski 	Reference< XInterface > xIFace = xSMgr->createInstance(OUString::createFromAscii("com.sun.star.registry.ImplementationRegistration"));
95*b1cdbd2cSJim Jagielski 	Reference< XImplementationRegistration > xImpReg( xIFace, UNO_QUERY);
96*b1cdbd2cSJim Jagielski 	TEST_ENSHURE( xImpReg.is(), "excomp error 1" );
97*b1cdbd2cSJim Jagielski 	try
98*b1cdbd2cSJim Jagielski 	{
99*b1cdbd2cSJim Jagielski 		xImpReg->registerImplementation(OUString::createFromAscii("com.sun.star.loader.SharedLibrary"),
100*b1cdbd2cSJim Jagielski 										compName1,
101*b1cdbd2cSJim Jagielski 										Reference< XSimpleRegistry >() );
102*b1cdbd2cSJim Jagielski 		xImpReg->registerImplementation(OUString::createFromAscii("com.sun.star.loader.SharedLibrary"),
103*b1cdbd2cSJim Jagielski 										compName2,
104*b1cdbd2cSJim Jagielski 										Reference< XSimpleRegistry >() );
105*b1cdbd2cSJim Jagielski 	}
106*b1cdbd2cSJim Jagielski 	catch( CannotRegisterImplementationException& e)
107*b1cdbd2cSJim Jagielski 	{
108*b1cdbd2cSJim Jagielski 		TEST_ENSHURE( e.Message.getLength(), OUStringToOString(e.Message, RTL_TEXTENCODING_ASCII_US).getStr() );
109*b1cdbd2cSJim Jagielski 	}
110*b1cdbd2cSJim Jagielski 
111*b1cdbd2cSJim Jagielski 	Reference< XTest > xTest1( xSMgr->createInstance(OUString::createFromAscii("example.ExampleComponent1")),
112*b1cdbd2cSJim Jagielski 							   UNO_QUERY);
113*b1cdbd2cSJim Jagielski 	TEST_ENSHURE( xTest1.is(), "excomp error 2" );
114*b1cdbd2cSJim Jagielski 	Reference< XTest > xTest2( xSMgr->createInstance(OUString::createFromAscii("example.ExampleComponent2")),
115*b1cdbd2cSJim Jagielski 							   UNO_QUERY);
116*b1cdbd2cSJim Jagielski 	TEST_ENSHURE( xTest2.is(), "excomp error 3" );
117*b1cdbd2cSJim Jagielski 
118*b1cdbd2cSJim Jagielski 	OUString m1 = xTest1->getMessage();
119*b1cdbd2cSJim Jagielski 	OUString m2 = xTest2->getMessage();
120*b1cdbd2cSJim Jagielski 
121*b1cdbd2cSJim Jagielski 	fprintf(stdout, "ExampleComponent1, Message = \"%s\"\n", OUStringToOString(m1, RTL_TEXTENCODING_ASCII_US).getStr());
122*b1cdbd2cSJim Jagielski 	fprintf(stdout, "ExampleComponent2, Message = \"%s\"\n", OUStringToOString(m2, RTL_TEXTENCODING_ASCII_US).getStr());
123*b1cdbd2cSJim Jagielski 
124*b1cdbd2cSJim Jagielski 	xImpReg->revokeImplementation(compName1, Reference< XSimpleRegistry >() );
125*b1cdbd2cSJim Jagielski 	xImpReg->revokeImplementation(compName2, Reference< XSimpleRegistry >() );
126*b1cdbd2cSJim Jagielski 
127*b1cdbd2cSJim Jagielski 	Reference< XComponent >( xSMgr, UNO_QUERY )->dispose();
128*b1cdbd2cSJim Jagielski 
129*b1cdbd2cSJim Jagielski 	return(0);
130*b1cdbd2cSJim Jagielski }
131*b1cdbd2cSJim Jagielski 
132*b1cdbd2cSJim Jagielski 
133