Branch libreoffice-5-0-4
[LibreOffice.git] / qadevOOo / tests / java / mod / _sc / ScTableRowsObj.java
bloba70cd7394e1060777a06f813240d1c3039bda83e
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.sheet.XSpreadsheet;
32 import com.sun.star.sheet.XSpreadsheetDocument;
33 import com.sun.star.sheet.XSpreadsheets;
34 import com.sun.star.table.XCellRange;
35 import com.sun.star.table.XColumnRowRange;
36 import com.sun.star.table.XTableRows;
37 import com.sun.star.uno.AnyConverter;
38 import com.sun.star.uno.Type;
39 import com.sun.star.uno.UnoRuntime;
40 import com.sun.star.uno.XInterface;
42 /**
43 * Test for object which is represented by service
44 * <code>com.sun.star.table.TableRows</code>. <p>
45 * Object implements the following interfaces :
46 * <ul>
47 * <li> <code>com::sun::star::container::XIndexAccess</code></li>
48 * <li> <code>com::sun::star::container::XElementAccess</code></li>
49 * <li> <code>com::sun::star::table::XTableRows</code></li>
50 * </ul>
51 * @see com.sun.star.table.TableRows
52 * @see com.sun.star.container.XIndexAccess
53 * @see com.sun.star.container.XElementAccess
54 * @see com.sun.star.table.XTableRows
55 * @see ifc.container._XIndexAccess
56 * @see ifc.container._XElementAccess
57 * @see ifc.table._XTableRows
59 public class ScTableRowsObj extends TestCase {
60 XSpreadsheetDocument xSheetDoc = null;
62 /**
63 * Creates Spreadsheet document.
65 @Override
66 protected void initialize( TestParameters tParam, PrintWriter log ) {
67 SOfficeFactory SOF = SOfficeFactory.getFactory( 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 @Override
83 protected void cleanup( TestParameters tParam, PrintWriter log ) {
84 log.println( " disposing xSheetDoc " );
85 XComponent oComp = UnoRuntime.queryInterface (XComponent.class, xSheetDoc) ;
86 util.DesktopTools.closeDoc(oComp);
89 /**
90 * Creating a Testenvironment for the interfaces to be tested.
91 * Retrieves a collection of spreadsheets from the document and takes one of
92 * them. Obtains the collection of rows using the interface
93 * <code>XColumnRowRange</code>. The obtained collection is the instance of
94 * the service <code>com.sun.star.table.TableRows</code>.
95 * @see com.sun.star.table.XColumnRowRange
96 * @see com.sun.star.table.TableRows
98 @Override
99 protected synchronized TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) {
101 XInterface oObj = null;
103 log.println("getting row");
104 XSpreadsheet xSpreadsheet = null;
106 XSpreadsheets xSpreadsheets = xSheetDoc.getSheets();
107 XNameAccess oNames = UnoRuntime.queryInterface( XNameAccess.class, xSpreadsheets );
108 try {
109 xSpreadsheet = (XSpreadsheet) AnyConverter.toObject(
110 new Type(XSpreadsheet.class),
111 oNames.getByName(oNames.getElementNames()[0]));
112 } catch(com.sun.star.lang.WrappedTargetException e) {
113 e.printStackTrace(log);
114 throw new StatusException("Couldn't get spreadsheet", e);
115 } catch(com.sun.star.container.NoSuchElementException e) {
116 e.printStackTrace(log);
117 throw new StatusException("Couldn't get spreadsheet", e);
118 } catch(com.sun.star.lang.IllegalArgumentException e) {
119 e.printStackTrace(log);
120 throw new StatusException("Couldn't get spreadsheet", e);
123 XColumnRowRange oColumnRowRange = UnoRuntime.queryInterface(XColumnRowRange.class, xSpreadsheet);
125 XTableRows oRows = oColumnRowRange.getRows();
126 oObj = oRows;
128 log.println("creating a new environment for object");
129 TestEnvironment tEnv = new TestEnvironment(oObj);
131 // adding relation for XTableRows
132 tEnv.addObjRelation("XTableRows.XCellRange",
133 UnoRuntime.queryInterface(XCellRange.class, xSpreadsheet));
135 return tEnv;
137 } // finish class ScTableRowsObj