1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 package mod._simplereg.uno; 29 30 import com.sun.star.lang.XMultiServiceFactory; 31 import com.sun.star.uno.XInterface; 32 import java.io.File; 33 import java.io.FileInputStream; 34 import java.io.FileOutputStream; 35 import java.io.PrintWriter; 36 import lib.TestCase; 37 import lib.TestEnvironment; 38 import lib.TestParameters; 39 import util.utils; 40 41 /** 42 * Test for object which is represented by service 43 * <code>com.sun.star.registry.SimpleRegistry</code>. <p> 44 * Object implements the following interfaces : 45 * <ul> 46 * <li> <code>com::sun::star::registry::XSimpleRegistry</code></li> 47 * </ul> <p> 48 * The following files used by this test : 49 * <ul> 50 * <li><b> XSimpleRegistry.rdb </b> : a registry file with 51 * some key set. </li> 52 * </ul> <p> 53 * This object test <b> is NOT </b> designed to be run in several 54 * threads concurently. 55 * 56 * @see com.sun.star.registry.XSimpleRegistry 57 * @see ifc.registry._XSimpleRegistry 58 */ 59 public class SimpleRegistry extends TestCase { 60 61 /** 62 * Creates a temporary copy of file, which is deleted when VM exits. 63 * @param src Source file path. 64 * @param dst Destination file path. 65 * @param log The log writer. 66 * @throws java.io.IOException If any problems occur during copiing. 67 */ 68 protected void copyFile(String src, String dst, PrintWriter log) 69 throws java.io.IOException { 70 File srcF = new File(src) ; 71 File dstF = new File(dst) ; 72 System.out.println("H1"); 73 74 if (dstF.exists()) dstF.delete() ; 75 System.out.println("H2"); 76 dstF.createNewFile() ; 77 78 dstF.deleteOnExit() ; 79 System.out.println("H3"); 80 81 FileInputStream fIn = new FileInputStream(srcF) ; 82 System.out.println("H4"); 83 84 FileOutputStream fOut = new FileOutputStream(dstF) ; 85 86 byte[] buf = new byte[1024] ; 87 int bytesRead = 0 ; 88 while ((bytesRead = fIn.read(buf)) > 0) 89 fOut.write(buf, 0, bytesRead) ; 90 91 fIn.close() ; 92 fOut.close() ; 93 } 94 /** 95 * Creating a Testenvironment for the interfaces to be tested. 96 * Creates an instance of the service 97 * <code>com.sun.star.registry.SimpleRegistry</code>. Then 98 * makes three copies of a predefined registry file with different 99 * names in a temporary SOffice directory and passes their URLs as 100 * relations. <p> 101 * 102 * Object relations created : 103 * <ul> 104 * <li> <code>'XSimpleRegistry.open'</code> for 105 * {@link ifc.registry._XSimpleRegistry} : 106 * URL of 'XSimpleRegistry.rbd' file copy in the 107 * temp directory. </li> 108 * <li> <code>'XSimpleRegistry.merge'</code> for 109 * {@link ifc.registry._XSimpleRegistry} : 110 * URL of 'XSimpleRegistry.rbd' file copy in the 111 * temp directory. </li> 112 * <li> <code>'XSimpleRegistry.destroy'</code> for 113 * {@link ifc.registry._XSimpleRegistry} : 114 * URL of 'XSimpleRegistry.rbd' file copy in the 115 * temp directory. </li> 116 * </ul> 117 */ 118 protected TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) { 119 XInterface oObj = null; 120 Object oInterface = null; 121 final String tmpDir = utils.getOfficeTempDirSys( 122 (XMultiServiceFactory)Param.getMSF()) ; 123 final String openF = "XSimpleRegistry_open.rdb" ; 124 final String destroyF = "XSimpleRegistry_destroy.rdb" ; 125 final String mergeF = "XSimpleRegistry_merge.rdb" ; 126 127 128 try { 129 XMultiServiceFactory xMSF = (XMultiServiceFactory)Param.getMSF(); 130 oInterface = xMSF.createInstance 131 ( "com.sun.star.registry.SimpleRegistry" ); 132 } catch( com.sun.star.uno.Exception e ) { 133 log.println("Service not available" ); 134 } 135 136 if (oInterface == null) 137 log.println("Service wasn't created") ; 138 139 oObj = (XInterface) oInterface; 140 141 log.println("creating copies of the registry for XSimpleRegistry"); 142 try { 143 String source = utils.getFullTestDocName("XSimpleRegistry.rdb"); 144 copyFile(source, tmpDir + openF, log); 145 copyFile(source, tmpDir + destroyF, log); 146 copyFile(source, tmpDir + mergeF, log); 147 } catch (java.io.IOException e) { 148 log.println("Exception occured while copying files"); 149 e.printStackTrace(log); 150 } 151 152 log.println( " creating a new environment for object" ); 153 TestEnvironment tEnv = new TestEnvironment( oObj ); 154 155 tEnv.addObjRelation("XSimpleRegistry.open", tmpDir + openF); 156 tEnv.addObjRelation("XSimpleRegistry.destroy", tmpDir + destroyF); 157 tEnv.addObjRelation("XSimpleRegistry.merge", tmpDir + mergeF); 158 159 return tEnv; 160 } // finish method getTestEnvironment 161 162 } // finish class SimpleRegistry 163 164