cURL: follow redirects
[LibreOffice.git] / cppuhelper / test / testlib / defbootstrap_lib.cxx
blob26d229f689d7b3545188f67836fe181f4c43b5e5
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 .
21 #include "EXTERN.h"
22 #include "perl.h"
23 #include "XSUB.h"
25 #include <cstdio>
27 #include <osl/module.hxx>
28 #include <rtl/process.h>
29 #include <cppuhelper/bootstrap.hxx>
31 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
33 using namespace ::cppu;
34 using namespace ::com::sun::star::lang;
35 using namespace ::com::sun::star::uno;
37 static sal_Bool tryService(const char * serviceName)
39 // use micro deployment to create initial context
40 OUString libraryFileUrl;
41 ::osl::Module::getUrlFromAddress((void *)tryService, libraryFileUrl);
43 OUString iniName = libraryFileUrl.copy(0, libraryFileUrl.lastIndexOf((sal_Unicode)'.')); // cut the library extension
44 iniName += SAL_CONFIGFILE(""); // add the rc file extension
46 SAL_INFO("cppuhelper", "using ini: " << iniName);
48 sal_Bool result = sal_True;
50 try {
51 Reference<XComponentContext> xComponentContext = defaultBootstrap_InitialComponentContext(iniName);
52 Reference<XMultiServiceFactory> smgr(xComponentContext->getServiceManager(), UNO_QUERY);
54 OUString arg = OUString::createFromAscii(serviceName);
55 Reference<XInterface> xInterface = smgr->createInstance(arg);
57 SAL_INFO("cppuhelper", "got the " << serviceName << " service " << xInterface.get());
58 result = result && (xInterface.get() != 0);
60 catch(Exception & exception) {
61 OString message = OUStringToOString(exception.Message, RTL_TEXTENCODING_ASCII_US);
63 fprintf(stderr, "an exception occurred: %s\n", message.getStr());
66 SAL_INFO("cppuhelper", "---------------------------------- " << result);
68 return result;
71 XS(XS_UNO_tryService)
73 dXSARGS;
74 if (items != 1)
75 Perl_croak(aTHX_ "Usage: UNO::tryService(input)");
77 const char * input = (const char *)SvPV(ST(0),PL_na);
78 int RETVAL;
79 dXSTARG;
81 RETVAL = tryService(input);
82 XSprePUSH; PUSHi((IV)RETVAL);
84 XSRETURN(1);
87 extern "C" {
88 XS(boot_UNO)
90 dXSARGS;
91 char* file = __FILE__;
93 /* XS_VERSION_BOOTCHECK ;*/
95 newXS("UNO::tryService", XS_UNO_tryService, file);
96 XSRETURN_YES;
101 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */