merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / mod / _simplereg.uno / SimpleRegistry.java
blob4da1e583d77eb458542173d184aa45c8679ff15e
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: SimpleRegistry.java,v $
10 * $Revision: 1.4 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 package mod._simplereg.uno;
33 import com.sun.star.lang.XMultiServiceFactory;
34 import com.sun.star.uno.XInterface;
35 import java.io.File;
36 import java.io.FileInputStream;
37 import java.io.FileOutputStream;
38 import java.io.PrintWriter;
39 import lib.TestCase;
40 import lib.TestEnvironment;
41 import lib.TestParameters;
42 import util.utils;
44 /**
45 * Test for object which is represented by service
46 * <code>com.sun.star.registry.SimpleRegistry</code>. <p>
47 * Object implements the following interfaces :
48 * <ul>
49 * <li> <code>com::sun::star::registry::XSimpleRegistry</code></li>
50 * </ul> <p>
51 * The following files used by this test :
52 * <ul>
53 * <li><b> XSimpleRegistry.rdb </b> : a registry file with
54 * some key set. </li>
55 * </ul> <p>
56 * This object test <b> is NOT </b> designed to be run in several
57 * threads concurently.
59 * @see com.sun.star.registry.XSimpleRegistry
60 * @see ifc.registry._XSimpleRegistry
62 public class SimpleRegistry extends TestCase {
64 /**
65 * Creates a temporary copy of file, which is deleted when VM exits.
66 * @param src Source file path.
67 * @param dst Destination file path.
68 * @param log The log writer.
69 * @throws java.io.IOException If any problems occur during copiing.
71 protected void copyFile(String src, String dst, PrintWriter log)
72 throws java.io.IOException {
73 File srcF = new File(src) ;
74 File dstF = new File(dst) ;
75 System.out.println("H1");
77 if (dstF.exists()) dstF.delete() ;
78 System.out.println("H2");
79 dstF.createNewFile() ;
81 dstF.deleteOnExit() ;
82 System.out.println("H3");
84 FileInputStream fIn = new FileInputStream(srcF) ;
85 System.out.println("H4");
87 FileOutputStream fOut = new FileOutputStream(dstF) ;
89 byte[] buf = new byte[1024] ;
90 int bytesRead = 0 ;
91 while ((bytesRead = fIn.read(buf)) > 0)
92 fOut.write(buf, 0, bytesRead) ;
94 fIn.close() ;
95 fOut.close() ;
97 /**
98 * Creating a Testenvironment for the interfaces to be tested.
99 * Creates an instance of the service
100 * <code>com.sun.star.registry.SimpleRegistry</code>. Then
101 * makes three copies of a predefined registry file with different
102 * names in a temporary SOffice directory and passes their URLs as
103 * relations. <p>
105 * Object relations created :
106 * <ul>
107 * <li> <code>'XSimpleRegistry.open'</code> for
108 * {@link ifc.registry._XSimpleRegistry} :
109 * URL of 'XSimpleRegistry.rbd' file copy in the
110 * temp directory. </li>
111 * <li> <code>'XSimpleRegistry.merge'</code> for
112 * {@link ifc.registry._XSimpleRegistry} :
113 * URL of 'XSimpleRegistry.rbd' file copy in the
114 * temp directory. </li>
115 * <li> <code>'XSimpleRegistry.destroy'</code> for
116 * {@link ifc.registry._XSimpleRegistry} :
117 * URL of 'XSimpleRegistry.rbd' file copy in the
118 * temp directory. </li>
119 * </ul>
121 protected TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) {
122 XInterface oObj = null;
123 Object oInterface = null;
124 final String tmpDir = utils.getOfficeTempDirSys(
125 (XMultiServiceFactory)Param.getMSF()) ;
126 final String openF = "XSimpleRegistry_open.rdb" ;
127 final String destroyF = "XSimpleRegistry_destroy.rdb" ;
128 final String mergeF = "XSimpleRegistry_merge.rdb" ;
131 try {
132 XMultiServiceFactory xMSF = (XMultiServiceFactory)Param.getMSF();
133 oInterface = xMSF.createInstance
134 ( "com.sun.star.registry.SimpleRegistry" );
135 } catch( com.sun.star.uno.Exception e ) {
136 log.println("Service not available" );
139 if (oInterface == null)
140 log.println("Service wasn't created") ;
142 oObj = (XInterface) oInterface;
144 log.println("creating copies of the registry for XSimpleRegistry");
145 try {
146 String source = utils.getFullTestDocName("XSimpleRegistry.rdb");
147 copyFile(source, tmpDir + openF, log);
148 copyFile(source, tmpDir + destroyF, log);
149 copyFile(source, tmpDir + mergeF, log);
150 } catch (java.io.IOException e) {
151 log.println("Exception occured while copying files");
152 e.printStackTrace(log);
155 log.println( " creating a new environment for object" );
156 TestEnvironment tEnv = new TestEnvironment( oObj );
158 tEnv.addObjRelation("XSimpleRegistry.open", tmpDir + openF);
159 tEnv.addObjRelation("XSimpleRegistry.destroy", tmpDir + destroyF);
160 tEnv.addObjRelation("XSimpleRegistry.merge", tmpDir + mergeF);
162 return tEnv;
163 } // finish method getTestEnvironment
165 } // finish class SimpleRegistry