1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
|
/*************************************************************************
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* Copyright 2008 by Sun Microsystems, Inc.
*
* OpenOffice.org - a multi-platform office productivity suite
*
* $RCSfile: cfg_test.cxx,v $
* $Revision: 1.8 $
*
* This file is part of OpenOffice.org.
*
* OpenOffice.org is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3
* only, as published by the Free Software Foundation.
*
* OpenOffice.org is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License version 3 for more details
* (a copy is included in the LICENSE file that accompanied this code).
*
* You should have received a copy of the GNU Lesser General Public License
* version 3 along with OpenOffice.org. If not, see
* <http://www.openoffice.org/license.html>
* for a copy of the LGPLv3 License.
*
************************************************************************/
// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_cppuhelper.hxx"
// starting the executable:
// -env:UNO_CFG_URL=local;<absolute_path>..\\..\\test\\cfg_data;<absolute_path>\\cfg_update
// -env:UNO_TYPES=cpputest.rdb
#include <sal/main.h>
#include <stdio.h>
#include <rtl/strbuf.hxx>
#include <cppuhelper/implementationentry.hxx>
#include <cppuhelper/bootstrap.hxx>
#include <cppuhelper/implbase2.hxx>
#include <com/sun/star/lang/XMultiComponentFactory.hpp>
#include <com/sun/star/lang/XInitialization.hpp>
#include <com/sun/star/lang/XServiceInfo.hpp>
#include <com/sun/star/lang/XComponent.hpp>
#include <com/sun/star/registry/XImplementationRegistration.hpp>
#define OUSTR(x) ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(x) )
using namespace ::cppu;
using namespace ::rtl;
using namespace ::osl;
using namespace ::com::sun::star;
using namespace ::com::sun::star::uno;
namespace cfg_test
{
//--------------------------------------------------------------------------------------------------
static Sequence< OUString > impl0_getSupportedServiceNames()
{
OUString str( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.bootstrap.TestComponent0") );
return Sequence< OUString >( &str, 1 );
}
//--------------------------------------------------------------------------------------------------
static OUString impl0_getImplementationName()
{
return OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.bootstrap.TestComponent0") );
}
//--------------------------------------------------------------------------------------------------
static Sequence< OUString > impl1_getSupportedServiceNames()
{
OUString str( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.bootstrap.TestComponent1") );
return Sequence< OUString >( &str, 1 );
}
//--------------------------------------------------------------------------------------------------
static OUString impl1_getImplementationName()
{
return OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.bootstrap.TestComponent1") );
}
//==================================================================================================
class ServiceImpl0
: public WeakImplHelper2< lang::XServiceInfo, lang::XInitialization >
{
Reference< XComponentContext > m_xContext;
public:
ServiceImpl0( Reference< XComponentContext > const & xContext ) SAL_THROW( () );
// XInitialization
virtual void SAL_CALL initialize( const Sequence< Any >& rArgs ) throw (Exception, RuntimeException);
// XServiceInfo
virtual Sequence< OUString > SAL_CALL getSupportedServiceNames() throw (RuntimeException);
virtual OUString SAL_CALL getImplementationName() throw (RuntimeException);
virtual sal_Bool SAL_CALL supportsService( const OUString & rServiceName ) throw (RuntimeException);
};
//__________________________________________________________________________________________________
ServiceImpl0::ServiceImpl0( Reference< XComponentContext > const & xContext ) SAL_THROW( () )
: m_xContext( xContext )
{
sal_Int32 n;
OUString val;
// service properties
OSL_VERIFY( m_xContext->getValueByName(
OUSTR("/services/com.sun.star.bootstrap.TestComponent0/context-properties/serviceprop0") ) >>= n );
OSL_VERIFY( n == 13 );
OSL_VERIFY( m_xContext->getValueByName(
OUSTR("/services/com.sun.star.bootstrap.TestComponent0/context-properties/serviceprop1") ) >>= val );
OSL_VERIFY( val.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("value of serviceprop1") ) );
// impl properties
OSL_VERIFY( m_xContext->getValueByName(
OUSTR("/implementations/com.sun.star.comp.bootstrap.TestComponent0/context-properties/implprop0") ) >>= n );
OSL_VERIFY( n == 15 );
OSL_VERIFY( m_xContext->getValueByName(
OUSTR("/implementations/com.sun.star.comp.bootstrap.TestComponent0/context-properties/implprop1") ) >>= val );
OSL_VERIFY( val.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("value of implprop1") ) );
}
// XInitialization
//__________________________________________________________________________________________________
void ServiceImpl0::initialize( const Sequence< Any >& rArgs )
throw (Exception, RuntimeException)
{
// check args
OUString val;
OSL_VERIFY( rArgs.getLength() == 3 );
OSL_VERIFY( rArgs[ 0 ] >>= val );
OSL_VERIFY( val.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("first argument") ) );
OSL_VERIFY( rArgs[ 1 ] >>= val );
OSL_VERIFY( val.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("second argument") ) );
OSL_VERIFY( rArgs[ 2 ] >>= val );
OSL_VERIFY( val.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("third argument") ) );
}
// XServiceInfo
//__________________________________________________________________________________________________
OUString ServiceImpl0::getImplementationName()
throw(::com::sun::star::uno::RuntimeException)
{
return impl0_getImplementationName();
}
//__________________________________________________________________________________________________
Sequence< OUString > ServiceImpl0::getSupportedServiceNames()
throw(::com::sun::star::uno::RuntimeException)
{
return impl0_getSupportedServiceNames();
}
//__________________________________________________________________________________________________
sal_Bool ServiceImpl0::supportsService( const OUString & rServiceName )
throw(::com::sun::star::uno::RuntimeException)
{
const Sequence< OUString > & rSNL = getSupportedServiceNames();
const OUString * pArray = rSNL.getConstArray();
for ( sal_Int32 nPos = rSNL.getLength(); nPos--; )
{
if (pArray[nPos] == rServiceName)
return sal_True;
}
return sal_False;
}
//==================================================================================================
class ServiceImpl1 : public ServiceImpl0
{
public:
inline ServiceImpl1( Reference< XComponentContext > const & xContext ) SAL_THROW( () )
: ServiceImpl0( xContext )
{}
// XServiceInfo
virtual Sequence< OUString > SAL_CALL getSupportedServiceNames() throw (RuntimeException);
virtual OUString SAL_CALL getImplementationName() throw (RuntimeException);
};
//__________________________________________________________________________________________________
OUString ServiceImpl1::getImplementationName()
throw(::com::sun::star::uno::RuntimeException)
{
return impl1_getImplementationName();
}
//__________________________________________________________________________________________________
Sequence< OUString > ServiceImpl1::getSupportedServiceNames()
throw(::com::sun::star::uno::RuntimeException)
{
return impl1_getSupportedServiceNames();
}
//==================================================================================================
static Reference< XInterface > SAL_CALL ServiceImpl0_create(
Reference< XComponentContext > const & xContext )
SAL_THROW( (Exception) )
{
return (OWeakObject *)new ServiceImpl0( xContext );
}
//==================================================================================================
static Reference< XInterface > SAL_CALL ServiceImpl1_create(
Reference< XComponentContext > const & xContext )
SAL_THROW( (Exception) )
{
return (OWeakObject *)new ServiceImpl1( xContext );
}
} // namespace cfg_test
static struct ImplementationEntry g_entries[] =
{
{
::cfg_test::ServiceImpl0_create, ::cfg_test::impl0_getImplementationName,
::cfg_test::impl0_getSupportedServiceNames, createSingleComponentFactory,
0, 0
},
{
::cfg_test::ServiceImpl1_create, ::cfg_test::impl1_getImplementationName,
::cfg_test::impl1_getSupportedServiceNames, createSingleComponentFactory,
0, 0
},
{ 0, 0, 0, 0, 0, 0 }
};
// component exports
extern "C"
{
//==================================================================================================
void SAL_CALL component_getImplementationEnvironment(
const sal_Char ** ppEnvTypeName, uno_Environment ** /*ppEnv*/ )
{
*ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
}
//==================================================================================================
sal_Bool SAL_CALL component_writeInfo(
void * pServiceManager, void * pRegistryKey )
{
return component_writeInfoHelper(
pServiceManager, pRegistryKey, g_entries );
}
//==================================================================================================
void * SAL_CALL component_getFactory(
const sal_Char * pImplName, void * pServiceManager, void * pRegistryKey )
{
return component_getFactoryHelper(
pImplName, pServiceManager, pRegistryKey , g_entries );
}
}
//##################################################################################################
//##################################################################################################
//##################################################################################################
SAL_IMPLEMENT_MAIN()
{
try
{
Reference< XComponentContext > xContext( defaultBootstrap_InitialComponentContext() );
Reference< lang::XMultiComponentFactory > xMgr( xContext->getServiceManager() );
// show what is in context
xContext->getValueByName( OUSTR("dump_maps") );
sal_Int32 n;
OSL_VERIFY( xContext->getValueByName( OUSTR("/global-context-properties/TestValue") ) >>= n );
::fprintf( stderr, "> n=%d\n", n );
Reference< XInterface > x;
OSL_VERIFY( !(xContext->getValueByName( OUSTR("/singletons/my_converter") ) >>= x) );
OSL_VERIFY( xContext->getValueByName( OUSTR("/singletons/com.sun.star.script.theConverter") ) >>= x );
OSL_VERIFY( xContext->getValueByName( OUSTR("/singletons/com.sun.star.bootstrap.theTestComponent0") ) >>= x );
::fprintf( stderr, "> registering service...\n", n );
#if defined(SAL_W32) || defined(SAL_OS2)
OUString libName( OUSTR("cfg_test.dll") );
#elif defined(SAL_UNX)
OUString libName( OUSTR("libcfg_test.so") );
#endif
Reference< registry::XImplementationRegistration > xImplReg( xMgr->createInstanceWithContext(
OUSTR("com.sun.star.registry.ImplementationRegistration"), xContext ), UNO_QUERY );
OSL_ENSURE( xImplReg.is(), "### no impl reg!" );
xImplReg->registerImplementation(
OUSTR("com.sun.star.loader.SharedLibrary"), libName,
Reference< registry::XSimpleRegistry >() );
OSL_VERIFY( (x = xMgr->createInstanceWithContext( OUSTR("com.sun.star.bootstrap.TestComponent0"), xContext )).is() );
OSL_VERIFY( (x = xMgr->createInstanceWithContext( OUSTR("com.sun.star.bootstrap.TestComponent1"), xContext )).is() );
Reference< lang::XComponent > xComp( xContext, UNO_QUERY );
if (xComp.is())
{
xComp->dispose();
}
return 0;
}
catch (Exception & exc)
{
OString str( OUStringToOString( exc.Message, RTL_TEXTENCODING_ASCII_US ) );
::fprintf( stderr, "# caught exception: %s\n", str.getStr() );
return 1;
}
}
|