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