update dev300-m58
[ooovba.git] / stoc / test / testsmgr2.cxx
blob56387cbcd24820c14aac32651722000c6504a8cb
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: testsmgr2.cxx,v $
10 * $Revision: 1.7.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 ************************************************************************/
32 // MARKER(update_precomp.py): autogen include statement, do not remove
33 #include "precompiled_stoc.hxx"
34 #include <stdio.h>
36 #include <sal/main.h>
37 #include <cppuhelper/bootstrap.hxx>
39 #include <com/sun/star/container/XContentEnumerationAccess.hpp>
40 #include <com/sun/star/lang/XServiceInfo.hpp>
41 #include <com/sun/star/registry/XSimpleRegistry.hpp>
42 #include <com/sun/star/lang/XInitialization.hpp>
43 #include <com/sun/star/lang/DisposedException.hpp>
44 #include <com/sun/star/lang/XComponent.hpp>
45 #include <com/sun/star/uno/XComponentContext.hpp>
47 using namespace ::rtl;
48 using namespace ::cppu;
49 using namespace ::com::sun::star::uno;
50 using namespace ::com::sun::star::lang;
51 using namespace ::com::sun::star::container;
52 using namespace ::com::sun::star::registry;
54 SAL_IMPLEMENT_MAIN()
56 try
59 Reference< XSimpleRegistry > r1 = createSimpleRegistry();
60 Reference< XSimpleRegistry > r2 = createSimpleRegistry();
61 r1->open( OUString( RTL_CONSTASCII_USTRINGPARAM( "test1.rdb" ) ), sal_True, sal_False );
62 r2->open( OUString( RTL_CONSTASCII_USTRINGPARAM( "test2.rdb" ) ), sal_True, sal_False );
63 Reference< XSimpleRegistry > r = createNestedRegistry( );
64 Reference< XInitialization > rInit( r, UNO_QUERY );
65 Sequence< Any > seq( 2 );
66 seq[0] <<= r1;
67 seq[1] <<= r2;
68 rInit->initialize( seq );
70 Reference< XComponentContext > rComp = bootstrap_InitialComponentContext( r );
72 Reference< XContentEnumerationAccess > xCtAccess( rComp->getServiceManager(), UNO_QUERY );
74 Reference< XEnumeration > rEnum =
75 xCtAccess->createContentEnumeration( OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.bridge.Bridge" ) ) );
77 sal_Int32 n = 0;
78 while( rEnum->hasMoreElements() )
80 Reference< XServiceInfo > r3;
81 rEnum->nextElement() >>= r3;
82 OString o = OUStringToOString( r3->getImplementationName() , RTL_TEXTENCODING_ASCII_US );
83 printf( "%s\n" , o.getStr() );
84 Sequence< OUString > seq2 = r3->getSupportedServiceNames();
85 for( int i = 0 ;i < seq2.getLength() ; i ++ )
87 o = OUStringToOString( seq2[i] , RTL_TEXTENCODING_ASCII_US );
88 printf( " %s\n" , o.getStr() );
90 n ++;
92 // there are two services in two registries !
93 OSL_ASSERT( 2 == n );
94 if( 2 == n )
96 printf( "test passed\n" );
99 Reference< XComponent > xComp( rComp, UNO_QUERY );
100 xComp->dispose();
103 xCtAccess->createContentEnumeration(
104 OUString( RTL_CONSTASCII_USTRINGPARAM( "blabla" ) ) );
106 catch (DisposedException &)
108 printf( "already disposed results in DisposedException: ok.\n" );
109 return 0;
111 fprintf( stderr, "missing DisposedException!\n" );
112 return 1;
114 catch ( Exception & e )
116 OString o = OUStringToOString( e.Message , RTL_TEXTENCODING_ASCII_US );
117 printf( "%s\n" , o.getStr() );
118 OSL_ASSERT( 0 );
119 return 1;