merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / mod / _sc / ScTableRowObj.java
blobf2e805577eda3a38339c45964ad2e61b6204c960
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: ScTableRowObj.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.container.XIndexAccess;
42 import com.sun.star.container.XNameAccess;
43 import com.sun.star.lang.XComponent;
44 import com.sun.star.lang.XMultiServiceFactory;
45 import com.sun.star.sheet.XSpreadsheet;
46 import com.sun.star.sheet.XSpreadsheetDocument;
47 import com.sun.star.sheet.XSpreadsheets;
48 import com.sun.star.table.XColumnRowRange;
49 import com.sun.star.table.XTableRows;
50 import com.sun.star.uno.AnyConverter;
51 import com.sun.star.uno.Type;
52 import com.sun.star.uno.UnoRuntime;
53 import com.sun.star.uno.XInterface;
55 /**
56 * Test for object which is represented by service
57 * <code>com.sun.star.table.TableRow</code>. <p>
58 * Object implements the following interfaces :
59 * <ul>
60 * <li> <code>com::sun::star::table::TableRow</code></li>
61 * <li> <code>com::sun::star::table::XCellRange</code></li>
62 * <li> <code>com::sun::star::beans::XPropertySet</code></li>
63 * </ul>
64 * @see com.sun.star.table.TableRow
65 * @see com.sun.star.table.XCellRange
66 * @see com.sun.star.beans.XPropertySet
67 * @see ifc.table._TableRow
68 * @see ifc.table._XCellRange
69 * @see ifc.beans._XPropertySet
71 public class ScTableRowObj extends TestCase {
72 static XSpreadsheetDocument xSheetDoc = null;
74 /**
75 * Creates Spreadsheet document.
77 protected void initialize( TestParameters tParam, PrintWriter log ) {
78 // get a soffice factory object
79 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF());
81 try {
82 log.println( "creating a sheetdocument" );
83 xSheetDoc = SOF.createCalcDoc(null);;
84 } catch (com.sun.star.uno.Exception e) {
85 // Some exception occures.FAILED
86 e.printStackTrace( log );
87 throw new StatusException( "Couldn't create document", e );
91 /**
92 * Disposes Spreadsheet document.
94 protected void cleanup( TestParameters tParam, PrintWriter log ) {
95 log.println( " disposing xSheetDoc " );
96 XComponent oComp = (XComponent)
97 UnoRuntime.queryInterface (XComponent.class, xSheetDoc) ;
98 util.DesktopTools.closeDoc(oComp);
102 * Creating a Testenvironment for the interfaces to be tested.
103 * Retrieves a collection of spreadsheets from the document and takes one of
104 * them. Obtains the collection of rows using the interface
105 * <code>XColumnRowRange</code>. Obtains the row with index 6 from the
106 * collection and this is the instance of the service
107 * <code>com.sun.star.table.TableRow</code>.
108 * Object relations created :
109 * <ul>
110 * <li> <code>'ValidRange'</code> for
111 * {@link ifc.table._XCellRange} </li>
112 * </ul>
113 * @see com.sun.star.table.XColumnRowRange
114 * @see com.sun.star.table.TableRow
116 protected synchronized TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) {
118 XInterface oObj = null;
120 // creation of the testobject here
121 // first we write what we are intend to do to log file
122 log.println("creating a test environment");
124 XSpreadsheet xSpreadsheet = null;
125 XSpreadsheets xSpreadsheets = (XSpreadsheets)xSheetDoc.getSheets();
126 XNameAccess oNames = (XNameAccess)
127 UnoRuntime.queryInterface( XNameAccess.class, xSpreadsheets );
128 try {
129 xSpreadsheet = (XSpreadsheet) AnyConverter.toObject(
130 new Type(XSpreadsheet.class),
131 oNames.getByName(oNames.getElementNames()[0]));
133 XColumnRowRange oColumnRowRange = (XColumnRowRange)
134 UnoRuntime.queryInterface(XColumnRowRange.class, xSpreadsheet);
135 XTableRows oRows = (XTableRows) oColumnRowRange.getRows();
136 XIndexAccess oIndexAccess = (XIndexAccess)
137 UnoRuntime.queryInterface(XIndexAccess.class, oRows);
138 oObj = (XInterface) AnyConverter.toObject(
139 new Type(XInterface.class),oIndexAccess.getByIndex(6));
140 } catch(com.sun.star.lang.WrappedTargetException e) {
141 e.printStackTrace(log);
142 throw new StatusException(
143 "Exception during creating Testenvironment", e);
144 } catch(com.sun.star.container.NoSuchElementException e) {
145 e.printStackTrace(log);
146 throw new StatusException(
147 "Exception during creating Testenvironment", e);
148 } catch(com.sun.star.lang.IndexOutOfBoundsException e) {
149 e.printStackTrace(log);
150 throw new StatusException(
151 "Exception during creating Testenvironment", e);
152 } catch(com.sun.star.lang.IllegalArgumentException e) {
153 e.printStackTrace(log);
154 throw new StatusException(
155 "Exception during creating Testenvironment", e);
158 log.println("creating a new environment for object");
159 TestEnvironment tEnv = new TestEnvironment(oObj);
160 tEnv.addObjRelation("ValidRange","A7:A7");
161 return tEnv;