Version 5.2.6.1, tag libreoffice-5.2.6.1
[LibreOffice.git] / ure / source / uretest / cppserver.cc
blob69b33c3b9f6a44cec6f855b491957512ac66f302
1 /*
2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 #include "sal/config.h"
21 #include <new>
23 #include "com/sun/star/uno/Exception.hpp"
24 #include "com/sun/star/uno/Reference.hxx"
25 #include "com/sun/star/uno/RuntimeException.hpp"
26 #include "com/sun/star/uno/Sequence.hxx"
27 #include "com/sun/star/uno/XComponentContext.hpp"
28 #include "com/sun/star/uno/XInterface.hpp"
29 #include "cppuhelper/factory.hxx"
30 #include "cppuhelper/implbase1.hxx"
31 #include "cppuhelper/implementationentry.hxx"
32 #include "cppuhelper/weak.hxx"
33 #include "rtl/ustring.h"
34 #include "rtl/ustring.hxx"
35 #include "sal/types.h"
36 #include "uno/environment.h"
38 #include "test/types/Data.hpp"
39 #include "test/types/XServer.hpp"
41 namespace {
43 class Service: public ::cppu::WeakImplHelper1< ::test::types::XServer > {
44 public:
45 Service() {}
47 virtual ::test::types::Data SAL_CALL getData()
48 throw (css::uno::RuntimeException)
50 return ::test::types::Data(rtl::OUString("Hello"), 42);
53 private:
54 Service(Service &); // not defined
55 void operator =(Service &); // not defined
57 virtual ~Service() {}
60 namespace CppServer {
62 css::uno::Reference< css::uno::XInterface > create(
63 css::uno::Reference< css::uno::XComponentContext > const &)
65 try {
66 return static_cast< ::cppu::OWeakObject * >(new Service);
67 } catch (::std::bad_alloc &) {
68 throw css::uno::RuntimeException("std::bad_alloc");
72 rtl::OUString getImplementationName() {
73 return rtl::OUString("test.cpp.cppserver.Component");
76 css::uno::Sequence< rtl::OUString > getSupportedServiceNames() {
77 return css::uno::Sequence< rtl::OUString >();
82 ::cppu::ImplementationEntry entries[] = {
83 { CppServer::create, CppServer::getImplementationName,
84 CppServer::getSupportedServiceNames, ::cppu::createSingleComponentFactory,
85 0, 0 },
86 { 0, 0, 0, 0, 0, 0 } };
90 extern "C" SAL_DLLPUBLIC_EXPORT ::sal_Bool SAL_CALL component_writeInfo(
91 void * serviceManager, void * registryKey)
93 return ::cppu::component_writeInfoHelper(
94 serviceManager, registryKey, entries);
97 extern "C" SAL_DLLPUBLIC_EXPORT void * SAL_CALL component_getFactory(
98 char const * implName, void * serviceManager, void * registryKey)
100 return ::cppu::component_getFactoryHelper(
101 implName, serviceManager, registryKey, entries);