tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / qadevOOo / tests / java / ifc / loader / _XImplementationLoader.java
blob1a8a05409d2e8d95d76f993f928fad2af1e920ea
1 /*
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 .
19 package ifc.loader;
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;
34 /**
35 * Testing <code>com.sun.star.loader.XImplementationLoader</code>
36 * interface methods :
37 * <ul>
38 * <li><code> activate()</code></li>
39 * <li><code> writeRegistryInfo()</code></li>
40 * </ul> <p>
42 * The following object relations required :
43 * <ul>
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>
48 * </ul> <p>
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 ;
59 /**
60 * Retrieves object relations.
61 * @throws StatusException If one of relations not found.
63 @Override
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()) ;
74 /**
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
78 * is destroyed.<p>
79 * Has OK status if some info was written into registry.
81 public void _writeRegistryInfo() {
82 XRegistryKey key ;
83 XSimpleRegistry xReg = null ;
85 String tmpDir = util.utils.getOfficeTempDir(tParam.getMSF());
87 try {
88 xReg = RegistryTools.createRegistryService
89 (tParam.getMSF()) ;
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) ;
98 return ;
101 boolean rc ;
102 try {
103 rc = oObj.writeRegistryInfo(key, implLoader, implUrl) ;
104 } catch (CannotRegisterImplementationException e) {
105 throw new StatusException("Can not register implementation", e) ;
108 if (!rc)
109 log.println("Method returned false value") ;
111 String[] keys ;
112 try {
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) ;
117 return ;
120 // destroying registry file
121 try {
122 xReg.close() ;
123 xReg.destroy() ;
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() {
138 boolean ok = true ;
139 XInterface factory = null ;
141 try {
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.");
154 } else {
155 log.println("Activated implementation doesn't support "+
156 "XServiceInfo - FAILED.");
158 ok = false ;
159 } else {
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);
165 ok = false ;
169 tRes.tested("activate()", ok) ;
173 * Forces object recreation.
175 @Override
176 public void after() {
177 this.disposeEnvironment() ;