1*647a425cSAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*647a425cSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*647a425cSAndrew Rist * or more contributor license agreements. See the NOTICE file
5*647a425cSAndrew Rist * distributed with this work for additional information
6*647a425cSAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*647a425cSAndrew Rist * to you under the Apache License, Version 2.0 (the
8*647a425cSAndrew Rist * "License"); you may not use this file except in compliance
9*647a425cSAndrew Rist * with the License. You may obtain a copy of the License at
10*647a425cSAndrew Rist *
11*647a425cSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*647a425cSAndrew Rist *
13*647a425cSAndrew Rist * Unless required by applicable law or agreed to in writing,
14*647a425cSAndrew Rist * software distributed under the License is distributed on an
15*647a425cSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*647a425cSAndrew Rist * KIND, either express or implied. See the License for the
17*647a425cSAndrew Rist * specific language governing permissions and limitations
18*647a425cSAndrew Rist * under the License.
19*647a425cSAndrew Rist *
20*647a425cSAndrew Rist *************************************************************/
21*647a425cSAndrew Rist
22*647a425cSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_stoc.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir #include <stdio.h>
28cdf0e10cSrcweir
29cdf0e10cSrcweir #include <sal/main.h>
30cdf0e10cSrcweir #ifndef _OSL_MODULE_H_
31cdf0e10cSrcweir #include <osl/module.hxx>
32cdf0e10cSrcweir #endif
33cdf0e10cSrcweir #include <osl/diagnose.h>
34cdf0e10cSrcweir
35cdf0e10cSrcweir #include <com/sun/star/loader/XImplementationLoader.hpp>
36cdf0e10cSrcweir #include <com/sun/star/lang/XServiceInfo.hpp>
37cdf0e10cSrcweir #include <com/sun/star/lang/XSingleServiceFactory.hpp>
38cdf0e10cSrcweir #include <com/sun/star/lang/XSingleComponentFactory.hpp>
39cdf0e10cSrcweir
40cdf0e10cSrcweir #include <cppuhelper/implbase1.hxx>
41cdf0e10cSrcweir #include <cppuhelper/factory.hxx>
42cdf0e10cSrcweir
43cdf0e10cSrcweir #if defined ( UNX )
44cdf0e10cSrcweir #include <limits.h>
45cdf0e10cSrcweir #define _MAX_PATH PATH_MAX
46cdf0e10cSrcweir #endif
47cdf0e10cSrcweir
48cdf0e10cSrcweir using namespace com::sun::star::uno;
49cdf0e10cSrcweir using namespace com::sun::star::loader;
50cdf0e10cSrcweir using namespace com::sun::star::lang;
51cdf0e10cSrcweir using namespace osl;
52cdf0e10cSrcweir using namespace rtl;
53cdf0e10cSrcweir using namespace cppu;
54cdf0e10cSrcweir
55cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 0
56cdf0e10cSrcweir #define TEST_ENSHURE(c, m) OSL_ENSURE(c, m)
57cdf0e10cSrcweir #else
58cdf0e10cSrcweir #define TEST_ENSHURE(c, m) OSL_VERIFY(c)
59cdf0e10cSrcweir #endif
60cdf0e10cSrcweir
61cdf0e10cSrcweir class EmptyComponentContext : public WeakImplHelper1< XComponentContext >
62cdf0e10cSrcweir {
63cdf0e10cSrcweir public:
getValueByName(const OUString &)64cdf0e10cSrcweir virtual Any SAL_CALL getValueByName( const OUString& /*Name*/ )
65cdf0e10cSrcweir throw (RuntimeException)
66cdf0e10cSrcweir {
67cdf0e10cSrcweir return Any();
68cdf0e10cSrcweir }
getServiceManager()69cdf0e10cSrcweir virtual Reference< XMultiComponentFactory > SAL_CALL getServiceManager( )
70cdf0e10cSrcweir throw (RuntimeException)
71cdf0e10cSrcweir {
72cdf0e10cSrcweir return Reference< XMultiComponentFactory > ();
73cdf0e10cSrcweir }
74cdf0e10cSrcweir
75cdf0e10cSrcweir };
76cdf0e10cSrcweir
77cdf0e10cSrcweir
SAL_IMPLEMENT_MAIN()78cdf0e10cSrcweir SAL_IMPLEMENT_MAIN()
79cdf0e10cSrcweir {
80cdf0e10cSrcweir Reference<XInterface> xIFace;
81cdf0e10cSrcweir
82cdf0e10cSrcweir Module module;
83cdf0e10cSrcweir
84cdf0e10cSrcweir OUString dllName(
85cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM("bootstrap.uno" SAL_DLLEXTENSION) );
86cdf0e10cSrcweir
87cdf0e10cSrcweir if (module.load(dllName))
88cdf0e10cSrcweir {
89cdf0e10cSrcweir // try to get provider from module
90cdf0e10cSrcweir component_getFactoryFunc pCompFactoryFunc = (component_getFactoryFunc)
91cdf0e10cSrcweir module.getFunctionSymbol( OUString::createFromAscii(COMPONENT_GETFACTORY) );
92cdf0e10cSrcweir
93cdf0e10cSrcweir if (pCompFactoryFunc)
94cdf0e10cSrcweir {
95cdf0e10cSrcweir XSingleServiceFactory * pRet = (XSingleServiceFactory *)(*pCompFactoryFunc)(
96cdf0e10cSrcweir "com.sun.star.comp.stoc.DLLComponentLoader", 0, 0 );
97cdf0e10cSrcweir if (pRet)
98cdf0e10cSrcweir {
99cdf0e10cSrcweir xIFace = pRet;
100cdf0e10cSrcweir pRet->release();
101cdf0e10cSrcweir }
102cdf0e10cSrcweir }
103cdf0e10cSrcweir }
104cdf0e10cSrcweir
105cdf0e10cSrcweir TEST_ENSHURE( xIFace.is(), "testloader error1");
106cdf0e10cSrcweir
107cdf0e10cSrcweir Reference<XSingleComponentFactory> xFactory( Reference<XSingleComponentFactory>::query(xIFace) );
108cdf0e10cSrcweir
109cdf0e10cSrcweir TEST_ENSHURE( xFactory.is(), "testloader error2");
110cdf0e10cSrcweir
111cdf0e10cSrcweir Reference<XInterface> xLoader = xFactory->createInstanceWithContext( new EmptyComponentContext );
112cdf0e10cSrcweir
113cdf0e10cSrcweir TEST_ENSHURE( xLoader.is(), "testloader error3");
114cdf0e10cSrcweir
115cdf0e10cSrcweir Reference<XServiceInfo> xServInfo( Reference<XServiceInfo>::query(xLoader) );
116cdf0e10cSrcweir
117cdf0e10cSrcweir TEST_ENSHURE( xServInfo.is(), "testloader error4");
118cdf0e10cSrcweir
119cdf0e10cSrcweir TEST_ENSHURE( xServInfo->getImplementationName().equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("com.sun.star.comp.stoc.DLLComponentLoader") ), "testloader error5");
120cdf0e10cSrcweir TEST_ENSHURE( xServInfo->supportsService(OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.loader.SharedLibrary")) ), "testloader error6");
121cdf0e10cSrcweir TEST_ENSHURE( xServInfo->getSupportedServiceNames().getLength() == 1, "testloader error7");
122cdf0e10cSrcweir
123cdf0e10cSrcweir xIFace.clear();
124cdf0e10cSrcweir xFactory.clear();
125cdf0e10cSrcweir xLoader.clear();
126cdf0e10cSrcweir xServInfo.clear();
127cdf0e10cSrcweir
128cdf0e10cSrcweir printf("Test Dll ComponentLoader, OK!\n");
129cdf0e10cSrcweir
130cdf0e10cSrcweir return(0);
131cdf0e10cSrcweir }
132cdf0e10cSrcweir
133cdf0e10cSrcweir
134