bump product version to 5.0.4.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _sc / ScCellsObj.java
blob923f10c8ecc4ada000c40dcd65b356999287aeee
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.lang.XComponent;
31 import com.sun.star.sheet.XCellRangesQuery;
32 import com.sun.star.sheet.XSheetCellRanges;
33 import com.sun.star.sheet.XSpreadsheetDocument;
34 import com.sun.star.sheet.XSpreadsheets;
35 import com.sun.star.table.XCell;
36 import com.sun.star.table.XCellRange;
37 import com.sun.star.text.XTextRange;
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.sheet.Cells</code>. <p>
46 * Object implements the following interfaces :
47 * <ul>
48 * <li> <code>com::sun::star::container::XEnumerationAccess</code></li>
49 * <li> <code>com::sun::star::container::XElementAccess</code></li>
50 * </ul>
51 * @see com.sun.star.sheet.Cells
52 * @see com.sun.star.container.XEnumerationAccess
53 * @see com.sun.star.container.XElementAccess
54 * @see ifc.container._XEnumerationAccess
55 * @see ifc.container._XElementAccess
57 public class ScCellsObj extends TestCase {
58 private XSpreadsheetDocument xSheetDoc = null;
60 /**
61 * Creates Spreadsheet document.
63 @Override
64 protected void initialize( TestParameters tParam, PrintWriter log ) {
66 // get a soffice factory object
67 SOfficeFactory SOF = SOfficeFactory.getFactory( 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 @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 a document,
92 * and takes one of them. Replaces text of some cells.
93 * Retrieves a cell range of the visible cells using the interface
94 * <code>XCellRangesQuery</code>. Retrieves a collection of cells from
95 * this cell range, this collection is instance of the service
96 * <code>com.sun.star.sheet.Cells</code>.
97 * @see com.sun.star.sheet.XCellRangesQuery
99 @Override
100 protected synchronized TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) {
102 XInterface oObj = null;
103 Object cellArr[] = new Object[3];
105 // creation of testobject here
106 XSpreadsheets oSheets = xSheetDoc.getSheets();
107 XIndexAccess oIndexAccess = UnoRuntime.queryInterface(XIndexAccess.class, oSheets);
108 XCellRange oSheet = null;
109 try {
110 oSheet = (XCellRange) AnyConverter.toObject(
111 new Type(XCellRange.class),oIndexAccess.getByIndex(0));
113 XCell oCell_1 = oSheet.getCellByPosition(0, 0);
114 XTextRange oTextRange = UnoRuntime.queryInterface(XTextRange.class, oCell_1);
116 oTextRange.setString("ScCellsObj test 1");
118 XCell oCell_2 = oSheet.getCellByPosition(5, 1);
119 oCell_2.setValue(15);
121 XCell oCell_3 = oSheet.getCellByPosition(3, 9);
122 oTextRange = UnoRuntime.queryInterface(XTextRange.class, oCell_3);
124 oTextRange.setString("ScCellsObj test 2");
126 cellArr[0] = oCell_1;
127 cellArr[2] = oCell_2;
128 cellArr[1] = oCell_3;
129 } catch(com.sun.star.lang.WrappedTargetException e) {
130 log.println ("Exception occurred while creating test Object.");
131 e.printStackTrace(log);
132 throw new StatusException("Couldn't create test object", e);
133 } catch(com.sun.star.lang.IndexOutOfBoundsException e) {
134 log.println ("Exception occurred while creating test Object.");
135 e.printStackTrace(log);
136 throw new StatusException("Couldn't create test object", e);
137 } catch(com.sun.star.lang.IllegalArgumentException e) {
138 log.println ("Exception occurred while creating test Object.");
139 e.printStackTrace(log);
140 throw new StatusException("Couldn't create test object", e);
143 XCellRangesQuery oCellRangesQuery = UnoRuntime.queryInterface(XCellRangesQuery.class, oSheet);
144 XSheetCellRanges oSheetCellRanges = oCellRangesQuery.queryVisibleCells();
146 oObj = oSheetCellRanges.getCells();
148 TestEnvironment tEnv = new TestEnvironment(oObj) ;
149 log.println ("Object created.") ;
151 return tEnv;
154 } // finish class ScCellsObj