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