tdf#130857 qt weld: Introduce QtInstanceScrolledWindow
[LibreOffice.git] / qadevOOo / tests / java / mod / _dbaccess / ODatabaseSource.java
blob1976f5711d779630ec3ecae22b77c1af0287d6f7
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._dbaccess;
21 import com.sun.star.beans.PropertyValue;
22 import com.sun.star.beans.XPropertySet;
23 import com.sun.star.frame.XStorable;
26 import com.sun.star.uno.Exception;
27 import com.sun.star.uno.UnoRuntime;
28 import com.sun.star.uno.XInterface;
29 import com.sun.star.uno.XNamingService;
30 import java.io.PrintWriter;
31 import lib.StatusException;
32 import lib.TestCase;
33 import lib.TestEnvironment;
34 import lib.TestParameters;
35 import util.DesktopTools;
36 import util.utils;
38 import com.sun.star.lang.XMultiServiceFactory;
39 import com.sun.star.sdb.XOfficeDatabaseDocument;
40 import com.sun.star.task.XInteractionHandler;
42 /**
43 * Test for object which is represented by service
44 * <code>com.sun.star.sdb.DataSource</code>. <p>
46 * Object implements the following interfaces :
47 * <ul>
48 * <li> <code>com::sun::star::sdb::XQueryDefinitionsSupplier</code></li>
49 * <li> <code>com::sun::star::sdb::DataSource</code></li>
50 * <li> <code>com::sun::star::sdb::XCompletedConnection</code></li>
51 * <li> <code>com::sun::star::util::XFlushable</code></li>
52 * <li> <code>com::sun::star::sdb::XBookmarksSupplier</code></li>
53 * <li> <code>com::sun::star::beans::XPropertySet</code></li>
54 * </ul>
56 * @see com.sun.star.sdb.XQueryDefinitionsSupplier
57 * @see com.sun.star.sdb.XFormDocumentsSupplier
58 * @see com.sun.star.beans.XPropertySet
59 * @see com.sun.star.sdb.DataSource
60 * @see com.sun.star.sdb.XCompletedConnection
61 * @see com.sun.star.util.XFlushable
62 * @see com.sun.star.sdb.XReportDocumentsSupplier
63 * @see ifc.sdb._XQueryDefinitionsSupplier
64 * @see ifc.sdb._XFormDocumentsSupplier
65 * @see ifc.beans._XPropertySet
66 * @see ifc.sdb._DataSource
67 * @see ifc.sdb._XCompletedConnection
68 * @see ifc.util._XFlushable
69 * @see ifc.sdb._XReportDocumentsSupplier
71 public class ODatabaseSource extends TestCase {
73 private static int uniqueSuffixStat = 0 ;
75 private int uniqueSuffix = 0 ;
76 private XOfficeDatabaseDocument xDBDoc = null;
78 /**
79 * Assigns database's name unique suffix for this object depending
80 * on static field. For names differs in different object threads.
82 @Override
83 protected void initialize ( TestParameters Param, PrintWriter log) throws Exception {
84 uniqueSuffix = uniqueSuffixStat++ ;
87 @Override
88 protected void cleanup(TestParameters tParam, PrintWriter log) {
89 log.println(" disposing no longer needed docs... ");
90 DesktopTools.closeDoc(xDBDoc);
95 /**
96 * Creating a TestEnvironment for the interfaces to be tested.
98 * Creates new <code>DataSource</code> which represents DBase database
99 * located in temporary directory, and then registers it in service
100 * <code>com.sun.star.sdb.DatabaseContext</code>.
102 * Created object relations :
103 * <ul>
104 * <li> <code>'XCompletedConnection.Handler'</code> for interface test
105 * <code>XCompletedConnection</code> </li>
106 * </ul>
107 * <li> <code>'UserAndPassword'</code> for interface test
108 * <code>XIsolatedConnection</code> </li>
109 * </ul>
110 * @see com.sun.star.sdb.DatabaseContext
111 * @see com.sun.star.sdb.DataSource
113 @Override
114 protected TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) throws Exception {
115 XMultiServiceFactory xMSF = Param.getMSF();
116 Object oInterface = xMSF.createInstance( "com.sun.star.sdb.DatabaseContext" );
118 XNamingService xDBContextNameServ = UnoRuntime.queryInterface(XNamingService.class, oInterface) ;
120 // retrieving temp directory for database
121 String tmpDatabaseUrl = utils.getOfficeTempDir(Param.getMSF());
123 tmpDatabaseUrl = "sdbc:dbase:file:///" + tmpDatabaseUrl ;
125 XInterface oDatabaseDoc = (XInterface) xMSF.createInstance
126 ("com.sun.star.sdb.OfficeDatabaseDocument") ;
128 if (oDatabaseDoc == null)
129 throw new StatusException("Could not get service 'com.sun.star.sdb.OfficeDatabaseDocument'", new Exception());
131 xDBDoc = UnoRuntime.queryInterface(
132 XOfficeDatabaseDocument.class,
133 oDatabaseDoc);
134 XInterface oObj = xDBDoc.getDataSource();
135 log.println("ImplementationName: " + utils.getImplName(oObj));
137 // Creating new DBase data source in the TEMP directory
139 XPropertySet xSrcProp = UnoRuntime.queryInterface(XPropertySet.class, oObj);
141 xSrcProp.setPropertyValue("URL", tmpDatabaseUrl) ;
143 String databaseName = "NewDatabaseSource" + uniqueSuffix ;
145 // make sure that the DatabaseContext isn't already registered
146 try {
147 xDBContextNameServ.revokeObject(databaseName) ;
148 } catch (Exception e) {
149 log.println("Nothing to be removed - OK");
152 // registering source in DatabaseContext
153 XStorable store = UnoRuntime.queryInterface(XStorable.class, xDBDoc);
154 String aFile = utils.getOfficeTemp (Param.getMSF ())+"DataSource.odb";
155 store.storeAsURL(aFile,new PropertyValue[]{});
157 xDBContextNameServ.registerObject(databaseName, oObj) ;
159 log.println( " creating a new environment for object" );
160 TestEnvironment tEnv = new TestEnvironment( oObj );
162 // adding obj relation for interface XCompletedConnection
163 Object handler = Param.getMSF().createInstance
164 ("com.sun.star.sdb.InteractionHandler") ;
166 // dbase does not need user and password
167 tEnv.addObjRelation("UserAndPassword", new String[]{"",""}) ;
169 tEnv.addObjRelation("XCompletedConnection.Handler",
170 UnoRuntime.queryInterface(XInteractionHandler.class, handler)) ;
172 return tEnv;
173 } // finish method getTestEnvironment