bump product version to 5.0.4.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _sc / ScIndexEnumeration_DatabaseRangesEnumeration.java
blobda2d518d51d8628f7ca5e00b987b99e0e6c83465
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.container.XEnumerationAccess;
31 import com.sun.star.lang.XComponent;
32 import com.sun.star.sheet.XDatabaseRanges;
33 import com.sun.star.sheet.XSpreadsheetDocument;
34 import com.sun.star.table.CellRangeAddress;
35 import com.sun.star.uno.AnyConverter;
36 import com.sun.star.uno.Type;
37 import com.sun.star.uno.UnoRuntime;
38 import com.sun.star.uno.XInterface;
41 public class ScIndexEnumeration_DatabaseRangesEnumeration extends TestCase {
42 private XSpreadsheetDocument xSheetDoc = null;
44 /**
45 * Creates Spreadsheet document.
47 @Override
48 protected void initialize( TestParameters tParam, PrintWriter log ) {
49 SOfficeFactory SOF = SOfficeFactory.getFactory( tParam.getMSF() );
51 try {
52 log.println( "creating a Spreadsheet document" );
53 xSheetDoc = SOF.createCalcDoc(null);
54 } catch ( com.sun.star.uno.Exception e ) {
55 // Some exception occurs.FAILED
56 e.printStackTrace( log );
57 throw new StatusException( "Couldn't create document", e );
62 /**
63 * Disposes Spreadsheet document.
65 @Override
66 protected void cleanup( TestParameters tParam, PrintWriter log ) {
67 log.println( " disposing xSheetDoc " );
68 XComponent oComp = UnoRuntime.queryInterface (XComponent.class, xSheetDoc) ;
69 util.DesktopTools.closeDoc(oComp);
72 @Override
73 protected synchronized TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) {
75 XInterface oObj = null;
77 // creation of testobject here
78 // first we write what we are intend to do to log file
79 log.println( "Creating a test environment" );
81 log.println("Getting test object ") ;
82 XPropertySet docProps = UnoRuntime.queryInterface(XPropertySet.class, xSheetDoc);
84 XDatabaseRanges dbRanges = null;
85 try {
86 dbRanges = (XDatabaseRanges) AnyConverter.toObject(
87 new Type(XDatabaseRanges.class),
88 docProps.getPropertyValue("DatabaseRanges"));
89 } catch (com.sun.star.lang.WrappedTargetException e) {
90 e.printStackTrace(log) ;
91 throw new StatusException(
92 "Error getting test object from spreadsheet document",e) ;
93 } catch (com.sun.star.beans.UnknownPropertyException e) {
94 e.printStackTrace(log) ;
95 throw new StatusException(
96 "Error getting test object from spreadsheet document",e) ;
97 } catch (com.sun.star.lang.IllegalArgumentException e) {
98 e.printStackTrace(log) ;
99 throw new StatusException(
100 "Error getting test object from spreadsheet document",e) ;
103 log.println("Adding at least one element for ElementAccess interface");
104 CellRangeAddress aRange = new CellRangeAddress((short)0, 2, 4, 5, 6);
105 if (!dbRanges.hasByName("dbRange")) {
106 dbRanges.addNewByName("dbRange", aRange);
109 oObj = dbRanges;
110 XEnumerationAccess ea = UnoRuntime.queryInterface(XEnumerationAccess.class,oObj);
112 oObj = ea.createEnumeration();
114 log.println("ImplementationName: "+util.utils.getImplName(oObj));
115 // creating test environment
116 TestEnvironment tEnv = new TestEnvironment( oObj );
118 tEnv.addObjRelation("ENUM",ea);
119 return tEnv;