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