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