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 .
20 import lib
.MultiMethodTest
;
22 import lib
.StatusException
;
23 import util
.RegistryTools
;
25 import com
.sun
.star
.registry
.InvalidRegistryException
;
26 import com
.sun
.star
.registry
.XRegistryKey
;
27 import com
.sun
.star
.registry
.XSimpleRegistry
;
31 * Testing <code>com.sun.star.registry.XSimpleRegistry</code>
34 * <li><code> getURL()</code></li>
35 * <li><code> open()</code></li>
36 * <li><code> isValid()</code></li>
37 * <li><code> close()</code></li>
38 * <li><code> destroy()</code></li>
39 * <li><code> getRootKey()</code></li>
40 * <li><code> isReadOnly()</code></li>
41 * <li><code> mergeKey()</code></li>
43 * This test needs the following object relations :
45 * <li> <code>'NR'</code> <b>optional</b> (of type <code>String</code>):
46 * if this object relation isn't null than the testing component
47 * doesn't support some methods of the interface
48 * (<code>open(), close(), destroy()</code>)</li>
49 * <li> <code>'XSimpleRegistry.open'</code> (of type <code>String</code>):
50 * The full system path to the registry file which is opened and modified.
52 * <li> <code>'XSimpleRegistry.destroy'</code> (of type <code>String</code>):
53 * The full system path to the registry file which is destroyed.
55 * <li> <code>'XSimpleRegistry.merge'</code> (of type <code>String</code>):
56 * The full system path to the registry file which is merged with the
60 * @see com.sun.star.registry.XSimpleRegistry
62 public class _XSimpleRegistry
extends MultiMethodTest
{
63 public XSimpleRegistry oObj
= null;
64 protected String nr
= null;
65 protected boolean configuration
= false;
66 protected String openF
= null;
67 protected String destroyF
= null;
68 protected String mergeF
= null;
71 * Retrieves object relations.
72 * @throws StatusException If one of required relations not found.
75 protected void before() {
76 if (tEnv
.getObjRelation("configuration") != null) {
80 nr
= (String
) tEnv
.getObjRelation("NR");
82 openF
= (String
) tEnv
.getObjRelation("XSimpleRegistry.open");
85 throw new StatusException(Status
.failed(
86 "Relation 'XSimpleRegistry.open' not found"));
89 destroyF
= (String
) tEnv
.getObjRelation("XSimpleRegistry.destroy");
91 if (destroyF
== null) {
92 throw new StatusException(Status
.failed(
93 "Relation 'XSimpleRegistry.destroy' not found"));
96 mergeF
= (String
) tEnv
.getObjRelation("XSimpleRegistry.merge");
99 throw new StatusException(Status
.failed(
100 "Relation 'XSimpleRegistry.merge' not found"));
105 * If the method is supported opens the registry key with the URL
106 * from <code>'XSimpleRegistry.open'</code> relation, then closes it. <p>
108 * Has <b> OK </b> status if the method isn't supported by the component
109 * (the object relation <code>'NR'</code> isn't null) or no exceptions were
110 * thrown during open/close operations. <p>
112 public void _open() {
114 log
.println("'open()' isn't supported by '" + nr
+ "'");
115 tRes
.tested("open()", true);
120 log
.println("Trying to open registry :" + openF
);
123 oObj
.open(openF
, false, true);
125 } catch (InvalidRegistryException e
) {
126 e
.printStackTrace(log
);
127 tRes
.tested("open()", false);
132 tRes
.tested("open()", true);
136 * Test opens the registry key with the URL from
137 * <code>'XSimpleRegistry.open'</code> relation not only for read,
138 * calls the method, checks returned value and closes the registry. <p>
140 * Has <b> OK </b> status if returned value is false and no exceptions were
143 public void _isReadOnly() {
144 boolean result
= false;
147 openReg(oObj
, openF
, false, true);
148 result
= !oObj
.isReadOnly();
150 } catch (InvalidRegistryException e
) {
151 e
.printStackTrace(log
);
155 tRes
.tested("isReadOnly()", result
);
159 * Test opens the registry key with the URL from
160 * <code>'XSimpleRegistry.open'</code> relation, calls the method,
161 * checks returned value and closes the registry key. <p>
163 * Has <b>OK</b> status if returned value isn't null and no exceptions were
166 public void _getRootKey() {
167 boolean result
= false;
170 openReg(oObj
, openF
, false, true);
172 XRegistryKey rootKey
= oObj
.getRootKey();
173 result
= rootKey
!= null;
175 } catch (InvalidRegistryException e
) {
176 e
.printStackTrace(log
);
180 tRes
.tested("getRootKey()", result
);
184 * Merges the current registry with the registry from URL got from
185 * <code>'XSimpleRegistry.merge'</code> relation under 'MergeKey' key.
186 * Then the keys of these two registries retrieved :
188 * <li> Root key from 'XSimpleRegistry.merge' registry </li>
189 * <li> 'MergeKey' key from the current registry </li>
191 * Then these two keys are recursively compared. <p>
193 * Has <b> OK </b> status if the method isn't supported by the component
194 * (the object relation <code>'NR'</code> isn't null)
196 * if it's supported and after successful merging the keys mentioned
197 * above are recursively equal. <p>
199 public void _mergeKey() {
202 "You can't merge into this registry. It's just a wrapper for a configuration node, which has a fixed structure which can not be modified");
203 tRes
.tested("mergeKey()", true);
209 log
.println("'mergeKey()' isn't supported by '" + nr
+ "'");
210 tRes
.tested("mergeKey()", true);
215 openReg(oObj
, openF
, false, true);
218 RegistryTools
.printRegistryInfo(oObj
.getRootKey(), log
);
219 oObj
.mergeKey("MergeKey", mergeF
);
220 RegistryTools
.printRegistryInfo(oObj
.getRootKey(), log
);
221 } catch (com
.sun
.star
.registry
.MergeConflictException e
) {
222 e
.printStackTrace(log
);
223 tRes
.tested("mergeKey()", false);
226 } catch (com
.sun
.star
.registry
.InvalidRegistryException e
) {
227 e
.printStackTrace(log
);
228 tRes
.tested("mergeKey()", false);
233 boolean isEqual
= false;
234 XSimpleRegistry reg
= null;
237 reg
= RegistryTools
.createRegistryService(tParam
.getMSF());
238 } catch (com
.sun
.star
.uno
.Exception e
) {
239 log
.print("Can't create registry service: ");
240 e
.printStackTrace(log
);
241 tRes
.tested("mergeKey()", false);
246 openReg(reg
, mergeF
, false, true);
249 XRegistryKey key
= oObj
.getRootKey().openKey("MergeKey");
250 XRegistryKey mergeKey
= reg
.getRootKey();
251 isEqual
= RegistryTools
.compareKeyTrees(key
, mergeKey
);
252 } catch (com
.sun
.star
.registry
.InvalidRegistryException e
) {
253 log
.print("Can't get root key: ");
254 e
.printStackTrace(log
);
255 tRes
.tested("mergeKey()", false);
263 tRes
.tested("mergeKey()", isEqual
);
267 * Test opens the registry key with the URL from
268 * <code>'XSimpleRegistry.open'</code> relation, calls the method,
269 * checks returned value and closes the registry key. <p>
271 * Has <b> OK </b> status if returned value isn't null and if length of the
272 * returned string is greater than 0. <p>
274 public void _getURL() {
275 openReg(oObj
, openF
, false, true);
277 String url
= oObj
.getURL();
279 log
.println("Getting URL: " + url
+";");
280 tRes
.tested("getURL()", (url
!= null));
284 * Test checks value returned by the object relation <code>'NR'</code>,
285 * opens the registry key with the URL from
286 * <code>XSimpleRegistry.open'</code> relation, calls the method
287 * and checks the validity of the registry key. <p>
289 * Has <b> OK </b> status if the registry key isn't valid after the method
290 * call, or if the method isn't supported by the component (the object
291 * relation <code>'NR'</code> isn't null). <p>
293 public void _close() {
295 log
.println("'close()' isn't supported by '" + nr
+ "'");
296 tRes
.tested("close()", true);
302 oObj
.open(openF
, false, true);
304 } catch (com
.sun
.star
.registry
.InvalidRegistryException e
) {
305 e
.printStackTrace(log
);
306 tRes
.tested("close()", false);
311 tRes
.tested("close()", !oObj
.isValid());
315 * Test checks value returned by the object relation <code>'NR'</code>,
316 * opens the registry key with the URL from
317 * <code>'XSimpleRegistry.destroy'</code> relation, calls the method
318 * and checks the validity of the registry key. <p>
320 * Has <b> OK </b> status if the registry key isn't valid after the method
321 * call, or if the method isn't supported by the component (the object
322 * relation <code>'NR'</code> isn't null). <p>
324 public void _destroy() {
327 "This registry is a wrapper for a configuration access. It can not be destroyed.");
328 tRes
.tested("destroy()", true);
334 log
.println("'destroy()' isn't supported by '" + nr
+ "'");
335 tRes
.tested("destroy()", true);
341 oObj
.open(destroyF
, false, true);
343 } catch (com
.sun
.star
.registry
.InvalidRegistryException e
) {
344 e
.printStackTrace(log
);
345 tRes
.tested("destroy()", false);
350 tRes
.tested("destroy()", !oObj
.isValid());
354 * Test opens the registry key with the URL from
355 * <code>'XSimpleRegistry.open'</code> relation, calls the method,
356 * checks returned value and closes the registry key. <p>
357 * Has <b> OK </b> status if returned value is true. <p>
359 public void _isValid() {
360 boolean valid
= true;
362 openReg(oObj
, openF
, false, true);
363 valid
= oObj
.isValid();
366 tRes
.tested("isValid()", valid
);
370 * Method calls <code>close()</code> of the interface
371 * <code>com.sun.star.registry.XRegistryKey</code>. <p>
372 * @param reg interface <code>com.sun.star.registry.XRegistryKey</code>
373 * @param url specifies the complete URL to access the data source
374 * @param arg1 specifies if the data source should be opened for read only
375 * @param arg2 specifies if the data source should be created if it does not
378 public void openReg(XSimpleRegistry reg
, String url
, boolean arg1
,
382 reg
.open(url
, arg1
, arg2
);
383 } catch (com
.sun
.star
.registry
.InvalidRegistryException e
) {
384 log
.print("Couldn't open registry:");
385 e
.printStackTrace(log
);
391 * Method calls <code>close()</code> of the interface
392 * <code>com.sun.star.registry.XRegistryKey</code>. <p>
393 * @param reg <code>com.sun.star.registry.XRegistryKey</code>
395 public void closeReg(XSimpleRegistry reg
) {
399 } catch (com
.sun
.star
.registry
.InvalidRegistryException e
) {
400 log
.print("Couldn't close registry:");
401 e
.printStackTrace(log
);