bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _simreg / SimpleRegistry.java
blobcc8cafc9b49bc3b1f42fcf8e0ee6ad009b695579
1 /*
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._simreg;
21 import java.io.File;
22 import java.io.FileInputStream;
23 import java.io.FileOutputStream;
24 import java.io.PrintWriter;
26 import lib.StatusException;
27 import lib.TestCase;
28 import lib.TestEnvironment;
29 import lib.TestParameters;
30 import util.utils;
32 import com.sun.star.lang.XMultiServiceFactory;
33 import com.sun.star.uno.XInterface;
35 /**
36 * Test for object which is represented by service
37 * <code>com.sun.star.registry.SimpleRegistry</code>. <p>
38 * Object implements the following interfaces :
39 * <ul>
40 * <li> <code>com::sun::star::registry::XSimpleRegistry</code></li>
41 * </ul> <p>
42 * The following files used by this test :
43 * <ul>
44 * <li><b> XSimpleRegistry.rdb </b> : a registry file with
45 * some key set. </li>
46 * </ul> <p>
47 * This object test <b> is NOT </b> designed to be run in several
48 * threads concurently.
50 * @see com.sun.star.registry.XSimpleRegistry
51 * @see ifc.registry._XSimpleRegistry
53 public class SimpleRegistry extends TestCase {
55 /**
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 copiing.
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) ;
66 log.println("H1");
68 if (dstF.exists()) dstF.delete() ;
69 log.println("H2");
70 dstF.createNewFile() ;
72 dstF.deleteOnExit() ;
73 log.println("H3");
75 FileInputStream fIn = new FileInputStream(srcF) ;
76 System.out.println("H4");
78 FileOutputStream fOut = new FileOutputStream(dstF) ;
80 byte[] buf = new byte[1024] ;
81 int bytesRead = 0 ;
82 while ((bytesRead = fIn.read(buf)) > 0)
83 fOut.write(buf, 0, bytesRead) ;
85 fIn.close() ;
86 fOut.close() ;
88 /**
89 * Creating a Testenvironment for the interfaces to be tested.
90 * Creates an instance of the service
91 * <code>com.sun.star.registry.SimpleRegistry</code>. Then
92 * makes three copies of a predefined registry file with different
93 * names in a temporary SOffice directory and passes their URLs as
94 * relations. <p>
96 * Object relations created :
97 * <ul>
98 * <li> <code>'XSimpleRegistry.open'</code> for
99 * {@link ifc.registry._XSimpleRegistry} :
100 * URL of 'XSimpleRegistry.rbd' file copy in the
101 * temp directory. </li>
102 * <li> <code>'XSimpleRegistry.merge'</code> for
103 * {@link ifc.registry._XSimpleRegistry} :
104 * URL of 'XSimpleRegistry.rbd' file copy in the
105 * temp directory. </li>
106 * <li> <code>'XSimpleRegistry.destroy'</code> for
107 * {@link ifc.registry._XSimpleRegistry} :
108 * URL of 'XSimpleRegistry.rbd' file copy in the
109 * temp directory. </li>
110 * </ul>
112 public TestEnvironment createTestEnvironment( TestParameters Param,
113 PrintWriter log )
114 throws StatusException {
115 XInterface oObj = null;
116 Object oInterface = null;
117 final String tmpDir = utils.getOfficeTempDirSys((XMultiServiceFactory)Param.getMSF()) ;
118 final String openF = "XSimpleRegistry_open.rdb" ;
119 final String destroyF = "XSimpleRegistry_destroy.rdb" ;
120 final String mergeF = "XSimpleRegistry_merge.rdb" ;
123 try {
124 XMultiServiceFactory xMSF = (XMultiServiceFactory)Param.getMSF();
125 oInterface = xMSF.createInstance
126 ( "com.sun.star.registry.SimpleRegistry" );
127 } catch( com.sun.star.uno.Exception e ) {
128 log.println("Service not available" );
131 if (oInterface == null)
132 log.println("Service wasn't created") ;
134 oObj = (XInterface) oInterface;
136 log.println("creating copies of the registry for XSimpleRegistry");
137 try {
138 String source = utils.getFullTestDocName("XSimpleRegistry.rdb");
139 copyFile(source, tmpDir + openF, log);
140 copyFile(source, tmpDir + destroyF, log);
141 copyFile(source, tmpDir + mergeF, log);
142 } catch (java.io.IOException e) {
143 log.println("Exception occurred while copying files");
144 e.printStackTrace(log);
147 log.println( " creating a new environment for object" );
148 TestEnvironment tEnv = new TestEnvironment( oObj );
150 tEnv.addObjRelation("XSimpleRegistry.open", tmpDir + openF);
151 tEnv.addObjRelation("XSimpleRegistry.destroy", tmpDir + destroyF);
152 tEnv.addObjRelation("XSimpleRegistry.merge", tmpDir + mergeF);
154 return tEnv;
155 } // finish method getTestEnvironment
157 } // finish class SimpleRegistry