1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 29 // MARKER(update_precomp.py): autogen include statement, do not remove 30 #include "precompiled_stoc.hxx" 31 #include <stdio.h> 32 33 #include <sal/main.h> 34 #include <cppuhelper/bootstrap.hxx> 35 36 #include <com/sun/star/container/XContentEnumerationAccess.hpp> 37 #include <com/sun/star/lang/XServiceInfo.hpp> 38 #include <com/sun/star/registry/XSimpleRegistry.hpp> 39 #include <com/sun/star/lang/XInitialization.hpp> 40 #include <com/sun/star/lang/DisposedException.hpp> 41 #include <com/sun/star/lang/XComponent.hpp> 42 #include <com/sun/star/uno/XComponentContext.hpp> 43 44 using namespace ::rtl; 45 using namespace ::cppu; 46 using namespace ::com::sun::star::uno; 47 using namespace ::com::sun::star::lang; 48 using namespace ::com::sun::star::container; 49 using namespace ::com::sun::star::registry; 50 51 SAL_IMPLEMENT_MAIN() 52 { 53 try 54 { 55 56 Reference< XSimpleRegistry > r1 = createSimpleRegistry(); 57 Reference< XSimpleRegistry > r2 = createSimpleRegistry(); 58 r1->open( OUString( RTL_CONSTASCII_USTRINGPARAM( "test1.rdb" ) ), sal_True, sal_False ); 59 r2->open( OUString( RTL_CONSTASCII_USTRINGPARAM( "test2.rdb" ) ), sal_True, sal_False ); 60 Reference< XSimpleRegistry > r = createNestedRegistry( ); 61 Reference< XInitialization > rInit( r, UNO_QUERY ); 62 Sequence< Any > seq( 2 ); 63 seq[0] <<= r1; 64 seq[1] <<= r2; 65 rInit->initialize( seq ); 66 67 Reference< XComponentContext > rComp = bootstrap_InitialComponentContext( r ); 68 69 Reference< XContentEnumerationAccess > xCtAccess( rComp->getServiceManager(), UNO_QUERY ); 70 71 Reference< XEnumeration > rEnum = 72 xCtAccess->createContentEnumeration( OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.bridge.Bridge" ) ) ); 73 74 sal_Int32 n = 0; 75 while( rEnum->hasMoreElements() ) 76 { 77 Reference< XServiceInfo > r3; 78 rEnum->nextElement() >>= r3; 79 OString o = OUStringToOString( r3->getImplementationName() , RTL_TEXTENCODING_ASCII_US ); 80 printf( "%s\n" , o.getStr() ); 81 Sequence< OUString > seq2 = r3->getSupportedServiceNames(); 82 for( int i = 0 ;i < seq2.getLength() ; i ++ ) 83 { 84 o = OUStringToOString( seq2[i] , RTL_TEXTENCODING_ASCII_US ); 85 printf( " %s\n" , o.getStr() ); 86 } 87 n ++; 88 } 89 // there are two services in two registries ! 90 OSL_ASSERT( 2 == n ); 91 if( 2 == n ) 92 { 93 printf( "test passed\n" ); 94 } 95 96 Reference< XComponent > xComp( rComp, UNO_QUERY ); 97 xComp->dispose(); 98 try 99 { 100 xCtAccess->createContentEnumeration( 101 OUString( RTL_CONSTASCII_USTRINGPARAM( "blabla" ) ) ); 102 } 103 catch (DisposedException &) 104 { 105 printf( "already disposed results in DisposedException: ok.\n" ); 106 return 0; 107 } 108 fprintf( stderr, "missing DisposedException!\n" ); 109 return 1; 110 } 111 catch ( Exception & e ) 112 { 113 OString o = OUStringToOString( e.Message , RTL_TEXTENCODING_ASCII_US ); 114 printf( "%s\n" , o.getStr() ); 115 OSL_ASSERT( 0 ); 116 return 1; 117 } 118 } 119