tdf#154285 Check upper bound of arguments in SbRtl_Minute function
[LibreOffice.git] / qadevOOo / tests / java / mod / _nestedreg / uno / NestedRegistry.java
blobb546d56d44a069c56a8994e3db1bd71aa75c551c
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.TestCase;
29 import lib.TestEnvironment;
30 import lib.TestParameters;
31 import util.RegistryTools;
32 import util.utils;
34 /**
35 * Test for object which is represented by service
36 * <code>com.sun.star.registry.NestedRegistry</code>. <p>
37 * Object implements the following interfaces :
38 * <ul>
39 * <li> <code>com::sun::star::registry::XSimpleRegistry</code></li>
40 * <li> <code>com::sun::star::lang::XInitialization</code></li>
41 * </ul>
42 * The following files used by this test :
43 * <ul>
44 * <li><b> XSimpleRegistry.rdb </b> : Registry file created before. </li>
45 * <li><b> XSimpleRegistry_open#.rdb </b> : Temporary registry file as copy of
46 * <b> XSimpleRegistry.rdb </b> in the SOffice temp directory.
47 * ('#' - is an ordinary number) </li>
48 * <li><b> XSimpleRegistry_merge#.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 * </ul> <p>
52 * This object test <b> is NOT </b> designed to be run in several
53 * threads concurrently.
54 * @see com.sun.star.registry.XSimpleRegistry
55 * @see com.sun.star.lang.XInitialization
56 * @see ifc.registry._XSimpleRegistry
57 * @see ifc.lang._XInitialization
59 public class NestedRegistry extends TestCase {
61 protected static int uniq = 0 ;
62 XSimpleRegistry reg1;
63 XSimpleRegistry reg2;
65 @Override
66 public synchronized void disposeTestEnvironment( TestEnvironment tEnv,
67 TestParameters tParam ) {
68 try {
69 reg1.destroy();
70 reg2.destroy();
72 catch (com.sun.star.registry.InvalidRegistryException e) {
73 System.out.println("caught exception: " + 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 copying.
83 protected void copyFile(String src, String dst)
84 throws java.io.IOException {
85 File srcF = new File(src) ;
86 File dstF = new File(dst) ;
88 if (dstF.exists()) {
89 boolean bDeleteOk = dstF.delete();
90 if (!bDeleteOk) {
91 System.out.println("delete failed");
95 boolean bCreateOk = dstF.createNewFile() ;
96 if (!bCreateOk) {
97 System.out.println("create failed");
100 dstF.deleteOnExit() ;
102 FileInputStream fIn = new FileInputStream(srcF) ;
103 FileOutputStream fOut = new FileOutputStream(dstF) ;
105 byte[] buf = new byte[1024] ;
106 int bytesRead = 0 ;
107 while ((bytesRead = fIn.read(buf)) > 0) {
108 fOut.write(buf, 0, bytesRead) ;
111 fIn.close() ;
112 fOut.close() ;
117 * Creating a TestEnvironment for the interfaces to be tested.
118 * Creates two temporary copies of registry file created before, opens
119 * them, and creates service <code>com.sun.star.comp.stoc.NestedRegistry</code>
120 * with these two registries. <p>
121 * Object relations created :
122 * <ul>
123 * <li> <code>'NR'</code> for {@link ifc.registry._XSimpleRegistry} :
124 * Just informs interface test that <code>NestedRegistry</code>
125 * service is tested. If this relation exists, then some methods
126 * are not supported. The relation is a <code>String</code> with
127 * object name.</li>
128 * <li> <code>'XSimpleRegistry.open'</code> for
129 * {@link ifc.registry._XSimpleRegistry}
130 * </li>
131 * <li> <code>'XSimpleRegistry.destroy'</code> for
132 * {@link ifc.registry._XSimpleRegistry}
133 * </li>
134 * <li> <code>'XSimpleRegistry.merge'</code> for
135 * {@link ifc.registry._XSimpleRegistry}
136 * </li>
137 * </ul>
139 @Override
140 protected TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) throws Exception {
141 XInterface oObj = null;
142 Object oInterface = null;
144 final String tmpDir = utils.getOfficeTempDirSys(
145 Param.getMSF()) ;
146 final String openF = tmpDir + "XSimpleRegistry_open" + uniq + ".rdb" ;
147 final String destroyF = tmpDir
148 + "XSimpleRegistry_destroy" + uniq + ".rdb" ;
149 final String mergeF = tmpDir + "XSimpleRegistry_merge" + uniq + ".rdb" ;
150 uniq++ ;
152 log.println("creating copies of the registry for XSimpleRegistry");
153 String source = utils.getFullTestDocName("XSimpleRegistry.rdb");
154 copyFile(source, openF) ;
155 copyFile(source, mergeF) ;
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