1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #if !defined(OSL_DEBUG_LEVEL) || OSL_DEBUG_LEVEL == 0
21 # undef OSL_DEBUG_LEVEL
22 # define OSL_DEBUG_LEVEL 2
29 #include <rtl/ustrbuf.hxx>
30 #include <osl/diagnose.h>
32 #include <cppuhelper/component_context.hxx>
33 #include <cppuhelper/servicefactory.hxx>
34 #include <com/sun/star/beans/XPropertySet.hpp>
35 #include <com/sun/star/registry/XSimpleRegistry.hpp>
36 #include <com/sun/star/registry/XImplementationRegistration.hpp>
37 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
38 #include <com/sun/star/lang/XComponent.hpp>
40 #include "testhelper.hxx"
43 using namespace com::sun::star::uno
;
44 using namespace com::sun::star
;
45 using namespace com::sun::star::lang
;
46 using namespace com::sun::star::registry
;
48 using ::rtl::OUString
;
50 using ::rtl::OUStringToOString
;
56 Reference
< XMultiComponentFactory
> xMgr( createRegistryServiceFactory(
57 OUString("cpputest.rdb") ), UNO_QUERY
);
58 Reference
< XComponentContext
> xInitialContext
;
59 OSL_VERIFY( Reference
< beans::XPropertySet
>( xMgr
, UNO_QUERY
)->getPropertyValue(
60 OUString("DefaultContext") ) >>= xInitialContext
);
62 ContextEntry_Init aEntry
;
63 aEntry
.bLateInitService
= false;
64 aEntry
.name
= "bla, bla";
65 aEntry
.value
= makeAny( (sal_Int32
)5 );
66 Reference
< XComponentContext
> xContext( createComponentContext( &aEntry
, 1, xInitialContext
) );
67 OSL_ASSERT( xContext
->getServiceManager() != xMgr
); // must be wrapped one
69 Reference
< beans::XPropertySet
>(
70 xContext
->getServiceManager(), UNO_QUERY
)->getPropertyValue(
71 OUString("DefaultContext") ) != xInitialContext
);
73 Reference
< XMultiServiceFactory
> x( xMgr
, UNO_QUERY
);
75 testPropertyTypeHelper();
77 test_PropertySetHelper();
78 test_interfacecontainer();
80 OSL_VERIFY( xContext
->getValueByName(
81 OUString("bla, bla") ) == (sal_Int32
)5 );
82 OSL_VERIFY( ! xInitialContext
->getValueByName(
83 OUString("bla, bla") ).hasValue() );
84 Reference
< XComponent
>( xInitialContext
, UNO_QUERY
)->dispose();
87 xInitialContext
.clear();
89 catch (Exception
& exc
)
91 OString
cstr_msg( OUStringToOString( exc
.Message
, RTL_TEXTENCODING_ASCII_US
) );
92 OSL_ENSURE( ! "exception occurred: ", cstr_msg
.getStr() );
95 printf( "Test finished\n" );
99 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */