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 #if !defined(OSL_DEBUG_LEVEL) || OSL_DEBUG_LEVEL == 0 29 # undef OSL_DEBUG_LEVEL 30 # define OSL_DEBUG_LEVEL 2 31 #endif 32 33 // MARKER(update_precomp.py): autogen include statement, do not remove 34 #include "precompiled_cppuhelper.hxx" 35 36 #include <sal/main.h> 37 38 #include <stdio.h> 39 #include <rtl/ustrbuf.hxx> 40 #include <osl/diagnose.h> 41 42 #include <cppuhelper/component_context.hxx> 43 #include <cppuhelper/servicefactory.hxx> 44 #include <com/sun/star/beans/XPropertySet.hpp> 45 #include <com/sun/star/registry/XSimpleRegistry.hpp> 46 #include <com/sun/star/registry/XImplementationRegistration.hpp> 47 #include <com/sun/star/lang/XMultiServiceFactory.hpp> 48 #include <com/sun/star/lang/XComponent.hpp> 49 50 #include "testhelper.hxx" 51 52 using namespace rtl; 53 using namespace cppu; 54 using namespace com::sun::star::uno; 55 using namespace com::sun::star; 56 using namespace com::sun::star::lang; 57 using namespace com::sun::star::registry; 58 59 SAL_IMPLEMENT_MAIN() 60 { 61 try 62 { 63 Reference< XMultiComponentFactory > xMgr( createRegistryServiceFactory( 64 OUString( RTL_CONSTASCII_USTRINGPARAM("cpputest.rdb") ) ), UNO_QUERY ); 65 Reference< XComponentContext > xInitialContext; 66 OSL_VERIFY( Reference< beans::XPropertySet >( xMgr, UNO_QUERY )->getPropertyValue( 67 OUString( RTL_CONSTASCII_USTRINGPARAM("DefaultContext") ) ) >>= xInitialContext ); 68 69 ContextEntry_Init aEntry; 70 aEntry.bLateInitService = false; 71 aEntry.name = OUString( RTL_CONSTASCII_USTRINGPARAM("bla, bla") ); 72 aEntry.value = makeAny( (sal_Int32)5 ); 73 Reference< XComponentContext > xContext( createComponentContext( &aEntry, 1, xInitialContext ) ); 74 OSL_ASSERT( xContext->getServiceManager() != xMgr ); // must be wrapped one 75 OSL_ASSERT( 76 Reference< beans::XPropertySet >( 77 xContext->getServiceManager(), UNO_QUERY )->getPropertyValue( 78 OUString( RTL_CONSTASCII_USTRINGPARAM("DefaultContext") ) ) != xInitialContext ); 79 80 Reference< XMultiServiceFactory > x( xMgr, UNO_QUERY ); 81 test_ImplHelper( x ); 82 testPropertyTypeHelper(); 83 testidlclass( x ); 84 test_PropertySetHelper(); 85 test_interfacecontainer(); 86 87 OSL_VERIFY( xContext->getValueByName( 88 OUString( RTL_CONSTASCII_USTRINGPARAM("bla, bla") ) ) == (sal_Int32)5 ); 89 OSL_VERIFY( ! xInitialContext->getValueByName( 90 OUString( RTL_CONSTASCII_USTRINGPARAM("bla, bla") ) ).hasValue() ); 91 Reference< XComponent >( xInitialContext, UNO_QUERY )->dispose(); 92 xMgr.clear(); 93 xContext.clear(); 94 xInitialContext.clear(); 95 } 96 catch (Exception & exc) 97 { 98 OString cstr_msg( OUStringToOString( exc.Message, RTL_TEXTENCODING_ASCII_US ) ); 99 OSL_ENSURE( ! "exception occured: ", cstr_msg.getStr() ); 100 } 101 102 printf( "Test finished\n" ); 103 return 0; 104 } 105