19d7e27acSAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
39d7e27acSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
49d7e27acSAndrew Rist * or more contributor license agreements. See the NOTICE file
59d7e27acSAndrew Rist * distributed with this work for additional information
69d7e27acSAndrew Rist * regarding copyright ownership. The ASF licenses this file
79d7e27acSAndrew Rist * to you under the Apache License, Version 2.0 (the
89d7e27acSAndrew Rist * "License"); you may not use this file except in compliance
99d7e27acSAndrew Rist * with the License. You may obtain a copy of the License at
109d7e27acSAndrew Rist *
119d7e27acSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
129d7e27acSAndrew Rist *
139d7e27acSAndrew Rist * Unless required by applicable law or agreed to in writing,
149d7e27acSAndrew Rist * software distributed under the License is distributed on an
159d7e27acSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
169d7e27acSAndrew Rist * KIND, either express or implied. See the License for the
179d7e27acSAndrew Rist * specific language governing permissions and limitations
189d7e27acSAndrew Rist * under the License.
199d7e27acSAndrew Rist *
209d7e27acSAndrew Rist *************************************************************/
219d7e27acSAndrew Rist
229d7e27acSAndrew 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
SAL_IMPLEMENT_MAIN()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 ) );
95*07a3d7f1SPedro Giffuni OSL_ENSURE( ! "exception occurred: ", cstr_msg.getStr() );
96cdf0e10cSrcweir }
97cdf0e10cSrcweir
98cdf0e10cSrcweir printf( "Test finished\n" );
99cdf0e10cSrcweir return 0;
100cdf0e10cSrcweir }
101