xref: /AOO41X/main/javaunohelper/test/com/sun/star/comp/helper/SharedLibraryLoader_Test.java (revision a5b190bfa3e1bed4623e2958a8877664a3b5506c)
1*a5b190bfSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*a5b190bfSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*a5b190bfSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*a5b190bfSAndrew Rist  * distributed with this work for additional information
6*a5b190bfSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*a5b190bfSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*a5b190bfSAndrew Rist  * "License"); you may not use this file except in compliance
9*a5b190bfSAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*a5b190bfSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*a5b190bfSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*a5b190bfSAndrew Rist  * software distributed under the License is distributed on an
15*a5b190bfSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*a5b190bfSAndrew Rist  * KIND, either express or implied.  See the License for the
17*a5b190bfSAndrew Rist  * specific language governing permissions and limitations
18*a5b190bfSAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*a5b190bfSAndrew Rist  *************************************************************/
21*a5b190bfSAndrew Rist 
22*a5b190bfSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir package com.sun.star.comp.helper;
25cdf0e10cSrcweir 
26cdf0e10cSrcweir import com.sun.star.comp.loader.JavaLoader;
27cdf0e10cSrcweir 
28cdf0e10cSrcweir import com.sun.star.comp.servicemanager.ServiceManager;
29cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime;
30cdf0e10cSrcweir 
31cdf0e10cSrcweir import com.sun.star.container.XSet;
32cdf0e10cSrcweir import com.sun.star.container.XContentEnumerationAccess;
33cdf0e10cSrcweir import com.sun.star.container.XEnumeration;
34cdf0e10cSrcweir import com.sun.star.container.XEnumerationAccess;
35cdf0e10cSrcweir import com.sun.star.container.XElementAccess;
36cdf0e10cSrcweir 
37cdf0e10cSrcweir import com.sun.star.lang.XComponent;
38cdf0e10cSrcweir 
39cdf0e10cSrcweir import com.sun.star.lang.XServiceInfo;
40cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory;
41cdf0e10cSrcweir import com.sun.star.lang.XSingleServiceFactory;
42cdf0e10cSrcweir import com.sun.star.lang.XInitialization;
43cdf0e10cSrcweir 
44cdf0e10cSrcweir import com.sun.star.loader.XImplementationLoader;
45cdf0e10cSrcweir 
46cdf0e10cSrcweir import com.sun.star.registry.XSimpleRegistry;
47cdf0e10cSrcweir 
48cdf0e10cSrcweir 
49cdf0e10cSrcweir public class SharedLibraryLoader_Test {
50cdf0e10cSrcweir 
51cdf0e10cSrcweir 	private static final String NATIVE_SERVICE_MANAGER_IMP_NAME = "com.sun.star.comp.stoc.OServiceManager";
52cdf0e10cSrcweir 	private static final String NATIVE_SERVICE_MANAGER_LIB_NAME = "servicemgr.uno";
53cdf0e10cSrcweir 	private static final String NATIVE_REGISTRY_IMP_NAME = "com.sun.star.comp.stoc.SimpleRegistry";
54cdf0e10cSrcweir 	private static final String NATIVE_REGISTRY_LIB_NAME = "simplereg.uno";
55cdf0e10cSrcweir 
56cdf0e10cSrcweir 	private static XMultiServiceFactory		nativeServiceManager		= null;
57cdf0e10cSrcweir 	private static XSingleServiceFactory 	sharedLibraryLoaderFactory 	= null;
58cdf0e10cSrcweir 	private static XImplementationLoader 	sharedLibraryLoader			= null;
59cdf0e10cSrcweir 	private static XSimpleRegistry			simpleRegistry				= null;
60cdf0e10cSrcweir 
test_getSharedLibraryLoaderFactory()61cdf0e10cSrcweir 	static public boolean test_getSharedLibraryLoaderFactory()
62cdf0e10cSrcweir 			throws java.lang.Exception
63cdf0e10cSrcweir 	{
64cdf0e10cSrcweir 		sharedLibraryLoaderFactory = null;
65cdf0e10cSrcweir 		System.out.println("*******************************************************************");
66cdf0e10cSrcweir 		System.out.println("Test: <<< get SharedLibraryLoader factory >>>");
67cdf0e10cSrcweir 		sharedLibraryLoaderFactory = SharedLibraryLoader.getServiceFactory(null, null);
68cdf0e10cSrcweir 
69cdf0e10cSrcweir 		System.out.print("Test - ");
70cdf0e10cSrcweir 		System.out.println(sharedLibraryLoaderFactory == null? "failed" : "successfull");
71cdf0e10cSrcweir 		System.out.println("*******************************************************************");
72cdf0e10cSrcweir 		System.out.println();
73cdf0e10cSrcweir 
74cdf0e10cSrcweir 		return sharedLibraryLoaderFactory != null;
75cdf0e10cSrcweir 	}
76cdf0e10cSrcweir 
test_instantiateSharedLibraryLoader()77cdf0e10cSrcweir 	static public boolean test_instantiateSharedLibraryLoader()
78cdf0e10cSrcweir 			throws java.lang.Exception
79cdf0e10cSrcweir 	{
80cdf0e10cSrcweir 		sharedLibraryLoader = null;
81cdf0e10cSrcweir 		System.out.println("*******************************************************************");
82cdf0e10cSrcweir 		System.out.println("Test: <<< instantiate SharedLibraryLoader >>>");
83cdf0e10cSrcweir 		if ( sharedLibraryLoaderFactory == null )
84cdf0e10cSrcweir 			if ( ! test_getSharedLibraryLoaderFactory() )
85cdf0e10cSrcweir 				return false;
86cdf0e10cSrcweir 
87cdf0e10cSrcweir 		sharedLibraryLoader = UnoRuntime.queryInterface(
88cdf0e10cSrcweir 				XImplementationLoader.class, sharedLibraryLoaderFactory.createInstance() );
89cdf0e10cSrcweir 
90cdf0e10cSrcweir 		System.out.print("Test - ");
91cdf0e10cSrcweir 		System.out.println(sharedLibraryLoader == null? "failed" : "successfull");
92cdf0e10cSrcweir 		System.out.println("*******************************************************************");
93cdf0e10cSrcweir 		System.out.println();
94cdf0e10cSrcweir 
95cdf0e10cSrcweir 		return sharedLibraryLoader != null;
96cdf0e10cSrcweir 	}
97cdf0e10cSrcweir 
test_loadNativeServiceManager()98cdf0e10cSrcweir 	static public boolean test_loadNativeServiceManager()
99cdf0e10cSrcweir 			throws java.lang.Exception
100cdf0e10cSrcweir 	{
101cdf0e10cSrcweir 		nativeServiceManager = null;
102cdf0e10cSrcweir 
103cdf0e10cSrcweir 		System.out.println("*******************************************************************");
104cdf0e10cSrcweir 		System.out.println("Test: <<< load native ServiceManager >>>");
105cdf0e10cSrcweir 		if ( sharedLibraryLoader == null )
106cdf0e10cSrcweir 			if ( ! test_instantiateSharedLibraryLoader() )
107cdf0e10cSrcweir 				return false;
108cdf0e10cSrcweir 
109cdf0e10cSrcweir 		System.err.println("- get the native ServiceManger factory");
110cdf0e10cSrcweir 		XSingleServiceFactory aSMgrFac =
111cdf0e10cSrcweir 			UnoRuntime.queryInterface( XSingleServiceFactory.class,
112cdf0e10cSrcweir 						sharedLibraryLoader.activate(NATIVE_SERVICE_MANAGER_IMP_NAME, null, NATIVE_SERVICE_MANAGER_LIB_NAME, null));
113cdf0e10cSrcweir 
114cdf0e10cSrcweir 		System.err.println("- instantiate the native ServiceManger");
115cdf0e10cSrcweir 		nativeServiceManager = UnoRuntime.queryInterface( XMultiServiceFactory.class, aSMgrFac.createInstance() );
116cdf0e10cSrcweir 
117cdf0e10cSrcweir 		System.out.print("Test - ");
118cdf0e10cSrcweir 		System.out.println(nativeServiceManager == null? "failed" : "successfull");
119cdf0e10cSrcweir 
120cdf0e10cSrcweir 		System.out.println("*******************************************************************");
121cdf0e10cSrcweir 		System.out.println();
122cdf0e10cSrcweir 		return nativeServiceManager != null;
123cdf0e10cSrcweir 	}
124cdf0e10cSrcweir 
test_loadNativeSimpleRegistry()125cdf0e10cSrcweir 	static public boolean test_loadNativeSimpleRegistry()
126cdf0e10cSrcweir 			throws java.lang.Exception
127cdf0e10cSrcweir 	{
128cdf0e10cSrcweir 		boolean result = false;
129cdf0e10cSrcweir 		System.out.println("*******************************************************************");
130cdf0e10cSrcweir 		System.out.println("Test: <<< load native SimpleRegistry >>>");
131cdf0e10cSrcweir 		if ( sharedLibraryLoader == null )
132cdf0e10cSrcweir 			if ( ! test_instantiateSharedLibraryLoader() )
133cdf0e10cSrcweir 				return false;
134cdf0e10cSrcweir 
135cdf0e10cSrcweir 		System.err.println("- get factory of the Registry");
136cdf0e10cSrcweir 		XSingleServiceFactory aRegFac =
137cdf0e10cSrcweir 			UnoRuntime.queryInterface( XSingleServiceFactory.class,
138cdf0e10cSrcweir 						sharedLibraryLoader.activate(NATIVE_REGISTRY_IMP_NAME, null, NATIVE_REGISTRY_LIB_NAME, null)
139cdf0e10cSrcweir 			);
140cdf0e10cSrcweir 		System.err.println("- instantiate the Registry");
141cdf0e10cSrcweir 		simpleRegistry =
142cdf0e10cSrcweir 			UnoRuntime.queryInterface( XSimpleRegistry.class, aRegFac.createInstance() );
143cdf0e10cSrcweir 		System.out.print("Test - ");
144cdf0e10cSrcweir 		System.out.println(simpleRegistry == null? "failed" : "successfull");
145cdf0e10cSrcweir 		System.out.println("*******************************************************************");
146cdf0e10cSrcweir 		System.err.println();
147cdf0e10cSrcweir 		return true;
148cdf0e10cSrcweir 	}
149cdf0e10cSrcweir 
test_registerSharedLibraryLoader()150cdf0e10cSrcweir 	static public boolean test_registerSharedLibraryLoader()
151cdf0e10cSrcweir 			throws java.lang.Exception
152cdf0e10cSrcweir 	{
153cdf0e10cSrcweir 		boolean result = true;
154cdf0e10cSrcweir 		System.out.println("*******************************************************************");
155cdf0e10cSrcweir 		System.out.println("Test: <<< register SharedLibraryLoader at the Registry >>>");
156cdf0e10cSrcweir 
157cdf0e10cSrcweir 		if ( simpleRegistry == null )
158cdf0e10cSrcweir 			if ( ! test_loadNativeSimpleRegistry() )
159cdf0e10cSrcweir 				return false;
160cdf0e10cSrcweir 
161cdf0e10cSrcweir 		com.sun.star.registry.XRegistryKey regKey = simpleRegistry.getRootKey();
162cdf0e10cSrcweir 		result = SharedLibraryLoader.writeRegistryServiceInfo( null,  regKey );
163cdf0e10cSrcweir 
164cdf0e10cSrcweir 		System.out.print("Test - ");
165cdf0e10cSrcweir 		System.out.println( result==false ? "failed" : "successfull");
166cdf0e10cSrcweir 		System.out.println("*******************************************************************");
167cdf0e10cSrcweir 		System.out.println();
168cdf0e10cSrcweir 		return result;
169cdf0e10cSrcweir 	}
170cdf0e10cSrcweir 
test()171cdf0e10cSrcweir 	static public boolean test() throws java.lang.Exception {
172cdf0e10cSrcweir 		boolean passed = true;
173cdf0e10cSrcweir 
174cdf0e10cSrcweir 		System.err.println("SharedLibraryLoader - doing tests...");
175cdf0e10cSrcweir 		passed = test_getSharedLibraryLoaderFactory() && passed;
176cdf0e10cSrcweir 		passed = test_instantiateSharedLibraryLoader() && passed;
177cdf0e10cSrcweir 		passed = test_loadNativeServiceManager() && passed;
178cdf0e10cSrcweir 		passed = test_loadNativeSimpleRegistry() && passed;
179cdf0e10cSrcweir 		//passed = test_registerSharedLibraryLoader() && passed;
180cdf0e10cSrcweir 
181cdf0e10cSrcweir 		System.err.println("SharedLibraryLoader test passed? " + passed);
182cdf0e10cSrcweir 
183cdf0e10cSrcweir 		return passed;
184cdf0e10cSrcweir 	}
185cdf0e10cSrcweir 
main(String args[])186cdf0e10cSrcweir 	static public void main(String args[]) throws java.lang.Exception {
187cdf0e10cSrcweir 		System.exit( test() == true ? 0: -1 );
188cdf0e10cSrcweir 	}
189cdf0e10cSrcweir }
190cdf0e10cSrcweir 
191