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 mod
._nestedreg
.uno
;
21 import com
.sun
.star
.lang
.XMultiServiceFactory
;
22 import com
.sun
.star
.registry
.XSimpleRegistry
;
23 import com
.sun
.star
.uno
.XInterface
;
25 import java
.io
.FileInputStream
;
26 import java
.io
.FileOutputStream
;
27 import java
.io
.PrintWriter
;
28 import lib
.StatusException
;
30 import lib
.TestEnvironment
;
31 import lib
.TestParameters
;
32 import util
.RegistryTools
;
36 * Test for object which is represented by service
37 * <code>com.sun.star.registry.NestedRegistry</code>. <p>
38 * Object implements the following interfaces :
40 * <li> <code>com::sun::star::registry::XSimpleRegistry</code></li>
41 * <li> <code>com::sun::star::lang::XInitialization</code></li>
43 * The following files used by this test :
45 * <li><b> XSimpleRegistry.rdb </b> : Registry file created before. </li>
46 * <li><b> XSimpleRegistry_open#.rdb </b> : Temporary registry file as copy of
47 * <b> XSimpleRegistry.rdb </b> in the SOffice temp directory.
48 * ('#' - is an ordinary number) </li>
49 * <li><b> XSimpleRegistry_merge#.rdb </b> : Temporary registry file as copy of
50 * <b> XSimpleRegistry.rdb </b> in the SOffice temp directory.
51 * ('#' - is an ordinary number) </li>
53 * This object test <b> is NOT </b> designed to be run in several
54 * threads concurently.
55 * @see com.sun.star.registry.XSimpleRegistry
56 * @see com.sun.star.lang.XInitialization
57 * @see ifc.registry._XSimpleRegistry
58 * @see ifc.lang._XInitialization
60 public class NestedRegistry
extends TestCase
{
62 protected static int uniq
= 0 ;
66 public synchronized void disposeTestEnvironment( TestEnvironment tEnv
,
67 TestParameters tParam
) {
72 catch (com
.sun
.star
.registry
.InvalidRegistryException e
) {}
76 * Creates a temporary copy of file, which is deleted when VM exits.
77 * @param src Source file path.
78 * @param dst Destination file path.
79 * @throws java.io.IOException If any problems occur during copiing.
81 protected void copyFile(String src
, String dst
, PrintWriter log
)
82 throws java
.io
.IOException
{
83 File srcF
= new File(src
) ;
84 File dstF
= new File(dst
) ;
86 if (dstF
.exists()) dstF
.delete() ;
87 dstF
.createNewFile() ;
91 FileInputStream fIn
= new FileInputStream(srcF
) ;
92 FileOutputStream fOut
= new FileOutputStream(dstF
) ;
94 byte[] buf
= new byte[1024] ;
96 while ((bytesRead
= fIn
.read(buf
)) > 0)
97 fOut
.write(buf
, 0, bytesRead
) ;
105 * Creating a Testenvironment for the interfaces to be tested.
106 * Creates two temporary copies of registry file created before, opens
107 * them, and creates service <code>com.sun.star.comp.stoc.NestedRegistry</code>
108 * with these two registries. <p>
109 * Object relations created :
111 * <li> <code>'NR'</code> for {@link ifc.registry._XSimpleRegistry} :
112 * Just informs interface test that <code>NestedRegistry</code>
113 * service is tested. If this relation exists, than some methods
114 * are not supported. The relation is a <code>String</code> with
116 * <li> <code>'XSimpleRegistry.open'</code> for
117 * {@link ifc.registry._XSimpleRegistry}
119 * <li> <code>'XSimpleRegistry.destroy'</code> for
120 * {@link ifc.registry._XSimpleRegistry}
122 * <li> <code>'XSimpleRegistry.merge'</code> for
123 * {@link ifc.registry._XSimpleRegistry}
127 protected TestEnvironment
createTestEnvironment(TestParameters Param
, PrintWriter log
) {
128 XInterface oObj
= null;
129 Object oInterface
= null;
131 final String tmpDir
= utils
.getOfficeTempDirSys(
132 (XMultiServiceFactory
)Param
.getMSF()) ;
133 final String openF
= tmpDir
+ "XSimpleRegistry_open" + uniq
+ ".rdb" ;
134 final String destroyF
= tmpDir
135 + "XSimpleRegistry_destroy" + uniq
+ ".rdb" ;
136 final String mergeF
= tmpDir
+ "XSimpleRegistry_merge" + uniq
+ ".rdb" ;
139 log
.println("creating copies of the registry for XSimpleRegistry");
141 String source
= utils
.getFullTestDocName("XSimpleRegistry.rdb");
142 copyFile(source
, openF
, log
) ;
143 copyFile(source
, mergeF
, log
) ;
144 } catch (java
.io
.IOException e
) {
145 log
.println("Exception occurred while copying files");
146 e
.printStackTrace(log
);
147 throw new StatusException("Exception occurred while copying files", e
);
151 XMultiServiceFactory xMSF
= (XMultiServiceFactory
)Param
.getMSF();
152 reg1
= RegistryTools
.
153 createRegistryService(xMSF
) ;
154 reg1
.open(mergeF
, false, true) ;
155 reg2
= RegistryTools
.
156 createRegistryService(xMSF
) ;
157 reg2
.open(openF
, false, true) ;
158 XSimpleRegistry
[] arg
= new XSimpleRegistry
[2];
161 oInterface
= xMSF
.createInstanceWithArguments
162 ( "com.sun.star.comp.stoc.NestedRegistry", arg
);
164 catch( Exception e
) {
165 log
.println("Introspection Service not available" );
167 oObj
= (XInterface
) oInterface
;
171 log
.println( " creating a new environment for Introspection object" );
172 TestEnvironment tEnv
= new TestEnvironment( oObj
);
174 tEnv
.addObjRelation("NR","NestedRegistry");
176 tEnv
.addObjRelation("XSimpleRegistry.open", openF
) ;
177 tEnv
.addObjRelation("XSimpleRegistry.merge", mergeF
) ;
178 tEnv
.addObjRelation("XSimpleRegistry.destroy", destroyF
) ;
181 } // finish method getTestEnvironment
183 protected void cleanup( TestParameters Param
, PrintWriter log
) {
188 } // finish class NestedRegistry