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 .
22 import java
.io
.FileInputStream
;
23 import java
.io
.FileOutputStream
;
24 import java
.io
.PrintWriter
;
26 import lib
.StatusException
;
28 import lib
.TestEnvironment
;
29 import lib
.TestParameters
;
32 import com
.sun
.star
.lang
.XMultiServiceFactory
;
33 import com
.sun
.star
.uno
.XInterface
;
36 * Test for object which is represented by service
37 * <code>com.sun.star.registry.SimpleRegistry</code>. <p>
38 * Object implements the following interfaces :
40 * <li> <code>com::sun::star::registry::XSimpleRegistry</code></li>
42 * The following files used by this test :
44 * <li><b> XSimpleRegistry.rdb </b> : a registry file with
47 * This object test <b> is NOT </b> designed to be run in several
48 * threads concurrently.
50 * @see com.sun.star.registry.XSimpleRegistry
51 * @see ifc.registry._XSimpleRegistry
53 public class SimpleRegistry
extends TestCase
{
56 * Creates a temporary copy of file, which is deleted when VM exits.
57 * @param src Source file path.
58 * @param dst Destination file path.
59 * @param log The log writer.
60 * @throws java.io.IOException If any problems occur during copying.
62 protected void copyFile(String src
, String dst
, PrintWriter log
)
63 throws java
.io
.IOException
{
64 File srcF
= new File(src
) ;
65 File dstF
= new File(dst
) ;
69 boolean bDeleteOk
= dstF
.delete();
71 System
.out
.println("delete failed");
75 System
.out
.println("H2");
77 boolean bCreateOk
= dstF
.createNewFile();
79 System
.out
.println("create failed");
85 FileInputStream fIn
= new FileInputStream(srcF
) ;
86 System
.out
.println("H4");
88 FileOutputStream fOut
= new FileOutputStream(dstF
) ;
90 byte[] buf
= new byte[1024] ;
92 while ((bytesRead
= fIn
.read(buf
)) > 0) {
93 fOut
.write(buf
, 0, bytesRead
) ;
100 * Creating a TestEnvironment for the interfaces to be tested.
101 * Creates an instance of the service
102 * <code>com.sun.star.registry.SimpleRegistry</code>. Then
103 * makes three copies of a predefined registry file with different
104 * names in a temporary SOffice directory and passes their URLs as
107 * Object relations created :
109 * <li> <code>'XSimpleRegistry.open'</code> for
110 * {@link ifc.registry._XSimpleRegistry} :
111 * URL of 'XSimpleRegistry.rbd' file copy in the
112 * temp directory. </li>
113 * <li> <code>'XSimpleRegistry.merge'</code> for
114 * {@link ifc.registry._XSimpleRegistry} :
115 * URL of 'XSimpleRegistry.rbd' file copy in the
116 * temp directory. </li>
117 * <li> <code>'XSimpleRegistry.destroy'</code> for
118 * {@link ifc.registry._XSimpleRegistry} :
119 * URL of 'XSimpleRegistry.rbd' file copy in the
120 * 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(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
= 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 occurred 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