bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _defreg / NestedRegistry.java
blobdd814bc47c7c41be3dc1f8d648588784b46d92f4
1 /*
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._defreg;
21 import java.io.File;
22 import java.io.FileInputStream;
23 import java.io.FileOutputStream;
24 import java.io.PrintWriter;
26 import lib.StatusException;
27 import lib.TestCase;
28 import lib.TestEnvironment;
29 import lib.TestParameters;
30 import util.RegistryTools;
31 import util.utils;
33 import com.sun.star.lang.XMultiServiceFactory;
34 import com.sun.star.registry.XSimpleRegistry;
35 import com.sun.star.uno.XInterface;
37 /**
38 * Test for object which is represented by service
39 * <code>com.sun.star.registry.NestedRegistry</code>. <p>
40 * Object implements the following interfaces :
41 * <ul>
42 * <li> <code>com::sun::star::registry::XSimpleRegistry</code></li>
43 * <li> <code>com::sun::star::lang::XInitialization</code></li>
44 * </ul>
45 * The following files used by this test :
46 * <ul>
47 * <li><b> XSimpleRegistry.rdb </b> : Registry file created before. </li>
48 * <li><b> XSimpleRegistry_open#.rdb </b> : Temporary registry file as copy of
49 * <b> XSimpleRegistry.rdb </b> in the SOffice temp directory.
50 * ('#' - is an ordinary number) </li>
51 * <li><b> XSimpleRegistry_merge#.rdb </b> : Temporary registry file as copy of
52 * <b> XSimpleRegistry.rdb </b> in the SOffice temp directory.
53 * ('#' - is an ordinary number) </li>
54 * </ul> <p>
55 * This object test <b> is NOT </b> designed to be run in several
56 * threads concurently.
57 * @see com.sun.star.registry.XSimpleRegistry
58 * @see com.sun.star.lang.XInitialization
59 * @see ifc.registry._XSimpleRegistry
60 * @see ifc.lang._XInitialization
62 public class NestedRegistry extends TestCase {
64 protected static int uniq = 0 ;
65 XSimpleRegistry reg1;
66 XSimpleRegistry reg2;
68 public synchronized void disposeTestEnvironment( TestEnvironment tEnv,
69 TestParameters tParam ) {
70 try {
71 reg1.destroy();
72 reg2.destroy();
74 catch (com.sun.star.registry.InvalidRegistryException e) {}
77 /**
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 copiing.
83 protected void copyFile(String src, String dst, PrintWriter log)
84 throws java.io.IOException {
85 log.println("Copy File "+src+" to "+dst);
86 File srcF = new File(src) ;
87 File dstF = new File(dst) ;
89 if (dstF.exists()) dstF.delete() ;
90 dstF.createNewFile() ;
92 dstF.deleteOnExit() ;
94 FileInputStream fIn = new FileInputStream(srcF) ;
95 FileOutputStream fOut = new FileOutputStream(dstF) ;
97 byte[] buf = new byte[1024] ;
98 int bytesRead = 0 ;
99 while ((bytesRead = fIn.read(buf)) > 0)
100 fOut.write(buf, 0, bytesRead) ;
102 fIn.close() ;
103 fOut.close() ;
108 * Creating a Testenvironment for the interfaces to be tested.
109 * Creates two temporary copies of registry file created before, opens
110 * them, and creates service <code>com.sun.star.comp.stoc.NestedRegistry</code>
111 * with these two registries. <p>
112 * Object relations created :
113 * <ul>
114 * <li> <code>'NR'</code> for {@link ifc.registry._XSimpleRegistry} :
115 * Just informs interface test that <code>NestedRegistry</code>
116 * service is tested. If this relation exists, than some methods
117 * are not supported. The relation is a <code>String</code> with
118 * object name.</li>
119 * <li> <code>'XSimpleRegistry.open'</code> for
120 * {@link ifc.registry._XSimpleRegistry}
121 * </li>
122 * <li> <code>'XSimpleRegistry.destroy'</code> for
123 * {@link ifc.registry._XSimpleRegistry}
124 * </li>
125 * <li> <code>'XSimpleRegistry.merge'</code> for
126 * {@link ifc.registry._XSimpleRegistry}
127 * </li>
128 * </ul>
130 public TestEnvironment createTestEnvironment( TestParameters Param,
131 PrintWriter log )
132 throws StatusException {
133 XInterface oObj = null;
134 Object oInterface = null;
136 final String tmpDir = utils.getOfficeTempDirSys((XMultiServiceFactory)Param.getMSF()) ;
137 final String openF = tmpDir + "XSimpleRegistry_open" + uniq + ".rdb" ;
138 final String destroyF = tmpDir
139 + "XSimpleRegistry_destroy" + uniq + ".rdb" ;
140 final String mergeF = tmpDir + "XSimpleRegistry_merge" + uniq + ".rdb" ;
141 uniq++ ;
143 log.println("creating copies of the registry for XSimpleRegistry");
144 try {
145 String source = utils.getFullTestDocName("XSimpleRegistry.rdb");
146 copyFile(source, openF, log) ;
147 copyFile(source, mergeF, log) ;
148 } catch (java.io.IOException e) {
149 log.println("Exception occurred while copying files");
150 e.printStackTrace(log);
151 throw new StatusException("Exception occurred while copying files", e);
154 try {
155 XMultiServiceFactory xMSF = (XMultiServiceFactory)Param.getMSF();
156 reg1 = RegistryTools.
157 createRegistryService(xMSF) ;
158 reg1.open(mergeF, false, true) ;
159 reg2 = RegistryTools.
160 createRegistryService(xMSF) ;
161 reg2.open(openF, false, true) ;
162 XSimpleRegistry[] arg = new XSimpleRegistry[2];
163 arg[0]=reg1;
164 arg[1]=reg2;
165 oInterface = xMSF.createInstanceWithArguments
166 ( "com.sun.star.comp.stoc.NestedRegistry", arg );
168 catch( Exception e ) {
169 log.println("Introspection Service not available" );
171 oObj = (XInterface) oInterface;
175 log.println( " creating a new environment for Introspection object" );
176 TestEnvironment tEnv = new TestEnvironment( oObj );
178 tEnv.addObjRelation("NR","NestedRegistry");
180 tEnv.addObjRelation("XSimpleRegistry.open", openF) ;
181 tEnv.addObjRelation("XSimpleRegistry.merge", mergeF) ;
182 tEnv.addObjRelation("XSimpleRegistry.destroy", destroyF) ;
184 return tEnv;
185 } // finish method getTestEnvironment
187 protected void cleanup( TestParameters Param, PrintWriter log) {
192 } // finish class NestedRegistry