1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: SimpleRegistry.java,v $
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 ************************************************************************/
34 import java
.io
.FileInputStream
;
35 import java
.io
.FileOutputStream
;
36 import java
.io
.PrintWriter
;
38 import lib
.StatusException
;
40 import lib
.TestEnvironment
;
41 import lib
.TestParameters
;
44 import com
.sun
.star
.lang
.XMultiServiceFactory
;
45 import com
.sun
.star
.uno
.XInterface
;
48 * Test for object which is represented by service
49 * <code>com.sun.star.registry.SimpleRegistry</code>. <p>
50 * Object implements the following interfaces :
52 * <li> <code>com::sun::star::registry::XSimpleRegistry</code></li>
54 * The following files used by this test :
56 * <li><b> XSimpleRegistry.rdb </b> : a registry file with
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
{
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
) ;
80 if (dstF
.exists()) dstF
.delete() ;
82 dstF
.createNewFile() ;
87 FileInputStream fIn
= new FileInputStream(srcF
) ;
88 System
.out
.println("H4");
90 FileOutputStream fOut
= new FileOutputStream(dstF
) ;
92 byte[] buf
= new byte[1024] ;
94 while ((bytesRead
= fIn
.read(buf
)) > 0)
95 fOut
.write(buf
, 0, bytesRead
) ;
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
108 * Object relations created :
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>
124 public TestEnvironment
createTestEnvironment( TestParameters Param
,
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" ;
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");
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
);
167 } // finish method getTestEnvironment
169 } // finish class SimpleRegistry