bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _sc / ScTableRowObj.java
blob7cc6cd3c076eb10c76f01afeb6043c821864ffc1
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.container.XIndexAccess;
30 import com.sun.star.container.XNameAccess;
31 import com.sun.star.lang.XComponent;
32 import com.sun.star.lang.XMultiServiceFactory;
33 import com.sun.star.sheet.XSpreadsheet;
34 import com.sun.star.sheet.XSpreadsheetDocument;
35 import com.sun.star.sheet.XSpreadsheets;
36 import com.sun.star.table.XColumnRowRange;
37 import com.sun.star.table.XTableRows;
38 import com.sun.star.uno.AnyConverter;
39 import com.sun.star.uno.Type;
40 import com.sun.star.uno.UnoRuntime;
41 import com.sun.star.uno.XInterface;
43 /**
44 * Test for object which is represented by service
45 * <code>com.sun.star.table.TableRow</code>. <p>
46 * Object implements the following interfaces :
47 * <ul>
48 * <li> <code>com::sun::star::table::TableRow</code></li>
49 * <li> <code>com::sun::star::table::XCellRange</code></li>
50 * <li> <code>com::sun::star::beans::XPropertySet</code></li>
51 * </ul>
52 * @see com.sun.star.table.TableRow
53 * @see com.sun.star.table.XCellRange
54 * @see com.sun.star.beans.XPropertySet
55 * @see ifc.table._TableRow
56 * @see ifc.table._XCellRange
57 * @see ifc.beans._XPropertySet
59 public class ScTableRowObj extends TestCase {
60 private XSpreadsheetDocument xSheetDoc = null;
62 /**
63 * Creates Spreadsheet document.
65 protected void initialize( TestParameters tParam, PrintWriter log ) {
66 // get a soffice factory object
67 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF());
69 try {
70 log.println( "creating a sheetdocument" );
71 xSheetDoc = SOF.createCalcDoc(null);
72 } catch (com.sun.star.uno.Exception e) {
73 // Some exception occurs.FAILED
74 e.printStackTrace( log );
75 throw new StatusException( "Couldn't create document", e );
79 /**
80 * Disposes Spreadsheet document.
82 protected void cleanup( TestParameters tParam, PrintWriter log ) {
83 log.println( " disposing xSheetDoc " );
84 XComponent oComp = UnoRuntime.queryInterface (XComponent.class, xSheetDoc) ;
85 util.DesktopTools.closeDoc(oComp);
88 /**
89 * Creating a Testenvironment for the interfaces to be tested.
90 * Retrieves a collection of spreadsheets from the document and takes one of
91 * them. Obtains the collection of rows using the interface
92 * <code>XColumnRowRange</code>. Obtains the row with index 6 from the
93 * collection and this is the instance of the service
94 * <code>com.sun.star.table.TableRow</code>.
95 * Object relations created :
96 * <ul>
97 * <li> <code>'ValidRange'</code> for
98 * {@link ifc.table._XCellRange} </li>
99 * </ul>
100 * @see com.sun.star.table.XColumnRowRange
101 * @see com.sun.star.table.TableRow
103 protected synchronized TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) {
105 XInterface oObj = null;
107 // creation of the testobject here
108 // first we write what we are intend to do to log file
109 log.println("creating a test environment");
111 XSpreadsheet xSpreadsheet = null;
112 XSpreadsheets xSpreadsheets = xSheetDoc.getSheets();
113 XNameAccess oNames = UnoRuntime.queryInterface( XNameAccess.class, xSpreadsheets );
114 try {
115 xSpreadsheet = (XSpreadsheet) AnyConverter.toObject(
116 new Type(XSpreadsheet.class),
117 oNames.getByName(oNames.getElementNames()[0]));
119 XColumnRowRange oColumnRowRange = UnoRuntime.queryInterface(XColumnRowRange.class, xSpreadsheet);
120 XTableRows oRows = oColumnRowRange.getRows();
121 XIndexAccess oIndexAccess = UnoRuntime.queryInterface(XIndexAccess.class, oRows);
122 oObj = (XInterface) AnyConverter.toObject(
123 new Type(XInterface.class),oIndexAccess.getByIndex(6));
124 } catch(com.sun.star.lang.WrappedTargetException e) {
125 e.printStackTrace(log);
126 throw new StatusException(
127 "Exception during creating Testenvironment", e);
128 } catch(com.sun.star.container.NoSuchElementException e) {
129 e.printStackTrace(log);
130 throw new StatusException(
131 "Exception during creating Testenvironment", e);
132 } catch(com.sun.star.lang.IndexOutOfBoundsException e) {
133 e.printStackTrace(log);
134 throw new StatusException(
135 "Exception during creating Testenvironment", e);
136 } catch(com.sun.star.lang.IllegalArgumentException e) {
137 e.printStackTrace(log);
138 throw new StatusException(
139 "Exception during creating Testenvironment", e);
142 log.println("creating a new environment for object");
143 TestEnvironment tEnv = new TestEnvironment(oObj);
144 tEnv.addObjRelation("ValidRange","A7:A7");
145 return tEnv;