bump product version to 5.0.4.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _defreg / NestedRegistry.java
bloba6cc37bdd93b7e6fab0648e509ba023a2729311d
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 @Override
69 public synchronized void disposeTestEnvironment( TestEnvironment tEnv,
70 TestParameters tParam ) {
71 try {
72 reg1.destroy();
73 reg2.destroy();
75 catch (com.sun.star.registry.InvalidRegistryException e) {}
78 /**
79 * Creates a temporary copy of file, which is deleted when VM exits.
80 * @param src Source file path.
81 * @param dst Destination file path.
82 * @throws java.io.IOException If any problems occur during copiing.
84 protected void copyFile(String src, String dst, PrintWriter log)
85 throws java.io.IOException {
86 log.println("Copy File "+src+" to "+dst);
87 File srcF = new File(src) ;
88 File dstF = new File(dst) ;
90 if (dstF.exists()) dstF.delete() ;
91 dstF.createNewFile() ;
93 dstF.deleteOnExit() ;
95 FileInputStream fIn = new FileInputStream(srcF) ;
96 FileOutputStream fOut = new FileOutputStream(dstF) ;
98 byte[] buf = new byte[1024] ;
99 int bytesRead = 0 ;
100 while ((bytesRead = fIn.read(buf)) > 0) {
101 fOut.write(buf, 0, bytesRead) ;
104 fIn.close() ;
105 fOut.close() ;
110 * Creating a Testenvironment for the interfaces to be tested.
111 * Creates two temporary copies of registry file created before, opens
112 * them, and creates service <code>com.sun.star.comp.stoc.NestedRegistry</code>
113 * with these two registries. <p>
114 * Object relations created :
115 * <ul>
116 * <li> <code>'NR'</code> for {@link ifc.registry._XSimpleRegistry} :
117 * Just informs interface test that <code>NestedRegistry</code>
118 * service is tested. If this relation exists, than some methods
119 * are not supported. The relation is a <code>String</code> with
120 * object name.</li>
121 * <li> <code>'XSimpleRegistry.open'</code> for
122 * {@link ifc.registry._XSimpleRegistry}
123 * </li>
124 * <li> <code>'XSimpleRegistry.destroy'</code> for
125 * {@link ifc.registry._XSimpleRegistry}
126 * </li>
127 * <li> <code>'XSimpleRegistry.merge'</code> for
128 * {@link ifc.registry._XSimpleRegistry}
129 * </li>
130 * </ul>
132 @Override
133 public TestEnvironment createTestEnvironment( TestParameters Param,
134 PrintWriter log )
135 throws StatusException {
136 XInterface oObj = null;
137 Object oInterface = null;
139 final String tmpDir = utils.getOfficeTempDirSys(Param.getMSF()) ;
140 final String openF = tmpDir + "XSimpleRegistry_open" + uniq + ".rdb" ;
141 final String destroyF = tmpDir
142 + "XSimpleRegistry_destroy" + uniq + ".rdb" ;
143 final String mergeF = tmpDir + "XSimpleRegistry_merge" + uniq + ".rdb" ;
144 uniq++ ;
146 log.println("creating copies of the registry for XSimpleRegistry");
147 try {
148 String source = utils.getFullTestDocName("XSimpleRegistry.rdb");
149 copyFile(source, openF, log) ;
150 copyFile(source, mergeF, log) ;
151 } catch (java.io.IOException e) {
152 log.println("Exception occurred while copying files");
153 e.printStackTrace(log);
154 throw new StatusException("Exception occurred while copying files", e);
157 try {
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];
166 arg[0]=reg1;
167 arg[1]=reg2;
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) ;
187 return tEnv;
188 } // finish method getTestEnvironment
190 @Override
191 protected void cleanup( TestParameters Param, PrintWriter log) {
196 } // finish class NestedRegistry