Version 4.0.0.1, tag libreoffice-4.0.0.1
[LibreOffice.git] / stoc / test / testsmgr2.cxx
blob58c2bcf20a8fed46cec5c24707257d7337ca8a1a
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <stdio.h>
23 #include <sal/main.h>
24 #include <cppuhelper/bootstrap.hxx>
26 #include <com/sun/star/container/XContentEnumerationAccess.hpp>
27 #include <com/sun/star/lang/XServiceInfo.hpp>
28 #include <com/sun/star/registry/XSimpleRegistry.hpp>
29 #include <com/sun/star/lang/XInitialization.hpp>
30 #include <com/sun/star/lang/DisposedException.hpp>
31 #include <com/sun/star/lang/XComponent.hpp>
32 #include <com/sun/star/uno/XComponentContext.hpp>
34 using namespace ::rtl;
35 using namespace ::cppu;
36 using namespace ::com::sun::star::uno;
37 using namespace ::com::sun::star::lang;
38 using namespace ::com::sun::star::container;
39 using namespace ::com::sun::star::registry;
41 SAL_IMPLEMENT_MAIN()
43 try
46 Reference< XSimpleRegistry > r1 = createSimpleRegistry();
47 Reference< XSimpleRegistry > r2 = createSimpleRegistry();
48 r1->open( OUString( RTL_CONSTASCII_USTRINGPARAM( "test1.rdb" ) ), sal_True, sal_False );
49 r2->open( OUString( RTL_CONSTASCII_USTRINGPARAM( "test2.rdb" ) ), sal_True, sal_False );
50 Reference< XSimpleRegistry > r = createNestedRegistry( );
51 Reference< XInitialization > rInit( r, UNO_QUERY );
52 Sequence< Any > seq( 2 );
53 seq[0] <<= r1;
54 seq[1] <<= r2;
55 rInit->initialize( seq );
57 Reference< XComponentContext > rComp = bootstrap_InitialComponentContext( r );
59 Reference< XContentEnumerationAccess > xCtAccess( rComp->getServiceManager(), UNO_QUERY );
61 Reference< XEnumeration > rEnum =
62 xCtAccess->createContentEnumeration( OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.bridge.Bridge" ) ) );
64 sal_Int32 n = 0;
65 while( rEnum->hasMoreElements() )
67 Reference< XServiceInfo > r3;
68 rEnum->nextElement() >>= r3;
69 OString o = OUStringToOString( r3->getImplementationName() , RTL_TEXTENCODING_ASCII_US );
70 printf( "%s\n" , o.getStr() );
71 Sequence< OUString > seq2 = r3->getSupportedServiceNames();
72 for( int i = 0 ;i < seq2.getLength() ; i ++ )
74 o = OUStringToOString( seq2[i] , RTL_TEXTENCODING_ASCII_US );
75 printf( " %s\n" , o.getStr() );
77 n ++;
79 // there are two services in two registries !
80 OSL_ASSERT( 2 == n );
81 if( 2 == n )
83 printf( "test passed\n" );
86 Reference< XComponent > xComp( rComp, UNO_QUERY );
87 xComp->dispose();
88 try
90 xCtAccess->createContentEnumeration(
91 OUString( RTL_CONSTASCII_USTRINGPARAM( "blabla" ) ) );
93 catch (DisposedException &)
95 printf( "already disposed results in DisposedException: ok.\n" );
96 return 0;
98 fprintf( stderr, "missing DisposedException!\n" );
99 return 1;
101 catch ( const Exception & e )
103 OString o = OUStringToOString( e.Message , RTL_TEXTENCODING_ASCII_US );
104 printf( "%s\n" , o.getStr() );
105 OSL_ASSERT( 0 );
106 return 1;
110 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */