bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / ifc / registry / _XImplementationRegistration.java
blobfaff40bb0e4e496bfb9eede7e115e7c88a6d7649
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 ifc.registry;
21 import com.sun.star.lang.XMultiServiceFactory;
22 import com.sun.star.registry.CannotRegisterImplementationException;
23 import com.sun.star.registry.XImplementationRegistration;
24 import com.sun.star.registry.XSimpleRegistry;
25 import com.sun.star.uno.RuntimeException;
26 import lib.MultiMethodTest;
27 import util.RegistryTools;
28 import util.utils;
30 /**
31 * Testing <code>com.sun.star.registry.XImplementationRegistration</code>
32 * interface methods :
33 * <ul>
34 * <li><code> registerImplementation()</code></li>
35 * <li><code> revokeImplementation()</code></li>
36 * <li><code> getImplementations()</code></li>
37 * <li><code> checkInstantiation()</code></li>
38 * </ul> <p>
39 * The following predefined files needed to complete the test:
40 * <ul>
41 * <li> <code>solibrary.jar</code> : jar file with implementation
42 * classes. One of the required implementation must have name
43 * <code>com.ivistaportal.solibrary.HistogramImpl</code> cause
44 * it is checked in <code>getImplementations</code> method. </li>
45 * <ul> <p>
46 * Test is <b> NOT </b> multithread compilant. <p>
47 * After test completion object environment has to be recreated.
48 * @see com.sun.star
50 public class _XImplementationRegistration extends MultiMethodTest {
52 public XImplementationRegistration oObj = null;
54 private String url = null ;
55 private String loader = null ;
56 private XSimpleRegistry reg = null ;
58 /**
59 * First a registry created and opened in the temporary directory
60 * of StarOffice. Then some implementations situated in JAR file
61 * is registered in the registry opened. <p>
62 * Has <b>OK</b> status if some information is written into registry.
65 public void _registerImplementation()
66 throws CannotRegisterImplementationException, RuntimeException
68 url = util.utils.getFullTestURL("qadevlibs/MyPersistObjectImpl.jar");
69 loader = "com.sun.star.loader.Java2";
70 boolean result = false ;
71 String name = null;
73 try {
74 name = utils.getOfficeTempDir((XMultiServiceFactory)tParam.getMSF()) +
75 "XImplementationRegistration_tmp.rdb";
76 reg = RegistryTools.openRegistry
77 (name, (XMultiServiceFactory)tParam.getMSF()) ;
79 oObj.registerImplementation(loader, url, reg) ;
81 RegistryTools.printRegistryInfo(reg.getRootKey(), log) ;
83 String[] subKeys = reg.getRootKey().getKeyNames() ;
85 result = subKeys != null && subKeys.length > 0 ;
87 } catch (com.sun.star.uno.Exception e) {
88 log.println("Can't open registry file: " + name) ;
89 e.printStackTrace(log) ;
91 tRes.tested("registerImplementation()", result) ;
94 /**
95 * Retrieves an array of implementation names and check them. <p>
96 * Has <b>OK</b> status if among them an implementation name
97 * <code>com.ivistaportal.solibrary.HistogramImpl</code> exists.
98 * The following method tests are to be completed successfully before :
99 * <ul>
100 * <li> <code> registerImplementation </code> </li>
101 * </ul>
103 public void _getImplementations() throws RuntimeException{
104 requiredMethod("registerImplementation()") ;
106 String[] impl = oObj.getImplementations(loader, url) ;
108 if (impl.length == 0) log.println("getImplementations() "+
109 "returns an empty array");
110 boolean result = false ;
111 log.println("Implementations found :") ;
112 for (int i = 0; i < impl.length; i++) {
113 log.println(" '" + impl[i] + "'") ;
114 if ("com.sun.star.cmp.MyPersistObject".
115 equals(impl[i])) {
117 result = true ;
118 break ;
124 tRes.tested("getImplementations()", result) ;
128 * Calls the method with
129 * <code>com.sun.star.comp.stoc.JavaComponentLoader</code>
130 * implementation name.<p>
131 * Has <b>OK</b> status if not null array returned. <p>
132 * The following method tests are to be completed successfully before :
133 * <ul>
134 * <li> <code> registerImplementation </code> </li>
135 * </ul>
137 public void _checkInstantiation() throws RuntimeException {
138 requiredMethod("registerImplementation()") ;
140 String[] inst = oObj.checkInstantiation(
141 "com.sun.star.comp.stoc.JavaComponentLoader") ;
143 tRes.tested("checkInstantiation()", inst != null) ;
147 * Revokes implementations from registry, and checks if
148 * all implementations' information is deleted. <p>
149 * Has <b>OK</b> status if registry has no key entries. <p>
150 * The following method tests are to be completed successfully before :
151 * <ul>
152 * <li> <code> registerImplementation </code> : to have
153 * implementation registered in registry. </li>
154 * </ul>
155 * The following method tests are to be executed before :
156 * <ul>
157 * <li> <code> getImplementations </code>
158 * <li> <code> checkInstantiation </code>
159 * </ul>
161 public void _revokeImplementation() throws RuntimeException{
162 requiredMethod("registerImplementation()") ;
164 executeMethod("getImplementations()") ;
165 executeMethod("checkInstantiation()") ;
167 oObj.revokeImplementation(url, reg);
168 RegistryTools.printRegistryInfo(reg, log) ;
170 try {
171 reg.getRootKey().getKeyNames();
172 } catch (com.sun.star.registry.InvalidRegistryException e) {
173 log.println("!!! Exception retrieving keys from registry :") ;
174 e.printStackTrace(log);
177 tRes.tested("revokeImplementation()", true) ;
180 public void after() {
181 this.disposeEnvironment() ;