1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: NestedRegistry.java,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 package mod
._nestedreg
.uno
;
33 import com
.sun
.star
.lang
.XMultiServiceFactory
;
34 import com
.sun
.star
.registry
.XSimpleRegistry
;
35 import com
.sun
.star
.uno
.XInterface
;
37 import java
.io
.FileInputStream
;
38 import java
.io
.FileOutputStream
;
39 import java
.io
.PrintWriter
;
40 import lib
.StatusException
;
42 import lib
.TestEnvironment
;
43 import lib
.TestParameters
;
44 import util
.RegistryTools
;
48 * Test for object which is represented by service
49 * <code>com.sun.star.registry.NestedRegistry</code>. <p>
50 * Object implements the following interfaces :
52 * <li> <code>com::sun::star::registry::XSimpleRegistry</code></li>
53 * <li> <code>com::sun::star::lang::XInitialization</code></li>
55 * The following files used by this test :
57 * <li><b> XSimpleRegistry.rdb </b> : Registry file created before. </li>
58 * <li><b> XSimpleRegistry_open#.rdb </b> : Temporary registry file as copy of
59 * <b> XSimpleRegistry.rdb </b> in the SOffice temp directory.
60 * ('#' - is an ordinary number) </li>
61 * <li><b> XSimpleRegistry_merge#.rdb </b> : Temporary registry file as copy of
62 * <b> XSimpleRegistry.rdb </b> in the SOffice temp directory.
63 * ('#' - is an ordinary number) </li>
65 * This object test <b> is NOT </b> designed to be run in several
66 * threads concurently.
67 * @see com.sun.star.registry.XSimpleRegistry
68 * @see com.sun.star.lang.XInitialization
69 * @see ifc.registry._XSimpleRegistry
70 * @see ifc.lang._XInitialization
72 public class NestedRegistry
extends TestCase
{
74 protected static int uniq
= 0 ;
78 public synchronized void disposeTestEnvironment( TestEnvironment tEnv
,
79 TestParameters tParam
) {
84 catch (com
.sun
.star
.registry
.InvalidRegistryException e
) {}
88 * Creates a temporary copy of file, which is deleted when VM exits.
89 * @param src Source file path.
90 * @param dst Destination file path.
91 * @throws java.io.IOException If any problems occur during copiing.
93 protected void copyFile(String src
, String dst
, PrintWriter log
)
94 throws java
.io
.IOException
{
95 File srcF
= new File(src
) ;
96 File dstF
= new File(dst
) ;
98 if (dstF
.exists()) dstF
.delete() ;
99 dstF
.createNewFile() ;
101 dstF
.deleteOnExit() ;
103 FileInputStream fIn
= new FileInputStream(srcF
) ;
104 FileOutputStream fOut
= new FileOutputStream(dstF
) ;
106 byte[] buf
= new byte[1024] ;
108 while ((bytesRead
= fIn
.read(buf
)) > 0)
109 fOut
.write(buf
, 0, bytesRead
) ;
117 * Creating a Testenvironment for the interfaces to be tested.
118 * Creates two temporary copies of registry file created before, opens
119 * them, and creates service <code>com.sun.star.comp.stoc.NestedRegistry</code>
120 * with these two registries. <p>
121 * Object relations created :
123 * <li> <code>'NR'</code> for {@link ifc.registry._XSimpleRegistry} :
124 * Just informs interface test that <code>NestedRegistry</code>
125 * service is tested. If this relation exists, than some methods
126 * are not supported. The relation is a <code>String</code> with
128 * <li> <code>'XSimpleRegistry.open'</code> for
129 * {@link ifc.registry._XSimpleRegistry}
131 * <li> <code>'XSimpleRegistry.destroy'</code> for
132 * {@link ifc.registry._XSimpleRegistry}
134 * <li> <code>'XSimpleRegistry.merge'</code> for
135 * {@link ifc.registry._XSimpleRegistry}
139 protected TestEnvironment
createTestEnvironment(TestParameters Param
, PrintWriter log
) {
140 XInterface oObj
= null;
141 Object oInterface
= null;
142 Object fileAcc
= null;
144 final String tmpDir
= utils
.getOfficeTempDirSys(
145 (XMultiServiceFactory
)Param
.getMSF()) ;
146 final String openF
= tmpDir
+ "XSimpleRegistry_open" + uniq
+ ".rdb" ;
147 final String destroyF
= tmpDir
148 + "XSimpleRegistry_destroy" + uniq
+ ".rdb" ;
149 final String mergeF
= tmpDir
+ "XSimpleRegistry_merge" + uniq
+ ".rdb" ;
152 log
.println("creating copies of the registry for XSimpleRegistry");
154 String source
= utils
.getFullTestDocName("XSimpleRegistry.rdb");
155 copyFile(source
, openF
, log
) ;
156 copyFile(source
, mergeF
, log
) ;
157 } catch (java
.io
.IOException e
) {
158 log
.println("Exception occured while copying files");
159 e
.printStackTrace(log
);
160 throw new StatusException("Exception occured while copying files", e
);
164 XMultiServiceFactory xMSF
= (XMultiServiceFactory
)Param
.getMSF();
165 reg1
= RegistryTools
.
166 createRegistryService(xMSF
) ;
167 reg1
.open(mergeF
, false, true) ;
168 reg2
= RegistryTools
.
169 createRegistryService(xMSF
) ;
170 reg2
.open(openF
, false, true) ;
171 XSimpleRegistry
[] arg
= new XSimpleRegistry
[2];
174 oInterface
= xMSF
.createInstanceWithArguments
175 ( "com.sun.star.comp.stoc.NestedRegistry", arg
);
177 catch( Exception e
) {
178 log
.println("Introspection Service not available" );
180 oObj
= (XInterface
) oInterface
;
184 log
.println( " creating a new environment for Introspection object" );
185 TestEnvironment tEnv
= new TestEnvironment( oObj
);
187 tEnv
.addObjRelation("NR","NestedRegistry");
189 tEnv
.addObjRelation("XSimpleRegistry.open", openF
) ;
190 tEnv
.addObjRelation("XSimpleRegistry.merge", mergeF
) ;
191 tEnv
.addObjRelation("XSimpleRegistry.destroy", destroyF
) ;
194 } // finish method getTestEnvironment
196 protected void cleanup( TestParameters Param
, PrintWriter log
) {
201 } // finish class NestedRegistry