bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _sc / ScLabelRangeObj.java
blob77892fe487ba65028a7b8ff683a3fb17cd1b649f
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.lang.XMultiServiceFactory;
32 import com.sun.star.sheet.XLabelRange;
33 import com.sun.star.sheet.XLabelRanges;
34 import com.sun.star.sheet.XSpreadsheetDocument;
35 import com.sun.star.table.CellRangeAddress;
36 import com.sun.star.uno.AnyConverter;
37 import com.sun.star.uno.Type;
38 import com.sun.star.uno.UnoRuntime;
39 import com.sun.star.uno.XInterface;
41 /**
42 * Test for object which is represented by service
43 * <code>com.sun.star.sheet.LabelRange</code>. <p>
44 * Object implements the following interfaces :
45 * <ul>
46 * <li> <code>com::sun::star::sheet::XLabelRange</code></li>
47 * </ul>
48 * @see com.sun.star.sheet.LabelRange
49 * @see com.sun.star.sheet.XLabelRange
50 * @see ifc.sheet._XLabelRange
52 public class ScLabelRangeObj extends TestCase {
53 private XSpreadsheetDocument xSheetDoc = null;
55 /**
56 * Creates Spreadsheet document.
58 protected void initialize( TestParameters tParam, PrintWriter log ) {
59 // get a soffice factory object
60 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF());
62 try {
63 log.println( "creating a sheetdocument" );
64 xSheetDoc = SOF.createCalcDoc(null);
65 } catch (com.sun.star.uno.Exception e) {
66 // Some exception occurs.FAILED
67 e.printStackTrace( log );
68 throw new StatusException( "Couldn't create document", e );
72 /**
73 * Disposes Spreadsheet document.
75 protected void cleanup( TestParameters tParam, PrintWriter log ) {
76 log.println( " disposing xSheetDoc " );
77 XComponent oComp = UnoRuntime.queryInterface (XComponent.class, xSheetDoc) ;
78 util.DesktopTools.closeDoc(oComp);
81 /**
82 * Creating a Testenvironment for the interfaces to be tested.
83 * Obtains the value of the property <code>'ColumnLabelRanges'</code>
84 * from the document. The property value is the collection of label ranges.
85 * Adds new label range to the collection using the interface
86 * <code>XLabelRanges</code> that was queried from the property value.
87 * Retrieved from the collection the label range with index 0.
88 * The retrieved label range is the instance of the service
89 * <code>com.sun.star.sheet.LabelRange</code>.
90 * @see com.sun.star.sheet.LabelRange
91 * @see com.sun.star.sheet.XLabelRanges
93 protected synchronized TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) {
95 XInterface oObj = null;
97 // creation of testobject here
98 // first we write what we are intend to do to log file
99 log.println( "Creating a test environment" );
101 try {
102 log.println("Getting test object ") ;
103 XPropertySet docProps = UnoRuntime.queryInterface(XPropertySet.class, xSheetDoc);
104 Object ranges = docProps.getPropertyValue("ColumnLabelRanges");
105 XLabelRanges lRanges = UnoRuntime.queryInterface(XLabelRanges.class, ranges);
107 log.println("Adding at least one element for ElementAccess interface");
108 CellRangeAddress aRange2 = new CellRangeAddress((short)0, 0, 1, 0, 6);
109 CellRangeAddress aRange1 = new CellRangeAddress((short)0, 0, 0, 0, 1);
110 lRanges.addNew(aRange1, aRange2);
112 oObj = (XLabelRange) AnyConverter.toObject(
113 new Type(XLabelRange.class),lRanges.getByIndex(0));
114 } catch (com.sun.star.lang.WrappedTargetException e) {
115 e.printStackTrace(log) ;
116 throw new StatusException(
117 "Error getting test object from spreadsheet document",e) ;
118 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
119 e.printStackTrace(log) ;
120 throw new StatusException(
121 "Error getting test object from spreadsheet document",e) ;
122 } catch (com.sun.star.beans.UnknownPropertyException e) {
123 e.printStackTrace(log) ;
124 throw new StatusException(
125 "Error getting test object from spreadsheet document",e) ;
126 } catch (com.sun.star.lang.IllegalArgumentException e) {
127 e.printStackTrace(log) ;
128 throw new StatusException(
129 "Error getting test object from spreadsheet document",e) ;
132 log.println("creating a new environment for object");
133 TestEnvironment tEnv = new TestEnvironment(oObj);
135 log.println("testing...");
137 return tEnv;
139 } // finish method getTestEnvironment
141 } // finish class ScLabelRangeObj