tdf#130857 qt weld: Introduce QtInstanceScrolledWindow
[LibreOffice.git] / qadevOOo / tests / java / mod / _defreg / NestedRegistry.java
bloba571c7e2c032d5b0919394ab5cf86fb091480a72
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.TestCase;
27 import lib.TestEnvironment;
28 import lib.TestParameters;
29 import util.RegistryTools;
30 import util.utils;
32 import com.sun.star.lang.XMultiServiceFactory;
33 import com.sun.star.registry.XSimpleRegistry;
34 import com.sun.star.uno.XInterface;
36 /**
37 * Test for object which is represented by service
38 * <code>com.sun.star.registry.NestedRegistry</code>. <p>
39 * Object implements the following interfaces :
40 * <ul>
41 * <li> <code>com::sun::star::registry::XSimpleRegistry</code></li>
42 * <li> <code>com::sun::star::lang::XInitialization</code></li>
43 * </ul>
44 * The following files used by this test :
45 * <ul>
46 * <li><b> XSimpleRegistry.rdb </b> : Registry file created before. </li>
47 * <li><b> XSimpleRegistry_open#.rdb </b> : Temporary registry file as copy of
48 * <b> XSimpleRegistry.rdb </b> in the SOffice temp directory.
49 * ('#' - is an ordinary number) </li>
50 * <li><b> XSimpleRegistry_merge#.rdb </b> : Temporary registry file as copy of
51 * <b> XSimpleRegistry.rdb </b> in the SOffice temp directory.
52 * ('#' - is an ordinary number) </li>
53 * </ul> <p>
54 * This object test <b> is NOT </b> designed to be run in several
55 * threads concurrently.
56 * @see com.sun.star.registry.XSimpleRegistry
57 * @see com.sun.star.lang.XInitialization
58 * @see ifc.registry._XSimpleRegistry
59 * @see ifc.lang._XInitialization
61 public class NestedRegistry extends TestCase {
63 protected static int uniq = 0 ;
64 XSimpleRegistry reg1;
65 XSimpleRegistry reg2;
67 @Override
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) {
75 System.out.println("caught exception: " + e);
79 /**
80 * Creates a temporary copy of file, which is deleted when VM exits.
81 * @param src Source file path.
82 * @param dst Destination file path.
83 * @throws java.io.IOException If any problems occur during copying.
85 protected void copyFile(String src, String dst, PrintWriter log)
86 throws java.io.IOException {
87 log.println("Copy File "+src+" to "+dst);
88 File srcF = new File(src) ;
89 File dstF = new File(dst) ;
91 if (dstF.exists()) {
92 boolean bDeleteOk = dstF.delete();
93 if (!bDeleteOk) {
94 System.out.println("delete failed");
98 boolean bCreateOk = dstF.createNewFile();
99 if (!bCreateOk) {
100 System.out.println("create failed");
103 dstF.deleteOnExit() ;
105 FileInputStream fIn = new FileInputStream(srcF) ;
106 FileOutputStream fOut = new FileOutputStream(dstF) ;
108 byte[] buf = new byte[1024] ;
109 int bytesRead = 0 ;
110 while ((bytesRead = fIn.read(buf)) > 0) {
111 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, then 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 @Override
143 public TestEnvironment createTestEnvironment( TestParameters Param,
144 PrintWriter log )
145 throws Exception {
146 XInterface oObj = null;
147 Object oInterface = null;
149 final String tmpDir = utils.getOfficeTempDirSys(Param.getMSF()) ;
150 final String openF = tmpDir + "XSimpleRegistry_open" + uniq + ".rdb" ;
151 final String destroyF = tmpDir
152 + "XSimpleRegistry_destroy" + uniq + ".rdb" ;
153 final String mergeF = tmpDir + "XSimpleRegistry_merge" + uniq + ".rdb" ;
154 uniq++ ;
156 log.println("creating copies of the registry for XSimpleRegistry");
157 String source = utils.getFullTestDocName("XSimpleRegistry.rdb");
158 copyFile(source, openF, log) ;
159 copyFile(source, mergeF, log) ;
161 try {
162 XMultiServiceFactory xMSF = Param.getMSF();
163 reg1 = RegistryTools.
164 createRegistryService(xMSF) ;
165 reg1.open(mergeF, false, true) ;
166 reg2 = RegistryTools.
167 createRegistryService(xMSF) ;
168 reg2.open(openF, false, true) ;
169 XSimpleRegistry[] arg = new XSimpleRegistry[2];
170 arg[0]=reg1;
171 arg[1]=reg2;
172 oInterface = xMSF.createInstanceWithArguments
173 ( "com.sun.star.comp.stoc.NestedRegistry", arg );
175 catch( Exception e ) {
176 log.println("Introspection Service not available" );
178 oObj = (XInterface) oInterface;
182 log.println( " creating a new environment for Introspection object" );
183 TestEnvironment tEnv = new TestEnvironment( oObj );
185 tEnv.addObjRelation("NR","NestedRegistry");
187 tEnv.addObjRelation("XSimpleRegistry.open", openF) ;
188 tEnv.addObjRelation("XSimpleRegistry.merge", mergeF) ;
189 tEnv.addObjRelation("XSimpleRegistry.destroy", destroyF) ;
191 return tEnv;
192 } // finish method getTestEnvironment
194 @Override
195 protected void cleanup( TestParameters Param, PrintWriter log) {
200 } // finish class NestedRegistry