testloader.cxx 3.56 KB
Newer Older
1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
Michael Meeks's avatar
Michael Meeks committed
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */
Jens-Heiner Rechtien's avatar
Jens-Heiner Rechtien committed
19

20

Jens-Heiner Rechtien's avatar
Jens-Heiner Rechtien committed
21 22
#include <stdio.h>

23
#include <sal/main.h>
24
#include <osl/module.hxx>
25
#include <osl/diagnose.h>
Jens-Heiner Rechtien's avatar
Jens-Heiner Rechtien committed
26 27 28 29

#include <com/sun/star/loader/XImplementationLoader.hpp>
#include <com/sun/star/lang/XServiceInfo.hpp>
#include <com/sun/star/lang/XSingleServiceFactory.hpp>
30
#include <com/sun/star/lang/XSingleComponentFactory.hpp>
Jens-Heiner Rechtien's avatar
Jens-Heiner Rechtien committed
31

32
#include <cppuhelper/implbase.hxx>
Jens-Heiner Rechtien's avatar
Jens-Heiner Rechtien committed
33 34
#include <cppuhelper/factory.hxx>

35
#if defined ( UNX )
Jens-Heiner Rechtien's avatar
Jens-Heiner Rechtien committed
36 37 38 39
#include <limits.h>
#define _MAX_PATH PATH_MAX
#endif

40 41 42
using namespace css::uno;
using namespace css::loader;
using namespace css::lang;
43
using namespace osl;
44
using namespace cppu;
Jens-Heiner Rechtien's avatar
Jens-Heiner Rechtien committed
45

46

47
class EmptyComponentContext : public WeakImplHelper< XComponentContext >
48 49
{
public:
50
    virtual Any SAL_CALL getValueByName( const OUString& /*Name*/ )
51 52 53 54 55 56 57 58 59 60 61 62 63
        throw (RuntimeException)
        {
            return Any();
        }
    virtual Reference< XMultiComponentFactory > SAL_CALL getServiceManager(  )
        throw (RuntimeException)
        {
            return Reference< XMultiComponentFactory > ();
        }

};


64
SAL_IMPLEMENT_MAIN()
Jens-Heiner Rechtien's avatar
Jens-Heiner Rechtien committed
65 66 67
{
    Reference<XInterface> xIFace;

68
    Module module;
Jens-Heiner Rechtien's avatar
Jens-Heiner Rechtien committed
69

70
    OUString dllName(
71
        "bootstrap.uno" SAL_DLLEXTENSION );
Jens-Heiner Rechtien's avatar
Jens-Heiner Rechtien committed
72

73
    if (module.load(dllName))
Jens-Heiner Rechtien's avatar
Jens-Heiner Rechtien committed
74 75 76
    {
        // try to get provider from module
        component_getFactoryFunc pCompFactoryFunc = (component_getFactoryFunc)
77
            module.getFunctionSymbol( OUString(COMPONENT_GETFACTORY) );
Jens-Heiner Rechtien's avatar
Jens-Heiner Rechtien committed
78 79 80 81 82 83 84 85 86 87 88 89 90

        if (pCompFactoryFunc)
        {
            XSingleServiceFactory * pRet = (XSingleServiceFactory *)(*pCompFactoryFunc)(
                "com.sun.star.comp.stoc.DLLComponentLoader", 0, 0 );
            if (pRet)
            {
                xIFace = pRet;
                pRet->release();
            }
        }
    }

91
    OSL_ENSURE( xIFace.is(), "testloader error1");
Jens-Heiner Rechtien's avatar
Jens-Heiner Rechtien committed
92

93
    Reference<XSingleComponentFactory> xFactory( Reference<XSingleComponentFactory>::query(xIFace) );
Jens-Heiner Rechtien's avatar
Jens-Heiner Rechtien committed
94

95
    OSL_ENSURE( xFactory.is(), "testloader error2");
Jens-Heiner Rechtien's avatar
Jens-Heiner Rechtien committed
96

97
    Reference<XInterface> xLoader = xFactory->createInstanceWithContext( new EmptyComponentContext );
Jens-Heiner Rechtien's avatar
Jens-Heiner Rechtien committed
98

99
    OSL_ENSURE( xLoader.is(), "testloader error3");
Jens-Heiner Rechtien's avatar
Jens-Heiner Rechtien committed
100 101 102

    Reference<XServiceInfo> xServInfo( Reference<XServiceInfo>::query(xLoader) );

103
    OSL_ENSURE( xServInfo.is(), "testloader error4");
Jens-Heiner Rechtien's avatar
Jens-Heiner Rechtien committed
104

105
    OSL_ENSURE( xServInfo->getImplementationName() == "com.sun.star.comp.stoc.DLLComponentLoader", "testloader error5");
106
    OSL_ENSURE( xServInfo->supportsService("com.sun.star.loader.SharedLibrary"), "testloader error6");
107
    OSL_ENSURE( xServInfo->getSupportedServiceNames().getLength() == 1, "testloader error7");
Jens-Heiner Rechtien's avatar
Jens-Heiner Rechtien committed
108 109 110 111 112 113 114 115

    xIFace.clear();
    xFactory.clear();
    xLoader.clear();
    xServInfo.clear();

    printf("Test Dll ComponentLoader, OK!\n");

116
    return 0;
Jens-Heiner Rechtien's avatar
Jens-Heiner Rechtien committed
117 118 119
}


120
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */