1ef39d40dSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3ef39d40dSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4ef39d40dSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5ef39d40dSAndrew Rist  * distributed with this work for additional information
6ef39d40dSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7ef39d40dSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8ef39d40dSAndrew Rist  * "License"); you may not use this file except in compliance
9ef39d40dSAndrew Rist  * with the License.  You may obtain a copy of the License at
10ef39d40dSAndrew Rist  *
11ef39d40dSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12ef39d40dSAndrew Rist  *
13ef39d40dSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14ef39d40dSAndrew Rist  * software distributed under the License is distributed on an
15ef39d40dSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16ef39d40dSAndrew Rist  * KIND, either express or implied.  See the License for the
17ef39d40dSAndrew Rist  * specific language governing permissions and limitations
18ef39d40dSAndrew Rist  * under the License.
19ef39d40dSAndrew Rist  *
20ef39d40dSAndrew Rist  *************************************************************/
21ef39d40dSAndrew Rist 
22ef39d40dSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir package mod._simplereg.uno;
25cdf0e10cSrcweir 
26cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory;
27cdf0e10cSrcweir import com.sun.star.uno.XInterface;
28cdf0e10cSrcweir import java.io.File;
29cdf0e10cSrcweir import java.io.FileInputStream;
30cdf0e10cSrcweir import java.io.FileOutputStream;
31cdf0e10cSrcweir import java.io.PrintWriter;
32cdf0e10cSrcweir import lib.TestCase;
33cdf0e10cSrcweir import lib.TestEnvironment;
34cdf0e10cSrcweir import lib.TestParameters;
35cdf0e10cSrcweir import util.utils;
36cdf0e10cSrcweir 
37cdf0e10cSrcweir /**
38cdf0e10cSrcweir  * Test for object which is represented by service
39cdf0e10cSrcweir  * <code>com.sun.star.registry.SimpleRegistry</code>. <p>
40cdf0e10cSrcweir  * Object implements the following interfaces :
41cdf0e10cSrcweir  * <ul>
42cdf0e10cSrcweir  *  <li> <code>com::sun::star::registry::XSimpleRegistry</code></li>
43cdf0e10cSrcweir  * </ul> <p>
44cdf0e10cSrcweir  * The following files used by this test :
45cdf0e10cSrcweir  * <ul>
46cdf0e10cSrcweir  *  <li><b> XSimpleRegistry.rdb </b> : a registry file with
47cdf0e10cSrcweir  *   some key set. </li>
48cdf0e10cSrcweir  * </ul> <p>
49cdf0e10cSrcweir  * This object test <b> is NOT </b> designed to be run in several
50cdf0e10cSrcweir  * threads concurently.
51cdf0e10cSrcweir  *
52cdf0e10cSrcweir  * @see com.sun.star.registry.XSimpleRegistry
53cdf0e10cSrcweir  * @see ifc.registry._XSimpleRegistry
54cdf0e10cSrcweir  */
55cdf0e10cSrcweir public class SimpleRegistry extends TestCase {
56cdf0e10cSrcweir 
57cdf0e10cSrcweir     /**
58cdf0e10cSrcweir     * Creates a temporary copy of file, which is deleted when VM exits.
59cdf0e10cSrcweir     * @param src Source file path.
60cdf0e10cSrcweir     * @param dst Destination file path.
61cdf0e10cSrcweir     * @param log The log writer.
62cdf0e10cSrcweir     * @throws java.io.IOException If any problems occur during copiing.
63cdf0e10cSrcweir     */
copyFile(String src, String dst, PrintWriter log)64cdf0e10cSrcweir     protected void copyFile(String src, String dst, PrintWriter log)
65cdf0e10cSrcweir             throws java.io.IOException {
66cdf0e10cSrcweir         File srcF = new File(src) ;
67cdf0e10cSrcweir         File dstF = new File(dst) ;
68cdf0e10cSrcweir         System.out.println("H1");
69cdf0e10cSrcweir 
70cdf0e10cSrcweir         if (dstF.exists()) dstF.delete() ;
71cdf0e10cSrcweir         System.out.println("H2");
72cdf0e10cSrcweir         dstF.createNewFile() ;
73cdf0e10cSrcweir 
74cdf0e10cSrcweir         dstF.deleteOnExit() ;
75cdf0e10cSrcweir         System.out.println("H3");
76cdf0e10cSrcweir 
77cdf0e10cSrcweir         FileInputStream fIn = new FileInputStream(srcF) ;
78cdf0e10cSrcweir         System.out.println("H4");
79cdf0e10cSrcweir 
80cdf0e10cSrcweir         FileOutputStream fOut = new FileOutputStream(dstF) ;
81cdf0e10cSrcweir 
82cdf0e10cSrcweir         byte[] buf = new byte[1024] ;
83cdf0e10cSrcweir         int bytesRead = 0 ;
84cdf0e10cSrcweir         while ((bytesRead = fIn.read(buf)) > 0)
85cdf0e10cSrcweir             fOut.write(buf, 0, bytesRead) ;
86cdf0e10cSrcweir 
87cdf0e10cSrcweir         fIn.close() ;
88cdf0e10cSrcweir         fOut.close() ;
89cdf0e10cSrcweir     }
90cdf0e10cSrcweir     /**
91cdf0e10cSrcweir      * Creating a Testenvironment for the interfaces to be tested.
92cdf0e10cSrcweir      * Creates an instance of the service
93cdf0e10cSrcweir      * <code>com.sun.star.registry.SimpleRegistry</code>. Then
94cdf0e10cSrcweir      * makes three copies of a predefined registry file with different
95cdf0e10cSrcweir      * names in a temporary SOffice directory and passes their URLs as
96cdf0e10cSrcweir      * relations. <p>
97cdf0e10cSrcweir      *
98cdf0e10cSrcweir      *     Object relations created :
99cdf0e10cSrcweir      * <ul>
100cdf0e10cSrcweir      *  <li> <code>'XSimpleRegistry.open'</code> for
101cdf0e10cSrcweir      *      {@link ifc.registry._XSimpleRegistry} :
102cdf0e10cSrcweir      *       URL of 'XSimpleRegistry.rbd' file copy in the
103cdf0e10cSrcweir      *       temp directory. </li>
104cdf0e10cSrcweir      *  <li> <code>'XSimpleRegistry.merge'</code> for
105cdf0e10cSrcweir      *      {@link ifc.registry._XSimpleRegistry} :
106cdf0e10cSrcweir      *       URL of 'XSimpleRegistry.rbd' file copy in the
107cdf0e10cSrcweir      *       temp directory. </li>
108cdf0e10cSrcweir      *  <li> <code>'XSimpleRegistry.destroy'</code> for
109cdf0e10cSrcweir      *      {@link ifc.registry._XSimpleRegistry} :
110cdf0e10cSrcweir      *       URL of 'XSimpleRegistry.rbd' file copy in the
111cdf0e10cSrcweir      *       temp directory. </li>
112cdf0e10cSrcweir      * </ul>
113cdf0e10cSrcweir      */
createTestEnvironment(TestParameters Param, PrintWriter log)114cdf0e10cSrcweir     protected TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) {
115cdf0e10cSrcweir         XInterface oObj = null;
116cdf0e10cSrcweir         Object oInterface = null;
117cdf0e10cSrcweir         final String tmpDir = utils.getOfficeTempDirSys(
118cdf0e10cSrcweir                                 (XMultiServiceFactory)Param.getMSF()) ;
119cdf0e10cSrcweir         final String openF = "XSimpleRegistry_open.rdb" ;
120cdf0e10cSrcweir         final String destroyF = "XSimpleRegistry_destroy.rdb" ;
121cdf0e10cSrcweir         final String mergeF = "XSimpleRegistry_merge.rdb" ;
122cdf0e10cSrcweir 
123cdf0e10cSrcweir 
124cdf0e10cSrcweir         try {
125cdf0e10cSrcweir             XMultiServiceFactory xMSF = (XMultiServiceFactory)Param.getMSF();
126cdf0e10cSrcweir             oInterface = xMSF.createInstance
127cdf0e10cSrcweir                 ( "com.sun.star.registry.SimpleRegistry" );
128cdf0e10cSrcweir         } catch( com.sun.star.uno.Exception e ) {
129cdf0e10cSrcweir             log.println("Service not available" );
130cdf0e10cSrcweir         }
131cdf0e10cSrcweir 
132cdf0e10cSrcweir         if (oInterface == null)
133cdf0e10cSrcweir             log.println("Service wasn't created") ;
134cdf0e10cSrcweir 
135cdf0e10cSrcweir         oObj = (XInterface) oInterface;
136cdf0e10cSrcweir 
137cdf0e10cSrcweir         log.println("creating copies of the registry for XSimpleRegistry");
138cdf0e10cSrcweir        try {
139cdf0e10cSrcweir             String source = utils.getFullTestDocName("XSimpleRegistry.rdb");
140cdf0e10cSrcweir             copyFile(source, tmpDir + openF, log);
141cdf0e10cSrcweir             copyFile(source, tmpDir + destroyF, log);
142cdf0e10cSrcweir             copyFile(source, tmpDir + mergeF, log);
143cdf0e10cSrcweir         } catch (java.io.IOException e) {
144*bb6af6bcSPedro Giffuni             log.println("Exception occurred while copying files");
145cdf0e10cSrcweir             e.printStackTrace(log);
146cdf0e10cSrcweir         }
147cdf0e10cSrcweir 
148cdf0e10cSrcweir         log.println( "    creating a new environment for object" );
149cdf0e10cSrcweir         TestEnvironment tEnv = new TestEnvironment( oObj );
150cdf0e10cSrcweir 
151cdf0e10cSrcweir         tEnv.addObjRelation("XSimpleRegistry.open", tmpDir + openF);
152cdf0e10cSrcweir         tEnv.addObjRelation("XSimpleRegistry.destroy", tmpDir + destroyF);
153cdf0e10cSrcweir         tEnv.addObjRelation("XSimpleRegistry.merge", tmpDir + mergeF);
154cdf0e10cSrcweir 
155cdf0e10cSrcweir         return tEnv;
156cdf0e10cSrcweir     } // finish method getTestEnvironment
157cdf0e10cSrcweir 
158cdf0e10cSrcweir }    // finish class SimpleRegistry
159cdf0e10cSrcweir 
160