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 .
22 import java
.io
.FileInputStream
;
23 import java
.io
.FileOutputStream
;
24 import java
.io
.PrintWriter
;
27 import lib
.TestEnvironment
;
28 import lib
.TestParameters
;
29 import util
.RegistryTools
;
32 import com
.sun
.star
.lang
.XMultiServiceFactory
;
33 import com
.sun
.star
.registry
.XSimpleRegistry
;
34 import com
.sun
.star
.uno
.XInterface
;
37 * Test for object which is represented by service
38 * <code>com.sun.star.registry.NestedRegistry</code>. <p>
39 * Object implements the following interfaces :
41 * <li> <code>com::sun::star::registry::XSimpleRegistry</code></li>
42 * <li> <code>com::sun::star::lang::XInitialization</code></li>
44 * The following files used by this test :
46 * <li><b> XSimpleRegistry.rdb </b> : Registry file created before. </li>
47 * <li><b> XSimpleRegistry_open#.rdb </b> : Temporary registry file as copy of
48 * <b> XSimpleRegistry.rdb </b> in the SOffice temp directory.
49 * ('#' - is an ordinary number) </li>
50 * <li><b> XSimpleRegistry_merge#.rdb </b> : Temporary registry file as copy of
51 * <b> XSimpleRegistry.rdb </b> in the SOffice temp directory.
52 * ('#' - is an ordinary number) </li>
54 * This object test <b> is NOT </b> designed to be run in several
55 * threads concurrently.
56 * @see com.sun.star.registry.XSimpleRegistry
57 * @see com.sun.star.lang.XInitialization
58 * @see ifc.registry._XSimpleRegistry
59 * @see ifc.lang._XInitialization
61 public class NestedRegistry
extends TestCase
{
63 protected static int uniq
= 0 ;
68 public synchronized void disposeTestEnvironment( TestEnvironment tEnv
,
69 TestParameters tParam
) {
74 catch (com
.sun
.star
.registry
.InvalidRegistryException e
) {
75 System
.out
.println("caught exception: " + e
);
80 * Creates a temporary copy of file, which is deleted when VM exits.
81 * @param src Source file path.
82 * @param dst Destination file path.
83 * @throws java.io.IOException If any problems occur during copying.
85 protected void copyFile(String src
, String dst
, PrintWriter log
)
86 throws java
.io
.IOException
{
87 log
.println("Copy File "+src
+" to "+dst
);
88 File srcF
= new File(src
) ;
89 File dstF
= new File(dst
) ;
92 boolean bDeleteOk
= dstF
.delete();
94 System
.out
.println("delete failed");
98 boolean bCreateOk
= dstF
.createNewFile();
100 System
.out
.println("create failed");
103 dstF
.deleteOnExit() ;
105 FileInputStream fIn
= new FileInputStream(srcF
) ;
106 FileOutputStream fOut
= new FileOutputStream(dstF
) ;
108 byte[] buf
= new byte[1024] ;
110 while ((bytesRead
= fIn
.read(buf
)) > 0) {
111 fOut
.write(buf
, 0, bytesRead
) ;
120 * Creating a TestEnvironment for the interfaces to be tested.
121 * Creates two temporary copies of registry file created before, opens
122 * them, and creates service <code>com.sun.star.comp.stoc.NestedRegistry</code>
123 * with these two registries. <p>
124 * Object relations created :
126 * <li> <code>'NR'</code> for {@link ifc.registry._XSimpleRegistry} :
127 * Just informs interface test that <code>NestedRegistry</code>
128 * service is tested. If this relation exists, then some methods
129 * are not supported. The relation is a <code>String</code> with
131 * <li> <code>'XSimpleRegistry.open'</code> for
132 * {@link ifc.registry._XSimpleRegistry}
134 * <li> <code>'XSimpleRegistry.destroy'</code> for
135 * {@link ifc.registry._XSimpleRegistry}
137 * <li> <code>'XSimpleRegistry.merge'</code> for
138 * {@link ifc.registry._XSimpleRegistry}
143 public TestEnvironment
createTestEnvironment( TestParameters Param
,
146 XInterface oObj
= null;
147 Object oInterface
= null;
149 final String tmpDir
= utils
.getOfficeTempDirSys(Param
.getMSF()) ;
150 final String openF
= tmpDir
+ "XSimpleRegistry_open" + uniq
+ ".rdb" ;
151 final String destroyF
= tmpDir
152 + "XSimpleRegistry_destroy" + uniq
+ ".rdb" ;
153 final String mergeF
= tmpDir
+ "XSimpleRegistry_merge" + uniq
+ ".rdb" ;
156 log
.println("creating copies of the registry for XSimpleRegistry");
157 String source
= utils
.getFullTestDocName("XSimpleRegistry.rdb");
158 copyFile(source
, openF
, log
) ;
159 copyFile(source
, mergeF
, log
) ;
162 XMultiServiceFactory xMSF
= Param
.getMSF();
163 reg1
= RegistryTools
.
164 createRegistryService(xMSF
) ;
165 reg1
.open(mergeF
, false, true) ;
166 reg2
= RegistryTools
.
167 createRegistryService(xMSF
) ;
168 reg2
.open(openF
, false, true) ;
169 XSimpleRegistry
[] arg
= new XSimpleRegistry
[2];
172 oInterface
= xMSF
.createInstanceWithArguments
173 ( "com.sun.star.comp.stoc.NestedRegistry", arg
);
175 catch( Exception e
) {
176 log
.println("Introspection Service not available" );
178 oObj
= (XInterface
) oInterface
;
182 log
.println( " creating a new environment for Introspection object" );
183 TestEnvironment tEnv
= new TestEnvironment( oObj
);
185 tEnv
.addObjRelation("NR","NestedRegistry");
187 tEnv
.addObjRelation("XSimpleRegistry.open", openF
) ;
188 tEnv
.addObjRelation("XSimpleRegistry.merge", mergeF
) ;
189 tEnv
.addObjRelation("XSimpleRegistry.destroy", destroyF
) ;
192 } // finish method getTestEnvironment
195 protected void cleanup( TestParameters Param
, PrintWriter log
) {
200 } // finish class NestedRegistry