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
._simplereg
.uno
;
21 import com
.sun
.star
.lang
.XMultiServiceFactory
;
22 import com
.sun
.star
.uno
.XInterface
;
24 import java
.io
.FileInputStream
;
25 import java
.io
.FileOutputStream
;
26 import java
.io
.PrintWriter
;
28 import lib
.TestEnvironment
;
29 import lib
.TestParameters
;
33 * Test for object which is represented by service
34 * <code>com.sun.star.registry.SimpleRegistry</code>. <p>
35 * Object implements the following interfaces :
37 * <li> <code>com::sun::star::registry::XSimpleRegistry</code></li>
39 * The following files used by this test :
41 * <li><b> XSimpleRegistry.rdb </b> : a registry file with
44 * This object test <b> is NOT </b> designed to be run in several
45 * threads concurently.
47 * @see com.sun.star.registry.XSimpleRegistry
48 * @see ifc.registry._XSimpleRegistry
50 public class SimpleRegistry
extends TestCase
{
53 * Creates a temporary copy of file, which is deleted when VM exits.
54 * @param src Source file path.
55 * @param dst Destination file path.
56 * @param log The log writer.
57 * @throws java.io.IOException If any problems occur during copiing.
59 protected void copyFile(String src
, String dst
, PrintWriter log
)
60 throws java
.io
.IOException
{
61 File srcF
= new File(src
) ;
62 File dstF
= new File(dst
) ;
63 System
.out
.println("H1");
65 if (dstF
.exists()) dstF
.delete() ;
66 System
.out
.println("H2");
67 dstF
.createNewFile() ;
70 System
.out
.println("H3");
72 FileInputStream fIn
= new FileInputStream(srcF
) ;
73 System
.out
.println("H4");
75 FileOutputStream fOut
= new FileOutputStream(dstF
) ;
77 byte[] buf
= new byte[1024] ;
79 while ((bytesRead
= fIn
.read(buf
)) > 0) {
80 fOut
.write(buf
, 0, bytesRead
) ;
87 * Creating a Testenvironment for the interfaces to be tested.
88 * Creates an instance of the service
89 * <code>com.sun.star.registry.SimpleRegistry</code>. Then
90 * makes three copies of a predefined registry file with different
91 * names in a temporary SOffice directory and passes their URLs as
94 * Object relations created :
96 * <li> <code>'XSimpleRegistry.open'</code> for
97 * {@link ifc.registry._XSimpleRegistry} :
98 * URL of 'XSimpleRegistry.rbd' file copy in the
99 * temp directory. </li>
100 * <li> <code>'XSimpleRegistry.merge'</code> for
101 * {@link ifc.registry._XSimpleRegistry} :
102 * URL of 'XSimpleRegistry.rbd' file copy in the
103 * temp directory. </li>
104 * <li> <code>'XSimpleRegistry.destroy'</code> for
105 * {@link ifc.registry._XSimpleRegistry} :
106 * URL of 'XSimpleRegistry.rbd' file copy in the
107 * temp directory. </li>
111 protected TestEnvironment
createTestEnvironment(TestParameters Param
, PrintWriter log
) {
112 XInterface oObj
= null;
113 Object oInterface
= null;
114 final String tmpDir
= utils
.getOfficeTempDirSys(
116 final String openF
= "XSimpleRegistry_open.rdb" ;
117 final String destroyF
= "XSimpleRegistry_destroy.rdb" ;
118 final String mergeF
= "XSimpleRegistry_merge.rdb" ;
122 XMultiServiceFactory xMSF
= Param
.getMSF();
123 oInterface
= xMSF
.createInstance
124 ( "com.sun.star.registry.SimpleRegistry" );
125 } catch( com
.sun
.star
.uno
.Exception e
) {
126 log
.println("Service not available" );
129 if (oInterface
== null)
130 log
.println("Service wasn't created") ;
132 oObj
= (XInterface
) oInterface
;
134 log
.println("creating copies of the registry for XSimpleRegistry");
136 String source
= utils
.getFullTestDocName("XSimpleRegistry.rdb");
137 copyFile(source
, tmpDir
+ openF
, log
);
138 copyFile(source
, tmpDir
+ destroyF
, log
);
139 copyFile(source
, tmpDir
+ mergeF
, log
);
140 } catch (java
.io
.IOException e
) {
141 log
.println("Exception occurred while copying files");
142 e
.printStackTrace(log
);
145 log
.println( " creating a new environment for object" );
146 TestEnvironment tEnv
= new TestEnvironment( oObj
);
148 tEnv
.addObjRelation("XSimpleRegistry.open", tmpDir
+ openF
);
149 tEnv
.addObjRelation("XSimpleRegistry.destroy", tmpDir
+ destroyF
);
150 tEnv
.addObjRelation("XSimpleRegistry.merge", tmpDir
+ mergeF
);
153 } // finish method getTestEnvironment
155 } // finish class SimpleRegistry