merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / mod / _sc / ScLabelRangeObj.java
blob09f8082b57ff431581826c04717f0717d09a7e15
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ScLabelRangeObj.java,v $
10 * $Revision: 1.8 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 package mod._sc;
33 import java.io.PrintWriter;
35 import lib.StatusException;
36 import lib.TestCase;
37 import lib.TestEnvironment;
38 import lib.TestParameters;
39 import util.SOfficeFactory;
41 import com.sun.star.beans.XPropertySet;
42 import com.sun.star.lang.XComponent;
43 import com.sun.star.lang.XMultiServiceFactory;
44 import com.sun.star.sheet.XLabelRange;
45 import com.sun.star.sheet.XLabelRanges;
46 import com.sun.star.sheet.XSpreadsheetDocument;
47 import com.sun.star.table.CellRangeAddress;
48 import com.sun.star.uno.AnyConverter;
49 import com.sun.star.uno.Type;
50 import com.sun.star.uno.UnoRuntime;
51 import com.sun.star.uno.XInterface;
53 /**
54 * Test for object which is represented by service
55 * <code>com.sun.star.sheet.LabelRange</code>. <p>
56 * Object implements the following interfaces :
57 * <ul>
58 * <li> <code>com::sun::star::sheet::XLabelRange</code></li>
59 * </ul>
60 * @see com.sun.star.sheet.LabelRange
61 * @see com.sun.star.sheet.XLabelRange
62 * @see ifc.sheet._XLabelRange
64 public class ScLabelRangeObj extends TestCase {
65 static XSpreadsheetDocument xSheetDoc = null;
67 /**
68 * Creates Spreadsheet document.
70 protected void initialize( TestParameters tParam, PrintWriter log ) {
71 // get a soffice factory object
72 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF());
74 try {
75 log.println( "creating a sheetdocument" );
76 xSheetDoc = SOF.createCalcDoc(null);;
77 } catch (com.sun.star.uno.Exception e) {
78 // Some exception occures.FAILED
79 e.printStackTrace( log );
80 throw new StatusException( "Couldn't create document", e );
84 /**
85 * Disposes Spreadsheet document.
87 protected void cleanup( TestParameters tParam, PrintWriter log ) {
88 log.println( " disposing xSheetDoc " );
89 XComponent oComp = (XComponent)
90 UnoRuntime.queryInterface (XComponent.class, xSheetDoc) ;
91 util.DesktopTools.closeDoc(oComp);
94 /**
95 * Creating a Testenvironment for the interfaces to be tested.
96 * Obtains the value of the property <code>'ColumnLabelRanges'</code>
97 * from the document. The property value is the collection of label ranges.
98 * Adds new label range to the collection using the interface
99 * <code>XLabelRanges</code> that was queried from the property value.
100 * Retrieved from the collection the label range with index 0.
101 * The retrieved label range is the instance of the service
102 * <code>com.sun.star.sheet.LabelRange</code>.
103 * @see com.sun.star.sheet.LabelRange
104 * @see com.sun.star.sheet.XLabelRanges
106 protected synchronized TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) {
108 XInterface oObj = null;
110 // creation of testobject here
111 // first we write what we are intend to do to log file
112 log.println( "Creating a test environment" );
114 try {
115 log.println("Getting test object ") ;
116 XPropertySet docProps = (XPropertySet)
117 UnoRuntime.queryInterface(XPropertySet.class, xSheetDoc);
118 Object ranges = docProps.getPropertyValue("ColumnLabelRanges");
119 XLabelRanges lRanges = (XLabelRanges)
120 UnoRuntime.queryInterface(XLabelRanges.class, ranges);
122 log.println("Adding at least one element for ElementAccess interface");
123 CellRangeAddress aRange2 = new CellRangeAddress((short)0, 0, 1, 0, 6);
124 CellRangeAddress aRange1 = new CellRangeAddress((short)0, 0, 0, 0, 1);
125 lRanges.addNew(aRange1, aRange2);
127 oObj = (XLabelRange) AnyConverter.toObject(
128 new Type(XLabelRange.class),lRanges.getByIndex(0));
129 } catch (com.sun.star.lang.WrappedTargetException e) {
130 e.printStackTrace(log) ;
131 throw new StatusException(
132 "Error getting test object from spreadsheet document",e) ;
133 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
134 e.printStackTrace(log) ;
135 throw new StatusException(
136 "Error getting test object from spreadsheet document",e) ;
137 } catch (com.sun.star.beans.UnknownPropertyException e) {
138 e.printStackTrace(log) ;
139 throw new StatusException(
140 "Error getting test object from spreadsheet document",e) ;
141 } catch (com.sun.star.lang.IllegalArgumentException e) {
142 e.printStackTrace(log) ;
143 throw new StatusException(
144 "Error getting test object from spreadsheet document",e) ;
147 log.println("creating a new environment for object");
148 TestEnvironment tEnv = new TestEnvironment(oObj);
150 log.println("testing...");
152 return tEnv;
154 } // finish method getTestEnvironment
156 } // finish class ScLabelRangeObj