bump product version to 5.0.4.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _sc / ScDatabaseRangesObj.java
blob950eacc1052cca18b8eae99c59f550eae299834a
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._sc;
21 import java.io.PrintWriter;
23 import lib.StatusException;
24 import lib.TestCase;
25 import lib.TestEnvironment;
26 import lib.TestParameters;
27 import util.SOfficeFactory;
29 import com.sun.star.beans.XPropertySet;
30 import com.sun.star.lang.XComponent;
31 import com.sun.star.sheet.XDatabaseRanges;
32 import com.sun.star.sheet.XSpreadsheetDocument;
33 import com.sun.star.table.CellRangeAddress;
34 import com.sun.star.uno.AnyConverter;
35 import com.sun.star.uno.Type;
36 import com.sun.star.uno.UnoRuntime;
37 import com.sun.star.uno.XInterface;
39 /**
40 * Test for object which is represented by service
41 * <code>com.sun.star.sheet.DatabaseRanges</code>. <p>
42 * Object implements the following interfaces :
43 * <ul>
44 * <li> <code>com::sun::star::sheet::XDatabaseRanges</code></li>
45 * <li> <code>com::sun::star::container::XNameAccess</code></li>
46 * <li> <code>com::sun::star::container::XElementAccess</code></li>
47 * </ul>
48 * @see com.sun.star.sheet.DatabaseRanges
49 * @see com.sun.star.sheet.XDatabaseRanges
50 * @see com.sun.star.container.XNameAccess
51 * @see com.sun.star.container.XElementAccess
52 * @see ifc.sheet._XDatabaseRanges
53 * @see ifc.container._XNameAccess
54 * @see ifc.container._XElementAccess
56 public class ScDatabaseRangesObj extends TestCase {
57 private XSpreadsheetDocument xSheetDoc = null;
59 /**
60 * Creates Spreadsheet document.
62 @Override
63 protected void initialize( TestParameters tParam, PrintWriter log ) {
64 SOfficeFactory SOF = SOfficeFactory.getFactory( tParam.getMSF() );
66 try {
67 log.println( "creating a Spreadsheet document" );
68 xSheetDoc = SOF.createCalcDoc(null);
69 } catch ( com.sun.star.uno.Exception e ) {
70 // Some exception occurs.FAILED
71 e.printStackTrace( log );
72 throw new StatusException( "Couldn't create document", e );
77 /**
78 * Disposes Spreadsheet document.
80 @Override
81 protected void cleanup( TestParameters tParam, PrintWriter log ) {
82 log.println( " disposing xSheetDoc " );
83 XComponent oComp = UnoRuntime.queryInterface (XComponent.class, xSheetDoc) ;
84 util.DesktopTools.closeDoc(oComp);
87 /**
88 * Creating a Testenvironment for the interfaces to be tested.
89 * Retrieves the collection of database ranges in the document.
90 * If the database range with name <code>'dbRange'</code> doesn't exist
91 * in the collection then creates new database range and adds it to the
92 * collection with the name <code>'dbRange'</code> to have one element
93 * for the test of the interface <code>ElementAccess</code> at least.
94 * The collection of database ranges is the instance of the service
95 * <code>com.sun.star.sheet.DatabaseRanges</code>.
96 * @see com.sun.star.sheet.DatabaseRanges
97 * @see com.sun.star.container.XElementAccess
99 @Override
100 protected synchronized TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) {
102 XInterface oObj = null;
104 // creation of testobject here
105 // first we write what we are intend to do to log file
106 log.println( "Creating a test environment" );
108 log.println("Getting test object ") ;
109 XPropertySet docProps = UnoRuntime.queryInterface(XPropertySet.class, xSheetDoc);
111 XDatabaseRanges dbRanges = null;
112 try {
113 dbRanges = (XDatabaseRanges) AnyConverter.toObject(
114 new Type(XDatabaseRanges.class),
115 docProps.getPropertyValue("DatabaseRanges"));
116 } catch (com.sun.star.lang.WrappedTargetException e) {
117 e.printStackTrace(log) ;
118 throw new StatusException(
119 "Error getting test object from spreadsheet document",e) ;
120 } catch (com.sun.star.beans.UnknownPropertyException e) {
121 e.printStackTrace(log) ;
122 throw new StatusException(
123 "Error getting test object from spreadsheet document",e) ;
124 } catch (com.sun.star.lang.IllegalArgumentException e) {
125 e.printStackTrace(log) ;
126 throw new StatusException(
127 "Error getting test object from spreadsheet document",e) ;
130 log.println("Adding at least one element for ElementAccess interface");
131 CellRangeAddress aRange = new CellRangeAddress((short)0, 2, 4, 5, 6);
132 if (!dbRanges.hasByName("dbRange")) {
133 dbRanges.addNewByName("dbRange", aRange);
136 oObj = dbRanges;
137 TestEnvironment tEnv = new TestEnvironment( oObj );
139 // Other parameters required for interface tests
140 return tEnv;