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 .
21 import lib
.MultiMethodTest
;
22 import lib
.StatusException
;
23 import util
.RegistryTools
;
25 import com
.sun
.star
.lang
.XServiceInfo
;
26 import com
.sun
.star
.loader
.CannotActivateFactoryException
;
27 import com
.sun
.star
.loader
.XImplementationLoader
;
28 import com
.sun
.star
.registry
.CannotRegisterImplementationException
;
29 import com
.sun
.star
.registry
.XRegistryKey
;
30 import com
.sun
.star
.registry
.XSimpleRegistry
;
31 import com
.sun
.star
.uno
.UnoRuntime
;
32 import com
.sun
.star
.uno
.XInterface
;
35 * Testing <code>com.sun.star.loader.XImplementationLoader</code>
38 * <li><code> activate()</code></li>
39 * <li><code> writeRegistryInfo()</code></li>
42 * The following object relations required :
44 * <li> <code>'ImplementationLoader'</code> : service which is
45 * responsible for loading implementations. </li>
46 * <li> <code>'ImplementationUrl'</code> : implementation file location. </li>
47 * <li> <code>'ImplementationName'</code> : Name of the implementation.</li>
49 * Object has to be recreated after this test. <p>
50 * Test is <b> Not </b> multithread compliant.
52 public class _XImplementationLoader
extends MultiMethodTest
{
54 public XImplementationLoader oObj
= null;
55 private String implLoader
= null ;
56 private String implUrl
= null ;
57 private String implName
= null ;
60 * Retrieves object relations.
61 * @throws StatusException If one of relations not found.
64 public void before() {
65 implLoader
= (String
) tEnv
.getObjRelation("ImplementationLoader") ;
66 implUrl
= (String
) tEnv
.getObjRelation("ImplementationUrl") ;
67 implName
= (String
) tEnv
.getObjRelation("ImplementationName") ;
69 if (implLoader
== null || implUrl
== null || implName
== null)
70 throw new StatusException("One of object relations not found",
71 new NullPointerException()) ;
75 * First registry file created, and the root key retrieved.
76 * Then method <code>writeRegistryInfo</code> called and it must
77 * write some info into the registry root key. After all registry
79 * Has OK status if some info was written into registry.
81 public void _writeRegistryInfo() {
83 XSimpleRegistry xReg
= null ;
85 String tmpDir
= util
.utils
.getOfficeTempDir(tParam
.getMSF());
88 xReg
= RegistryTools
.createRegistryService
91 xReg
.open(tmpDir
+ "XImpLoader_tmp.rdb", false, true) ;
93 key
= xReg
.getRootKey() ;
94 } catch (com
.sun
.star
.uno
.Exception e
) {
95 log
.println("Can not create registry for writing") ;
96 e
.printStackTrace(log
) ;
97 tRes
.tested("writeRegistryInfo()", false) ;
103 rc
= oObj
.writeRegistryInfo(key
, implLoader
, implUrl
) ;
104 } catch (CannotRegisterImplementationException e
) {
105 throw new StatusException("Can not register implementation", e
) ;
109 log
.println("Method returned false value") ;
113 keys
= key
.getKeyNames() ;
114 } catch (com
.sun
.star
.uno
.Exception e
) {
115 log
.println("Error retrieving key names from registry") ;
116 tRes
.tested("writeRegistryInfo()", false) ;
120 // destroying registry file
124 } catch (com
.sun
.star
.registry
.InvalidRegistryException e
) {
125 log
.println("Can't destroy registry file.") ;
128 tRes
.tested("writeRegistryInfo()", rc
&& keys
.length
> 0) ;
132 * Tries to activate the implementation. <p>
134 * Has OK status if not <code>null</code> value returned by method,
135 * if its implementation name is the same as expected.
137 public void _activate() {
139 XInterface factory
= null ;
142 factory
= (XInterface
) oObj
.activate
143 (implName
, implLoader
, implUrl
, null) ;
144 } catch (CannotActivateFactoryException e
) {
145 throw new StatusException("Can not activate factory", e
) ;
148 XServiceInfo xServInf
= UnoRuntime
.queryInterface
149 (XServiceInfo
.class, factory
) ;
151 if (xServInf
== null) {
152 if (factory
== null) {
153 log
.println("activate() returns null - FAILED.");
155 log
.println("Activated implementation doesn't support "+
156 "XServiceInfo - FAILED.");
160 String gImpName
= xServInf
.getImplementationName() ;
161 log
.println("Implementation name returned :" + gImpName
);
163 if (!gImpName
.equals(implName
)) {
164 log
.println("!!! But other name was expected :" + implName
);
169 tRes
.tested("activate()", ok
) ;
173 * Forces object recreation.
176 public void after() {
177 this.disposeEnvironment() ;