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