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