xref: /aoo42x/main/cppuhelper/test/testhelper.cxx (revision 9d7e27ac)
1*9d7e27acSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*9d7e27acSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*9d7e27acSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*9d7e27acSAndrew Rist  * distributed with this work for additional information
6*9d7e27acSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*9d7e27acSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*9d7e27acSAndrew Rist  * "License"); you may not use this file except in compliance
9*9d7e27acSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*9d7e27acSAndrew Rist  *
11*9d7e27acSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*9d7e27acSAndrew Rist  *
13*9d7e27acSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*9d7e27acSAndrew Rist  * software distributed under the License is distributed on an
15*9d7e27acSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*9d7e27acSAndrew Rist  * KIND, either express or implied.  See the License for the
17*9d7e27acSAndrew Rist  * specific language governing permissions and limitations
18*9d7e27acSAndrew Rist  * under the License.
19*9d7e27acSAndrew Rist  *
20*9d7e27acSAndrew Rist  *************************************************************/
21*9d7e27acSAndrew Rist 
22*9d7e27acSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #if !defined(OSL_DEBUG_LEVEL) || OSL_DEBUG_LEVEL == 0
25cdf0e10cSrcweir # undef OSL_DEBUG_LEVEL
26cdf0e10cSrcweir # define OSL_DEBUG_LEVEL 2
27cdf0e10cSrcweir #endif
28cdf0e10cSrcweir 
29cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
30cdf0e10cSrcweir #include "precompiled_cppuhelper.hxx"
31cdf0e10cSrcweir 
32cdf0e10cSrcweir #include <sal/main.h>
33cdf0e10cSrcweir 
34cdf0e10cSrcweir #include <stdio.h>
35cdf0e10cSrcweir #include <rtl/ustrbuf.hxx>
36cdf0e10cSrcweir #include <osl/diagnose.h>
37cdf0e10cSrcweir 
38cdf0e10cSrcweir #include <cppuhelper/component_context.hxx>
39cdf0e10cSrcweir #include <cppuhelper/servicefactory.hxx>
40cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
41cdf0e10cSrcweir #include <com/sun/star/registry/XSimpleRegistry.hpp>
42cdf0e10cSrcweir #include <com/sun/star/registry/XImplementationRegistration.hpp>
43cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp>
44cdf0e10cSrcweir #include <com/sun/star/lang/XComponent.hpp>
45cdf0e10cSrcweir 
46cdf0e10cSrcweir #include "testhelper.hxx"
47cdf0e10cSrcweir 
48cdf0e10cSrcweir using namespace rtl;
49cdf0e10cSrcweir using namespace cppu;
50cdf0e10cSrcweir using namespace com::sun::star::uno;
51cdf0e10cSrcweir using namespace com::sun::star;
52cdf0e10cSrcweir using namespace com::sun::star::lang;
53cdf0e10cSrcweir using namespace com::sun::star::registry;
54cdf0e10cSrcweir 
55cdf0e10cSrcweir SAL_IMPLEMENT_MAIN()
56cdf0e10cSrcweir {
57cdf0e10cSrcweir     try
58cdf0e10cSrcweir     {
59cdf0e10cSrcweir         Reference< XMultiComponentFactory > xMgr( createRegistryServiceFactory(
60cdf0e10cSrcweir                                                       OUString( RTL_CONSTASCII_USTRINGPARAM("cpputest.rdb") ) ), UNO_QUERY );
61cdf0e10cSrcweir         Reference< XComponentContext > xInitialContext;
62cdf0e10cSrcweir         OSL_VERIFY( Reference< beans::XPropertySet >( xMgr, UNO_QUERY )->getPropertyValue(
63cdf0e10cSrcweir                         OUString( RTL_CONSTASCII_USTRINGPARAM("DefaultContext") ) ) >>= xInitialContext );
64cdf0e10cSrcweir 
65cdf0e10cSrcweir         ContextEntry_Init aEntry;
66cdf0e10cSrcweir         aEntry.bLateInitService = false;
67cdf0e10cSrcweir         aEntry.name = OUString( RTL_CONSTASCII_USTRINGPARAM("bla, bla") );
68cdf0e10cSrcweir         aEntry.value = makeAny( (sal_Int32)5 );
69cdf0e10cSrcweir         Reference< XComponentContext > xContext( createComponentContext( &aEntry, 1, xInitialContext ) );
70cdf0e10cSrcweir         OSL_ASSERT( xContext->getServiceManager() != xMgr ); // must be wrapped one
71cdf0e10cSrcweir         OSL_ASSERT(
72cdf0e10cSrcweir             Reference< beans::XPropertySet >(
73cdf0e10cSrcweir                 xContext->getServiceManager(), UNO_QUERY )->getPropertyValue(
74cdf0e10cSrcweir                     OUString( RTL_CONSTASCII_USTRINGPARAM("DefaultContext") ) ) != xInitialContext );
75cdf0e10cSrcweir 
76cdf0e10cSrcweir         Reference< XMultiServiceFactory > x( xMgr, UNO_QUERY );
77cdf0e10cSrcweir 		test_ImplHelper( x );
78cdf0e10cSrcweir 		testPropertyTypeHelper();
79cdf0e10cSrcweir 		testidlclass( x );
80cdf0e10cSrcweir  		test_PropertySetHelper();
81cdf0e10cSrcweir 		test_interfacecontainer();
82cdf0e10cSrcweir 
83cdf0e10cSrcweir         OSL_VERIFY( xContext->getValueByName(
84cdf0e10cSrcweir                         OUString( RTL_CONSTASCII_USTRINGPARAM("bla, bla") ) ) == (sal_Int32)5 );
85cdf0e10cSrcweir         OSL_VERIFY( ! xInitialContext->getValueByName(
86cdf0e10cSrcweir                         OUString( RTL_CONSTASCII_USTRINGPARAM("bla, bla") ) ).hasValue() );
87cdf0e10cSrcweir         Reference< XComponent >( xInitialContext, UNO_QUERY )->dispose();
88cdf0e10cSrcweir         xMgr.clear();
89cdf0e10cSrcweir         xContext.clear();
90cdf0e10cSrcweir 		xInitialContext.clear();
91cdf0e10cSrcweir     }
92cdf0e10cSrcweir     catch (Exception & exc)
93cdf0e10cSrcweir     {
94cdf0e10cSrcweir         OString cstr_msg( OUStringToOString( exc.Message, RTL_TEXTENCODING_ASCII_US ) );
95cdf0e10cSrcweir         OSL_ENSURE( ! "exception occured: ", cstr_msg.getStr() );
96cdf0e10cSrcweir     }
97cdf0e10cSrcweir 
98cdf0e10cSrcweir 	printf( "Test finished\n" );
99cdf0e10cSrcweir 	return 0;
100cdf0e10cSrcweir }
101