summaryrefslogtreecommitdiffstats
path: root/javaunohelper/test/com/sun/star/comp
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 16:51:28 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 16:51:28 +0000
commit940b4d1848e8c70ab7642901a68594e8016caffc (patch)
treeeb72f344ee6c3d9b80a7ecc079ea79e9fba8676d /javaunohelper/test/com/sun/star/comp
parentInitial commit. (diff)
downloadlibreoffice-940b4d1848e8c70ab7642901a68594e8016caffc.tar.xz
libreoffice-940b4d1848e8c70ab7642901a68594e8016caffc.zip
Adding upstream version 1:7.0.4.upstream/1%7.0.4upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'javaunohelper/test/com/sun/star/comp')
-rw-r--r--javaunohelper/test/com/sun/star/comp/helper/Bootstrap_Test.java113
-rw-r--r--javaunohelper/test/com/sun/star/comp/helper/ComponentContext_Test.java72
-rw-r--r--javaunohelper/test/com/sun/star/comp/helper/SharedLibraryLoader_Test.java165
3 files changed, 350 insertions, 0 deletions
diff --git a/javaunohelper/test/com/sun/star/comp/helper/Bootstrap_Test.java b/javaunohelper/test/com/sun/star/comp/helper/Bootstrap_Test.java
new file mode 100644
index 000000000..9be051b62
--- /dev/null
+++ b/javaunohelper/test/com/sun/star/comp/helper/Bootstrap_Test.java
@@ -0,0 +1,113 @@
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+package com.sun.star.comp.helper;
+
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.uno.AnyConverter;
+
+import com.sun.star.uno.XComponentContext;
+import com.sun.star.lang.XComponent;
+import com.sun.star.lang.XMultiServiceFactory;
+
+import java.util.logging.Logger;
+import java.util.logging.Level;
+import java.util.Map;
+
+public class Bootstrap_Test {
+
+ private static final Logger logger = Logger.getLogger(Bootstrap_Test.class.getName());
+
+ public static boolean test( String ini_file, Map<String,String> bootstrap_parameters )
+ throws java.lang.Exception
+ {
+ boolean passed = false;
+ logger.log(Level.INFO, "Bootstrap - doing tests...");
+
+ try {
+ XComponentContext xContext =
+ com.sun.star.comp.helper.Bootstrap.defaultBootstrap_InitialComponentContext(
+ ini_file, bootstrap_parameters );
+
+ if (AnyConverter.isVoid(
+ xContext.getValueByName(
+ "/singletons/com.sun.star.reflection.theTypeDescriptionManager" ) ))
+ {
+ throw new Exception(
+ "no /singletons/com.sun.star.reflection.theTypeDescriptionManager!" );
+ }
+
+ XMultiServiceFactory msf = UnoRuntime.queryInterface(
+ XMultiServiceFactory.class, xContext.getServiceManager() );
+ String services[] = msf.getAvailableServiceNames();
+ logger.log(Level.FINE, "Available services are:");
+ if (services.length == 0)
+ logger.log(Level.FINE, "No services available!");
+
+ else
+ for ( int i=0; i<services.length; i++ )
+ logger.log(Level.FINE, services[i]);
+
+ XComponent xComp = UnoRuntime.queryInterface(
+ XComponent.class, xContext );
+ xComp.dispose();
+
+ passed = true;
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+ logger.log(Level.INFO, "Bootstrap test passed? " + passed);
+ return passed;
+ }
+
+ private static void usage() {
+ System.out.println();
+ System.out.println("usage:");
+ System.out.println("java com.sun.star.comp.helper.Bootstrap_Test ini-file name=value ...");
+ System.out.println("example:");
+ System.out.println("java com.sun.star.comp.helper.Bootstrap_Test file:///c:/ooo10/program/uno.ini SYSBINDIR=file:///c:/ooo10/program");
+ System.exit( -1 );
+ }
+
+ public static void main(String args[]) throws java.lang.Exception {
+ if ( args.length == 0 )
+ usage();
+
+ java.util.HashMap<String,String> bootstrap_parameters = new java.util.HashMap<String,String>();
+ for ( int nPos = 1; nPos < args.length; ++nPos ) {
+ if (args[nPos].contains("=")) {
+ String bootstrap_parameter[] = args[nPos].split("=",2);
+ if (bootstrap_parameter[0].length() > 0) {
+ bootstrap_parameters.put( bootstrap_parameter[0], bootstrap_parameter[1] );
+ } else {
+ System.out.println();
+ System.out.println("The 1st argument in a bootstrap parameter is the key of a HashMap element and can't be null : '" + args[nPos] + "'");
+ usage();
+ }
+ } else {
+ System.out.println();
+ System.out.println("Missing '=' in bootstrap parameter : '" + args[nPos] + "'");
+ usage();
+ }
+ }
+
+ System.exit( test(args[0], bootstrap_parameters) ? 0: -1 );
+ }
+}
+
diff --git a/javaunohelper/test/com/sun/star/comp/helper/ComponentContext_Test.java b/javaunohelper/test/com/sun/star/comp/helper/ComponentContext_Test.java
new file mode 100644
index 000000000..122ed2ce9
--- /dev/null
+++ b/javaunohelper/test/com/sun/star/comp/helper/ComponentContext_Test.java
@@ -0,0 +1,72 @@
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+package com.sun.star.comp.helper;
+
+import java.util.HashMap;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import com.sun.star.lang.XComponent;
+import com.sun.star.lang.XMultiComponentFactory;
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.uno.XComponentContext;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import org.junit.Test;
+
+public class ComponentContext_Test {
+
+ private static final Logger logger = Logger.getLogger(ComponentContext_Test.class.getName());
+
+ @Test public void test() throws Exception {
+ logger.log(Level.INFO, "Testing ComponentContext");
+ HashMap<String, Object> table = new HashMap<String, Object>();
+ table.put("bla1", new ComponentContextEntry(null, Integer.valueOf(1)));
+ XComponentContext xInitialContext = Bootstrap.createInitialComponentContext(table);
+
+ table = new HashMap<String, Object>();
+ table.put("bla2", new ComponentContextEntry(Integer.valueOf(2)));
+ table.put("bla3", Integer.valueOf(3));
+ XComponentContext xContext = new ComponentContext(table, xInitialContext);
+
+ XMultiComponentFactory xSMgr = xContext.getServiceManager();
+
+ assertNotNull(xSMgr.createInstanceWithContext("com.sun.star.loader.Java", xContext));
+ assertNotNull(xSMgr.createInstanceWithContext("com.sun.star.bridge.BridgeFactory", xContext));
+ assertNotNull(xSMgr.createInstanceWithContext("com.sun.star.bridge.UnoUrlResolver", xContext));
+ assertNotNull(xSMgr.createInstanceWithContext("com.sun.star.connection.Connector", xContext));
+ assertNotNull(xSMgr.createInstanceWithContext("com.sun.star.connection.Acceptor", xContext));
+// assertNotNull(xSMgr.createInstanceWithContext("com.sun.star.lang.ServiceManager", xContext));
+
+ assertNotNull(xContext.getValueByName("bla1"));
+ assertNotNull(xContext.getValueByName("bla2"));
+ assertNotNull(xContext.getValueByName("bla3"));
+ assertNotNull(xInitialContext.getValueByName("bla2"));
+ assertNotNull(xInitialContext.getValueByName("bla3"));
+
+ assertEquals(((Integer) xContext.getValueByName("bla1")).intValue(), 1);
+ assertEquals(((Integer) xContext.getValueByName("bla2")).intValue(), 2);
+ assertEquals(((Integer) xContext.getValueByName("bla3")).intValue(), 3);
+ assertEquals(((Integer) xInitialContext.getValueByName("bla1")).intValue(), 1);
+
+ XComponent xComp = UnoRuntime.queryInterface(
+ XComponent.class, xInitialContext);
+ xComp.dispose();
+ }
+} \ No newline at end of file
diff --git a/javaunohelper/test/com/sun/star/comp/helper/SharedLibraryLoader_Test.java b/javaunohelper/test/com/sun/star/comp/helper/SharedLibraryLoader_Test.java
new file mode 100644
index 000000000..b9c67e68b
--- /dev/null
+++ b/javaunohelper/test/com/sun/star/comp/helper/SharedLibraryLoader_Test.java
@@ -0,0 +1,165 @@
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+package com.sun.star.comp.helper;
+
+import com.sun.star.uno.UnoRuntime;
+
+import com.sun.star.lang.XMultiServiceFactory;
+import com.sun.star.lang.XSingleServiceFactory;
+import com.sun.star.loader.XImplementationLoader;
+
+import com.sun.star.registry.XSimpleRegistry;
+
+@Deprecated
+public class SharedLibraryLoader_Test {
+
+ private static final String NATIVE_SERVICE_MANAGER_IMP_NAME = "com.sun.star.comp.stoc.OServiceManager";
+ private static final String NATIVE_SERVICE_MANAGER_LIB_NAME = "servicemgr.uno";
+ private static final String NATIVE_REGISTRY_IMP_NAME = "com.sun.star.comp.stoc.SimpleRegistry";
+ private static final String NATIVE_REGISTRY_LIB_NAME = "simplereg.uno";
+
+ private static XMultiServiceFactory nativeServiceManager = null;
+ private static XSingleServiceFactory sharedLibraryLoaderFactory = null;
+ private static XImplementationLoader sharedLibraryLoader = null;
+ private static XSimpleRegistry simpleRegistry = null;
+
+ public static boolean test_getSharedLibraryLoaderFactory()
+ throws java.lang.Exception
+ {
+ sharedLibraryLoaderFactory = null;
+ System.out.println("*******************************************************************");
+ System.out.println("Test: <<< get SharedLibraryLoader factory >>>");
+ sharedLibraryLoaderFactory = SharedLibraryLoader.getServiceFactory(null, null);
+
+ System.out.print("Test - ");
+ System.out.println(sharedLibraryLoaderFactory == null? "failed" : "successful");
+ System.out.println("*******************************************************************");
+ System.out.println();
+
+ return sharedLibraryLoaderFactory != null;
+ }
+
+ public static boolean test_instantiateSharedLibraryLoader()
+ throws java.lang.Exception
+ {
+ sharedLibraryLoader = null;
+ System.out.println("*******************************************************************");
+ System.out.println("Test: <<< instantiate SharedLibraryLoader >>>");
+ if ( sharedLibraryLoaderFactory == null && ! test_getSharedLibraryLoaderFactory() )
+ return false;
+
+ sharedLibraryLoader = UnoRuntime.queryInterface(
+ XImplementationLoader.class, sharedLibraryLoaderFactory.createInstance() );
+
+ System.out.print("Test - ");
+ System.out.println(sharedLibraryLoader == null? "failed" : "successful");
+ System.out.println("*******************************************************************");
+ System.out.println();
+
+ return sharedLibraryLoader != null;
+ }
+
+ public static boolean test_loadNativeServiceManager()
+ throws java.lang.Exception
+ {
+ nativeServiceManager = null;
+
+ System.out.println("*******************************************************************");
+ System.out.println("Test: <<< load native ServiceManager >>>");
+ if ( sharedLibraryLoader == null && ! test_instantiateSharedLibraryLoader() )
+ return false;
+
+ System.err.println("- get the native ServiceManger factory");
+ XSingleServiceFactory aSMgrFac =
+ UnoRuntime.queryInterface( XSingleServiceFactory.class,
+ sharedLibraryLoader.activate(NATIVE_SERVICE_MANAGER_IMP_NAME, null, NATIVE_SERVICE_MANAGER_LIB_NAME, null));
+
+ System.err.println("- instantiate the native ServiceManger");
+ nativeServiceManager = UnoRuntime.queryInterface( XMultiServiceFactory.class, aSMgrFac.createInstance() );
+
+ System.out.print("Test - ");
+ System.out.println(nativeServiceManager == null? "failed" : "successful");
+
+ System.out.println("*******************************************************************");
+ System.out.println();
+ return nativeServiceManager != null;
+ }
+
+ public static boolean test_loadNativeSimpleRegistry()
+ throws java.lang.Exception
+ {
+ System.out.println("*******************************************************************");
+ System.out.println("Test: <<< load native SimpleRegistry >>>");
+ if ( sharedLibraryLoader == null && ! test_instantiateSharedLibraryLoader() )
+ return false;
+
+ System.err.println("- get factory of the Registry");
+ XSingleServiceFactory aRegFac =
+ UnoRuntime.queryInterface( XSingleServiceFactory.class,
+ sharedLibraryLoader.activate(NATIVE_REGISTRY_IMP_NAME, null, NATIVE_REGISTRY_LIB_NAME, null)
+ );
+ System.err.println("- instantiate the Registry");
+ simpleRegistry =
+ UnoRuntime.queryInterface( XSimpleRegistry.class, aRegFac.createInstance() );
+ System.out.print("Test - ");
+ System.out.println(simpleRegistry == null? "failed" : "successful");
+ System.out.println("*******************************************************************");
+ System.err.println();
+ return true;
+ }
+
+ public static boolean test_registerSharedLibraryLoader()
+ throws java.lang.Exception
+ {
+ boolean result = true;
+ System.out.println("*******************************************************************");
+ System.out.println("Test: <<< register SharedLibraryLoader at the Registry >>>");
+
+ if ( simpleRegistry == null && ! test_loadNativeSimpleRegistry() )
+ return false;
+
+ com.sun.star.registry.XRegistryKey regKey = simpleRegistry.getRootKey();
+ result = SharedLibraryLoader.writeRegistryServiceInfo( null, regKey );
+
+ System.out.print("Test - ");
+ System.out.println( !result ? "failed" : "successful");
+ System.out.println("*******************************************************************");
+ System.out.println();
+ return result;
+ }
+
+ public static boolean test() throws java.lang.Exception {
+ boolean passed = true;
+
+ System.err.println("SharedLibraryLoader - doing tests...");
+ passed = test_getSharedLibraryLoaderFactory() && passed;
+ passed = test_instantiateSharedLibraryLoader() && passed;
+ passed = test_loadNativeServiceManager() && passed;
+ passed = test_loadNativeSimpleRegistry() && passed;
+
+ System.err.println("SharedLibraryLoader test passed? " + passed);
+
+ return passed;
+ }
+
+ public static void main(String args[]) throws java.lang.Exception {
+ System.exit( test() ? 0: -1 );
+ }
+}
+