merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / mod / _simreg / SimpleRegistry.java
blobf7a11d59eb517d18f449f139c12c1505669a79db
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.5 $
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._simreg;
33 import java.io.File;
34 import java.io.FileInputStream;
35 import java.io.FileOutputStream;
36 import java.io.PrintWriter;
38 import lib.StatusException;
39 import lib.TestCase;
40 import lib.TestEnvironment;
41 import lib.TestParameters;
42 import util.utils;
44 import com.sun.star.lang.XMultiServiceFactory;
45 import com.sun.star.uno.XInterface;
47 /**
48 * Test for object which is represented by service
49 * <code>com.sun.star.registry.SimpleRegistry</code>. <p>
50 * Object implements the following interfaces :
51 * <ul>
52 * <li> <code>com::sun::star::registry::XSimpleRegistry</code></li>
53 * </ul> <p>
54 * The following files used by this test :
55 * <ul>
56 * <li><b> XSimpleRegistry.rdb </b> : a registry file with
57 * some key set. </li>
58 * </ul> <p>
59 * This object test <b> is NOT </b> designed to be run in several
60 * threads concurently.
62 * @see com.sun.star.registry.XSimpleRegistry
63 * @see ifc.registry._XSimpleRegistry
65 public class SimpleRegistry extends TestCase {
67 /**
68 * Creates a temporary copy of file, which is deleted when VM exits.
69 * @param src Source file path.
70 * @param dst Destination file path.
71 * @param log The log writer.
72 * @throws java.io.IOException If any problems occur during copiing.
74 protected void copyFile(String src, String dst, PrintWriter log)
75 throws java.io.IOException {
76 File srcF = new File(src) ;
77 File dstF = new File(dst) ;
78 log.println("H1");
80 if (dstF.exists()) dstF.delete() ;
81 log.println("H2");
82 dstF.createNewFile() ;
84 dstF.deleteOnExit() ;
85 log.println("H3");
87 FileInputStream fIn = new FileInputStream(srcF) ;
88 System.out.println("H4");
90 FileOutputStream fOut = new FileOutputStream(dstF) ;
92 byte[] buf = new byte[1024] ;
93 int bytesRead = 0 ;
94 while ((bytesRead = fIn.read(buf)) > 0)
95 fOut.write(buf, 0, bytesRead) ;
97 fIn.close() ;
98 fOut.close() ;
101 * Creating a Testenvironment for the interfaces to be tested.
102 * Creates an instance of the service
103 * <code>com.sun.star.registry.SimpleRegistry</code>. Then
104 * makes three copies of a predefined registry file with different
105 * names in a temporary SOffice directory and passes their URLs as
106 * relations. <p>
108 * Object relations created :
109 * <ul>
110 * <li> <code>'XSimpleRegistry.open'</code> for
111 * {@link ifc.registry._XSimpleRegistry} :
112 * URL of 'XSimpleRegistry.rbd' file copy in the
113 * temp directory. </li>
114 * <li> <code>'XSimpleRegistry.merge'</code> for
115 * {@link ifc.registry._XSimpleRegistry} :
116 * URL of 'XSimpleRegistry.rbd' file copy in the
117 * temp directory. </li>
118 * <li> <code>'XSimpleRegistry.destroy'</code> for
119 * {@link ifc.registry._XSimpleRegistry} :
120 * URL of 'XSimpleRegistry.rbd' file copy in the
121 * temp directory. </li>
122 * </ul>
124 public TestEnvironment createTestEnvironment( TestParameters Param,
125 PrintWriter log )
126 throws StatusException {
127 XInterface oObj = null;
128 Object oInterface = null;
129 final String tmpDir = utils.getOfficeTempDirSys((XMultiServiceFactory)Param.getMSF()) ;
130 final String openF = "XSimpleRegistry_open.rdb" ;
131 final String destroyF = "XSimpleRegistry_destroy.rdb" ;
132 final String mergeF = "XSimpleRegistry_merge.rdb" ;
135 try {
136 XMultiServiceFactory xMSF = (XMultiServiceFactory)Param.getMSF();
137 oInterface = xMSF.createInstance
138 ( "com.sun.star.registry.SimpleRegistry" );
139 } catch( com.sun.star.uno.Exception e ) {
140 log.println("Service not available" );
143 if (oInterface == null)
144 log.println("Service wasn't created") ;
146 oObj = (XInterface) oInterface;
148 log.println("creating copies of the registry for XSimpleRegistry");
149 try {
150 String source = utils.getFullTestDocName("XSimpleRegistry.rdb");
151 copyFile(source, tmpDir + openF, log);
152 copyFile(source, tmpDir + destroyF, log);
153 copyFile(source, tmpDir + mergeF, log);
154 } catch (java.io.IOException e) {
155 log.println("Exception occured while copying files");
156 e.printStackTrace(log);
159 log.println( " creating a new environment for object" );
160 TestEnvironment tEnv = new TestEnvironment( oObj );
162 tEnv.addObjRelation("XSimpleRegistry.open", tmpDir + openF);
163 tEnv.addObjRelation("XSimpleRegistry.destroy", tmpDir + destroyF);
164 tEnv.addObjRelation("XSimpleRegistry.merge", tmpDir + mergeF);
166 return tEnv;
167 } // finish method getTestEnvironment
169 } // finish class SimpleRegistry