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
;
26 import lib
.StatusException
;
28 import lib
.TestEnvironment
;
29 import lib
.TestParameters
;
30 import util
.RegistryTools
;
33 import com
.sun
.star
.lang
.XMultiServiceFactory
;
34 import com
.sun
.star
.registry
.XSimpleRegistry
;
35 import com
.sun
.star
.uno
.XInterface
;
38 * Test for object which is represented by service
39 * <code>com.sun.star.registry.NestedRegistry</code>. <p>
40 * Object implements the following interfaces :
42 * <li> <code>com::sun::star::registry::XSimpleRegistry</code></li>
43 * <li> <code>com::sun::star::lang::XInitialization</code></li>
45 * The following files used by this test :
47 * <li><b> XSimpleRegistry.rdb </b> : Registry file created before. </li>
48 * <li><b> XSimpleRegistry_open#.rdb </b> : Temporary registry file as copy of
49 * <b> XSimpleRegistry.rdb </b> in the SOffice temp directory.
50 * ('#' - is an ordinary number) </li>
51 * <li><b> XSimpleRegistry_merge#.rdb </b> : Temporary registry file as copy of
52 * <b> XSimpleRegistry.rdb </b> in the SOffice temp directory.
53 * ('#' - is an ordinary number) </li>
55 * This object test <b> is NOT </b> designed to be run in several
56 * threads concurently.
57 * @see com.sun.star.registry.XSimpleRegistry
58 * @see com.sun.star.lang.XInitialization
59 * @see ifc.registry._XSimpleRegistry
60 * @see ifc.lang._XInitialization
62 public class NestedRegistry
extends TestCase
{
64 protected static int uniq
= 0 ;
69 public synchronized void disposeTestEnvironment( TestEnvironment tEnv
,
70 TestParameters tParam
) {
75 catch (com
.sun
.star
.registry
.InvalidRegistryException e
) {}
79 * Creates a temporary copy of file, which is deleted when VM exits.
80 * @param src Source file path.
81 * @param dst Destination file path.
82 * @throws java.io.IOException If any problems occur during copiing.
84 protected void copyFile(String src
, String dst
, PrintWriter log
)
85 throws java
.io
.IOException
{
86 log
.println("Copy File "+src
+" to "+dst
);
87 File srcF
= new File(src
) ;
88 File dstF
= new File(dst
) ;
90 if (dstF
.exists()) dstF
.delete() ;
91 dstF
.createNewFile() ;
95 FileInputStream fIn
= new FileInputStream(srcF
) ;
96 FileOutputStream fOut
= new FileOutputStream(dstF
) ;
98 byte[] buf
= new byte[1024] ;
100 while ((bytesRead
= fIn
.read(buf
)) > 0) {
101 fOut
.write(buf
, 0, bytesRead
) ;
110 * Creating a Testenvironment for the interfaces to be tested.
111 * Creates two temporary copies of registry file created before, opens
112 * them, and creates service <code>com.sun.star.comp.stoc.NestedRegistry</code>
113 * with these two registries. <p>
114 * Object relations created :
116 * <li> <code>'NR'</code> for {@link ifc.registry._XSimpleRegistry} :
117 * Just informs interface test that <code>NestedRegistry</code>
118 * service is tested. If this relation exists, than some methods
119 * are not supported. The relation is a <code>String</code> with
121 * <li> <code>'XSimpleRegistry.open'</code> for
122 * {@link ifc.registry._XSimpleRegistry}
124 * <li> <code>'XSimpleRegistry.destroy'</code> for
125 * {@link ifc.registry._XSimpleRegistry}
127 * <li> <code>'XSimpleRegistry.merge'</code> for
128 * {@link ifc.registry._XSimpleRegistry}
133 public TestEnvironment
createTestEnvironment( TestParameters Param
,
135 throws StatusException
{
136 XInterface oObj
= null;
137 Object oInterface
= null;
139 final String tmpDir
= utils
.getOfficeTempDirSys(Param
.getMSF()) ;
140 final String openF
= tmpDir
+ "XSimpleRegistry_open" + uniq
+ ".rdb" ;
141 final String destroyF
= tmpDir
142 + "XSimpleRegistry_destroy" + uniq
+ ".rdb" ;
143 final String mergeF
= tmpDir
+ "XSimpleRegistry_merge" + uniq
+ ".rdb" ;
146 log
.println("creating copies of the registry for XSimpleRegistry");
148 String source
= utils
.getFullTestDocName("XSimpleRegistry.rdb");
149 copyFile(source
, openF
, log
) ;
150 copyFile(source
, mergeF
, log
) ;
151 } catch (java
.io
.IOException e
) {
152 log
.println("Exception occurred while copying files");
153 e
.printStackTrace(log
);
154 throw new StatusException("Exception occurred while copying files", e
);
158 XMultiServiceFactory xMSF
= Param
.getMSF();
159 reg1
= RegistryTools
.
160 createRegistryService(xMSF
) ;
161 reg1
.open(mergeF
, false, true) ;
162 reg2
= RegistryTools
.
163 createRegistryService(xMSF
) ;
164 reg2
.open(openF
, false, true) ;
165 XSimpleRegistry
[] arg
= new XSimpleRegistry
[2];
168 oInterface
= xMSF
.createInstanceWithArguments
169 ( "com.sun.star.comp.stoc.NestedRegistry", arg
);
171 catch( Exception e
) {
172 log
.println("Introspection Service not available" );
174 oObj
= (XInterface
) oInterface
;
178 log
.println( " creating a new environment for Introspection object" );
179 TestEnvironment tEnv
= new TestEnvironment( oObj
);
181 tEnv
.addObjRelation("NR","NestedRegistry");
183 tEnv
.addObjRelation("XSimpleRegistry.open", openF
) ;
184 tEnv
.addObjRelation("XSimpleRegistry.merge", mergeF
) ;
185 tEnv
.addObjRelation("XSimpleRegistry.destroy", destroyF
) ;
188 } // finish method getTestEnvironment
191 protected void cleanup( TestParameters Param
, PrintWriter log
) {
196 } // finish class NestedRegistry