1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: SharedLibraryLoader_Test.java,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 package com
.sun
.star
.comp
.helper
;
33 import com
.sun
.star
.comp
.loader
.JavaLoader
;
35 import com
.sun
.star
.comp
.servicemanager
.ServiceManager
;
36 import com
.sun
.star
.uno
.UnoRuntime
;
38 import com
.sun
.star
.container
.XSet
;
39 import com
.sun
.star
.container
.XContentEnumerationAccess
;
40 import com
.sun
.star
.container
.XEnumeration
;
41 import com
.sun
.star
.container
.XEnumerationAccess
;
42 import com
.sun
.star
.container
.XElementAccess
;
44 import com
.sun
.star
.lang
.XComponent
;
46 import com
.sun
.star
.lang
.XServiceInfo
;
47 import com
.sun
.star
.lang
.XMultiServiceFactory
;
48 import com
.sun
.star
.lang
.XSingleServiceFactory
;
49 import com
.sun
.star
.lang
.XInitialization
;
51 import com
.sun
.star
.loader
.XImplementationLoader
;
53 import com
.sun
.star
.registry
.XSimpleRegistry
;
56 public class SharedLibraryLoader_Test
{
58 private static final String NATIVE_SERVICE_MANAGER_IMP_NAME
= "com.sun.star.comp.stoc.OServiceManager";
59 private static final String NATIVE_SERVICE_MANAGER_LIB_NAME
= "servicemgr.uno";
60 private static final String NATIVE_REGISTRY_IMP_NAME
= "com.sun.star.comp.stoc.SimpleRegistry";
61 private static final String NATIVE_REGISTRY_LIB_NAME
= "simplereg.uno";
63 private static XMultiServiceFactory nativeServiceManager
= null;
64 private static XSingleServiceFactory sharedLibraryLoaderFactory
= null;
65 private static XImplementationLoader sharedLibraryLoader
= null;
66 private static XSimpleRegistry simpleRegistry
= null;
68 static public boolean test_getSharedLibraryLoaderFactory()
69 throws java
.lang
.Exception
71 sharedLibraryLoaderFactory
= null;
72 System
.out
.println("*******************************************************************");
73 System
.out
.println("Test: <<< get SharedLibraryLoader factory >>>");
74 sharedLibraryLoaderFactory
= SharedLibraryLoader
.getServiceFactory(null, null);
76 System
.out
.print("Test - ");
77 System
.out
.println(sharedLibraryLoaderFactory
== null?
"failed" : "successfull");
78 System
.out
.println("*******************************************************************");
81 return sharedLibraryLoaderFactory
!= null;
84 static public boolean test_instantiateSharedLibraryLoader()
85 throws java
.lang
.Exception
87 sharedLibraryLoader
= null;
88 System
.out
.println("*******************************************************************");
89 System
.out
.println("Test: <<< instantiate SharedLibraryLoader >>>");
90 if ( sharedLibraryLoaderFactory
== null )
91 if ( ! test_getSharedLibraryLoaderFactory() )
94 sharedLibraryLoader
= UnoRuntime
.queryInterface(
95 XImplementationLoader
.class, sharedLibraryLoaderFactory
.createInstance() );
97 System
.out
.print("Test - ");
98 System
.out
.println(sharedLibraryLoader
== null?
"failed" : "successfull");
99 System
.out
.println("*******************************************************************");
100 System
.out
.println();
102 return sharedLibraryLoader
!= null;
105 static public boolean test_loadNativeServiceManager()
106 throws java
.lang
.Exception
108 nativeServiceManager
= null;
110 System
.out
.println("*******************************************************************");
111 System
.out
.println("Test: <<< load native ServiceManager >>>");
112 if ( sharedLibraryLoader
== null )
113 if ( ! test_instantiateSharedLibraryLoader() )
116 System
.err
.println("- get the native ServiceManger factory");
117 XSingleServiceFactory aSMgrFac
=
118 UnoRuntime
.queryInterface( XSingleServiceFactory
.class,
119 sharedLibraryLoader
.activate(NATIVE_SERVICE_MANAGER_IMP_NAME
, null, NATIVE_SERVICE_MANAGER_LIB_NAME
, null));
121 System
.err
.println("- instantiate the native ServiceManger");
122 nativeServiceManager
= UnoRuntime
.queryInterface( XMultiServiceFactory
.class, aSMgrFac
.createInstance() );
124 System
.out
.print("Test - ");
125 System
.out
.println(nativeServiceManager
== null?
"failed" : "successfull");
127 System
.out
.println("*******************************************************************");
128 System
.out
.println();
129 return nativeServiceManager
!= null;
132 static public boolean test_loadNativeSimpleRegistry()
133 throws java
.lang
.Exception
135 boolean result
= false;
136 System
.out
.println("*******************************************************************");
137 System
.out
.println("Test: <<< load native SimpleRegistry >>>");
138 if ( sharedLibraryLoader
== null )
139 if ( ! test_instantiateSharedLibraryLoader() )
142 System
.err
.println("- get factory of the Registry");
143 XSingleServiceFactory aRegFac
=
144 UnoRuntime
.queryInterface( XSingleServiceFactory
.class,
145 sharedLibraryLoader
.activate(NATIVE_REGISTRY_IMP_NAME
, null, NATIVE_REGISTRY_LIB_NAME
, null)
147 System
.err
.println("- instantiate the Registry");
149 UnoRuntime
.queryInterface( XSimpleRegistry
.class, aRegFac
.createInstance() );
150 System
.out
.print("Test - ");
151 System
.out
.println(simpleRegistry
== null?
"failed" : "successfull");
152 System
.out
.println("*******************************************************************");
153 System
.err
.println();
157 static public boolean test_registerSharedLibraryLoader()
158 throws java
.lang
.Exception
160 boolean result
= true;
161 System
.out
.println("*******************************************************************");
162 System
.out
.println("Test: <<< register SharedLibraryLoader at the Registry >>>");
164 if ( simpleRegistry
== null )
165 if ( ! test_loadNativeSimpleRegistry() )
168 com
.sun
.star
.registry
.XRegistryKey regKey
= simpleRegistry
.getRootKey();
169 result
= SharedLibraryLoader
.writeRegistryServiceInfo( null, regKey
);
171 System
.out
.print("Test - ");
172 System
.out
.println( result
==false ?
"failed" : "successfull");
173 System
.out
.println("*******************************************************************");
174 System
.out
.println();
178 static public boolean test() throws java
.lang
.Exception
{
179 boolean passed
= true;
181 System
.err
.println("SharedLibraryLoader - doing tests...");
182 passed
= test_getSharedLibraryLoaderFactory() && passed
;
183 passed
= test_instantiateSharedLibraryLoader() && passed
;
184 passed
= test_loadNativeServiceManager() && passed
;
185 passed
= test_loadNativeSimpleRegistry() && passed
;
186 //passed = test_registerSharedLibraryLoader() && passed;
188 System
.err
.println("SharedLibraryLoader test passed? " + passed
);
193 static public void main(String args
[]) throws java
.lang
.Exception
{
194 System
.exit( test() == true ?
0: -1 );