tdf#130857 qt weld: Introduce QtInstanceScrolledWindow
[LibreOffice.git] / qadevOOo / tests / java / mod / _sc / ScDatabaseRangeObj.java
blob65630bd00989ad4d9a43f4f33d3ad94b90c495fb
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 .
18 package mod._sc;
20 import com.sun.star.beans.PropertyValue;
21 import com.sun.star.beans.XPropertySet;
22 import com.sun.star.container.XNameAccess;
23 import com.sun.star.container.XNamed;
24 import com.sun.star.lang.XComponent;
25 import com.sun.star.sheet.XCellRangeAddressable;
26 import com.sun.star.sheet.XCellRangeReferrer;
27 import com.sun.star.sheet.XDatabaseRanges;
28 import com.sun.star.sheet.XSpreadsheetDocument;
29 import com.sun.star.sheet.XSpreadsheets;
30 import com.sun.star.table.CellRangeAddress;
31 import com.sun.star.table.XCellRange;
32 import com.sun.star.uno.AnyConverter;
33 import com.sun.star.uno.Type;
34 import com.sun.star.uno.UnoRuntime;
35 import com.sun.star.uno.XInterface;
36 import com.sun.star.util.XImportable;
38 import java.io.PrintWriter;
40 import lib.TestCase;
41 import lib.TestEnvironment;
42 import lib.TestParameters;
44 import util.SOfficeFactory;
47 /**
48 * Test for object which is represented by service
49 * <code>com.sun.star.sheet.DatabaseRange</code>. <p>
50 * Object implements the following interfaces :
51 * <ul>
52 * <li> <code>com::sun::star::container::XNamed</code></li>
53 * <li> <code>com::sun::star::sheet::DatabaseRange</code></li>
54 * <li> <code>com::sun::star::beans::XPropertySet</code></li>
55 * <li> <code>com::sun::star::sheet::XDatabaseRange</code></li>
56 * <li> <code>com::sun::star::sheet::XCellRangeReferrer</code></li>
57 * </ul>
58 * @see com.sun.star.sheet.DatabaseRange
59 * @see com.sun.star.container.XNamed
60 * @see com.sun.star.sheet.DatabaseRange
61 * @see com.sun.star.beans.XPropertySet
62 * @see com.sun.star.sheet.XDatabaseRange
63 * @see com.sun.star.sheet.XCellRangeReferrer
64 * @see ifc.container._XNamed
65 * @see ifc.sheet._DatabaseRange
66 * @see ifc.beans._XPropertySet
67 * @see ifc.sheet._XDatabaseRange
68 * @see ifc.sheet._XCellRangeReferrer
70 public class ScDatabaseRangeObj extends TestCase {
71 private XSpreadsheetDocument xSheetDoc = null;
73 /**
74 * Creates Spreadsheet document.
76 @Override
77 protected void initialize(TestParameters tParam, PrintWriter log) throws Exception {
78 SOfficeFactory SOF = SOfficeFactory.getFactory(
79 tParam.getMSF());
81 log.println("creating a Spreadsheet document");
82 xSheetDoc = SOF.createCalcDoc(null);
85 /**
86 * Disposes Spreadsheet document.
88 @Override
89 protected void cleanup(TestParameters tParam, PrintWriter log) {
90 log.println(" disposing xSheetDoc ");
92 XComponent oComp = UnoRuntime.queryInterface(
93 XComponent.class, xSheetDoc);
94 util.DesktopTools.closeDoc(oComp);
97 /**
98 * Creating a TestEnvironment for the interfaces to be tested.
99 * Retrieves the collection of database ranges in the document.
100 * If the database range with name <code>'dbRange'</code> exists
101 * in the collection then removes it from the collection.
102 * Creates new database range and adds it to the collection with the name
103 * <code>'dbRange'</code>.The database range that was added to the collection
104 * is the instance of the service <code>com.sun.star.sheet.DatabaseRange</code>.
105 * Object relations created :
106 * <ul>
107 * <li> <code>'DATAAREA'</code> for
108 * {@link ifc.sheet._XCellRangeReferrer}(of type
109 * <code>CellRangeAddress</code>)</li>
110 * <li> <code>'XCELLRANGE'</code> (of type <code>XCellRange</code>):
111 * cell range of the spreadsheet with database range</li>
112 * </ul>
113 * @see com.sun.star.sheet.DatabaseRange
114 * @see com.sun.star.table.CellRangeAddress
116 @Override
117 protected TestEnvironment createTestEnvironment(TestParameters Param,
118 PrintWriter log) throws Exception {
119 XInterface oObj = null;
122 // creation of testobject here
123 // first we write what we are intend to do to log file
124 log.println("Creating a test environment");
126 log.println("Getting test object ");
128 XPropertySet docProps = UnoRuntime.queryInterface(
129 XPropertySet.class, xSheetDoc);
131 XSpreadsheets sheets = xSheetDoc.getSheets();
132 String[] names = sheets.getElementNames();
133 XDatabaseRanges dbRanges = null;
134 XImportable xImp = null;
136 Object sheet = sheets.getByName(names[0]);
137 xImp = UnoRuntime.queryInterface(XImportable.class,
138 sheet);
139 dbRanges = (XDatabaseRanges) AnyConverter.toObject(
140 new Type(XDatabaseRanges.class),
141 docProps.getPropertyValue("DatabaseRanges"));
142 _doImport(xImp);
144 String dbName = "dbRange";
146 if (dbRanges.hasByName(dbName)) {
147 dbRanges.removeByName(dbName);
151 CellRangeAddress aRange = null;
153 XNameAccess dbrNA = UnoRuntime.queryInterface(
154 XNameAccess.class, dbRanges);
155 // we need to add it
156 dbRanges.addNewByName(dbName,new CellRangeAddress((short)0, 0, 0, 0, 5));
158 UnoRuntime.queryInterface(XNamed.class,
159 dbrNA.getByName(
160 dbName));
162 XCellRangeReferrer aReferrer = UnoRuntime.queryInterface(
163 XCellRangeReferrer.class,
164 dbrNA.getByName(dbName));
165 XCellRangeAddressable aRangeA = UnoRuntime.queryInterface(
166 XCellRangeAddressable.class,
167 aReferrer.getReferredCells());
168 aRange = aRangeA.getRangeAddress();
169 oObj = (XInterface) AnyConverter.toObject(
170 new Type(XInterface.class),
171 dbrNA.getByName(dbName));
173 TestEnvironment tEnv = new TestEnvironment(oObj);
176 // Other parameters required for interface tests
177 tEnv.addObjRelation("DATAAREA", aRange);
179 XCellRange xCellRange = UnoRuntime.queryInterface(
180 XCellRange.class, sheets.getByName(names[0]));
182 tEnv.addObjRelation("XCELLRANGE", xCellRange);
184 return tEnv;
187 public void _doImport(XImportable imp) {
188 PropertyValue[] descriptor = imp.createImportDescriptor(false);
190 log.print("Setting the ImportDescriptor (Bibliograpy, SQL, select Identifier from biblio) -- ");
191 descriptor[0].Value = "Bibliography";
192 descriptor[1].Value = com.sun.star.sheet.DataImportMode.SQL;
193 descriptor[2].Value = "select Identifier from biblio";
194 log.println("done");
196 log.print("Importing data (Bibliograpy, Table, biblio) -- ");
197 imp.doImport(descriptor);
198 log.println("done");