xref: /aoo41x/main/ure/source/uretest/cpptest.cc (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #include "sal/config.h"
29 
30 #include "com/sun/star/uno/Exception.hpp"
31 #include "com/sun/star/uno/Reference.hxx"
32 #include "com/sun/star/uno/RuntimeException.hpp"
33 #include "com/sun/star/uno/Sequence.hxx"
34 #include "com/sun/star/uno/XComponentContext.hpp"
35 #include "com/sun/star/uno/XInterface.hpp"
36 #include "cppuhelper/factory.hxx"
37 #include "cppuhelper/implbase1.hxx"
38 #include "cppuhelper/implementationentry.hxx"
39 #include "cppuhelper/weak.hxx"
40 #include "rtl/ustring.h"
41 #include "rtl/ustring.hxx"
42 #include "sal/types.h"
43 #include "uno/environment.h"
44 #include "uno/lbnames.h"
45 
46 #include "test/types/TestException.hpp"
47 #include "test/types/XTest.hpp"
48 
49 namespace css = com::sun::star;
50 
51 namespace {
52 
53 class Service: public cppu::WeakImplHelper1< test::types::XTest > {
54 public:
55     Service() {}
56 
57     virtual void SAL_CALL throwException()
58         throw (test::types::TestException, css::uno::RuntimeException)
59     {
60         throw test::types::TestException(
61             rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("test")),
62             static_cast< cppu::OWeakObject * >(this));
63     }
64 
65 private:
66     Service(Service &); // not defined
67     void operator =(Service &); // not defined
68 
69     virtual ~Service() {}
70 };
71 
72 namespace CppTest {
73 
74 css::uno::Reference< css::uno::XInterface > create(
75     css::uno::Reference< css::uno::XComponentContext > const &)
76     SAL_THROW((css::uno::Exception))
77 {
78     try {
79         return static_cast< cppu::OWeakObject * >(new Service);
80     } catch (std::bad_alloc &) {
81         throw css::uno::RuntimeException(
82             rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("std::bad_alloc")),
83             css::uno::Reference< css::uno::XInterface >());
84     }
85 }
86 
87 rtl::OUString getImplementationName() {
88     return rtl::OUString(
89         RTL_CONSTASCII_USTRINGPARAM("test.cpp.cpptest.Component"));
90 }
91 
92 css::uno::Sequence< rtl::OUString > getSupportedServiceNames() {
93     rtl::OUString s(RTL_CONSTASCII_USTRINGPARAM("test.types.CppTest"));
94     return css::uno::Sequence< rtl::OUString >(&s, 1);
95 }
96 
97 }
98 
99 cppu::ImplementationEntry entries[] = {
100     { CppTest::create, CppTest::getImplementationName,
101       CppTest::getSupportedServiceNames, cppu::createSingleComponentFactory, 0,
102       0 },
103     { 0, 0, 0, 0, 0, 0 } };
104 
105 }
106 
107 extern "C" sal_Bool SAL_CALL component_writeInfo(
108     void * serviceManager, void * registryKey)
109 {
110     return cppu::component_writeInfoHelper(
111         serviceManager, registryKey, entries);
112 }
113 
114 extern "C" void * SAL_CALL component_getFactory(
115     char const * implName, void * serviceManager, void * registryKey)
116 {
117     return cppu::component_getFactoryHelper(
118         implName, serviceManager, registryKey, entries);
119 }
120 
121 extern "C" void SAL_CALL component_getImplementationEnvironment(
122     char const ** envTypeName, uno_Environment **)
123 {
124     *envTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
125 }
126