xref: /AOO41X/main/javaunohelper/test/com/sun/star/comp/helper/SharedLibraryLoader_Test.java (revision a5b190bfa3e1bed4623e2958a8877664a3b5506c)
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 package com.sun.star.comp.helper;
25 
26 import com.sun.star.comp.loader.JavaLoader;
27 
28 import com.sun.star.comp.servicemanager.ServiceManager;
29 import com.sun.star.uno.UnoRuntime;
30 
31 import com.sun.star.container.XSet;
32 import com.sun.star.container.XContentEnumerationAccess;
33 import com.sun.star.container.XEnumeration;
34 import com.sun.star.container.XEnumerationAccess;
35 import com.sun.star.container.XElementAccess;
36 
37 import com.sun.star.lang.XComponent;
38 
39 import com.sun.star.lang.XServiceInfo;
40 import com.sun.star.lang.XMultiServiceFactory;
41 import com.sun.star.lang.XSingleServiceFactory;
42 import com.sun.star.lang.XInitialization;
43 
44 import com.sun.star.loader.XImplementationLoader;
45 
46 import com.sun.star.registry.XSimpleRegistry;
47 
48 
49 public class SharedLibraryLoader_Test {
50 
51     private static final String NATIVE_SERVICE_MANAGER_IMP_NAME = "com.sun.star.comp.stoc.OServiceManager";
52     private static final String NATIVE_SERVICE_MANAGER_LIB_NAME = "servicemgr.uno";
53     private static final String NATIVE_REGISTRY_IMP_NAME = "com.sun.star.comp.stoc.SimpleRegistry";
54     private static final String NATIVE_REGISTRY_LIB_NAME = "simplereg.uno";
55 
56     private static XMultiServiceFactory     nativeServiceManager        = null;
57     private static XSingleServiceFactory    sharedLibraryLoaderFactory  = null;
58     private static XImplementationLoader    sharedLibraryLoader         = null;
59     private static XSimpleRegistry          simpleRegistry              = null;
60 
test_getSharedLibraryLoaderFactory()61     static public boolean test_getSharedLibraryLoaderFactory()
62             throws java.lang.Exception
63     {
64         sharedLibraryLoaderFactory = null;
65         System.out.println("*******************************************************************");
66         System.out.println("Test: <<< get SharedLibraryLoader factory >>>");
67         sharedLibraryLoaderFactory = SharedLibraryLoader.getServiceFactory(null, null);
68 
69         System.out.print("Test - ");
70         System.out.println(sharedLibraryLoaderFactory == null? "failed" : "successfull");
71         System.out.println("*******************************************************************");
72         System.out.println();
73 
74         return sharedLibraryLoaderFactory != null;
75     }
76 
test_instantiateSharedLibraryLoader()77     static public boolean test_instantiateSharedLibraryLoader()
78             throws java.lang.Exception
79     {
80         sharedLibraryLoader = null;
81         System.out.println("*******************************************************************");
82         System.out.println("Test: <<< instantiate SharedLibraryLoader >>>");
83         if ( sharedLibraryLoaderFactory == null )
84             if ( ! test_getSharedLibraryLoaderFactory() )
85                 return false;
86 
87         sharedLibraryLoader = UnoRuntime.queryInterface(
88                 XImplementationLoader.class, sharedLibraryLoaderFactory.createInstance() );
89 
90         System.out.print("Test - ");
91         System.out.println(sharedLibraryLoader == null? "failed" : "successfull");
92         System.out.println("*******************************************************************");
93         System.out.println();
94 
95         return sharedLibraryLoader != null;
96     }
97 
test_loadNativeServiceManager()98     static public boolean test_loadNativeServiceManager()
99             throws java.lang.Exception
100     {
101         nativeServiceManager = null;
102 
103         System.out.println("*******************************************************************");
104         System.out.println("Test: <<< load native ServiceManager >>>");
105         if ( sharedLibraryLoader == null )
106             if ( ! test_instantiateSharedLibraryLoader() )
107                 return false;
108 
109         System.err.println("- get the native ServiceManger factory");
110         XSingleServiceFactory aSMgrFac =
111             UnoRuntime.queryInterface( XSingleServiceFactory.class,
112                         sharedLibraryLoader.activate(NATIVE_SERVICE_MANAGER_IMP_NAME, null, NATIVE_SERVICE_MANAGER_LIB_NAME, null));
113 
114         System.err.println("- instantiate the native ServiceManger");
115         nativeServiceManager = UnoRuntime.queryInterface( XMultiServiceFactory.class, aSMgrFac.createInstance() );
116 
117         System.out.print("Test - ");
118         System.out.println(nativeServiceManager == null? "failed" : "successfull");
119 
120         System.out.println("*******************************************************************");
121         System.out.println();
122         return nativeServiceManager != null;
123     }
124 
test_loadNativeSimpleRegistry()125     static public boolean test_loadNativeSimpleRegistry()
126             throws java.lang.Exception
127     {
128         boolean result = false;
129         System.out.println("*******************************************************************");
130         System.out.println("Test: <<< load native SimpleRegistry >>>");
131         if ( sharedLibraryLoader == null )
132             if ( ! test_instantiateSharedLibraryLoader() )
133                 return false;
134 
135         System.err.println("- get factory of the Registry");
136         XSingleServiceFactory aRegFac =
137             UnoRuntime.queryInterface( XSingleServiceFactory.class,
138                         sharedLibraryLoader.activate(NATIVE_REGISTRY_IMP_NAME, null, NATIVE_REGISTRY_LIB_NAME, null)
139             );
140         System.err.println("- instantiate the Registry");
141         simpleRegistry =
142             UnoRuntime.queryInterface( XSimpleRegistry.class, aRegFac.createInstance() );
143         System.out.print("Test - ");
144         System.out.println(simpleRegistry == null? "failed" : "successfull");
145         System.out.println("*******************************************************************");
146         System.err.println();
147         return true;
148     }
149 
test_registerSharedLibraryLoader()150     static public boolean test_registerSharedLibraryLoader()
151             throws java.lang.Exception
152     {
153         boolean result = true;
154         System.out.println("*******************************************************************");
155         System.out.println("Test: <<< register SharedLibraryLoader at the Registry >>>");
156 
157         if ( simpleRegistry == null )
158             if ( ! test_loadNativeSimpleRegistry() )
159                 return false;
160 
161         com.sun.star.registry.XRegistryKey regKey = simpleRegistry.getRootKey();
162         result = SharedLibraryLoader.writeRegistryServiceInfo( null,  regKey );
163 
164         System.out.print("Test - ");
165         System.out.println( result==false ? "failed" : "successfull");
166         System.out.println("*******************************************************************");
167         System.out.println();
168         return result;
169     }
170 
test()171     static public boolean test() throws java.lang.Exception {
172         boolean passed = true;
173 
174         System.err.println("SharedLibraryLoader - doing tests...");
175         passed = test_getSharedLibraryLoaderFactory() && passed;
176         passed = test_instantiateSharedLibraryLoader() && passed;
177         passed = test_loadNativeServiceManager() && passed;
178         passed = test_loadNativeSimpleRegistry() && passed;
179         //passed = test_registerSharedLibraryLoader() && passed;
180 
181         System.err.println("SharedLibraryLoader test passed? " + passed);
182 
183         return passed;
184     }
185 
main(String args[])186     static public void main(String args[]) throws java.lang.Exception {
187         System.exit( test() == true ? 0: -1 );
188     }
189 }
190 
191