1*647a425cSAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*647a425cSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*647a425cSAndrew Rist * or more contributor license agreements. See the NOTICE file
5*647a425cSAndrew Rist * distributed with this work for additional information
6*647a425cSAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*647a425cSAndrew Rist * to you under the Apache License, Version 2.0 (the
8*647a425cSAndrew Rist * "License"); you may not use this file except in compliance
9*647a425cSAndrew Rist * with the License. You may obtain a copy of the License at
10*647a425cSAndrew Rist *
11*647a425cSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*647a425cSAndrew Rist *
13*647a425cSAndrew Rist * Unless required by applicable law or agreed to in writing,
14*647a425cSAndrew Rist * software distributed under the License is distributed on an
15*647a425cSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*647a425cSAndrew Rist * KIND, either express or implied. See the License for the
17*647a425cSAndrew Rist * specific language governing permissions and limitations
18*647a425cSAndrew Rist * under the License.
19*647a425cSAndrew Rist *
20*647a425cSAndrew Rist *************************************************************/
21*647a425cSAndrew Rist
22*647a425cSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir
25cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
26cdf0e10cSrcweir #include "precompiled_stoc.hxx"
27cdf0e10cSrcweir #include <stdio.h>
28cdf0e10cSrcweir
29cdf0e10cSrcweir #include <sal/main.h>
30cdf0e10cSrcweir #include <cppuhelper/bootstrap.hxx>
31cdf0e10cSrcweir
32cdf0e10cSrcweir #include <com/sun/star/container/XContentEnumerationAccess.hpp>
33cdf0e10cSrcweir #include <com/sun/star/lang/XServiceInfo.hpp>
34cdf0e10cSrcweir #include <com/sun/star/registry/XSimpleRegistry.hpp>
35cdf0e10cSrcweir #include <com/sun/star/lang/XInitialization.hpp>
36cdf0e10cSrcweir #include <com/sun/star/lang/DisposedException.hpp>
37cdf0e10cSrcweir #include <com/sun/star/lang/XComponent.hpp>
38cdf0e10cSrcweir #include <com/sun/star/uno/XComponentContext.hpp>
39cdf0e10cSrcweir
40cdf0e10cSrcweir using namespace ::rtl;
41cdf0e10cSrcweir using namespace ::cppu;
42cdf0e10cSrcweir using namespace ::com::sun::star::uno;
43cdf0e10cSrcweir using namespace ::com::sun::star::lang;
44cdf0e10cSrcweir using namespace ::com::sun::star::container;
45cdf0e10cSrcweir using namespace ::com::sun::star::registry;
46cdf0e10cSrcweir
SAL_IMPLEMENT_MAIN()47cdf0e10cSrcweir SAL_IMPLEMENT_MAIN()
48cdf0e10cSrcweir {
49cdf0e10cSrcweir try
50cdf0e10cSrcweir {
51cdf0e10cSrcweir
52cdf0e10cSrcweir Reference< XSimpleRegistry > r1 = createSimpleRegistry();
53cdf0e10cSrcweir Reference< XSimpleRegistry > r2 = createSimpleRegistry();
54cdf0e10cSrcweir r1->open( OUString( RTL_CONSTASCII_USTRINGPARAM( "test1.rdb" ) ), sal_True, sal_False );
55cdf0e10cSrcweir r2->open( OUString( RTL_CONSTASCII_USTRINGPARAM( "test2.rdb" ) ), sal_True, sal_False );
56cdf0e10cSrcweir Reference< XSimpleRegistry > r = createNestedRegistry( );
57cdf0e10cSrcweir Reference< XInitialization > rInit( r, UNO_QUERY );
58cdf0e10cSrcweir Sequence< Any > seq( 2 );
59cdf0e10cSrcweir seq[0] <<= r1;
60cdf0e10cSrcweir seq[1] <<= r2;
61cdf0e10cSrcweir rInit->initialize( seq );
62cdf0e10cSrcweir
63cdf0e10cSrcweir Reference< XComponentContext > rComp = bootstrap_InitialComponentContext( r );
64cdf0e10cSrcweir
65cdf0e10cSrcweir Reference< XContentEnumerationAccess > xCtAccess( rComp->getServiceManager(), UNO_QUERY );
66cdf0e10cSrcweir
67cdf0e10cSrcweir Reference< XEnumeration > rEnum =
68cdf0e10cSrcweir xCtAccess->createContentEnumeration( OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.bridge.Bridge" ) ) );
69cdf0e10cSrcweir
70cdf0e10cSrcweir sal_Int32 n = 0;
71cdf0e10cSrcweir while( rEnum->hasMoreElements() )
72cdf0e10cSrcweir {
73cdf0e10cSrcweir Reference< XServiceInfo > r3;
74cdf0e10cSrcweir rEnum->nextElement() >>= r3;
75cdf0e10cSrcweir OString o = OUStringToOString( r3->getImplementationName() , RTL_TEXTENCODING_ASCII_US );
76cdf0e10cSrcweir printf( "%s\n" , o.getStr() );
77cdf0e10cSrcweir Sequence< OUString > seq2 = r3->getSupportedServiceNames();
78cdf0e10cSrcweir for( int i = 0 ;i < seq2.getLength() ; i ++ )
79cdf0e10cSrcweir {
80cdf0e10cSrcweir o = OUStringToOString( seq2[i] , RTL_TEXTENCODING_ASCII_US );
81cdf0e10cSrcweir printf( " %s\n" , o.getStr() );
82cdf0e10cSrcweir }
83cdf0e10cSrcweir n ++;
84cdf0e10cSrcweir }
85cdf0e10cSrcweir // there are two services in two registries !
86cdf0e10cSrcweir OSL_ASSERT( 2 == n );
87cdf0e10cSrcweir if( 2 == n )
88cdf0e10cSrcweir {
89cdf0e10cSrcweir printf( "test passed\n" );
90cdf0e10cSrcweir }
91cdf0e10cSrcweir
92cdf0e10cSrcweir Reference< XComponent > xComp( rComp, UNO_QUERY );
93cdf0e10cSrcweir xComp->dispose();
94cdf0e10cSrcweir try
95cdf0e10cSrcweir {
96cdf0e10cSrcweir xCtAccess->createContentEnumeration(
97cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM( "blabla" ) ) );
98cdf0e10cSrcweir }
99cdf0e10cSrcweir catch (DisposedException &)
100cdf0e10cSrcweir {
101cdf0e10cSrcweir printf( "already disposed results in DisposedException: ok.\n" );
102cdf0e10cSrcweir return 0;
103cdf0e10cSrcweir }
104cdf0e10cSrcweir fprintf( stderr, "missing DisposedException!\n" );
105cdf0e10cSrcweir return 1;
106cdf0e10cSrcweir }
107cdf0e10cSrcweir catch ( Exception & e )
108cdf0e10cSrcweir {
109cdf0e10cSrcweir OString o = OUStringToOString( e.Message , RTL_TEXTENCODING_ASCII_US );
110cdf0e10cSrcweir printf( "%s\n" , o.getStr() );
111cdf0e10cSrcweir OSL_ASSERT( 0 );
112cdf0e10cSrcweir return 1;
113cdf0e10cSrcweir }
114cdf0e10cSrcweir }
115