merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / mod / _nestedreg.uno / NestedRegistry.java
blobab1aa363196c0188c0a5d82ac66f87f3eaaf98c8
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: NestedRegistry.java,v $
10 * $Revision: 1.4 $
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;
36 import java.io.File;
37 import java.io.FileInputStream;
38 import java.io.FileOutputStream;
39 import java.io.PrintWriter;
40 import lib.StatusException;
41 import lib.TestCase;
42 import lib.TestEnvironment;
43 import lib.TestParameters;
44 import util.RegistryTools;
45 import util.utils;
47 /**
48 * Test for object which is represented by service
49 * <code>com.sun.star.registry.NestedRegistry</code>. <p>
50 * Object implements the following interfaces :
51 * <ul>
52 * <li> <code>com::sun::star::registry::XSimpleRegistry</code></li>
53 * <li> <code>com::sun::star::lang::XInitialization</code></li>
54 * </ul>
55 * The following files used by this test :
56 * <ul>
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>
64 * </ul> <p>
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 ;
75 XSimpleRegistry reg1;
76 XSimpleRegistry reg2;
78 public synchronized void disposeTestEnvironment( TestEnvironment tEnv,
79 TestParameters tParam ) {
80 try {
81 reg1.destroy();
82 reg2.destroy();
84 catch (com.sun.star.registry.InvalidRegistryException e) {}
87 /**
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] ;
107 int bytesRead = 0 ;
108 while ((bytesRead = fIn.read(buf)) > 0)
109 fOut.write(buf, 0, bytesRead) ;
111 fIn.close() ;
112 fOut.close() ;
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 :
122 * <ul>
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
127 * object name.</li>
128 * <li> <code>'XSimpleRegistry.open'</code> for
129 * {@link ifc.registry._XSimpleRegistry}
130 * </li>
131 * <li> <code>'XSimpleRegistry.destroy'</code> for
132 * {@link ifc.registry._XSimpleRegistry}
133 * </li>
134 * <li> <code>'XSimpleRegistry.merge'</code> for
135 * {@link ifc.registry._XSimpleRegistry}
136 * </li>
137 * </ul>
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" ;
150 uniq++ ;
152 log.println("creating copies of the registry for XSimpleRegistry");
153 try {
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);
163 try {
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];
172 arg[0]=reg1;
173 arg[1]=reg2;
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) ;
193 return tEnv;
194 } // finish method getTestEnvironment
196 protected void cleanup( TestParameters Param, PrintWriter log) {
201 } // finish class NestedRegistry