1ef39d40dSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3ef39d40dSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4ef39d40dSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5ef39d40dSAndrew Rist  * distributed with this work for additional information
6ef39d40dSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7ef39d40dSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8ef39d40dSAndrew Rist  * "License"); you may not use this file except in compliance
9ef39d40dSAndrew Rist  * with the License.  You may obtain a copy of the License at
10ef39d40dSAndrew Rist  *
11ef39d40dSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12ef39d40dSAndrew Rist  *
13ef39d40dSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14ef39d40dSAndrew Rist  * software distributed under the License is distributed on an
15ef39d40dSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16ef39d40dSAndrew Rist  * KIND, either express or implied.  See the License for the
17ef39d40dSAndrew Rist  * specific language governing permissions and limitations
18ef39d40dSAndrew Rist  * under the License.
19ef39d40dSAndrew Rist  *
20ef39d40dSAndrew Rist  *************************************************************/
21ef39d40dSAndrew Rist 
22ef39d40dSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir package ifc.registry;
25cdf0e10cSrcweir 
26cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory;
27cdf0e10cSrcweir import com.sun.star.registry.CannotRegisterImplementationException;
28cdf0e10cSrcweir import com.sun.star.registry.XImplementationRegistration;
29cdf0e10cSrcweir import com.sun.star.registry.XSimpleRegistry;
30cdf0e10cSrcweir import com.sun.star.uno.RuntimeException;
31cdf0e10cSrcweir import lib.MultiMethodTest;
32cdf0e10cSrcweir import util.RegistryTools;
33cdf0e10cSrcweir import util.utils;
34cdf0e10cSrcweir 
35cdf0e10cSrcweir /**
36cdf0e10cSrcweir * Testing <code>com.sun.star.registry.XImplementationRegistration</code>
37cdf0e10cSrcweir * interface methods :
38cdf0e10cSrcweir * <ul>
39cdf0e10cSrcweir *  <li><code> registerImplementation()</code></li>
40cdf0e10cSrcweir *  <li><code> revokeImplementation()</code></li>
41cdf0e10cSrcweir *  <li><code> getImplementations()</code></li>
42cdf0e10cSrcweir *  <li><code> checkInstantiation()</code></li>
43cdf0e10cSrcweir * </ul> <p>
44cdf0e10cSrcweir * The following predefined files needed to complete the test:
45cdf0e10cSrcweir * <ul>
46cdf0e10cSrcweir *  <li> <code>solibrary.jar</code> : jar file with implementation
47cdf0e10cSrcweir *   classes. One of the required implementation must have name
48cdf0e10cSrcweir *   <code>com.ivistaportal.solibrary.HistogramImpl</code> cause
49cdf0e10cSrcweir *   it is checked in <code>getImplementations</code> method. </li>
50cdf0e10cSrcweir * <ul> <p>
51cdf0e10cSrcweir * Test is <b> NOT </b> multithread compilant. <p>
52cdf0e10cSrcweir * After test completion object environment has to be recreated.
53*e6b649b5SPedro Giffuni * @see com.sun.star
54cdf0e10cSrcweir */
55cdf0e10cSrcweir public class _XImplementationRegistration extends MultiMethodTest {
56cdf0e10cSrcweir 
57cdf0e10cSrcweir     public XImplementationRegistration oObj = null;
58cdf0e10cSrcweir 
59cdf0e10cSrcweir     private String url = null ;
60cdf0e10cSrcweir     private String loader = null ;
61cdf0e10cSrcweir     private XSimpleRegistry reg = null ;
62cdf0e10cSrcweir 
63cdf0e10cSrcweir     /**
64cdf0e10cSrcweir     * First a registry created and opened in the temporary directory
65cdf0e10cSrcweir     * of StarOffice. Then some implementations situated in JAR file
66cdf0e10cSrcweir     * is registered in the registry opened. <p>
67cdf0e10cSrcweir     * Has <b>OK</b> status if some information is written into registry.
68cdf0e10cSrcweir     *
69cdf0e10cSrcweir     */
_registerImplementation()70cdf0e10cSrcweir     public void _registerImplementation()
71cdf0e10cSrcweir         throws CannotRegisterImplementationException, RuntimeException
72cdf0e10cSrcweir     {
73cdf0e10cSrcweir         url = util.utils.getFullTestURL("qadevlibs/MyPersistObjectImpl.jar");
74cdf0e10cSrcweir         loader = "com.sun.star.loader.Java2";
75cdf0e10cSrcweir         boolean result = false ;
76cdf0e10cSrcweir         String name = null;
77cdf0e10cSrcweir 
78cdf0e10cSrcweir         try {
79cdf0e10cSrcweir             name = utils.getOfficeTempDir((XMultiServiceFactory)tParam.getMSF()) +
80cdf0e10cSrcweir                 "XImplementationRegistration_tmp.rdb";
81cdf0e10cSrcweir             reg = RegistryTools.openRegistry
82cdf0e10cSrcweir                 (name, (XMultiServiceFactory)tParam.getMSF()) ;
83cdf0e10cSrcweir 
84cdf0e10cSrcweir             oObj.registerImplementation(loader, url, reg) ;
85cdf0e10cSrcweir 
86cdf0e10cSrcweir             RegistryTools.printRegistryInfo(reg.getRootKey(), log) ;
87cdf0e10cSrcweir 
88cdf0e10cSrcweir             String[] subKeys = reg.getRootKey().getKeyNames() ;
89cdf0e10cSrcweir 
90cdf0e10cSrcweir             result = subKeys != null && subKeys.length > 0 ;
91cdf0e10cSrcweir 
92cdf0e10cSrcweir         } catch (com.sun.star.uno.Exception e) {
93cdf0e10cSrcweir             log.println("Can't open registry file: " + name) ;
94cdf0e10cSrcweir             e.printStackTrace(log) ;
95cdf0e10cSrcweir         }
96cdf0e10cSrcweir         tRes.tested("registerImplementation()", result) ;
97cdf0e10cSrcweir     }
98cdf0e10cSrcweir 
99cdf0e10cSrcweir     /**
100cdf0e10cSrcweir     * Retrieves an array of implementation names and check them. <p>
101cdf0e10cSrcweir     * Has <b>OK</b> status if among them an implementation name
102cdf0e10cSrcweir     * <code>com.ivistaportal.solibrary.HistogramImpl</code> exists.
103cdf0e10cSrcweir     * The following method tests are to be completed successfully before :
104cdf0e10cSrcweir     * <ul>
105cdf0e10cSrcweir     *  <li> <code> registerImplementation </code>  </li>
106cdf0e10cSrcweir     * </ul>
107cdf0e10cSrcweir     */
_getImplementations()108cdf0e10cSrcweir     public void _getImplementations() throws RuntimeException{
109cdf0e10cSrcweir         requiredMethod("registerImplementation()") ;
110cdf0e10cSrcweir 
111cdf0e10cSrcweir         String[] impl = oObj.getImplementations(loader, url) ;
112cdf0e10cSrcweir 
113cdf0e10cSrcweir         if (impl.length == 0) log.println("getImplementations() "+
114cdf0e10cSrcweir             "returns an empty array");
115cdf0e10cSrcweir         boolean result = false ;
116cdf0e10cSrcweir         log.println("Implementations found :") ;
117cdf0e10cSrcweir         for (int i = 0; i < impl.length; i++) {
118cdf0e10cSrcweir             log.println(" '" + impl[i] + "'") ;
119cdf0e10cSrcweir             if ("com.sun.star.cmp.MyPersistObject".
120cdf0e10cSrcweir                 equals(impl[i])) {
121cdf0e10cSrcweir 
122cdf0e10cSrcweir                 result = true ;
123cdf0e10cSrcweir                 break ;
124cdf0e10cSrcweir             }
125cdf0e10cSrcweir         }
126cdf0e10cSrcweir 
127cdf0e10cSrcweir 
128cdf0e10cSrcweir 
129cdf0e10cSrcweir         tRes.tested("getImplementations()", result) ;
130cdf0e10cSrcweir     }
131cdf0e10cSrcweir 
132cdf0e10cSrcweir     /**
133cdf0e10cSrcweir     * Calls the method with
134cdf0e10cSrcweir     * <code>com.sun.star.comp.stoc.JavaComponentLoader</code>
135cdf0e10cSrcweir     * implementation name.<p>
136cdf0e10cSrcweir     * Has <b>OK</b> status if not null array returned. <p>
137cdf0e10cSrcweir     * The following method tests are to be completed successfully before :
138cdf0e10cSrcweir     * <ul>
139cdf0e10cSrcweir     *  <li> <code> registerImplementation </code>  </li>
140cdf0e10cSrcweir     * </ul>
141cdf0e10cSrcweir     */
_checkInstantiation()142cdf0e10cSrcweir     public void _checkInstantiation() throws RuntimeException {
143cdf0e10cSrcweir         requiredMethod("registerImplementation()") ;
144cdf0e10cSrcweir 
145cdf0e10cSrcweir         String[] inst = oObj.checkInstantiation(
146cdf0e10cSrcweir             "com.sun.star.comp.stoc.JavaComponentLoader") ;
147cdf0e10cSrcweir 
148cdf0e10cSrcweir         tRes.tested("checkInstantiation()", inst != null) ;
149cdf0e10cSrcweir     }
150cdf0e10cSrcweir 
151cdf0e10cSrcweir     /**
152cdf0e10cSrcweir     * Revokes implementations from registry, and checks if
153cdf0e10cSrcweir     * all implementations' information is deleted. <p>
154cdf0e10cSrcweir     * Has <b>OK</b> status if registry has no key entries. <p>
155cdf0e10cSrcweir     * The following method tests are to be completed successfully before :
156cdf0e10cSrcweir     * <ul>
157cdf0e10cSrcweir     *  <li> <code> registerImplementation </code> : to have
158cdf0e10cSrcweir     *   implementation registered in registry. </li>
159cdf0e10cSrcweir     * </ul>
160cdf0e10cSrcweir     * The following method tests are to be executed before :
161cdf0e10cSrcweir     * <ul>
162cdf0e10cSrcweir     *  <li> <code> getImplementations </code>
163cdf0e10cSrcweir     *  <li> <code> checkInstantiation </code>
164cdf0e10cSrcweir     * </ul>
165cdf0e10cSrcweir     */
_revokeImplementation()166cdf0e10cSrcweir     public void _revokeImplementation() throws RuntimeException{
167cdf0e10cSrcweir         boolean result = false ;
168cdf0e10cSrcweir 
169cdf0e10cSrcweir         requiredMethod("registerImplementation()") ;
170cdf0e10cSrcweir 
171cdf0e10cSrcweir         executeMethod("getImplementations()") ;
172cdf0e10cSrcweir         executeMethod("checkInstantiation()") ;
173cdf0e10cSrcweir 
174cdf0e10cSrcweir         oObj.revokeImplementation(url, reg);
175cdf0e10cSrcweir         RegistryTools.printRegistryInfo(reg, log) ;
176cdf0e10cSrcweir 
177cdf0e10cSrcweir         try {
178cdf0e10cSrcweir             String[] subKeys = reg.getRootKey().getKeyNames() ;
179cdf0e10cSrcweir 
180cdf0e10cSrcweir             result = subKeys == null || subKeys.length == 0 ;
181cdf0e10cSrcweir         } catch (com.sun.star.registry.InvalidRegistryException e) {
182cdf0e10cSrcweir             log.println("!!! Exception retrieving keys from registry :") ;
183cdf0e10cSrcweir             e.printStackTrace(log);
184cdf0e10cSrcweir         }
185cdf0e10cSrcweir 
186cdf0e10cSrcweir         tRes.tested("revokeImplementation()", true) ;
187cdf0e10cSrcweir     }
188cdf0e10cSrcweir 
after()189cdf0e10cSrcweir     public void after() {
190cdf0e10cSrcweir         this.disposeEnvironment() ;
191cdf0e10cSrcweir     }
192cdf0e10cSrcweir }
193cdf0e10cSrcweir 
194cdf0e10cSrcweir 
195