bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _sc / ScTableRowsObj.java
blob7ff7844664d04263c2f6aabe51ec96f213b9d006
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.XNameAccess;
30 import com.sun.star.lang.XComponent;
31 import com.sun.star.lang.XMultiServiceFactory;
32 import com.sun.star.sheet.XSpreadsheet;
33 import com.sun.star.sheet.XSpreadsheetDocument;
34 import com.sun.star.sheet.XSpreadsheets;
35 import com.sun.star.table.XCellRange;
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.TableRows</code>. <p>
46 * Object implements the following interfaces :
47 * <ul>
48 * <li> <code>com::sun::star::container::XIndexAccess</code></li>
49 * <li> <code>com::sun::star::container::XElementAccess</code></li>
50 * <li> <code>com::sun::star::table::XTableRows</code></li>
51 * </ul>
52 * @see com.sun.star.table.TableRows
53 * @see com.sun.star.container.XIndexAccess
54 * @see com.sun.star.container.XElementAccess
55 * @see com.sun.star.table.XTableRows
56 * @see ifc.container._XIndexAccess
57 * @see ifc.container._XElementAccess
58 * @see ifc.table._XTableRows
60 public class ScTableRowsObj extends TestCase {
61 XSpreadsheetDocument xSheetDoc = null;
63 /**
64 * Creates Spreadsheet document.
66 protected void initialize( TestParameters tParam, PrintWriter log ) {
67 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() );
69 try {
70 log.println( "creating a Spreadsheet document" );
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>. The obtained collection is the instance of
93 * the service <code>com.sun.star.table.TableRows</code>.
94 * @see com.sun.star.table.XColumnRowRange
95 * @see com.sun.star.table.TableRows
97 protected synchronized TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) {
99 XInterface oObj = null;
101 log.println("getting row");
102 XSpreadsheet xSpreadsheet = null;
104 XSpreadsheets xSpreadsheets = xSheetDoc.getSheets();
105 XNameAccess oNames = UnoRuntime.queryInterface( XNameAccess.class, xSpreadsheets );
106 try {
107 xSpreadsheet = (XSpreadsheet) AnyConverter.toObject(
108 new Type(XSpreadsheet.class),
109 oNames.getByName(oNames.getElementNames()[0]));
110 } catch(com.sun.star.lang.WrappedTargetException e) {
111 e.printStackTrace(log);
112 throw new StatusException("Couldn't get spreadsheet", e);
113 } catch(com.sun.star.container.NoSuchElementException e) {
114 e.printStackTrace(log);
115 throw new StatusException("Couldn't get spreadsheet", e);
116 } catch(com.sun.star.lang.IllegalArgumentException e) {
117 e.printStackTrace(log);
118 throw new StatusException("Couldn't get spreadsheet", e);
121 XColumnRowRange oColumnRowRange = UnoRuntime.queryInterface(XColumnRowRange.class, xSpreadsheet);
123 XTableRows oRows = oColumnRowRange.getRows();
124 oObj = oRows;
126 log.println("creating a new environment for object");
127 TestEnvironment tEnv = new TestEnvironment(oObj);
129 // adding relation for XTableRows
130 tEnv.addObjRelation("XTableRows.XCellRange",
131 UnoRuntime.queryInterface(XCellRange.class, xSpreadsheet));
133 return tEnv;
135 } // finish class ScTableRowsObj