Version 3.6.0.4, tag libreoffice-3.6.0.4
[LibreOffice.git] / qadevOOo / tests / java / ifc / loader / _XImplementationLoader.java
blob47918fef95af53d64a1942f43239f813baa11646
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 ************************************************************************/
28 package ifc.loader;
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;
44 /**
45 * Testing <code>com.sun.star.loader.XImplementationLoader</code>
46 * interface methods :
47 * <ul>
48 * <li><code> activate()</code></li>
49 * <li><code> writeRegistryInfo()</code></li>
50 * </ul> <p>
52 * The following object relations required :
53 * <ul>
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>
58 * </ul> <p>
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 ;
69 /**
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()) ;
83 /**
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
87 * is destroyed.<p>
88 * Has OK status if some info was written into registry.
90 public void _writeRegistryInfo() {
91 XRegistryKey key ;
92 XSimpleRegistry xReg = null ;
94 String tmpDir = util.utils.getOfficeTempDir((XMultiServiceFactory)tParam.getMSF());
96 try {
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) ;
107 return ;
110 boolean rc ;
111 try {
112 rc = oObj.writeRegistryInfo(key, implLoader, implUrl) ;
113 } catch (CannotRegisterImplementationException e) {
114 throw new StatusException("Can not register implementation", e) ;
117 if (rc == false)
118 log.println("Method returned false value") ;
120 String[] keys ;
121 try {
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) ;
126 return ;
129 // destroying registry file
130 try {
131 xReg.close() ;
132 xReg.destroy() ;
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() {
147 boolean ok = true ;
148 XInterface factory = null ;
150 try {
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.");
163 } else {
164 log.println("Activated impementation doesn't support "+
165 "XServiceInfo - FAILED.");
167 ok = false ;
168 } else {
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);
174 ok = false ;
178 tRes.tested("activate()", ok) ;
182 * Forces object recreation.
184 public void after() {
185 this.disposeEnvironment() ;