| 1 |
/* |
| 2 |
* This file is part of the LibreOffice project. |
| 3 |
* |
| 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/. |
| 7 |
* |
| 8 |
* This file incorporates work covered by the following license notice: |
| 9 |
* |
| 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 . |
| 17 |
*/ |
| 18 |
|
| 19 |
package com.sun.star.comp.helper; |
| 20 |
|
| 21 |
import com.sun.star.uno.UnoRuntime; |
| 22 |
|
| 23 |
import com.sun.star.lang.XMultiServiceFactory; |
| 24 |
import com.sun.star.lang.XSingleServiceFactory; |
| 25 |
import com.sun.star.loader.XImplementationLoader; |
| 26 |
|
| 27 |
import com.sun.star.registry.XSimpleRegistry; |
| 28 |
|
| 29 |
@Deprecated |
| 30 |
public class SharedLibraryLoader_Test { |
| 31 |
|
| 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"; |
| 36 |
|
| 37 |
private static XMultiServiceFactory nativeServiceManager = null; |
| 38 |
private static XSingleServiceFactory sharedLibraryLoaderFactory = null; |
| 39 |
private static XImplementationLoader sharedLibraryLoader = null; |
| 40 |
private static XSimpleRegistry simpleRegistry = null; |
| 41 |
|
| 42 |
public static boolean test_getSharedLibraryLoaderFactory() |
| 43 |
throws java.lang.Exception |
| 44 |
{ |
| 45 |
sharedLibraryLoaderFactory = null; |
| 46 |
System.out.println("*******************************************************************"); |
| 47 |
System.out.println("Test: <<< get SharedLibraryLoader factory >>>"); |
| 48 |
sharedLibraryLoaderFactory = SharedLibraryLoader.getServiceFactory(null, null); |
| 49 |
|
| 50 |
System.out.print("Test - "); |
| 51 |
System.out.println(sharedLibraryLoaderFactory == null? "failed" : "successful"); |
| 52 |
System.out.println("*******************************************************************"); |
| 53 |
System.out.println(); |
| 54 |
|
| 55 |
return sharedLibraryLoaderFactory != null; |
| 56 |
} |
| 57 |
|
| 58 |
public static boolean test_instantiateSharedLibraryLoader() |
| 59 |
throws java.lang.Exception |
| 60 |
{ |
| 61 |
sharedLibraryLoader = null; |
| 62 |
System.out.println("*******************************************************************"); |
| 63 |
System.out.println("Test: <<< instantiate SharedLibraryLoader >>>"); |
| 64 |
if ( sharedLibraryLoaderFactory == null && ! test_getSharedLibraryLoaderFactory() ) |
| 65 |
return false; |
| 66 |
|
| 67 |
sharedLibraryLoader = UnoRuntime.queryInterface( |
| 68 |
XImplementationLoader.class, sharedLibraryLoaderFactory.createInstance() ); |
| 69 |
|
| 70 |
System.out.print("Test - "); |
| 71 |
System.out.println(sharedLibraryLoader == null? "failed" : "successful"); |
| 72 |
System.out.println("*******************************************************************"); |
| 73 |
System.out.println(); |
| 74 |
|
| 75 |
return sharedLibraryLoader != null; |
| 76 |
} |
| 77 |
|
| 78 |
public static boolean test_loadNativeServiceManager() |
| 79 |
throws java.lang.Exception |
| 80 |
{ |
| 81 |
nativeServiceManager = null; |
| 82 |
|
| 83 |
System.out.println("*******************************************************************"); |
| 84 |
System.out.println("Test: <<< load native ServiceManager >>>"); |
| 85 |
if ( sharedLibraryLoader == null && ! test_instantiateSharedLibraryLoader() ) |
| 86 |
return false; |
| 87 |
|
| 88 |
System.err.println("- get the native ServiceManager factory"); |
| 89 |
XSingleServiceFactory aSMgrFac = |
| 90 |
UnoRuntime.queryInterface( XSingleServiceFactory.class, |
| 91 |
sharedLibraryLoader.activate(NATIVE_SERVICE_MANAGER_IMP_NAME, null, NATIVE_SERVICE_MANAGER_LIB_NAME, null)); |
| 92 |
|
| 93 |
System.err.println("- instantiate the native ServiceManager"); |
| 94 |
nativeServiceManager = UnoRuntime.queryInterface( XMultiServiceFactory.class, aSMgrFac.createInstance() ); |
| 95 |
|
| 96 |
System.out.print("Test - "); |
| 97 |
System.out.println(nativeServiceManager == null? "failed" : "successful"); |
| 98 |
|
| 99 |
System.out.println("*******************************************************************"); |
| 100 |
System.out.println(); |
| 101 |
return nativeServiceManager != null; |
| 102 |
} |
| 103 |
|
| 104 |
public static boolean test_loadNativeSimpleRegistry() |
| 105 |
throws java.lang.Exception |
| 106 |
{ |
| 107 |
System.out.println("*******************************************************************"); |
| 108 |
System.out.println("Test: <<< load native SimpleRegistry >>>"); |
| 109 |
if ( sharedLibraryLoader == null && ! test_instantiateSharedLibraryLoader() ) |
| 110 |
return false; |
| 111 |
|
| 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) |
| 116 |
); |
| 117 |
System.err.println("- instantiate the Registry"); |
| 118 |
simpleRegistry = |
| 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(); |
| 124 |
return true; |
| 125 |
} |
| 126 |
|
| 127 |
public static boolean test_registerSharedLibraryLoader() |
| 128 |
throws java.lang.Exception |
| 129 |
{ |
| 130 |
boolean result = true; |
| 131 |
System.out.println("*******************************************************************"); |
| 132 |
System.out.println("Test: <<< register SharedLibraryLoader at the Registry >>>"); |
| 133 |
|
| 134 |
if ( simpleRegistry == null && ! test_loadNativeSimpleRegistry() ) |
| 135 |
return false; |
| 136 |
|
| 137 |
com.sun.star.registry.XRegistryKey regKey = simpleRegistry.getRootKey(); |
| 138 |
result = SharedLibraryLoader.writeRegistryServiceInfo( null, regKey ); |
| 139 |
|
| 140 |
System.out.print("Test - "); |
| 141 |
System.out.println( !result ? "failed" : "successful"); |
| 142 |
System.out.println("*******************************************************************"); |
| 143 |
System.out.println(); |
| 144 |
return result; |
| 145 |
} |
| 146 |
|
| 147 |
public static boolean test() throws java.lang.Exception { |
| 148 |
boolean passed = true; |
| 149 |
|
| 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; |
| 155 |
|
| 156 |
System.err.println("SharedLibraryLoader test passed? " + passed); |
| 157 |
|
| 158 |
return passed; |
| 159 |
} |
| 160 |
|
| 161 |
public static void main(String args[]) throws java.lang.Exception { |
| 162 |
System.exit( test() ? 0: -1 ); |
| 163 |
} |
| 164 |
} |
| 165 |
|