merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / mod / _defreg / NestedRegistry.java
blob169cc30c3b34caee154e350f71d503e28595fde2
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.5 $
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._defreg;
33 import java.io.File;
34 import java.io.FileInputStream;
35 import java.io.FileOutputStream;
36 import java.io.PrintWriter;
38 import lib.StatusException;
39 import lib.TestCase;
40 import lib.TestEnvironment;
41 import lib.TestParameters;
42 import util.RegistryTools;
43 import util.utils;
45 import com.sun.star.lang.XMultiServiceFactory;
46 import com.sun.star.registry.XSimpleRegistry;
47 import com.sun.star.uno.XInterface;
49 /**
50 * Test for object which is represented by service
51 * <code>com.sun.star.registry.NestedRegistry</code>. <p>
52 * Object implements the following interfaces :
53 * <ul>
54 * <li> <code>com::sun::star::registry::XSimpleRegistry</code></li>
55 * <li> <code>com::sun::star::lang::XInitialization</code></li>
56 * </ul>
57 * The following files used by this test :
58 * <ul>
59 * <li><b> XSimpleRegistry.rdb </b> : Registry file created before. </li>
60 * <li><b> XSimpleRegistry_open#.rdb </b> : Temporary registry file as copy of
61 * <b> XSimpleRegistry.rdb </b> in the SOffice temp directory.
62 * ('#' - is an ordinary number) </li>
63 * <li><b> XSimpleRegistry_merge#.rdb </b> : Temporary registry file as copy of
64 * <b> XSimpleRegistry.rdb </b> in the SOffice temp directory.
65 * ('#' - is an ordinary number) </li>
66 * </ul> <p>
67 * This object test <b> is NOT </b> designed to be run in several
68 * threads concurently.
69 * @see com.sun.star.registry.XSimpleRegistry
70 * @see com.sun.star.lang.XInitialization
71 * @see ifc.registry._XSimpleRegistry
72 * @see ifc.lang._XInitialization
74 public class NestedRegistry extends TestCase {
76 protected static int uniq = 0 ;
77 XSimpleRegistry reg1;
78 XSimpleRegistry reg2;
80 public synchronized void disposeTestEnvironment( TestEnvironment tEnv,
81 TestParameters tParam ) {
82 try {
83 reg1.destroy();
84 reg2.destroy();
86 catch (com.sun.star.registry.InvalidRegistryException e) {}
89 /**
90 * Creates a temporary copy of file, which is deleted when VM exits.
91 * @param src Source file path.
92 * @param dst Destination file path.
93 * @throws java.io.IOException If any problems occur during copiing.
95 protected void copyFile(String src, String dst, PrintWriter log)
96 throws java.io.IOException {
97 log.println("Copy File "+src+" to "+dst);
98 File srcF = new File(src) ;
99 File dstF = new File(dst) ;
101 if (dstF.exists()) dstF.delete() ;
102 dstF.createNewFile() ;
104 dstF.deleteOnExit() ;
106 FileInputStream fIn = new FileInputStream(srcF) ;
107 FileOutputStream fOut = new FileOutputStream(dstF) ;
109 byte[] buf = new byte[1024] ;
110 int bytesRead = 0 ;
111 while ((bytesRead = fIn.read(buf)) > 0)
112 fOut.write(buf, 0, bytesRead) ;
114 fIn.close() ;
115 fOut.close() ;
120 * Creating a Testenvironment for the interfaces to be tested.
121 * Creates two temporary copies of registry file created before, opens
122 * them, and creates service <code>com.sun.star.comp.stoc.NestedRegistry</code>
123 * with these two registries. <p>
124 * Object relations created :
125 * <ul>
126 * <li> <code>'NR'</code> for {@link ifc.registry._XSimpleRegistry} :
127 * Just informs interface test that <code>NestedRegistry</code>
128 * service is tested. If this relation exists, than some methods
129 * are not supported. The relation is a <code>String</code> with
130 * object name.</li>
131 * <li> <code>'XSimpleRegistry.open'</code> for
132 * {@link ifc.registry._XSimpleRegistry}
133 * </li>
134 * <li> <code>'XSimpleRegistry.destroy'</code> for
135 * {@link ifc.registry._XSimpleRegistry}
136 * </li>
137 * <li> <code>'XSimpleRegistry.merge'</code> for
138 * {@link ifc.registry._XSimpleRegistry}
139 * </li>
140 * </ul>
142 public TestEnvironment createTestEnvironment( TestParameters Param,
143 PrintWriter log )
144 throws StatusException {
145 XInterface oObj = null;
146 Object oInterface = null;
148 final String tmpDir = utils.getOfficeTempDirSys((XMultiServiceFactory)Param.getMSF()) ;
149 final String openF = tmpDir + "XSimpleRegistry_open" + uniq + ".rdb" ;
150 final String destroyF = tmpDir
151 + "XSimpleRegistry_destroy" + uniq + ".rdb" ;
152 final String mergeF = tmpDir + "XSimpleRegistry_merge" + uniq + ".rdb" ;
153 uniq++ ;
155 log.println("creating copies of the registry for XSimpleRegistry");
156 try {
157 String source = utils.getFullTestDocName("XSimpleRegistry.rdb");
158 copyFile(source, openF, log) ;
159 copyFile(source, mergeF, log) ;
160 } catch (java.io.IOException e) {
161 log.println("Exception occured while copying files");
162 e.printStackTrace(log);
163 throw new StatusException("Exception occured while copying files", e);
166 try {
167 XMultiServiceFactory xMSF = (XMultiServiceFactory)Param.getMSF();
168 reg1 = RegistryTools.
169 createRegistryService(xMSF) ;
170 reg1.open(mergeF, false, true) ;
171 reg2 = RegistryTools.
172 createRegistryService(xMSF) ;
173 reg2.open(openF, false, true) ;
174 XSimpleRegistry[] arg = new XSimpleRegistry[2];
175 arg[0]=reg1;
176 arg[1]=reg2;
177 oInterface = xMSF.createInstanceWithArguments
178 ( "com.sun.star.comp.stoc.NestedRegistry", arg );
180 catch( Exception e ) {
181 log.println("Introspection Service not available" );
183 oObj = (XInterface) oInterface;
187 log.println( " creating a new environment for Introspection object" );
188 TestEnvironment tEnv = new TestEnvironment( oObj );
190 tEnv.addObjRelation("NR","NestedRegistry");
192 tEnv.addObjRelation("XSimpleRegistry.open", openF) ;
193 tEnv.addObjRelation("XSimpleRegistry.merge", mergeF) ;
194 tEnv.addObjRelation("XSimpleRegistry.destroy", destroyF) ;
196 return tEnv;
197 } // finish method getTestEnvironment
199 protected void cleanup( TestParameters Param, PrintWriter log) {
204 } // finish class NestedRegistry