Version 4.0.0.1, tag libreoffice-4.0.0.1
[LibreOffice.git] / stoc / test / testloader.cxx
blob44af57bf4caeee0241b455aa1136397e6e670948
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 <stdio.h>
23 #include <sal/main.h>
24 #include <osl/module.hxx>
25 #include <osl/diagnose.h>
27 #include <com/sun/star/loader/XImplementationLoader.hpp>
28 #include <com/sun/star/lang/XServiceInfo.hpp>
29 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
30 #include <com/sun/star/lang/XSingleComponentFactory.hpp>
32 #include <cppuhelper/implbase1.hxx>
33 #include <cppuhelper/factory.hxx>
35 #if defined ( UNX )
36 #include <limits.h>
37 #define _MAX_PATH PATH_MAX
38 #endif
40 using namespace com::sun::star::uno;
41 using namespace com::sun::star::loader;
42 using namespace com::sun::star::lang;
43 using namespace osl;
44 using namespace cppu;
46 using ::rtl::OUString;
48 class EmptyComponentContext : public WeakImplHelper1< XComponentContext >
50 public:
51 virtual Any SAL_CALL getValueByName( const OUString& /*Name*/ )
52 throw (RuntimeException)
54 return Any();
56 virtual Reference< XMultiComponentFactory > SAL_CALL getServiceManager( )
57 throw (RuntimeException)
59 return Reference< XMultiComponentFactory > ();
65 SAL_IMPLEMENT_MAIN()
67 Reference<XInterface> xIFace;
69 Module module;
71 OUString dllName(
72 "bootstrap.uno" SAL_DLLEXTENSION );
74 if (module.load(dllName))
76 // try to get provider from module
77 component_getFactoryFunc pCompFactoryFunc = (component_getFactoryFunc)
78 module.getFunctionSymbol( OUString(COMPONENT_GETFACTORY) );
80 if (pCompFactoryFunc)
82 XSingleServiceFactory * pRet = (XSingleServiceFactory *)(*pCompFactoryFunc)(
83 "com.sun.star.comp.stoc.DLLComponentLoader", 0, 0 );
84 if (pRet)
86 xIFace = pRet;
87 pRet->release();
92 OSL_ENSURE( xIFace.is(), "testloader error1");
94 Reference<XSingleComponentFactory> xFactory( Reference<XSingleComponentFactory>::query(xIFace) );
96 OSL_ENSURE( xFactory.is(), "testloader error2");
98 Reference<XInterface> xLoader = xFactory->createInstanceWithContext( new EmptyComponentContext );
100 OSL_ENSURE( xLoader.is(), "testloader error3");
102 Reference<XServiceInfo> xServInfo( Reference<XServiceInfo>::query(xLoader) );
104 OSL_ENSURE( xServInfo.is(), "testloader error4");
106 OSL_ENSURE( xServInfo->getImplementationName() == "com.sun.star.comp.stoc.DLLComponentLoader", "testloader error5");
107 OSL_ENSURE( xServInfo->supportsService(OUString( "com.sun.star.loader.SharedLibrary") ), "testloader error6");
108 OSL_ENSURE( xServInfo->getSupportedServiceNames().getLength() == 1, "testloader error7");
110 xIFace.clear();
111 xFactory.clear();
112 xLoader.clear();
113 xServInfo.clear();
115 printf("Test Dll ComponentLoader, OK!\n");
117 return(0);
121 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */