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