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
;
29 import lib
.TestEnvironment
;
30 import lib
.TestParameters
;
31 import util
.RegistryTools
;
35 * Test for object which is represented by service
36 * <code>com.sun.star.registry.NestedRegistry</code>. <p>
37 * Object implements the following interfaces :
39 * <li> <code>com::sun::star::registry::XSimpleRegistry</code></li>
40 * <li> <code>com::sun::star::lang::XInitialization</code></li>
42 * The following files used by this test :
44 * <li><b> XSimpleRegistry.rdb </b> : Registry file created before. </li>
45 * <li><b> XSimpleRegistry_open#.rdb </b> : Temporary registry file as copy of
46 * <b> XSimpleRegistry.rdb </b> in the SOffice temp directory.
47 * ('#' - is an ordinary number) </li>
48 * <li><b> XSimpleRegistry_merge#.rdb </b> : Temporary registry file as copy of
49 * <b> XSimpleRegistry.rdb </b> in the SOffice temp directory.
50 * ('#' - is an ordinary number) </li>
52 * This object test <b> is NOT </b> designed to be run in several
53 * threads concurrently.
54 * @see com.sun.star.registry.XSimpleRegistry
55 * @see com.sun.star.lang.XInitialization
56 * @see ifc.registry._XSimpleRegistry
57 * @see ifc.lang._XInitialization
59 public class NestedRegistry
extends TestCase
{
61 protected static int uniq
= 0 ;
66 public synchronized void disposeTestEnvironment( TestEnvironment tEnv
,
67 TestParameters tParam
) {
72 catch (com
.sun
.star
.registry
.InvalidRegistryException e
) {
73 System
.out
.println("caught exception: " + e
);
78 * Creates a temporary copy of file, which is deleted when VM exits.
79 * @param src Source file path.
80 * @param dst Destination file path.
81 * @throws java.io.IOException If any problems occur during copying.
83 protected void copyFile(String src
, String dst
)
84 throws java
.io
.IOException
{
85 File srcF
= new File(src
) ;
86 File dstF
= new File(dst
) ;
89 boolean bDeleteOk
= dstF
.delete();
91 System
.out
.println("delete failed");
95 boolean bCreateOk
= dstF
.createNewFile() ;
97 System
.out
.println("create failed");
100 dstF
.deleteOnExit() ;
102 FileInputStream fIn
= new FileInputStream(srcF
) ;
103 FileOutputStream fOut
= new FileOutputStream(dstF
) ;
105 byte[] buf
= new byte[1024] ;
107 while ((bytesRead
= fIn
.read(buf
)) > 0) {
108 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, then 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}
140 protected TestEnvironment
createTestEnvironment(TestParameters Param
, PrintWriter log
) throws Exception
{
141 XInterface oObj
= null;
142 Object oInterface
= null;
144 final String tmpDir
= utils
.getOfficeTempDirSys(
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");
153 String source
= utils
.getFullTestDocName("XSimpleRegistry.rdb");
154 copyFile(source
, openF
) ;
155 copyFile(source
, mergeF
) ;
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