Branch libreoffice-5-0-4
[LibreOffice.git] / cppuhelper / test / testhelper.cxx
blob0fbd0caf96aa908f9e19884b10dba44dcd76daa4
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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
23 #endif
26 #include <sal/main.h>
28 #include <stdio.h>
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"
42 using namespace cppu;
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;
49 using ::rtl::OString;
50 using ::rtl::OUStringToOString;
52 SAL_IMPLEMENT_MAIN()
54 try
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
68 OSL_ASSERT(
69 Reference< beans::XPropertySet >(
70 xContext->getServiceManager(), UNO_QUERY )->getPropertyValue(
71 OUString("DefaultContext") ) != xInitialContext );
73 Reference< XMultiServiceFactory > x( xMgr, UNO_QUERY );
74 test_ImplHelper( x );
75 testPropertyTypeHelper();
76 testidlclass( x );
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();
85 xMgr.clear();
86 xContext.clear();
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" );
96 return 0;
99 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */