2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 package com
.sun
.star
.comp
.helper
;
21 import com
.sun
.star
.uno
.UnoRuntime
;
23 import com
.sun
.star
.lang
.XMultiServiceFactory
;
24 import com
.sun
.star
.lang
.XSingleServiceFactory
;
25 import com
.sun
.star
.loader
.XImplementationLoader
;
27 import com
.sun
.star
.registry
.XSimpleRegistry
;
30 public class SharedLibraryLoader_Test
{
32 private static final String NATIVE_SERVICE_MANAGER_IMP_NAME
= "com.sun.star.comp.stoc.OServiceManager";
33 private static final String NATIVE_SERVICE_MANAGER_LIB_NAME
= "servicemgr.uno";
34 private static final String NATIVE_REGISTRY_IMP_NAME
= "com.sun.star.comp.stoc.SimpleRegistry";
35 private static final String NATIVE_REGISTRY_LIB_NAME
= "simplereg.uno";
37 private static XMultiServiceFactory nativeServiceManager
= null;
38 private static XSingleServiceFactory sharedLibraryLoaderFactory
= null;
39 private static XImplementationLoader sharedLibraryLoader
= null;
40 private static XSimpleRegistry simpleRegistry
= null;
42 static public boolean test_getSharedLibraryLoaderFactory()
43 throws java
.lang
.Exception
45 sharedLibraryLoaderFactory
= null;
46 System
.out
.println("*******************************************************************");
47 System
.out
.println("Test: <<< get SharedLibraryLoader factory >>>");
48 sharedLibraryLoaderFactory
= SharedLibraryLoader
.getServiceFactory(null, null);
50 System
.out
.print("Test - ");
51 System
.out
.println(sharedLibraryLoaderFactory
== null?
"failed" : "successful");
52 System
.out
.println("*******************************************************************");
55 return sharedLibraryLoaderFactory
!= null;
58 static public boolean test_instantiateSharedLibraryLoader()
59 throws java
.lang
.Exception
61 sharedLibraryLoader
= null;
62 System
.out
.println("*******************************************************************");
63 System
.out
.println("Test: <<< instantiate SharedLibraryLoader >>>");
64 if ( sharedLibraryLoaderFactory
== null )
65 if ( ! test_getSharedLibraryLoaderFactory() )
68 sharedLibraryLoader
= UnoRuntime
.queryInterface(
69 XImplementationLoader
.class, sharedLibraryLoaderFactory
.createInstance() );
71 System
.out
.print("Test - ");
72 System
.out
.println(sharedLibraryLoader
== null?
"failed" : "successful");
73 System
.out
.println("*******************************************************************");
76 return sharedLibraryLoader
!= null;
79 static public boolean test_loadNativeServiceManager()
80 throws java
.lang
.Exception
82 nativeServiceManager
= null;
84 System
.out
.println("*******************************************************************");
85 System
.out
.println("Test: <<< load native ServiceManager >>>");
86 if ( sharedLibraryLoader
== null )
87 if ( ! test_instantiateSharedLibraryLoader() )
90 System
.err
.println("- get the native ServiceManger factory");
91 XSingleServiceFactory aSMgrFac
=
92 UnoRuntime
.queryInterface( XSingleServiceFactory
.class,
93 sharedLibraryLoader
.activate(NATIVE_SERVICE_MANAGER_IMP_NAME
, null, NATIVE_SERVICE_MANAGER_LIB_NAME
, null));
95 System
.err
.println("- instantiate the native ServiceManger");
96 nativeServiceManager
= UnoRuntime
.queryInterface( XMultiServiceFactory
.class, aSMgrFac
.createInstance() );
98 System
.out
.print("Test - ");
99 System
.out
.println(nativeServiceManager
== null?
"failed" : "successful");
101 System
.out
.println("*******************************************************************");
102 System
.out
.println();
103 return nativeServiceManager
!= null;
106 static public boolean test_loadNativeSimpleRegistry()
107 throws java
.lang
.Exception
109 System
.out
.println("*******************************************************************");
110 System
.out
.println("Test: <<< load native SimpleRegistry >>>");
111 if ( sharedLibraryLoader
== null )
112 if ( ! test_instantiateSharedLibraryLoader() )
115 System
.err
.println("- get factory of the Registry");
116 XSingleServiceFactory aRegFac
=
117 UnoRuntime
.queryInterface( XSingleServiceFactory
.class,
118 sharedLibraryLoader
.activate(NATIVE_REGISTRY_IMP_NAME
, null, NATIVE_REGISTRY_LIB_NAME
, null)
120 System
.err
.println("- instantiate the Registry");
122 UnoRuntime
.queryInterface( XSimpleRegistry
.class, aRegFac
.createInstance() );
123 System
.out
.print("Test - ");
124 System
.out
.println(simpleRegistry
== null?
"failed" : "successful");
125 System
.out
.println("*******************************************************************");
126 System
.err
.println();
130 static public boolean test_registerSharedLibraryLoader()
131 throws java
.lang
.Exception
133 boolean result
= true;
134 System
.out
.println("*******************************************************************");
135 System
.out
.println("Test: <<< register SharedLibraryLoader at the Registry >>>");
137 if ( simpleRegistry
== null )
138 if ( ! test_loadNativeSimpleRegistry() )
141 com
.sun
.star
.registry
.XRegistryKey regKey
= simpleRegistry
.getRootKey();
142 result
= SharedLibraryLoader
.writeRegistryServiceInfo( null, regKey
);
144 System
.out
.print("Test - ");
145 System
.out
.println( !result ?
"failed" : "successful");
146 System
.out
.println("*******************************************************************");
147 System
.out
.println();
151 static public boolean test() throws java
.lang
.Exception
{
152 boolean passed
= true;
154 System
.err
.println("SharedLibraryLoader - doing tests...");
155 passed
= test_getSharedLibraryLoaderFactory() && passed
;
156 passed
= test_instantiateSharedLibraryLoader() && passed
;
157 passed
= test_loadNativeServiceManager() && passed
;
158 passed
= test_loadNativeSimpleRegistry() && passed
;
160 System
.err
.println("SharedLibraryLoader test passed? " + passed
);
165 static public void main(String args
[]) throws java
.lang
.Exception
{
166 System
.exit( test() ?
0: -1 );