Branch libreoffice-5-0-4
[LibreOffice.git] / qadevOOo / tests / java / mod / _sc / ScLabelRangeObj.java
blob1dd858706337a3226422fb9af8a52276dec202ad
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.XLabelRange;
32 import com.sun.star.sheet.XLabelRanges;
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;
40 /**
41 * Test for object which is represented by service
42 * <code>com.sun.star.sheet.LabelRange</code>. <p>
43 * Object implements the following interfaces :
44 * <ul>
45 * <li> <code>com::sun::star::sheet::XLabelRange</code></li>
46 * </ul>
47 * @see com.sun.star.sheet.LabelRange
48 * @see com.sun.star.sheet.XLabelRange
49 * @see ifc.sheet._XLabelRange
51 public class ScLabelRangeObj extends TestCase {
52 private XSpreadsheetDocument xSheetDoc = null;
54 /**
55 * Creates Spreadsheet document.
57 @Override
58 protected void initialize( TestParameters tParam, PrintWriter log ) {
59 // get a soffice factory object
60 SOfficeFactory SOF = SOfficeFactory.getFactory( 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 @Override
76 protected void cleanup( TestParameters tParam, PrintWriter log ) {
77 log.println( " disposing xSheetDoc " );
78 XComponent oComp = UnoRuntime.queryInterface (XComponent.class, xSheetDoc) ;
79 util.DesktopTools.closeDoc(oComp);
82 /**
83 * Creating a Testenvironment for the interfaces to be tested.
84 * Obtains the value of the property <code>'ColumnLabelRanges'</code>
85 * from the document. The property value is the collection of label ranges.
86 * Adds new label range to the collection using the interface
87 * <code>XLabelRanges</code> that was queried from the property value.
88 * Retrieved from the collection the label range with index 0.
89 * The retrieved label range is the instance of the service
90 * <code>com.sun.star.sheet.LabelRange</code>.
91 * @see com.sun.star.sheet.LabelRange
92 * @see com.sun.star.sheet.XLabelRanges
94 @Override
95 protected synchronized TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) {
97 XInterface oObj = null;
99 // creation of testobject here
100 // first we write what we are intend to do to log file
101 log.println( "Creating a test environment" );
103 try {
104 log.println("Getting test object ") ;
105 XPropertySet docProps = UnoRuntime.queryInterface(XPropertySet.class, xSheetDoc);
106 Object ranges = docProps.getPropertyValue("ColumnLabelRanges");
107 XLabelRanges lRanges = UnoRuntime.queryInterface(XLabelRanges.class, ranges);
109 log.println("Adding at least one element for ElementAccess interface");
110 CellRangeAddress aRange2 = new CellRangeAddress((short)0, 0, 1, 0, 6);
111 CellRangeAddress aRange1 = new CellRangeAddress((short)0, 0, 0, 0, 1);
112 lRanges.addNew(aRange1, aRange2);
114 oObj = (XLabelRange) AnyConverter.toObject(
115 new Type(XLabelRange.class),lRanges.getByIndex(0));
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.lang.IndexOutOfBoundsException e) {
121 e.printStackTrace(log) ;
122 throw new StatusException(
123 "Error getting test object from spreadsheet document",e) ;
124 } catch (com.sun.star.beans.UnknownPropertyException e) {
125 e.printStackTrace(log) ;
126 throw new StatusException(
127 "Error getting test object from spreadsheet document",e) ;
128 } catch (com.sun.star.lang.IllegalArgumentException e) {
129 e.printStackTrace(log) ;
130 throw new StatusException(
131 "Error getting test object from spreadsheet document",e) ;
134 log.println("creating a new environment for object");
135 TestEnvironment tEnv = new TestEnvironment(oObj);
137 log.println("testing...");
139 return tEnv;
141 } // finish method getTestEnvironment
143 } // finish class ScLabelRangeObj