1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
30 import lib
.MultiMethodTest
;
31 import lib
.StatusException
;
32 import util
.RegistryTools
;
34 import com
.sun
.star
.lang
.XMultiServiceFactory
;
35 import com
.sun
.star
.lang
.XServiceInfo
;
36 import com
.sun
.star
.loader
.CannotActivateFactoryException
;
37 import com
.sun
.star
.loader
.XImplementationLoader
;
38 import com
.sun
.star
.registry
.CannotRegisterImplementationException
;
39 import com
.sun
.star
.registry
.XRegistryKey
;
40 import com
.sun
.star
.registry
.XSimpleRegistry
;
41 import com
.sun
.star
.uno
.UnoRuntime
;
42 import com
.sun
.star
.uno
.XInterface
;
45 * Testing <code>com.sun.star.loader.XImplementationLoader</code>
48 * <li><code> activate()</code></li>
49 * <li><code> writeRegistryInfo()</code></li>
52 * The following object relations required :
54 * <li> <code>'ImplementationLoader'</code> : service which is
55 * responsible for loading implementations. </li>
56 * <li> <code>'ImplementationUrl'</code> : implementation file location. </li>
57 * <li> <code>'ImplementationName'</code> : Name of the implementation.</li>
59 * Object has to be recreated after this test. <p>
60 * Test is <b> Not </b> multithread compilant.
62 public class _XImplementationLoader
extends MultiMethodTest
{
64 public XImplementationLoader oObj
= null;
65 private String implLoader
= null ;
66 private String implUrl
= null ;
67 private String implName
= null ;
70 * Retrieves object relations.
71 * @throws StatusException If one of relations not found.
73 public void before() {
74 implLoader
= (String
) tEnv
.getObjRelation("ImplementationLoader") ;
75 implUrl
= (String
) tEnv
.getObjRelation("ImplementationUrl") ;
76 implName
= (String
) tEnv
.getObjRelation("ImplementationName") ;
78 if (implLoader
== null || implUrl
== null || implName
== null)
79 throw new StatusException("One of object relations not found",
80 new NullPointerException()) ;
84 * First registry file created, and the root key retrieved.
85 * Then method <code>writeRegistryInfo</code> called and it must
86 * write some info into the registry root key. After all registry
88 * Has OK status if some info was written into registry.
90 public void _writeRegistryInfo() {
92 XSimpleRegistry xReg
= null ;
94 String tmpDir
= util
.utils
.getOfficeTempDir((XMultiServiceFactory
)tParam
.getMSF());
97 xReg
= RegistryTools
.createRegistryService
98 ((XMultiServiceFactory
)tParam
.getMSF()) ;
100 xReg
.open(tmpDir
+ "XImpLoader_tmp.rdb", false, true) ;
102 key
= xReg
.getRootKey() ;
103 } catch (com
.sun
.star
.uno
.Exception e
) {
104 log
.println("Can not create registry for writing") ;
105 e
.printStackTrace(log
) ;
106 tRes
.tested("writeRegistryInfo()", false) ;
112 rc
= oObj
.writeRegistryInfo(key
, implLoader
, implUrl
) ;
113 } catch (CannotRegisterImplementationException e
) {
114 throw new StatusException("Can not register implementation", e
) ;
118 log
.println("Method returned false value") ;
122 keys
= key
.getKeyNames() ;
123 } catch (com
.sun
.star
.uno
.Exception e
) {
124 log
.println("Error retrieving key names from registry") ;
125 tRes
.tested("writeRegistryInfo()", false) ;
129 // destroying registry file
133 } catch (com
.sun
.star
.registry
.InvalidRegistryException e
) {
134 log
.println("Can't destroy registry file.") ;
137 tRes
.tested("writeRegistryInfo()", rc
&& keys
.length
> 0) ;
141 * Tries to activate the implementation. <p>
143 * Has OK status if not <code>null</code> value returned by method,
144 * if its implementation name is the same as expected.
146 public void _activate() {
148 XInterface factory
= null ;
151 factory
= (XInterface
) oObj
.activate
152 (implName
, implLoader
, implUrl
, null) ;
153 } catch (CannotActivateFactoryException e
) {
154 throw new StatusException("Can not activate factory", e
) ;
157 XServiceInfo xServInf
= (XServiceInfo
) UnoRuntime
.queryInterface
158 (XServiceInfo
.class, factory
) ;
160 if (xServInf
== null) {
161 if (factory
== null) {
162 log
.println("activate() returns null - FAILED.");
164 log
.println("Activated impementation doesn't support "+
165 "XServiceInfo - FAILED.");
169 String gImpName
= xServInf
.getImplementationName() ;
170 log
.println("Implementation name returned :" + gImpName
);
172 if (!gImpName
.equals(implName
)) {
173 log
.println("!!! But other name was expected :" + implName
);
178 tRes
.tested("activate()", ok
) ;
182 * Forces object recreation.
184 public void after() {
185 this.disposeEnvironment() ;