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