Version 6.4.0.3, tag libreoffice-6.4.0.3
[LibreOffice.git] / javaunohelper / test / com / sun / star / comp / helper / Bootstrap_Test.java
blob9be051b623eb74592aa1a6ee4a9d27cf3da1ce3d
1 /*
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;
22 import com.sun.star.uno.AnyConverter;
24 import com.sun.star.uno.XComponentContext;
25 import com.sun.star.lang.XComponent;
26 import com.sun.star.lang.XMultiServiceFactory;
28 import java.util.logging.Logger;
29 import java.util.logging.Level;
30 import java.util.Map;
32 public class Bootstrap_Test {
34 private static final Logger logger = Logger.getLogger(Bootstrap_Test.class.getName());
36 public static boolean test( String ini_file, Map<String,String> bootstrap_parameters )
37 throws java.lang.Exception
39 boolean passed = false;
40 logger.log(Level.INFO, "Bootstrap - doing tests...");
42 try {
43 XComponentContext xContext =
44 com.sun.star.comp.helper.Bootstrap.defaultBootstrap_InitialComponentContext(
45 ini_file, bootstrap_parameters );
47 if (AnyConverter.isVoid(
48 xContext.getValueByName(
49 "/singletons/com.sun.star.reflection.theTypeDescriptionManager" ) ))
51 throw new Exception(
52 "no /singletons/com.sun.star.reflection.theTypeDescriptionManager!" );
55 XMultiServiceFactory msf = UnoRuntime.queryInterface(
56 XMultiServiceFactory.class, xContext.getServiceManager() );
57 String services[] = msf.getAvailableServiceNames();
58 logger.log(Level.FINE, "Available services are:");
59 if (services.length == 0)
60 logger.log(Level.FINE, "No services available!");
62 else
63 for ( int i=0; i<services.length; i++ )
64 logger.log(Level.FINE, services[i]);
66 XComponent xComp = UnoRuntime.queryInterface(
67 XComponent.class, xContext );
68 xComp.dispose();
70 passed = true;
72 catch (Exception e) {
73 e.printStackTrace();
75 logger.log(Level.INFO, "Bootstrap test passed? " + passed);
76 return passed;
79 private static void usage() {
80 System.out.println();
81 System.out.println("usage:");
82 System.out.println("java com.sun.star.comp.helper.Bootstrap_Test ini-file name=value ...");
83 System.out.println("example:");
84 System.out.println("java com.sun.star.comp.helper.Bootstrap_Test file:///c:/ooo10/program/uno.ini SYSBINDIR=file:///c:/ooo10/program");
85 System.exit( -1 );
88 public static void main(String args[]) throws java.lang.Exception {
89 if ( args.length == 0 )
90 usage();
92 java.util.HashMap<String,String> bootstrap_parameters = new java.util.HashMap<String,String>();
93 for ( int nPos = 1; nPos < args.length; ++nPos ) {
94 if (args[nPos].contains("=")) {
95 String bootstrap_parameter[] = args[nPos].split("=",2);
96 if (bootstrap_parameter[0].length() > 0) {
97 bootstrap_parameters.put( bootstrap_parameter[0], bootstrap_parameter[1] );
98 } else {
99 System.out.println();
100 System.out.println("The 1st argument in a bootstrap parameter is the key of a HashMap element and can't be null : '" + args[nPos] + "'");
101 usage();
103 } else {
104 System.out.println();
105 System.out.println("Missing '=' in bootstrap parameter : '" + args[nPos] + "'");
106 usage();
110 System.exit( test(args[0], bootstrap_parameters) ? 0: -1 );