Set that a non-modal Popover don't auto-grab focus on popup
[LibreOffice.git] / qadevOOo / tests / java / mod / _simplereg / uno / SimpleRegistry.java
blob99146f159e3d9563049965e7bf6f9fc50510b8a2
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._simplereg.uno;
21 import com.sun.star.lang.XMultiServiceFactory;
22 import com.sun.star.uno.XInterface;
23 import java.io.File;
24 import java.io.FileInputStream;
25 import java.io.FileOutputStream;
26 import java.io.PrintWriter;
27 import lib.TestCase;
28 import lib.TestEnvironment;
29 import lib.TestParameters;
30 import util.utils;
32 /**
33 * Test for object which is represented by service
34 * <code>com.sun.star.registry.SimpleRegistry</code>. <p>
35 * Object implements the following interfaces :
36 * <ul>
37 * <li> <code>com::sun::star::registry::XSimpleRegistry</code></li>
38 * </ul> <p>
39 * The following files used by this test :
40 * <ul>
41 * <li><b> XSimpleRegistry.rdb </b> : a registry file with
42 * some key set. </li>
43 * </ul> <p>
44 * This object test <b> is NOT </b> designed to be run in several
45 * threads concurrently.
47 * @see com.sun.star.registry.XSimpleRegistry
48 * @see ifc.registry._XSimpleRegistry
50 public class SimpleRegistry extends TestCase {
52 /**
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 copying.
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()) {
66 boolean bDeleteOk = dstF.delete();
67 if (!bDeleteOk) {
68 System.out.println("delete failed");
72 System.out.println("H2");
74 boolean bCreateOk = dstF.createNewFile();
75 if (!bCreateOk) {
76 System.out.println("create failed");
79 dstF.deleteOnExit() ;
80 System.out.println("H3");
82 FileInputStream fIn = new FileInputStream(srcF) ;
83 System.out.println("H4");
85 FileOutputStream fOut = new FileOutputStream(dstF) ;
87 byte[] buf = new byte[1024] ;
88 int bytesRead = 0 ;
89 while ((bytesRead = fIn.read(buf)) > 0) {
90 fOut.write(buf, 0, bytesRead) ;
93 fIn.close() ;
94 fOut.close() ;
96 /**
97 * Creating a TestEnvironment for the interfaces to be tested.
98 * Creates an instance of the service
99 * <code>com.sun.star.registry.SimpleRegistry</code>. Then
100 * makes three copies of a predefined registry file with different
101 * names in a temporary SOffice directory and passes their URLs as
102 * relations. <p>
104 * Object relations created :
105 * <ul>
106 * <li> <code>'XSimpleRegistry.open'</code> for
107 * {@link ifc.registry._XSimpleRegistry} :
108 * URL of 'XSimpleRegistry.rbd' file copy in the
109 * temp directory. </li>
110 * <li> <code>'XSimpleRegistry.merge'</code> for
111 * {@link ifc.registry._XSimpleRegistry} :
112 * URL of 'XSimpleRegistry.rbd' file copy in the
113 * temp directory. </li>
114 * <li> <code>'XSimpleRegistry.destroy'</code> for
115 * {@link ifc.registry._XSimpleRegistry} :
116 * URL of 'XSimpleRegistry.rbd' file copy in the
117 * temp directory. </li>
118 * </ul>
120 @Override
121 protected TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) {
122 XInterface oObj = null;
123 Object oInterface = null;
124 final String tmpDir = utils.getOfficeTempDirSys(
125 Param.getMSF()) ;
126 final String openF = "XSimpleRegistry_open.rdb" ;
127 final String destroyF = "XSimpleRegistry_destroy.rdb" ;
128 final String mergeF = "XSimpleRegistry_merge.rdb" ;
131 try {
132 XMultiServiceFactory xMSF = Param.getMSF();
133 oInterface = xMSF.createInstance
134 ( "com.sun.star.registry.SimpleRegistry" );
135 } catch( com.sun.star.uno.Exception e ) {
136 log.println("Service not available" );
139 if (oInterface == null)
140 log.println("Service wasn't created") ;
142 oObj = (XInterface) oInterface;
144 log.println("creating copies of the registry for XSimpleRegistry");
145 try {
146 String source = utils.getFullTestDocName("XSimpleRegistry.rdb");
147 copyFile(source, tmpDir + openF, log);
148 copyFile(source, tmpDir + destroyF, log);
149 copyFile(source, tmpDir + mergeF, log);
150 } catch (java.io.IOException e) {
151 log.println("Exception occurred while copying files");
152 e.printStackTrace(log);
155 log.println( " creating a new environment for object" );
156 TestEnvironment tEnv = new TestEnvironment( oObj );
158 tEnv.addObjRelation("XSimpleRegistry.open", tmpDir + openF);
159 tEnv.addObjRelation("XSimpleRegistry.destroy", tmpDir + destroyF);
160 tEnv.addObjRelation("XSimpleRegistry.merge", tmpDir + mergeF);
162 return tEnv;
163 } // finish method getTestEnvironment
165 } // finish class SimpleRegistry