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 public static 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 public static 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 && ! test_getSharedLibraryLoaderFactory() )
67 sharedLibraryLoader
= UnoRuntime
.queryInterface(
68 XImplementationLoader
.class, sharedLibraryLoaderFactory
.createInstance() );
70 System
.out
.print("Test - ");
71 System
.out
.println(sharedLibraryLoader
== null?
"failed" : "successful");
72 System
.out
.println("*******************************************************************");
75 return sharedLibraryLoader
!= null;
78 public static boolean test_loadNativeServiceManager()
79 throws java
.lang
.Exception
81 nativeServiceManager
= null;
83 System
.out
.println("*******************************************************************");
84 System
.out
.println("Test: <<< load native ServiceManager >>>");
85 if ( sharedLibraryLoader
== null && ! test_instantiateSharedLibraryLoader() )
88 System
.err
.println("- get the native ServiceManger factory");
89 XSingleServiceFactory aSMgrFac
=
90 UnoRuntime
.queryInterface( XSingleServiceFactory
.class,
91 sharedLibraryLoader
.activate(NATIVE_SERVICE_MANAGER_IMP_NAME
, null, NATIVE_SERVICE_MANAGER_LIB_NAME
, null));
93 System
.err
.println("- instantiate the native ServiceManger");
94 nativeServiceManager
= UnoRuntime
.queryInterface( XMultiServiceFactory
.class, aSMgrFac
.createInstance() );
96 System
.out
.print("Test - ");
97 System
.out
.println(nativeServiceManager
== null?
"failed" : "successful");
99 System
.out
.println("*******************************************************************");
100 System
.out
.println();
101 return nativeServiceManager
!= null;
104 public static boolean test_loadNativeSimpleRegistry()
105 throws java
.lang
.Exception
107 System
.out
.println("*******************************************************************");
108 System
.out
.println("Test: <<< load native SimpleRegistry >>>");
109 if ( sharedLibraryLoader
== null && ! test_instantiateSharedLibraryLoader() )
112 System
.err
.println("- get factory of the Registry");
113 XSingleServiceFactory aRegFac
=
114 UnoRuntime
.queryInterface( XSingleServiceFactory
.class,
115 sharedLibraryLoader
.activate(NATIVE_REGISTRY_IMP_NAME
, null, NATIVE_REGISTRY_LIB_NAME
, null)
117 System
.err
.println("- instantiate the Registry");
119 UnoRuntime
.queryInterface( XSimpleRegistry
.class, aRegFac
.createInstance() );
120 System
.out
.print("Test - ");
121 System
.out
.println(simpleRegistry
== null?
"failed" : "successful");
122 System
.out
.println("*******************************************************************");
123 System
.err
.println();
127 public static boolean test_registerSharedLibraryLoader()
128 throws java
.lang
.Exception
130 boolean result
= true;
131 System
.out
.println("*******************************************************************");
132 System
.out
.println("Test: <<< register SharedLibraryLoader at the Registry >>>");
134 if ( simpleRegistry
== null && ! test_loadNativeSimpleRegistry() )
137 com
.sun
.star
.registry
.XRegistryKey regKey
= simpleRegistry
.getRootKey();
138 result
= SharedLibraryLoader
.writeRegistryServiceInfo( null, regKey
);
140 System
.out
.print("Test - ");
141 System
.out
.println( !result ?
"failed" : "successful");
142 System
.out
.println("*******************************************************************");
143 System
.out
.println();
147 public static boolean test() throws java
.lang
.Exception
{
148 boolean passed
= true;
150 System
.err
.println("SharedLibraryLoader - doing tests...");
151 passed
= test_getSharedLibraryLoaderFactory() && passed
;
152 passed
= test_instantiateSharedLibraryLoader() && passed
;
153 passed
= test_loadNativeServiceManager() && passed
;
154 passed
= test_loadNativeSimpleRegistry() && passed
;
156 System
.err
.println("SharedLibraryLoader test passed? " + passed
);
161 public static void main(String args
[]) throws java
.lang
.Exception
{
162 System
.exit( test() ?
0: -1 );